feat: record every sample machine's boot as an animated WebP

Each sample machine now has a VM check, including new ones for
text-console and scripted-initrd. While a check runs, a recorder takes a
frame every half second through a second QEMU monitor socket, and
record-screencasts encodes the frames into recordings/<machine>.webp with
img2webp, dropping the BIOS frames at other resolutions. The guide shows
each machine's recording in the section it illustrates, replacing the PNG
screenshots. The checks are now named vm-<machine>.
This commit is contained in:
Willem Vanhulle committed 2026-10-30 14:59:10 +01:00
1 parent 7e95cbd8e9
commit c5e2e16b67
21 files changed
+402 -106

No files matched your search

+6 -14
View File
@@ -34,18 +34,10 @@ in
];
};
checksFor = pkgs: {
vm-boot-and-shutdown = pkgs.testers.runNixOSTest (
import ./slow-services/check.nix { machine = machines.slow-services; }
);
vm-luks-passphrase = pkgs.testers.runNixOSTest (
import ./encrypted-volume/check.nix {
machine = machines.encrypted-volume;
inherit pkgs;
}
);
vm-failures = pkgs.testers.runNixOSTest (
import ./failures/check.nix { machine = machines.failures; }
);
};
checksFor =
pkgs:
lib.mapAttrs (
machineName: machine:
pkgs.testers.runNixOSTest (import ./${machineName}/check.nix { inherit machine pkgs; })
) machines;
}
+6 -6
View File
@@ -3,16 +3,15 @@ let
secretDisk = import ./secret-disk.nix { inherit pkgs; };
in
{
name = "bootvine-luks-passphrase";
name = "bootvine-encrypted-volume";
nodes.machine = {
imports = [ machine ];
imports = [
machine
../shared/recorded-display.nix
];
testing.initrdBackdoor = true;
virtualisation.qemu.options = [
"-vga none"
"-device virtio-vga,xres=1280,yres=800"
];
virtualisation.qemu.drives = [ secretDisk.qemuDrive ];
};
@@ -20,5 +19,6 @@ in
PASSPHRASE = "${secretDisk.passphrase}"
''
+ builtins.readFile ../shared/console.py
+ builtins.readFile ../shared/screen_recording.py
+ builtins.readFile ./check.py;
}
+3 -1
View File
@@ -7,7 +7,9 @@ def pending_prompt():
return next((name for name in listing if name.startswith("ask.")), "")
recording = ScreenRecording(machine)
machine.start()
recording.start()
retry(lambda _: pending_prompt() != "", timeout_seconds=60)
wait_for_screen("passphrase")
@@ -18,7 +20,6 @@ retry(lambda _: answered_prompts() == 1, timeout_seconds=30)
retry(lambda _: pending_prompt() not in ("", first_prompt), timeout_seconds=30)
wait_for_screen("passphrase")
assert_text_visible(font_has_512_glyphs=True)
machine.screenshot("passphrase")
machine.send_chars(f"{PASSPHRASE}\n")
machine.wait_for_unit("systemd-cryptsetup@secret.service")
machine.switch_root()
@@ -29,3 +30,4 @@ journal = bootvine_journal()
print(journal)
assert " in Initrd " in journal, "never ran in the initrd"
assert journal.count("answered a password prompt") == 2, "did not answer both attempts itself"
recording.stop()
+7 -10
View File
@@ -1,4 +1,4 @@
{ machine }:
{ machine, ... }:
{
name = "bootvine-failures";
@@ -9,7 +9,10 @@
marker: "${pkgs.bash}/bin/bash -c 'until [ -e /run/${marker} ]; do sleep 0.1; done'";
in
{
imports = [ machine ];
imports = [
machine
../shared/recorded-display.nix
];
bootvineSample.startFailuresByHand = true;
testing.initrdBackdoor = true;
@@ -36,14 +39,8 @@
};
};
virtualisation = {
memorySize = 2048;
qemu.options = [
"-vga none"
"-device virtio-vga,xres=1280,yres=800"
];
};
};
testScript = builtins.readFile ../shared/console.py + builtins.readFile ./check.py;
testScript = builtins.readFile ../shared/console.py
+ builtins.readFile ../shared/screen_recording.py + builtins.readFile ./check.py;
}
+3 -1
View File
@@ -12,7 +12,9 @@ def failure_panel():
return "\n".join(lines[start:])
recording = ScreenRecording(machine)
machine.start()
recording.start()
wait_for_screen("Initrd", "Initrd held for the check")
start_failing_unit("initrd-nic-firmware-load")
@@ -52,8 +54,8 @@ wait_for_screen("upstream-uplink exited with status 1", "lost connection to ups
wait_for_screen("× 9 failed", "connection refused")
assert "Started Upstream uplink" not in failure_panel(), f"systemd's own start line reached the panel:\n{screen()}"
print(screen())
machine.screenshot("failures")
machine.succeed("touch /run/release-boot-failures-hold")
retry(lambda _: "handing the console over" in bootvine_journal(), timeout_seconds=60)
print(bootvine_journal())
recording.stop()
+25
View File
@@ -0,0 +1,25 @@
{ machine, ... }:
{
name = "bootvine-scripted-initrd";
nodes.machine =
{ lib, ... }:
let
waitFor = flag: "/bin/sh -c 'until [ -e /run/${flag} ]; do sleep 0.1; done'";
in
{
imports = [
machine
../shared/recorded-display.nix
];
systemd.services = {
sample-database.serviceConfig.ExecStop = lib.mkForce (waitFor "release-sample-database");
backdoor.before = [ "sample-database.service" ];
};
};
testScript =
builtins.readFile ../shared/console.py
+ builtins.readFile ../shared/screen_recording.py
+ builtins.readFile ./check.py;
}
+28
View File
@@ -0,0 +1,28 @@
def unit_state(unit):
return machine.succeed(f"systemctl is-active {unit} || true").strip()
recording = ScreenRecording(machine)
machine.start()
recording.start()
wait_for_screen("Stage 2", "sample-database")
assert_bootvine_in_front()
assert_text_visible(font_has_512_glyphs=True)
machine.wait_for_unit("greetd.service")
retry(lambda _: unit_state("bootvine") == "inactive", timeout_seconds=60)
journal = bootvine_journal()
print(journal)
watched = [line for line in journal.splitlines() if line.startswith("bootvine: watching")]
assert watched, "bootvine never started"
assert not any(" in Initrd " in line for line in watched), "bootvine ran in a scripted initrd"
assert "handing the console over" in journal, "never handed the console over"
machine.succeed("systemctl poweroff --no-block")
retry(lambda _: unit_state("sample-database") == "deactivating", timeout_seconds=60)
wait_for_screen("Shutdown", "sample-database")
assert_bootvine_in_front()
machine.succeed("touch /run/release-sample-database")
machine.wait_for_shutdown()
recording.stop()
+11
View File
@@ -0,0 +1,11 @@
{
virtualisation = {
memorySize = 2048;
qemu.options = [
"-vga none"
"-device virtio-vga,xres=1280,yres=800"
"-chardev socket,id=recording-monitor,path=recording-monitor,server=on,wait=off"
"-mon chardev=recording-monitor,mode=readline"
];
};
}
+74
View File
@@ -0,0 +1,74 @@
import os
import socket
import subprocess
import threading
import time
RECORDING_FRAME_SECONDS = 0.5
RECORDING_CONNECT_SECONDS = 30
QEMU_PROMPT = b"(qemu) "
class ScreenRecording:
def __init__(self, recorded_machine):
self.recorded_machine = recorded_machine
self.frames_directory = os.path.join(recorded_machine.out_dir, "recording")
self.raw_frame = os.path.join(recorded_machine.state_dir, "recording-frame.ppm")
self.stopping = threading.Event()
self.thread = threading.Thread(target=self.record_frames, daemon=True)
def start(self):
os.makedirs(self.frames_directory, exist_ok=True)
self.thread.start()
def stop(self):
self.stopping.set()
self.thread.join()
def connect_monitor(self):
monitor_path = os.path.join(self.recorded_machine.state_dir, "recording-monitor")
deadline = time.monotonic() + RECORDING_CONNECT_SECONDS
while time.monotonic() < deadline and not self.stopping.is_set():
monitor = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
monitor.connect(monitor_path)
return monitor
except OSError:
monitor.close()
time.sleep(0.1)
return None
def read_until_prompt(self, monitor):
received = b""
while not received.endswith(QEMU_PROMPT):
chunk = monitor.recv(4096)
if not chunk:
raise ConnectionError("the recording monitor closed")
received += chunk
def save_frame(self, monitor, frame_number):
monitor.sendall(f"screendump {self.raw_frame}\n".encode())
self.read_until_prompt(monitor)
frame_path = os.path.join(self.frames_directory, f"frame-{frame_number:05d}.png")
unfinished_path = f"{frame_path}.unfinished"
subprocess.run(f"pnmtopng '{self.raw_frame}' > '{unfinished_path}'", shell=True, check=True)
os.replace(unfinished_path, frame_path)
def record_frames(self):
monitor = self.connect_monitor()
if monitor is None:
return
try:
self.read_until_prompt(monitor)
frame_number = 0
while not self.stopping.is_set():
self.save_frame(monitor, frame_number)
frame_number += 1
self.stopping.wait(RECORDING_FRAME_SECONDS)
except (OSError, ConnectionError, subprocess.CalledProcessError):
pass
finally:
monitor.close()
for leftover in os.listdir(self.frames_directory):
if leftover.endswith(".unfinished"):
os.remove(os.path.join(self.frames_directory, leftover))
+8 -11
View File
@@ -1,6 +1,6 @@
{ machine }:
{ machine, ... }:
{
name = "bootvine-boot-and-shutdown";
name = "bootvine-slow-services";
nodes.machine =
{ lib, ... }:
@@ -8,7 +8,10 @@
waitFor = flag: "/bin/sh -c 'until [ -e /run/${flag} ]; do sleep 0.1; done'";
in
{
imports = [ machine ];
imports = [
machine
../shared/recorded-display.nix
];
testing.initrdBackdoor = true;
boot.initrd.systemd.services.initrd-hardware-probe.serviceConfig.ExecStart = lib.mkForce (
waitFor "release-initrd-hardware-probe"
@@ -26,14 +29,8 @@
};
};
};
virtualisation = {
memorySize = 2048;
qemu.options = [
"-vga none"
"-device virtio-vga,xres=1280,yres=800"
];
};
};
testScript = builtins.readFile ../shared/console.py + builtins.readFile ./check.py;
testScript = builtins.readFile ../shared/console.py
+ builtins.readFile ../shared/screen_recording.py + builtins.readFile ./check.py;
}
+3
View File
@@ -6,7 +6,9 @@ def unit_state(unit):
return machine.succeed(f"systemctl is-active {unit} || true").strip()
recording = ScreenRecording(machine)
machine.start()
recording.start()
wait_for_screen("Initrd", "Slow hardware probe")
assert_bootvine_in_front()
@@ -56,3 +58,4 @@ assert_bootvine_in_front()
assert_text_visible(font_has_512_glyphs=True)
machine.succeed("touch /run/release-sample-database")
machine.wait_for_shutdown()
recording.stop()
+29
View File
@@ -0,0 +1,29 @@
{ machine, ... }:
{
name = "bootvine-text-console";
nodes.machine =
{ lib, ... }:
let
waitFor = flag: "/bin/sh -c 'until [ -e /run/${flag} ]; do sleep 0.1; done'";
in
{
imports = [
machine
../shared/recorded-display.nix
];
testing.initrdBackdoor = true;
boot.initrd.systemd.services.initrd-hardware-probe.serviceConfig.ExecStart = lib.mkForce (
waitFor "release-initrd-hardware-probe"
);
systemd.services = {
sample-database.serviceConfig.ExecStop = lib.mkForce (waitFor "release-sample-database");
backdoor.before = [ "sample-database.service" ];
};
};
testScript =
builtins.readFile ../shared/console.py
+ builtins.readFile ../shared/screen_recording.py
+ builtins.readFile ./check.py;
}
+31
View File
@@ -0,0 +1,31 @@
def unit_state(unit):
return machine.succeed(f"systemctl is-active {unit} || true").strip()
recording = ScreenRecording(machine)
machine.start()
recording.start()
wait_for_screen("Initrd", "Slow hardware probe")
assert_bootvine_in_front()
machine.succeed("touch /run/release-initrd-hardware-probe")
machine.switch_root()
wait_for_screen("Stage 2", "slow-warm-up")
assert_bootvine_in_front()
assert_text_visible(font_has_512_glyphs=True)
retry(lambda _: unit_state("bootvine") == "inactive", timeout_seconds=60)
journal = bootvine_journal()
print(journal)
assert "handing the console over" in journal, "never handed the console over"
assert foreground_terminal() != f"tty{BOOTVINE_TERMINAL}", "bootvine kept the console without a display manager"
machine.wait_until_tty_matches("1", "login: ")
machine.succeed("systemctl poweroff --no-block")
retry(lambda _: unit_state("sample-database") == "deactivating", timeout_seconds=60)
wait_for_screen("Shutdown", "sample-database")
assert_bootvine_in_front()
machine.succeed("touch /run/release-sample-database")
machine.wait_for_shutdown()
recording.stop()