Compare commits

...
Author SHA1 Message Date
BFE EngineeringandClaude Opus 5.5 b94fd156b4 qemu: control bridge waits out a slow UI and never hands on a late reply
ci / test (push) Successful in 2m34s
ci / mcdc (push) Successful in 48s
ci / bench (push) Successful in 25s
ci / qemu-tools (push) Successful in 4m5s
ci / patches-apply (push) Successful in 2m26s
ci / quality (push) Successful in 1m36s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / kernel-symbols (push) Successful in 7m19s
ci / badges (push) Skipped
ci / mcdc (pull_request) Successful in 56s
ci / bench (pull_request) Successful in 17s
ci / test (pull_request) Successful in 2m29s
ci / patches-apply (pull_request) Successful in 1m25s
ci / qemu-tools (pull_request) Successful in 4m54s
ci / quality (pull_request) Successful in 2m16s
ci / badges (pull_request) Skipped
ci / kernel-symbols (pull_request) Successful in 5m57s
The bridge waited 5 s for warden-ui's reply. On the lenovo QEMU host a
page build outran it: the bridge answered an empty reply, and the UI's
late reply then landed after the next command's remove and was read as
that command's answer (flare-edge#1448: "page is ''", a nav answered
with the previous hit).

The loop moves to warden_ctl_bridge in etc/warden-lib.sh so a host test
reaches it. The wait is 30 s (WARDEN_CTL_WAIT_S); a timeout answers
"bridge: no reply from warden-ui ...", which qmp.py raises as a rig
fault, and the next command first drains the late reply. Replies slower
than 5 s are logged on the console with their time. qmp.py's control
socket timeout is 90 s so it outlasts the bridge's wait.

Tests: qemu/tests/ctl-bridge-test.sh (new, in CI), test_qmp_drive.py.

