From e13e193bb8c201a1131682c7b27237becb767a7a Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 16 Nov 2026 12:24:42 +0000 Subject: [PATCH] guest: leave kwtest and kwbench out of release bundles alpine.sh always writes alpine-test.cpio: the image followed by a second cpio archive with kwtest and kwbench, which the kernel unpacks after the first. alpine.cpio, which build.sh bundles, is the same, or with KW_RELEASE=1 the image alone. The choice is in alpine.sh because build.sh is part of the release workflow's cache keys. The release workflow sets KW_RELEASE=1, so the GitHub release bundle, the npm package and the deployed page have no test programs. Its kwtest steps boot the release bundle's kernel with --initrd alpine-test. wasi-node.ts uses alpine-test.cpio, and the headless lowmem scenario boots to the shell instead of running kwtest, since the built page runs a release kernel. --- .agents/kernel.md | 8 +++++-- .agents/testing.md | 13 ++++++----- .agents/web.md | 2 +- .github/workflows/release.yml | 14 +++++++++--- js/cli.ts | 5 +++-- kernel/README.md | 4 ++-- kernel/guest/alpine.sh | 42 ++++++++++++++++++++++++++++------- test/wasi-node.ts | 3 ++- web/test/headless.mjs | 16 +++++++------ 9 files changed, 76 insertions(+), 31 deletions(-) diff --git a/.agents/kernel.md b/.agents/kernel.md index d91f2de..59f462b 100644 --- a/.agents/kernel.md +++ b/.agents/kernel.md @@ -567,8 +567,12 @@ required: build.sh fetches Binaryen 133 if it finds no `wasm-opt` with ## Kernel tests -- kwtest (`kernel/guest/kwtest.c`, `/usr/bin/kwtest` in the image): run as - `rdinit=` on both builds, with and without `--no-jit`. It powers off on +- kwtest (`kernel/guest/kwtest.c`, `/usr/bin/kwtest` in local builds and + `alpine-test.cpio`, not in release bundles; kernel/README.md, alpine): + run as `rdinit=` on both builds, with and without `--no-jit`. Device + nodes come from devtmpfs when it is mounted, else they are made in + `/tmp`; it never opens a node in `/tmp` once `/dev` has one, because + the overlay root mounts `/tmp` nodev. It powers off on success and halts (exit 1) on failure. What it covers beyond syscalls: - ISA, reading `kw.isa=` from `/proc/cmdline`: the cpuinfo `isa` line (order, names, what must be listed), `riscv_hwprobe` `IMA_EXT_0` and diff --git a/.agents/testing.md b/.agents/testing.md index b4dc081..a48f704 100644 --- a/.agents/testing.md +++ b/.agents/testing.md @@ -19,8 +19,9 @@ are run only when asked; the page is tested by hand with `pnpm dev`. | Host file systems (`fs.ts`, `9p.ts`, `memfs.ts`, `mounts.ts`, `nodefs.ts`, `kw9p.c`) | after a kw9p change `kernel/build.sh alpine`; `pnpm test:9p`; `pnpm test:api`; `node test/9p-bench.ts` and with `--worker`, against js.md's table | | Page (`web/`) | `pnpm typecheck:web`; `pnpm build:web` | -A separate static guest test program goes into the `kwtest kwbench ...` loop at -the end of `kernel/guest/alpine.sh`. `node test/glimmer-check.mjs --run` +A separate static guest program goes into the `glimmer kwvsock ...` loop at +the end of `kernel/guest/alpine.sh`, or into the `kwtest kwbench` loop +after it if it is only for tests (those stay out of release bundles). `node test/glimmer-check.mjs --run` boots with `--display --sound-wav`, runs `glimmer --test` and checks the dumped frame pixel for pixel, the injected input events and the recorded test signal sample for sample (`--no-sound`: without a sound card; `--worker`: @@ -40,12 +41,14 @@ date, UTC), which it tags `v` once the build passes. Its `release` input (on by default) unchecked makes it a smoke run. A pushed `v` tag on main is a release of that version. It refuses any other ref before building, and stamps the version into package.json -before `pnpm build`. It builds everything from source +before `pnpm build`. It builds everything from source with `KW_RELEASE=1`, so `alpine.sh` +leaves kwtest and kwbench out of `alpine.cpio` and the bundle (`kernel/build.sh toolchain kernel alpine datadisk`, clang 22 from apt.llvm.org; kwemu with `zig build -Dcpu=baseline` handed over as `KWEMU=`, so the zig cache survives runners with other CPU models), runs -kwtest with and without the JIT, `pnpm typecheck`, the tty, http and 9p -tests, `pnpm build`, kwtest and the api tests on the built package, then +kwtest with and without the JIT (the bundle's kernel with `--initrd +alpine-test`), `pnpm typecheck`, the tty, http and 9p +tests, `pnpm build`, kwtest (the same way) and the api tests on the built package, then uploads `npm pack`'s tarball (`unkernel.tgz`) and the bundle. A release publishes the tarball to npm through trusted publishing (npmjs.com trusts `release.yml` of this repository; no token), always on the dist-tag diff --git a/.agents/web.md b/.agents/web.md index 65a007b..60e6c79 100644 --- a/.agents/web.md +++ b/.agents/web.md @@ -521,7 +521,7 @@ Agents run these only when asked. The page is tested by hand with `headless.mjs` (`pnpm test:web`: desktop with the JIT compiling and cross-origin isolation asserted, phone over LAN, nojspi, fetch404, modfail, -lowmem running kwtest), `data.mjs` (data disk, overlay root, safe mode, +lowmem booting to the shell at 128 MiB), `data.mjs` (data disk, overlay root, safe mode, second tab, export/reset/import) and `net.mjs` (needs the internet). Shared code is in `lib.mjs`. They drive Chromium over the DevTools protocol with no npm dependencies and start the built server (`--dev` starts the Vite dev diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0428c49..1b1f79a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -113,6 +113,11 @@ jobs: # cores for the wasm-ld and kernel builds), if one is set up. runs-on: ${{ vars.RELEASE_RUNNER || 'ubuntu-24.04' }} timeout-minutes: 240 + env: + # alpine.sh then writes alpine.cpio, which the bundle gets, without + # kwtest and kwbench. The kwtest steps boot this bundle's kernel with + # alpine-test.cpio instead: the same image plus the test programs. + KW_RELEASE: "1" steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -291,11 +296,13 @@ jobs: - name: kwtest (JIT) run: | - node js/cli.ts --timeout 600 --append "console=hvc0 rdinit=/usr/bin/kwtest" "$stage/usr/lib/kw-image" echo "image id: alpine-$ALPINE_VERSION-$id" -python3 "$root/kernel/tools/mkcpio.py" "$stage" "$out/alpine.cpio" -echo "initramfs: $out/alpine.cpio" +# alpine-test.cpio is the image plus kwtest and kwbench: two archives back +# to back, which the kernel unpacks in turn (the second adds its files). +# alpine.cpio, which kernel/build.sh bundles, is the same, or with +# KW_RELEASE=1 (the release workflow) the image alone. The image id above +# leaves the test programs out, so all carry the same one. (The choice is +# made here, not in build.sh: build.sh is part of CI's kernel cache key.) +python3 "$root/kernel/tools/mkcpio.py" "$stage" "$out/alpine-image.cpio" +python3 "$root/kernel/tools/mkcpio.py" "$tstage" "$out/kwtest.cpio" +cat "$out/alpine-image.cpio" "$out/kwtest.cpio" > "$out/alpine-test.cpio" +rm "$out/kwtest.cpio" +if [ "${KW_RELEASE:-0}" = 1 ]; then + mv "$out/alpine-image.cpio" "$out/alpine.cpio" + echo "initramfs: $out/alpine.cpio (KW_RELEASE=1: without kwtest and kwbench)" +else + rm "$out/alpine-image.cpio" + cp "$out/alpine-test.cpio" "$out/alpine.cpio" + echo "initramfs: $out/alpine.cpio (with kwtest and kwbench; KW_RELEASE=1 leaves them out)" +fi +echo "initramfs with kwtest and kwbench: $out/alpine-test.cpio" diff --git a/test/wasi-node.ts b/test/wasi-node.ts index 1ae748e..29e304c 100644 --- a/test/wasi-node.ts +++ b/test/wasi-node.ts @@ -135,7 +135,8 @@ async function test(): Promise { const k32 = path.join(root, "vendor/build/kernel/vmlinux32.wasm"); const k64 = path.join(root, "vendor/build/kernel/vmlinux"); const alpineCpio = path.join(root, "vendor/build/initramfs/alpine.cpio"); - const kwtest = { initrd: alpineCpio, cmdline: "console=hvc0 rdinit=/usr/bin/kwtest", expect: [/kwtest: 0 failure\(s\)/] }; + const testCpio = path.join(root, "vendor/build/initramfs/alpine-test.cpio"); + const kwtest = { initrd: testCpio, cmdline: "console=hvc0 rdinit=/usr/bin/kwtest", expect: [/kwtest: 0 failure\(s\)/] }; const cases: Case[] = [ { name: "kwtest vmlinux32.wasm", kernel: k32, ...kwtest }, { name: "kwtest vmlinux (memory64)", kernel: k64, ...kwtest }, diff --git a/web/test/headless.mjs b/web/test/headless.mjs index 0a7e091..2a09c6b 100644 --- a/web/test/headless.mjs +++ b/web/test/headless.mjs @@ -27,8 +27,9 @@ // modfail the network drops the boot module (boot-*.js, or src/boot.ts // with --dev): main.tsx reports it in the panel. // lowmem ?simulate=lowmem&mem=512: allocations above 128 MiB fail, the -// SDK falls back to 128 MiB and kwtest still passes -// (rdinit=/usr/bin/kwtest). +// SDK falls back to 128 MiB and Alpine still boots to the shell +// and runs a command. (kwtest is not in release bundles, which +// the built page runs.) // Layout checks (nothing overflows or overlaps) run at both viewports. // Screenshots go to --shots (default: $TMPDIR/unkernel-shots). import { mkdirSync } from "node:fs"; @@ -350,12 +351,13 @@ const scenarios = { async lowmem(page) { await page.emulate(DESKTOP); - await page.goto(`http://127.0.0.1:${port}/?simulate=lowmem&mem=512&append=${encodeURIComponent("console=hvc0 rdinit=/usr/bin/kwtest")}`); - await page.waitFor("['halted', 'error'].includes(document.getElementById('app').dataset.state)", "kwtest to finish", 60000); + await page.goto(`http://127.0.0.1:${port}/?simulate=lowmem&mem=512`); + await page.waitScreen(PROMPT, "shell prompt"); + await page.evaluate(`globalThis.kernel.sendInput(${JSON.stringify("echo $((7*6))\r")})`); + await page.waitScreen("/^42\\s*$/m", "command output"); const r = await page.evaluate(`({ state: document.getElementById('app').dataset.state, mem: KW.memActualMiB, label: document.getElementById('status-label').textContent })`); - const s = await page.screen(); - console.log(` state=${r.state} (${r.label}), allocated ${r.mem} MiB; ${s.match(/kwtest: \d+ failure\(s\)/)?.[0] ?? "no kwtest summary"}`); - if (r.state !== "halted" || r.mem !== 128 || !/kwtest: 0 failure/.test(s)) throw new Error(`unexpected: ${JSON.stringify(r)}`); + console.log(` state=${r.state} (${r.label}), allocated ${r.mem} MiB`); + if (r.state !== "running" || r.mem !== 128) throw new Error(`unexpected: ${JSON.stringify(r)}`); }, };