Files
bfe-core1106-sdk/qemu/tests/run-sh-args-test.sh
T
BFE EngineeringandClaude Opus 5.5 579ac260ca
ci / test (push) Successful in 10s
ci / patches-apply (push) Successful in 25s
ci / quality (push) Successful in 36s
ci / badges (push) Skipped
ci / kernel-symbols (push) Successful in 4m38s
ci / mcdc (push) Successful in 37s
ci / bench (push) Successful in 6s
ci / qemu-tools (push) Failing after 15s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / test (pull_request) Successful in 9s
ci / prune-artifacts (pull_request) Skipped
ci / mcdc (pull_request) Successful in 34s
ci / bench (pull_request) Successful in 20s
ci / kernel-build (pull_request) Skipped
ci / qemu-tools (pull_request) Failing after 57s
ci / patches-apply (pull_request) Successful in 1m16s
ci / kernel-symbols (pull_request) Successful in 2m14s
ci / badges (pull_request) Skipped
ci / quality (pull_request) Successful in 2m51s
qemu: rig agent, a framed guest shell on its own serial port (flare-edge M9 soak-lite)
run.sh --agent SOCK adds a third pci-serial after ctl and rs485 (their
ttyS order is unchanged) and warden.agent on the command line. Stage-2
init then runs warden_agent (rootfs/etc/warden-lib.sh) on that port with
echo off: `@run ID SECS B64` runs a script and answers <<BEGIN ID>>, the
base64 of its output and <<END ID RC>>; `@chunk` pieces get past the
4095-byte cooked line; a script past its deadline is killed with its
process group and answers 124 (the panel BusyBox has no timeout). It is
the guest channel of flare-edge tools/soak/rig-qemu.py, which needs bus
reads and writes, the clock and /proc inside the gate image. Rig rootfs
only: no panel image carries it.

Tests: qemu/tests/agent-test.sh (sh and busybox sh, in CI) and new
run-sh-args-test.sh cases (agent last, warden.agent only with the flag).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BdKQBQkJkq4zE7iPFMkAhS
2026-10-31 17:05:50 -06:00

