From ae4e5957d85c0c5f5c645fe1d7460b883c8b2a7b Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Wed, 21 Jun 2023 14:58:10 +0200 Subject: [PATCH 1/2] nixosTests.sway: don't use ORC --- nixos/tests/sway.nix | 66 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/nixos/tests/sway.nix b/nixos/tests/sway.nix index 52e2c7c99ec..bd7dfe9caa9 100644 --- a/nixos/tests/sway.nix +++ b/nixos/tests/sway.nix @@ -71,16 +71,53 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: { virtualisation.qemu.options = [ "-vga none -device virtio-gpu-pci" ]; }; - enableOCR = true; - testScript = { nodes, ... }: '' import shlex + import json - def swaymsg(command: str, succeed=True): - with machine.nested(f"sending swaymsg {command!r}" + " (allowed to fail)" * (not succeed)): - (machine.succeed if succeed else machine.execute)( - f"su - alice -c {shlex.quote('swaymsg -- ' + command)}" - ) + q = shlex.quote + NODE_GROUPS = ["nodes", "floating_nodes"] + + + def swaymsg(command: str = "", succeed=True, type="command"): + assert command != "" or type != "command", "Must specify command or type" + shell = q(f"swaymsg -t {q(type)} -- {q(command)}") + with machine.nested( + f"sending swaymsg {shell!r}" + " (allowed to fail)" * (not succeed) + ): + ret = (machine.succeed if succeed else machine.execute)( + f"su - alice -c {shell}" + ) + + # execute also returns a status code, but disregard. + if not succeed: + _, ret = ret + + if not succeed and not ret: + return None + + parsed = json.loads(ret) + return parsed + + + def walk(tree): + yield tree + for group in NODE_GROUPS: + for node in tree.get(group, []): + yield from walk(node) + + + def wait_for_window(pattern): + def func(last_chance): + nodes = (node["name"] for node in walk(swaymsg(type="get_tree"))) + + if last_chance: + nodes = list(nodes) + machine.log(f"Last call! Current list of windows: {nodes}") + + return any(pattern in name for name in nodes) + + retry(func) start_all() machine.wait_for_unit("multi-user.target") @@ -94,7 +131,7 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: { # Test XWayland (foot does not support X): swaymsg("exec WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY=invalid alacritty") - machine.wait_for_text("alice@machine") + wait_for_window("alice@machine") machine.send_chars("test-x11\n") machine.wait_for_file("/tmp/test-x11-exit-ok") print(machine.succeed("cat /tmp/test-x11.out")) @@ -106,7 +143,7 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: { machine.send_key("alt-3") machine.sleep(3) machine.send_key("alt-ret") - machine.wait_for_text("alice@machine") + wait_for_window("alice@machine") machine.send_chars("test-wayland\n") machine.wait_for_file("/tmp/test-wayland-exit-ok") print(machine.succeed("cat /tmp/test-wayland.out")) @@ -117,16 +154,21 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: { # Test gpg-agent starting pinentry-gnome3 via D-Bus (tests if # $WAYLAND_DISPLAY is correctly imported into the D-Bus user env): - swaymsg("exec gpg --no-tty --yes --quick-generate-key test") + swaymsg("exec DISPLAY=INVALID gpg --no-tty --yes --quick-generate-key test", succeed=False) machine.wait_until_succeeds("pgrep --exact gpg") - machine.wait_for_text("Passphrase") + wait_for_window("gpg") + machine.succeed("pgrep --exact gpg") machine.screenshot("gpg_pinentry") machine.send_key("alt-shift-q") machine.wait_until_fails("pgrep --exact gpg") # Test swaynag: + def get_height(): + return [node['rect']['height'] for node in walk(swaymsg(type="get_tree")) if node['focused']][0] + + before = get_height() machine.send_key("alt-shift-e") - machine.wait_for_text("You pressed the exit shortcut.") + retry(lambda _: get_height() < before) machine.screenshot("sway_exit") swaymsg("exec swaylock") From 5bd226bfd912a4029d3a29033b1b65f4ecd6caab Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Wed, 21 Jun 2023 16:08:00 +0200 Subject: [PATCH 2/2] nixosTests.sway: don't timeout gpg-agent --- nixos/tests/sway.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nixos/tests/sway.nix b/nixos/tests/sway.nix index bd7dfe9caa9..d95334c10e4 100644 --- a/nixos/tests/sway.nix +++ b/nixos/tests/sway.nix @@ -45,6 +45,10 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: { regular2 = foreground; }; }; + + etc."gpg-agent.conf".text = '' + pinentry-timeout 86400 + ''; }; fonts.fonts = [ pkgs.inconsolata ]; @@ -154,6 +158,9 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: { # Test gpg-agent starting pinentry-gnome3 via D-Bus (tests if # $WAYLAND_DISPLAY is correctly imported into the D-Bus user env): + swaymsg("exec mkdir -p ~/.gnupg") + swaymsg("exec cp /etc/gpg-agent.conf ~/.gnupg") + swaymsg("exec DISPLAY=INVALID gpg --no-tty --yes --quick-generate-key test", succeed=False) machine.wait_until_succeeds("pgrep --exact gpg") wait_for_window("gpg")