A machine running this module has a GPU. aquamarine's headless backend has no allocator of its own -- `CHeadlessBackend::drmFD()` returns -1 and `CBackend::start()` takes the allocator from the first backend with a drm fd -- so the session always rides on the DRM backend and always has the host's own connectors. `HEADLESS-1` is a name no connector will ever have, which made the shipped default a monitor rule Hyprland silently ignored, and made `vm-hyprland`'s assertion on that name unsatisfiable. `outputs` now means "monitor rules applied to whatever outputs the machine has". `name` is a regex against the real connector names and defaults to the empty string -- Hyprland's own wildcard form, as in its shipped `monitor=,preferred,auto,1` -- so `enable = true` alone gives a session at a known size on any host. Nothing else about the option changed. SEATD_VTBOUND=0 moves from checks/lib/gpu-session.nix into the compositor unit, where it belongs: libseat finds no seatd socket and no logind session for a system service, falls back to its embedded seatd, and that seat is VT-bound by default -- so it opens /dev/tty0, which the service user cannot, and every device open is refused. That is true on any host, not just in the test. gpu-session.nix keeps only the two things that really are the test machine's business: a render node and Mesa. vm-hyprland now asserts over `hyprctl -j monitors` that at least one monitor exists at the configured mode, with no monitor name anywhere in the check. It also gains a wallpaper, because `--reject-blank` could not otherwise mean anything: the session the module configures by default is a flat black field, which grim captures as an all-zero 1280x720 RGBA PNG of exactly 3653 bytes -- `blank_png_size()` to the byte. Runs that passed that assertion were reading Hyprland's startup notification overlay, which expires after about fifteen seconds. With `misc:force_default_wallpaper` on, the frame is 85267 bytes with all 921600 pixels non-zero and is byte-identical at +15s, +30s and +60s. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M5GEju6XhoRXDWvEiaAX2r
162 lines
5.8 KiB
Nix
162 lines
5.8 KiB
Nix
# checks.<system>.vm-basic -- boot a real machine with the module enabled, point
|
|
# `captureCommand` at a fake capture program, and read the socket.
|
|
#
|
|
# This check is about the module's wiring and the wire contract, not about
|
|
# Hyprland: the fake capture emits one fixed PNG, so "two frames arrived and
|
|
# they are the same image" is a real assertion rather than a coincidence.
|
|
{
|
|
testers,
|
|
hhstream,
|
|
testTools,
|
|
python3,
|
|
hhsModule,
|
|
width ? 1280,
|
|
height ? 720,
|
|
fps ? 30,
|
|
socketPath ? "/run/hyprland-headless-stream/stream.sock",
|
|
}:
|
|
testers.runNixOSTest {
|
|
name = "hhstream-vm-basic";
|
|
|
|
# KVM is available, so this is a minute or two; cap it so a hang is a failure
|
|
# rather than a wedged builder.
|
|
globalTimeout = 900;
|
|
|
|
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;
|
|
# The module declares `package` with no default (see README.dev.md), so the
|
|
# test has to supply the flake's build.
|
|
package = hhstream;
|
|
inherit socketPath;
|
|
frameRate = fps;
|
|
format = "png";
|
|
# The fake capture fixes the frame size, so the monitor rule does not
|
|
# matter here -- but it must not be a name no connector has either, or
|
|
# this file would keep advertising a shape that does nothing.
|
|
outputs = [
|
|
{
|
|
inherit width height;
|
|
refresh = fps;
|
|
}
|
|
];
|
|
captureCommand = [
|
|
"${testTools}/bin/hhs-fake-capture"
|
|
"--width"
|
|
(toString width)
|
|
"--height"
|
|
(toString height)
|
|
];
|
|
};
|
|
|
|
environment.systemPackages = [
|
|
testTools
|
|
hhstream
|
|
# The "client dying mid-stream" subtest opens the socket from a python
|
|
# one-liner in the guest. hhstream's own interpreter is reachable only
|
|
# through its wrapper, so without this the subtest dies on exit code 127
|
|
# (`python3: command not found`) rather than on anything it asserts.
|
|
python3
|
|
];
|
|
|
|
# Mesa and the compositor together need more than the fake capture alone
|
|
# did; the GPU itself comes from gpu-session.nix.
|
|
virtualisation = {
|
|
memorySize = 2048;
|
|
cores = 2;
|
|
diskSize = 4096;
|
|
graphics = false;
|
|
};
|
|
};
|
|
|
|
testScript = ''
|
|
SOCKET = "${socketPath}"
|
|
ASSERT = "hhs-assert-stream --socket " + SOCKET
|
|
|
|
|
|
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 module's two units come up"):
|
|
try:
|
|
machine.wait_for_unit("hyprland-headless.service", timeout=120)
|
|
machine.wait_for_unit("hyprland-headless-stream.service", timeout=120)
|
|
except Exception:
|
|
dump("units did not start")
|
|
raise
|
|
|
|
with subtest("the socket exists, owned by the service user, mode 0660"):
|
|
try:
|
|
machine.wait_for_file(SOCKET, timeout=60)
|
|
print(machine.succeed(f"stat -c 'owner=%U group=%G mode=%a type=%F' {SOCKET}"))
|
|
machine.succeed(f"[ \"$(stat -c %a {SOCKET})\" = 660 ]")
|
|
machine.succeed(f"[ \"$(stat -c %U {SOCKET})\" = hhstream ]")
|
|
machine.succeed(f"[ \"$(stat -c %G {SOCKET})\" = hhstream ]")
|
|
machine.succeed(f"[ \"$(stat -c %F {SOCKET})\" = socket ]")
|
|
except Exception:
|
|
dump("socket missing or wrong ownership")
|
|
raise
|
|
|
|
with subtest("the Hello parses, magic is HHS1, size is non-zero"):
|
|
try:
|
|
print(machine.succeed(f"{ASSERT} --frames 1 --timeout 30"))
|
|
except Exception:
|
|
dump("Hello did not parse")
|
|
raise
|
|
|
|
with subtest("two frames arrive, non-empty, byte-identical, matching the Hello"):
|
|
try:
|
|
print(
|
|
machine.succeed(
|
|
f"{ASSERT} --frames 2 --timeout 60"
|
|
" --expect-width ${toString width} --expect-height ${toString height}"
|
|
" --expect-format image/png --expect-fps ${toString fps}"
|
|
" --require-png --identical-frames --min-bytes 1"
|
|
)
|
|
)
|
|
except Exception:
|
|
dump("frames did not satisfy the contract")
|
|
raise
|
|
|
|
with subtest("two clients are served concurrently and independently"):
|
|
try:
|
|
print(
|
|
machine.succeed(
|
|
f"{ASSERT} --frames 3 --timeout 60 --require-png > /tmp/a.log 2>&1 & p1=$!; "
|
|
f"{ASSERT} --frames 3 --timeout 60 --require-png > /tmp/b.log 2>&1 & p2=$!; "
|
|
"wait $p1; r1=$?; wait $p2; r2=$?; "
|
|
"echo '--- client a ---'; cat /tmp/a.log; "
|
|
"echo '--- client b ---'; cat /tmp/b.log; "
|
|
"exit $((r1 + r2))"
|
|
)
|
|
)
|
|
except Exception:
|
|
dump("concurrent clients were not both served")
|
|
raise
|
|
|
|
with subtest("a client dying mid-stream leaves the server serving"):
|
|
try:
|
|
machine.succeed(
|
|
"timeout 5 python3 -c 'import socket;"
|
|
f"s=socket.socket(socket.AF_UNIX);s.connect(\"{SOCKET}\");s.recv(1);s.close()'"
|
|
)
|
|
print(machine.succeed(f"{ASSERT} --frames 2 --timeout 60 --require-png"))
|
|
machine.succeed("systemctl is-active hyprland-headless-stream.service")
|
|
except Exception:
|
|
dump("server did not survive a client dying mid-frame")
|
|
raise
|
|
'';
|
|
}
|