180 lines
7.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Offline regression test for run.sh's own argv construction: no real QEMU,
# no kernel image. A fake `qemu-system-arm` placed first on PATH dumps the
# argv it was handed (one token per line) and exits, so this pins the exact
# contract run.sh:121-138 and rootfs/sbin/init:54,161 share without either
# side moving: init decides ttyS0 vs ttyS1 for the Modbus alias purely by
# grepping warden.ctl off /proc/cmdline, so run.sh has to keep two promises
# every single invocation -- the ctl pci-serial device, when present, comes
# BEFORE the rs485 one in argv (virt's PCI bus enumerates in that order),
# and an rs485 pci-serial device (real or null-backed) is always there so
# the port count init relies on never shifts.
#
# What is worth pinning: nothing else exercises this. test-ui-drive-rs485.sh
# stubs run.sh out entirely (a fake VM), and the only real boot in CI
# (boot-smoke.sh) passes neither --ctl nor --rs485, so a swapped
# `[ -n "$CTL" ]`/`[ -n "$RS485" ]` block, or a dropped null-chardev
# fallback, would reach a panel as Modbus polls landing on the debug channel
# (run.sh:131-133's own incident) before anything here caught it.
#
# bash run-sh-args-test.sh
set -uo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
RUN_SH="$HERE/../run.sh"
SCRATCH="$(mktemp -d /tmp/runshargs.XXXXXX)"
trap 'rm -rf "$SCRATCH"' EXIT
FAIL=0
pass() { printf '[PASS] %s\n' "$1"; }
fail() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
KERNEL="$SCRATCH/fake-zImage"
INITRD="$SCRATCH/fake-initramfs.cpio.gz"
: > "$KERNEL"
: > "$INITRD"
BIN="$SCRATCH/bin"
mkdir -p "$BIN"
cat > "$BIN/qemu-system-arm" <<'STUB'
#!/usr/bin/env bash
# Stand-in for the real binary: record argv, one token per line, and exit
# straight away. $ARGV_CAPTURE names where -- run.sh always `exec`s this as
# its very last step, so nothing downstream of it ever runs.
printf '%s\n' "$@" > "$ARGV_CAPTURE"
STUB
chmod +x "$BIN/qemu-system-arm"
# run_case ARGV_FILE EXTRA_ARGS...: invoke the real run.sh --no-disk (so
# nothing under the real qemu/out/ is ever touched) with the fake binary
# first on PATH, capturing its argv into ARGV_FILE. Fails the case loudly if
# run.sh itself exits nonzero -- a silent empty capture would otherwise look
# just like "the assertions below simply found nothing".
run_case() {
local argv_file="$1"; shift
local out rc
out="$(cd "$SCRATCH" && PATH="$BIN:$PATH" ARGV_CAPTURE="$argv_file" \
bash "$RUN_SH" --kernel "$KERNEL" --initrd "$INITRD" --no-disk "$@" 2>&1)"
rc=$?
[ "$rc" -eq 0 ] || { fail "run.sh exited $rc for: $* -- output: $out"; return 1; }
[ -s "$argv_file" ] || { fail "run.sh produced no captured argv for: $*"; return 1; }
return 0
}
# chardev_line ARGV_FILE PREFIX: 1-indexed line number of the first argv
# token starting with PREFIX (the socket/null chardev spec, which always
# immediately follows the "-chardev" token it belongs to), or empty.
chardev_line() { grep -n -m1 "^$2" "$1" | cut -d: -f1; }
# --- case: neither --ctl nor --rs485 -> null-backed rs485, no ctl device ---
argv="$SCRATCH/argv-neither.txt"
if run_case "$argv"; then
if ! grep -qF 'id=ctl' "$argv"; then
pass "neither flag: no ctl chardev/device at all"
else
fail "neither flag: a ctl chardev/device appeared unrequested"
fi
if grep -qF -- '-append' "$argv" && ! grep -qw 'warden.ctl' "$argv"; then
pass "neither flag: -append omits warden.ctl"
else
fail "neither flag: -append should omit warden.ctl"
fi
if [ -n "$(chardev_line "$argv" 'null,id=rs485')" ] \
&& grep -qF 'pci-serial,chardev=rs485' "$argv"; then
pass "neither flag: null-backed rs485 pci-serial device is still present"
else
fail "neither flag: expected a null-backed rs485 device (port count must not shift)"
fi
fi
# --- case: --rs485 alone -> real rs485 device, still no ctl device ---------
argv="$SCRATCH/argv-rs485-only.txt"
if run_case "$argv" --rs485 "$SCRATCH/rs.sock"; then
if ! grep -qF 'id=ctl' "$argv"; then
pass "rs485 only: no ctl chardev/device"
else
fail "rs485 only: a ctl chardev/device appeared unrequested"
fi
if ! grep -qw 'warden.ctl' "$argv"; then
pass "rs485 only: -append omits warden.ctl"
else
fail "rs485 only: -append should omit warden.ctl"
fi
if [ -n "$(chardev_line "$argv" "socket,id=rs485,path=$SCRATCH/rs.sock,")" ]; then
pass "rs485 only: rs485 chardev carries the requested socket path"
else
fail "rs485 only: rs485 chardev did not carry the requested socket path"
fi
fi
# --- case: --ctl alone -> ctl device first, null-backed rs485 still present,
# and warden.ctl on the cmdline ------------------------------------------
argv="$SCRATCH/argv-ctl-only.txt"
if run_case "$argv" --ctl "$SCRATCH/ctl.sock"; then
ctl_ln="$(chardev_line "$argv" "socket,id=ctl,path=$SCRATCH/ctl.sock,")"
rs_ln="$(chardev_line "$argv" 'null,id=rs485')"
if [ -n "$ctl_ln" ] && [ -n "$rs_ln" ] && [ "$ctl_ln" -lt "$rs_ln" ]; then
pass "ctl only: ctl chardev (line $ctl_ln) precedes the null rs485 chardev (line $rs_ln)"
else
fail "ctl only: expected ctl chardev before a null-backed rs485 chardev, got ctl=$ctl_ln rs485=$rs_ln"
fi
if grep -qw 'warden.ctl' "$argv"; then
pass "ctl only: -append carries warden.ctl"
else
fail "ctl only: -append should carry warden.ctl"
fi
fi
# --- case: --ctl and --rs485 together -> ctl device still enumerates first -
argv="$SCRATCH/argv-both.txt"
if run_case "$argv" --ctl "$SCRATCH/ctl.sock" --rs485 "$SCRATCH/rs.sock"; then
ctl_ln="$(chardev_line "$argv" "socket,id=ctl,path=$SCRATCH/ctl.sock,")"
rs_ln="$(chardev_line "$argv" "socket,id=rs485,path=$SCRATCH/rs.sock,")"
if [ -n "$ctl_ln" ] && [ -n "$rs_ln" ] && [ "$ctl_ln" -lt "$rs_ln" ]; then
pass "both flags: ctl chardev (line $ctl_ln) precedes the rs485 chardev (line $rs_ln)"
else
fail "both flags: expected ctl chardev before rs485 chardev, got ctl=$ctl_ln rs485=$rs_ln"
fi
if grep -qw 'warden.ctl' "$argv"; then
pass "both flags: -append carries warden.ctl"
else
fail "both flags: -append should carry warden.ctl"
fi
fi
# --- case: --agent (the rig agent, flare-edge M9 soak-lite) -> its
# pci-serial comes LAST, after ctl and rs485, so neither moves, and
# warden.agent lands on the cmdline only with the flag -------------------
if ! grep -qw 'warden.agent' "$SCRATCH/argv-both.txt" && ! grep -qF 'id=agent' "$SCRATCH/argv-both.txt"; then
pass "no --agent: no agent chardev and no warden.agent"
else
fail "no --agent: an agent chardev or warden.agent appeared unrequested"
fi
for combo in "agent-ctl:--ctl $SCRATCH/ctl.sock" "agent-alone:"; do
name="${combo%%:*}" extra="${combo#*:}"
argv="$SCRATCH/argv-$name.txt"
# shellcheck disable=SC2086 # extra is a word list on purpose
if run_case "$argv" $extra --rs485 "$SCRATCH/rs.sock" --agent "$SCRATCH/agent.sock"; then
ag_ln="$(chardev_line "$argv" "socket,id=agent,path=$SCRATCH/agent.sock,")"
rs_ln="$(chardev_line "$argv" "socket,id=rs485,path=$SCRATCH/rs.sock,")"
ctl_ln="$(chardev_line "$argv" "socket,id=ctl,")"
if [ -n "$ag_ln" ] && [ -n "$rs_ln" ] && [ "$rs_ln" -lt "$ag_ln" ] &&
{ [ -z "$ctl_ln" ] || [ "$ctl_ln" -lt "$rs_ln" ]; }; then
pass "$name: agent chardev (line $ag_ln) comes after rs485 (line $rs_ln) and ctl (${ctl_ln:-none})"
else
fail "$name: expected ctl < rs485 < agent, got ctl=$ctl_ln rs485=$rs_ln agent=$ag_ln"
fi
if grep -qF 'pci-serial,chardev=agent' "$argv" && grep -qw 'warden.agent' "$argv"; then
pass "$name: agent pci-serial device and warden.agent present"
else
fail "$name: agent pci-serial device or warden.agent missing"
fi
fi
done
if [ "$FAIL" -eq 0 ]; then
echo "ALL RUN.SH ARGV TESTS PASSED"
exit 0
else
echo "RUN.SH ARGV TESTS FAILED"
exit 1
fi