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.
This commit is contained in:
Pooya Parsa
2026-11-16 12:24:42 +00:00
parent eacd495a91
commit e13e193bb8
9 changed files with 76 additions and 31 deletions

View File

@@ -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

View File

@@ -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<version>` once the build passes. Its
`release` input (on by default) unchecked makes it a smoke run. A pushed
`v<version>` 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

View File

@@ -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

View File

@@ -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" </dev/null | tee kwtest.log
node js/cli.ts --timeout 600 --kernel vendor/build/bundle/unkernel-alpine.wasm --initrd alpine-test \
--append "console=hvc0 rdinit=/usr/bin/kwtest" </dev/null | tee kwtest.log
grep -q 'kwtest: 0 failure(s)' kwtest.log
- name: kwtest (no JIT)
run: |
node js/cli.ts --timeout 900 --no-jit --append "console=hvc0 rdinit=/usr/bin/kwtest" </dev/null | tee kwtest.log
node js/cli.ts --timeout 900 --no-jit --kernel vendor/build/bundle/unkernel-alpine.wasm --initrd alpine-test \
--append "console=hvc0 rdinit=/usr/bin/kwtest" </dev/null | tee kwtest.log
grep -q 'kwtest: 0 failure(s)' kwtest.log
- name: Typecheck
@@ -316,7 +323,8 @@ jobs:
# as the sources, plus the packaging.
- name: Test the built package
run: |
node dist/cli.mjs --timeout 600 --append "console=hvc0 rdinit=/usr/bin/kwtest" </dev/null | tee kwtest.log
node dist/cli.mjs --timeout 600 --kernel dist/unkernel-alpine.wasm --initrd vendor/build/initramfs/alpine-test.cpio \
--append "console=hvc0 rdinit=/usr/bin/kwtest" </dev/null | tee kwtest.log
grep -q 'kwtest: 0 failure(s)' kwtest.log
UNKERNEL_DIST=1 node --test test/api.test.ts
- name: Pack

View File

@@ -43,8 +43,9 @@ With no arguments it boots Alpine from the bundled kernel (unkernel-alpine.wasm:
vmlinux32.wasm with the root fs and command line in custom sections), interactive
on this terminal; Ctrl-] quits. In a source checkout, any other --initrd (a NAME
from vendor/build/initramfs/, or a path) loads vendor/build/kernel/vmlinux32.wasm
plus that file. The kwtest smoke test is part of Alpine:
--append "console=hvc0 rdinit=/usr/bin/kwtest" (exit 0, or 1 on a failure).
plus that file. The kwtest smoke test is in a local build's Alpine (not in
releases): --append "console=hvc0 rdinit=/usr/bin/kwtest" (exit 0, or 1 on a
failure); with a release bundle add --initrd alpine-test.
--kernel (or a positional path) replaces the kernel: either build, or a bundle;
the memory type is detected from the module. A kernel with a bundled root fs

View File

@@ -97,10 +97,10 @@ separate and not part of `all`):
reproducible: fixed `-U` and `hash_seed`, and `E2FSPROGS_FAKE_TIME` /
`SOURCE_DATE_EPOCH` for the timestamps. `all` runs it before `bundle`, and
without mke2fs warns and goes on.
* **alpine** (`guest/alpine.sh`), the only initramfs, `vendor/build/initramfs/alpine.cpio`:
* **alpine** (`guest/alpine.sh`), the only initramfs, `vendor/build/initramfs/alpine.cpio`, and `alpine-test.cpio`, which always has kwtest and kwbench:
* The Alpine minirootfs 3.24.4 (version and checksum pinned in `tools/env.sh`, `ALPINE_TARBALL=file` overrides). It gets a small `/init` and an inittab with `hvc0::respawn:-/bin/sh` and `::respawn:/usr/bin/kwtty serve` (see vsock).
* busybox, zlib, libcrypto, libssl, libapk and apk are the same Alpine packages rebuilt for kwemu's CPU (`guest/alpine-opt.sh`: gcc 16 `-O2` with Zba/Zbb/Zbs/Zicond, linked with lld), which made shell scripts about 20% faster and apk about 11% (2026-11-16). The disk image gets them too. Details in `.agents/guest-packages.md`.
* `/usr/bin/kwtest` and `/usr/bin/kwbench` (`guest/kwtest.c`, `guest/kwbench.c`), built static with `zig cc -target riscv64-linux-musl`, so they run as `/init` (`rdinit=/usr/bin/kwtest`; it powers off, or halts on a failure) or from the shell.
* `/usr/bin/kwtest` and `/usr/bin/kwbench` (`guest/kwtest.c`, `guest/kwbench.c`), built static with `zig cc -target riscv64-linux-musl`, so they run as `/init` (`rdinit=/usr/bin/kwtest`; it powers off, or halts on a failure) or from the shell. They come as a second cpio archive after the image's, which the kernel unpacks after the first. With `KW_RELEASE=1` (set by the release workflow) `alpine.sh` leaves them out of `alpine.cpio`, so release bundles, the npm package and the deployed page have no kwtest; boot a release bundle with `--initrd alpine-test` to run it. The choice is in `alpine.sh`, not `build.sh`, because `build.sh` is part of CI's kernel cache key. Both archives have the same image id (`/usr/lib/kw-image`), which leaves the test programs out.
* `/usr/bin/glimmer`, built the same way (see Display, input and sound), and so are `/usr/bin/kwvsock`, `/usr/bin/kwshm`, `/usr/bin/kwtty` and `/usr/bin/kw9p` (see vsock, Host file systems and Shared memory).
* The cpio archive is written by `tools/mkcpio.py`; no root is needed.
* **disk** (`guest/alpine-disk.sh`, `DISK_SIZE`, default 512M; `all` keeps

View File

@@ -6,11 +6,13 @@
# /init mounts the pseudo filesystems and hands over to busybox init with a
# login-less shell on hvc0; with a disk labelled kwdata, mounted at /data,
# the root becomes an overlay that keeps every change on it (kw-overlay).
# It also carries
# the kernel smoke test and benchmark (static, so they work as /init too):
# It also carries the kernel smoke test and benchmark (static, so they work
# as /init too), except with KW_RELEASE=1 (release bundles; see the end of
# this file). vendor/build/initramfs/alpine-test.cpio always has them:
# rdinit=/usr/bin/kwtest kernel/guest/kwtest.c, powers off (halts on a failure)
# rdinit=/usr/bin/kwbench kernel/guest/kwbench.c, rough guest speed
# /usr/bin/glimmer kernel/guest/glimmer.c, a small game on /dev/fb0, evdev and
# Always in the image:
# /usr/bin/glimmer kernel/guest/glimmer.c, a small game on /dev/fb0, evdev and
# ALSA; glimmer --test draws a check pattern, plays a test
# signal and prints input events
# /usr/bin/kwvsock kernel/guest/kwvsock.c, a byte pipe over AF_VSOCK (connect or
@@ -449,16 +451,23 @@ Section "InputDevice"
EndSection
EOF
# Kernel smoke test and benchmark (see the top of this file), and the
# display, input and sound game and self-test (glimmer.c; it needs the CLI's
# The display, input and sound game and self-test (glimmer.c; it needs the CLI's
# --display or the page, and plays sound with --sound/--sound-wav or on the page),
# the vsock pipe (kwvsock.c; it needs a host with vsock, CLI --vsock or the SDK),
# the shm exporter (kwshm.c; it needs a host with shm, CLI --shm or the SDK)
# the terminal server (kwtty.c, from inittab; it serves a host with vsock)
# and the 9p mounter (kw9p.c; it needs a host serving 9p over vsock).
for t in kwtest kwbench glimmer kwvsock kwshm kwtty kw9p; do
for t in glimmer kwvsock kwshm kwtty kw9p; do
"$zig" cc -target riscv64-linux-musl -static -O2 -s -o "$stage/usr/bin/$t" "$root/kernel/guest/$t.c"
done
# The kernel smoke test and benchmark (see the top of this file) are not in
# the image: they go into a second archive, below.
tstage="$out/kwtest-root"
rm -rf "$tstage"
mkdir -p "$tstage/usr/bin"
for t in kwtest kwbench; do
"$zig" cc -target riscv64-linux-musl -static -O2 -s -o "$tstage/usr/bin/$t" "$root/kernel/guest/$t.c"
done
# Image id, for the overlay root (overlay/root.sh): a hash of the tree (names,
# modes, links, contents; no times or owners), so an identical rebuild keeps
@@ -467,5 +476,22 @@ id=$(tar -C "$stage" --sort=name --mtime=@0 --owner=0 --group=0 --numeric-owner
echo "alpine-$ALPINE_VERSION-$id" > "$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"

View File

@@ -135,7 +135,8 @@ async function test(): Promise<void> {
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 },

View File

@@ -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)}`);
},
};