Files
komorebi/nix/tests/vm/suites/render-smoke/test.py
T
LGUG2Z fec9c2773a build(nix): a Plasma session node for tests
A virtual KWin has no output to draw on, so every test about pixels, and later
about the pointer, needs a real session. The `session` node is the headless node
plus a login: plasma-login-manager logs the test user in by itself, the way
nixpkgs' own `plasma6` test does, and Plasma draws on the machine's display. The
choice of login manager is made in `nodes/session.nix` and nowhere else, and the
file says how to switch to sddm.

The node adds no display device. The test driver gives every aarch64 guest one
virtio-gpu and takes screenshots of it; a second device is a second KWin output
that screenshots never show, which is what a first attempt did (a blank 1280x800
console).

`Kde.session` attaches to the session once the desktop is up: the shell is
running, the user manager knows the Wayland display, and the splash screen has
gone. The display is read from the user manager because plasma-login-manager's
greeter has its own KWin and takes `wayland-0`, and the user's session gets
`wayland-1`. The splash condition is there because KSplash has over a thousand
colors on it, so a "not blank" check passed on the splash screen. NixOS wraps
programs, which is why processes are found by their command lines: `pgrep -x
plasmashell` never matches `.plasmashell-wrapped`, and an exact match for the
splash would have passed because nothing matched. `Kde.shot` returns a
screenshot as a Pillow image.

`vm-render-smoke` is the first slow suite: it starts a session, opens a
terminal, and checks the middle of the window is dark and that the desktop
behind it has thousands of colors. On aarch64 under HVF five runs gave the same
screenshot, with the desktop up after 34 seconds. docs/dev/vm-tests.md describes
the node and the two traps.
2026-10-27 14:06:52 -07:00

45 lines
1.4 KiB
Python

# A Plasma session draws a desktop in the test machine, so that every test after this one can trust
# a screenshot. KSplash has thousands of colors on it too, so "not blank" is not the check: the
# splash has to be gone and a window has to be painted on the desktop.
import time
from komorebi_vm import Checks, Kde
start_all()
started = time.monotonic()
machine.wait_for_unit("multi-user.target")
checks = Checks()
kde = Kde.session(machine, scale=SCALE)
print(f"the desktop is up after {time.monotonic() - started:.0f}s")
def konsole() -> str:
return kde.run("kdotool search --class konsole | head -1")[1].strip()
kde.spawn("konsole")
checks.check("a window appears", kde.wait_for(lambda: konsole() != "", timeout=60))
rect = kde.rect(konsole())
checks.check("the window has a size", rect.w > 0 and rect.h > 0)
def painted() -> bool:
image = kde.shot("desktop")
center = image.getpixel((rect.x + rect.w // 2, rect.y + rect.h // 2))
assert isinstance(center, tuple)
# the terminal's background is dark; the wallpaper behind it is not
return sum(center) < 3 * 90
checks.check("the window is painted on the screen", kde.wait_for(painted, timeout=60))
image = kde.shot("desktop")
colors = image.getcolors(maxcolors=image.width * image.height)
assert colors is not None
print(f"the screenshot is {image.size[0]}x{image.size[1]} with {len(colors)} colors")
checks.check("the desktop behind it is drawn", len(colors) > 5000)
checks.finish()