From 5659ea3d6ba5f1da0a09c9d8a656eaebf14b5b73 Mon Sep 17 00:00:00 2001 From: OPNA2608 Date: Mon, 10 Jun 2024 15:55:54 +0200 Subject: [PATCH] tests/miracle-wm: init --- nixos/tests/all-tests.nix | 1 + nixos/tests/miracle-wm.nix | 131 +++++++++++++++++++++++++ pkgs/by-name/mi/miracle-wm/package.nix | 2 + 3 files changed, 134 insertions(+) create mode 100644 nixos/tests/miracle-wm.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index b69b22c15b85..f6392be29437 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -579,6 +579,7 @@ in { minidlna = handleTest ./minidlna.nix {}; miniflux = handleTest ./miniflux.nix {}; minio = handleTest ./minio.nix {}; + miracle-wm = runTest ./miracle-wm.nix; miriway = handleTest ./miriway.nix {}; misc = handleTest ./misc.nix {}; mjolnir = handleTest ./matrix/mjolnir.nix {}; diff --git a/nixos/tests/miracle-wm.nix b/nixos/tests/miracle-wm.nix new file mode 100644 index 000000000000..2bb62222b22a --- /dev/null +++ b/nixos/tests/miracle-wm.nix @@ -0,0 +1,131 @@ +{ pkgs, lib, ... }: +{ + name = "miracle-wm"; + + meta = { + maintainers = with lib.maintainers; [ OPNA2608 ]; + }; + + nodes.machine = + { config, ... }: + { + imports = [ + ./common/auto.nix + ./common/user-account.nix + ]; + + # Seems to very rarely get interrupted by oom-killer + virtualisation.memorySize = 2047; + + test-support.displayManager.auto = { + enable = true; + user = "alice"; + }; + + services.xserver.enable = true; + services.displayManager.defaultSession = lib.mkForce "miracle-wm"; + + programs.wayland.miracle-wm.enable = true; + + # To ensure a specific config for the tests + systemd.tmpfiles.rules = + let + testConfig = (pkgs.formats.yaml { }).generate "miracle-wm.yaml" { + terminal = "env WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY= alacritty"; + startup_apps = [ + { + command = "foot"; + restart_on_death = false; + } + ]; + }; + in + [ + "d ${config.users.users.alice.home}/.config 0700 alice users - -" + "L ${config.users.users.alice.home}/.config/miracle-wm.yaml - - - - ${testConfig}" + ]; + + environment = { + shellAliases = { + test-wayland = "wayland-info | tee /tmp/test-wayland.out && touch /tmp/test-wayland-exit-ok"; + test-x11 = "glinfo | tee /tmp/test-x11.out && touch /tmp/test-x11-exit-ok"; + }; + + systemPackages = with pkgs; [ + mesa-demos + wayland-utils + foot + alacritty + ]; + + # To help with OCR + etc."xdg/foot/foot.ini".text = lib.generators.toINI { } { + main = { + font = "inconsolata:size=16"; + }; + colors = rec { + foreground = "000000"; + background = "ffffff"; + regular2 = foreground; + }; + }; + etc."xdg/alacritty/alacritty.yml".text = lib.generators.toYAML { } { + font = rec { + normal.family = "Inconsolata"; + bold.family = normal.family; + italic.family = normal.family; + bold_italic.family = normal.family; + size = 16; + }; + colors = rec { + primary = { + foreground = "0x000000"; + background = "0xffffff"; + }; + normal = { + green = primary.foreground; + }; + }; + }; + }; + + fonts.packages = [ pkgs.inconsolata ]; + }; + + enableOCR = true; + + testScript = + { ... }: + '' + start_all() + machine.wait_for_unit("multi-user.target") + + # Wait for Miriway to complete startup + machine.wait_for_file("/run/user/1000/wayland-0") + machine.succeed("pgrep miracle-wm") + machine.screenshot("miracle-wm_launched") + + # Test Wayland + with subtest("wayland client works"): + # We let miracle-wm start the first terminal, as we might get stuck if it's not ready to process the first keybind + # machine.send_key("ctrl-alt-t") + machine.wait_for_text("alice@machine") + machine.send_chars("test-wayland\n") + machine.wait_for_file("/tmp/test-wayland-exit-ok") + machine.copy_from_vm("/tmp/test-wayland.out") + machine.screenshot("foot_wayland_info") + machine.send_chars("exit\n") + machine.wait_until_fails("pgrep foot") + + # Test XWayland + with subtest("x11 client works"): + machine.send_key("meta_l-ret") + machine.wait_for_text("alice@machine") + machine.send_chars("test-x11\n") + machine.wait_for_file("/tmp/test-x11-exit-ok") + machine.copy_from_vm("/tmp/test-x11.out") + machine.screenshot("alacritty_glinfo") + machine.send_chars("exit\n") + machine.wait_until_fails("pgrep alacritty") + ''; +} diff --git a/pkgs/by-name/mi/miracle-wm/package.nix b/pkgs/by-name/mi/miracle-wm/package.nix index 22e937d43376..3b8f9964db31 100644 --- a/pkgs/by-name/mi/miracle-wm/package.nix +++ b/pkgs/by-name/mi/miracle-wm/package.nix @@ -3,6 +3,7 @@ lib, fetchFromGitHub, gitUpdater, + nixosTests, cmake, glib, gtest, @@ -71,6 +72,7 @@ stdenv.mkDerivation (finalAttrs: { passthru = { updateScript = gitUpdater { rev-prefix = "v"; }; providedSessions = [ "miracle-wm" ]; + tests.vm = nixosTests.miracle-wm; }; meta = with lib; {