mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-08-01 04:31:57 -07:00
Core: Add a test suite (#9297)
Adds a test suite for testing hyprland's features with a runtime tester --------- Co-authored-by: Mihai Fufezan <mihai@fufexan.net>
This commit is contained in:
58
nix/hyprtester.nix
Normal file
58
nix/hyprtester.nix
Normal file
@@ -0,0 +1,58 @@
|
||||
{
|
||||
lib,
|
||||
stdenv,
|
||||
stdenvAdapters,
|
||||
cmake,
|
||||
pkg-config,
|
||||
hyprland,
|
||||
hyprwayland-scanner,
|
||||
version ? "git",
|
||||
}: let
|
||||
inherit (lib.lists) flatten foldl';
|
||||
inherit (lib.sources) cleanSourceWith cleanSource;
|
||||
inherit (lib.strings) hasSuffix;
|
||||
|
||||
adapters = flatten [
|
||||
stdenvAdapters.useMoldLinker
|
||||
stdenvAdapters.keepDebugInfo
|
||||
];
|
||||
|
||||
customStdenv = foldl' (acc: adapter: adapter acc) stdenv adapters;
|
||||
in
|
||||
customStdenv.mkDerivation (finalAttrs: {
|
||||
pname = "hyprtester";
|
||||
inherit version;
|
||||
|
||||
src = cleanSourceWith {
|
||||
filter = name: _type: let
|
||||
baseName = baseNameOf (toString name);
|
||||
in
|
||||
! (hasSuffix ".nix" baseName);
|
||||
src = cleanSource ../.;
|
||||
};
|
||||
|
||||
nativeBuildInputs = [
|
||||
cmake
|
||||
pkg-config
|
||||
hyprwayland-scanner
|
||||
];
|
||||
|
||||
buildInputs = hyprland.buildInputs;
|
||||
|
||||
preConfigure = ''
|
||||
cmake -S . -B .
|
||||
cmake --build . --target generate-protocol-headers -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
||||
|
||||
cd hyprtester
|
||||
'';
|
||||
|
||||
cmakeBuildType = "Debug";
|
||||
|
||||
meta = {
|
||||
homepage = "https://github.com/hyprwm/Hyprland";
|
||||
description = "Hyprland testing framework";
|
||||
license = lib.licenses.bsd3;
|
||||
platforms = hyprland.meta.platforms;
|
||||
mainProgram = "hyprtester";
|
||||
};
|
||||
})
|
@@ -8,7 +8,7 @@
|
||||
(builtins.substring 4 2 longDate)
|
||||
(builtins.substring 6 2 longDate)
|
||||
]);
|
||||
version = lib.removeSuffix "\n" (builtins.readFile ../VERSION);
|
||||
ver = lib.removeSuffix "\n" (builtins.readFile ../VERSION);
|
||||
in {
|
||||
# Contains what a user is most likely to care about:
|
||||
# Hyprland itself, XDPH and the Share Picker.
|
||||
@@ -33,13 +33,13 @@ in {
|
||||
# Hyprland packages themselves
|
||||
(final: _prev: let
|
||||
date = mkDate (self.lastModifiedDate or "19700101");
|
||||
version = "${ver}+date=${date}_${self.shortRev or "dirty"}";
|
||||
in {
|
||||
hyprland = final.callPackage ./default.nix {
|
||||
stdenv = final.gcc15Stdenv;
|
||||
version = "${version}+date=${date}_${self.shortRev or "dirty"}";
|
||||
commit = self.rev or "";
|
||||
revCount = self.sourceInfo.revCount or "";
|
||||
inherit date;
|
||||
inherit date version;
|
||||
};
|
||||
hyprland-unwrapped = final.hyprland.override {wrapRuntimeDeps = false;};
|
||||
|
||||
@@ -50,6 +50,10 @@ in {
|
||||
debug = true;
|
||||
};
|
||||
|
||||
hyprtester = final.callPackage ./hyprtester.nix {
|
||||
inherit version;
|
||||
};
|
||||
|
||||
# deprecated packages
|
||||
hyprland-legacy-renderer =
|
||||
builtins.trace ''
|
||||
@@ -74,6 +78,18 @@ in {
|
||||
})
|
||||
];
|
||||
|
||||
# Debug
|
||||
hyprland-debug = lib.composeManyExtensions [
|
||||
# Dependencies
|
||||
self.overlays.hyprland-packages
|
||||
|
||||
(final: prev: {
|
||||
aquamarine = prev.aquamarine.override {debug = true;};
|
||||
hyprutils = prev.hyprutils.override {debug = true;};
|
||||
hyprland-debug = prev.hyprland.override {debug = true;};
|
||||
})
|
||||
];
|
||||
|
||||
# Packages for extra software recommended for usage with Hyprland,
|
||||
# including forked or patched packages for compatibility.
|
||||
hyprland-extras = lib.composeManyExtensions [
|
||||
|
86
nix/tests/default.nix
Normal file
86
nix/tests/default.nix
Normal file
@@ -0,0 +1,86 @@
|
||||
inputs: pkgs: let
|
||||
flake = inputs.self.packages.${pkgs.stdenv.hostPlatform.system};
|
||||
hyprland = flake.hyprland;
|
||||
in {
|
||||
tests = pkgs.testers.runNixOSTest {
|
||||
name = "hyprland-tests";
|
||||
|
||||
nodes.machine = {pkgs, ...}: {
|
||||
environment.systemPackages = with pkgs; [
|
||||
flake.hyprtester
|
||||
|
||||
# Programs needed for tests
|
||||
kitty
|
||||
xorg.xeyes
|
||||
];
|
||||
|
||||
# Enabled by default for some reason
|
||||
services.speechd.enable = false;
|
||||
|
||||
environment.variables = {
|
||||
"AQ_TRACE" = "1";
|
||||
"HYPRLAND_TRACE" = "1";
|
||||
"XDG_RUNTIME_DIR" = "/tmp";
|
||||
"XDG_CACHE_HOME" = "/tmp";
|
||||
};
|
||||
|
||||
programs.hyprland = {
|
||||
enable = true;
|
||||
package = hyprland;
|
||||
# We don't need portals in this test, so we don't set portalPackage
|
||||
};
|
||||
|
||||
# Test configuration
|
||||
environment.etc."test.conf".source = "${flake.hyprtester}/share/hypr/test.conf";
|
||||
|
||||
# Disable portals
|
||||
xdg.portal.enable = pkgs.lib.mkForce false;
|
||||
|
||||
# Autologin root into tty
|
||||
services.getty.autologinUser = "alice";
|
||||
|
||||
system.stateVersion = "24.11";
|
||||
|
||||
users.users.alice = {
|
||||
isNormalUser = true;
|
||||
};
|
||||
|
||||
virtualisation = {
|
||||
cores = 4;
|
||||
# Might crash with less
|
||||
memorySize = 8192;
|
||||
resolution = {
|
||||
x = 1920;
|
||||
y = 1080;
|
||||
};
|
||||
|
||||
# Doesn't seem to do much, thought it would fix XWayland crashing
|
||||
qemu.options = ["-vga none -device virtio-gpu-pci"];
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
# Wait for tty to be up
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
|
||||
# Run hyprtester testing framework/suite
|
||||
print("Running hyprtester")
|
||||
exit_status, _out = machine.execute("su - alice -c 'hyprtester -b ${hyprland}/bin/Hyprland -c /etc/test.conf -p ${flake.hyprtester}/lib/hyprtestplugin.so 2>&1 | tee /tmp/testerlog; exit ''${PIPESTATUS[0]}'")
|
||||
print(f"Hyprtester exited with {exit_status}")
|
||||
|
||||
# Copy logs to host
|
||||
machine.execute('cp "$(find /tmp/hypr -name *.log | head -1)" /tmp/hyprlog')
|
||||
machine.execute(f'echo {exit_status} > /tmp/exit_status')
|
||||
machine.copy_from_vm("/tmp/testerlog")
|
||||
machine.copy_from_vm("/tmp/hyprlog")
|
||||
machine.copy_from_vm("/tmp/exit_status")
|
||||
|
||||
# Print logs for visibility in CI
|
||||
_, out = machine.execute("cat /tmp/testerlog")
|
||||
print(f"Hyprtester log:\n{out}")
|
||||
|
||||
# Finally - shutdown
|
||||
machine.shutdown()
|
||||
'';
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user