summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorPatrick Hilhorst <git@hilhorst.be>2023-06-21 14:58:10 +0200
committerPatrick Hilhorst <git@hilhorst.be>2023-06-21 14:58:10 +0200
commitae4e5957d85c0c5f5c645fe1d7460b883c8b2a7b (patch)
tree65dc426fe2e59d6552a59e4dfc9eab093ccfc99c /nixos
parentc443448bad33a00d22049873ed1173e74cd3eae6 (diff)
downloadnixpkgs-ae4e5957d85c0c5f5c645fe1d7460b883c8b2a7b.tar
nixpkgs-ae4e5957d85c0c5f5c645fe1d7460b883c8b2a7b.tar.gz
nixpkgs-ae4e5957d85c0c5f5c645fe1d7460b883c8b2a7b.tar.bz2
nixpkgs-ae4e5957d85c0c5f5c645fe1d7460b883c8b2a7b.tar.lz
nixpkgs-ae4e5957d85c0c5f5c645fe1d7460b883c8b2a7b.tar.xz
nixpkgs-ae4e5957d85c0c5f5c645fe1d7460b883c8b2a7b.tar.zst
nixpkgs-ae4e5957d85c0c5f5c645fe1d7460b883c8b2a7b.zip
nixosTests.sway: don't use ORC
Diffstat (limited to 'nixos')
-rw-r--r--nixos/tests/sway.nix66
1 files 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
+
+    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 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)}"
-          )
+
+    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")