Files
komorebi/nix/tests/vm/default.nix
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

102 lines
2.8 KiB
Nix

# The NixOS VM tests. Every directory under `suites/` is one test, `checks.<system>.vm-<name>`
# (Linux) and `legacyPackages.<system>.vm.<name>` (everywhere), so a new suite needs no edit to
# the flake. See docs/dev/vm-tests.md.
#
# `hostPkgs` is the pkgs of the machine that runs QEMU; the guests are always Linux. `scale` says
# how much slower than KVM that machine is (1 for KVM, 1.5 for HVF on a Mac, 8 for TCG), and every
# wait in the suites is multiplied by it.
{
hostPkgs,
scale ? 1,
}:
let
inherit (hostPkgs) lib;
# the library the suites import, built for the python of the test driver
komorebiVm =
ps:
ps.buildPythonPackage {
pname = "komorebi-vm";
version = "0.1.0";
pyproject = true;
src = lib.fileset.toSource {
root = ./lib;
fileset = ./lib;
};
build-system = [ ps.setuptools ];
dependencies = [ ps.pillow ];
doCheck = false;
};
# unit tests of the library against a fake machine, and the linters over it
libCheck =
let
python = hostPkgs.python3.withPackages (ps: [
ps.pytest
(komorebiVm ps)
]);
in
hostPkgs.runCommand "vm-lib"
{
nativeBuildInputs = [
python
hostPkgs.ruff
hostPkgs.ty
];
src = lib.fileset.toSource {
root = ./lib;
fileset = ./lib;
};
}
''
cp -r $src lib && chmod -R u+w lib && cd lib
ruff check .
ruff format --check .
ty check --python ${python} .
pytest -q -p no:cacheprovider
touch $out
'';
suiteNames = lib.attrNames (
lib.filterAttrs (_: type: type == "directory") (builtins.readDir ./suites)
);
suiteDefs = lib.genAttrs suiteNames (name: import (./suites + "/${name}"));
mkSuite =
name:
let
dir = ./suites + "/${name}";
suite = suiteDefs.${name};
in
hostPkgs.testers.runNixOSTest {
name = "komorebi-${name}";
extraPythonPackages = ps: [ (komorebiVm ps) ];
globalTimeout = builtins.ceil (suite.timeoutMinutes * 60 * scale);
passthru.tier = suite.tier;
nodes.machine = {
imports = [ (./nodes + "/${suite.kind}.nix") ];
};
testScript = ''
SCALE = ${toString scale}
''
+ builtins.readFile (dir + "/${suite.script or "test.py"}");
};
suites = lib.genAttrs suiteNames mkSuite;
in
{
inherit suites;
lib = libCheck;
# the suites of each tier, for the CI matrix: { fast = [ "kwin" ... ]; slow = [ ... ]; }
tiers = lib.groupBy (name: suiteDefs.${name}.tier) suiteNames;
# the guests of every suite, so that a Mac can build them on a Linux builder first
guests = lib.mapAttrs (
_: test: lib.mapAttrs (_: node: node.system.build.toplevel) test.nodes
) suites;
}