| 1 |
inputs: pkgs: |
| 2 |
let |
| 3 |
flake = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}; |
| 4 |
hyprland = flake.hyprland-with-tests; |
| 5 |
in |
| 6 |
{ |
| 7 |
tests = pkgs.testers.runNixOSTest { |
| 8 |
name = "hyprland-tests"; |
| 9 |
|
| 10 |
nodes.machine = |
| 11 |
{ pkgs, ... }: |
| 12 |
{ |
| 13 |
environment.systemPackages = with pkgs; [ |
| 14 |
# Programs needed for tests |
| 15 |
jq |
| 16 |
kitty |
| 17 |
wl-clipboard |
| 18 |
xeyes |
| 19 |
]; |
| 20 |
|
| 21 |
# Enabled by default for some reason |
| 22 |
services.speechd.enable = false; |
| 23 |
|
| 24 |
environment.variables = { |
| 25 |
"AQ_TRACE" = "1"; |
| 26 |
"HYPRLAND_TRACE" = "1"; |
| 27 |
"XDG_RUNTIME_DIR" = "/tmp"; |
| 28 |
"XDG_CACHE_HOME" = "/tmp"; |
| 29 |
"KITTY_CONFIG_DIRECTORY" = "/etc/kitty"; |
| 30 |
}; |
| 31 |
|
| 32 |
environment.etc."kitty/kitty.conf".text = '' |
| 33 |
confirm_os_window_close 0 |
| 34 |
remember_window_size no |
| 35 |
initial_window_width 640 |
| 36 |
initial_window_height 400 |
| 37 |
''; |
| 38 |
|
| 39 |
programs.hyprland = { |
| 40 |
enable = true; |
| 41 |
package = hyprland; |
| 42 |
# We don't need portals in this test, so we don't set portalPackage |
| 43 |
}; |
| 44 |
|
| 45 |
# Test configuration |
| 46 |
environment.etc."test.lua".source = "${hyprland}/share/hypr/test.lua"; |
| 47 |
|
| 48 |
# Disable portals |
| 49 |
xdg.portal.enable = pkgs.lib.mkForce false; |
| 50 |
|
| 51 |
# Autologin root into tty |
| 52 |
services.getty.autologinUser = "alice"; |
| 53 |
|
| 54 |
system.stateVersion = "24.11"; |
| 55 |
|
| 56 |
users.users.alice = { |
| 57 |
isNormalUser = true; |
| 58 |
}; |
| 59 |
|
| 60 |
virtualisation = { |
| 61 |
cores = 4; |
| 62 |
# Might crash with less |
| 63 |
memorySize = 8192; |
| 64 |
resolution = { |
| 65 |
x = 1920; |
| 66 |
y = 1080; |
| 67 |
}; |
| 68 |
|
| 69 |
# Doesn't seem to do much, thought it would fix XWayland crashing |
| 70 |
qemu.options = [ "-vga none -device virtio-gpu-pci" ]; |
| 71 |
}; |
| 72 |
}; |
| 73 |
|
| 74 |
testScript = '' |
| 75 |
# Wait for tty to be up |
| 76 |
machine.wait_for_unit("multi-user.target") |
| 77 |
|
| 78 |
|
| 79 |
# Run gtests |
| 80 |
print("Running gtests") |
| 81 |
exit_status, _out = machine.execute("su - alice -c 'hyprland_gtests 2>&1 | tee /tmp/gtestslog; exit ''${PIPESTATUS[0]}'") |
| 82 |
machine.execute(f'echo {exit_status} > /tmp/exit_status_gtests') |
| 83 |
|
| 84 |
# Print logs for visibility in CI |
| 85 |
_, out = machine.execute("cat /tmp/gtestslog") |
| 86 |
print(f"gtests log:\n{out}") |
| 87 |
|
| 88 |
# Run hyprtester testing framework/suite |
| 89 |
print("Running hyprtester") |
| 90 |
exit_status, _out = machine.execute("su - alice -c 'hyprtester -b ${hyprland}/bin/Hyprland -c /etc/test.lua -p ${hyprland}/lib/hyprtestplugin.so 2>&1 | tee /tmp/testerlog; exit ''${PIPESTATUS[0]}'") |
| 91 |
print(f"Hyprtester exited with {exit_status}") |
| 92 |
|
| 93 |
# Print logs for visibility in CI |
| 94 |
_, out = machine.execute("cat /tmp/testerlog") |
| 95 |
print(f"Hyprtester log:\n{out}") |
| 96 |
|
| 97 |
# Copy logs to host |
| 98 |
machine.execute('cp "$(find /tmp/hypr -name *.log | head -1)" /tmp/hyprlog') |
| 99 |
machine.execute(f'echo {exit_status} > /tmp/exit_status') |
| 100 |
machine.copy_from_vm("/tmp/gtestslog") |
| 101 |
machine.copy_from_vm("/tmp/testerlog") |
| 102 |
machine.copy_from_vm("/tmp/hyprlog") |
| 103 |
machine.copy_from_vm("/tmp/exit_status") |
| 104 |
machine.copy_from_vm("/tmp/exit_status_gtests") |
| 105 |
|
| 106 |
# Finally - shutdown |
| 107 |
machine.shutdown() |
| 108 |
''; |
| 109 |
}; |
| 110 |
} |