# checks..vm-hyprland -- the real one. Same machine as vm-basic, but no # `captureCommand` override, so the server captures the actual headless # compositor through grim. # # This is the check expected to be flaky, so it is deliberately impatient: every # wait has a bounded timeout, no assertion is retried, and any failure dumps the # compositor's log and `hyprctl monitors` before it propagates. A flake you can # read is worth more than a flake that eventually goes green. # # There is exactly one waiting loop, and it waits for the compositor to finish # starting (see "the session settles ..." below) rather than for an assertion to # pass. Every assertion after it runs once. { testers, hhstream, testTools, hhsModule, hyprland, grim, width ? 1280, height ? 720, fps ? 30, socketPath ? "/run/hyprland-headless-stream/stream.sock", }: testers.runNixOSTest { name = "hhstream-vm-hyprland"; globalTimeout = 1800; nodes.machine = { # gpu-session.nix is what makes the compositor able to start at all; see # that file for the two pieces of hardware a bare test machine is missing # (the third thing it used to carry, SEATD_VTBOUND=0, is in nix/module.nix # now -- it is a property of the session, not of the test machine). imports = [ hhsModule ./lib/gpu-session.nix ]; services.hyprland-headless-stream = { enable = true; package = hhstream; hyprlandPackage = hyprland; inherit socketPath; frameRate = fps; format = "png"; # No `name`, so the module's wildcard rule applies to whatever connector # the virtio GPU gives this guest. The check must not know that name: on # QEMU it is `Virtual-1`, on a real host it is whatever the DRM backend # reports, and a rule naming a connector that does not exist is silently # ignored rather than an error. outputs = [ { inherit width height; refresh = fps; } ]; # No captureCommand: the module's default (grim) is the point of this check. # Put a picture on the screen, so that `--reject-blank` below is an # assertion and not a formality. # # The session the module configures by default is a flat field: no logo, # no splash, no wallpaper, `background_color = 0x000000`. Measured in this # guest, grim captures that as 1280x720 RGBA in which every byte is zero, # encoding to *exactly* 3653 bytes -- which is `blank_png_size()` in # tests/assert_stream.py to the byte. A flat field is by construction # indistinguishable from a zero-filled buffer, so against the default # config `--reject-blank` cannot pass, and any run in which it appears to # is reading something transient (the startup notification overlay lives # for about fifteen seconds and is 9739 bytes). # # Turning Hyprland's own wallpaper back on costs no new package and gives # the compositor real content to composite: measured 85267 bytes, all # 921600 pixels non-zero, byte-identical at +15s, +30s and +60s. That is # what makes "the frame is not blank" mean "grim captured composited # pixels". extraConfig = '' misc:force_default_wallpaper = 1 misc:disable_hyprland_logo = false misc:disable_splash_rendering = false ''; }; # hyprctl and grim are here for the diagnostics dump and for the manual # cross-check below, not for the code path under test. environment.systemPackages = [ testTools hhstream hyprland grim ]; # The compositor needs more room than the fake capture did, and its software # renderer wants a CPU. The virtio GPU from gpu-session.nix is there for its # render node and its DRM backend, not for acceleration: rendering is still # Mesa's software path. virtualisation = { memorySize = 2048; cores = 2; diskSize = 4096; graphics = false; }; }; testScript = '' import json SOCKET = "${socketPath}" WIDTH, HEIGHT = ${toString width}, ${toString height} # The module pins XDG_RUNTIME_DIR; the instance signature under it is the # only part that is not known ahead of time. Root may connect to the # compositor's IPC socket even though it belongs to `hhstream`. HYPRCTL_MONITORS = ( "set -eu; " "sig=$(ls -1 /run/hyprland-headless-stream/hypr | head -n1); " "XDG_RUNTIME_DIR=/run/hyprland-headless-stream" " HYPRLAND_INSTANCE_SIGNATURE=$sig hyprctl -j monitors" ) def dump(label): print(f"########## diagnostics: {label} ##########") status, out = machine.execute("hhs-hyprland-diagnostics", timeout=120) print(out) print(f"########## end diagnostics (exit {status}) ##########") start_all() with subtest("the compositor unit comes up"): try: machine.wait_for_unit("hyprland-headless.service", timeout=180) except Exception: dump("hyprland-headless.service did not start") raise with subtest("the compositor reports a monitor at the configured mode"): try: # Proves the compositor is really driving a WIDTHxHEIGHT output # before we blame the capture for a wrong-sized frame. Asked over # hyprctl's JSON so the assertion is on the mode, never on a # monitor name: the name belongs to the host's connector. monitors = json.loads(machine.succeed(HYPRCTL_MONITORS, timeout=120)) print(json.dumps(monitors, indent=2, sort_keys=True)) assert monitors, "hyprctl reported no monitors at all" print( "monitors: " + ", ".join( f"{m['name']} {m['width']}x{m['height']}@{m.get('refreshRate')}" for m in monitors ) ) assert any( m["width"] == WIDTH and m["height"] == HEIGHT for m in monitors ), ( f"no monitor is at the configured {WIDTH}x{HEIGHT}; the wildcard " "monitor rule did not take" ) except Exception: dump("compositor output not as configured") raise with subtest("the frame server unit comes up and publishes the socket"): try: machine.wait_for_unit("hyprland-headless-stream.service", timeout=180) machine.wait_for_file(SOCKET, timeout=120) except Exception: dump("frame server did not publish the socket") raise with subtest("grim can capture the session at all"): # Diagnostic, not an assertion: it separates "grim cannot see the # compositor" from "the server is wrong", which are the two failures # that look identical from the socket. The session's XDG_RUNTIME_DIR is # the module's private one, not /run/user/, and the socket name is # whatever the compositor bound -- so discover both, as the unit does. # The grim path is the store one: a transient systemd unit gets a # minimal PATH, not the guest's environment.systemPackages. status, out = machine.execute( "systemd-run --pipe --wait --uid=hhstream" " --setenv=XDG_RUNTIME_DIR=/run/hyprland-headless-stream" " --setenv=WAYLAND_DISPLAY=$(cd /run/hyprland-headless-stream" " && ls -1 wayland-* | grep -v '\.lock$' | head -n1)" " sh -c '${grim}/bin/grim -t png - > /tmp/direct.png' 2>&1", timeout=120, ) print(f"direct grim exit {status}: {out}") print(machine.execute("stat -c 'direct.png: %s bytes' /tmp/direct.png")[1]) with subtest("the session settles into a frame with a picture in it"): # A bounded wait for the *end of startup*, in the same spirit as # wait_for_unit -- not a retry until something goes green. The Wayland # socket is bound before the wallpaper texture has been uploaded and # composited, so the very first frames off the socket can still be the # empty field. Everything below this point is a hard assertion, made # once, on a session that has finished coming up. try: machine.wait_until_succeeds( f"hhs-assert-stream --socket {SOCKET} --frames 1 --timeout 30" " --require-png --reject-blank", timeout=120, ) except Exception: dump("the session never rendered anything but a blank field") raise with subtest("a frame off the socket is a real PNG of the configured size"): try: print( machine.succeed( f"hhs-assert-stream --socket {SOCKET} --frames 1 --timeout 60" f" --expect-width {WIDTH} --expect-height {HEIGHT}" " --expect-format image/png --require-png --reject-blank", timeout=180, ) ) except Exception: dump("frame off the socket failed the PNG assertions") raise with subtest("the stream keeps producing frames"): try: print( machine.succeed( f"hhs-assert-stream --socket {SOCKET} --frames 3 --timeout 60" f" --expect-width {WIDTH} --expect-height {HEIGHT}" " --require-png --reject-blank", timeout=240, ) ) machine.succeed("systemctl is-active hyprland-headless-stream.service") except Exception: dump("the stream stopped after the first frame") raise ''; }