Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9f2b9b26a | ||
|
|
6e51f1a0e5 | ||
|
|
333c237949 | ||
|
|
f46a3519aa | ||
|
|
f04a31dc06 |
@@ -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.
|
||||
|
||||
+6
-1
@@ -106,6 +106,11 @@ daemons in place of its direct root start of `warden-ui`. S99lvgl then runs
|
||||
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
|
||||
@@ -128,7 +133,7 @@ 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 |
|
||||
| `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` |
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -148,6 +148,30 @@ 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
|
||||
|
||||
@@ -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
|
||||
@@ -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 *
|
||||
|
||||
+23
-12
@@ -36,24 +36,35 @@
|
||||
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=""
|
||||
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 +82,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 +190,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=$!
|
||||
@@ -235,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
@@ -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" "$@"; }
|
||||
|
||||
|
||||
Executable
+152
@@ -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"
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user