Compare commits

...
Author SHA1 Message Date
BFE Engineering 333c237949 Merge remote-tracking branch 'origin/rebuild' into rb/ln-init-chain-boot
ci / test (push) Skipped
ci / mcdc (push) Skipped
ci / bench (push) Skipped
ci / qemu-tools (push) Skipped
ci / kernel-symbols (push) Skipped
ci / patches-apply (push) Skipped
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Skipped
ci / badges (push) Skipped
ci / bench (pull_request) Successful in 20s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / quality (pull_request) Successful in 42s
ci / test (pull_request) Successful in 15s
ci / mcdc (pull_request) Successful in 1m3s
ci / kernel-symbols (pull_request) Successful in 5m24s
ci / qemu-tools (pull_request) Successful in 1m58s
ci / patches-apply (pull_request) Successful in 31s
ci / badges (pull_request) Skipped
2026-10-28 11:38:54 -06:00
noah f46a3519aa Merge pull request 'qemu: boot the UI through the panel shipped init chain (flare-edge#2210)' (#32) from rb/ln-init-chain into rebuild
ci / test (push) Successful in 17s
ci / qemu-tools (push) Successful in 3m14s
ci / patches-apply (push) Successful in 50s
ci / bench (push) Successful in 6s
ci / mcdc (push) Successful in 23s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 37s
ci / badges (push) Skipped
ci / kernel-symbols (push) Successful in 2m3s
2026-10-28 11:32:36 -06:00
BFE EngineeringandClaude Opus 5.5 f04a31dc06 qemu: ui-drive --init-chain and the assert_ui_chain verb (flare-edge#2210)
ci / qemu-tools (push) Successful in 3m26s
ci / test (push) Successful in 25s
ci / bench (push) Successful in 18s
ci / mcdc (push) Successful in 32s
ci / quality (push) Successful in 35s
ci / badges (push) Skipped
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / patches-apply (push) Successful in 24s
ci / kernel-symbols (push) Successful in 5m45s
ui-drive.sh --init-chain DIR lays the panel's scripts over the rootfs
(ROOTFS_OVERLAY) and boots with warden.initchain; it refuses a missing
directory or one without etc/init.d/S99lvgl before anything is built.

qmp.py assert_ui_chain [ACCOUNT] reads the guest over the control channel
(@procs, @cat) and fails unless exactly one warden-ui and one warden-ui-run
loop run, the UI's real, effective, saved and filesystem uids are all the
account's (never 0), the safe-mode flag is absent and /tmp/warden-ui.log
holds no exit or refusal of warden-ui-run. tests/scripts/init-chain-ui.txt
runs it at about T+120 s.

Tests: UiChainVerb in test_qmp_drive.py (12 cases, among them the #1903
case: no UI, safe mode, three exits); 6 of 6 mutants caught.
rootfs-overlay.sh gains the three ui-drive.sh --init-chain checks.

Refs flare-edge#2210

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
2026-10-28 10:39:31 -06:00
BFE EngineeringandClaude Opus 5.5 a4bbfbd83b qemu: boot the UI through the panel's shipped init chain (flare-edge#2210)
ci / prune-artifacts (push) Skipped
ci / patches-apply (push) Successful in 24s
ci / bench (pull_request) Successful in 16s
ci / test (push) Successful in 24s
ci / mcdc (push) Successful in 29s
ci / kernel-build (push) Skipped
ci / test (pull_request) Successful in 10s
ci / quality (push) Successful in 39s
ci / badges (push) Skipped
ci / mcdc (pull_request) Successful in 30s
ci / bench (push) Successful in 10s
ci / qemu-tools (push) Successful in 3m16s
ci / qemu-tools (pull_request) Successful in 2m34s
ci / kernel-symbols (pull_request) Successful in 1m54s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / patches-apply (pull_request) Successful in 55s
ci / quality (pull_request) Successful in 1m36s
ci / badges (pull_request) Skipped
ci / kernel-symbols (push) Successful in 4m24s
The rig's stage-2 init starts /usr/bin/warden-ui directly as root, so it
never ran S03warden-accounts, S99lvgl or warden-ui-run: no privilege drop,
respawn loop or safe mode was exercised, and the BusyBox setpriv bug of
flare-edge #1903 left every rebuild image without a UI while CI was green.

- mkimage.sh: ROOTFS_OVERLAY lays a directory of panel files over the
  rootfs of both slots, modes kept. Only etc/ and usr/ at its top, no
  symlinks; a refused overlay writes no image.
- sbin/init: with warden.initchain on the command line it runs
  /etc/init.d/S00-S09 before the bus and S10-S99 after the payload daemons,
  in place of the direct UI start (warden_init_chain in warden-lib.sh). The
  splash handover is marked done and warden-ui-run gets "-b fbdev". A chain
  boot without scripts prints WARDEN-QEMU-INITCHAIN-EMPTY and starts no UI.
- warden_rig_bus_owners: when the accounts exist, cred/ui belongs to
  warden-ui and the cred directory to group warden-bus, as S10bus does.
- Tests: init-chain-test.sh (19 checks, also under busybox sh) and
  rootfs-overlay.sh (17 scenarios, images read back with debugfs), both in CI.

Refs flare-edge#2210

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
2026-10-28 10:35:29 -06:00
noah 7d5686e287 Merge pull request 'qemu: PAYLOAD_DIR lets one run boot its own payload set' (#31) from rb/ln-hook-payload into rebuild
ci / qemu-tools (push) Successful in 1m32s
ci / test (push) Successful in 21s
ci / mcdc (push) Successful in 23s
ci / patches-apply (push) Successful in 21s
ci / badges (push) Skipped
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / bench (push) Successful in 17s
ci / quality (push) Successful in 1m25s
ci / kernel-symbols (push) Successful in 4m58s
2026-10-27 19:37:41 -06:00
11 changed files with 708 additions and 3 deletions
+12
View File
@@ -170,6 +170,18 @@ jobs:
if command -v busybox >/dev/null; then
WARDEN_TEST_SH="busybox sh" bash qemu/tests/ctl-bridge-test.sh
fi
- name: rig init boots through the shipped init chain (flare-edge#2210)
# warden_init_chain against stub scripts and the warden.initchain
# wiring in sbin/init; once more under busybox sh, the rig's own shell.
run: |
bash qemu/tests/init-chain-test.sh
if command -v busybox >/dev/null; then
WARDEN_TEST_SH="busybox sh" bash qemu/tests/init-chain-test.sh
fi
- 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.
run: bash qemu/tests/rootfs-overlay.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
+19
View File
@@ -95,6 +95,23 @@ does on a panel instead of rejecting every attempt. `qemu_stage_rootfs()`
the executable bit, so the checked-out source file's own mode depends on the
checking-out umask and cannot be trusted to arrive non-world-readable.
`--append warden.initchain` boots the UI the way a panel does (flare-edge
#2210). The caller lays the panel's own scripts over the rootfs with
`ROOTFS_OVERLAY=<dir> mkimage.sh` (only `etc/` and `usr/` at its top, no
symlinks). Stage-2 init then starts `/etc/init.d/S00`-`S09` with `start`
before the bus (S03warden-accounts creates the platform accounts, and the
bus hands `cred/ui` to `warden-ui`), and `S10`-`S99` after the payload
daemons in place of its direct root start of `warden-ui`. S99lvgl then runs
`warden-ui-run`, which drops the UI to its account and respawns it. Rig
differences: the splash handover is marked done (no S09splash) and
warden-ui-run passes `-b fbdev`, not the panel's `-b drm`. A chain boot
with no script prints `WARDEN-QEMU-INITCHAIN-EMPTY` and starts no UI.
`tests/ui-drive.sh --init-chain <dir>` does both steps, and the drive verb
`assert_ui_chain` judges the result: one `warden-ui` and one `warden-ui-run`,
the UI's four uids all `warden-ui`'s, no safe-mode flag, and no exit or
refusal in `/tmp/warden-ui.log`. `tests/scripts/init-chain-ui.txt` runs the
check at about T+120 s.
A flow seed may contain `qemu-flow-setup.sh`. Stage-2 init runs it inside the
disposable guest after mounting userdata and before starting daemons or the
UI. A nonzero exit stops the boot. Use it only for test devices and commands
@@ -116,6 +133,8 @@ All take the virt-fragment `<zImage>`; `FLARE_EDGE=<checkout>` where noted.
| `ui-drive.sh <script>` | - | the same rig for a SEQUENCE: boots once, runs a `qmp.py drive` script of taps/swipes/screenshots in panel pixels, and FAILS if warden-ui died on the way (stage-2 init announces the exit on the console). `tests/scripts/nav-stress.txt` is the navigation regression: it reproduces the s_row_left overflow that segfaulted the UI on returning to Settings > Apps; `tests/scripts/home-leaves-fullscreen.txt` proves the `home` verb clears dashboard fullscreen, the state a hardware wake tap leaves behind (flare-edge #176); `tests/scripts/fullscreen-toggle-tracks-real-state.txt` proves a `fullscreen toggle` right after `home` (or a real tap) reads the dashboard's actual state rather than a belief `home` bypassed -- `test_qmp_drive.py`'s `FullscreenToggleTracksRealState` pins the same contract offline |
| `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 |
| `rootfs-overlay.sh` | - | offline, no VM: `mkimage.sh`'s `ROOTFS_OVERLAY` hook lays a directory of panel files (flare-edge's S03warden-accounts, S99lvgl, warden-ui-run) over the rootfs of both slots with their modes kept, beside the skeleton's own files; without it there is no `/etc/init.d`; an overlay that is not a directory, names anything but `etc/` and `usr/` at its top, or holds a symlink fails closed and writes no image; `ui-drive.sh --init-chain` refuses a missing directory or one without `etc/init.d/S99lvgl` before boot |
| `init-chain-test.sh` | - | offline, no VM: `warden_init_chain` (rootfs/etc/warden-lib.sh) starts the executable `S<NN>*` scripts of a number range in name order, names a failing one and goes on, and counts them; `warden_rig_bus_owners` hands a bus credential to its account only when the rootfs has it; sbin/init runs S00-S09 before the bus and S10-S99 instead of the direct UI start on a `warden.initchain` boot (flare-edge #2210) |
| `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). A fake `wthctl` stands in for the hook client behind `@hookdoc`/`@hook` (flare-edge #2054): the pieces join into one request whose args are used once, only plain words reach the client, and a missing client or a request with no reply answers a `bridge:` line. CI runs it under bash's `sh` and busybox `sh` |
| `init-rig-bus-test.sh` | - | offline, no VM: `warden_rig_bus` in rootfs/etc/warden-lib.sh against stub brokers. No broker in the payload creates nothing; a broker that listens gets the panel's layout (the `bus.sock` link, a 0400 64-hex credential per bus user, a config without password file, ACL or plugin); a broker that exits or never listens is reported within the bound; init starts the bus before the payload daemons. `WARDEN_TEST_MOSQUITTO_DIR` adds a real mosquitto carrying one message between two users logged in by credential file (flare-edge #1754) |
+25
View File
@@ -23,6 +23,14 @@
# production payload plus the test-flavor UI and wthctl) while
# other runs read qemu/payload at the same time. Not a
# directory: fails closed.
# ROOTFS_OVERLAY a directory laid over the staged rootfs of both slots,
# after the payload, with its modes kept (cp -a). Only etc/ and
# usr/ may appear at its top, and no entry may be a symlink, so
# it can neither replace the rig's own /init and /sbin/init nor
# point outside the image. flare-edge #2210 stages the panel's
# S03warden-accounts, S99lvgl and /usr/lib/warden/warden-ui-run
# this way for a boot with warden.initchain (rootfs/sbin/init).
# Not a directory, or a disallowed entry: fails closed.
# SEED_DIR a directory of pre-built userdata/warden files (one file per
# settings key, e.g. flare-edge tools/seed-fixtures.py's output)
# copied in VERBATIM, after --portal-url/--state. Lets a caller
@@ -86,6 +94,23 @@ for p in "$PAYLOAD_DIR"/*; do
install -m 0755 "$p" "$ROOT/usr/bin/$(basename "$p")"
done
# ROOTFS_OVERLAY (see the Env note above): checked whole before anything of
# it is copied, so a refused overlay leaves no partial tree and no image.
if [ -n "${ROOTFS_OVERLAY:-}" ]; then
[ -d "$ROOTFS_OVERLAY" ] || { echo "FATAL: ROOTFS_OVERLAY '$ROOTFS_OVERLAY' is not a directory" >&2; exit 1; }
for entry in "$ROOTFS_OVERLAY"/* "$ROOTFS_OVERLAY"/.[!.]*; do
[ -e "$entry" ] || [ -L "$entry" ] || continue
case "$(basename "$entry")" in
etc|usr) [ -d "$entry" ] && [ ! -L "$entry" ] && continue ;;
esac
echo "FATAL: ROOTFS_OVERLAY may hold only the directories etc/ and usr/ at its top, not '$(basename "$entry")'" >&2
exit 1
done
links="$(find "$ROOTFS_OVERLAY" -type l)"
[ -z "$links" ] || { echo "FATAL: ROOTFS_OVERLAY holds symlinks: $links" >&2; exit 1; }
cp -a "$ROOTFS_OVERLAY"/. "$ROOT/"
fi
# Firmware version stamp: same path the device build writes; flared reads its
# running version here (downgrade rules key off it).
printf '%s\n' "$FW_VERSION" > "$ROOT/etc/warden-firmware-version"
+61
View File
@@ -281,6 +281,7 @@ WRB_CONF
(umask 077; od -An -tx1 -N32 /dev/urandom | tr -d ' \n' > "$_wrb_dir/cred/$_wrb_u")
chmod 0400 "$_wrb_dir/cred/$_wrb_u"
done
warden_rig_bus_owners "$_wrb_dir"
ln -sfn sock/bus.sock "$_wrb_dir/bus.sock"
ln -sfn sock/mosquitto.pid "$_wrb_dir/mosquitto.pid"
"$_wrb_broker" -c "$_wrb_dir/mosquitto.conf" > "$_wrb_log" 2>&1 &
@@ -305,3 +306,63 @@ WRB_CONF
done
echo "init: rig bus up on $_wrb_dir/bus.sock (broker pid $_wrb_pid)"
}
# warden_rig_bus_owners <bus dir>: give a credential file to the account that
# reads it, when the rootfs has that account. The rig rootfs has none of the
# platform accounts, so by default this changes nothing and every client runs
# as root. A boot through the shipped init chain (warden.initchain, see
# warden_init_chain) creates them first with S03warden-accounts; then the UI
# runs as warden-ui, as on a panel, and needs its own credential: S10bus there
# makes cred/<user> 0400 owned by the daemon's account in a cred directory of
# group warden-bus, mode 0710. Pairs are user=account.
# WARDEN_RIG_BUS_OWNERS, WARDEN_RIG_PASSWD and WARDEN_RIG_GROUP exist for the
# host test only.
warden_rig_bus_owners() {
_wro_passwd="${WARDEN_RIG_PASSWD:-/etc/passwd}"
_wro_group="${WARDEN_RIG_GROUP:-/etc/group}"
if grep -q '^warden-bus:' "$_wro_group" 2>/dev/null; then
chgrp warden-bus "$1/cred" || echo "init: rig bus: chgrp warden-bus $1/cred failed"
fi
for _wro_pair in ${WARDEN_RIG_BUS_OWNERS:-ui=warden-ui}; do
_wro_user="${_wro_pair%%=*}"
_wro_acct="${_wro_pair#*=}"
[ -f "$1/cred/$_wro_user" ] || continue
grep -q "^$_wro_acct:" "$_wro_passwd" 2>/dev/null || continue
if chown "$_wro_acct" "$1/cred/$_wro_user"; then
echo "init: rig bus: cred/$_wro_user belongs to $_wro_acct"
else
echo "init: rig bus: chown $_wro_acct cred/$_wro_user failed"
fi
done
}
# warden_init_chain <first> <last>: start the shipped SysV scripts numbered
# <first> to <last> (S<NN>name, both bounds included), in name order, each
# with `start`, as the panel's rcS does. Used only on a boot with
# warden.initchain on the command line, where the caller laid the panel's own
# scripts into /etc/init.d with mkimage.sh's ROOTFS_OVERLAY (flare-edge #2210:
# S03warden-accounts, S99lvgl and /usr/lib/warden/warden-ui-run, so the UI
# starts through its privilege drop, respawn loop and safe mode instead of
# directly as root). The rig skeleton itself has no /etc/init.d. A script
# that fails is named on the console and the chain goes on, as rcS does.
# Prints how many scripts it started. WARDEN_INITD exists for the host test.
warden_init_chain() {
_wic_dir="${WARDEN_INITD:-/etc/init.d}"
_wic_ran=0
for _wic_s in "$_wic_dir"/S[0-9][0-9]*; do
if [ ! -f "$_wic_s" ] || [ ! -x "$_wic_s" ]; then continue; fi
_wic_name="${_wic_s##*/}"
_wic_n="${_wic_name#S}"
_wic_n="${_wic_n%"${_wic_n#??}"}"
# test(1) reads "08" as decimal eight, so no leading zero is cut.
if [ "$_wic_n" -lt "$1" ] || [ "$_wic_n" -gt "$2" ]; then continue; fi
echo "init: chain $_wic_name start" >&2
if "$_wic_s" start >&2; then
:
else
echo "init: chain $_wic_name start FAILED rc=$?" >&2
fi
_wic_ran=$((_wic_ran + 1))
done
echo "$_wic_ran"
}
+28 -2
View File
@@ -108,6 +108,23 @@ export WARDEN_HARD_RESET=0
# Production init scripts create this volatile socket directory before their
# daemons start. The compact QEMU rootfs must provide the same contract.
mkdir -p /run/warden
# warden.initchain (flare-edge #2210): the UI starts through the panel's own
# scripts, laid into /etc/init.d and /usr/lib/warden by mkimage.sh's
# ROOTFS_OVERLAY, not directly as root below. Scripts S00 to S09 (the
# accounts) run before the bus, which then hands each account its
# credential, and S10 to S99 run where the direct UI start would. The rig
# has no S09splash, so the splash handover is marked done, and its UI is the
# fbdev build, so warden-ui-run passes "-b fbdev" instead of the panel's
# "-b drm". A chain boot without any script fails loudly: a direct start
# there would pass a check that asked for the shipped chain.
initchain=0
if grep -qw warden.initchain /proc/cmdline; then
initchain=1
echo "init: shipped init chain (warden.initchain)"
export WARDEN_UI_ARGS="-b fbdev"
: > /tmp/splash.done
chain_early="$(warden_init_chain 0 9)"
fi
# The device bus, when the payload carries a broker (warden_rig_bus): up
# before the daemons, as S10bus is before every bus client on the panel. A
# failed start is logged and the boot goes on: the clients keep dialing, and
@@ -137,10 +154,19 @@ for d in /usr/bin/warden-modbus /usr/bin/warden-automation /usr/bin/warden-ai \
fi
done
if [ "$initchain" = 1 ]; then
chain_late="$(warden_init_chain 10 99)"
if [ "$((chain_early + chain_late))" -eq 0 ]; then
echo "WARDEN-QEMU-INITCHAIN-EMPTY: warden.initchain but no /etc/init.d/S* script; the UI is not started"
else
echo "init: chain started $((chain_early + chain_late)) script(s)"
fi
fi
# The UI (LVGL fbdev+evdev build from flare-edge tools/build-ui-vm.sh) needs
# virtio-gpu's fbdev: present only with run.sh --display on|headless AND the
# virt.fragment kernel.
if [ -x /usr/bin/warden-ui ] && [ -c /dev/fb0 ]; then
# virt.fragment kernel. A chain boot started it above, through S99lvgl.
if [ "$initchain" = 0 ] && [ -x /usr/bin/warden-ui ] && [ -c /dev/fb0 ]; then
echo "init: starting warden-ui (fbdev)"
# Announce the exit on the CONSOLE, not just in the log. A UI that dies
# mid-scenario otherwise looks exactly like a UI that stopped repainting:
+124
View File
@@ -0,0 +1,124 @@
#!/usr/bin/env bash
# Host test for the rig's shipped-init-chain boot (flare-edge #2210):
# warden_init_chain and warden_rig_bus_owners in qemu/rootfs/etc/warden-lib.sh,
# and the warden.initchain wiring in qemu/rootfs/sbin/init. Offline, no VM.
#
# warden_init_chain <first> <last> starts the executable S<NN>* scripts of
# that number range in name order with `start`, names a failing one and
# goes on, reads "08" and "09" as decimal (test, not shell arithmetic), and prints how many it started.
# warden_rig_bus_owners hands a credential file to its account only when
# the passwd database has that account.
# sbin/init runs S00-S09 before the bus and S10-S99 before the direct UI
# start, which a chain boot skips, and says so when the chain is empty.
#
# bash init-chain-test.sh (WARDEN_TEST_SH="busybox sh" for the rig shell)
set -uo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
LIB="$HERE/../rootfs/etc/warden-lib.sh"
INIT="$HERE/../rootfs/sbin/init"
SH="${WARDEN_TEST_SH:-sh}"
WORK="$(mktemp -d "${TMPDIR:-/tmp}/warden-init-chain.XXXXXX")" || exit 1
trap 'rm -rf "$WORK"' 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
}
# Stub scripts: each appends "<name> <arg>" to the log; S20bad fails.
D="$WORK/init.d"
mkdir -p "$D"
# shellcheck disable=SC2016 # $1 belongs to the stub script
stub() { # stub <name> [rc]
printf '#!/bin/sh\necho "%s $1" >> "%s"\nexit %s\n' "$1" "$WORK/log" "${2:-0}" > "$D/$1"
chmod 0755 "$D/$1"
}
stub S03warden-accounts
stub S08eight
stub S09splash
stub S10bus
stub S20bad 3
stub S99lvgl
stub S01runtime
# shellcheck disable=SC2016 # $1 belongs to the stub script
printf '#!/bin/sh\necho "S50off $1" >> "%s"\n' "$WORK/log" > "$D/S50off" # not executable
printf 'x\n' > "$D/README"
mkdir -p "$D/S60dir"
chain() { # chain <first> <last>: stdout to $WORK/out, stderr to $WORK/err
: > "$WORK/log"
# shellcheck disable=SC2086,SC2016
WARDEN_INITD="$D" $SH -c '. "$1"; warden_init_chain "$2" "$3"' sh "$LIB" "$1" "$2" \
> "$WORK/out" 2> "$WORK/err"
}
chain 0 9
check "early range starts S01, S03, S08, S09 in name order" \
test "$(cat "$WORK/log")" = "S01runtime start
S03warden-accounts start
S08eight start
S09splash start"
check "early range prints its count (4)" test "$(cat "$WORK/out")" = 4
check "early range names each start on the console" grep -q '^init: chain S08eight start$' "$WORK/err"
chain 10 99
check "late range starts S10, S20, S99 and skips the non-executable S50 and the directory S60" \
test "$(cat "$WORK/log")" = "S10bus start
S20bad start
S99lvgl start"
check "late range counts the failed script as started (3)" test "$(cat "$WORK/out")" = 3
check "a failing script is named with its status" grep -q '^init: chain S20bad start FAILED rc=3$' "$WORK/err"
chain 9 9
check "a one-number range starts only that number" test "$(cat "$WORK/log")" = "S09splash start"
rm -rf "$D"; mkdir -p "$D"
chain 0 99
check "no scripts: nothing runs and the count is 0" test "$(cat "$WORK/out")" = 0
# shellcheck disable=SC2086,SC2016
WARDEN_INITD="$WORK/none" $SH -c '. "$1"; warden_init_chain 0 99' sh "$LIB" > "$WORK/out" 2>&1
check "a missing init.d directory counts 0" test "$(cat "$WORK/out")" = 0
# warden_rig_bus_owners: the test's own account stands in for warden-ui
# (chown to oneself needs no root).
me="$(id -un)"
B="$WORK/bus"
mkdir -p "$B/cred"
: > "$B/cred/ui"; : > "$B/cred/flared"
printf '%s:x:%s:%s::/:/bin/sh\n' "$me" "$(id -u)" "$(id -g)" > "$WORK/passwd"
printf 'root:x:0:\n' > "$WORK/group"
owners() { # owners <pairs>
# shellcheck disable=SC2086,SC2016
WARDEN_RIG_BUS_OWNERS="$1" WARDEN_RIG_PASSWD="$WORK/passwd" WARDEN_RIG_GROUP="$WORK/group" \
$SH -c '. "$1"; warden_rig_bus_owners "$2"' sh "$LIB" "$B" > "$WORK/out" 2>&1
}
owners "ui=$me"
check "a credential whose account exists is handed to it" grep -qx "init: rig bus: cred/ui belongs to $me" "$WORK/out"
owners "ui=warden-ui-absent flared=$me-absent"
check "accounts the rootfs lacks change nothing (the rig default)" test ! -s "$WORK/out"
owners "nosuch=$me"
check "a user without a credential file is skipped" test ! -s "$WORK/out"
owners ""
check "the default pair is ui=warden-ui" test ! -s "$WORK/out"
# sbin/init wiring, read from the script itself.
line_of() { grep -n -m1 -e "$1" "$INIT" | cut -d: -f1; }
early="$(line_of 'warden_init_chain 0 9')"
bus="$(line_of '^warden_rig_bus ')"
late="$(line_of 'warden_init_chain 10 99')"
daemons="$(line_of '^for d in /usr/bin/warden-')"
ui="$(line_of 'if .*-x /usr/bin/warden-ui')"
check "init runs S00-S09 before the rig bus" test -n "$early" -a -n "$bus" -a "${early:-0}" -lt "${bus:-0}"
check "init runs S10-S99 after the payload daemons and before the direct UI start" \
test -n "$late" -a -n "$daemons" -a -n "$ui" -a "${daemons:-0}" -lt "${late:-0}" -a "${late:-0}" -lt "${ui:-0}"
# shellcheck disable=SC2016 # a literal pattern
check "the direct UI start is skipped on a chain boot" grep -q '^if \[ "$initchain" = 0 \] && \[ -x /usr/bin/warden-ui \]' "$INIT"
check "the chain is armed only by warden.initchain on the command line" grep -q 'grep -qw warden.initchain /proc/cmdline' "$INIT"
check "a chain boot passes the fbdev backend to warden-ui-run" grep -q 'export WARDEN_UI_ARGS="-b fbdev"' "$INIT"
check "an empty chain is reported, not replaced by the direct start" grep -q 'WARDEN-QEMU-INITCHAIN-EMPTY' "$INIT"
echo "init-chain: $CHECKS checks"
if [ "$FAIL" -ne 0 ]; then echo "init-chain: FAILED"; exit 1; fi
echo "init-chain: all checks passed"
+92
View File
@@ -54,6 +54,16 @@ a real panel, so these verbs mean the same thing on the rig and on hardware:
the hook (no bus, no wthctl, no reply). Needs a
broker, wthctl and a test-flavor warden-ui in the
payload
assert_ui_chain [ACCOUNT]
the UI runs the way a panel starts it (a boot
through ui-drive.sh --init-chain, flare-edge
#2210): exactly one warden-ui and one
warden-ui-run loop, the UI's real, effective,
saved and filesystem uids all ACCOUNT's
(default warden-ui, never 0), no safe-mode flag
(/run/warden/ui-safe-mode) and no exit or
refusal in /tmp/warden-ui.log. Read with
`@procs` and `@cat` over the control channel
assert_page MENU/TAB the active page is exactly this
assert_hit X Y CLASS [box=X1,Y1,WxH] [TEXT...]
a real tap at X,Y lands on an object of CLASS,
@@ -1223,6 +1233,87 @@ def verb_override(ctx, lineno, cmd, args, line):
return judge_hook_reply(hook_request(ctx.ctl, "override", {"topic": topic, "doc": doc}))
UI_CHAIN_SAFE_FLAG = "/run/warden/ui-safe-mode"
UI_CHAIN_LOG = "/tmp/warden-ui.log"
UI_CHAIN_NO_FILE = "bridge: no such file: "
# warden-ui-run's own lines in the log S99lvgl points it at: a restart
# ("warden-ui exited N") or the end of the loop ("refusing to run the UI").
UI_CHAIN_LOG_BAD = re.compile(r"warden-ui-run: .*(exited|refusing|already running)|exited \d+")
def account_uid(passwd_text, account):
"""The account's uid from passwd text, or None."""
for line in passwd_text.splitlines():
f = line.split(":")
if len(f) >= 3 and f[0] == account and f[2].isdigit():
return int(f[2])
return None
def status_uids(status_text):
"""The four uids of a /proc/<pid>/status Uid line, or None."""
for line in status_text.splitlines():
parts = line.split()
if parts and parts[0] == "Uid:" and len(parts) >= 5:
try:
return [int(x) for x in parts[1:5]]
except ValueError:
return None
return None
def judge_ui_chain(procs_text, passwd_text, status_of, safe_reply, log_text, account):
"""Problems with a UI started through the shipped init chain; empty
when it runs as a panel runs it. status_of(pid) -> that pid's
/proc/<pid>/status text."""
problems = []
want = account_uid(passwd_text, account)
if want is None:
problems.append(f"no account {account} in /etc/passwd (S03warden-accounts did not run)")
elif want == 0:
problems.append(f"account {account} has uid 0")
procs = parse_procs(procs_text)
live = {pid: comm for pid, (comm, state, _t) in procs.items() if state != "Z"}
uis = sorted(pid for pid, comm in live.items() if comm == "warden-ui")
loops = sorted(pid for pid, comm in live.items() if comm == "warden-ui-run")
if len(uis) != 1:
problems.append(f"{len(uis)} warden-ui processes, want 1 (pids {uis})")
if len(loops) != 1:
problems.append(f"{len(loops)} warden-ui-run loops, want 1 (pids {loops})")
for pid in uis:
seen = status_uids(status_of(pid))
if seen is None:
problems.append(f"warden-ui pid {pid}: no Uid line")
elif want not in (None, 0) and seen != [want] * 4:
problems.append(f"warden-ui pid {pid} runs with uids {seen}, not {account} ({want})")
if not safe_reply.startswith(UI_CHAIN_NO_FILE):
problems.append(f"safe mode is on ({UI_CHAIN_SAFE_FLAG} exists)")
if log_text.startswith(UI_CHAIN_NO_FILE):
problems.append(f"no {UI_CHAIN_LOG}: S99lvgl never started the UI")
else:
bad = [line for line in log_text.splitlines() if UI_CHAIN_LOG_BAD.search(line)]
if bad:
problems.append(f"{UI_CHAIN_LOG}: {bad[0]!r}" + (f" (+{len(bad) - 1} more)" if len(bad) > 1 else ""))
return problems
def verb_assert_ui_chain(ctx, lineno, cmd, args, line):
# assert_ui_chain [ACCOUNT] (flare-edge #2210): the UI came up through
# S03warden-accounts, S99lvgl and warden-ui-run, and stays up as its
# account. A missing process is a `fail`: that is exactly the bug class
# (#1903's setpriv left no UI), not a rig fault.
ctx.need_ctl(lineno, cmd)
account = args[0] if args else "warden-ui"
problems = judge_ui_chain(
ctx.ctl.send("@procs"),
ctx.ctl.send("@cat /etc/passwd"),
lambda pid: ctx.ctl.send(f"@cat /proc/{pid}/status"),
ctx.ctl.send(f"@cat {UI_CHAIN_SAFE_FLAG}"),
ctx.ctl.send(f"@cat {UI_CHAIN_LOG}"),
account)
return ("fail", "; ".join(problems)) if problems else ("ok", "")
def verb_assert_page(ctx, lineno, cmd, args, line):
ctx.need_ctl(lineno, cmd)
want = " ".join(args)
@@ -1442,6 +1533,7 @@ VERBS = {
"ctl": verb_query,
"rs485": verb_rs485,
"assert_page": verb_assert_page,
"assert_ui_chain": verb_assert_ui_chain,
"assert_hit": verb_assert_hit,
"wait_hit": verb_wait_hit,
"assert_json": verb_assert_json,
+179
View File
@@ -0,0 +1,179 @@
#!/usr/bin/env bash
# Regression test for mkimage.sh's ROOTFS_OVERLAY hook (see its Env note): a
# run lays the panel's own init scripts over the rig rootfs of both slots, so
# a warden.initchain boot starts the UI through S99lvgl and warden-ui-run
# (flare-edge #2210). Only etc/ and usr/ may appear at the overlay's top and
# no entry may be a symlink; a refused overlay writes no image.
#
# Works on a copy of qemu/ (no payload, no out/) so the default payload
# directory is the copy's own and nothing in the checkout is touched. Builds
# real disk images the same way mkimage.sh always does (unprivileged
# mkfs.ext4 -d), then reads rootfs_a and rootfs_b back with debugfs -R
# (read-only, no mount or loop device) to check what actually landed.
#
# bash rootfs-overlay.sh
set -uo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # qemu/tests/
SRC_QEMU="$(cd "$HERE/.." && pwd)" # qemu/
FAIL=0
pass() { printf '[PASS] %s\n' "$1"; }
fail() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
# mkfs.ext4 and debugfs live in sbin, which user shells on Debian do not put
# on PATH; mkimage.sh applies the same fix.
PATH="$PATH:/usr/sbin:/sbin"
command -v debugfs >/dev/null || {
echo "FATAL: debugfs (e2fsprogs) not found: needed to read the rootfs partitions back" >&2
exit 1
}
SCRATCH="$(mktemp -d "${TMPDIR:-/tmp}/warden-qemu-rootfs-overlay.XXXXXX")"
trap 'rm -rf "$SCRATCH"' EXIT
# The copy: everything mkimage.sh reads, without the build outputs or any
# payload a developer dropped into the checkout.
QEMU_DIR="$SCRATCH/qemu"
mkdir -p "$QEMU_DIR/payload"
for entry in "$SRC_QEMU"/*; do
case "$(basename "$entry")" in out|payload) continue ;; esac
cp -a "$entry" "$QEMU_DIR/"
done
# shellcheck source=../lib.sh disable=SC1091
. "$QEMU_DIR/lib.sh"
# shellcheck source=../blkdevparts.conf disable=SC1091
. "$QEMU_DIR/blkdevparts.conf"
declare -A PART_OFF PART_SIZE
capture_part() { PART_OFF[$1]="$2"; PART_SIZE[$1]="$3"; return 0; }
qemu_each_partition capture_part
for name in rootfs_a rootfs_b; do
[ -n "${PART_OFF[$name]:-}" ] || { echo "FATAL: no '$name' entry in blkdevparts.conf" >&2; exit 1; }
done
# extract_part DISK NAME OUTFILE: one partition window, sparse.
extract_part() {
dd if="$1" of="$3" bs=4096 skip=$((PART_OFF[$2] / 4096)) \
count=$((PART_SIZE[$2] / 4096)) conv=sparse status=none
}
# Reuse an already-verified busybox wherever a prior build produced one; a
# checkout that never ran mkimage.sh fetches and verifies it once here.
BUSYBOX_BIN="$SRC_QEMU/out/busybox-armv7l"
if [ ! -f "$BUSYBOX_BIN" ]; then
OUT="$SCRATCH/bb" qemu_get_busybox
BUSYBOX_BIN="$BB"
fi
OV="$SCRATCH/overlay"
mkdir -p "$OV/etc/init.d" "$OV/usr/lib/warden"
printf '#!/bin/sh\necho lvgl\n' > "$OV/etc/init.d/S99lvgl"
chmod 0755 "$OV/etc/init.d/S99lvgl"
printf '#!/bin/sh\necho run\n' > "$OV/usr/lib/warden/warden-ui-run"
chmod 0750 "$OV/usr/lib/warden/warden-ui-run"
printf 'ui=1\n' > "$OV/etc/flare.conf"
chmod 0640 "$OV/etc/flare.conf"
mode_of() { # mode_of IMG PATH
debugfs -R "stat $2" "$1" 2>/dev/null | grep -oE 'Mode: *[0-7]+' | grep -oE '[0-7]+$'
}
# --- scenario 1: the overlay lands in both slots with its modes ---
OUT1="$SCRATCH/out1"
if OUT="$OUT1" BUSYBOX="$BUSYBOX_BIN" ROOTFS_OVERLAY="$OV" \
bash "$QEMU_DIR/mkimage.sh" > "$SCRATCH/mkimage1.log" 2>&1; then
for slot in rootfs_a rootfs_b; do
IMG="$SCRATCH/$slot.1.img"
extract_part "$OUT1/disk.img" "$slot" "$IMG"
got="$(debugfs -R "cat /etc/init.d/S99lvgl" "$IMG" 2>/dev/null | tail -n 1)"
if [ "$got" = "echo lvgl" ]; then pass "overlay: $slot carries etc/init.d/S99lvgl"
else fail "overlay: $slot S99lvgl = '$got'"; fi
m="$(mode_of "$IMG" /usr/lib/warden/warden-ui-run)"
if [ "$m" = "0750" ]; then pass "overlay: $slot keeps warden-ui-run's mode 0750"
else fail "overlay: $slot warden-ui-run mode '$m', want 0750"; fi
m="$(mode_of "$IMG" /etc/flare.conf)"
if [ "$m" = "0640" ]; then pass "overlay: $slot keeps a data file's mode 0640"
else fail "overlay: $slot flare.conf mode '$m', want 0640"; fi
if debugfs -R "stat /sbin/init" "$IMG" 2>&1 | grep -q 'File not found'; then
fail "overlay: $slot lost the rig's own /sbin/init"
else
pass "overlay: $slot still has the rig's /sbin/init"
fi
if debugfs -R "stat /etc/passwd" "$IMG" 2>&1 | grep -q 'File not found'; then
fail "overlay: $slot lost the skeleton's /etc/passwd"
else
pass "overlay: $slot keeps the skeleton's /etc/passwd beside the overlay's etc/"
fi
done
else
fail "overlay: mkimage.sh exited nonzero with a valid overlay (see $SCRATCH/mkimage1.log)"
fi
# --- scenario 2: no overlay leaves /etc/init.d out ---
OUT2="$SCRATCH/out2"
if OUT="$OUT2" BUSYBOX="$BUSYBOX_BIN" bash "$QEMU_DIR/mkimage.sh" > "$SCRATCH/mkimage2.log" 2>&1; then
IMG="$SCRATCH/rootfs_a.2.img"
extract_part "$OUT2/disk.img" rootfs_a "$IMG"
if debugfs -R "stat /etc/init.d" "$IMG" 2>&1 | grep -q 'File not found'; then
pass "no overlay: rootfs_a has no /etc/init.d (the rig's direct start)"
else
fail "no overlay: rootfs_a has an /etc/init.d"
fi
else
fail "no overlay: mkimage.sh exited nonzero (see $SCRATCH/mkimage2.log)"
fi
# --- scenario 3: refused overlays fail closed and write no image ---
refused() { # refused <label> <dir> <stderr text>
local out="$SCRATCH/out-$1" err rc
err="$(OUT="$out" BUSYBOX="$BUSYBOX_BIN" ROOTFS_OVERLAY="$2" bash "$QEMU_DIR/mkimage.sh" 2>&1 1>/dev/null)"
rc=$?
if [ "$rc" -ne 0 ] && printf '%s' "$err" | grep -qF "$3" && [ ! -e "$out/disk.img" ]; then
pass "overlay refused ($1): nonzero, '$3', no image"
else
fail "overlay $1: rc=$rc stderr='$err' image=$([ -e "$out/disk.img" ] && echo yes || echo no)"
fi
}
: > "$SCRATCH/notadir"
refused notadir "$SCRATCH/notadir" "is not a directory"
mkdir -p "$SCRATCH/sbin-ov/sbin"; printf 'x\n' > "$SCRATCH/sbin-ov/sbin/init"
refused sbin "$SCRATCH/sbin-ov" "not 'sbin'"
mkdir -p "$SCRATCH/init-ov"; printf 'x\n' > "$SCRATCH/init-ov/init"
refused init "$SCRATCH/init-ov" "not 'init'"
mkdir -p "$SCRATCH/link-ov/etc"; ln -s /etc/shadow "$SCRATCH/link-ov/etc/shadow"
refused link "$SCRATCH/link-ov" "holds symlinks"
mkdir -p "$SCRATCH/toplink-ov"; ln -s "$OV/etc" "$SCRATCH/toplink-ov/etc"
refused toplink "$SCRATCH/toplink-ov" "not 'etc'"
mkdir -p "$SCRATCH/dot-ov/etc"; printf 'x\n' > "$SCRATCH/dot-ov/.hidden"
refused dot "$SCRATCH/dot-ov" "not '.hidden'"
# --- scenario 4: ui-drive.sh --init-chain checks its directory before boot ---
# Its PATH holds only dirname, so a directory that passes stops at the
# qemu-system-arm check and no VM boots.
mkdir -p "$SCRATCH/nobin" "$SCRATCH/pl"
ln -s "$(command -v dirname)" "$SCRATCH/nobin/dirname"
BASH_BIN="$(command -v bash)"
printf 'sleep 1\n' > "$SCRATCH/drive.txt"
: > "$SCRATCH/zImage"
printf '#!/bin/sh\n' > "$SCRATCH/pl/warden-ui"; chmod +x "$SCRATCH/pl/warden-ui"
drive_err() { # drive_err <init-chain dir>
PAYLOAD_DIR="$SCRATCH/pl" PATH="$SCRATCH/nobin" "$BASH_BIN" "$QEMU_DIR/tests/ui-drive.sh" \
--init-chain "$1" "$SCRATCH/zImage" "$SCRATCH/drive.txt" "$SCRATCH/drive-out" 2>&1
}
err="$(drive_err "$SCRATCH/no-such-dir")"
if printf '%s' "$err" | grep -qF "is not a directory"; then pass "ui-drive.sh: --init-chain with no directory is refused"
else fail "ui-drive.sh: --init-chain missing dir gave '$err'"; fi
mkdir -p "$SCRATCH/no-lvgl/etc/init.d"
err="$(drive_err "$SCRATCH/no-lvgl")"
if printf '%s' "$err" | grep -qF "has no etc/init.d/S99lvgl"; then pass "ui-drive.sh: --init-chain without S99lvgl is refused"
else fail "ui-drive.sh: --init-chain without S99lvgl gave '$err'"; fi
err="$(drive_err "$OV")"
if printf '%s' "$err" | grep -qF "qemu-system-arm not on PATH"; then pass "ui-drive.sh: a chain directory with S99lvgl passes its checks"
else fail "ui-drive.sh: --init-chain with S99lvgl gave '$err'"; fi
if [ "$FAIL" -ne 0 ]; then
echo "rootfs-overlay: FAILED"
exit 1
fi
echo "rootfs-overlay: all scenarios passed"
+11
View File
@@ -0,0 +1,11 @@
# The UI as a panel starts it (flare-edge #2210), run with
# ui-drive.sh --init-chain <dir with the panel's S03warden-accounts,
# S99lvgl, /usr/lib/warden/warden-ui-run and uid-check.sh> <zImage> this
# ui-drive.sh hands this script over once the UI has drawn a frame and the
# control bridge is up, about 20 to 40 s after boot under TCG. The sleep
# brings the check to roughly T+120 s, past three restarts and the 5 s
# hold-down, so a UI that only lives a few seconds per start is not seen as
# up, and a loop that gave up has had time to set safe mode.
echo init chain: waiting to about T+120 s
sleep 90
assert_ui_chain warden-ui
+139
View File
@@ -967,6 +967,145 @@ class OverrideVerb(unittest.TestCase):
self.assertEqual(HookCtl.sent, [])
def stat_line(pid, comm, state="S"):
"""A /proc/<pid>/stat line with enough fields for parse_procs."""
return f"{pid} ({comm}) {state} 1 1 1 0 -1 4194560 0 0 0 0 7 3 0 0 20 0 1 0 100"
class ChainCtl(FakeCtl):
"""A guest booted through the shipped init chain: what `@procs` and
`@cat` answer there. Class attributes are the scenario."""
procs = [stat_line(1, "init"), stat_line(310, "warden-ui-run"), stat_line(311, "warden-ui")]
passwd = "root:x:0:0:root:/root:/bin/sh\nwarden-ui:x:970:970::/var/empty:/bin/false\n"
uids = {311: "970\t970\t970\t970"}
files = {"/tmp/warden-ui.log": "Starting\nLVGL up\n"}
sent = []
def send(self, cmd):
ChainCtl.sent.append(cmd)
if cmd == "@procs":
return "\n".join(ChainCtl.procs)
if cmd == "@cat /etc/passwd":
return ChainCtl.passwd
m = re.match(r"@cat /proc/(\d+)/status$", cmd)
if m:
pid = int(m.group(1))
if pid not in ChainCtl.uids:
return f"bridge: no such file: /proc/{pid}/status"
return f"Name:\twarden-ui\nState:\tS (sleeping)\nUid:\t{ChainCtl.uids[pid]}\nGid:\t970\t970\t970\t970\n"
if cmd.startswith("@cat "):
path = cmd[len("@cat "):]
if path in ChainCtl.files:
return ChainCtl.files[path]
return f"bridge: no such file: {path}"
return super().send(cmd)
class UiChainVerb(unittest.TestCase):
"""assert_ui_chain (flare-edge #2210): the UI started through
S03warden-accounts, S99lvgl and warden-ui-run, and runs as its account."""
def setUp(self):
ChainCtl.procs = [stat_line(1, "init"), stat_line(310, "warden-ui-run"), stat_line(311, "warden-ui")]
ChainCtl.passwd = "root:x:0:0:root:/root:/bin/sh\nwarden-ui:x:970:970::/var/empty:/bin/false\n"
ChainCtl.uids = {311: "970\t970\t970\t970"}
ChainCtl.files = {"/tmp/warden-ui.log": "Starting\nLVGL up\n"}
ChainCtl.sent = []
def verdict(self, line="assert_ui_chain"):
rc, by, rows = run_script(line + "\n", ctl_cls=ChainCtl)
return rc, rows[0]
def test_a_ui_running_as_its_account_passes(self):
rc, row = self.verdict()
self.assertIsNone(rc, row)
self.assertEqual(row["status"], "ok", row)
self.assertIn("@cat /proc/311/status", ChainCtl.sent)
self.assertIn("@cat /run/warden/ui-safe-mode", ChainCtl.sent)
def test_the_1903_class_no_ui_after_the_loop_gave_up_fails(self):
# BusyBox setpriv without --reuid: every start exits 1, the loop
# sets safe mode, and the log has the exits.
ChainCtl.procs = [stat_line(1, "init"), stat_line(310, "warden-ui-run")]
ChainCtl.uids = {}
ChainCtl.files = {
"/tmp/warden-ui.log": "setpriv: unrecognized option '--reuid=warden-ui'\n"
"warden-ui-run: warden-ui exited 1\n" * 3,
"/run/warden/ui-safe-mode": "",
}
rc, row = self.verdict()
self.assertEqual(rc, 1)
self.assertEqual(row["status"], "fail")
self.assertIn("0 warden-ui processes, want 1", row["detail"])
self.assertIn("safe mode is on", row["detail"])
self.assertIn("warden-ui exited 1", row["detail"])
self.assertIn("(+2 more)", row["detail"])
def test_a_ui_left_running_as_root_fails(self):
ChainCtl.uids = {311: "0\t0\t0\t0"}
rc, row = self.verdict()
self.assertEqual(row["status"], "fail")
self.assertIn("runs with uids [0, 0, 0, 0], not warden-ui (970)", row["detail"])
def test_one_uid_of_four_left_behind_fails(self):
ChainCtl.uids = {311: "970\t970\t0\t970"}
rc, row = self.verdict()
self.assertIn("uids [970, 970, 0, 970]", row["detail"])
def test_no_account_fails(self):
ChainCtl.passwd = "root:x:0:0:root:/root:/bin/sh\n"
rc, row = self.verdict()
self.assertIn("no account warden-ui in /etc/passwd", row["detail"])
def test_an_account_with_uid_0_fails(self):
ChainCtl.passwd = "warden-ui:x:0:0::/:/bin/false\n"
rc, row = self.verdict()
self.assertIn("account warden-ui has uid 0", row["detail"])
def test_the_direct_start_without_a_loop_fails(self):
# The rig's own direct start: no warden-ui-run, no log.
ChainCtl.procs = [stat_line(1, "init"), stat_line(311, "warden-ui")]
ChainCtl.files = {}
rc, row = self.verdict()
self.assertIn("0 warden-ui-run loops, want 1", row["detail"])
self.assertIn("no /tmp/warden-ui.log", row["detail"])
def test_two_uis_or_two_loops_fail_and_zombies_do_not_count(self):
ChainCtl.procs = [stat_line(310, "warden-ui-run"), stat_line(320, "warden-ui-run"),
stat_line(311, "warden-ui"), stat_line(312, "warden-ui"),
stat_line(313, "warden-ui", "Z")]
ChainCtl.uids = {311: "970\t970\t970\t970", 312: "970\t970\t970\t970"}
rc, row = self.verdict()
self.assertIn("2 warden-ui processes, want 1 (pids [311, 312])", row["detail"])
self.assertIn("2 warden-ui-run loops", row["detail"])
def test_a_restart_in_the_log_fails_even_with_the_ui_back_up(self):
ChainCtl.files = {"/tmp/warden-ui.log": "warden-ui-run: warden-ui exited 139\n"}
rc, row = self.verdict()
self.assertEqual(row["status"], "fail")
self.assertIn("exited 139", row["detail"])
def test_a_refused_start_in_the_log_fails(self):
ChainCtl.files = {"/tmp/warden-ui.log":
"warden-ui-run: no setpriv with --reuid and no su; refusing to run the UI as root\n"}
rc, row = self.verdict()
self.assertIn("refusing", row["detail"])
def test_another_account_can_be_named(self):
ChainCtl.passwd = "kiosk:x:980:980::/:/bin/false\n"
ChainCtl.uids = {311: "980\t980\t980\t980"}
rc, row = self.verdict("assert_ui_chain kiosk")
self.assertEqual(row["status"], "ok", row)
def test_pure_helpers(self):
self.assertEqual(qmp.account_uid("a:x:5:5::/:/bin/sh\nb:x:x:1::/:/\n", "a"), 5)
self.assertIsNone(qmp.account_uid("a:x:5:5::/:/bin/sh\n", "b"))
self.assertIsNone(qmp.account_uid("b:x:nope:1::/:/\n", "b"))
self.assertEqual(qmp.status_uids("Uid:\t1\t2\t3\t4\n"), [1, 2, 3, 4])
self.assertIsNone(qmp.status_uids("Gid:\t1\t2\t3\t4\n"))
class ConsoleWatchTests(unittest.TestCase):
"""ConsoleWatch replaced a ui_exited() that reread and rescanned the
WHOLE console log on every one of drive()'s per-step checks -- O(steps *
+18 -1
View File
@@ -40,20 +40,29 @@ QDIR="$(cd "$HERE/.." && pwd)" # qemu/
SEED_FILE=""
REFS_FILE=""
RS485_DEVICES=""
INIT_CHAIN=""
ARGS=()
while [ $# -gt 0 ]; do
case "$1" in
--seed) SEED_FILE="${2:?--seed needs a manifest path}"; shift 2 ;;
--refs) REFS_FILE="${2:?--refs needs a path}"; shift 2 ;;
--rs485-devices) RS485_DEVICES="${2:?--rs485-devices needs ADDR:SLUG[,...]}"; shift 2 ;;
--init-chain) INIT_CHAIN="${2:?--init-chain needs a directory}"; shift 2 ;;
--) shift; ARGS+=("$@"); break ;;
-*) echo "FATAL: unknown option '$1' (usage: $0 [--seed FILE] [--refs FILE] [--rs485-devices LIST] <zImage> <script> [out-dir])" >&2; exit 1 ;;
-*) echo "FATAL: unknown option '$1' (usage: $0 [--seed FILE] [--refs FILE] [--rs485-devices LIST] [--init-chain DIR] <zImage> <script> [out-dir])" >&2; exit 1 ;;
*) ARGS+=("$1"); shift ;;
esac
done
ZIMAGE="${ARGS[0]:-}"
SCRIPT="${ARGS[1]:-}"
OUTDIR="${ARGS[2]:-$QDIR/out/ui-drive}"
if [ -n "$INIT_CHAIN" ]; then
[ -d "$INIT_CHAIN" ] || { echo "FATAL: --init-chain '$INIT_CHAIN' is not a directory" >&2; exit 1; }
[ -f "$INIT_CHAIN/etc/init.d/S99lvgl" ] || {
echo "FATAL: --init-chain '$INIT_CHAIN' has no etc/init.d/S99lvgl: the UI would never start" >&2; exit 1; }
ROOTFS_OVERLAY="$(cd "$INIT_CHAIN" && pwd)"
export ROOTFS_OVERLAY
fi
if [ -z "$ZIMAGE" ] || [ ! -f "$ZIMAGE" ]; then
echo "FATAL: usage: $0 [--seed FILE] [--refs FILE] [--rs485-devices LIST] <zImage> <script> [out-dir]: the virt.fragment kernel variant" >&2
@@ -71,6 +80,13 @@ if [ -n "$SEED_FILE" ] && { [ -z "${FLARE_EDGE:-}" ] || [ ! -f "$FLARE_EDGE/tool
echo "FATAL: --seed needs FLARE_EDGE to point at a flare-edge checkout (seed-fixtures.py not found under '${FLARE_EDGE:-}')" >&2
exit 1
fi
# --init-chain DIR
# boot the UI through the panel's shipped init scripts
# (flare-edge #2210): DIR is laid over the rootfs with
# mkimage.sh's ROOTFS_OVERLAY and the VM boots with
# warden.initchain, so stage-2 init starts /etc/init.d/S*
# instead of warden-ui directly. qmp.py's assert_ui_chain
# verb judges the result.
# PAYLOAD_DIR (mkimage.sh's Env note) picks another payload set for this run.
[ -x "${PAYLOAD_DIR:-$QDIR/payload}/warden-ui" ] || {
echo "FATAL: no warden-ui in ${PAYLOAD_DIR:-qemu/payload}: build it with flare-edge tools/build-ui-vm.sh" >&2
@@ -172,6 +188,7 @@ for _attempt in 1 2 3; do
: > "$WORK/console.log"
bash "$QDIR/run.sh" --kernel "$ZIMAGE" --display headless --qmp "$WORK/qmp.sock" \
--ctl "$WORK/ctl.sock" ${RS485_DEVICES:+--rs485 "$WORK/rs.sock"} \
${INIT_CHAIN:+--append warden.initchain} \
--ssh-port "$PORT" --http-port $((PORT + 1)) --api-port $((PORT + 2)) \
> "$WORK/console.log" 2>&1 &
QEMU_PID=$!