qemu: ui-drive waits for the chain start on an init-chain boot (flare-edge#2295)
ci / test (pull_request) Successful in 24s
ci / mcdc (pull_request) Successful in 17s
ci / badges (push) Skipped
ci / test (push) Successful in 9s
ci / qemu-tools (push) Successful in 1m27s
ci / bench (pull_request) Successful in 5s
ci / mcdc (push) Successful in 12s
ci / bench (push) Successful in 5s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / patches-apply (push) Successful in 43s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / patches-apply (pull_request) Successful in 24s
ci / quality (pull_request) Successful in 2m35s
ci / kernel-symbols (pull_request) Successful in 5m7s
ci / quality (push) Successful in 1m28s
ci / qemu-tools (pull_request) Successful in 1m36s
ci / badges (pull_request) Skipped
ci / kernel-symbols (push) Successful in 5m2s

ui-drive.sh --init-chain boots with warden.initchain, where sbin/init starts
the UI through the panel's S99lvgl and prints "init: chain started N
script(s)"; the direct-start line "init: starting warden-ui" is never
printed. ui-drive.sh still waited for that line, so the first flare-edge
"QEMU UI shipped init chain" run (job 99350) gave "warden-ui never started"
after 180 s on a chain that had booted cleanly.

The wait moves to qemu/tests/ui-start.sh (sourced by ui-drive.sh and
ui-shot.sh): wait_ui_started picks the marker by mode and, on a chain boot,
fails at once on WARDEN-QEMU-INITCHAIN-EMPTY or a failed S99lvgl instead of
at the deadline.

Tests: new qemu/tests/ui-start-test.sh (27 checks, in CI): every marker is
the one sbin/init or warden-lib.sh prints in that mode, the job 99350
console counts as started in chain mode, empty and failed chains fail fast,
a dead VM and a silent console fail with their own messages, and both
drivers wait through the helper. The old ui-drive.sh fails 4 checks.

Fixes flare-edge#2295

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
This commit is contained in:
BFE Engineering
2026-10-28 17:17:14 -06:00
co-authored by Claude Opus 5.5
parent 6e51f1a0e5
commit a9f2b9b26a
5 changed files with 226 additions and 22 deletions
+5
View File
@@ -178,6 +178,11 @@ jobs:
if command -v busybox >/dev/null; then
WARDEN_TEST_SH="busybox sh" bash qemu/tests/init-chain-test.sh
fi
- name: ui-drive.sh / ui-shot.sh UI start wait regression test (flare-edge#2295)
# The console line that means "UI started" differs between a direct
# start and a shipped init chain boot; every marker is checked
# against sbin/init, and a chain failure fails at once.
run: bash qemu/tests/ui-start-test.sh
- name: mkimage.sh ROOTFS_OVERLAY regression test (flare-edge#2210)
# The panel's scripts land in both slots with their modes; an overlay
# reaching outside etc/ and usr/, or holding a symlink, writes no image.
+5 -11
View File
@@ -36,6 +36,8 @@
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # qemu/tests/
QDIR="$(cd "$HERE/.." && pwd)" # qemu/
# shellcheck source=qemu/tests/ui-start.sh disable=SC1091
. "$HERE/ui-start.sh"
SEED_FILE=""
REFS_FILE=""
@@ -252,17 +254,9 @@ if [ -n "$RS485_DEVICES" ]; then
fi
echo "== waiting for warden-ui"
deadline=$((SECONDS + 180))
while [ $SECONDS -lt $deadline ]; do
grep -aq 'init: starting warden-ui' "$WORK/console.log" && break
kill -0 "$QEMU_PID" 2>/dev/null || { echo "FATAL: VM exited early" >&2; tail -25 "$WORK/console.log" >&2; exit 1; }
sleep 2
done
grep -aq 'init: starting warden-ui' "$WORK/console.log" || {
echo "FATAL: warden-ui never started (no fb0? wrong kernel?)" >&2
tail -25 "$WORK/console.log" >&2
exit 1
}
# A chain boot reports the start through the chain, not the direct-start line
# (ui-start.sh, flare-edge#2295).
wait_ui_started "$WORK/console.log" "$QEMU_PID" 180 "$([ -n "$INIT_CHAIN" ] && echo 1 || echo 0)" || exit 1
# A started process is not a rendered frame. Poll screendumps until the panel
# stops being a single flat colour, on a bounded deadline: TCG renders CPU-bound
+3 -11
View File
@@ -13,6 +13,8 @@ set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # qemu/tests/
QDIR="$(cd "$HERE/.." && pwd)" # qemu/
# shellcheck source=qemu/tests/ui-start.sh disable=SC1091
. "$HERE/ui-start.sh"
ZIMAGE="${1:-}"
OUTDIR="${2:-$QDIR/out}"
@@ -66,17 +68,7 @@ if [ -z "$QEMU_PID" ] || ! kill -0 "$QEMU_PID" 2>/dev/null; then
exit 1
fi
deadline=$((SECONDS + 120))
while [ $SECONDS -lt $deadline ]; do
grep -aq 'init: starting warden-ui' "$WORK/console.log" && break
kill -0 "$QEMU_PID" 2>/dev/null || { echo "FATAL: VM exited early" >&2; tail -25 "$WORK/console.log" >&2; exit 1; }
sleep 2
done
grep -aq 'init: starting warden-ui' "$WORK/console.log" || {
echo "FATAL: warden-ui never started (no fb0? wrong kernel?)" >&2
tail -25 "$WORK/console.log" >&2
exit 1
}
wait_ui_started "$WORK/console.log" "$QEMU_PID" 120 0 || exit 1
qmp() { python3 "$HERE/qmp.py" "$WORK/qmp.sock" "$@"; }
+152
View File
@@ -0,0 +1,152 @@
#!/usr/bin/env bash
# shellcheck disable=SC2016 # the single-quoted $ strings are literal patterns and child-shell args
# Host test for qemu/tests/ui-start.sh (flare-edge#2295): the console line
# ui-drive.sh and ui-shot.sh wait for before driving the UI. Offline, no VM.
#
# flare-edge job 99350 (the first "QEMU UI shipped init chain" run) booted
# the chain cleanly but ui-drive.sh waited 180 s for the direct-start line,
# which a warden.initchain boot never prints. This test pins:
# - every marker ui-start.sh waits for is printed by rootfs/sbin/init or
# rootfs/etc/warden-lib.sh, in the mode it is used for;
# - a chain-boot console (the 99350 lines) counts as started in chain
# mode, and a direct-start console in direct mode;
# - an empty chain and a failed S99lvgl fail at once, not at the deadline;
# - a dead VM and a silent console fail with their own messages;
# - ui-drive.sh and ui-shot.sh wait through ui-start.sh only, and
# ui-drive.sh passes chain mode exactly when --init-chain is given.
#
# bash ui-start-test.sh
set -uo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
INIT="$HERE/../rootfs/sbin/init"
LIB="$HERE/../rootfs/etc/warden-lib.sh"
WORK="$(mktemp -d "${TMPDIR:-/tmp}/warden-ui-start.XXXXXX")" || exit 1
VMPID=""
# shellcheck disable=SC2317 # called from the EXIT trap
cleanup() { [ -n "$VMPID" ] && kill "$VMPID" 2>/dev/null; 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
}
# shellcheck source=qemu/tests/ui-start.sh disable=SC1091
. "$HERE/ui-start.sh"
UI_START_POLL=0.1
export UI_START_POLL
# --- the markers are the ones init prints -----------------------------------
check "direct-start marker is echoed by sbin/init" \
grep -qF "echo \"$UI_START_DIRECT" "$INIT"
check "chain marker is echoed by sbin/init" \
grep -qF "echo \"$UI_START_CHAIN" "$INIT"
check "empty-chain marker is echoed by sbin/init" \
grep -qF "echo \"$UI_FAIL_CHAIN_EMPTY" "$INIT"
check "the chain marker is printed only on a chain boot" \
awk -v m="echo \"$UI_START_CHAIN" '
/^if \[ "\$initchain" = 1 \]; then/ { inchain = 1 }
inchain && /^fi$/ { inchain = 0 }
index($0, m) { found = 1; if (!inchain) bad = 1 }
END { exit !(found && !bad) }' "$INIT"
check "the direct-start marker is printed only on a direct boot" \
awk -v m="echo \"$UI_START_DIRECT" '
/^if \[ "\$initchain" = 0 \]/ { indirect = 1 }
indirect && /^fi$/ { indirect = 0 }
index($0, m) { found = 1; if (!indirect) bad = 1 }
END { exit !(found && !bad) }' "$INIT"
check "ui_start_marker picks the mode's marker" \
test "$(ui_start_marker 0)|$(ui_start_marker 1)" = "$UI_START_DIRECT|$UI_START_CHAIN"
# The S99lvgl failure line, from the real warden_init_chain with a failing stub.
D="$WORK/init.d"
mkdir -p "$D"
printf '#!/bin/sh\nexit 4\n' > "$D/S99lvgl"
chmod 0755 "$D/S99lvgl"
WARDEN_INITD="$D" sh -c '. "$1"; warden_init_chain 10 99' sh "$LIB" > /dev/null 2> "$WORK/lvgl-fail.err"
check "warden_init_chain prints the S99lvgl failure line ui-start.sh watches for" \
grep -qF "$UI_FAIL_CHAIN_LVGL rc=4" "$WORK/lvgl-fail.err"
# --- console fixtures -------------------------------------------------------
# Chain boot, as flare-edge job 99350 printed it.
cat > "$WORK/chain.log" <<'EOF'
WARDEN-QEMU-ROOTFS-OK slot=_a
init: shipped init chain (warden.initchain)
init: chain S03warden-accounts start
Creating platform accounts: OK
init: rig bus up on /run/warden/bus/bus.sock (broker pid 253)
init: starting warden-modbus
init: starting warden-flared
init: chain S99lvgl start
warden-ui: no backlight device
Starting Warden UI: OK
init: chain started 2 script(s)
init: control bridge on /dev/ttyS0
EOF
cat > "$WORK/direct.log" <<'EOF'
WARDEN-QEMU-ROOTFS-OK slot=_a
init: starting warden-modbus
init: starting warden-ui (fbdev)
EOF
cat > "$WORK/empty-chain.log" <<'EOF'
init: shipped init chain (warden.initchain)
init: starting warden-flared
WARDEN-QEMU-INITCHAIN-EMPTY: warden.initchain but no /etc/init.d/S* script; the UI is not started
EOF
{ head -n 8 "$WORK/chain.log"; cat "$WORK/lvgl-fail.err"; } > "$WORK/lvgl-fail.log"
: > "$WORK/silent.log"
sleep 60 &
VMPID=$!
run_wait() { # run_wait <log> <secs> <chain>: rc in $RC, stderr in $WORK/err, seconds in $TOOK
local t0=$SECONDS
wait_ui_started "$WORK/$1" "$VMPID" "$2" "$3" 2> "$WORK/err"
RC=$?
TOOK=$((SECONDS - t0))
}
run_wait chain.log 5 1
check "chain console counts as started in chain mode (flare-edge#2295)" test "$RC" = 0
run_wait chain.log 0 0
check "the same console is not a direct start (the 99350 failure)" test "$RC" = 1
check "a direct-mode timeout names the direct start" \
grep -qF "warden-ui never started" "$WORK/err"
run_wait direct.log 5 0
check "direct console counts as started in direct mode" test "$RC" = 0
run_wait direct.log 0 1
check "a direct console is not a chain start" test "$RC" = 1
check "a chain-mode timeout names the chain marker" \
grep -qF "the shipped init chain never reported its start" "$WORK/err"
run_wait empty-chain.log 30 1
check "an empty chain fails" test "$RC" = 1
check "an empty chain fails at once, not at the deadline" test "$TOOK" -lt 5
check "an empty chain says why" grep -qF "has no /etc/init.d/S* script" "$WORK/err"
run_wait lvgl-fail.log 30 1
check "a failed S99lvgl fails" test "$RC" = 1
check "a failed S99lvgl fails at once" test "$TOOK" -lt 5
check "a failed S99lvgl names its status" grep -qF "S99lvgl start FAILED rc=4" "$WORK/err"
run_wait silent.log 1 1
check "a silent console times out" test "$RC" = 1
kill "$VMPID" 2>/dev/null
wait "$VMPID" 2>/dev/null
run_wait silent.log 30 1
check "a dead VM fails at once with its own message" \
sh -c 'test "$1" = 1 && test "$2" -lt 5 && grep -qF "VM exited early" "$3"' sh "$RC" "$TOOK" "$WORK/err"
VMPID=""
# --- the drivers use it -----------------------------------------------------
for s in ui-drive.sh ui-shot.sh; do
check "$s sources ui-start.sh" grep -qF '. "$HERE/ui-start.sh"' "$HERE/$s"
check "$s waits through wait_ui_started" grep -q '^wait_ui_started ' "$HERE/$s"
done
check "no driver greps a UI start marker of its own" \
sh -c '! grep -lF "init: starting warden-ui" "$1"/*.sh | grep -v "/ui-start.sh$" | grep -v "/ui-start-test.sh$" | grep -q .' sh "$HERE"
check "ui-drive.sh waits in chain mode exactly when --init-chain is given" \
grep -qF 'wait_ui_started "$WORK/console.log" "$QEMU_PID" 180 "$([ -n "$INIT_CHAIN" ] && echo 1 || echo 0)"' "$HERE/ui-drive.sh"
echo "ui-start: $CHECKS checks, $([ "$FAIL" = 0 ] && echo OK || echo FAILED)"
exit "$FAIL"
+61
View File
@@ -0,0 +1,61 @@
# shellcheck shell=bash
# Sourced by ui-drive.sh and ui-shot.sh: wait for stage-2 init to report the
# UI started, from the VM console log.
#
# The console line depends on how the UI is started (rootfs/sbin/init):
# direct start (default) "init: starting warden-ui (fbdev)"
# shipped chain (warden.initchain, ui-drive.sh --init-chain)
# "init: chain started N script(s)", after
# the panel's S99lvgl ran; the direct start
# line is never printed (flare-edge#2295)
# A chain boot that cannot start the UI says so at once, so these fail fast
# instead of spending the whole deadline:
# "WARDEN-QEMU-INITCHAIN-EMPTY" no /etc/init.d/S* script at all
# "init: chain S99lvgl start FAILED rc=N" the UI's own script failed
# qemu/tests/ui-start-test.sh checks every marker here against sbin/init.
UI_START_DIRECT='init: starting warden-ui'
UI_START_CHAIN='init: chain started '
UI_FAIL_CHAIN_EMPTY='WARDEN-QEMU-INITCHAIN-EMPTY'
UI_FAIL_CHAIN_LVGL='init: chain S99lvgl start FAILED'
# ui_start_marker <initchain 0|1>: the console line that means "UI started".
ui_start_marker() {
if [ "${1:-0}" = 1 ]; then printf '%s' "$UI_START_CHAIN"; else printf '%s' "$UI_START_DIRECT"; fi
}
# wait_ui_started <console.log> <qemu pid> <seconds> <initchain 0|1>
# Returns 0 once the UI is reported started; prints a FATAL line and the
# console tail to stderr and returns 1 on a VM exit, a chain failure or the
# deadline.
wait_ui_started() {
local log="$1" pid="$2" secs="$3" chain="${4:-0}" marker deadline
marker="$(ui_start_marker "$chain")"
deadline=$((SECONDS + secs))
while :; do
grep -aqF "$marker" "$log" && return 0
if [ "$chain" = 1 ]; then
if grep -aqF "$UI_FAIL_CHAIN_EMPTY" "$log"; then
echo "FATAL: the init chain has no /etc/init.d/S* script, so warden-ui is not started" >&2
tail -25 "$log" >&2
return 1
fi
if grep -aqF "$UI_FAIL_CHAIN_LVGL" "$log"; then
echo "FATAL: S99lvgl failed in the shipped init chain: $(grep -aF "$UI_FAIL_CHAIN_LVGL" "$log" | head -1)" >&2
tail -25 "$log" >&2
return 1
fi
fi
kill -0 "$pid" 2>/dev/null || { echo "FATAL: VM exited early" >&2; tail -25 "$log" >&2; return 1; }
[ $SECONDS -lt $deadline ] || break
sleep "${UI_START_POLL:-2}"
done
grep -aqF "$marker" "$log" && return 0
if [ "$chain" = 1 ]; then
echo "FATAL: the shipped init chain never reported its start ('$marker' not on the console)" >&2
else
echo "FATAL: warden-ui never started (no fb0? wrong kernel?)" >&2
fi
tail -25 "$log" >&2
return 1
}