about summary refs log tree commit diff
path: root/nixos/tests/tinywl.nix
blob: 411cdb1f64192db2953ac372a9dbce09e92ec5db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import ./make-test-python.nix ({ pkgs, lib, ... }:

  {
    name = "tinywl";
    meta = {
      maintainers = with lib.maintainers; [ primeos ];
    };

    nodes.machine = { config, ... }: {
      # Automatically login on tty1 as a normal user:
      imports = [ ./common/user-account.nix ];
      services.getty.autologinUser = "alice";
      security.polkit.enable = true;

      environment = {
        systemPackages = with pkgs; [ tinywl foot wayland-utils ];
      };

      # Automatically start TinyWL when logging in on tty1:
      programs.bash.loginShellInit = ''
        if [ "$(tty)" = "/dev/tty1" ]; then
          set -e
          test ! -e /tmp/tinywl.log # Only start tinywl once
          readonly TEST_CMD="wayland-info |& tee /tmp/test-wayland.out && touch /tmp/test-wayland-exit-ok; read"
          readonly FOOT_CMD="foot sh -c '$TEST_CMD'"
          tinywl -s "$FOOT_CMD" |& tee /tmp/tinywl.log
          touch /tmp/tinywl-exit-ok
        fi
      '';

      # Switch to a different GPU driver (default: -vga std), otherwise TinyWL segfaults:
      virtualisation.qemu.options = [ "-vga none -device virtio-gpu-pci" ];
    };

    testScript = { nodes, ... }: ''
      start_all()
      machine.wait_for_unit("multi-user.target")

      # Wait for complete startup:
      machine.wait_until_succeeds("pgrep tinywl")
      machine.wait_for_file("/run/user/1000/wayland-0")
      machine.wait_until_succeeds("pgrep foot")
      machine.wait_for_file("/tmp/test-wayland-exit-ok")

      # Make a screenshot and save the result:
      machine.screenshot("tinywl_foot")
      print(machine.succeed("cat /tmp/test-wayland.out"))
      machine.copy_from_vm("/tmp/test-wayland.out")

      # Terminate cleanly:
      machine.send_key("alt-esc")
      machine.wait_until_fails("pgrep foot")
      machine.wait_until_fails("pgrep tinywl")
      machine.wait_for_file("/tmp/tinywl-exit-ok")
      machine.copy_from_vm("/tmp/tinywl.log")
    '';
  })