about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Weiss <dev.primeos@gmail.com>2021-05-05 13:52:51 +0200
committerGitHub <noreply@github.com>2021-05-05 13:52:51 +0200
commitff5fdec09358341fd2cc4a2069f0defd6529451a (patch)
tree1ce3fa43ad81d849b91c04a40e0f2a93fd22f73c
parent25ab86aa3208e598065b5b95c7122d331a34e146 (diff)
parent957b7a476eeff2c331da2102953d00c6b30568ca (diff)
Merge pull request #121437 from primeos/nixos-tests-sway
nixos/tests/sway: init
-rw-r--r--nixos/tests/all-tests.nix1
-rw-r--r--nixos/tests/sway.nix92
-rw-r--r--pkgs/applications/window-managers/sway/default.nix3
3 files changed, 96 insertions, 0 deletions
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
index e39c525a604af..c34bf3623b616 100644
--- a/nixos/tests/all-tests.nix
+++ b/nixos/tests/all-tests.nix
@@ -387,6 +387,7 @@ in
   sssd-ldap = handleTestOn ["x86_64-linux"] ./sssd-ldap.nix {};
   strongswan-swanctl = handleTest ./strongswan-swanctl.nix {};
   sudo = handleTest ./sudo.nix {};
+  sway = handleTest ./sway.nix {};
   switchTest = handleTest ./switch-test.nix {};
   sympa = handleTest ./sympa.nix {};
   syncthing = handleTest ./syncthing.nix {};
diff --git a/nixos/tests/sway.nix b/nixos/tests/sway.nix
new file mode 100644
index 0000000000000..fad7f7dc4e68f
--- /dev/null
+++ b/nixos/tests/sway.nix
@@ -0,0 +1,92 @@
+import ./make-test-python.nix ({ pkgs, lib, ...} :
+
+{
+  name = "sway";
+  meta = {
+    maintainers = with lib.maintainers; [ primeos synthetica ];
+  };
+
+  machine = { config, ... }: {
+    # Automatically login on tty1 as a normal user:
+    imports = [ ./common/user-account.nix ];
+    services.getty.autologinUser = "alice";
+
+    environment = {
+      # For glinfo and wayland-info:
+      systemPackages = with pkgs; [ mesa-demos wayland-utils ];
+      # Use a fixed SWAYSOCK path (for swaymsg):
+      variables."SWAYSOCK" = "/tmp/sway-ipc.sock";
+      # For convenience:
+      shellAliases = {
+        test-x11 = "glinfo | head -n 3 | tee /tmp/test-x11.out && touch /tmp/test-x11-exit-ok";
+        test-wayland = "wayland-info | tee /tmp/test-wayland.out && touch /tmp/test-wayland-exit-ok";
+      };
+    };
+
+    # Automatically configure and start Sway when logging in on tty1:
+    programs.bash.loginShellInit = ''
+      if [ "$(tty)" = "/dev/tty1" ]; then
+        set -e
+
+        mkdir -p ~/.config/sway
+        sed s/Mod4/Mod1/ /etc/sway/config > ~/.config/sway/config
+
+        sway --validate
+        sway && touch /tmp/sway-exit-ok
+      fi
+    '';
+
+    programs.sway.enable = true;
+
+    virtualisation.memorySize = 1024;
+    # Need to switch to a different VGA card / GPU driver than the default one (std) so that Sway can launch:
+    virtualisation.qemu.options = [ "-vga virtio" ];
+  };
+
+  enableOCR = true;
+
+  testScript = { nodes, ... }: ''
+    start_all()
+    machine.wait_for_unit("multi-user.target")
+
+    # To check the version:
+    print(machine.succeed("sway --version"))
+
+    # Wait for Sway to complete startup:
+    machine.wait_for_file("/run/user/1000/wayland-1")
+    machine.wait_for_file("/tmp/sway-ipc.sock")
+
+    # Test XWayland:
+    machine.succeed(
+        "su - alice -c 'swaymsg exec WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY=invalid alacritty'"
+    )
+    machine.wait_for_text("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"))
+    machine.screenshot("alacritty_glinfo")
+    machine.succeed("pkill alacritty")
+
+    # Start a terminal (Alacritty) on workspace 3:
+    machine.send_key("alt-3")
+    machine.succeed(
+        "su - alice -c 'swaymsg exec WINIT_UNIX_BACKEND=wayland DISPLAY=invalid alacritty'"
+    )
+    machine.wait_for_text("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"))
+    machine.screenshot("alacritty_wayland_info")
+    machine.send_key("alt-shift-q")
+    machine.wait_until_fails("pgrep alacritty")
+
+    # Test swaynag:
+    machine.send_key("alt-shift-e")
+    machine.wait_for_text("You pressed the exit shortcut.")
+    machine.screenshot("sway_exit")
+
+    # Exit Sway and verify process exit status 0:
+    machine.succeed("su - alice -c 'swaymsg exit || true'")
+    machine.wait_for_file("/tmp/sway-exit-ok")
+  '';
+})
diff --git a/pkgs/applications/window-managers/sway/default.nix b/pkgs/applications/window-managers/sway/default.nix
index d8a1679bbed3e..2636d9100d574 100644
--- a/pkgs/applications/window-managers/sway/default.nix
+++ b/pkgs/applications/window-managers/sway/default.nix
@@ -3,6 +3,7 @@
 , libxkbcommon, pcre, json_c, dbus, libevdev
 , pango, cairo, libinput, libcap, pam, gdk-pixbuf, librsvg
 , wlroots, wayland-protocols, libdrm
+, nixosTests
 }:
 
 stdenv.mkDerivation rec {
@@ -41,6 +42,8 @@ stdenv.mkDerivation rec {
     "-Dsd-bus-provider=libsystemd"
   ];
 
+  passthru.tests.basic = nixosTests.sway;
+
   meta = with lib; {
     description = "An i3-compatible tiling Wayland compositor";
     longDescription = ''