summaryrefslogtreecommitdiffstats
path: root/nixos/tests/drawterm.nix
blob: e4da864bff7f47f28e2f68aec4e06bb9f5153b59 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{ system, pkgs }:
let
  tests = {
    xorg = {
      node =
        { pkgs, ... }:
        {
          imports = [
            ./common/user-account.nix
            ./common/x11.nix
          ];
          services.xserver.enable = true;
          services.xserver.displayManager.sessionCommands = ''
            ${pkgs.drawterm}/bin/drawterm -g 1024x768 &
          '';
          test-support.displayManager.auto.user = "alice";
        };
      systems = [
        "x86_64-linux"
        "aarch64-linux"
      ];
    };
    wayland = {
      node =
        { pkgs, ... }:
        {
          imports = [ ./common/wayland-cage.nix ];
          services.cage.program = "${pkgs.drawterm-wayland}/bin/drawterm";
        };
      systems = [ "x86_64-linux" ];
    };
  };

  mkTest =
    name: machine:
    import ./make-test-python.nix (
      { pkgs, ... }:
      {
        inherit name;

        nodes = {
          "${name}" = machine;
        };

        meta = with pkgs.lib.maintainers; {
          maintainers = [ moody ];
        };

        enableOCR = true;

        testScript = ''
          machine = ${name}

          @polling_condition
          def drawterm_running():
              machine.succeed("pgrep drawterm")

          # cage is a bit wonky here.
          # it seems to lag behind drawing
          # and somehow needs a single input character
          # in order to get the first prompt to show up.
          # This is not present in any other compositor
          # as far as I know, and after spending a couple
          # hours with the upstream source trying to deduce
          # how to perhaps fix it, I figured just polling is OK.
          @polling_condition
          def cpu_shown_up():
              machine.send_chars(".")
              machine.wait_for_text("cpu", 1)

          start_all()

          machine.wait_for_unit("graphical.target")
          drawterm_running.wait() # type: ignore[union-attr]
          cpu_shown_up.wait() # type: ignore[union-attr]
          machine.send_chars("cpu\n")
          machine.wait_for_text("auth")
          machine.send_chars("cpu\n")
          machine.wait_for_text("ending")
          machine.screenshot("out.png")
        '';

      }
    );
  mkTestOn =
    systems: name: machine:
    if pkgs.lib.elem system systems then mkTest name machine else { ... }: { };
in
builtins.mapAttrs (k: v: mkTestOn v.systems k v.node { inherit system; }) tests