11inputs : pkgs : let
2+ inherit ( pkgs ) lib ;
3+ inherit ( lib . lists ) flatten ;
24 flake = inputs . self . packages . ${ pkgs . stdenv . hostPlatform . system } ;
35
46 env = {
@@ -9,19 +11,22 @@ inputs: pkgs: let
911 "XDG_CACHE_HOME" = "/tmp" ;
1012 } ;
1113
12- envAddToSystemdRun = pkgs . lib . concatStringsSep " " (
13- pkgs . lib . mapAttrsToList ( k : v : "--setenv ${ k } =${ v } " ) env
14+ envAddToSystemdRun = lib . concatStringsSep " " (
15+ lib . mapAttrsToList ( k : v : "--setenv ${ k } =${ v } " ) env
1416 ) ;
17+
18+ APITRACE_RECORD = false ;
19+ APITRACE_RECORD_PY = if APITRACE_RECORD then "True" else "False" ;
1520in {
1621 tests = pkgs . testers . runNixOSTest {
1722 name = "hyprlock-tests" ;
1823
1924 nodes . machine = { pkgs , ...} : {
20- environment . systemPackages = with pkgs ; [
25+ environment . systemPackages = with pkgs ; flatten [
2126 # Programs needed for tests
2227 coreutils # date command
2328 procps # pidof
24- libinput
29+ ( lib . optional APITRACE_RECORD apitrace )
2530 ] ;
2631
2732 # Enabled by default for some reason
3641
3742 programs . hyprlock = {
3843 enable = true ;
39- package = flake . hyprlock-debug ;
44+ package = flake . hyprlock ;
4045 } ;
4146
4247 networking . dhcpcd . enable = false ;
4348
4449 # Disable portals
45- xdg . portal . enable = pkgs . lib . mkForce false ;
50+ xdg . portal . enable = lib . mkForce false ;
4651
4752 # Autologin root into tty
4853 services . getty . autologinUser = "alice" ;
4954
5055 system . stateVersion = "24.11" ;
5156
57+ environment . etc . "hyprlock/assets" . source = "${ flake . hyprlock-test-meta } /share/hypr/assets/" ;
58+
5259 users . users . alice = {
5360 isNormalUser = true ;
5461 # password: abcdefghijklmnopqrstuvwxyz1234567890-=!@#$%^&*()_+[]{};\':\\"]\\|,./<>?`~äöüćńóśź
7380 from pathlib import Path
7481 # Wait for tty to be up
7582 machine.wait_for_unit("multi-user.target")
76- # Run hyprtester testing framework/suite
83+ # Startup Hyprland as the test compositor for hyprlock
7784 print("Running Hyprland")
78- _, __ = machine.execute("systemd-run -q -u hyprland --uid $(id -u alice) -p RuntimeMaxSec=60 ${ envAddToSystemdRun } ${ pkgs . hyprland } /bin/Hyprland -c ${ flake . lock_tester } /share/hypr/hyprland.conf", timeout=60)
79-
85+ _, __ = machine.execute("systemd-run -q -u hyprland --uid $(id -u alice) -p RuntimeMaxSec=60 ${ envAddToSystemdRun } --setenv PATH=$PATH ${ pkgs . hyprland } /bin/Hyprland -c ${ flake . hyprlock-test-meta } /share/hypr/hyprland.conf")
8086 _, __ = machine.execute("sleep 2")
81- _, out = machine.execute("hyprctl --instance 0 systeminfo")
82- print(out)
83- for hyprlock_config in Path("${ flake . lock_tester } /share/hypr/configs/").iterdir():
87+ _, systeminfo = machine.execute("hyprctl --instance 0 systeminfo")
88+ print(systeminfo)
89+
90+ for hyprlock_config in Path("${ flake . hyprlock-test-meta } /share/hypr/configs/").iterdir():
8491 print(f"Testing configuration file {hyprlock_config}")
85- log_file_path = "/tmp/lock_tester_" + hyprlock_config.stem
86- print(log_file_path)
87- cmd = f"${ pkgs . lib . getExe flake . lock_tester } --binary ${ pkgs . lib . getExe flake . hyprlock-debug } --config {str(hyprlock_config)} 2>&1 >>{log_file_path}; echo $? > /tmp/exit_code"
88- _, out = machine.execute(f"hyprctl --instance 0 dispatch exec '{cmd}'")
89- print(out)
90- machine.wait_for_file("/tmp/.session-locked", timeout=30)
91- _, tester_pid = machine.execute("pidof lock_tester")
92- print(f"Lock tester pid {tester_pid}")
93- machine.send_chars("asdf\n") # wrong password
94- _, __ = machine.execute("sleep 3")
92+ log_file_path = "/tmp/hyprlock_test_" + hyprlock_config.stem
93+
94+ hyprlock_cmd = f"hyprlock --config {str(hyprlock_config)} -v 2>&1 >{log_file_path}; echo $? > /tmp/exit_status"
95+ if ${ APITRACE_RECORD_PY } :
96+ hyprlock_cmd = f"${ lib . getExe pkgs . apitrace } trace --output {log_file_path}.trace --api egl {hyprlock_cmd}"
97+ _, __ = machine.execute(f"hyprctl --instance 0 dispatch exec '{hyprlock_cmd}'")
98+
99+ wait_for_lock_exit_status, out = machine.execute("WAYLAND_DISPLAY=wayland-1 ${ flake . hyprlock-test-meta } /bin/wait-for-lock")
100+ print(f"Wait for lock exit code: {wait_for_lock_exit_status}")
101+ if wait_for_lock_exit_status != 0:
102+ break
103+
104+ _, hyprlock_pid = machine.execute("pidof hyprlock")
105+ print(f"Hyprlock pid {hyprlock_pid}")
106+
107+ # wrong password
108+ machine.send_chars("asdf\n")
109+
110+ _, __ = machine.execute("sleep 3") # default fail_timeout is 2 seconds
111+
112+ # correct password
95113 machine.send_chars("abcdefghijklmnopqrstuvwxyz1234567890-=!@#$%^&*()_+[]{};':\"]\\|,./<>?`~")
96114 machine.send_key("alt_r-a")
97115 machine.send_key("alt_r-o")
@@ -107,24 +125,34 @@ in {
107125 machine.send_key("alt_r-apostrophe")
108126 machine.send_key("z")
109127 machine.send_chars("\n")
110- _, __ = machine.execute(f"waitpid {tester_pid}")
111- _, exit_status = machine.execute("cat /tmp/exit_code")
112- print(f"Lock tester exited with {exit_status}")
128+
129+ _, __ = machine.execute(f"waitpid {hyprlock_pid}")
130+ _, exit_status = machine.execute("cat /tmp/exit_status")
131+ print(f"Hyprlock exited with {exit_status}")
132+
113133 machine.copy_from_vm(log_file_path)
134+ if ${ APITRACE_RECORD_PY } :
135+ machine.copy_from_vm(log_file_path + ".trace")
136+
137+ _, out = machine.execute(f"cat {log_file_path}")
138+ print(f"Hyprlock log:\n{out}")
114139 _, out = machine.execute(f"cat {log_file_path}")
115- print(f"Lock tester log:\n{out}")
116140
117- #machine.wait_for_file("/tmp/exit_status", timeout=30)
118- machine.wait_for_unit("hyprland", timeout=30)
141+ if not exit_status or int(exit_status) != 0:
142+ break
143+
144+
145+ _, out = machine.execute("hyprctl --instance 0 dispatch exit")
146+ machine.wait_for_unit("hyprland", timeout=10)
119147
120- # Copy logs to host
121- #machine.execute('cp "$(find /tmp/hypr -name *.log | head -1)" /tmp/hyprlog')
122- #machine.copy_from_vm("/tmp/hyprlog")
123- #machine.copy_from_vm("/tmp/exit_status")
148+ _, exit_status = machine.execute("cat /tmp/exit_status")
149+ # For the github runner, just to make sure wen don't accidentally succeed
150+ if not exit_status.strip():
151+ _, __ = machine.execute("echo 99 >/tmp/exit_status")
152+ exit_status = "99"
124153
125- # Print logs for visibility in CI
126- #_, out = machine.execute("cat /tmp/hyprlog")
127- #print(f"Hyprland logs:\n{out}")
154+ machine.copy_from_vm("/tmp/exit_status")
155+ assert int(exit_status) == 0, f"hyprlock exit code != 0 (exited with {exit_status})"
128156
129157 # Finally - shutdown
130158 machine.shutdown()
0 commit comments