Refs flare-edge#1448

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
2026-10-21 00:32:37 -06:00
noah f435a7d665 Merge pull request 'qemu: power-signal test waits for the trap install (rebuild)' (#23) from rb/lf-fix-sdk22 into rebuild
ci / test (push) Successful in 9s
ci / mcdc (push) Successful in 15s
ci / qemu-tools (push) Successful in 52s
ci / patches-apply (push) Successful in 22s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 30s
ci / badges (push) Skipped
ci / bench (push) Successful in 9s
ci / kernel-symbols (push) Successful in 2m33s
2026-10-17 21:19:12 -06:00
BFE EngineeringandClaude Opus 5.5 be4ad86230 qemu: power-signal test waits for the trap install (#22)
ci / mcdc (pull_request) Successful in 16s
ci / test (push) Successful in 10s
ci / mcdc (push) Successful in 17s
ci / bench (push) Successful in 5s
ci / qemu-tools (push) Successful in 50s
ci / patches-apply (push) Successful in 24s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / kernel-symbols (push) Successful in 2m40s
ci / test (pull_request) Successful in 9s
ci / quality (push) Successful in 34s
ci / badges (push) Skipped
ci / bench (pull_request) Successful in 7s
ci / qemu-tools (pull_request) Successful in 54s
ci / prune-artifacts (pull_request) Skipped
ci / patches-apply (pull_request) Successful in 27s
ci / kernel-symbols (pull_request) Successful in 2m30s
ci / kernel-build (pull_request) Skipped
ci / quality (pull_request) Successful in 44s
ci / badges (pull_request) Skipped
init-power-signals-test.sh slept a fixed 0.5 s before sending each signal.
On a loaded runner the shell had not installed its traps yet, so SIGTERM
took its default action and the case failed with nothing written.

Each case now polls /proc/<pid>/status until SigCgt has the signal's bit
(10 s hang backstop, WARDEN_TEST_TRAP_WAIT_S), and fails clearly if the
handler never appears. Regression: a case whose handler install is held
back 1.5 s (fails on the old fixed sleep), plus a check that the wait gives
up on a shell without a handler.

Fixes #22

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
2026-10-17 17:51:08 -06:00
noah aadf0e7f07 Merge pull request 'qemu: input consumption wait is a hang backstop (flare-edge#1138)' (#20) from rb/lf-fix-1138 into rebuild
ci / test (push) Successful in 12s
ci / bench (push) Successful in 8s
ci / patches-apply (push) Successful in 24s
ci / mcdc (push) Successful in 20s
ci / qemu-tools (push) Successful in 1m12s
ci / quality (push) Successful in 31s
ci / kernel-symbols (push) Successful in 2m15s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / badges (push) Skipped
2026-10-17 17:19:08 -06:00
BFE EngineeringandClaude Opus 5.5 6f931bf3ad qemu: input consumption wait is a hang backstop (flare-edge#1138)
ci / bench (push) Successful in 8s
ci / qemu-tools (push) Successful in 57s
ci / patches-apply (push) Successful in 23s
ci / test (push) Successful in 12s
ci / mcdc (push) Successful in 21s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 55s
ci / kernel-symbols (push) Successful in 2m45s
ci / kernel-symbols (pull_request) Successful in 2m17s
ci / badges (push) Skipped
ci / qemu-tools (pull_request) Successful in 55s
ci / patches-apply (pull_request) Successful in 24s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / quality (pull_request) Successful in 28s
ci / badges (pull_request) Skipped
ci / test (pull_request) Successful in 11s
ci / bench (pull_request) Successful in 6s
ci / mcdc (pull_request) Successful in 13s
The runner waited 2 s for the guest to count an injected press or
release. On a loaded runner the release that opens the drawer took
longer, so navigation/drawer-drag-release-policy failed both attempts
although the UI handled the swipe. The wait is now a 20 s hang backstop;
a wait over 2 s still passes and puts "slow guest: input consumed after
N s" in the step's detail.

Regression: test_swipe_release_counted_late_on_a_loaded_guest_passes
(release counted 2.5 s after the drag; fails with the 2 s bound), plus
a prompt-release case and a never-counted case bounded by the backstop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
2026-10-17 14:24:59 -06:00
noahandClaude Sonnet 5.5 5507842878 Merge pull request 'Single M0 kernel batch with CONFIG_SUSPEND off' (#17) from rb/w04-kernel-options into rebuild
ci / kernel-symbols (push) Successful in 1m40s
ci / patches-apply (push) Successful in 15s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 25s
ci / badges (push) Skipped
ci / test (push) Successful in 8s
ci / mcdc (push) Successful in 13s
ci / bench (push) Successful in 5s
ci / qemu-tools (push) Successful in 46s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cxh2piVufTWbzKTmUafTkk
2026-10-09 20:08:37 -06:00
8 changed files with 387 additions and 67 deletions
+2
View File
@@ -155,6 +155,8 @@ jobs:
run: bash qemu/tests/init-power-signals-test.sh
- name: rig init daemon order matches the panel (flare-edge#348)
run: bash qemu/tests/init-daemon-order-test.sh
- name: rig control bridge waits out a slow UI (flare-edge#1448)
run: bash qemu/tests/ctl-bridge-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
+1
View File
@@ -106,6 +106,7 @@ All take the virt-fragment `<zImage>`; `FLARE_EDGE=<checkout>` where noted.
| `real-image-boot.sh` | matched `rootfs.img` + `oem.img` | an ACTUAL flare-edge build (placed by `mkimage.sh --rootfs-image/--oem-image`) boots its own init chain to getty; binaries predating known fixes reproduce their bugs faithfully, a time machine for field issues |
| `test-ui-drive-rs485.sh` | - | offline, no VM: a fake `run.sh` and (for one case) a fake `socat` stand in so `ui-drive.sh --rs485-devices`'s startup fails closed instead of printing a false "== rs485 simulator: ..." over a bus nothing is serving, for each of a qemu rs.sock that never appears, a socat that never links rs.pty, and an mbsim.py that dies before opening rs.ctl; also proves `cleanup()` escalates to SIGKILL for a sim process that ignores SIGTERM |
| `run-sh-args-test.sh` | - | offline, no VM: a fake `qemu-system-arm` captures run.sh's own argv and pins the ctl/rs485 pci-serial ordering contract rootfs/sbin/init's ttyS0-vs-ttyS1 alias depends on -- the ctl device always enumerates before rs485, warden.ctl only lands on the cmdline when --ctl is given, and an rs485 pci-serial device (real or null-backed) is always present so the port count never shifts |
| `ctl-bridge-test.sh` | - | offline, no VM: runs the control bridge (`warden_ctl_bridge` in rootfs/etc/warden-lib.sh) against a fake warden-ui that answers some commands late. A reply slower than the old 5 s bound still arrives (the bound is now 30 s, `WARDEN_CTL_WAIT_S`), a timeout answers `bridge: no reply from warden-ui ...` (qmp.py raises it as a rig fault), and a timed-out command's late reply is drained instead of being read as the next command's answer (flare-edge #1448) |
| watchdog (`run.sh --watchdog`) | - | arm `/dev/watchdog`, don't pet: the VM resets ~30 s later (verified) |
Scenario fine print:
+79
View File
@@ -62,3 +62,82 @@ warden_idle_forever() {
wait $!
done
}
# The control bridge's command loop (/sbin/init runs it on the ctl serial
# port): one command per line on stdin, the reply then the sentinel line
# <<END>> on stdout. qmp.py's Ctl matches the sentinel byte for byte.
#
# `@cat PATH` is answered here and never forwarded: PATH's contents (or one
# "bridge: no such file: PATH" line), which is how the json flow channel
# reads webstatus.c's snapshot from outside the VM. Everything else goes to
# warden-ui's FIFO, and the bridge waits for the reply file the UI renames
# into place whole. The previous reply is removed BEFORE sending: a fixed
# settle handed back the previous command's reply (flare-edge #152).
#
# The wait is bounded by WARDEN_CTL_WAIT_S (default 30 s of polling). It was
# 5 s, and a slow QEMU host (lenovo-x3650, two TCG guests) let a page build
# outrun it: the bridge answered an empty reply, and the UI's late reply
# then landed after the NEXT command's remove and was read as that
# command's answer (flare-edge #1448). Now a timeout answers one
# "bridge: no reply from warden-ui ..." line (qmp.py treats it as a rig
# fault), and the next command first waits, on the same bound, for the late
# reply and discards it. A reply slower than 5 s is logged on stderr (the
# console) with its time, for the host-speed baselines.
#
# WARDEN_CTL_FIFO and WARDEN_CTL_REPLY exist for the host test only.
warden_ctl_bridge() {
_wcb_fifo="${WARDEN_CTL_FIFO:-/tmp/warden-ui.ctl}"
_wcb_reply="${WARDEN_CTL_REPLY:-/tmp/warden-ui.dbg}"
_wcb_limit=$(( ${WARDEN_CTL_WAIT_S:-30} * 20 ))
_wcb_stale=0
while IFS= read -r cmd; do
[ -n "$cmd" ] || continue
case "$cmd" in
"@cat "*)
path="${cmd#@cat }"
if [ -f "$path" ]; then
cat "$path"
# The status json has no trailing newline; without this
# the sentinel would share its line and the line-based
# reader would never see it.
echo
else
echo "bridge: no such file: $path"
fi
;;
*)
if [ -p "$_wcb_fifo" ]; then
if [ "$_wcb_stale" = 1 ]; then
_wcb_wait_reply
_wcb_stale=0
fi
rm -f "$_wcb_reply"
printf '%s\n' "$cmd" > "$_wcb_fifo"
if _wcb_wait_reply; then
cat "$_wcb_reply" 2>/dev/null
else
echo "bridge: no reply from warden-ui within $((_wcb_limit / 20)) s: $cmd"
_wcb_stale=1
fi
if [ "$_wcb_n" -gt 100 ]; then
echo "ctl bridge: slow reply, $((_wcb_n / 20)) s of polling: $cmd" >&2
fi
else
echo "bridge: warden-ui control FIFO not present"
fi
;;
esac
echo "<<END>>"
done
}
# Polls for a non-empty reply file every 0.05 s, up to the bridge's bound;
# leaves the poll count in _wcb_n.
_wcb_wait_reply() {
_wcb_n=0
while [ ! -s "$_wcb_reply" ]; do
[ "$_wcb_n" -ge "$_wcb_limit" ] && return 1
sleep 0.05
_wcb_n=$((_wcb_n + 1))
done
}
+3 -48
View File
@@ -192,54 +192,9 @@ if grep -qw warden.ctl /proc/cmdline && [ -c /dev/ttyS0 ]; then
# mode: the host discards echoed input, and a whole line arrives per
# read.
exec 3<> "$ctl"
while IFS= read -r cmd <&3; do
[ -n "$cmd" ] || continue
case "$cmd" in
"@cat "*)
# A bridge-local command, never forwarded to warden-ui's
# FIFO: `@cat PATH` reads PATH directly off the GUEST's
# own filesystem and answers with it, which is how the
# json flow channel gets webstatus.c's snapshot out to
# the host driving the VM from outside. `-f` so a
# directory or device node reports as missing rather than
# cat hanging or erroring oddly.
path="${cmd#@cat }"
if [ -f "$path" ]; then
cat "$path" >&3
# Force a newline after the file's own bytes: the
# status json (webstatus.c) is written with NO
# trailing newline, and without this the sentinel
# below would land on the SAME line as the content
# and the reader (qmp.py Ctl.send, line-based) would
# block forever waiting for a line that never comes.
echo >&3
else
echo "bridge: no such file: $path" >&3
fi
;;
*)
if [ -p /tmp/warden-ui.ctl ]; then
# Remove the previous reply BEFORE sending, then wait
# for the new one to appear (the UI renames it into
# place whole). A fixed settle used to hand back the
# previous command's reply whenever a page took longer
# than 0.3 s to build (flare-edge #152); this is the
# same recipe tools/warden-ctl uses over SSH.
rm -f /tmp/warden-ui.dbg
printf '%s\n' "$cmd" > /tmp/warden-ui.ctl
n=0
while [ ! -s /tmp/warden-ui.dbg ] && [ "$n" -lt 100 ]; do
sleep 0.05
n=$((n + 1))
done
cat /tmp/warden-ui.dbg 2>/dev/null >&3
else
echo "bridge: warden-ui control FIFO not present" >&3
fi
;;
esac
echo "<<END>>" >&3
done
# The loop itself is warden_ctl_bridge (/etc/warden-lib.sh), where
# the host test reaches it.
warden_ctl_bridge <&3 >&3
) &
fi
+109
View File
@@ -0,0 +1,109 @@
#!/usr/bin/env bash
# Host test for the rig's control bridge, warden_ctl_bridge in
# qemu/rootfs/etc/warden-lib.sh (flare-edge #1448). A fake warden-ui reads
# the FIFO and renames each reply into place, as warden_debug.c does; some
# commands answer late. Checks: a reply slower than the old 5 s bound still
# arrives, a timeout answers the explicit no-reply line, and the late reply
# of a timed-out command is never handed to the next command.
set -uo pipefail
# Job control: the fake UI leads its own process group, so one kill stops
# its pending sleep too.
set -m
HERE="$(cd "$(dirname "$0")" && pwd)"
LIB="$HERE/../rootfs/etc/warden-lib.sh"
SH="${WARDEN_TEST_SH:-sh}"
WORK="$(mktemp -d)" || exit 1
UI_PID=
stop_ui() {
[ -n "$UI_PID" ] || return 0
{ kill -KILL -- "-$UI_PID"; wait "$UI_PID"; } 2>/dev/null
UI_PID=
}
cleanup() {
stop_ui
rm -rf "$WORK"
}
trap cleanup EXIT
FAIL=0
CHECKS=0
check() { # check <label> <command...>
CHECKS=$((CHECKS + 1))
if "${@:2}"; then
echo "[PASS] $1"
else
echo "[FAIL] $1"
FAIL=1
fi
}
# The fake UI: "slowN" answers after N tenths of a second, anything else at
# once. Replies are "reply:<command>", written to a temp file and renamed.
start_ui() {
mkfifo "$WORK/ctl"
(
while :; do
IFS= read -r cmd < "$WORK/ctl" || continue
case "$cmd" in
slow*) sleep "$(awk -v t="${cmd#slow}" 'BEGIN { print t / 10 }')" ;;
esac
printf 'reply:%s\n' "$cmd" > "$WORK/dbg.tmp"
mv "$WORK/dbg.tmp" "$WORK/dbg"
done
) &
UI_PID=$!
}
run_bridge() { # run_bridge <name> <wait s or ""> <lines...>
local name="$1" wait="$2"
shift 2
printf '%s\n' "$@" |
env WARDEN_CTL_FIFO="$WORK/ctl" WARDEN_CTL_REPLY="$WORK/dbg" \
${wait:+WARDEN_CTL_WAIT_S="$wait"} \
"$SH" -c ". '$LIB'; warden_ctl_bridge" > "$WORK/$name.out" 2> "$WORK/$name.err"
}
same() { # same <file> <expected lines...>
local file="$1"
shift
diff <(printf '%s\n' "$@") "$file" > "$WORK/diff" || { cat "$WORK/diff"; return 1; }
}
start_ui
# A 1 s bound, a 1.5 s reply: the explicit no-reply line, then the next
# command gets ITS reply, not the late one (the desync behind #1448).
run_bridge timeout 1 fast1 slow15 fast2
check "timeout answers no-reply; the late reply is not the next answer" \
same "$WORK/timeout.out" reply:fast1 '<<END>>' \
'bridge: no reply from warden-ui within 1 s: slow15' '<<END>>' \
reply:fast2 '<<END>>'
# The default bound: a 6 s reply (over the old 5 s) still arrives, and the
# console note gives its time.
run_bridge slow "" slow60 after
check "default bound: a 6 s reply arrives" \
same "$WORK/slow.out" reply:slow60 '<<END>>' reply:after '<<END>>'
check "slow reply logged on stderr" grep -Eq "^ctl bridge: slow reply, [5-7] s of polling: slow60\$" "$WORK/slow.err"
check "fast reply not logged" bash -c "! grep -q after '$WORK/slow.err'"
# @cat is answered by the bridge itself, with a newline after the file.
printf '{"a":1}' > "$WORK/status.json"
run_bridge cat 1 "@cat $WORK/status.json" "@cat $WORK/missing"
check "@cat answers the file and a missing-file line" \
same "$WORK/cat.out" '{"a":1}' '<<END>>' "bridge: no such file: $WORK/missing" '<<END>>'
# No FIFO: one line, no wait.
stop_ui
rm -f "$WORK/ctl"
run_bridge nofifo 1 page
check "missing FIFO answers at once" \
same "$WORK/nofifo.out" 'bridge: warden-ui control FIFO not present' '<<END>>'
if [ "$FAIL" = 0 ]; then
echo "ctl-bridge tests: OK ($CHECKS checks)"
else
echo "ctl-bridge tests: FAILED"
exit 1
fi
+47 -5
View File
@@ -3,7 +3,9 @@
# 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.
# the matching action within two seconds. Each signal goes out only once the
# shell has its handler installed (SigCgt), so a slow start cannot turn the
# signal's default action into a false failure (bfe-core1106-sdk#22).
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
@@ -16,15 +18,41 @@ SH="${WARDEN_TEST_SH:-sh}"
WORK="$(mktemp -d)" || exit 1
trap 'rm -rf "$WORK"' EXIT
FAIL=0
# Hang backstop for the handler install; a quiet host takes milliseconds.
TRAP_WAIT_S="${WARDEN_TEST_TRAP_WAIT_S:-10}"
run_case() { # run_case <signal> <expected marker> <label>
local sig="$1" want="$2" label="$3" out="$WORK/$1.out"
# Succeeds once <pid> catches <signal>: its bit is set in /proc SigCgt.
catches() { # catches <pid> <signal name>
local mask num
mask="$(awk '/^SigCgt:/ { print $2 }' "/proc/$1/status" 2>/dev/null)"
num="$(kill -l "$2")" || return 1
[ -n "$mask" ] && (( (16#$mask >> (num - 1)) & 1 ))
}
# Waits up to TRAP_WAIT_S for <pid> to catch <signal>.
wait_trapped() { # wait_trapped <pid> <signal name>
local n=0 limit=$((TRAP_WAIT_S * 10))
until catches "$1" "$2"; do
[ "$n" -ge "$limit" ] && return 1
sleep 0.1; n=$((n + 1))
done
}
# <delay> holds the handler install back, as a loaded runner does.
run_case() { # run_case <signal> <expected marker> <label> [delay s]
local sig="$1" want="$2" label="$3" delay="${4:-0}" 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" &
"$SH" -c "sleep $delay; . '$LIB'; warden_trap_power_signals; warden_idle_forever" &
local pid=$!
sleep 0.5
if ! wait_trapped "$pid" "$sig"; then
echo "[FAIL] $label (SIG$sig handler not installed within ${TRAP_WAIT_S} s)"
FAIL=1
kill -KILL -- "-$pid" 2>/dev/null
wait "$pid" 2>/dev/null
return
fi
kill -"$sig" "$pid"
local n=0
while ! grep -qx "$want" "$out" && [ "$n" -lt 20 ]; do
@@ -42,5 +70,19 @@ run_case() { # run_case <signal> <expected marker> <label>
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"
# Regression for bfe-core1106-sdk#22: the old fixed 0.5 s sleep sent SIGTERM
# before this shell installed its trap, killing it with nothing written.
run_case TERM reboot "SIGTERM after a slow handler install still reboots" 1.5
# The wait itself must fail, not hang or pass, when no handler ever appears.
"$SH" -c 'sleep 3600' &
pid=$!
if TRAP_WAIT_S=1 wait_trapped "$pid" TERM; then
echo "[FAIL] wait_trapped reported a handler a plain shell never installs"; FAIL=1
else
echo "[PASS] wait_trapped gives up on a shell without a handler"
fi
kill -KILL -- "-$pid" 2>/dev/null
wait "$pid" 2>/dev/null
exit "$FAIL"
+56 -14
View File
@@ -154,7 +154,13 @@ def _load_imgtools():
AXIS_MAX = 32767
TAP_HOLD_S = 0.35
TAP_OBSERVE_TIMEOUT_S = 2.0
# How long the runner waits for the guest to count an injected press or
# release. A behaviour check, not a budget: a loaded runner (two TCG VMs on a
# shared host) has taken longer than 2 s to count the release that opens the
# drawer (flare-edge#1138), so the wait is a hang backstop. A wait longer than
# INPUT_SLOW_NOTE_S still passes and says so in the step's detail.
TAP_OBSERVE_TIMEOUT_S = 20.0
INPUT_SLOW_NOTE_S = 2.0
# Bounds every blocking read on the QMP socket -- the greeting banner, the
# qmp_capabilities handshake, and every screendump/tap/quit round trip --
@@ -166,6 +172,12 @@ TAP_OBSERVE_TIMEOUT_S = 2.0
# wedged qemu-system-arm cannot outlive the script.
QMP_TIMEOUT_S = 20.0
# Bounds each recv() on the control channel. It must outlast the bridge's
# own reply wait (WARDEN_CTL_WAIT_S, 30 s of 0.05 s polls, which take longer
# in wall time on a slow TCG guest), so a slow UI reaches the driver as the
# bridge's explicit "no reply" line rather than a bare socket timeout.
CTL_TIMEOUT_S = 90.0
# Where webstatus.c (ui-src/src/warden/webstatus.c) publishes its atomic
# snapshot inside the guest. assert_json/wait_json `@cat` this path over the
# control channel; see the bridge in rootfs/sbin/init.
@@ -223,19 +235,36 @@ def do_tap(s, f, ax, ay, hold=TAP_HOLD_S):
def wait_input_count(ctx, field, before):
"""Wait until one guest input counter advances."""
"""Wait until one guest input counter advances.
Records the longest wait of the current verb in ctx.input_wait_s, so a
slow guest shows in the results without failing the step."""
if before is None:
time.sleep(0.05)
return True
deadline = time.monotonic() + TAP_OBSERVE_TIMEOUT_S
start = time.monotonic()
deadline = start + TAP_OBSERVE_TIMEOUT_S
while time.monotonic() < deadline:
now = parse_stats(ctx.ctl.send("stats")).get(field)
if now is not None and now != before:
waited = time.monotonic() - start
ctx.input_wait_s = max(getattr(ctx, "input_wait_s", 0.0), waited)
return True
time.sleep(0.02)
return False
def input_verdict(ctx, observed):
"""The (status, detail) of a tap, swipe or fling from its observation."""
if not observed:
return ("fail", "input press or release was not consumed within "
f"{TAP_OBSERVE_TIMEOUT_S:g} seconds")
waited = getattr(ctx, "input_wait_s", 0.0)
if waited > INPUT_SLOW_NOTE_S:
return "ok", f"slow guest: input consumed after {waited:.1f} s"
return "ok", ""
def do_observed_tap(ctx, ax, ay):
"""Wait until the guest consumes both halves of a tap."""
before = parse_stats(ctx.ctl.send("stats"))
@@ -327,12 +356,12 @@ class Ctl:
# rootfs/sbin/init's ctl bridge (the FIFO-to-socket relay this class
# talks to). Nothing enforces the two staying in sync -- a sentinel
# changed on one side and not the other means send() below blocks until
# its own 15s timeout on every ctl-dependent step, with nothing at that
# its own CTL_TIMEOUT_S on every ctl-dependent step, with nothing at that
# point pointing back at this mismatch as the cause.
SENTINEL = "<<END>>"
# A real reply (a hit's box, the status JSON) is at most a few KB. The
# 15s socket timeout below bounds each individual recv(), not the total
# socket timeout below bounds each individual recv(), not the total
# bytes accepted, so a peer that keeps streaming data fast enough to beat
# that per-call timeout, but never emits a newline or SENTINEL, would
# otherwise grow self.buf without limit and exhaust host memory before
@@ -340,7 +369,13 @@ class Ctl:
# silent or closes outright already does.
MAX_BUF = 256 * 1024
def __init__(self, path, timeout=15.0):
# The bridge's own answer when warden-ui did not reply within its bound
# (warden_ctl_bridge in rootfs/etc/warden-lib.sh, flare-edge #1448).
NO_REPLY = "bridge: no reply from warden-ui"
def __init__(self, path, timeout=None):
if timeout is None:
timeout = CTL_TIMEOUT_S
self.sock = socket.socket(socket.AF_UNIX)
self.sock.settimeout(timeout)
self.sock.connect(path)
@@ -369,7 +404,12 @@ class Ctl:
if line.strip() == cmd.strip():
continue
lines.append(line)
return "\n".join(lines).strip()
reply = "\n".join(lines).strip()
# A UI that did not answer in time is a rig fault, not evidence: an
# empty reply judged as "page is ''" hid it (flare-edge #1448).
if reply.startswith(self.NO_REPLY):
raise RuntimeError(f"control channel: {reply}")
return reply
HIT_RE = re.compile(r'^hit \d+,\d+: (\S+)(?: text="(.*)" box=(-?\d+),(-?\d+),(\d+)x(\d+))?$')
@@ -402,7 +442,7 @@ def poll_until(check, timeout_s, period=0.5):
they all mean the same thing by a timeout.
A CHECK that raises RuntimeError or OSError -- the control channel
dying mid-poll, e.g. a socket.timeout past Ctl's own 15s per-call
dying mid-poll, e.g. a socket.timeout past Ctl's own CTL_TIMEOUT_S per-call
timeout -- stops polling right there instead of retrying a channel
that is probably gone, and comes back with FATAL true so the caller
records a `fatal` row (the same idea as ConsoleWatch.check() turning a
@@ -733,6 +773,8 @@ class Ctx:
# console size when the step before this one began (flare-edge#233).
self.next_cmd = None
self.prev_step_console = 0
# The longest input-count wait of the current tap, swipe or fling.
self.input_wait_s = 0.0
def need_ctl(self, lineno, cmd):
if self.ctl is None:
@@ -792,6 +834,7 @@ def verb_shot(ctx, lineno, cmd, args, line):
def verb_tap(ctx, lineno, cmd, args, line):
x, y = int(args[0]), int(args[1])
ctx.tap_sent = False
ctx.input_wait_s = 0.0
try:
observed = do_observed_tap(ctx, to_axis(x, ctx.size), to_axis(y, ctx.size))
except (RuntimeError, OSError):
@@ -804,23 +847,22 @@ def verb_tap(ctx, lineno, cmd, args, line):
if ctx.next_cmd == "expect_reboot" and ctx.tap_sent:
return "ok", "tap sent; the control channel closed as the guest went down"
raise
return (("ok", "") if observed else
("fail", "input press or release was not consumed within 2 seconds"))
return input_verdict(ctx, observed)
def verb_swipe(ctx, lineno, cmd, args, line):
ms = int(args[4]) if len(args) > 4 else 400
ctx.input_wait_s = 0.0
observed = do_observed_swipe(
ctx, int(args[0]), int(args[1]), int(args[2]), int(args[3]), ms)
return (("ok", "") if observed else
("fail", "input press or release was not consumed within 2 seconds"))
return input_verdict(ctx, observed)
def verb_fling(ctx, lineno, cmd, args, line):
ctx.input_wait_s = 0.0
observed = do_observed_swipe(
ctx, int(args[0]), int(args[1]), int(args[2]), int(args[3]), ms=120)
return (("ok", "") if observed else
("fail", "input press or release was not consumed within 2 seconds"))
return input_verdict(ctx, observed)
def verb_sleep(ctx, lineno, cmd, args, line):
+90
View File
@@ -15,6 +15,7 @@ was never compared with the one the reference was captured under.
"""
import json
import os
import re
import socket
import subprocess
import sys
@@ -339,6 +340,52 @@ class PureHelpers(unittest.TestCase):
self.assertEqual(len(calls), 2)
self.assertEqual(calls[-1], [qmp.btn_ev(False)])
def _swipe_on_fake_clock(self, release_at_s):
"""verb_swipe against a guest that counts the press at once and the
release only once release_at_s of fake time has passed (None: never).
Returns the verdict and the fake time the verb took."""
clock = [0.0]
replies = iter(["presses: 0\nreleases: 0"]) # the baseline read
def send(cmd):
late = release_at_s is not None and clock[0] >= release_at_s
return next(replies, f"presses: 1\nreleases: {1 if late else 0}")
ctx = SimpleNamespace(s=None, f=None, size=720,
ctl=SimpleNamespace(send=send), input_wait_s=0.0)
def sleep(seconds):
clock[0] += seconds
saved = qmp.send_events, qmp.time.sleep, qmp.time.monotonic
qmp.send_events = lambda _s, _f, _events: None
qmp.time.sleep = sleep
qmp.time.monotonic = lambda: clock[0]
try:
verdict = qmp.verb_swipe(ctx, 1, "swipe", ["2", "350", "520", "352", "3000"], "")
finally:
qmp.send_events, qmp.time.sleep, qmp.time.monotonic = saved
return verdict, clock[0]
def test_swipe_release_counted_late_on_a_loaded_guest_passes(self):
# flare-edge#1138: the release that opens the drawer was counted
# after more than 2 s on a loaded runner; the old 2 s bound failed
# the swipe although the guest handled it. It passes, with a note.
(status, detail), _ = self._swipe_on_fake_clock(release_at_s=3.0 + 2.5)
self.assertEqual(status, "ok")
self.assertIn("slow guest: input consumed after 2.5 s", detail)
def test_swipe_release_counted_promptly_has_no_note(self):
(status, detail), _ = self._swipe_on_fake_clock(release_at_s=3.0 + 0.5)
self.assertEqual((status, detail), ("ok", ""))
def test_swipe_release_never_counted_fails_at_the_backstop(self):
(status, detail), took = self._swipe_on_fake_clock(release_at_s=None)
self.assertEqual(status, "fail")
self.assertIn(f"within {qmp.TAP_OBSERVE_TIMEOUT_S:g} seconds", detail)
# Bounded: the 3 s drag plus the backstop, and not much more.
self.assertLess(took, 3.0 + qmp.TAP_OBSERVE_TIMEOUT_S + 1.0)
def test_every_pixel_round_trips_through_lvgl_calibration(self):
# lv_evdev.c _evdev_calibrate: px = axis * (width - 1) / AXIS_MAX,
# integer division. A tap requested at px must land at px, for every
@@ -1113,6 +1160,49 @@ class CtlSocketProtocol(unittest.TestCase):
th.join(timeout=2)
self.assertEqual(got, "the actual reply")
def test_bridge_no_reply_line_raises_as_a_rig_fault(self):
# flare-edge #1448: a UI slower than the bridge's wait came back as
# an empty reply and was judged "page is ''". The bridge now says
# so, and that line must stop the flow as a rig fault.
def server():
self.server_sock.recv(4096)
self.server_sock.sendall(
b"bridge: no reply from warden-ui within 30 s: page\n<<END>>\n")
th = threading.Thread(target=server, daemon=True)
th.start()
try:
with self.assertRaises(RuntimeError) as cm:
self.ctl.send("page")
finally:
th.join(timeout=2)
self.assertIn("no reply from warden-ui", str(cm.exception))
def test_bridge_no_such_file_stays_an_ordinary_reply(self):
# Only the no-reply line is a fault; @cat's missing-file answer is
# a detail the json channel handles itself.
def server():
self.server_sock.recv(4096)
self.server_sock.sendall(b"bridge: no such file: /x\n<<END>>\n")
th = threading.Thread(target=server, daemon=True)
th.start()
try:
got = self.ctl.send("@cat /x")
finally:
th.join(timeout=2)
self.assertEqual(got, "bridge: no such file: /x")
def test_ctl_timeout_outlasts_the_bridge_wait(self):
# The bridge polls up to 30 s (more wall time on a slow guest); a
# shorter socket timeout would turn its explicit answer into a bare
# socket.timeout. Read the bridge default from the rootfs itself.
lib = os.path.join(HERE, "..", "rootfs", "etc", "warden-lib.sh")
with open(lib) as f:
m = re.search(r"WARDEN_CTL_WAIT_S:-(\d+)", f.read())
self.assertIsNotNone(m, "warden_ctl_bridge default wait not found")
self.assertGreaterEqual(qmp.CTL_TIMEOUT_S, 2 * int(m.group(1)))
def test_leftover_bytes_after_sentinel_carry_over_to_the_next_send(self):
# One write carries this reply's SENTINEL immediately followed by
# bytes belonging to the NEXT command's reply -- proving self.buf