Compare commits

..
Author SHA1 Message Date
NoahandClaude Opus 5.5 07db1b9ec0 qemu: rig init honours reboot, poweroff and halt
ci / test (push) Successful in 13s
ci / bench (push) Successful in 5s
ci / mcdc (push) Successful in 15s
ci / patches-apply (push) Successful in 22s
ci / qemu-tools (push) Successful in 46s
ci / qemu-tools (pull_request) Successful in 42s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 37s
ci / badges (push) Skipped
ci / test (pull_request) Successful in 13s
ci / mcdc (pull_request) Successful in 11s
ci / bench (pull_request) Successful in 5s
ci / patches-apply (pull_request) Successful in 16s
ci / quality (pull_request) Successful in 27s
ci / badges (pull_request) Skipped
The stage-2 init is a busybox sh script running as PID 1. Busybox reboot,
poweroff and halt only signal PID 1 (TERM, USR2, USR1), and the kernel
drops a signal PID 1 has no handler for, so a plain reboot did nothing on
the rig while a panel's busybox init honours it. Settings > System >
Reboot hit exactly that (flare-edge#96).

warden_trap_power_signals performs the -f action after a sync, and
warden_idle_forever idles with sleep & wait so the trap runs at once
instead of after an hour-long foreground sleep.

Test: qemu/tests/init-power-signals-test.sh runs the real helpers in sh
with stub commands and sends each signal; it fails without the traps and
with a foreground sleep, and cannot hang on failure.

Fixes #5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-09-28 11:17:07 -06:00
noah eb0691d84f Merge pull request 'Clear the shellcheck findings that would fail qemu-tools' (#3) from sdk-shellcheck into flare-edge-next
ci / kernel-build (push) Skipped
ci / test (push) Successful in 17s
ci / mcdc (push) Successful in 18s
ci / bench (push) Successful in 8s
ci / patches-apply (push) Successful in 16s
ci / prune-artifacts (push) Skipped
ci / qemu-tools (push) Successful in 39s
ci / quality (push) Successful in 26s
ci / badges (push) Skipped
2026-09-28 03:30:57 -06:00
NoahandClaude Opus 5.5 4636f0fe4c ci: keep PATH when the quality job runs npm under sudo
ci / bench (pull_request) Successful in 5s
ci / qemu-tools (pull_request) Successful in 39s
ci / quality (pull_request) Successful in 26s
ci / badges (pull_request) Skipped
ci / test (push) Successful in 15s
ci / bench (push) Successful in 9s
ci / kernel-build (push) Skipped
ci / mcdc (push) Successful in 19s
ci / qemu-tools (push) Successful in 38s
ci / patches-apply (push) Successful in 27s
ci / prune-artifacts (push) Skipped
ci / quality (push) Successful in 28s
ci / badges (push) Skipped
ci / test (pull_request) Successful in 13s
ci / mcdc (pull_request) Successful in 12s
ci / patches-apply (pull_request) Successful in 16s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
sudo resets PATH to its secure_path, and the Gitea job image keeps node
and npm in the runner tool cache, so 'sudo npm' was not found. Pass the
job's PATH through; GitHub-hosted runners behave the same either way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-09-28 02:42:47 -06:00
NoahandClaude Opus 5.5 fe29ece741 ci: let the quality job's pip install run on the Gitea runners
ci / test (push) Successful in 12s
ci / mcdc (push) Successful in 13s
ci / bench (push) Successful in 5s
ci / test (pull_request) Successful in 12s
ci / patches-apply (pull_request) Successful in 15s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / quality (pull_request) Failing after 12s
ci / badges (pull_request) Skipped
ci / qemu-tools (push) Successful in 39s
ci / patches-apply (push) Successful in 16s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Failing after 15s
ci / badges (push) Skipped
ci / mcdc (pull_request) Successful in 12s
ci / bench (pull_request) Successful in 5s
ci / qemu-tools (pull_request) Successful in 37s
The first CI run on Gitea (1447) failed only in quality: the job image's
Python is PEP 668 externally managed, so 'pip install lizard ruff' is
refused. GitHub's hosted runners set PIP_BREAK_SYSTEM_PACKAGES; set the
same for that step, which runs in a throwaway container on a throwaway
VM.

Refs #2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-09-28 02:09:30 -06:00
NoahandClaude Opus 5.5 b30621e372 Clear the shellcheck findings that would fail qemu-tools
ci / patches-apply (pull_request) Successful in 20s
ci / qemu-tools (pull_request) Successful in 40s
ci / prune-artifacts (pull_request) Skipped
ci / quality (pull_request) Failing after 13s
ci / badges (pull_request) Skipped
ci / bench (pull_request) Successful in 5s
ci / mcdc (pull_request) Successful in 15s
ci / kernel-build (pull_request) Skipped
ci / test (pull_request) Successful in 11s
CI has not run on this repository since the move to Gitea (Actions was
off), and 13 shellcheck findings accumulated in the files the qemu-tools
job lints, so that job would fail the moment Actions is enabled.

- test-ui-drive-rs485.sh: eight `cond && pass || fail` checks become
  if/then/else, so a pass() that returned non-zero could never also
  record a failure.
- ui-drive.sh and mk-bootimg.sh: four `[ A ] && [ B ] || die` guards get
  explicit braces; the behaviour is unchanged.
- fetch-vendor.sh: the unused fourth read field is `_desc`; it still
  has to be read so the loop's other fields are split correctly.

Every qemu-tools step passes locally, including all four rs485 cases.

Closes #2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-09-28 01:28:24 -06:00
noah 0cf46ba1a4 Merge pull request 'qemu: provision a real U-Boot env and add expect_reboot' (#1) from qemu-env-partition into flare-edge-next
Merge qemu-env-partition: real U-Boot env on the QEMU rig and expect_reboot (flare-edge#62)
2026-09-28 01:26:07 -06:00
NoahandClaude Opus 5.5 5fd6d2da5b qemu: provision a real U-Boot env and add expect_reboot
The rig's env partition was left zeroed, so flared could never clear
bootcount there. It treats that as "intentional reboot bookkeeping not
durable", so every factory reset on the rig wiped the store, was then
refused, and never rebooted (flare-edge#62). mkimage.sh now writes a
valid 32 KiB Rockchip ENVF image (bootcount=0, LE CRC32 over the rest),
the same format flared/src/envf.rs and flare-edge tools/envf.py read;
tools/envf.py parses it with a matching CRC.

An accepted reset then reboots the guest, which ends the VM under
-no-reboot. qmp.py gains expect_reboot TIMEOUT_S for an action whose
correct outcome is a reboot: it passes only when the console shows the
kernel's orderly "reboot: Restarting system" (written after the step
began) and QEMU is gone, and fails on a kernel panic, on an exit without
that line, and on a VM still running at the deadline. The console is
read after the liveness check so the guest's last lines are not missed.
Six drive tests cover it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-09-28 00:32:14 -06:00
11 changed files with 279 additions and 35 deletions
+9 -1
View File
@@ -148,6 +148,8 @@ jobs:
# on the debug channel. All offline (a stub qemu-system-arm on
# PATH), so it runs on every push/PR, not only a real boot.
run: bash qemu/tests/run-sh-args-test.sh
- name: rig init honours reboot/poweroff/halt (#5)
run: bash qemu/tests/init-power-signals-test.sh
- name: mkimage.sh SEED_DIR regression test
# Only ui-drive.sh --seed (a real VM boot) exercises this hook
# otherwise; this builds the same unprivileged mkfs.ext4 image and
@@ -340,10 +342,16 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: install analyzers
# The job image's Python is PEP 668 "externally managed", so a plain
# pip install is refused. GitHub's hosted runners set this same
# variable; here every job runs in a throwaway container on a
# throwaway VM (the GARM runners), so nothing outlives the job.
env:
PIP_BREAK_SYSTEM_PACKAGES: "1"
run: |
sudo apt-get update -qq && sudo apt-get install -y -qq cppcheck shellcheck
pip install --quiet lizard ruff
sudo npm install --silent -g jscpd
sudo env "PATH=$PATH" npm install --silent -g jscpd
curl -fsSL -o /tmp/scc.tar.gz \
https://github.com/boyter/scc/releases/download/v3.6.0/scc_Linux_x86_64.tar.gz
sudo tar -C /usr/local/bin -xzf /tmp/scc.tar.gz scc
+1 -1
View File
@@ -66,7 +66,7 @@ tree_path() {
}
rc=0
while IFS=$'\t' read -r name url commit desc; do
while IFS=$'\t' read -r name url commit _desc; do
case "$name" in ''|\#*) continue ;; esac
path="$(tree_path "$name")"
+3 -3
View File
@@ -52,8 +52,8 @@ while [ $# -gt 0 ]; do
esac
done
[ -n "$KERNEL" ] && [ -f "$KERNEL" ] || { echo "FATAL: --kernel: no such file" >&2; exit 1; }
[ -n "$DTB" ] && [ -f "$DTB" ] || { echo "FATAL: --dtb: no such file" >&2; exit 1; }
{ [ -n "$KERNEL" ] && [ -f "$KERNEL" ]; } || { echo "FATAL: --kernel: no such file" >&2; exit 1; }
{ [ -n "$DTB" ] && [ -f "$DTB" ]; } || { echo "FATAL: --dtb: no such file" >&2; exit 1; }
[ -n "$OUT" ] || { echo "FATAL: --out is required" >&2; exit 1; }
command -v mkimage >/dev/null || {
echo "FATAL: mkimage not on PATH (Debian/Ubuntu: u-boot-tools)" >&2; exit 1; }
@@ -76,7 +76,7 @@ if [ -z "$RTOOL" ]; then
[ -x "$c" ] && { RTOOL="$c"; break; }
done
fi
[ -n "$RTOOL" ] && [ -x "$RTOOL" ] || {
{ [ -n "$RTOOL" ] && [ -x "$RTOOL" ]; } || {
echo "FATAL: resource_tool not found; pass --resource-tool PATH" >&2; exit 1; }
WORKDIR="$(mktemp -d)"
+27 -1
View File
@@ -186,10 +186,16 @@ place_partition() {
# scenarios. Bytes mirror flare-edge tools/mk-misc.py provisioning
# defaults (A: prio 15 successful, B: prio 14 successful, CRC32-BE).
misc) stage="__misc__" ;;
# env carries a REAL U-Boot environment: flared clears bootcount there
# before an intentional reboot, and treats a zeroed (bad-CRC) env as
# "bookkeeping not durable", so a factory reset on the rig was always
# refused (flare-edge#62). Format mirrors flare-edge flared/src/envf.rs
# and tools/envf.py: LE CRC32 of the rest, NUL-separated entries.
env) stage="__env__" ;;
# Boot-chain partitions the VM never reads: present at the right offsets,
# left zeroed. Enumerated (not a wildcard) so a typo'd name in
# blkdevparts.conf fails HERE, not as a confusing mount error at boot.
env|idblock|uboot|boot_a|boot_b|recovery) stage="" ;;
idblock|uboot|boot_a|boot_b|recovery) stage="" ;;
*) echo "FATAL: unknown partition name '$name' in blkdevparts.conf" >&2; exit 1 ;;
esac
DISK_END_TRACK "$off" "$size"
@@ -220,6 +226,26 @@ PYMISC
qemu_log " $name: AvbABData provisioned @ +2048"
return 0
fi
if [ "$stage" = "__env__" ]; then
python3 - "$img" "$size" <<'PYENV'
import struct, sys, zlib
img, size = sys.argv[1], int(sys.argv[2])
ENV_SIZE = 0x8000 # CONFIG_ENV_SIZE; flared refuses any other length
if size < ENV_SIZE:
sys.exit(f"FATAL: env partition is {size} bytes, need {ENV_SIZE}")
body = bytearray(ENV_SIZE - 4)
entries = b"bootcount=0\0\0" # one entry, then the empty terminator
body[:len(entries)] = entries
env = struct.pack("<I", zlib.crc32(bytes(body)) & 0xFFFFFFFF) + bytes(body)
buf = bytearray(size)
buf[:ENV_SIZE] = env
open(img, "wb").write(buf)
PYENV
dd if="$img" of="$DISK" bs=4096 seek=$((off / 4096)) \
conv=notrunc,sparse status=none
qemu_log " $name: U-Boot env provisioned (bootcount=0)"
return 0
fi
mkfs_part "$stage" "$size" "$img"
dd if="$img" of="$DISK" bs=4096 seek=$((off / 4096)) \
conv=notrunc,sparse status=none
+21
View File
@@ -41,3 +41,24 @@ warden_slot() {
esac
echo "$slot"
}
# PID 1 must answer busybox's reboot/poweroff/halt itself: they only signal
# PID 1 (TERM, USR2, USR1), and the kernel drops any signal PID 1 has no
# handler for. A panel's busybox init handles them; without this the rig
# ignored a plain `reboot` (bfe-core1106-sdk#5). The -f forms skip init, and
# the kernel still prints its orderly "reboot: Restarting system" line.
# WARDEN_REBOOT_CMD / WARDEN_POWEROFF_CMD exist for the host test only.
warden_trap_power_signals() {
trap 'echo "init: reboot requested"; sync; ${WARDEN_REBOOT_CMD:-reboot -f}' TERM
trap 'echo "init: poweroff requested"; sync; ${WARDEN_POWEROFF_CMD:-poweroff -f}' USR2
trap 'echo "init: halt requested"; sync; ${WARDEN_POWEROFF_CMD:-poweroff -f}' USR1
}
# Idle forever in a way a trapped signal interrupts at once: a foreground
# `sleep` would hold the trap until it returned, up to an hour later.
warden_idle_forever() {
while :; do
sleep 3600 &
wait $!
done
}
+4 -2
View File
@@ -239,5 +239,7 @@ if grep -qw warden.shell /proc/cmdline; then
poweroff -f
fi
# Hold: daemons run, console idles, scenarios drive the VM from outside.
while :; do sleep 3600; done
# Hold: daemons run, console idles, scenarios drive the VM from outside. As
# PID 1 this shell must honour reboot/poweroff/halt itself (#5).
warden_trap_power_signals
warden_idle_forever
+46
View File
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
# Regression test for bfe-core1106-sdk#5: the rig's PID 1 script ignored
# busybox reboot/poweroff/halt, which only signal PID 1. Runs the real
# helpers from qemu/rootfs/etc/warden-lib.sh in a plain sh with stub
# commands, idles it the way /sbin/init does, sends each signal and requires
# the matching action within two seconds.
set -uo pipefail
# Job control: each case's shell leads its own process group, so cleanup can
# kill the whole group. An orphaned `sleep 3600` would otherwise keep this
# script's output pipe open for an hour when a case fails.
set -m
HERE="$(cd "$(dirname "$0")" && pwd)"
LIB="$HERE/../rootfs/etc/warden-lib.sh"
SH="${WARDEN_TEST_SH:-sh}"
WORK="$(mktemp -d)" || exit 1
trap 'rm -rf "$WORK"' EXIT
FAIL=0
run_case() { # run_case <signal> <expected marker> <label>
local sig="$1" want="$2" label="$3" out="$WORK/$1.out"
: > "$out"
WARDEN_REBOOT_CMD="eval echo reboot >> $out; exit 0" \
WARDEN_POWEROFF_CMD="eval echo poweroff >> $out; exit 0" \
"$SH" -c ". '$LIB'; warden_trap_power_signals; warden_idle_forever" &
local pid=$!
sleep 0.5
kill -"$sig" "$pid"
local n=0
while ! grep -qx "$want" "$out" && [ "$n" -lt 20 ]; do
sleep 0.1; n=$((n + 1))
done
if grep -qx "$want" "$out"; then
echo "[PASS] $label"
else
echo "[FAIL] $label (got: $(tr '\n' ' ' < "$out"))"; FAIL=1
fi
kill -KILL -- "-$pid" 2>/dev/null
wait "$pid" 2>/dev/null
}
run_case TERM reboot "SIGTERM (busybox reboot) reboots at once"
run_case USR2 poweroff "SIGUSR2 (busybox poweroff) powers off at once"
run_case USR1 poweroff "SIGUSR1 (busybox halt) powers off at once"
exit "$FAIL"
+61 -2
View File
@@ -716,7 +716,9 @@ class Ctx:
need_ctl, need_imgtools and fresh_region move here since verb handlers,
not drive(), are what call them now). One instance per run."""
def __init__(self, s, f, size, ctl, refs, refs_path, rs485_control, outdir, script_path):
def __init__(self, s, f, size, ctl, refs, refs_path, rs485_control, outdir, script_path,
console_path=None):
self.console_path = console_path
self.s = s
self.f = f
self.size = size
@@ -809,6 +811,61 @@ def verb_sleep(ctx, lineno, cmd, args, line):
return "ok", ""
REBOOT_MARKER = b"reboot: Restarting system"
PANIC_MARKER = b"Kernel panic"
def verb_expect_reboot(ctx, lineno, cmd, args, line):
"""expect_reboot TIMEOUT_S: the guest reboots, in an orderly way, within
TIMEOUT_S seconds (flare-edge#62). For an action whose correct outcome IS a
reboot (factory reset, Reboot, the A/B Boot button), which used to be
untestable here: run.sh boots with -no-reboot, so the reboot ends the VM.
Passes only when both hold: the console shows the kernel's orderly restart
line, written after this step began, and QEMU is gone (QMP closed or
reporting shutdown). A kernel panic, a VM that exits without the orderly
line, and a VM still running at the deadline all fail. It must be a
script's last command: nothing can run on a VM that has left."""
timeout = float(args[0])
if not ctx.console_path:
sys.exit(f"FATAL: {ctx.script_path}:{lineno}: '{cmd}' needs --console")
try:
start = os.path.getsize(ctx.console_path)
except OSError:
start = 0
deadline = time.monotonic() + timeout
def console_since_start():
try:
with open(ctx.console_path, "rb") as fh:
fh.seek(start)
return fh.read()
except OSError:
return b""
while True:
try:
gone = rpc(ctx.s, ctx.f, {"execute": "query-status"}).get("status") == "shutdown"
except (RuntimeError, OSError, ValueError):
gone = True
# Read the console AFTER asking whether QEMU is gone: the guest's last
# lines (the restart line, or a panic) arrive just before it exits,
# and a read taken first would judge a finished reboot on stale text.
tail = console_since_start()
if PANIC_MARKER in tail:
return "fail", "kernel panic, not an orderly reboot"
restarted = REBOOT_MARKER in tail
if gone:
if restarted:
return "ok", ""
return "fail", "the VM exited without the kernel's orderly restart line"
if time.monotonic() >= deadline:
if restarted:
return "fail", f"the guest restarted but QEMU was still running after {timeout:g}s"
return "fail", f"no reboot within {timeout:g}s"
time.sleep(0.2)
def verb_echo(ctx, lineno, cmd, args, line):
print(f" [{lineno}] {' '.join(args)}", flush=True)
return None
@@ -1098,6 +1155,7 @@ VERBS = {
"assert_region": verb_assert_region,
"wait_region": verb_wait_region,
"assert_ocr": verb_assert_ocr,
"expect_reboot": verb_expect_reboot,
}
@@ -1120,7 +1178,8 @@ def drive(s, f, script_path, outdir, size, ctl_path=None, console_path=None, ref
print(f" [{lineno}] {tag}{cmd}{(' -- ' + detail) if detail else ''}", flush=True)
refs_path = refs_path or os.path.join(outdir, "refs.json")
ctx = Ctx(s, f, size, ctl, load_refs(refs_path), refs_path, rs485_control, outdir, script_path)
ctx = Ctx(s, f, size, ctl, load_refs(refs_path), refs_path, rs485_control, outdir, script_path,
console_path)
console = ConsoleWatch(console_path)
for lineno, raw in enumerate(lines, 1):
+40 -24
View File
@@ -98,15 +98,21 @@ printf '#!/usr/bin/env python3\nimport sys; sys.exit(1)\n' > "$FLARE_EDGE/tools/
# without a subshell: run_rig's RIG_OUT/RIG_RC writes land here directly, so
# nothing needs to be re-serialized as text and re-parsed back out below.
FLARE_EDGE="$FLARE_EDGE" TEST_MAKE_RS_SOCK='' run_rig "$work"
[ "$RIG_RC" -ne 0 ] \
&& pass "case A: never-appeared rs.sock fails the run (rc=$RIG_RC)" \
|| fail "case A: never-appeared rs.sock fails the run: rc=$RIG_RC, out: $RIG_OUT"
printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 bus socket never appeared' \
&& pass "case A: FATAL names the missing rs.sock" \
|| fail "case A: FATAL names the missing rs.sock: $RIG_OUT"
printf '%s\n' "$RIG_OUT" | grep -qF '== rs485 simulator:' \
&& fail "case A: printed the rs485-live success line over a bus that was never up: $RIG_OUT" \
|| pass "case A: never claims the bus is live"
if [ "$RIG_RC" -ne 0 ]; then
pass "case A: never-appeared rs.sock fails the run (rc=$RIG_RC)"
else
fail "case A: never-appeared rs.sock fails the run: rc=$RIG_RC, out: $RIG_OUT"
fi
if printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 bus socket never appeared'; then
pass "case A: FATAL names the missing rs.sock"
else
fail "case A: FATAL names the missing rs.sock: $RIG_OUT"
fi
if printf '%s\n' "$RIG_OUT" | grep -qF '== rs485 simulator:'; then
fail "case A: printed the rs485-live success line over a bus that was never up: $RIG_OUT"
else
pass "case A: never claims the bus is live"
fi
# --- case B: rs.sock is up but socat never creates rs.pty -------------------
work="$SCRATCH/b"; build_rig "$work"
@@ -117,12 +123,16 @@ FAKEBIN="$SCRATCH/fakebin-b"; mkdir -p "$FAKEBIN"
printf '#!/usr/bin/env bash\necho "FAKE SOCAT: simulated failure" >&2\nexit 1\n' > "$FAKEBIN/socat"
chmod +x "$FAKEBIN/socat"
FLARE_EDGE="$FLARE_EDGE" TEST_MAKE_RS_SOCK=1 PATH="$FAKEBIN:$PATH" run_rig "$work"
[ "$RIG_RC" -ne 0 ] \
&& pass "case B: socat never linking rs.pty fails the run (rc=$RIG_RC)" \
|| fail "case B: socat never linking rs.pty fails the run: rc=$RIG_RC, out: $RIG_OUT"
printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 socat never created rs.pty' \
&& pass "case B: FATAL names the missing rs.pty" \
|| fail "case B: FATAL names the missing rs.pty: $RIG_OUT"
if [ "$RIG_RC" -ne 0 ]; then
pass "case B: socat never linking rs.pty fails the run (rc=$RIG_RC)"
else
fail "case B: socat never linking rs.pty fails the run: rc=$RIG_RC, out: $RIG_OUT"
fi
if printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 socat never created rs.pty'; then
pass "case B: FATAL names the missing rs.pty"
else
fail "case B: FATAL names the missing rs.pty: $RIG_OUT"
fi
# --- case C: rs.sock+rs.pty are up but mbsim.py crashes before rs.ctl -------
work="$SCRATCH/c"; build_rig "$work"
@@ -135,15 +145,21 @@ sys.stderr.write("FAKE MBSIM: simulated crash before opening the control socket\
sys.exit(1)
EOS
FLARE_EDGE="$FLARE_EDGE" TEST_MAKE_RS_SOCK=1 TEST_MBSIM_PID_FILE='' run_rig "$work"
[ "$RIG_RC" -ne 0 ] \
&& pass "case C: mbsim.py crashing before rs.ctl fails the run (rc=$RIG_RC)" \
|| fail "case C: mbsim.py crashing before rs.ctl fails the run: rc=$RIG_RC, out: $RIG_OUT"
printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 simulator (mbsim.py) never came up' \
&& pass "case C: FATAL names the dead simulator" \
|| fail "case C: FATAL names the dead simulator: $RIG_OUT"
printf '%s\n' "$RIG_OUT" | grep -qF 'FAKE MBSIM: simulated crash' \
&& pass "case C: mbsim.log is dumped on failure" \
|| fail "case C: mbsim.log is dumped on failure: $RIG_OUT"
if [ "$RIG_RC" -ne 0 ]; then
pass "case C: mbsim.py crashing before rs.ctl fails the run (rc=$RIG_RC)"
else
fail "case C: mbsim.py crashing before rs.ctl fails the run: rc=$RIG_RC, out: $RIG_OUT"
fi
if printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 simulator (mbsim.py) never came up'; then
pass "case C: FATAL names the dead simulator"
else
fail "case C: FATAL names the dead simulator: $RIG_OUT"
fi
if printf '%s\n' "$RIG_OUT" | grep -qF 'FAKE MBSIM: simulated crash'; then
pass "case C: mbsim.log is dumped on failure"
else
fail "case C: mbsim.log is dumped on failure: $RIG_OUT"
fi
# --- case D: a sim process that ignores SIGTERM is still reaped ------------
work="$SCRATCH/d"; build_rig "$work"
+66
View File
@@ -858,6 +858,72 @@ class DriveConsoleCheck(unittest.TestCase):
self.assertTrue(all(r["line"] == 1 for r in rows))
class ExpectReboot(unittest.TestCase):
"""expect_reboot (flare-edge#62): an action whose correct outcome is a
reboot ends the VM on this rig (-no-reboot), so the reboot itself is the
thing to assert. QEMU's behaviour is scripted through the fake rpc: each
query-status call can append console output and then report the VM gone."""
def run_reboot(self, steps, before=b"", timeout="2"):
d = tempfile.mkdtemp(prefix="console.")
console = os.path.join(d, "console.log")
with open(console, "wb") as fh:
fh.write(before)
calls = []
def rpc(sock, sock_file, obj):
if obj.get("execute") != "query-status":
return fake_rpc(sock, sock_file, obj)
step = steps[min(len(calls), len(steps) - 1)]
calls.append(step)
text, state = step
if text:
with open(console, "ab") as fh:
fh.write(text)
if state == "gone":
raise RuntimeError("QMP connection closed")
return {"status": state}
return run_script(f"expect_reboot {timeout}\n", rpc_fn=rpc, console_path=console)
def test_orderly_reboot_passes(self):
rc, by, rows = self.run_reboot([
(b"", "running"),
(b"[ 12.3] reboot: Restarting system\n", "running"),
(b"", "gone"),
])
self.assertIsNone(rc)
self.assertEqual(rows[-1]["status"], "ok", rows)
def test_qmp_reporting_shutdown_counts_as_gone(self):
rc, by, rows = self.run_reboot([(b"reboot: Restarting system\n", "shutdown")])
self.assertEqual(rows[-1]["status"], "ok", rows)
def test_no_reboot_before_the_deadline_fails(self):
rc, by, rows = self.run_reboot([(b"", "running")], timeout="0.5")
self.assertEqual(rc, 1)
self.assertIn("no reboot within", rows[-1]["detail"])
def test_a_kernel_panic_is_not_a_reboot(self):
rc, by, rows = self.run_reboot([
(b"Kernel panic - not syncing: Attempted to kill init!\n"
b"reboot: Restarting system\n", "gone"),
])
self.assertEqual(rc, 1)
self.assertIn("kernel panic", rows[-1]["detail"])
def test_exiting_without_the_orderly_line_fails(self):
rc, by, rows = self.run_reboot([(b"", "gone")])
self.assertEqual(rc, 1)
self.assertIn("without the kernel's orderly restart line", rows[-1]["detail"])
def test_a_restart_line_from_before_the_step_does_not_count(self):
rc, by, rows = self.run_reboot([(b"", "gone")],
before=b"reboot: Restarting system\n")
self.assertEqual(rc, 1)
self.assertIn("without the kernel's orderly restart line", rows[-1]["detail"])
class FullscreenToggleTracksRealState(unittest.TestCase):
"""qemu/tests/scripts/fullscreen-toggle-tracks-real-state.txt, offline:
`home` clears the dashboard's real fullscreen state directly, and a
+1 -1
View File
@@ -195,7 +195,7 @@ if [ -n "$RS485_DEVICES" ]; then
# simulator the serial device it expects; mbsim then answers the guest's
# Modbus polls with the corpus profiles' own register maps.
command -v socat >/dev/null || { echo "FATAL: --rs485-devices needs socat" >&2; exit 1; }
[ -n "${FLARE_EDGE:-}" ] && [ -f "$FLARE_EDGE/tools/modbus-sim/mbsim.py" ] || {
{ [ -n "${FLARE_EDGE:-}" ] && [ -f "$FLARE_EDGE/tools/modbus-sim/mbsim.py" ]; } || {
echo "FATAL: --rs485-devices needs FLARE_EDGE to point at a flare-edge checkout (mbsim.py)" >&2; exit 1; }
wait_for_path "$WORK/rs.sock"
[ -S "$WORK/rs.sock" ] || {