···
1
+
import ./make-test-python.nix (
6
+
maintainers = with lib.maintainers; [ eclairevoyant ];
9
+
# testScriptWithTypes:49: error: Cannot call function of unknown type
10
+
# (machine.succeed if succeed else machine.execute)(
12
+
# Found 1 error in 1 file (checked 1 source file)
13
+
skipTypeCheck = true;
18
+
# Automatically login on tty1 as a normal user:
19
+
imports = [ ./common/user-account.nix ];
20
+
services.getty.autologinUser = "alice";
23
+
# For glinfo and wayland-info:
24
+
systemPackages = with pkgs; [
29
+
# Use a fixed SWAYSOCK path (for swaymsg):
31
+
"SWAYSOCK" = "/tmp/sway-ipc.sock";
32
+
# TODO: Investigate if we can get hardware acceleration to work (via
33
+
# virtio-gpu and Virgil). We currently have to use the Pixman software
34
+
# renderer since the GLES2 renderer doesn't work inside the VM (even
35
+
# with WLR_RENDERER_ALLOW_SOFTWARE):
36
+
# "WLR_RENDERER_ALLOW_SOFTWARE" = "1";
37
+
"WLR_RENDERER" = "pixman";
41
+
test-x11 = "glinfo | tee /tmp/test-x11.out && touch /tmp/test-x11-exit-ok";
42
+
test-wayland = "wayland-info | tee /tmp/test-wayland.out && touch /tmp/test-wayland-exit-ok";
46
+
etc."xdg/foot/foot.ini".text = lib.generators.toINI { } {
48
+
font = "inconsolata:size=14";
51
+
foreground = "000000";
52
+
background = "ffffff";
53
+
regular2 = foreground;
57
+
etc."gpg-agent.conf".text = ''
58
+
pinentry-timeout 86400
62
+
fonts.packages = [ pkgs.inconsolata ];
64
+
# Automatically configure and start Sway when logging in on tty1:
65
+
programs.bash.loginShellInit = ''
66
+
if [ "$(tty)" = "/dev/tty1" ]; then
69
+
mkdir -p ~/.config/sway
70
+
sed s/Mod4/Mod1/ /etc/sway/config > ~/.config/sway/config
73
+
sway && touch /tmp/sway-exit-ok
79
+
package = pkgs.swayfx.override { isNixOS = true; };
82
+
# To test pinentry via gpg-agent:
83
+
programs.gnupg.agent.enable = true;
85
+
# Need to switch to a different GPU driver than the default one (-vga std) so that Sway can launch:
86
+
virtualisation.qemu.options = [ "-vga none -device virtio-gpu-pci" ];
96
+
NODE_GROUPS = ["nodes", "floating_nodes"]
99
+
def swaymsg(command: str = "", succeed=True, type="command"):
100
+
assert command != "" or type != "command", "Must specify command or type"
101
+
shell = q(f"swaymsg -t {q(type)} -- {q(command)}")
102
+
with machine.nested(
103
+
f"sending swaymsg {shell!r}" + " (allowed to fail)" * (not succeed)
105
+
ret = (machine.succeed if succeed else machine.execute)(
106
+
f"su - alice -c {shell}"
109
+
# execute also returns a status code, but disregard.
113
+
if not succeed and not ret:
116
+
parsed = json.loads(ret)
122
+
for group in NODE_GROUPS:
123
+
for node in tree.get(group, []):
124
+
yield from walk(node)
127
+
def wait_for_window(pattern):
128
+
def func(last_chance):
129
+
nodes = (node["name"] for node in walk(swaymsg(type="get_tree")))
132
+
nodes = list(nodes)
133
+
machine.log(f"Last call! Current list of windows: {nodes}")
135
+
return any(pattern in name for name in nodes)
140
+
machine.wait_for_unit("multi-user.target")
142
+
# To check the version:
143
+
print(machine.succeed("sway --version"))
145
+
# Wait for Sway to complete startup:
146
+
machine.wait_for_file("/run/user/1000/wayland-1")
147
+
machine.wait_for_file("/tmp/sway-ipc.sock")
149
+
# Test XWayland (foot does not support X):
150
+
swaymsg("exec WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY= alacritty")
151
+
wait_for_window("alice@machine")
152
+
machine.send_chars("test-x11\n")
153
+
machine.wait_for_file("/tmp/test-x11-exit-ok")
154
+
print(machine.succeed("cat /tmp/test-x11.out"))
155
+
machine.copy_from_vm("/tmp/test-x11.out")
156
+
machine.screenshot("alacritty_glinfo")
157
+
machine.succeed("pkill alacritty")
159
+
# Start a terminal (foot) on workspace 3:
160
+
machine.send_key("alt-3")
162
+
machine.send_key("alt-ret")
163
+
wait_for_window("alice@machine")
164
+
machine.send_chars("test-wayland\n")
165
+
machine.wait_for_file("/tmp/test-wayland-exit-ok")
166
+
print(machine.succeed("cat /tmp/test-wayland.out"))
167
+
machine.copy_from_vm("/tmp/test-wayland.out")
168
+
machine.screenshot("foot_wayland_info")
169
+
machine.send_key("alt-shift-q")
170
+
machine.wait_until_fails("pgrep foot")
172
+
# Test gpg-agent starting pinentry-gnome3 via D-Bus (tests if
173
+
# $WAYLAND_DISPLAY is correctly imported into the D-Bus user env):
174
+
swaymsg("exec mkdir -p ~/.gnupg")
175
+
swaymsg("exec cp /etc/gpg-agent.conf ~/.gnupg")
177
+
swaymsg("exec DISPLAY=INVALID gpg --no-tty --yes --quick-generate-key test", succeed=False)
178
+
machine.wait_until_succeeds("pgrep --exact gpg")
179
+
wait_for_window("gpg")
180
+
machine.succeed("pgrep --exact gpg")
181
+
machine.screenshot("gpg_pinentry")
182
+
machine.send_key("alt-shift-q")
183
+
machine.wait_until_fails("pgrep --exact gpg")
187
+
return [node['rect']['height'] for node in walk(swaymsg(type="get_tree")) if node['focused']][0]
189
+
before = get_height()
190
+
machine.send_key("alt-shift-e")
191
+
retry(lambda _: get_height() < before)
192
+
machine.screenshot("sway_exit")
194
+
swaymsg("exec swaylock")
195
+
machine.wait_until_succeeds("pgrep -x swaylock")
197
+
machine.send_chars("${nodes.machine.config.users.users.alice.password}")
198
+
machine.send_key("ret")
199
+
machine.wait_until_fails("pgrep -x swaylock")
201
+
# Exit Sway and verify process exit status 0:
202
+
swaymsg("exit", succeed=False)
203
+
machine.wait_until_fails("pgrep -x sway")
204
+
machine.wait_for_file("/tmp/sway-exit-ok")