1 import ./make-test-python.nix ({ pkgs, lib, ... }: {
4 maintainers = with lib.maintainers; [ primeos synthetica ];
7 # testScriptWithTypes:49: error: Cannot call function of unknown type
8 # (machine.succeed if succeed else machine.execute)(
10 # Found 1 error in 1 file (checked 1 source file)
13 nodes.machine = { config, ... }: {
14 # Automatically login on tty1 as a normal user:
15 imports = [ ./common/user-account.nix ];
16 services.getty.autologinUser = "alice";
19 # For glinfo and wayland-info:
20 systemPackages = with pkgs; [ mesa-demos wayland-utils alacritty ];
21 # Use a fixed SWAYSOCK path (for swaymsg):
23 "SWAYSOCK" = "/tmp/sway-ipc.sock";
24 # TODO: Investigate if we can get hardware acceleration to work (via
25 # virtio-gpu and Virgil). We currently have to use the Pixman software
26 # renderer since the GLES2 renderer doesn't work inside the VM (even
27 # with WLR_RENDERER_ALLOW_SOFTWARE):
28 # "WLR_RENDERER_ALLOW_SOFTWARE" = "1";
29 "WLR_RENDERER" = "pixman";
33 test-x11 = "glinfo | tee /tmp/test-x11.out && touch /tmp/test-x11-exit-ok";
34 test-wayland = "wayland-info | tee /tmp/test-wayland.out && touch /tmp/test-wayland-exit-ok";
38 etc."xdg/foot/foot.ini".text = lib.generators.toINI { } {
40 font = "inconsolata:size=14";
43 foreground = "000000";
44 background = "ffffff";
45 regular2 = foreground;
49 etc."gpg-agent.conf".text = ''
50 pinentry-timeout 86400
54 fonts.packages = [ pkgs.inconsolata ];
56 # Automatically configure and start Sway when logging in on tty1:
57 programs.bash.loginShellInit = ''
58 if [ "$(tty)" = "/dev/tty1" ]; then
61 mkdir -p ~/.config/sway
62 sed s/Mod4/Mod1/ /etc/sway/config > ~/.config/sway/config
65 sway && touch /tmp/sway-exit-ok
69 programs.sway.enable = true;
71 # To test pinentry via gpg-agent:
72 programs.gnupg.agent.enable = true;
74 # Need to switch to a different GPU driver than the default one (-vga std) so that Sway can launch:
75 virtualisation.qemu.options = [ "-vga none -device virtio-gpu-pci" ];
78 testScript = { nodes, ... }: ''
83 NODE_GROUPS = ["nodes", "floating_nodes"]
86 def swaymsg(command: str = "", succeed=True, type="command"):
87 assert command != "" or type != "command", "Must specify command or type"
88 shell = q(f"swaymsg -t {q(type)} -- {q(command)}")
90 f"sending swaymsg {shell!r}" + " (allowed to fail)" * (not succeed)
92 ret = (machine.succeed if succeed else machine.execute)(
93 f"su - alice -c {shell}"
96 # execute also returns a status code, but disregard.
100 if not succeed and not ret:
103 parsed = json.loads(ret)
109 for group in NODE_GROUPS:
110 for node in tree.get(group, []):
111 yield from walk(node)
114 def wait_for_window(pattern):
115 def func(last_chance):
116 nodes = (node["name"] for node in walk(swaymsg(type="get_tree")))
120 machine.log(f"Last call! Current list of windows: {nodes}")
122 return any(pattern in name for name in nodes)
127 machine.wait_for_unit("multi-user.target")
129 # To check the version:
130 print(machine.succeed("sway --version"))
132 # Wait for Sway to complete startup:
133 machine.wait_for_file("/run/user/1000/wayland-1")
134 machine.wait_for_file("/tmp/sway-ipc.sock")
136 # Test XWayland (foot does not support X):
137 swaymsg("exec WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY= alacritty")
138 wait_for_window("alice@machine")
139 machine.send_chars("test-x11\n")
140 machine.wait_for_file("/tmp/test-x11-exit-ok")
141 print(machine.succeed("cat /tmp/test-x11.out"))
142 machine.copy_from_vm("/tmp/test-x11.out")
143 machine.screenshot("alacritty_glinfo")
144 machine.succeed("pkill alacritty")
146 # Start a terminal (foot) on workspace 3:
147 machine.send_key("alt-3")
149 machine.send_key("alt-ret")
150 wait_for_window("alice@machine")
151 machine.send_chars("test-wayland\n")
152 machine.wait_for_file("/tmp/test-wayland-exit-ok")
153 print(machine.succeed("cat /tmp/test-wayland.out"))
154 machine.copy_from_vm("/tmp/test-wayland.out")
155 machine.screenshot("foot_wayland_info")
156 machine.send_key("alt-shift-q")
157 machine.wait_until_fails("pgrep foot")
159 # Test gpg-agent starting pinentry-gnome3 via D-Bus (tests if
160 # $WAYLAND_DISPLAY is correctly imported into the D-Bus user env):
161 swaymsg("exec mkdir -p ~/.gnupg")
162 swaymsg("exec cp /etc/gpg-agent.conf ~/.gnupg")
164 swaymsg("exec DISPLAY=INVALID gpg --no-tty --yes --quick-generate-key test", succeed=False)
165 machine.wait_until_succeeds("pgrep --exact gpg")
166 wait_for_window("gpg")
167 machine.succeed("pgrep --exact gpg")
168 machine.screenshot("gpg_pinentry")
169 machine.send_key("alt-shift-q")
170 machine.wait_until_fails("pgrep --exact gpg")
174 return [node['rect']['height'] for node in walk(swaymsg(type="get_tree")) if node['focused']][0]
176 before = get_height()
177 machine.send_key("alt-shift-e")
178 retry(lambda _: get_height() < before)
179 machine.screenshot("sway_exit")
181 swaymsg("exec swaylock")
182 machine.wait_until_succeeds("pgrep -x swaylock")
184 machine.send_chars("${nodes.machine.config.users.users.alice.password}")
185 machine.send_key("ret")
186 machine.wait_until_fails("pgrep -x swaylock")
188 # Exit Sway and verify process exit status 0:
189 swaymsg("exit", succeed=False)
190 machine.wait_until_fails("pgrep -x sway")
191 machine.wait_for_file("/tmp/sway-exit-ok")