test: skip the capture and camera tests on a bundle without kwrec and kwcap (a release build), and restore the 3 s recording

This commit is contained in:
Pooya Parsa
2026-11-29 20:11:37 +00:00
parent 599746c2dc
commit 61519ce4e5

View File

@@ -65,6 +65,9 @@ const kernelHasShm = kernelImports.some((i) => i.name === "wasm_driver_shm_init"
const kernelHasJit = kernelImports.some((i) => i.name === "kw_host_jit_caps");
/** Does the bundle carry the SMP kernel (its patch; kernel.md, Two kernels)? */
const hasSmpPatch = WebAssembly.Module.customSections(kernelModule, "unkernel.kernel.smp.kwpatch").length > 0;
/** The capture tests' guest programs (guest/src/test/kwrec.c, kwcap.c), or a reason to skip them: a release bundle (KW_RELEASE=1, the release's package test) has them only in base-test.cpio. */
const bundleInitrd = Buffer.from(bundledBoot(kernelModule).initrd ?? []);
const noCaptureTools = !(bundleInitrd.includes("usr/bin/kwrec") && bundleInitrd.includes("usr/bin/kwcap")) && "the bundle's initramfs has no kwrec and kwcap (a release build)";
type BootOptions = NonNullable<Parameters<typeof createKernel>[0]>;
// A failed assertion must not leave a kernel running (it would keep the test process alive).
@@ -476,7 +479,7 @@ describe("api", { concurrency: CONCURRENCY }, () => {
const st = vm.stats().soundIn; // in a worker: its last report, at the exit
assert.ok(st && st.opens === 2 && st.starts === 2 && st.frames >= 12000 + 4000, JSON.stringify(st));
};
for (const { worker, shared, name } of TRANSPORTS) test(`sound in: a guest records the source's samples through ALSA hw:0,0 and /dev/dsp (read(), ${name})`, async (t) => {
for (const { worker, shared, name } of TRANSPORTS) test(`sound in: a guest records the source's samples through ALSA hw:0,0 and /dev/dsp (read(), ${name})`, { skip: noCaptureTools }, async (t) => {
const events: string[] = [];
let pos = 0;
await captureRoundTrip(t, {
@@ -493,7 +496,7 @@ describe("api", { concurrency: CONCURRENCY }, () => {
},
}, events, !worker);
});
for (const { worker, name } of MODES) test(`sound in: a producer on its own clock writes the capture ring (onRing, ${name})`, async (t) => {
for (const { worker, name } of MODES) test(`sound in: a producer on its own clock writes the capture ring (onRing, ${name})`, { skip: noCaptureTools }, async (t) => {
const events: string[] = [];
let producer: Worker | undefined, started: Promise<unknown> | undefined;
// What a microphone's worklet does, on a thread of its own as an AudioWorklet is (so the load of this
@@ -575,7 +578,7 @@ describe("api", { concurrency: CONCURRENCY }, () => {
// ones skip, never rush), so only the first frame's lateness shortens the span, by less than an interval.
assert.ok(frames.at(-1)!.ms >= (frames.at(-1)!.seq - frames[0]!.seq - 1) * 1000 / fps * 0.95, `${frames.at(-1)!.ms} ms for ${count} frames at ${fps} fps`);
};
for (const { worker, shared, name } of TRANSPORTS) test(`camera: a guest captures the source's frames through V4L2 /dev/video0, I420, NV12 and YUYV (${name})`, async (t) => {
for (const { worker, shared, name } of TRANSPORTS) test(`camera: a guest captures the source's frames through V4L2 /dev/video0, I420, NV12 and YUYV (${name})`, { skip: noCaptureTools }, async (t) => {
const made = new Map<string, number>();
const streams: string[] = [];
const src = sdk.patternSource((n, frame) => made.set(fnv1a(frame), n));
@@ -606,7 +609,7 @@ describe("api", { concurrency: CONCURRENCY }, () => {
assert.ok(st && st.starts === 4 && st.stops === 4 && st.frames >= 31 && (worker || st.blackFrames === 0), JSON.stringify(st));
assert.deepEqual(vm.camera, { format: null });
});
test("camera: without a picture the guest gets black frames at its rate; without the option no /dev/video0", async (t) => {
test("camera: without a picture the guest gets black frames at its rate; without the option no /dev/video0", { skip: noCaptureTools }, async (t) => {
const vm = await boot(t, { log: () => {}, disks: [], camera: true });
const r = await vm.exec("sh", ["-c", "kwcap nv12 320 240 10 5"], { timeout: 120000 });
assert.equal(r.exitCode, 0, r.stdout + r.stderr);
@@ -672,7 +675,7 @@ describe("api", { concurrency: CONCURRENCY }, () => {
});
return { ns, gaps, keys: cs.flatMap((c, i) => (c.key ? [i] : [])), cs };
};
for (const { worker, shared, name } of TRANSPORTS) test(`camera: H.264 the source encodes reaches the guest chunk for chunk, in order and once, key frames where the controls say; a guest that stops taking it loses chunks only up to a key frame (${name})`, async (t) => {
for (const { worker, shared, name } of TRANSPORTS) test(`camera: H.264 the source encodes reaches the guest chunk for chunk, in order and once, key frames where the controls say; a guest that stops taking it loses chunks only up to a key frame (${name})`, { skip: noCaptureTools }, async (t) => {
const made: Made = new Map(), streams: string[] = [];
const vm = await boot(t, { log: () => {}, disks: [], worker, shared, camera: h264Source(made, streams) });
const run = async (cmd: string) => {
@@ -2250,7 +2253,7 @@ describe("api", { concurrency: CONCURRENCY }, () => {
assert.equal((await vm2.exited).code, 0);
});
test("snapshot() while a guest records: the restored capture stream is replayed to the source and the recording goes on", async (t) => {
test("snapshot() while a guest records: the restored capture stream is replayed to the source and the recording goes on", { skip: noCaptureTools }, async (t) => {
const opts = (events: string[]) => {
let pos = 0;
return {
@@ -2265,7 +2268,7 @@ describe("api", { concurrency: CONCURRENCY }, () => {
const vm = await boot(t, opts(ev1));
const a = screen(vm);
await a.waitFor(PROMPT);
vm.write("kwrec 8000 1 s16 80000 /tmp/c.raw; echo recorded\n"); // 10 s: still recording at the snapshot on a slow host
vm.write("kwrec 8000 1 s16 24000 /tmp/c.raw; echo recorded\n"); // 3 s
await waitEvent(ev1, "start");
await new Promise((r) => setTimeout(r, 300));
const snap = sdk.decodeSnapshot(sdk.encodeSnapshot(await vm.snapshot({ stop: true })));
@@ -2279,13 +2282,13 @@ describe("api", { concurrency: CONCURRENCY }, () => {
const b = screen(vm2);
assert.deepEqual(ev2, ["open", "prepare", "start"], "replayed to the new source");
assert.equal(vm2.soundIn?.capturing, true);
await b.waitFor(/kwrec: 80000 frames, \d+ overrun\(s\)[\s\S]*recorded/);
await b.waitFor(/kwrec: 24000 frames, \d+ overrun\(s\)[\s\S]*recorded/);
assert.equal(ev2.at(-1), "close", ev2.join(","));
vm2.write("poweroff\n");
assert.equal((await vm2.exited).code, 0);
});
test("snapshot() while a guest streams the camera: the stream is replayed to the new source and the capture goes on", async (t) => {
test("snapshot() while a guest streams the camera: the stream is replayed to the new source and the capture goes on", { skip: noCaptureTools }, async (t) => {
const opts = (streams: string[], made: Map<string, number>) => {
const src = sdk.patternSource((n, frame) => made.set(fnv1a(frame), n));
return {
@@ -2318,7 +2321,7 @@ describe("api", { concurrency: CONCURRENCY }, () => {
assert.equal((await vm2.exited).code, 0);
});
for (const { worker, shared, name } of TRANSPORTS) test(`snapshot() while a guest streams H.264: the new source's stream goes on at a key frame (${name})`, async (t) => {
for (const { worker, shared, name } of TRANSPORTS) test(`snapshot() while a guest streams H.264: the new source's stream goes on at a key frame (${name})`, { skip: noCaptureTools }, async (t) => {
const opts = (made: Made, streams: string[], h264 = true, start = 0) => ({
log: () => {}, vsock: false, disks: [], worker, shared,
camera: h264 ? h264Source(made, streams, start) : { read: () => false },