Eight words at the PC, by its address, name the function offline. The image loads where the firmware puts it, and the boot does not print that address. aarch64's monitor has no $pc, so the address is taken from the register line; checked on a real, paused QEMU. Test first: the snapshot test, 6 checks; the new one failed before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
1332 lines
71 KiB
Python
Executable File
1332 lines
71 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: LicenseRef-Starship-1.0
|
|
# Copyright (c) 2023-2026 Robert A. James
|
|
"""qemu_session.py -- one typed QEMU session against a kernel boot, and its verdict.
|
|
|
|
scripts/qemu_session.py MODE ARCH [--label L] [--make "VAR=val ..."] [--no-zuse]
|
|
|
|
Builds and boots `make ARCH=<arch> clean qemu` (one QEMU, in the foreground of
|
|
this script). Its disks are the Makefile's defaults -- on v4, a fresh data stick
|
|
and nothing else, so every boot is a first boot (plan 2026-10-29-stick-5,
|
|
Task 3) -- except for the modes that ask for the minted Zuse pair
|
|
(disk/zuse-scratch/) by name: copies of it, made under
|
|
build/qemu-session/<label>/ so the committed images are never booted, laid out
|
|
as a stick (zusestick.img), or her raw identity image for v3.
|
|
It reads the serial socket continuously, drives the boot over the serial and
|
|
QMP sockets the `qemu` goal opens, prints PASS:/FAIL: lines and
|
|
RESULT: PASS|FAIL, and quits QEMU over QMP. The serial log is the usual
|
|
logs/<TS>/<arch>/qemu-<arch>-<TS>.log.
|
|
|
|
Modes (the identity gate's, plan 2026-10-26-engine-step4-identity-gate.md, and
|
|
the stick's, plan 2026-10-26-stick-1-screen-and-keyboard.md):
|
|
headless no Zuse drive: POST: PASSED, then no `ok> ` for 60 s
|
|
zuse the default disks, a fresh data stick: the genesis line, [zuse@Hera] ok>,
|
|
`3 4 + .` -> 7 ok (plan 2026-10-29-stick-5, Task 3: it was the minted pair)
|
|
hotplug no drive; Zuse added over QMP -> prompt; pulled -> session ended,
|
|
headless; added again -> prompt
|
|
midpull pulled while a line is in hand: what is typed after does not run
|
|
waitpull pulled while a line WAITS: the wait ends at logout; re-attach -> prompt
|
|
typeahead serial bytes typed while headless do not run once Zuse attaches
|
|
emergency an EMERGENCY_CONSOLE_ENABLED=1 build: ok> with no drive
|
|
v3_keys system=v3: `3 4 + .` typed on QEMU's keyboard (send-key) -> 7 ok
|
|
screen_dark_until_login no drive: 30 s after POST the screen is all black
|
|
screen_console_after_login Zuse added: the screen shows the console; keys typed
|
|
on QEMU's keyboard answer 7 ok and change the screen
|
|
screen_dark_after_logout ... and when her drive is pulled, the screen is black again
|
|
kbd_typeahead keys pressed while headless do not run once Zuse attaches
|
|
usb_kbd the only keyboard a USB one (--make "QEMU_EXTRA='-machine
|
|
i8042=off -device usb-kbd,bus=xhci0.0,port=3'"): it types
|
|
no_framebuffer no display (-vga none): serial alone, 7 ok
|
|
alttab_after_logout after logout, Alt+TAB twice: the screen stays black
|
|
alttab_before_pull Alt+TAB, then the drive pulled: black; re-attach draws the console
|
|
emergency_pull EMERGENCY_CONSOLE_ENABLED=1: Zuse added and pulled, the screen
|
|
still shows the running console, and it types
|
|
gpt_zuse a GPT drive, Zuse in its StarshipOS identity partition: recognised; the partition
|
|
is attached (run with --make KERNEL_ARGS=--log-level=info)
|
|
gpt_hotplug ... pulled: session ended; added again: prompt
|
|
gpt_foreign a GPT drive with only a Linux partition: no identity, not attached (info level)
|
|
gpt_bad_crc the gpt_zuse image with its header CRC broken: not used, said so, not attached
|
|
gpt_bad_entries ... its entry array changed (the header intact): the same
|
|
gpt_no_header ... its "EFI PART" signature gone, the protective MBR kept: the same
|
|
gpt_read_error the raw Zuse drive with reads of its sector 0 failing (blkdebug): not used,
|
|
said so, not attached
|
|
virtio_kbd aarch64/riscv64: QEMU's virtio keyboard types 7 ok
|
|
stick_boot --target qemu-stick (amd64): the PC stick booted as a USB stick through OVMF; its
|
|
blank identity partition attached (500 MiB, not the 2 GiB disk); the proxy Zuse
|
|
minted onto it (genesis), [zuse@Hera] ok> (plan 2026-10-29-stick-5, Task 1)
|
|
genesis a fresh data stick (DATASTICK=1, no Zuse drive), booted twice, one QEMU at a time:
|
|
first the genesis line, [zuse@Hera] ok>, 7 ok; then the same copy again:
|
|
identity confirmed, no genesis, the prompt (plan 2026-10-29-stick-5, Task 1)
|
|
stick_genesis --target qemu-stick, the PC stick as built (no STICK_PAIR): its first boot mints
|
|
the proxy Zuse and reaches [zuse@Hera] ok> with nothing set up (plug and play)
|
|
stick_grow --target qemu-stick --stick-gib 16: the first boot grows Artemis to fill the stick
|
|
(over 12000000 user blocks), mints, the prompt, its time POST -> prompt printed; the
|
|
second boot of the same copy is not grown again and recognises Zuse; sfdisk --verify
|
|
on the copy is clean (plan 2026-10-29-stick-5, Task 2)
|
|
stick_small --target qemu-stick --stick-gib 4: under 8 GB -- not grown, said so; Artemis at the
|
|
image's size; the prompt
|
|
mint_zuse the default fresh data stick, the prompt; MINT-ZUSE; a blank 600 MiB stick added on port 3:
|
|
its size said, YES typed, "real Zuse minted onto the second stick", the prompt, 7 ok;
|
|
afterwards sfdisk --verify on it clean, one StarshipOS identity partition (plan
|
|
2026-10-29-stick-5, Task 4)
|
|
mint_zuse_refuse as mint_zuse, `no` typed: "stopped -- nothing written", the stick's bytes the
|
|
same, the prompt (still the proxy); a second MINT-ZUSE offers the same stick again
|
|
mint_small a 32 MiB stick offered: "under 64 MiB", nothing written, the prompt
|
|
mint_zuse_used as mint_zuse, the stick offered the pair's Zuse stick (Review Focus 2): rewritten,
|
|
the new Zuse recognised
|
|
mint_pull_system MINT-ZUSE, then the data stick pulled (Review Focus 3): "stopped -- nothing
|
|
written", session ended, headless; replugged: the proxy logs in again
|
|
zuse_stick_first after a mint on a data stick made in the session, the same copy booted again with
|
|
her stick on port 1 and the data stick on port 2 (Review Focus 1): she is logged in
|
|
fallback a mint on a data stick made in the session, then that stick booted alone (plan
|
|
2026-10-29-stick-5, Task 5): the fixed screen's four lines, no ok> for 30 s, `3 4 + .`
|
|
typed there not run; her stick added: the prompt; pulled: the screen again; R with no
|
|
stick offered: the plug-in line, any key stops it, the screen again
|
|
replace the fixed screen (as fallback); R, a blank stick, YES: a replacement minted, its prompt;
|
|
it pulled: the screen; the old stick added: "not this system's Zuse stick -- not used",
|
|
no ok> for 30 s; the new one added: the prompt
|
|
mint_fail the fixed screen; R, a stick whose writes all fail (blkdebug): "failed -- nothing
|
|
changed", the screen again; the old stick added: the prompt (Review Focus 4)
|
|
gpt_many no drive at boot; a data stick whose two StarshipOS partitions are entries 17 and 18,
|
|
after 16 others: "GPT: a USB drive has more than 16 partitions -- not used", not cut
|
|
to 16 (#180); pulled; the same with an entry 19 outside the usable range:
|
|
"a damaged partition table" -- every entry checked (#180)
|
|
ident_attach_fail no drive at boot; a fresh data stick hot-plugged whose reads at its identity
|
|
partition's first sector (LBA 2048) fail, so that partition cannot be attached after
|
|
Artemis is: a message naming the identity partition, Artemis let go -- both or
|
|
neither (#179) -- no prompt; the same stick without the fault: genesis, the prompt
|
|
mint_part_fail as mint_fail, but only writes to the identity partition's first sector (LBA 2048)
|
|
fail: the GPT is written, then the mint fails -- "failed -- the stick was erased; Zuse
|
|
not minted", never "nothing changed" (#168); no replacement; the old stick: the prompt
|
|
system_pull_real logged in on her stick; the data stick pulled: hers let go first (no detach
|
|
refusal), session ended; the data stick replugged, hers still in: she is logged in
|
|
bam_flush --target qemu-stick --stick-gib 16: an Artemis block changed and SAVE-BUFFERS'd three
|
|
times, each timed (TIME:); each answers ok within 2 s (#155: it took 5-6 s); then the BAM's bytes on the
|
|
stick hashed (BAM:), to be the same before and after #155's change
|
|
stick_artemis ARTDISK= (no virtio disk): Artemis and Zuse from the Zuse stick alone -- the
|
|
stick's Artemis partition attached first (785938 user blocks), then its identity
|
|
(48724); [zuse@Hera] ok> (plan 2026-10-27-stick-4-one-disk.md, Task 4)
|
|
stick_zuse --target qemu-stick, the PC stick with Zuse's pair in it: a stick, Artemis attached,
|
|
[zuse@Hera] ok>
|
|
two_sticks --make "DATASTICK=1 ...": Zuse's stick on port 1, a blank data stick on port 2;
|
|
Zuse logs in; the data stick is "not this system's stick -- not used" (replaces
|
|
datastick)
|
|
artemis_unsigned the Zuse stick with its Artemis signature zeroed: "signature is bad -- not
|
|
used", nothing attached, headless
|
|
raw_ident Zuse's raw identity image, no GPT: "not this system's stick -- not used", headless
|
|
screen_boot KERNEL_ARGS=screen=boot, no drive: "Screen: the console stays on until login
|
|
(screen=boot)"; 30 s after POST the screen is not black; no ok> (plan
|
|
2026-10-27-stick-4-one-disk.md, Task 5)
|
|
stick_v3 --target qemu-stick, system=v3 in the stick's starforth.cfg: "Boot disk: a StarshipOS
|
|
stick", the refusal, then v4's POST; no v3 (plan 2026-10-27-stick-4-one-disk.md, Task 3)
|
|
entropy after "System: StarForth v4", the entropy backend -- rdrand on amd64 (qemu and
|
|
--target qemu-stick), virtio-rng on aarch64 and riscv64 -- then "entropy: ready";
|
|
on the qemu target, [zuse@Hera] ok> (plan 2026-10-27-stick-4-one-disk.md, Task 2)
|
|
|
|
Needs only Python 3. One QEMU at a time (.claude/CLAUDE.md).
|
|
"""
|
|
import argparse, glob, json, os, re, shlex, shutil, socket, subprocess, sys, threading, time
|
|
|
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
|
PROMPT = r"\[zuse@Hera\][^\n]*ok> "
|
|
ANYPROMPT = r"ok> "
|
|
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("mode")
|
|
ap.add_argument("arch")
|
|
ap.add_argument("--label", default=None)
|
|
ap.add_argument("--make", default="")
|
|
ap.add_argument("--no-zuse", action="store_true")
|
|
ap.add_argument("--target", default="qemu") # qemu-stick: boot the PC stick (amd64)
|
|
ap.add_argument("--stick-gib", type=int, default=None) # qemu-stick: the copy extended to N GiB
|
|
a = ap.parse_args()
|
|
|
|
NO_ZUSE_MODES = {"gpt_many", "ident_attach_fail", "gpt_zuse", "gpt_hotplug", "gpt_foreign", "gpt_bad_crc", "gpt_bad_entries", "gpt_no_header",
|
|
"gpt_read_error", "headless", "hotplug", "midpull", "waitpull", "typeahead", "emergency",
|
|
"alttab_after_logout", "alttab_before_pull", "emergency_pull",
|
|
"screen_dark_until_login", "screen_console_after_login", "screen_dark_after_logout",
|
|
"kbd_typeahead", "stick_boot", "stick_v3", "stick_zuse", "screen_boot", "genesis",
|
|
"stick_genesis", "stick_grow", "stick_small", "bam_flush",
|
|
"zuse_stick_first", "fallback", "replace", "mint_fail", "mint_part_fail", "system_pull_real"}
|
|
label = a.label or f"{a.mode}-{a.arch}"
|
|
work = os.path.join(ROOT, "build", "qemu-session", label)
|
|
shutil.rmtree(work, ignore_errors=True)
|
|
os.makedirs(work)
|
|
for f in ("artemis.img", "zuse-thumb-ident.img"):
|
|
subprocess.run(["cp", "--sparse=always", os.path.join(ROOT, "disk/zuse-scratch", f), work], check=True)
|
|
art = os.path.join(work, "artemis.img")
|
|
ident = os.path.join(work, "zuse-thumb-ident.img") # the raw identity image (GPT-mode payloads)
|
|
# Zuse's drive is her pair as a stick (plan 2026-10-27-stick-4-one-disk.md, Task 1): identity and
|
|
# Artemis partitions on one disk, built from this session's copies
|
|
zimg = os.path.join(work, "zusestick.img")
|
|
subprocess.run(["bash", os.path.join(ROOT, "scripts/mkdiskimage.sh"), "--out", zimg, "--table", "gpt",
|
|
"--label", "ZUSESTICK", "--esp-mib", "0", "--starship-from", ident, art],
|
|
check=True, stdout=subprocess.DEVNULL)
|
|
if a.mode == "artemis_unsigned":
|
|
# the Zuse stick with the 4 KiB artemis_sig_t zeroed: it is devblock total - 1 - 64
|
|
# (artemis_sig.c, ARTEMIS_SIG_DEVBLOCK_FROM_TOP), i.e. 65 4 KiB devblocks below the top of the
|
|
# Artemis partition, which starts 1 MiB + |ident| in
|
|
unsigned = os.path.join(work, "unsigned.img")
|
|
subprocess.run(["cp", "--sparse=always", zimg, unsigned], check=True)
|
|
sig_at = 1048576 + os.path.getsize(ident) + os.path.getsize(art) - 65 * 4096
|
|
with open(unsigned, "r+b") as f:
|
|
f.seek(sig_at)
|
|
f.write(bytes(4096))
|
|
# the modes that ask for the minted pair by name (plan 2026-10-29-stick-5, Task 3); the others
|
|
# boot the Makefile's defaults, or no drive at all
|
|
PAIR_MODES = {"stick_artemis", "two_sticks", "artemis_unsigned", "raw_ident", "v3_keys"}
|
|
|
|
# v3 reads identity drives raw, never through a GPT (only the v4 path reads one: sk_v4_identity.c),
|
|
# so a system=v3 boot gets Zuse's raw identity image, not her stick (plan 2026-10-27-stick-4, R2)
|
|
zdrive = {"v3_keys": ident, "raw_ident": ident}.get(a.mode, zimg)
|
|
if a.mode == "artemis_unsigned":
|
|
zdrive = unsigned
|
|
make_args = ["make", "-f", "kernel/Makefile", f"ARCH={a.arch}", "clean", a.target]
|
|
if a.mode in PAIR_MODES:
|
|
make_args += [f"ZUSEDISK={zdrive}", "DATASTICK="]
|
|
elif a.no_zuse or a.mode in NO_ZUSE_MODES:
|
|
make_args += ["ZUSEDISK=", "DATASTICK="] # no drive at boot
|
|
if a.mode == "v3_keys":
|
|
make_args.append(f"ARTDISK={art}") # v3's Artemis is the virtio disk
|
|
make_args += shlex.split(a.make)
|
|
if a.mode in ("v3_keys", "stick_v3"):
|
|
make_args.append("KERNEL_ARGS=system=v3")
|
|
if a.mode == "screen_boot":
|
|
make_args.append("KERNEL_ARGS=screen=boot")
|
|
if a.mode == "stick_zuse":
|
|
make_args.append(f"STICK_PAIR={work}") # the PC stick with this session's copy of the pair
|
|
if a.stick_gib:
|
|
make_args.append(f"STICK_GIB={a.stick_gib}")
|
|
if a.mode in ("stick_grow", "stick_small", "bam_flush"):
|
|
make_args.append("KERNEL_ARGS=--log-level=info") # the blk: disk lines the sizes are read from
|
|
if a.mode in ("zuse_stick_first", "fallback", "replace", "mint_fail", "mint_part_fail", "system_pull_real"):
|
|
# a data stick made once into the session's directory: minted on, then booted again
|
|
dstick = os.path.join(work, "data.img")
|
|
subprocess.run(["make", "-f", "kernel/Makefile", f"ARCH={a.arch}", "datastick", f"DATASTICK_IMG={dstick}"],
|
|
cwd=ROOT, check=True, stdout=subprocess.DEVNULL)
|
|
make_args += ["DATASTICK=1", f"DATASTICK_IMG={dstick}", "DATASTICK_DEP="]
|
|
if a.mode == "gpt_many":
|
|
# made before the boot, so a failure here leaves no QEMU running
|
|
import struct, zlib
|
|
many = os.path.join(work, "many.img")
|
|
subprocess.run(["make", "-f", "kernel/Makefile", f"ARCH={a.arch}", "datastick", f"DATASTICK_IMG={many}"],
|
|
cwd=ROOT, check=True, stdout=subprocess.DEVNULL)
|
|
sg = ["sgdisk", "-a", "1", "--transpose=1:17", "--transpose=2:18"]
|
|
for k in range(1, 17): # 16 fillers in the free sectors after Artemis (the
|
|
lo = 3143680 + (k - 1) * 64 # first usable is 2048: none before the identity)
|
|
sg += ["-n", f"{k}:{lo}:{lo + 63}", "-t", f"{k}:8300"]
|
|
subprocess.run(sg + [many], check=True, stdout=subprocess.DEVNULL)
|
|
bad = os.path.join(work, "many-bad.img")
|
|
subprocess.run(["cp", "--sparse=always", many, bad], check=True)
|
|
with open(bad, "r+b") as fh: # entry 19 past the last usable LBA, CRCs made good
|
|
fh.seek(512); hdr = bytearray(fh.read(92))
|
|
ent_lba, nent, esz = struct.unpack_from("<QII", hdr, 72)
|
|
last_usable = struct.unpack_from("<Q", hdr, 48)[0]
|
|
fh.seek(ent_lba * 512); ents = bytearray(fh.read(nent * esz))
|
|
o = 18 * esz
|
|
ents[o:o + 16] = bytes.fromhex("af3dc60f838472478e793d69d8477de4")
|
|
ents[o + 16:o + 32] = bytes(range(1, 17))
|
|
struct.pack_into("<QQ", ents, o + 32, last_usable - 8, last_usable + 64)
|
|
struct.pack_into("<I", hdr, 88, zlib.crc32(ents) & 0xFFFFFFFF)
|
|
struct.pack_into("<I", hdr, 16, 0); struct.pack_into("<I", hdr, 16, zlib.crc32(hdr) & 0xFFFFFFFF)
|
|
fh.seek(ent_lba * 512); fh.write(ents)
|
|
fh.seek(512); fh.write(hdr)
|
|
if a.mode == "genesis":
|
|
# a fresh data stick, made once into this session's directory and booted twice: the second
|
|
# boot is the same copy, so it finds what the first wrote (plan 2026-10-29-stick-5, Task 1)
|
|
dstick = os.path.join(work, "data.img")
|
|
subprocess.run(["make", "-f", "kernel/Makefile", f"ARCH={a.arch}", "datastick", f"DATASTICK_IMG={dstick}"],
|
|
cwd=ROOT, check=True, stdout=subprocess.DEVNULL)
|
|
make_args += ["DATASTICK=1", f"DATASTICK_IMG={dstick}", "DATASTICK_DEP="]
|
|
def newest(pattern):
|
|
c = [p for p in glob.glob(pattern) if os.path.getmtime(p) >= start]
|
|
return max(c, key=os.path.getmtime) if c else None
|
|
|
|
|
|
def drain():
|
|
while True:
|
|
try:
|
|
if not s.recv(4096):
|
|
return
|
|
except OSError:
|
|
return
|
|
|
|
|
|
def qcmd(cmd, **args):
|
|
msg = {"execute": cmd}
|
|
if args:
|
|
msg["arguments"] = args
|
|
q.send(json.dumps(msg).encode())
|
|
while True:
|
|
r = json.loads(qf.readline())
|
|
if "return" in r or "error" in r:
|
|
if "error" in r:
|
|
print(f"QMP {cmd}: {json.dumps(r)}", flush=True)
|
|
return r
|
|
|
|
|
|
def boot(args):
|
|
"""One `make ... qemu` boot: QEMU in the foreground of make, its serial log, serial and QMP
|
|
sockets found and connected (the globals every check reads)."""
|
|
global start, mk, log, s, q, qf
|
|
start = time.time()
|
|
make_log = open(os.path.join(work, "make.txt"), "a")
|
|
mk = subprocess.Popen(args, cwd=ROOT, stdout=make_log, stderr=subprocess.STDOUT)
|
|
deadline = time.time() + 1800
|
|
log = ser = qmp = None
|
|
while time.time() < deadline and not (log and ser and qmp):
|
|
if mk.poll() is not None:
|
|
print(f"MAKE FAILED (exit {mk.returncode}); see {make_log.name}", flush=True)
|
|
sys.exit(1)
|
|
log = log or newest(f"{ROOT}/logs/*/{a.arch}/qemu-{a.arch}-*.log")
|
|
ser = ser or newest(f"{ROOT}/build/{a.arch}/kernel/qemu-serial-{a.arch}-*.sock")
|
|
qmp = qmp or newest(f"{ROOT}/build/{a.arch}/kernel/qemu-qmp-{a.arch}-*.sock")
|
|
time.sleep(1)
|
|
print(f"LOG: {os.path.relpath(log, ROOT)}", flush=True)
|
|
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
for _ in range(60):
|
|
try:
|
|
s.connect(ser)
|
|
break
|
|
except OSError:
|
|
time.sleep(1)
|
|
threading.Thread(target=drain, daemon=True).start()
|
|
q = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
q.connect(qmp)
|
|
qf = q.makefile("r")
|
|
qf.readline()
|
|
qcmd("qmp_capabilities")
|
|
|
|
|
|
def shutdown():
|
|
"""Quit QEMU over QMP and let make finish: one QEMU at a time (.claude/CLAUDE.md)."""
|
|
q.send(json.dumps({"execute": "quit"}).encode())
|
|
mk.wait()
|
|
time.sleep(2)
|
|
|
|
|
|
ok = True
|
|
boot(make_args)
|
|
|
|
|
|
def text():
|
|
with open(log, errors="replace") as f:
|
|
return f.read()
|
|
|
|
|
|
def count(pat):
|
|
return len(re.findall(pat, text()))
|
|
|
|
|
|
def wait_for(pat, secs, after=0):
|
|
t = time.time()
|
|
while time.time() - t < secs:
|
|
if count(pat) > after:
|
|
return True
|
|
if "POST: FAILED" in text() or "PARITY:FAIL" in text():
|
|
return False
|
|
time.sleep(0.5)
|
|
return False
|
|
|
|
|
|
def excerpt(near=None, after=20, tail=40):
|
|
"""The serial log where a failed check looked (#136): the lines after the first match of
|
|
`near`, else the log's last lines -- control characters shown as escapes, so a terminal's
|
|
sequences cannot garble the job's output."""
|
|
lines = text().splitlines()
|
|
start = None
|
|
if near is not None:
|
|
start = next((i for i, l in enumerate(lines) if re.search(near, l)), None)
|
|
if start is None:
|
|
start, what = max(0, len(lines) - tail), f"the log's last {tail} lines"
|
|
stop = len(lines)
|
|
else:
|
|
stop, what = min(len(lines), start + 1 + after), f"after /{near}/, line {start + 1}"
|
|
print(f" --- serial log, {what} ({os.path.relpath(log, ROOT)}):", flush=True)
|
|
for i in range(start, stop):
|
|
shown = "".join(c if c.isprintable() else repr(c)[1:-1] for c in lines[i])
|
|
print(f" {i + 1:6} | {shown}", flush=True)
|
|
print(" ---", flush=True)
|
|
|
|
|
|
def cpu_snapshot(times=3, apart=1.0):
|
|
"""Where the CPUs are (Captain Bob, 2026-11-19: "Diagnose on CI"): QEMU's monitor asked for
|
|
the registers `times` times, `apart` seconds apart, and the lines that name the program
|
|
counter printed, with the code at it (`x /8wx` at that address, which names the function offline: the image is
|
|
loaded where the firmware puts it) -- so a failed check's log shows where the kernel is, and
|
|
whether it moves.
|
|
A monitor that does not answer is said, and the run goes on."""
|
|
for k in range(times):
|
|
try:
|
|
r = qcmd("human-monitor-command", **{"command-line": "info registers"})
|
|
said = r.get("return", "") if isinstance(r, dict) else str(r)
|
|
except Exception as e: # the monitor gone: the run is not stopped by it
|
|
print(f" --- the CPUs, {k + 1} of {times}: the monitor did not answer ({e})", flush=True)
|
|
return
|
|
pcs = [l.strip() for l in said.splitlines() if re.search(r"\b(PC|RIP|EIP|pc)\s*[=:]?\s*[0-9a-fA-F]", l)]
|
|
print(f" --- the CPUs, {k + 1} of {times}: " + (" | ".join(pcs) if pcs else said.strip()[:200]), flush=True)
|
|
m = re.search(r"\b(?:PC|RIP|EIP|pc)\s*[=:]?\s*([0-9a-fA-F]+)", said)
|
|
if not m:
|
|
continue
|
|
try: # the code there: unique enough to name the function offline
|
|
c = qcmd("human-monitor-command", **{"command-line": f"x /8wx 0x{m.group(1)}"})
|
|
code = c.get("return", "") if isinstance(c, dict) else str(c)
|
|
print(f" the code at the PC: {' '.join(code.split())[:200]}", flush=True)
|
|
except Exception as e:
|
|
print(f" the code at the PC: the monitor did not answer ({e})", flush=True)
|
|
if k + 1 < times:
|
|
time.sleep(apart)
|
|
|
|
|
|
def check(name, cond, near=None):
|
|
"""PASS or FAIL; a FAIL also prints the serial log where the check looked: after the first
|
|
line matching `near` (a regex), when it is given, else the log's end -- and where the CPUs
|
|
are (cpu_snapshot)."""
|
|
global ok
|
|
print(f"{'PASS' if cond else 'FAIL'}: {name}", flush=True)
|
|
if not cond:
|
|
excerpt(near)
|
|
cpu_snapshot()
|
|
ok = ok and cond
|
|
|
|
|
|
def type_line(line):
|
|
"""Over the serial line, a character at a time."""
|
|
for ch in line:
|
|
s.send(ch.encode())
|
|
time.sleep(0.05)
|
|
s.send(b"\r")
|
|
|
|
|
|
# QEMU qcodes for what the tests type on a keyboard
|
|
QCODE = {" ": ["spc"], ".": ["dot"], "+": ["shift", "equal"], "-": ["minus"], "\n": ["ret"]}
|
|
|
|
|
|
def key_line(line):
|
|
"""On QEMU's keyboard (send-key), a key at a time."""
|
|
for ch in line + "\n":
|
|
keys = QCODE.get(ch, [ch.lower()])
|
|
qcmd("send-key", keys=[{"type": "qcode", "data": k} for k in keys])
|
|
time.sleep(0.1)
|
|
|
|
|
|
# The two StarshipOS partition type GUIDs (docs/v4.0.0/plans/2026-10-26-stick-2-gpt-reader.md)
|
|
GPT_IDENTITY = "23BEBFE1-4817-4CF3-A537-9069BF159788"
|
|
GPT_LINUX = "0FC63DAF-8483-4772-8E79-3D69D8477DE4"
|
|
|
|
|
|
def make_gpt_image(path, ptype, payload, mib=72, break_crc=False, break_entries=False, break_sig=False):
|
|
"""A GPT disk image: one partition at LBA 2048, 131072 sectors (64 MiB), of type
|
|
`ptype`, holding `payload` from its start; optionally the primary header's CRC broken,
|
|
a byte of the entry array changed (the header left valid), or the header's "EFI PART"
|
|
signature zeroed (the protective MBR left in place)."""
|
|
subprocess.run(["truncate", "-s", f"{mib}M", path], check=True)
|
|
sf = shutil.which("sfdisk") or "/usr/sbin/sfdisk"
|
|
subprocess.run([sf, "--quiet", path], input=f"label: gpt\nstart=2048, size=131072, type={ptype}\n",
|
|
text=True, check=True)
|
|
subprocess.run(["dd", f"if={payload}", f"of={path}", "bs=512", "seek=2048", "conv=notrunc,sparse",
|
|
"status=none"], check=True)
|
|
if break_crc:
|
|
with open(path, "r+b") as f:
|
|
f.seek(512 + 16) # the primary header's HeaderCRC32
|
|
b = f.read(1)
|
|
f.seek(512 + 16)
|
|
f.write(bytes([b[0] ^ 0xFF]))
|
|
if break_entries:
|
|
with open(path, "r+b") as f:
|
|
f.seek(1024 + 56) # entry 0's name, inside the CRC'd entry array
|
|
b = f.read(1)
|
|
f.seek(1024 + 56)
|
|
f.write(bytes([b[0] ^ 0xFF]))
|
|
if break_sig:
|
|
with open(path, "r+b") as f:
|
|
f.seek(512) # the primary header's Signature
|
|
f.write(bytes(8))
|
|
|
|
|
|
def blk_lines():
|
|
return count(r"blk: ")
|
|
|
|
|
|
def alt_tab():
|
|
qcmd("send-key", keys=[{"type": "qcode", "data": "alt"}, {"type": "qcode", "data": "tab"}])
|
|
time.sleep(1)
|
|
|
|
|
|
SHOTS = 0
|
|
|
|
|
|
def screen():
|
|
"""A screendump of QEMU's display: (width, height, number of non-black pixels, bytes)."""
|
|
global SHOTS
|
|
SHOTS += 1
|
|
path = os.path.join(work, f"screen-{SHOTS}.ppm")
|
|
qcmd("screendump", filename=path)
|
|
for _ in range(20):
|
|
if os.path.exists(path) and os.path.getsize(path) > 0:
|
|
break
|
|
time.sleep(0.5)
|
|
with open(path, "rb") as f:
|
|
data = f.read()
|
|
parts = data.split(b"\n", 3) # P6, "w h", maxval, pixels
|
|
w, h = (int(x) for x in parts[1].split())
|
|
px = parts[3]
|
|
lit = sum(1 for i in range(0, len(px) - 2, 3) if px[i] or px[i + 1] or px[i + 2])
|
|
return w, h, lit, px
|
|
|
|
|
|
def add_zuse(n, img=None, fail_sector0=False):
|
|
f = {"driver": "file", "filename": img or zimg}
|
|
if fail_sector0: # every read touching sector 0 fails, EIO
|
|
f = {"driver": "blkdebug", "image": f,
|
|
"inject-error": [{"event": "none", "iotype": "read", "sector": 0, "errno": 5}]}
|
|
qcmd("blockdev-add", driver="raw", **{"node-name": f"zuse{n}"}, file=f)
|
|
qcmd("device_add", driver="usb-storage", bus="xhci0.0", port="1",
|
|
drive=f"zuse{n}", id=f"zusedev{n}")
|
|
|
|
|
|
def add_stick(n, img, port, fail_writes=False, fail_sector=None, fail_read_sector=None):
|
|
"""A USB stick added over QMP on the xHCI controller's `port` (plan 2026-10-29-stick-5, Task 4);
|
|
with fail_writes, every write to it fails (blkdebug, EIO -- Task 5's mint_fail); with fail_sector,
|
|
only writes touching that sector fail (#168's mint_part_fail); with fail_read_sector, only reads
|
|
touching that sector fail (#179's ident_attach_fail)."""
|
|
f = {"driver": "file", "filename": img}
|
|
if fail_writes:
|
|
f = {"driver": "blkdebug", "image": f, "inject-error": [{"event": "none", "iotype": "write", "errno": 5}]}
|
|
elif fail_sector is not None:
|
|
f = {"driver": "blkdebug", "image": f,
|
|
"inject-error": [{"event": "none", "iotype": "write", "sector": fail_sector, "errno": 5}]}
|
|
elif fail_read_sector is not None:
|
|
f = {"driver": "blkdebug", "image": f,
|
|
"inject-error": [{"event": "none", "iotype": "read", "sector": fail_read_sector, "errno": 5}]}
|
|
qcmd("blockdev-add", driver="raw", **{"node-name": f"stick{n}"}, file=f)
|
|
qcmd("device_add", driver="usb-storage", bus="xhci0.0", port=str(port), drive=f"stick{n}", id=f"stickdev{n}")
|
|
|
|
|
|
def del_zuse(n):
|
|
qcmd("device_del", id=f"zusedev{n}")
|
|
time.sleep(3)
|
|
qcmd("blockdev-del", **{"node-name": f"zuse{n}"})
|
|
|
|
|
|
def physics():
|
|
"""A v4 boot's physics, before its prompt (#189: "a boot without the physics fails"; plan
|
|
2026-11-13-engine-step4-phase1, Task 4): the Stadium made, conservation checked, the heartbeat
|
|
ticking. A v3 boot prints the same lines (kernel_main.c, stadium_words.c)."""
|
|
check("the Stadium: its cells allocated", re.search(r"Stadium: \d+ cells", text()) is not None)
|
|
check("the Stadium: conservation CONSERVED", wait_for(r"Stadium conservation: CONSERVED", 120))
|
|
check("the heartbeat: ticking", wait_for(r"Heartbeat: [1-9]\d* ticks", 120))
|
|
# Phase 2 (#189): Hera's words are in the Stadium -- every call to a word counted on the kernel's record
|
|
# of it, joined by the word ID in its header, and charged after POST (Captain Bob, 2026-11-13)
|
|
check("the Stadium: Hera's words admitted after POST",
|
|
re.search(r"Stadium words: promotions=[1-9]\d*", text()) is not None)
|
|
|
|
|
|
def registry():
|
|
"""Hera in the kernel's fabric and registry (#189, Phase 1 Task 5a): NODE-ME, made by centre.4th,
|
|
is answered by the kernel with her place, 0 -- as the host mesh answers it (test_host_unit.c)."""
|
|
n = count(PROMPT)
|
|
type_line("NODE-ME .")
|
|
check("NODE-ME: Hera is at place 0 of the kernel's fabric",
|
|
wait_for(PROMPT, 60, n) and re.search(r"(?:^|[^0-9])0\s+ok", text()[-200:]) is not None
|
|
and "UNKNOWN WORD" not in text()[-200:])
|
|
births()
|
|
|
|
|
|
def births():
|
|
"""A node born from Hera in the kernel's fabric, answering, and killed (#189, Phase 1 Task 5d):
|
|
11 2 2 BIRTH gives it the nucleus and FORTH-79 (its parity line); Hera sends it a line and awaits
|
|
it; 11 KILL removes it, its Stadium quota given back, and conservation holds after."""
|
|
n = count(PROMPT)
|
|
type_line("11 2 2 BIRTH .")
|
|
check("BIRTH: node 11 born from Hera, its parity recorded",
|
|
wait_for(PROMPT, 300, n) and re.search(r"PARITY:V4_BIRTH node=11 dict_hash=0x[0-9a-f]{16}", text()) is not None
|
|
and "ERROR" not in text()[-300:])
|
|
n = count(PROMPT)
|
|
type_line('S" 6 7 * ." 11 SEND 11 AWAIT .')
|
|
check("node 11 answers Hera: 42, and its text completed",
|
|
wait_for(PROMPT, 120, n) and re.search(r"42\s", text()[-300:]) is not None and "ERROR" not in text()[-300:])
|
|
c = count(r"Stadium conservation: CONSERVED")
|
|
n = count(PROMPT)
|
|
type_line("11 KILL")
|
|
check("KILL: node 11 removed, the Stadium CONSERVED after",
|
|
wait_for(PROMPT, 120, n) and count(r"Stadium conservation: CONSERVED") > c and "ERROR" not in text()[-300:])
|
|
# the edges (Captain Bob, 2026-11-13: "Check for the edge cases"): a node set running for ever
|
|
# does not hold the console -- it runs on between lines, and is killed
|
|
n = count(PROMPT)
|
|
type_line("11 2 2 BIRTH .")
|
|
check("after a kill, 11 is born again", wait_for(PROMPT, 300, n) and "ERROR" not in text()[-300:])
|
|
n = count(PROMPT)
|
|
type_line('S" VARIABLE N1 : SPIN BEGIN 1 N1 +! AGAIN ;" 11 SEND 11 AWAIT .')
|
|
check("node 11 is given SPIN", wait_for(PROMPT, 120, n) and "ERROR" not in text()[-300:])
|
|
n = count(PROMPT)
|
|
type_line('S" SPIN" 11 SEND')
|
|
check("Hera's line ends, though node 11 runs for ever", wait_for(PROMPT, 120, n) and "ERROR" not in text()[-300:])
|
|
n = count(PROMPT)
|
|
type_line("3 4 + .")
|
|
check("and the prompt answers while it runs: 7 ok", wait_for(PROMPT, 120, n) and re.search(r"7\s+ok", text()[-300:]) is not None)
|
|
c = count(r"Stadium conservation: CONSERVED")
|
|
n = count(PROMPT)
|
|
type_line("11 KILL")
|
|
check("a node running for ever is killed, the Stadium CONSERVED after",
|
|
wait_for(PROMPT, 120, n) and count(r"Stadium conservation: CONSERVED") > c and "ERROR" not in text()[-300:])
|
|
|
|
|
|
check("POST: PASSED", wait_for(r"POST: PASSED", 900))
|
|
m = a.mode
|
|
|
|
if m == "headless":
|
|
check("no ok> for 60 s after POST", not wait_for(ANYPROMPT, 60))
|
|
|
|
elif m == "zuse":
|
|
check("Boot disk: not a StarshipOS stick (an ISO or ESP boot)",
|
|
re.search(r"Boot disk: not a StarshipOS stick", text()) is not None, near=r"Boot successful!")
|
|
check("Zuse: genesis minted onto attached thumbdrive (a fresh data stick)",
|
|
wait_for(r"Zuse: genesis minted onto attached thumbdrive", 180), near=r"Artemis: |Zuse: |USB: ")
|
|
physics()
|
|
check("[zuse@Hera] ok>", wait_for(PROMPT, 60))
|
|
n = count(PROMPT)
|
|
type_line("3 4 + .")
|
|
check("7 ok, and a prompt", wait_for(PROMPT, 60, n) and re.search(r"7\s+ok", text()) is not None)
|
|
registry()
|
|
|
|
elif m in ("stick_boot", "two_sticks"):
|
|
def disks():
|
|
# "us", not "user": the kernel cuts log messages at 63 characters (LOG_LINE_MAX 64,
|
|
# v3/include/vm.h), and with seven-digit LBNs the attach line ends "(383542 us"
|
|
return [int(u) for u in re.findall(r"blk: disk .*?\((\d+) us", text())]
|
|
if m == "stick_boot":
|
|
# the PC stick: Artemis is the rest of 2 GiB (well over 1 million user blocks), its blank
|
|
# identity 500 MiB (about 380000)
|
|
check("Boot disk: a StarshipOS stick", re.search(r"Boot disk: a StarshipOS stick", text()) is not None, near=r"Boot successful!")
|
|
check("System: StarForth v4", re.search(r"System: StarForth v4", text()) is not None)
|
|
check("Artemis: the stick's partition attached",
|
|
wait_for(r"Artemis: the stick's partition attached", 120))
|
|
check("Zuse: genesis minted onto attached thumbdrive",
|
|
wait_for(r"Zuse: genesis minted onto attached thumbdrive", 120))
|
|
check("[zuse@Hera] ok>", wait_for(PROMPT, 60))
|
|
d = disks()
|
|
check(f"Artemis attached first, then the identity partition (user blocks {d})",
|
|
len(d) >= 2 and d[0] > 1000000 and 300000 < d[1] < 512000)
|
|
else:
|
|
check("Zuse: identity confirmed", wait_for(r"Zuse: identity confirmed from attached thumbdrive", 120))
|
|
check("[zuse@Hera] ok>", wait_for(PROMPT, 60))
|
|
n = count(PROMPT)
|
|
type_line("3 4 + .")
|
|
check("7 ok", wait_for(PROMPT, 60, n) and re.search(r"7\s+ok", text()[-400:]) is not None)
|
|
check(f"two USB drives found ({count(r'blkio_usb: MSC device ready')})",
|
|
count(r"blkio_usb: MSC device ready") >= 2)
|
|
time.sleep(5)
|
|
nu = count(r"USB: a drive that is not this system's stick -- not used")
|
|
check(f"the data stick: not this system's stick -- not used (said {nu} times)", nu == 1)
|
|
d = disks()
|
|
check(f"nothing of the data stick attached (user blocks {d})", not any(300000 < u < 512000 for u in d))
|
|
check("no fault", count(r"EXCEPTION|PANIC|panic") == 0)
|
|
|
|
elif m in ("stick_artemis", "stick_zuse"):
|
|
if m == "stick_zuse":
|
|
check("Boot disk: a StarshipOS stick", re.search(r"Boot disk: a StarshipOS stick", text()) is not None, near=r"Boot successful!")
|
|
check("Artemis: the stick's partition attached", wait_for(r"Artemis: the stick's partition attached", 120))
|
|
check("Zuse: identity confirmed", wait_for(r"Zuse: identity confirmed from attached thumbdrive", 120))
|
|
check("[zuse@Hera] ok>", wait_for(PROMPT, 60))
|
|
if m == "stick_artemis":
|
|
d = [int(u) for u in re.findall(r"blk: disk .*?\((\d+) us", text())]
|
|
check(f"Artemis first (785938 user blocks), then the identity (48724): {d}", d[:2] == [785938, 48724])
|
|
n = count(PROMPT)
|
|
type_line("3 4 + .")
|
|
check("7 ok", wait_for(PROMPT, 60, n) and re.search(r"7\s+ok", text()[-400:]) is not None)
|
|
check("no fault", count(r"EXCEPTION|PANIC|panic") == 0)
|
|
|
|
elif m in ("artemis_unsigned", "raw_ident"):
|
|
if m == "artemis_unsigned":
|
|
check("Artemis: the stick's signature is bad -- not used",
|
|
wait_for(r"Artemis: the stick's signature is bad -- not used", 120))
|
|
else:
|
|
check("USB: a drive that is not this system's stick -- not used",
|
|
wait_for(r"USB: a drive that is not this system's stick -- not used", 120))
|
|
check("no ok> for 60 s", not wait_for(ANYPROMPT, 60))
|
|
check("no identity", count(r"Zuse: identity confirmed") == 0)
|
|
check("no blk: disk line (nothing attached)", count(r"blk: disk ") == 0)
|
|
check("no fault", count(r"EXCEPTION|PANIC|panic") == 0)
|
|
|
|
elif m in ("genesis", "stick_genesis"):
|
|
if m == "stick_genesis":
|
|
check("Boot disk: a StarshipOS stick", re.search(r"Boot disk: a StarshipOS stick", text()) is not None,
|
|
near=r"Boot successful!")
|
|
check("Zuse: genesis minted onto attached thumbdrive",
|
|
wait_for(r"Zuse: genesis minted onto attached thumbdrive", 180), near=r"Artemis: |Zuse: ")
|
|
physics()
|
|
check("[zuse@Hera] ok>", wait_for(PROMPT, 60))
|
|
check("no identity confirmed on a first boot", count(r"Zuse: identity confirmed") == 0)
|
|
n = count(PROMPT)
|
|
type_line("3 4 + .")
|
|
check("7 ok", wait_for(PROMPT, 60, n) and re.search(r"7\s+ok", text()[-400:]) is not None)
|
|
registry()
|
|
check("no fault", count(r"EXCEPTION|PANIC|panic") == 0)
|
|
if m == "genesis":
|
|
shutdown()
|
|
print("-- the second boot, the same copy of the data stick", flush=True)
|
|
boot([x for x in make_args if x != "clean"])
|
|
check("POST: PASSED (second boot)", wait_for(r"POST: PASSED", 900))
|
|
check("Zuse: identity confirmed (second boot)",
|
|
wait_for(r"Zuse: identity confirmed from attached thumbdrive", 120), near=r"Artemis: |Zuse: ")
|
|
check("no genesis on the second boot", count(r"Zuse: genesis minted") == 0)
|
|
check("[zuse@Hera] ok> (second boot)", wait_for(PROMPT, 60))
|
|
n = count(PROMPT)
|
|
type_line("3 4 + .")
|
|
check("7 ok (second boot)", wait_for(PROMPT, 60, n) and re.search(r"7\s+ok", text()[-400:]) is not None)
|
|
check("no fault (second boot)", count(r"EXCEPTION|PANIC|panic") == 0)
|
|
|
|
elif m in ("stick_grow", "stick_small"):
|
|
def artemis_blocks():
|
|
u = re.findall(r"blk: disk .*?\((\d+) us", text())
|
|
return int(u[0]) if u else None
|
|
t0 = time.time()
|
|
if m == "stick_grow":
|
|
check("Artemis: grown to fill the stick", wait_for(r"Artemis: grown to fill the stick", 300),
|
|
near=r"Artemis: |GPT: ")
|
|
else:
|
|
check("Artemis: the stick is under 8 GB -- not grown",
|
|
wait_for(r"Artemis: the stick is under 8 GB -- not grown", 300), near=r"Artemis: |GPT: ")
|
|
check("Zuse: genesis minted onto attached thumbdrive",
|
|
wait_for(r"Zuse: genesis minted onto attached thumbdrive", 300), near=r"Artemis: |Zuse: ")
|
|
check("[zuse@Hera] ok>", wait_for(PROMPT, 120))
|
|
print(f"TIME: POST to the prompt, first boot: {time.time() - t0:.0f} s", flush=True)
|
|
b1 = artemis_blocks()
|
|
if m == "stick_grow":
|
|
check(f"Artemis over 12000000 user blocks ({b1})", b1 is not None and b1 > 12000000)
|
|
else:
|
|
check(f"Artemis at the image's size, 1000000..1200000 user blocks ({b1})",
|
|
b1 is not None and 1000000 < b1 < 1200000)
|
|
check("no fault", count(r"EXCEPTION|PANIC|panic") == 0)
|
|
if m == "stick_grow":
|
|
shutdown()
|
|
print("-- the second boot, the same copy of the stick", flush=True)
|
|
boot([x for x in make_args if x != "clean"] + ["STICK_FRESH=0"])
|
|
check("POST: PASSED (second boot)", wait_for(r"POST: PASSED", 900))
|
|
check("Zuse: identity confirmed (second boot)",
|
|
wait_for(r"Zuse: identity confirmed from attached thumbdrive", 300), near=r"Artemis: |Zuse: ")
|
|
check("[zuse@Hera] ok> (second boot)", wait_for(PROMPT, 120))
|
|
check("not grown again", count(r"Artemis: grown") == 0)
|
|
b2 = artemis_blocks()
|
|
check(f"the same Artemis size ({b1} -> {b2})", b2 == b1)
|
|
check("no fault (second boot)", count(r"EXCEPTION|PANIC|panic") == 0)
|
|
shutdown()
|
|
sf = shutil.which("sfdisk") or "/usr/sbin/sfdisk"
|
|
run = os.path.join(ROOT, "build", a.arch, "kernel", "stick-run.img")
|
|
v = subprocess.run([sf, "--verify", run], capture_output=True, text=True)
|
|
print(v.stdout.strip() + v.stderr.strip(), flush=True)
|
|
check("sfdisk --verify on the grown copy: clean",
|
|
v.returncode == 0 and "No errors detected" in v.stdout + v.stderr)
|
|
boot_done = True
|
|
|
|
elif m in ("mint_zuse_refuse", "mint_small", "mint_zuse_used", "mint_pull_system", "zuse_stick_first"):
|
|
import hashlib
|
|
|
|
def sha(path):
|
|
with open(path, "rb") as f:
|
|
return hashlib.sha256(f.read()).hexdigest()
|
|
|
|
def mint_offer(img, port=3, n=1):
|
|
c = count(r"MINT-ZUSE: plug in the stick for the real Zuse")
|
|
type_line("MINT-ZUSE")
|
|
check("MINT-ZUSE: plug in the stick for the real Zuse",
|
|
wait_for(r"MINT-ZUSE: plug in the stick for the real Zuse", 60, c), near=r"MINT-ZUSE")
|
|
if img:
|
|
add_stick(n, img, port)
|
|
|
|
check("[zuse@Hera] ok> (the proxy, on a fresh data stick)", wait_for(PROMPT, 300))
|
|
if m == "mint_zuse_refuse":
|
|
img = os.path.join(work, "offered.img")
|
|
subprocess.run(["truncate", "-s", "600M", img], check=True)
|
|
before = sha(img)
|
|
mint_offer(img)
|
|
check("the size line", wait_for(r"MINT-ZUSE: a stick of 600 MiB -- all of it is erased", 120), near=r"MINT-ZUSE")
|
|
wait_for(r"MINT-ZUSE: type YES to write it", 30)
|
|
n = count(PROMPT)
|
|
type_line("no")
|
|
check("MINT-ZUSE: stopped -- nothing written", wait_for(r"MINT-ZUSE: stopped -- nothing written", 60), near=r"MINT-ZUSE")
|
|
check("the prompt", wait_for(PROMPT, 60, n))
|
|
check("no real Zuse minted", count(r"real Zuse minted") == 0)
|
|
# a second MINT-ZUSE: the same stick, still plugged in, offered again
|
|
type_line("MINT-ZUSE")
|
|
check("offered again: the size line a second time",
|
|
wait_for(r"MINT-ZUSE: a stick of 600 MiB -- all of it is erased", 60, 1), near=r"MINT-ZUSE")
|
|
wait_for(r"MINT-ZUSE: type YES to write it", 30, 1)
|
|
n = count(PROMPT)
|
|
type_line("no")
|
|
check("stopped again", wait_for(r"MINT-ZUSE: stopped -- nothing written", 60, 1))
|
|
check("the prompt again", wait_for(PROMPT, 60, n))
|
|
shutdown()
|
|
boot_done = True
|
|
check("the offered stick's bytes are the same (sha256)", sha(img) == before)
|
|
elif m == "mint_small":
|
|
img = os.path.join(work, "small.img")
|
|
subprocess.run(["truncate", "-s", "32M", img], check=True)
|
|
before = sha(img)
|
|
n = count(PROMPT)
|
|
mint_offer(img)
|
|
check("MINT-ZUSE: the stick is under 64 MiB", wait_for(r"MINT-ZUSE: the stick is under 64 MiB", 120), near=r"MINT-ZUSE")
|
|
check("the prompt", wait_for(PROMPT, 60, n))
|
|
check("no real Zuse minted", count(r"real Zuse minted") == 0)
|
|
shutdown()
|
|
boot_done = True
|
|
check("the small stick's bytes are the same (sha256)", sha(img) == before)
|
|
elif m == "mint_zuse_used":
|
|
img = os.path.join(work, "used.img")
|
|
subprocess.run(["cp", "--sparse=always", zimg, img], check=True) # the pair's Zuse stick
|
|
mint_offer(img)
|
|
check("the size line names the used stick", wait_for(r"MINT-ZUSE: a stick of \d+ MiB -- all of it is erased", 120),
|
|
near=r"MINT-ZUSE")
|
|
wait_for(r"MINT-ZUSE: type YES to write it", 30)
|
|
type_line("YES")
|
|
minted = wait_for(r"Zuse: real Zuse minted onto the second stick", 300)
|
|
check("Zuse: real Zuse minted onto the second stick", minted, near=r"MINT-ZUSE|Zuse:")
|
|
t = text()
|
|
after = t[t.find("real Zuse minted"):] if minted else ""
|
|
check("the new Zuse recognised on it", "Zuse: identity confirmed from attached thumbdrive" in after)
|
|
shutdown()
|
|
boot_done = True
|
|
sf = shutil.which("sfdisk") or "/usr/sbin/sfdisk"
|
|
j = subprocess.run([sf, "--json", img], capture_output=True, text=True)
|
|
parts = json.loads(j.stdout)["partitiontable"]["partitions"] if j.returncode == 0 and j.stdout else []
|
|
check(f"rewritten: one identity partition, no Artemis ({len(parts)} partition(s))",
|
|
len(parts) == 1 and parts[0]["type"].upper() == GPT_IDENTITY)
|
|
elif m == "mint_pull_system":
|
|
mint_offer(None)
|
|
time.sleep(3)
|
|
qcmd("device_del", id="datadev")
|
|
check("MINT-ZUSE: stopped -- nothing written", wait_for(r"MINT-ZUSE: stopped -- nothing written", 120), near=r"MINT-ZUSE")
|
|
check("Zuse: session ended", wait_for(r"Zuse: session ended -- reattach to re-authenticate", 60))
|
|
n = count(ANYPROMPT)
|
|
check("headless: no new ok> for 20 s", not wait_for(ANYPROMPT, 20, n))
|
|
data = os.path.join(ROOT, "build", a.arch, "kernel", "datastick.img")
|
|
c = count(r"Zuse: identity confirmed from attached thumbdrive")
|
|
add_stick(9, data, 2)
|
|
check("replugged: the proxy logs in again", wait_for(r"Zuse: identity confirmed from attached thumbdrive", 120, c))
|
|
check("no real Zuse minted", count(r"real Zuse minted") == 0)
|
|
elif m == "zuse_stick_first":
|
|
img = os.path.join(work, "zuse-real.img")
|
|
subprocess.run(["truncate", "-s", "600M", img], check=True)
|
|
mint_offer(img)
|
|
wait_for(r"MINT-ZUSE: type YES to write it", 120)
|
|
type_line("YES")
|
|
check("the real Zuse minted", wait_for(r"Zuse: real Zuse minted onto the second stick", 300), near=r"MINT-ZUSE|Zuse:")
|
|
shutdown()
|
|
print("-- the second boot: her stick on port 1, the same data stick on port 2", flush=True)
|
|
boot([x for x in make_args if x != "clean" and not x.startswith("ZUSEDISK=")] + [f"ZUSEDISK={img}"])
|
|
check("POST: PASSED (second boot)", wait_for(r"POST: PASSED", 900))
|
|
check("she is logged in: identity confirmed",
|
|
wait_for(r"Zuse: identity confirmed from attached thumbdrive", 300), near=r"Artemis: |Zuse: |USB: ")
|
|
check("[zuse@Hera] ok> (second boot)", wait_for(PROMPT, 120))
|
|
time.sleep(5)
|
|
check(f"identity confirmed once ({count(r'Zuse: identity confirmed')})", count(r"Zuse: identity confirmed") == 1)
|
|
check("no genesis on the second boot", count(r"Zuse: genesis minted") == 0)
|
|
check("no fault", count(r"EXCEPTION|PANIC|panic") == 0)
|
|
|
|
elif m == "fallback":
|
|
SCREEN = [r"Zuse's stick is not here\.", r"Plug it in to log in\.",
|
|
r"Or plug in another stick and press R to mint a replacement",
|
|
r"-- the old Zuse stick will stop working\."]
|
|
img = os.path.join(work, "zuse-real.img")
|
|
subprocess.run(["truncate", "-s", "600M", img], check=True)
|
|
check("[zuse@Hera] ok> (the proxy, first boot)", wait_for(PROMPT, 300))
|
|
type_line("MINT-ZUSE")
|
|
wait_for(r"MINT-ZUSE: plug in the stick for the real Zuse", 60)
|
|
add_stick(1, img, 3)
|
|
wait_for(r"MINT-ZUSE: type YES to write it", 120)
|
|
type_line("YES")
|
|
check("the real Zuse minted (first boot)", wait_for(r"Zuse: real Zuse minted onto the second stick", 300))
|
|
shutdown()
|
|
print("-- the second boot: the data stick alone", flush=True)
|
|
boot([x for x in make_args if x != "clean"])
|
|
check("POST: PASSED (second boot)", wait_for(r"POST: PASSED", 900))
|
|
shown = all(wait_for(line, 120) for line in SCREEN)
|
|
check("the fixed screen: its four lines", shown, near=r"Artemis: |Zuse")
|
|
check("no ok> for 30 s", not wait_for(ANYPROMPT, 30))
|
|
type_line("3 4 + .")
|
|
time.sleep(5)
|
|
c = count(r"Zuse: identity confirmed from attached thumbdrive")
|
|
add_stick(2, img, 3)
|
|
check("her stick added: identity confirmed", wait_for(r"Zuse: identity confirmed from attached thumbdrive", 120, c))
|
|
check("the prompt", wait_for(PROMPT, 60))
|
|
time.sleep(3)
|
|
check("what was typed on the screen did not run (no 7)", re.search(r"\b7\s+ok", text()) is None)
|
|
n = count(PROMPT)
|
|
type_line("3 4 + .")
|
|
check("7 ok at her prompt", wait_for(PROMPT, 60, n) and re.search(r"7\s+ok", text()[-400:]) is not None)
|
|
shots = count(SCREEN[0])
|
|
qcmd("device_del", id="stickdev2")
|
|
check("pulled: session ended", wait_for(r"Zuse: session ended -- reattach to re-authenticate", 60))
|
|
check("pulled: the fixed screen again", wait_for(SCREEN[0], 60, shots))
|
|
qcmd("blockdev-del", **{"node-name": "stick2"})
|
|
shots = count(SCREEN[0])
|
|
p0 = count(r"MINT-ZUSE: plug in the stick for the real Zuse")
|
|
s.send(b"R")
|
|
check("R with no stick: the plug-in line", wait_for(r"MINT-ZUSE: plug in the stick for the real Zuse", 60, p0))
|
|
time.sleep(2)
|
|
s.send(b"x")
|
|
check("any key stops it", wait_for(r"MINT-ZUSE: stopped -- nothing written", 60), near=r"MINT-ZUSE")
|
|
check("the fixed screen again", wait_for(SCREEN[0], 60, shots))
|
|
check("no ok> on the screen", "ok> " not in text()[text().rfind("Zuse: session ended"):])
|
|
check("no fault", count(r"EXCEPTION|PANIC|panic") == 0)
|
|
|
|
elif m in ("replace", "mint_fail", "mint_part_fail", "system_pull_real"):
|
|
SCREEN0 = r"Zuse's stick is not here\."
|
|
old_img = os.path.join(work, "zuse-real.img")
|
|
subprocess.run(["truncate", "-s", "600M", old_img], check=True)
|
|
check("[zuse@Hera] ok> (the proxy, first boot)", wait_for(PROMPT, 300))
|
|
type_line("MINT-ZUSE")
|
|
wait_for(r"MINT-ZUSE: plug in the stick for the real Zuse", 60)
|
|
add_stick(1, old_img, 3)
|
|
wait_for(r"MINT-ZUSE: type YES to write it", 120)
|
|
type_line("YES")
|
|
check("the real Zuse minted (first boot)", wait_for(r"Zuse: real Zuse minted onto the second stick", 300))
|
|
shutdown()
|
|
print("-- the second boot: the data stick alone", flush=True)
|
|
boot([x for x in make_args if x != "clean"])
|
|
check("POST: PASSED (second boot)", wait_for(r"POST: PASSED", 900))
|
|
if m in ("replace", "mint_fail", "mint_part_fail"):
|
|
check("the fixed screen", wait_for(SCREEN0, 120), near=r"Artemis: |Zuse")
|
|
time.sleep(3)
|
|
p0 = count(r"MINT-ZUSE: plug in the stick for the real Zuse")
|
|
s.send(b"R")
|
|
check("R: the plug-in line", wait_for(r"MINT-ZUSE: plug in the stick for the real Zuse", 60, p0))
|
|
new_img = os.path.join(work, "zuse-new.img")
|
|
subprocess.run(["truncate", "-s", "600M", new_img], check=True)
|
|
if m == "replace":
|
|
add_stick(2, new_img, 3)
|
|
wait_for(r"MINT-ZUSE: type YES to write it", 120)
|
|
c = count(r"Zuse: identity confirmed from attached thumbdrive")
|
|
type_line("YES")
|
|
check("a replacement minted", wait_for(r"Zuse: real Zuse minted onto the second stick", 300), near=r"MINT-ZUSE|Zuse:")
|
|
check("the new stick logs in", wait_for(r"Zuse: identity confirmed from attached thumbdrive", 120, c))
|
|
check("its prompt", wait_for(PROMPT, 60))
|
|
shots = count(SCREEN0)
|
|
qcmd("device_del", id="stickdev2")
|
|
check("the new stick pulled: the screen", wait_for(SCREEN0, 60, shots))
|
|
qcmd("blockdev-del", **{"node-name": "stick2"})
|
|
nr = count(r"Zuse: not this system's Zuse stick -- not used")
|
|
add_stick(3, old_img, 3)
|
|
check("the old stick: not this system's Zuse stick -- not used",
|
|
wait_for(r"Zuse: not this system's Zuse stick -- not used", 120, nr), near=r"Zuse|USB")
|
|
n = count(ANYPROMPT)
|
|
check("no ok> for 30 s with the old stick", not wait_for(ANYPROMPT, 30, n))
|
|
qcmd("device_del", id="stickdev3")
|
|
time.sleep(3)
|
|
qcmd("blockdev-del", **{"node-name": "stick3"})
|
|
c = count(r"Zuse: identity confirmed from attached thumbdrive")
|
|
add_stick(4, new_img, 3)
|
|
check("the new one again: identity confirmed", wait_for(r"Zuse: identity confirmed from attached thumbdrive", 120, c))
|
|
check("the prompt", wait_for(PROMPT, 60))
|
|
elif m == "mint_part_fail":
|
|
# #168: the GPT is written (sectors 0-33 and the disk's end), the identity partition's
|
|
# first sector is not -- the stick has been changed when the mint fails
|
|
shots = count(SCREEN0)
|
|
add_stick(2, new_img, 3, fail_sector=2048)
|
|
wait_for(r"MINT-ZUSE: type YES to write it", 120)
|
|
type_line("YES")
|
|
check("MINT-ZUSE: failed -- the stick was erased; Zuse not minted",
|
|
wait_for(r"MINT-ZUSE: failed -- the stick was erased; Zuse not minted", 300), near=r"MINT-ZUSE")
|
|
check("never \"nothing changed\" for a stick that was written", count(r"failed -- nothing changed") == 0)
|
|
check("no replacement minted (none in this boot's log)", count(r"real Zuse minted") == 0)
|
|
check("the fixed screen again", wait_for(SCREEN0, 60, shots))
|
|
qcmd("device_del", id="stickdev2")
|
|
time.sleep(3)
|
|
qcmd("blockdev-del", **{"node-name": "stick2"})
|
|
c = count(r"Zuse: identity confirmed from attached thumbdrive")
|
|
add_stick(3, old_img, 3)
|
|
check("the old stick still logs in", wait_for(r"Zuse: identity confirmed from attached thumbdrive", 120, c))
|
|
check("the prompt", wait_for(PROMPT, 60))
|
|
else:
|
|
shots = count(SCREEN0)
|
|
add_stick(2, new_img, 3, fail_writes=True)
|
|
wait_for(r"MINT-ZUSE: type YES to write it", 120)
|
|
type_line("YES")
|
|
check("MINT-ZUSE: failed -- nothing changed", wait_for(r"MINT-ZUSE: failed -- nothing changed", 300), near=r"MINT-ZUSE")
|
|
# each boot has its own serial log: this one is the second boot's
|
|
check("no replacement minted (none in this boot's log)", count(r"real Zuse minted") == 0)
|
|
check("the fixed screen again", wait_for(SCREEN0, 60, shots))
|
|
qcmd("device_del", id="stickdev2")
|
|
time.sleep(3)
|
|
qcmd("blockdev-del", **{"node-name": "stick2"})
|
|
c = count(r"Zuse: identity confirmed from attached thumbdrive")
|
|
add_stick(3, old_img, 3)
|
|
check("the old stick still logs in", wait_for(r"Zuse: identity confirmed from attached thumbdrive", 120, c))
|
|
check("the prompt", wait_for(PROMPT, 60))
|
|
else:
|
|
wait_for(SCREEN0, 120)
|
|
c = count(r"Zuse: identity confirmed from attached thumbdrive")
|
|
add_stick(2, old_img, 3)
|
|
check("her stick: logged in", wait_for(r"Zuse: identity confirmed from attached thumbdrive", 120, c))
|
|
check("the prompt", wait_for(PROMPT, 60))
|
|
e = count(r"Zuse: session ended")
|
|
qcmd("device_del", id="datadev")
|
|
check("the data stick pulled: session ended", wait_for(r"Zuse: session ended -- reattach to re-authenticate", 60, e))
|
|
time.sleep(5)
|
|
check("no detach refusal in the log", re.search(r"detach.*(refus|fail|not the tail)", text(), re.I) is None)
|
|
data = os.path.join(work, "data.img") # the session's own data stick
|
|
c = count(r"Zuse: identity confirmed from attached thumbdrive")
|
|
add_stick(9, data, 2)
|
|
check("the data stick replugged, hers still in: she is logged in",
|
|
wait_for(r"Zuse: identity confirmed from attached thumbdrive", 120, c), near=r"Artemis: |Zuse|USB")
|
|
check("the prompt", wait_for(PROMPT, 60))
|
|
check("no fault", count(r"EXCEPTION|PANIC|panic") == 0)
|
|
|
|
elif m == "mint_zuse":
|
|
blank = os.path.join(work, "zuse-real.img")
|
|
subprocess.run(["truncate", "-s", "600M", blank], check=True)
|
|
check("[zuse@Hera] ok> (the proxy, on a fresh data stick)", wait_for(PROMPT, 300))
|
|
type_line("MINT-ZUSE")
|
|
check("MINT-ZUSE: plug in the stick for the real Zuse",
|
|
wait_for(r"MINT-ZUSE: plug in the stick for the real Zuse", 60), near=r"MINT-ZUSE")
|
|
add_stick(1, blank, 3)
|
|
check("MINT-ZUSE: a stick of 600 MiB -- all of it is erased",
|
|
wait_for(r"MINT-ZUSE: a stick of 600 MiB -- all of it is erased", 120), near=r"MINT-ZUSE")
|
|
check("MINT-ZUSE: type YES to write it", wait_for(r"MINT-ZUSE: type YES to write it", 30), near=r"MINT-ZUSE")
|
|
type_line("YES")
|
|
minted = wait_for(r"Zuse: real Zuse minted onto the second stick", 300)
|
|
check("Zuse: real Zuse minted onto the second stick", minted, near=r"MINT-ZUSE|Zuse:")
|
|
t = text()
|
|
after = t[t.find("Zuse: real Zuse minted onto the second stick"):] if minted else ""
|
|
check("her stick recognised: identity confirmed after it (her session on it)",
|
|
minted and "Zuse: identity confirmed from attached thumbdrive" in after, near=r"real Zuse minted")
|
|
check("[zuse@Hera] ok> after it (the real Zuse)", minted and (re.search(PROMPT, after) is not None
|
|
or wait_for(PROMPT, 120, count(PROMPT))))
|
|
n = count(PROMPT)
|
|
type_line("3 4 + .")
|
|
check("7 ok", wait_for(PROMPT, 60, n) and re.search(r"7\s+ok", text()[-400:]) is not None)
|
|
check("no fault", count(r"EXCEPTION|PANIC|panic") == 0)
|
|
shutdown()
|
|
boot_done = True
|
|
sf = shutil.which("sfdisk") or "/usr/sbin/sfdisk"
|
|
v = subprocess.run([sf, "--verify", blank], capture_output=True, text=True)
|
|
print(v.stdout.strip() + v.stderr.strip(), flush=True)
|
|
check("sfdisk --verify on the new Zuse stick: clean", v.returncode == 0 and "No errors detected" in v.stdout + v.stderr)
|
|
j = subprocess.run([sf, "--json", blank], capture_output=True, text=True)
|
|
parts = json.loads(j.stdout)["partitiontable"]["partitions"] if j.returncode == 0 and j.stdout else []
|
|
check(f"one StarshipOS identity partition ({[q['type'] for q in parts]})",
|
|
len(parts) == 1 and parts[0]["type"].upper() == GPT_IDENTITY)
|
|
|
|
elif m == "bam_flush":
|
|
check("[zuse@Hera] ok>", wait_for(PROMPT, 600))
|
|
lbns = re.findall(r"blk: disk .*? LBN (\d+)\.\.(\d+)", text())
|
|
check(f"Artemis's LBN range ({lbns[:1]})", bool(lbns))
|
|
first = int(lbns[0][0]) if lbns else 0
|
|
times = []
|
|
for i in range(3):
|
|
blk = first + 100 + i
|
|
n = count(PROMPT)
|
|
type_line(f"{blk} BLOCK DROP UPDATE")
|
|
check(f"block {blk} changed", wait_for(PROMPT, 60, n))
|
|
n = count(PROMPT)
|
|
t = time.time()
|
|
type_line("SAVE-BUFFERS")
|
|
done = wait_for(PROMPT, 300, n)
|
|
times.append(time.time() - t)
|
|
print(f"TIME: SAVE-BUFFERS of block {blk}: {times[-1]:.1f} s", flush=True)
|
|
check(f"SAVE-BUFFERS answers ok within 2 s ({times[-1]:.1f} s)", done and times[-1] < 2)
|
|
check("no fault", count(r"EXCEPTION|PANIC|panic") == 0)
|
|
shutdown()
|
|
boot_done = True
|
|
sf = shutil.which("sfdisk") or "/usr/sbin/sfdisk"
|
|
run = os.path.join(ROOT, "build", a.arch, "kernel", "stick-run.img")
|
|
parts = json.loads(subprocess.run([sf, "--json", run], capture_output=True, text=True).stdout)
|
|
art = [q for q in parts["partitiontable"]["partitions"]
|
|
if q["type"].upper() == "BCD7B586-1C8E-4EEF-86A3-273A8D8EE624"][0]
|
|
import hashlib
|
|
with open(run, "rb") as f:
|
|
f.seek(art["start"] * 512 + 4096) # the BAM: devblocks 1 .. 6144 of Artemis
|
|
bam = f.read(6144 * 4096)
|
|
print(f"BAM: sha256 {hashlib.sha256(bam).hexdigest()}, {sum(1 for x in bam if x)} non-zero bytes",
|
|
flush=True)
|
|
|
|
elif m == "stick_v3":
|
|
t = text()
|
|
check("Boot disk: a StarshipOS stick", re.search(r"Boot disk: a StarshipOS stick", t) is not None)
|
|
check("System: v3 is not on this stick -- StarForth v4",
|
|
re.search(r"System: v3 is not on this stick -- StarForth v4", t) is not None)
|
|
check("v4's POST (PARITY:V4_POST)", re.search(r"PARITY:V4_POST tests=\d+ pass=\d+ fail=0", t) is not None)
|
|
check("no System: StarForth v3", re.search(r"System: StarForth v3", t) is None)
|
|
check("no fault", count(r"EXCEPTION|PANIC|panic") == 0)
|
|
|
|
elif m == "entropy":
|
|
want = "rdrand" if a.arch == "amd64" else "virtio-rng"
|
|
wait_for(r"entropy: (ready|not available)|Zuse:|ok> ", 120) # the block chain runs after POST
|
|
t = text()
|
|
v4 = re.search(r"System: StarForth v4", t)
|
|
after = t[v4.end():] if v4 else ""
|
|
check("System: StarForth v4", v4 is not None)
|
|
be = re.search(r"rng: backend = (\S+)", after)
|
|
check(f"after it, rng: backend = {want} (got {be.group(1) if be else None})",
|
|
be is not None and be.group(1) == want)
|
|
check("entropy: ready", re.search(r"entropy: ready", after) is not None)
|
|
if a.target == "qemu":
|
|
check("[zuse@Hera] ok>", wait_for(PROMPT, 120))
|
|
check("no fault", count(r"EXCEPTION|PANIC|panic") == 0)
|
|
|
|
elif m == "gpt_many":
|
|
# #180: gpt_read() stopped reading entries at its max (16 here) and checked none after them
|
|
# the two sticks were made before the boot (see "gpt_many" above)
|
|
check("no ok> for 20 s with no drive", not wait_for(ANYPROMPT, 20))
|
|
add_stick(1, many, 2)
|
|
check("GPT: a USB drive has more than 16 partitions -- not used",
|
|
wait_for(r"GPT: a USB drive has more than 16 partitions -- not used", 120), near=r"GPT|USB|Artemis|Zuse")
|
|
qcmd("device_del", id="stickdev1")
|
|
time.sleep(3)
|
|
qcmd("blockdev-del", **{"node-name": "stick1"})
|
|
d = count(r"GPT: a USB drive has a damaged partition table -- not used")
|
|
add_stick(2, bad, 2)
|
|
check("an entry past the usable range, after the 16th: a damaged partition table",
|
|
wait_for(r"GPT: a USB drive has a damaged partition table -- not used", 120, d), near=r"GPT|USB|Artemis|Zuse")
|
|
check("no ok> throughout", count(ANYPROMPT) == 0)
|
|
|
|
elif m == "ident_attach_fail":
|
|
# #179: the identity partition (LBA 2048 on a data stick) cannot be read, so it cannot be
|
|
# attached -- after Artemis has been. Both partitions or neither.
|
|
dstick = os.path.join(work, "ident-fail.img")
|
|
subprocess.run(["make", "-f", "kernel/Makefile", f"ARCH={a.arch}", "datastick", f"DATASTICK_IMG={dstick}"],
|
|
cwd=ROOT, check=True, stdout=subprocess.DEVNULL)
|
|
check("no ok> for 20 s with no drive", not wait_for(ANYPROMPT, 20))
|
|
add_stick(1, dstick, 2, fail_read_sector=2048)
|
|
check("Zuse: the stick's identity partition failed -- not used",
|
|
wait_for(r"Zuse: the stick's identity partition failed -- not used", 120), near=r"Artemis|Zuse|xhci")
|
|
check("Artemis: the stick's partition let go -- both or neither",
|
|
wait_for(r"Artemis: the stick's partition let go", 30), near=r"Artemis|Zuse|xhci")
|
|
n = count(ANYPROMPT)
|
|
check("no ok> for 20 s with the faulty stick", not wait_for(ANYPROMPT, 20, n))
|
|
qcmd("device_del", id="stickdev1")
|
|
time.sleep(3)
|
|
qcmd("blockdev-del", **{"node-name": "stick1"})
|
|
g = count(r"Zuse: genesis minted onto attached thumbdrive")
|
|
add_stick(2, dstick, 2)
|
|
check("the same stick, without the fault: genesis", wait_for(r"Zuse: genesis minted onto attached thumbdrive", 180, g),
|
|
near=r"Artemis|Zuse")
|
|
check("[zuse@Hera] ok>", wait_for(PROMPT, 60))
|
|
|
|
elif m == "hotplug":
|
|
check("no ok> for 20 s with no drive", not wait_for(ANYPROMPT, 20))
|
|
add_zuse(1)
|
|
check("identity confirmed on attach", wait_for(r"Zuse: identity confirmed from attached thumbdrive", 120))
|
|
check("[zuse@Hera] ok> after attach", wait_for(PROMPT, 60))
|
|
n = count(PROMPT)
|
|
type_line("3 4 + .")
|
|
check("7 ok", wait_for(PROMPT, 60, n) and re.search(r"7\s+ok", text()) is not None)
|
|
del_zuse(1)
|
|
check("session ended on detach", wait_for(r"Zuse: session ended -- reattach to re-authenticate", 60))
|
|
n = count(ANYPROMPT)
|
|
check("no new ok> for 30 s after detach", not wait_for(ANYPROMPT, 30, n))
|
|
c = count(r"Zuse: identity confirmed from attached thumbdrive")
|
|
p = count(PROMPT)
|
|
add_zuse(2)
|
|
check("identity confirmed on re-attach", wait_for(r"Zuse: identity confirmed from attached thumbdrive", 120, c))
|
|
check("[zuse@Hera] ok> again", wait_for(PROMPT, 60, p))
|
|
|
|
elif m == "midpull":
|
|
add_zuse(1)
|
|
check("[zuse@Hera] ok> after attach", wait_for(PROMPT, 120))
|
|
qcmd("device_del", id="zusedev1")
|
|
type_line("3 4 + .")
|
|
type_line("5 6 + .")
|
|
check("session ended on detach", wait_for(r"Zuse: session ended -- reattach to re-authenticate", 60))
|
|
time.sleep(10)
|
|
t = text()
|
|
check("the line typed after the pull did not run (no 11)", re.search(r"\b11\s+ok", t) is None)
|
|
check("no ok> after the session ended", "ok> " not in t[t.rfind("Zuse: session ended"):])
|
|
# the replug: identity and Artemis were both let go; Artemis is attached first again
|
|
qcmd("blockdev-del", **{"node-name": "zuse1"})
|
|
p = count(PROMPT)
|
|
add_zuse(2)
|
|
check("[zuse@Hera] ok> again after the replug", wait_for(PROMPT, 120, p))
|
|
na = count(r"Artemis: the stick's partition attached")
|
|
check(f"Artemis attached again: two Artemis lines in all ({na})", na == 2)
|
|
|
|
elif m == "waitpull":
|
|
add_zuse(1)
|
|
check("[zuse@Hera] ok> after attach", wait_for(PROMPT, 120))
|
|
type_line("5 AWAIT")
|
|
time.sleep(5)
|
|
del_zuse(1)
|
|
check("session ended on detach", wait_for(r"Zuse: session ended -- reattach to re-authenticate", 60))
|
|
check("the waiting line ended at logout (Interrupted)", wait_for(r"Interrupted", 30))
|
|
p = count(PROMPT)
|
|
add_zuse(2)
|
|
check("identity confirmed on re-attach", wait_for(r"Zuse: identity confirmed from attached thumbdrive", 120, 1))
|
|
check("[zuse@Hera] ok> again", wait_for(PROMPT, 60, p))
|
|
n = count(PROMPT)
|
|
type_line("3 4 + .")
|
|
check("7 ok after re-attach", wait_for(PROMPT, 60, n) and re.search(r"7\s+ok", text()) is not None)
|
|
|
|
elif m == "typeahead":
|
|
check("no ok> for 10 s with no drive", not wait_for(ANYPROMPT, 10))
|
|
type_line("3 4 + .")
|
|
time.sleep(5)
|
|
add_zuse(1)
|
|
check("[zuse@Hera] ok> after attach", wait_for(PROMPT, 120))
|
|
time.sleep(5)
|
|
check("what was typed while headless did not run (no 7)", re.search(r"\b7\s+ok", text()) is None)
|
|
n = count(PROMPT)
|
|
type_line("1 2 + .")
|
|
check("3 ok typed at the prompt", wait_for(PROMPT, 60, n) and re.search(r"\b3\s+ok", text()) is not None)
|
|
|
|
elif m == "emergency":
|
|
check("ok> with no drive", wait_for(ANYPROMPT, 60))
|
|
n = count(ANYPROMPT)
|
|
type_line("3 4 + .")
|
|
check("7 ok", wait_for(ANYPROMPT, 60, n) and re.search(r"7\s+ok", text()) is not None)
|
|
|
|
elif m == "v3_keys":
|
|
check("[zuse@Hera] ok>", wait_for(PROMPT, 300))
|
|
time.sleep(2)
|
|
n = count(PROMPT)
|
|
key_line("3 4 + .")
|
|
check("7 ok typed on the keyboard", wait_for(PROMPT, 60, n) and re.search(r"7\s+ok", text()) is not None)
|
|
|
|
elif m == "screen_dark_until_login":
|
|
time.sleep(30)
|
|
w, h, lit, _ = screen()
|
|
check(f"the screen ({w}x{h}) is all black before login ({lit} lit)", lit == 0)
|
|
|
|
elif m == "screen_boot":
|
|
check("Screen: the console stays on until login (screen=boot)",
|
|
wait_for(r"Screen: the console stays on until login \(screen=boot\)", 60))
|
|
time.sleep(30)
|
|
w, h, lit, _ = screen()
|
|
check(f"the screen ({w}x{h}) shows the console before login ({lit} lit)", lit >= 500)
|
|
check("no ok> (no one is logged in)", not wait_for(ANYPROMPT, 5))
|
|
check("no fault", count(r"EXCEPTION|PANIC|panic") == 0)
|
|
|
|
elif m in ("screen_console_after_login", "screen_dark_after_logout"):
|
|
add_zuse(1)
|
|
check("[zuse@Hera] ok> after attach", wait_for(PROMPT, 120))
|
|
time.sleep(3)
|
|
w, h, lit1, px1 = screen()
|
|
check(f"the screen shows the console ({lit1} lit pixels)", lit1 >= 500)
|
|
n = count(PROMPT)
|
|
key_line("3 4 + .")
|
|
check("7 ok typed on the keyboard", wait_for(PROMPT, 60, n) and re.search(r"7\s+ok", text()) is not None)
|
|
time.sleep(3)
|
|
_, _, lit2, px2 = screen()
|
|
check("the screen changed with what was typed", px2 != px1)
|
|
if m == "screen_dark_after_logout":
|
|
del_zuse(1)
|
|
check("session ended on detach", wait_for(r"Zuse: session ended -- reattach to re-authenticate", 60))
|
|
time.sleep(5)
|
|
_, _, lit3, _ = screen()
|
|
check(f"the screen is black after logout ({lit3} lit)", lit3 == 0)
|
|
|
|
elif m == "kbd_typeahead":
|
|
check("no ok> for 10 s with no drive", not wait_for(ANYPROMPT, 10))
|
|
key_line("3 4 + .")
|
|
time.sleep(5)
|
|
add_zuse(1)
|
|
check("[zuse@Hera] ok> after attach", wait_for(PROMPT, 120))
|
|
time.sleep(5)
|
|
check("keys pressed while headless did not run (no 7)", re.search(r"\b7\s+ok", text()) is None)
|
|
n = count(PROMPT)
|
|
key_line("1 2 + .")
|
|
check("3 ok typed on the keyboard", wait_for(PROMPT, 60, n) and re.search(r"\b3\s+ok", text()) is not None)
|
|
|
|
elif m == "usb_kbd":
|
|
check("[zuse@Hera] ok>", wait_for(PROMPT, 300))
|
|
time.sleep(2)
|
|
n = count(PROMPT)
|
|
key_line("3 4 + .") # the USB keyboard is the only one (-machine i8042=off)
|
|
check("7 ok typed on the USB keyboard", wait_for(PROMPT, 60, n) and re.search(r"7\s+ok", text()) is not None)
|
|
|
|
elif m in ("no_framebuffer", "virtio_kbd"):
|
|
check("[zuse@Hera] ok>", wait_for(PROMPT, 300))
|
|
time.sleep(2)
|
|
n = count(PROMPT)
|
|
if m == "no_framebuffer":
|
|
type_line("3 4 + .")
|
|
else:
|
|
key_line("3 4 + .")
|
|
check("7 ok", wait_for(PROMPT, 60, n) and re.search(r"7\s+ok", text()) is not None)
|
|
|
|
elif m in ("alttab_after_logout", "alttab_before_pull"):
|
|
add_zuse(1)
|
|
check("[zuse@Hera] ok> after attach", wait_for(PROMPT, 120))
|
|
n = count(PROMPT)
|
|
key_line("3 4 + .")
|
|
check("7 ok typed", wait_for(PROMPT, 60, n))
|
|
if m == "alttab_before_pull":
|
|
alt_tab() # to the graphics view, her session on screen
|
|
del_zuse(1)
|
|
check("session ended on detach", wait_for(r"Zuse: session ended -- reattach to re-authenticate", 60))
|
|
time.sleep(5)
|
|
if m == "alttab_after_logout":
|
|
alt_tab()
|
|
alt_tab()
|
|
time.sleep(3)
|
|
_, _, lit, _ = screen()
|
|
check(f"the screen is black after logout ({lit} lit)", lit == 0)
|
|
if m == "alttab_before_pull":
|
|
p = count(PROMPT)
|
|
add_zuse(2)
|
|
check("[zuse@Hera] ok> again", wait_for(PROMPT, 120, p))
|
|
time.sleep(3)
|
|
_, _, lit1, px1 = screen()
|
|
check(f"the console is drawn again ({lit1} lit)", lit1 >= 500)
|
|
n = count(PROMPT)
|
|
key_line("1 2 + .")
|
|
check("3 ok typed", wait_for(PROMPT, 60, n))
|
|
time.sleep(3)
|
|
_, _, _, px2 = screen()
|
|
check("the screen changed with what was typed", px2 != px1)
|
|
|
|
elif m == "emergency_pull":
|
|
check("ok> with no drive", wait_for(ANYPROMPT, 60))
|
|
add_zuse(1)
|
|
check("Zuse: identity confirmed", wait_for(r"Zuse: identity confirmed from attached thumbdrive", 120))
|
|
time.sleep(3)
|
|
del_zuse(1)
|
|
check("session ended on detach", wait_for(r"Zuse: session ended -- reattach to re-authenticate", 60))
|
|
time.sleep(5)
|
|
_, _, lit1, px1 = screen()
|
|
check(f"the screen still shows the console ({lit1} lit)", lit1 >= 500)
|
|
n = count(ANYPROMPT)
|
|
key_line("3 4 + .")
|
|
check("7 ok typed after the pull", wait_for(ANYPROMPT, 60, n) and re.search(r"7\s+ok", text()) is not None)
|
|
time.sleep(3)
|
|
_, _, _, px2 = screen()
|
|
check("the screen changed with what was typed", px2 != px1)
|
|
|
|
elif m in ("gpt_zuse", "gpt_hotplug", "gpt_foreign", "gpt_bad_crc", "gpt_bad_entries", "gpt_no_header",
|
|
"gpt_read_error"):
|
|
gimg = os.path.join(work, "gpt.img")
|
|
make_gpt_image(gimg, GPT_LINUX if m == "gpt_foreign" else GPT_IDENTITY, ident,
|
|
break_crc=(m == "gpt_bad_crc"), break_entries=(m == "gpt_bad_entries"),
|
|
break_sig=(m == "gpt_no_header"))
|
|
check("no ok> for 10 s with no drive", not wait_for(ANYPROMPT, 10))
|
|
b0 = blk_lines()
|
|
if m == "gpt_read_error":
|
|
add_zuse(1, ident, fail_sector0=True) # the raw Zuse drive: no GPT, but block 0 unreadable
|
|
else:
|
|
add_zuse(1, gimg)
|
|
if m in ("gpt_zuse", "gpt_hotplug"):
|
|
# a GPT disk with only an identity partition is not a stick: on v4 it is not used
|
|
# (plan 2026-10-27-stick-4-one-disk.md, R2; Zuse's own case is the stick now)
|
|
check("not this system's stick -- not used",
|
|
wait_for(r"USB: a drive that is not this system's stick -- not used", 60))
|
|
check("no ok> for 30 s", not wait_for(ANYPROMPT, 30))
|
|
check(f"not attached (blk: lines {b0} -> {blk_lines()})", blk_lines() == b0)
|
|
else:
|
|
if m in ("gpt_bad_crc", "gpt_bad_entries", "gpt_no_header"):
|
|
check("the damaged table is said so", wait_for(r"GPT: a USB drive has a damaged partition table -- not used", 60))
|
|
if m == "gpt_read_error":
|
|
check("the unreadable drive is said so", wait_for(r"GPT: a USB drive could not be read -- not used", 60))
|
|
check("no ok> for 30 s", not wait_for(ANYPROMPT, 30))
|
|
check("no identity", count(r"Zuse: identity confirmed") == 0)
|
|
check(f"not attached (blk: lines {b0} -> {blk_lines()})", blk_lines() == b0)
|
|
|
|
else:
|
|
check(f"known mode {m}", False)
|
|
|
|
print(f"RESULT: {'PASS' if ok else 'FAIL'}", flush=True)
|
|
if not globals().get("boot_done"):
|
|
shutdown()
|
|
for f in ("capsules/BLOCK_MAP.md",): # a signed build rewrites its Signed column; version.h is untracked (#145)
|
|
subprocess.run(["git", "checkout", "-q", "--", f], cwd=ROOT)
|
|
sys.exit(0 if ok else 2)
|