Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5494b87dc3 | ||
|
|
13cd0c63be | ||
|
|
d279bc4c9f | ||
|
|
44b96074ed | ||
|
|
b7be6f7fbe | ||
|
|
7d18896a0d |
@@ -112,7 +112,7 @@ jobs:
|
||||
qemu/rootfs/etc/warden-lib.sh qemu/rootfs/etc/rc \
|
||||
qemu/rootfs/sbin/init qemu/rootfs/init tests/mk-bootimg/*.sh \
|
||||
tests/fetch-vendor/*.sh tests/fetch-buildroot-tarball/*.sh \
|
||||
tests/unpack-buildroot/*.sh
|
||||
tests/fetch-kernel-tarball/*.sh tests/unpack-buildroot/*.sh
|
||||
- name: qemu init shellcheck regression test
|
||||
run: bash tests/qemu-init/run-init-shellcheck-tests.sh
|
||||
- name: cache apt archives (python3-pil)
|
||||
@@ -155,6 +155,14 @@ jobs:
|
||||
run: bash qemu/tests/init-power-signals-test.sh
|
||||
- name: rig init daemon order matches the panel (flare-edge#348)
|
||||
run: bash qemu/tests/init-daemon-order-test.sh
|
||||
- name: rig bus starts when the payload carries a broker (flare-edge#1754)
|
||||
# A stub broker stands in for mosquitto (the runner has none), and
|
||||
# once more under busybox sh, the rig's own shell.
|
||||
run: |
|
||||
bash qemu/tests/init-rig-bus-test.sh
|
||||
if command -v busybox >/dev/null; then
|
||||
WARDEN_TEST_SH="busybox sh" bash qemu/tests/init-rig-bus-test.sh
|
||||
fi
|
||||
- name: rig control bridge waits out a slow UI (flare-edge#1448)
|
||||
run: bash qemu/tests/ctl-bridge-test.sh
|
||||
- name: mkimage.sh SEED_DIR regression test
|
||||
@@ -175,6 +183,14 @@ jobs:
|
||||
# Retry-on-mismatch, cleanup, and the already-verified
|
||||
# short-circuit, against a fake curl on PATH: no network.
|
||||
run: bash tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh
|
||||
- name: fetch-kernel-tarball regression tests
|
||||
# Bounded curl and no partial tarball after a failed fetch (#1588),
|
||||
# against a fake curl on PATH: no network.
|
||||
run: bash tests/fetch-kernel-tarball/run-fetch-kernel-tarball-tests.sh
|
||||
- name: QEMU busybox fetch regression tests
|
||||
# Retry on a bad sha256, the cached copy, and a server that answers
|
||||
# and then stalls (#1588), against local listeners: no network.
|
||||
run: bash qemu/tests/busybox-fetch.sh
|
||||
- name: unpack-buildroot regression tests
|
||||
# Fresh unpack, leave-existing-tree-alone, and every refusal path
|
||||
# (unpatched selectors, bad tarball, half-present tree, failed
|
||||
|
||||
@@ -22,7 +22,16 @@ TB="${1:?usage: fetch-kernel-tarball.sh <destination-path>}"
|
||||
}
|
||||
if [ ! -f "$TB" ]; then
|
||||
echo "== downloading $URL"
|
||||
curl --retry 3 --retry-delay 5 --retry-connrefused -fSL "$URL" -o "$TB"
|
||||
# Bounded (#1588): a connection that opens and then stalls gives up after
|
||||
# 30 s below 10 KiB/s and is retried, instead of holding the job until its
|
||||
# own timeout. The download lands beside $TB and is renamed only when curl
|
||||
# succeeds, so a failed fetch never leaves a partial tarball that the next
|
||||
# run would take as present and then reject on its sha256.
|
||||
tmp="$TB.download.$$"
|
||||
trap 'rm -f "$tmp"' EXIT
|
||||
curl --retry 2 --retry-delay 5 --retry-connrefused --connect-timeout 20 \
|
||||
--speed-limit 10240 --speed-time 30 --max-time 600 -fSL "$URL" -o "$tmp"
|
||||
mv -f "$tmp" "$TB"
|
||||
fi
|
||||
want="$(cat "$SHA_FILE")"
|
||||
got="$(sha256sum "$TB" | awk '{print $1}')"
|
||||
|
||||
@@ -73,6 +73,11 @@ daemons a bench panel already runs: flare-edge `tools/rig-pull-daemons.sh
|
||||
chardev without `--rs485`), so `warden-modbus` polls a port with nothing on
|
||||
it, as on a panel with an empty header, and never the control channel.
|
||||
|
||||
A `mosquitto` in the payload starts the panel's device bus first (socket
|
||||
`/run/warden/bus/bus.sock`, one credential file per bus user under
|
||||
`/run/warden/bus/cred/`), as S10bus does before every bus client on a panel;
|
||||
see `payload/README.md`. The rig broker takes any user and loads no plugin.
|
||||
|
||||
The VT cursor is kept off (`vt.global_cursor_default=0`): fbcon shares the
|
||||
virtio-gpu framebuffer with warden-ui and its blinking cursor would otherwise
|
||||
show up in screendumps at random (issue #18).
|
||||
@@ -107,6 +112,7 @@ All take the virt-fragment `<zImage>`; `FLARE_EDGE=<checkout>` where noted.
|
||||
| `test-ui-drive-rs485.sh` | - | offline, no VM: a fake `run.sh` and (for one case) a fake `socat` stand in so `ui-drive.sh --rs485-devices`'s startup fails closed instead of printing a false "== rs485 simulator: ..." over a bus nothing is serving, for each of a qemu rs.sock that never appears, a socat that never links rs.pty, and an mbsim.py that dies before opening rs.ctl; also proves `cleanup()` escalates to SIGKILL for a sim process that ignores SIGTERM |
|
||||
| `run-sh-args-test.sh` | - | offline, no VM: a fake `qemu-system-arm` captures run.sh's own argv and pins the ctl/rs485 pci-serial ordering contract rootfs/sbin/init's ttyS0-vs-ttyS1 alias depends on -- the ctl device always enumerates before rs485, warden.ctl only lands on the cmdline when --ctl is given, and an rs485 pci-serial device (real or null-backed) is always present so the port count never shifts |
|
||||
| `ctl-bridge-test.sh` | - | offline, no VM: runs the control bridge (`warden_ctl_bridge` in rootfs/etc/warden-lib.sh) against a fake warden-ui that answers some commands late. A reply slower than the old 5 s bound still arrives (the bound is now 30 s, `WARDEN_CTL_WAIT_S`), a timeout answers `bridge: no reply from warden-ui ...` (qmp.py raises it as a rig fault), and a timed-out command's late reply is drained instead of being read as the next command's answer (flare-edge #1448) |
|
||||
| `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) |
|
||||
| watchdog (`run.sh --watchdog`) | - | arm `/dev/watchdog`, don't pet: the VM resets ~30 s later (verified) |
|
||||
|
||||
Scenario fine print:
|
||||
|
||||
+10
-1
@@ -33,11 +33,20 @@ qemu_get_busybox() {
|
||||
qemu_log "cached busybox failed verification; fetching a clean copy"
|
||||
fi
|
||||
|
||||
# Every attempt is bounded: a server that answers and then stalls would
|
||||
# otherwise hold the job until its own timeout, with no retry (#1588). Below
|
||||
# 1 KiB/s for the stall window, or past the total cap, curl gives up and the
|
||||
# loop moves on. Defaults cap the worst case near 6 minutes; the tests
|
||||
# shorten them through the environment.
|
||||
local stall="${BB_FETCH_STALL_SECS:-20}" max="${BB_FETCH_MAX_SECS:-60}"
|
||||
local delay="${BB_FETCH_RETRY_DELAY:-5}"
|
||||
local attempt tmp="${BB}.download.$$"
|
||||
rm -f "$tmp"
|
||||
for attempt in 1 2 3; do
|
||||
qemu_log "downloading $BB_URL (attempt $attempt/3)"
|
||||
if curl --retry 3 --retry-delay 5 --retry-connrefused -fSL "$BB_URL" -o "$tmp"; then
|
||||
if curl --retry 1 --retry-delay "$delay" --retry-connrefused \
|
||||
--connect-timeout "$stall" --speed-limit 1024 --speed-time "$stall" \
|
||||
--max-time "$max" -fSL "$BB_URL" -o "$tmp"; then
|
||||
got="$(sha256sum "$tmp" | awk '{print $1}')"
|
||||
if [ "$want" = "$got" ]; then
|
||||
mv -f "$tmp" "$BB"
|
||||
|
||||
@@ -26,6 +26,13 @@ musl binary, so flare-edge `tools/rig-pull-daemons.sh --host <panel>` copies
|
||||
release and each md5 in `PULLED.txt`), minus `warden-ui`, which the rig
|
||||
needs as the fbdev+evdev build.
|
||||
|
||||
A `mosquitto` here (the static armhf broker of flare-edge
|
||||
`tools/mosquitto-build.sh armhf`) gives the guest the panel's device bus:
|
||||
stage-2 init starts it on `/run/warden/bus/bus.sock` before any daemon and
|
||||
writes a credential file per bus user to `/run/warden/bus/cred/<user>`
|
||||
(`warden_rig_bus` in `qemu/rootfs/etc/warden-lib.sh`; the broker log is
|
||||
`/tmp/mosquitto.log`). Without it the guest has no bus, as before.
|
||||
|
||||
Stage-2 init starts every `warden-*` daemon it finds here, in the panel's
|
||||
own S-number order (ai, automation, modbus, mikrotik, asic, starlink,
|
||||
stratum, flared), then `warden-ui` (the UI also needs `--display
|
||||
|
||||
@@ -69,7 +69,9 @@ warden_idle_forever() {
|
||||
#
|
||||
# `@cat PATH` is answered here and never forwarded: PATH's contents (or one
|
||||
# "bridge: no such file: PATH" line), which is how the json flow channel
|
||||
# reads webstatus.c's snapshot from outside the VM. Everything else goes to
|
||||
# reads webstatus.c's snapshot from outside the VM. `@procs` is answered
|
||||
# here too: every /proc/<pid>/stat line, for qmp.py's stall probe
|
||||
# (flare-edge #1528). Everything else goes to
|
||||
# warden-ui's FIFO, and the bridge waits for the reply file the UI renames
|
||||
# into place whole. The previous reply is removed BEFORE sending: a fixed
|
||||
# settle handed back the previous command's reply (flare-edge #152).
|
||||
@@ -105,6 +107,11 @@ warden_ctl_bridge() {
|
||||
echo "bridge: no such file: $path"
|
||||
fi
|
||||
;;
|
||||
"@procs")
|
||||
# Every process's stat line, for the driver's stall probe
|
||||
# (qmp.py stall_report, flare-edge #1528); needs no UI.
|
||||
cat /proc/[0-9]*/stat 2>/dev/null
|
||||
;;
|
||||
*)
|
||||
if [ -p "$_wcb_fifo" ]; then
|
||||
if [ "$_wcb_stale" = 1 ]; then
|
||||
@@ -141,3 +148,94 @@ _wcb_wait_reply() {
|
||||
_wcb_n=$((_wcb_n + 1))
|
||||
done
|
||||
}
|
||||
|
||||
# The rig's device bus (flare-edge #1754, the #1050 QEMU half). A panel runs
|
||||
# one mosquitto on /run/warden/bus/bus.sock (flare-edge S10bus) and every
|
||||
# daemon, the UI included, talks over it. The rig starts the same broker
|
||||
# when the payload carries one (/usr/bin/mosquitto, the static armhf build of
|
||||
# flare-edge tools/mosquitto-build.sh); a payload without it boots exactly as
|
||||
# before, with no bus.
|
||||
#
|
||||
# Same paths as the panel, so the production clients need no rig switch:
|
||||
# the socket at <bus>/sock/bus.sock with the <bus>/bus.sock link clients
|
||||
# dial, and one credential file per bus user at <bus>/cred/<user>, which a
|
||||
# client reads at every CONNECT. What the rig leaves out, on purpose: the
|
||||
# password file and ACL (the broker takes any user; the rig is a test
|
||||
# instrument and every process in it runs as root anyway) and the retain gate
|
||||
# plugin (a static broker loads no plugins). The credential files hold a
|
||||
# fresh random secret all the same, so a client finds what it expects.
|
||||
#
|
||||
# WARDEN_RIG_BUS_USERS lists the bus users that get a credential file: the
|
||||
# panel's /etc/warden/bus/users and bundled-users (flare-edge busgen output).
|
||||
# WARDEN_RIG_BROKER, WARDEN_BUS_RUN, WARDEN_RIG_BUS_LOG and
|
||||
# WARDEN_RIG_BUS_WAIT_S exist for the host test only.
|
||||
warden_rig_bus() {
|
||||
_wrb_broker="${WARDEN_RIG_BROKER:-/usr/bin/mosquitto}"
|
||||
[ -x "$_wrb_broker" ] || return 0
|
||||
_wrb_dir="${WARDEN_BUS_RUN:-/run/warden/bus}"
|
||||
_wrb_log="${WARDEN_RIG_BUS_LOG:-/tmp/mosquitto.log}"
|
||||
_wrb_users="${WARDEN_RIG_BUS_USERS:-flared ui io modbus appd telemetry automation.main}"
|
||||
if ! mkdir -p "$_wrb_dir/cred" "$_wrb_dir/sock"; then
|
||||
echo "init: rig bus FAILED: cannot create $_wrb_dir"
|
||||
return 1
|
||||
fi
|
||||
chmod 0751 "$_wrb_dir"
|
||||
chmod 0710 "$_wrb_dir/cred"
|
||||
# The panel's broker settings (flare-edge
|
||||
# overlay-flare-warden-ui/etc/warden/bus/mosquitto.conf) minus the
|
||||
# password file, ACL and plugin lines (see above). `user root` keeps the
|
||||
# broker from dropping to an account the rig rootfs does not have.
|
||||
cat > "$_wrb_dir/mosquitto.conf" <<WRB_CONF
|
||||
# QEMU rig broker, written by warden_rig_bus (qemu/rootfs/etc/warden-lib.sh).
|
||||
user root
|
||||
listener 0 $_wrb_dir/sock/bus.sock
|
||||
allow_anonymous true
|
||||
pid_file $_wrb_dir/sock/mosquitto.pid
|
||||
use_username_as_clientid true
|
||||
persistence false
|
||||
message_size_limit 131072
|
||||
max_packet_size 135168
|
||||
max_connections 128
|
||||
max_queued_messages 1000
|
||||
max_queued_bytes 2097152
|
||||
max_inflight_messages 20
|
||||
max_qos 1
|
||||
max_keepalive 60
|
||||
sys_interval 0
|
||||
connection_messages false
|
||||
log_dest stderr
|
||||
log_type error
|
||||
log_type warning
|
||||
WRB_CONF
|
||||
for _wrb_u in $_wrb_users; do
|
||||
case "$_wrb_u" in
|
||||
''|*/*|.*) echo "init: rig bus: bad user name '$_wrb_u' skipped"; continue ;;
|
||||
esac
|
||||
rm -f "$_wrb_dir/cred/$_wrb_u"
|
||||
(umask 077; od -An -tx1 -N32 /dev/urandom | tr -d ' \n' > "$_wrb_dir/cred/$_wrb_u")
|
||||
chmod 0400 "$_wrb_dir/cred/$_wrb_u"
|
||||
done
|
||||
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 &
|
||||
_wrb_pid=$!
|
||||
# Clients retry a missing socket, but a daemon started before the broker
|
||||
# listens logs a refused first dial: wait for the socket (0.1 s polls,
|
||||
# bounded) so the payload daemons find it on their first try.
|
||||
_wrb_n=0
|
||||
_wrb_limit=$(( ${WARDEN_RIG_BUS_WAIT_S:-10} * 10 ))
|
||||
while [ ! -S "$_wrb_dir/sock/bus.sock" ]; do
|
||||
if ! kill -0 "$_wrb_pid" 2>/dev/null; then
|
||||
echo "init: rig bus FAILED: the broker exited; log tail:"
|
||||
tail -n 5 "$_wrb_log" 2>/dev/null
|
||||
return 1
|
||||
fi
|
||||
if [ "$_wrb_n" -ge "$_wrb_limit" ]; then
|
||||
echo "init: rig bus FAILED: no socket after $((_wrb_limit / 10)) s"
|
||||
return 1
|
||||
fi
|
||||
sleep 0.1
|
||||
_wrb_n=$((_wrb_n + 1))
|
||||
done
|
||||
echo "init: rig bus up on $_wrb_dir/bus.sock (broker pid $_wrb_pid)"
|
||||
}
|
||||
|
||||
@@ -108,6 +108,11 @@ 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
|
||||
# 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
|
||||
# a flow that needs the bus fails on its own checks.
|
||||
warden_rig_bus || true
|
||||
# OTA apply is opt-in per boot (run.sh --allow-apply): writing rootfs_b is
|
||||
# safe inside disk.img but must never be the default posture.
|
||||
if grep -qw warden.fwapply /proc/cmdline; then
|
||||
|
||||
@@ -69,4 +69,54 @@ cp "$SCRATCH/good" "$SCRATCH/cached/busybox-armv7l"
|
||||
OUT="$SCRATCH/cached" qemu_get_busybox
|
||||
test "$(cat "$FAKE_CURL_COUNT")" = 0
|
||||
|
||||
# A server that answers and then stalls must not hang the fetch (#1588). This
|
||||
# runs the real curl against a local listener that sends headers and a few
|
||||
# bytes, then goes silent; the short limits keep the test fast.
|
||||
PATH="${PATH//"$FAKE_BIN:"/}"
|
||||
python3 - "$SCRATCH/stall-port" <<'STALL' &
|
||||
import os, socket, sys, threading, time
|
||||
srv = socket.socket()
|
||||
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
srv.bind(("127.0.0.1", 0))
|
||||
srv.listen(16)
|
||||
with open(sys.argv[1] + ".tmp", "w") as f:
|
||||
f.write(str(srv.getsockname()[1]))
|
||||
os.rename(sys.argv[1] + ".tmp", sys.argv[1])
|
||||
held = []
|
||||
def serve(conn):
|
||||
try:
|
||||
conn.recv(4096)
|
||||
conn.sendall(b"HTTP/1.1 200 OK\r\nContent-Length: 1000000\r\n\r\nstall")
|
||||
held.append(conn)
|
||||
time.sleep(600)
|
||||
except OSError:
|
||||
pass
|
||||
while True:
|
||||
c, _ = srv.accept()
|
||||
threading.Thread(target=serve, args=(c,), daemon=True).start()
|
||||
STALL
|
||||
STALL_PID=$!
|
||||
trap 'kill "$STALL_PID" 2>/dev/null || true; rm -rf "$SCRATCH"' EXIT
|
||||
for _ in $(seq 100); do [ -s "$SCRATCH/stall-port" ] && break; sleep 0.1; done
|
||||
test -s "$SCRATCH/stall-port"
|
||||
BB_URL="http://127.0.0.1:$(cat "$SCRATCH/stall-port")/busybox"
|
||||
start=$SECONDS
|
||||
# The bash -c program expands its own positional arguments.
|
||||
# shellcheck disable=SC2016
|
||||
if (OUT="$SCRATCH/stalled" BB_FETCH_STALL_SECS=1 BB_FETCH_MAX_SECS=3 \
|
||||
BB_FETCH_RETRY_DELAY=1 timeout 60 bash -c \
|
||||
'set -euo pipefail; source "$1"; QEMU_DIR="$2"; BB_URL="$3"; qemu_get_busybox' \
|
||||
_ "$TEST_DIR/../lib.sh" "$QEMU_DIR" "$BB_URL") >"$SCRATCH/stall.log" 2>&1; then
|
||||
echo "FAIL: a stalled download was accepted" >&2
|
||||
exit 1
|
||||
fi
|
||||
elapsed=$((SECONDS - start))
|
||||
if ! grep -q 'after 3 verified attempts' "$SCRATCH/stall.log"; then
|
||||
echo "FAIL: a stalled download hung instead of failing (${elapsed}s)" >&2
|
||||
cat "$SCRATCH/stall.log" >&2
|
||||
exit 1
|
||||
fi
|
||||
test "$elapsed" -lt 45
|
||||
test ! -e "$SCRATCH/stalled/busybox-armv7l"
|
||||
|
||||
echo "busybox fetch tests passed"
|
||||
|
||||
@@ -101,6 +101,16 @@ run_bridge nofifo 1 page
|
||||
check "missing FIFO answers at once" \
|
||||
same "$WORK/nofifo.out" 'bridge: warden-ui control FIFO not present' '<<END>>'
|
||||
|
||||
# @procs: the process table for the stall probe (flare-edge #1528), answered
|
||||
# by the bridge itself, so it works with no UI at all.
|
||||
procs_ok() {
|
||||
grep -Eq '^[0-9]+ \(.*\) [A-Z] ' "$WORK/procs.out" &&
|
||||
[ "$(tail -n 1 "$WORK/procs.out")" = '<<END>>' ] &&
|
||||
! grep -q 'FIFO not present' "$WORK/procs.out"
|
||||
}
|
||||
run_bridge procs 1 @procs
|
||||
check "@procs lists process stat lines without the UI" procs_ok
|
||||
|
||||
if [ "$FAIL" = 0 ]; then
|
||||
echo "ctl-bridge tests: OK ($CHECKS checks)"
|
||||
else
|
||||
|
||||
Executable
+176
@@ -0,0 +1,176 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC2317 # the checks and the cleanup run through check() and trap
|
||||
# Host test for the rig's device bus, warden_rig_bus in
|
||||
# qemu/rootfs/etc/warden-lib.sh (flare-edge #1754, #1050). Checks:
|
||||
# - a payload without a broker boots as before: nothing created, status 0
|
||||
# - with a broker: the panel's layout (sock/bus.sock and the bus.sock link,
|
||||
# one 0400 credential file of 64 hex digits per bus user, each its own),
|
||||
# a config with the listener and no password file, ACL or plugin
|
||||
# - a broker that exits, or never listens, is reported and returns 1
|
||||
# within the wait bound
|
||||
# - a user name that is not a plain file name gets no file
|
||||
# - /sbin/init starts the bus before the payload daemons
|
||||
# A stub broker (python3, binds the configured listener) stands in for
|
||||
# mosquitto. With WARDEN_TEST_MOSQUITTO_DIR set to a directory holding
|
||||
# mosquitto, mosquitto_pub and mosquitto_sub (flare-edge
|
||||
# tools/build-host-mosquitto.sh), the real broker also carries one message
|
||||
# between two users that log in with their credential files.
|
||||
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)" || exit 1
|
||||
cleanup() {
|
||||
# The brokers outlive the shell that started them, as on the rig; each
|
||||
# has this test's folder in its argv (the stub that never listens writes
|
||||
# its pid instead).
|
||||
pkill -f -- "$WORK/" 2>/dev/null
|
||||
[ -f "$STUB/mute.pid" ] && kill "$(cat "$STUB/mute.pid")" 2>/dev/null
|
||||
rm -rf "$WORK"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
STUB="$WORK/stubs"
|
||||
mkdir -p "$STUB"
|
||||
FAIL=0
|
||||
|
||||
check() { # check <label> <command...>
|
||||
if "${@:2}"; then
|
||||
echo "[PASS] $1"
|
||||
else
|
||||
echo "[FAIL] $1"
|
||||
FAIL=1
|
||||
fi
|
||||
}
|
||||
|
||||
# Stub brokers: argv is "-c <conf>", as the lib calls mosquitto.
|
||||
# good: binds the listener path from the config and stays.
|
||||
# exits: dies at once. mute: stays and never listens.
|
||||
cat > "$STUB/good" <<'PY'
|
||||
#!/usr/bin/env python3
|
||||
import socket, sys, time
|
||||
conf = sys.argv[sys.argv.index("-c") + 1]
|
||||
lines = open(conf).read().splitlines()
|
||||
path = [l.split()[2] for l in lines if l.startswith("listener ")][0]
|
||||
time.sleep(0.3)
|
||||
s = socket.socket(socket.AF_UNIX)
|
||||
s.bind(path)
|
||||
s.listen(1)
|
||||
print("stub broker listening", flush=True)
|
||||
time.sleep(600)
|
||||
PY
|
||||
printf '#!/bin/sh\necho "Error: stub broker refused" >&2\nexit 3\n' > "$STUB/exits"
|
||||
cat > "$STUB/mute" <<'EOF'
|
||||
#!/bin/sh
|
||||
echo $$ > "${0%/*}/mute.pid"
|
||||
exec sleep 600
|
||||
EOF
|
||||
chmod +x "$STUB/good" "$STUB/exits" "$STUB/mute"
|
||||
|
||||
run_bus() { # run_bus <case> <broker> [VAR=value...]: output in <case>/out, status in <case>/rc
|
||||
local name="$1" broker="$2"
|
||||
shift 2
|
||||
mkdir -p "$WORK/$name"
|
||||
# $SH unquoted: WARDEN_TEST_SH may be "busybox sh". The lib is sourced
|
||||
# inside, so the quoted script is meant literally.
|
||||
# shellcheck disable=SC2086,SC2016
|
||||
env WARDEN_RIG_BROKER="$broker" WARDEN_BUS_RUN="$WORK/$name/bus" \
|
||||
WARDEN_RIG_BUS_LOG="$WORK/$name/broker.log" "$@" \
|
||||
$SH -c '. "$1"; warden_rig_bus' sh "$LIB" > "$WORK/$name/out" 2>&1
|
||||
echo $? > "$WORK/$name/rc"
|
||||
}
|
||||
rc_is() { [ "$(cat "$WORK/$1/rc")" = "$2" ]; }
|
||||
out_has() { grep -qF -- "$2" "$WORK/$1/out"; }
|
||||
|
||||
# 1. No broker in the payload.
|
||||
run_bus none "$WORK/no-such-broker"
|
||||
check "no broker: status 0" rc_is none 0
|
||||
check "no broker: nothing created" test ! -e "$WORK/none/bus"
|
||||
check "no broker: silent" test ! -s "$WORK/none/out"
|
||||
|
||||
# 2. A broker that listens.
|
||||
run_bus good "$STUB/good" WARDEN_RIG_BUS_USERS="flared ui modbus ../evil .hidden automation.main"
|
||||
B="$WORK/good/bus"
|
||||
check "broker up: status 0" rc_is good 0
|
||||
check "broker up: reported" out_has good "init: rig bus up on $B/bus.sock"
|
||||
check "broker up: socket listens" test -S "$B/sock/bus.sock"
|
||||
check "broker up: bus.sock link resolves to the socket" test "$(readlink "$B/bus.sock")" = sock/bus.sock -a -S "$B/bus.sock"
|
||||
creds_ok() {
|
||||
local u f seen=""
|
||||
for u in flared ui modbus automation.main; do
|
||||
f="$B/cred/$u"
|
||||
[ -f "$f" ] || { echo "missing $f"; return 1; }
|
||||
[ "$(stat -c %a "$f")" = 400 ] || { echo "$f mode $(stat -c %a "$f")"; return 1; }
|
||||
grep -qxE '[0-9a-f]{64}' "$f" || { echo "$f is not 64 hex digits"; return 1; }
|
||||
case " $seen " in *" $(cat "$f") "*) echo "$f repeats a secret"; return 1 ;; esac
|
||||
seen="$seen $(cat "$f")"
|
||||
done
|
||||
}
|
||||
check "broker up: one 0400 64-hex credential per user, all different" creds_ok
|
||||
check "broker up: a name with a slash gets no file" test ! -e "$B/evil"
|
||||
check "broker up: a dot name gets no file" test ! -e "$B/cred/.hidden"
|
||||
check "broker up: bad names reported" out_has good "bad user name '../evil' skipped"
|
||||
check "broker up: cred/ is 0710" test "$(stat -c %a "$B/cred")" = 710
|
||||
conf_ok() {
|
||||
local c="$B/mosquitto.conf"
|
||||
grep -qx "listener 0 $B/sock/bus.sock" "$c" &&
|
||||
grep -qx 'allow_anonymous true' "$c" &&
|
||||
grep -qx 'use_username_as_clientid true' "$c" &&
|
||||
! grep -qE '^(password_file|acl_file|plugin)' "$c"
|
||||
}
|
||||
check "broker up: config has the listener and no password file, ACL or plugin" conf_ok
|
||||
|
||||
# 3. A broker that exits at once.
|
||||
run_bus exits "$STUB/exits" WARDEN_RIG_BUS_WAIT_S=5
|
||||
check "broker exits: status 1" rc_is exits 1
|
||||
check "broker exits: reported with its log" out_has exits "init: rig bus FAILED: the broker exited"
|
||||
check "broker exits: log tail shown" out_has exits "stub broker refused"
|
||||
|
||||
# 4. A broker that never listens.
|
||||
start=$(date +%s)
|
||||
run_bus mute "$STUB/mute" WARDEN_RIG_BUS_WAIT_S=1
|
||||
took=$(( $(date +%s) - start ))
|
||||
[ -f "$STUB/mute.pid" ] && kill "$(cat "$STUB/mute.pid")" 2>/dev/null
|
||||
check "silent broker: status 1" rc_is mute 1
|
||||
check "silent broker: reported" out_has mute "init: rig bus FAILED: no socket after 1 s"
|
||||
check "silent broker: gave up within the bound (${took} s)" test "$took" -le 4
|
||||
|
||||
# 5. /sbin/init: the bus before the payload daemon loop.
|
||||
order_ok() {
|
||||
local bus loop
|
||||
bus=$(grep -n '^warden_rig_bus' "$INIT" | head -1 | cut -d: -f1)
|
||||
loop=$(grep -n '^for d in /usr/bin/warden-' "$INIT" | head -1 | cut -d: -f1)
|
||||
[ -n "$bus" ] && [ -n "$loop" ] && [ "$bus" -lt "$loop" ]
|
||||
}
|
||||
check "init: the rig bus starts before the payload daemons" order_ok
|
||||
|
||||
# 6. The real broker, when one is given.
|
||||
MQ="${WARDEN_TEST_MOSQUITTO_DIR:-}"
|
||||
if [ -n "$MQ" ] && [ -x "$MQ/mosquitto" ] && [ -x "$MQ/mosquitto_sub" ] && [ -x "$MQ/mosquitto_pub" ]; then
|
||||
run_bus real "$MQ/mosquitto" WARDEN_RIG_BUS_USERS="modbus ui"
|
||||
R="$WORK/real/bus"
|
||||
check "real broker: up" rc_is real 0
|
||||
real_message() {
|
||||
local got
|
||||
"$MQ/mosquitto_sub" --unix "$R/bus.sock" -u ui -P "$(cat "$R/cred/ui")" \
|
||||
-t 'modbus/state/test' -C 1 -W 10 > "$WORK/real/sub.out" 2>&1 &
|
||||
local sub=$!
|
||||
sleep 0.5
|
||||
"$MQ/mosquitto_pub" --unix "$R/bus.sock" -u modbus -P "$(cat "$R/cred/modbus")" \
|
||||
-t 'modbus/state/test' -m rig-bus-ok || return 1
|
||||
wait "$sub"
|
||||
got=$(cat "$WORK/real/sub.out")
|
||||
[ "$got" = rig-bus-ok ] || { echo "subscriber got: $got"; return 1; }
|
||||
}
|
||||
check "real broker: ui receives what modbus publishes, both logged in by credential file" real_message
|
||||
else
|
||||
echo "[SKIP] real broker (set WARDEN_TEST_MOSQUITTO_DIR)"
|
||||
fi
|
||||
|
||||
if [ "$FAIL" -eq 0 ]; then
|
||||
echo "PASS: rig bus"
|
||||
else
|
||||
echo "FAIL: rig bus"
|
||||
fi
|
||||
exit "$FAIL"
|
||||
+181
-1
@@ -178,6 +178,11 @@ QMP_TIMEOUT_S = 20.0
|
||||
# bridge's explicit "no reply" line rather than a bare socket timeout.
|
||||
CTL_TIMEOUT_S = 90.0
|
||||
|
||||
# The bridge's own answer when warden-ui did not reply within its bound
|
||||
# (Ctl.NO_REPLY; a module constant too because the offline tests swap the
|
||||
# Ctl class out).
|
||||
BRIDGE_NO_REPLY = "bridge: no reply from warden-ui"
|
||||
|
||||
# Where webstatus.c (ui-src/src/warden/webstatus.c) publishes its atomic
|
||||
# snapshot inside the guest. assert_json/wait_json `@cat` this path over the
|
||||
# control channel; see the bridge in rootfs/sbin/init.
|
||||
@@ -371,7 +376,7 @@ class Ctl:
|
||||
|
||||
# The bridge's own answer when warden-ui did not reply within its bound
|
||||
# (warden_ctl_bridge in rootfs/etc/warden-lib.sh, flare-edge #1448).
|
||||
NO_REPLY = "bridge: no reply from warden-ui"
|
||||
NO_REPLY = BRIDGE_NO_REPLY
|
||||
|
||||
def __init__(self, path, timeout=None):
|
||||
if timeout is None:
|
||||
@@ -412,6 +417,171 @@ class Ctl:
|
||||
return reply
|
||||
|
||||
|
||||
# Stall probe (flare-edge #1528). When a step fails because warden-ui did not
|
||||
# answer (the bridge's no-reply line) or did not consume an injected press,
|
||||
# the driver samples the host, the VM's vCPU thread and the guest over
|
||||
# STALL_WINDOW_S and appends one line to the step's detail, so the job log
|
||||
# itself says whether the host starved the VM, the guest CPU was saturated
|
||||
# (and by which processes), the guest waited on I/O, or the guest sat idle
|
||||
# while warden-ui was blocked. Re-run jobs lose their artifacts; the job log
|
||||
# keeps this line. At most STALL_REPORTS_MAX probes per run, since each one
|
||||
# costs the window.
|
||||
STALL_WINDOW_S = 2.0
|
||||
STALL_REPORTS_MAX = 3
|
||||
INPUT_NOT_CONSUMED = "was not consumed within"
|
||||
|
||||
|
||||
def is_stall(detail):
|
||||
"""Whether a failed step's detail is warden-ui not answering."""
|
||||
return BRIDGE_NO_REPLY in detail or INPUT_NOT_CONSUMED in detail
|
||||
|
||||
|
||||
def parse_proc_stat(text):
|
||||
"""Guest /proc/stat -> (cpu jiffies list, procs_running, procs_blocked);
|
||||
None when the text has no aggregate cpu line."""
|
||||
cpu, running, blocked = None, None, None
|
||||
for line in text.splitlines():
|
||||
parts = line.split()
|
||||
if not parts:
|
||||
continue
|
||||
if parts[0] == "cpu":
|
||||
cpu = [int(x) for x in parts[1:] if x.isdigit()]
|
||||
elif parts[0] == "procs_running" and len(parts) > 1:
|
||||
running = int(parts[1])
|
||||
elif parts[0] == "procs_blocked" and len(parts) > 1:
|
||||
blocked = int(parts[1])
|
||||
if not cpu or len(cpu) < 5:
|
||||
return None
|
||||
return cpu, running, blocked
|
||||
|
||||
|
||||
def parse_procs(text):
|
||||
"""/proc/<pid>/stat lines (the bridge's `@procs`) -> {pid: (comm, state,
|
||||
utime + stime)}. The comm may hold spaces or parentheses, so the fields
|
||||
are counted from its last ')'."""
|
||||
out = {}
|
||||
for line in text.splitlines():
|
||||
head, sep, tail = line.rpartition(")")
|
||||
if not sep or " (" not in head:
|
||||
continue
|
||||
pid, _, comm = head.partition(" (")
|
||||
fields = tail.split()
|
||||
if not pid.strip().isdigit() or len(fields) < 13:
|
||||
continue
|
||||
try:
|
||||
ticks = int(fields[11]) + int(fields[12])
|
||||
except ValueError:
|
||||
continue
|
||||
out[int(pid)] = (comm, fields[0], ticks)
|
||||
return out
|
||||
|
||||
|
||||
def guest_cpu_delta(a, b):
|
||||
"""Two parse_proc_stat() samples -> (busy share, iowait share) of the
|
||||
guest CPU over the window, or None when nothing was counted."""
|
||||
if a is None or b is None:
|
||||
return None
|
||||
d = [y - x for x, y in zip(a[0], b[0])]
|
||||
total = sum(d)
|
||||
if total <= 0:
|
||||
return None
|
||||
idle, iowait = d[3], d[4]
|
||||
return (total - idle - iowait) / total, iowait / total
|
||||
|
||||
|
||||
def top_procs(a, b, total_ticks, n=3):
|
||||
"""The N guest processes that used the most CPU between two parse_procs()
|
||||
samples, as 'comm share%' strings, and the comms in state D at the end."""
|
||||
used = []
|
||||
for pid, (comm, _state, ticks) in b.items():
|
||||
before = a.get(pid)
|
||||
if before is not None and ticks > before[2]:
|
||||
used.append((ticks - before[2], comm))
|
||||
used.sort(reverse=True)
|
||||
top = [f"{comm} {100 * t / total_ticks:.0f}%" for t, comm in used[:n]] if total_ticks > 0 else []
|
||||
dstate = sorted({comm for comm, state, _ in b.values() if state == "D"})
|
||||
return top, dstate
|
||||
|
||||
|
||||
def stall_verdict(vcpu_share, guest, blocked, dstate):
|
||||
"""One phrase naming the most likely cause from the probe's numbers."""
|
||||
if vcpu_share is not None and vcpu_share < 0.6:
|
||||
return "the host starves the VM (its vCPU thread ran under 60% of a core)"
|
||||
if guest is None:
|
||||
return "the guest did not answer the probe"
|
||||
busy, iowait = guest
|
||||
if busy >= 0.9:
|
||||
return "the guest CPU is saturated"
|
||||
if iowait >= 0.3 or blocked or dstate:
|
||||
return "the guest waits on I/O"
|
||||
return "the guest is mostly idle: warden-ui is blocked, not starved"
|
||||
|
||||
|
||||
def _read(path):
|
||||
try:
|
||||
with open(path) as fh:
|
||||
return fh.read()
|
||||
except OSError:
|
||||
return ""
|
||||
|
||||
|
||||
def _host_psi(kind):
|
||||
m = re.search(r"some avg10=([0-9.]+)", _read(f"/proc/pressure/{kind}"))
|
||||
return f"{float(m.group(1)):.0f}%" if m else "n/a"
|
||||
|
||||
|
||||
def _thread_ticks(tids):
|
||||
total = 0
|
||||
for tid in tids:
|
||||
fields = _read(f"/proc/{tid}/stat").rpartition(")")[2].split()
|
||||
if len(fields) < 13:
|
||||
return None
|
||||
total += int(fields[11]) + int(fields[12])
|
||||
return total
|
||||
|
||||
|
||||
def _guest_sample(ctl):
|
||||
try:
|
||||
return parse_proc_stat(ctl.send("@cat /proc/stat")), parse_procs(ctl.send("@procs"))
|
||||
except (RuntimeError, OSError):
|
||||
return None, {}
|
||||
|
||||
|
||||
def stall_report(ctx):
|
||||
"""Sample the host, the vCPU thread and the guest over STALL_WINDOW_S and
|
||||
describe them in one line (see the block comment above STALL_WINDOW_S)."""
|
||||
try:
|
||||
tids = [c["thread-id"] for c in rpc(ctx.s, ctx.f, {"execute": "query-cpus-fast"})]
|
||||
except (RuntimeError, OSError, KeyError, TypeError, ValueError):
|
||||
tids = []
|
||||
hz = os.sysconf("SC_CLK_TCK")
|
||||
v0 = _thread_ticks(tids) if tids else None
|
||||
g0, p0 = _guest_sample(ctx.ctl) if ctx.ctl else (None, {})
|
||||
t0 = time.monotonic()
|
||||
time.sleep(STALL_WINDOW_S)
|
||||
v1 = _thread_ticks(tids) if tids else None
|
||||
g1, p1 = _guest_sample(ctx.ctl) if ctx.ctl else (None, {})
|
||||
window = time.monotonic() - t0
|
||||
vcpu = (v1 - v0) / (hz * window) if v0 is not None and v1 is not None else None
|
||||
guest = guest_cpu_delta(g0, g1)
|
||||
blocked = g1[2] if g1 else None
|
||||
total_ticks = sum(y - x for x, y in zip(g0[0], g1[0])) if g0 and g1 else 0
|
||||
top, dstate = top_procs(p0, p1, total_ticks)
|
||||
load = os.getloadavg()[0]
|
||||
parts = [f"stall probe ({window:.1f} s): {stall_verdict(vcpu, guest, blocked, dstate)}",
|
||||
f"host load {load:.1f}/{os.cpu_count()} cpus, psi cpu {_host_psi('cpu')} "
|
||||
f"io {_host_psi('io')}",
|
||||
"vcpu " + (f"{100 * vcpu:.0f}% of a core" if vcpu is not None else "n/a")]
|
||||
if guest is None:
|
||||
parts.append("guest n/a")
|
||||
else:
|
||||
parts.append(f"guest busy {100 * guest[0]:.0f}% iowait {100 * guest[1]:.0f}%, "
|
||||
f"running {g1[1]} blocked {g1[2]}")
|
||||
parts.append("top " + (", ".join(top) if top else "n/a"))
|
||||
parts.append("D " + (", ".join(dstate) if dstate else "none"))
|
||||
return "; ".join(parts)
|
||||
|
||||
|
||||
HIT_RE = re.compile(r'^hit \d+,\d+: (\S+)(?: text="(.*)" box=(-?\d+),(-?\d+),(\d+)x(\d+))?$')
|
||||
|
||||
|
||||
@@ -775,6 +945,8 @@ class Ctx:
|
||||
self.prev_step_console = 0
|
||||
# The longest input-count wait of the current tap, swipe or fling.
|
||||
self.input_wait_s = 0.0
|
||||
# Stall probes run so far (STALL_REPORTS_MAX bounds them).
|
||||
self.stall_reports = 0
|
||||
|
||||
def need_ctl(self, lineno, cmd):
|
||||
if self.ctl is None:
|
||||
@@ -1289,6 +1461,14 @@ def drive(s, f, script_path, outdir, size, ctl_path=None, console_path=None, ref
|
||||
# Recorded the same as any other fatal row: the run keeps going
|
||||
# past it.
|
||||
result = ("fatal", str(e))
|
||||
if (result is not None and result[0] != "ok" and len(result) > 1
|
||||
and is_stall(str(result[1])) and ctx.stall_reports < STALL_REPORTS_MAX):
|
||||
ctx.stall_reports += 1
|
||||
try:
|
||||
probe = stall_report(ctx)
|
||||
except (RuntimeError, OSError, ValueError) as e:
|
||||
probe = f"stall probe failed: {e}"
|
||||
result = (result[0], f"{result[1]}; {probe}")
|
||||
if result is not None:
|
||||
record(lineno, line, *result)
|
||||
|
||||
|
||||
@@ -1361,5 +1361,109 @@ class JsonStatusFetch(unittest.TestCase):
|
||||
self.assertGreaterEqual(time.monotonic() - t0, 0.6)
|
||||
|
||||
|
||||
|
||||
def _proc_stat(user, idle, iowait=0, running=1, blocked=0):
|
||||
return (f"cpu {user} 0 0 {idle} {iowait} 0 0 0 0 0\ncpu0 {user} 0 0 {idle} {iowait} 0 0 0 0 0\n"
|
||||
f"ctxt 1\nprocs_running {running}\nprocs_blocked {blocked}\n")
|
||||
|
||||
|
||||
def _pid_line(pid, comm, state, utime, stime=0):
|
||||
rest = " ".join(["0"] * 10)
|
||||
return f"{pid} ({comm}) {state} 1 1 1 0 -1 0 0 0 0 0 {utime} {stime} {rest}"
|
||||
|
||||
|
||||
class StallProbe(unittest.TestCase):
|
||||
"""flare-edge #1528: a step that fails because warden-ui did not answer
|
||||
carries one probe line saying why (host starving the VM, guest CPU
|
||||
saturated, guest I/O wait, or an idle guest with a blocked UI)."""
|
||||
|
||||
def test_parsers(self):
|
||||
st = qmp.parse_proc_stat(_proc_stat(5, 7, 2, running=3, blocked=1))
|
||||
self.assertEqual(st, ([5, 0, 0, 7, 2, 0, 0, 0, 0, 0], 3, 1))
|
||||
self.assertIsNone(qmp.parse_proc_stat("bridge: no such file: /proc/stat"))
|
||||
procs = qmp.parse_procs(_pid_line(7, "warden ui) x", "R", 40, 2) + "\n"
|
||||
+ _pid_line(9, "sh", "D", 1) + "\njunk\n")
|
||||
self.assertEqual(procs, {7: ("warden ui) x", "R", 42), 9: ("sh", "D", 1)})
|
||||
|
||||
def test_verdicts(self):
|
||||
self.assertIn("starves the VM", qmp.stall_verdict(0.3, (1.0, 0.0), 0, []))
|
||||
self.assertIn("did not answer", qmp.stall_verdict(0.99, None, None, []))
|
||||
self.assertIn("saturated", qmp.stall_verdict(0.99, (0.95, 0.0), 0, []))
|
||||
self.assertIn("I/O", qmp.stall_verdict(0.99, (0.2, 0.5), 1, ["warden-ui"]))
|
||||
self.assertIn("I/O", qmp.stall_verdict(None, (0.1, 0.0), 0, ["warden-ui"]))
|
||||
self.assertIn("idle", qmp.stall_verdict(0.99, (0.05, 0.0), 0, []))
|
||||
|
||||
def test_cpu_delta_and_top(self):
|
||||
a = qmp.parse_proc_stat(_proc_stat(100, 100))
|
||||
b = qmp.parse_proc_stat(_proc_stat(190, 110))
|
||||
busy, iowait = qmp.guest_cpu_delta(a, b)
|
||||
self.assertAlmostEqual(busy, 0.9)
|
||||
self.assertEqual(iowait, 0.0)
|
||||
p0 = qmp.parse_procs(_pid_line(7, "warden-ui", "R", 10) + "\n" + _pid_line(8, "flared", "S", 5))
|
||||
p1 = qmp.parse_procs(_pid_line(7, "warden-ui", "R", 80) + "\n" + _pid_line(8, "flared", "D", 25))
|
||||
top, dstate = qmp.top_procs(p0, p1, 100)
|
||||
self.assertEqual(top, ["warden-ui 70%", "flared 20%"])
|
||||
self.assertEqual(dstate, ["flared"])
|
||||
|
||||
def _drive_no_reply(self, script):
|
||||
class NoReplyCtl(FakeCtl):
|
||||
samples = 0
|
||||
|
||||
def send(self, cmd):
|
||||
if cmd == "@cat /proc/stat":
|
||||
NoReplyCtl.samples += 1
|
||||
n = NoReplyCtl.samples
|
||||
return _proc_stat(100 * n, 10)
|
||||
if cmd == "@procs":
|
||||
n = NoReplyCtl.samples
|
||||
return _pid_line(7, "warden-ui", "R", 95 * n) + "\n" + _pid_line(8, "sh", "S", 5 * n)
|
||||
if cmd == "page":
|
||||
raise RuntimeError("control channel: bridge: no reply from warden-ui "
|
||||
"within 30 s: page")
|
||||
return super().send(cmd)
|
||||
|
||||
def rpc_fn(sock, sock_file, obj):
|
||||
if obj.get("execute") == "query-cpus-fast":
|
||||
# No vCPU thread to sample here (test_vcpu_thread_ticks
|
||||
# covers the sampling); the verdict then rests on the guest.
|
||||
return []
|
||||
return fake_rpc(sock, sock_file, obj)
|
||||
|
||||
saved = qmp.STALL_WINDOW_S
|
||||
qmp.STALL_WINDOW_S = 0.05
|
||||
try:
|
||||
return run_script(script, ctl_cls=NoReplyCtl, rpc_fn=rpc_fn)
|
||||
finally:
|
||||
qmp.STALL_WINDOW_S = saved
|
||||
|
||||
def test_no_reply_steps_carry_a_bounded_probe(self):
|
||||
rc, _by, rows = self._drive_no_reply("assert_page Demo/Rows\n" * 4 + "assert_stat fps lt 0\n")
|
||||
self.assertEqual(rc, 1)
|
||||
self.assertEqual([r["status"] for r in rows], ["fatal"] * 4 + ["fail"])
|
||||
probed = [r["detail"] for r in rows if "stall probe" in r["detail"]]
|
||||
self.assertEqual(len(probed), qmp.STALL_REPORTS_MAX, rows)
|
||||
first = rows[0]["detail"]
|
||||
self.assertTrue(first.startswith("control channel: bridge: no reply"), first)
|
||||
self.assertIn("the guest CPU is saturated", first)
|
||||
self.assertIn("top warden-ui 95%, sh 5%", first)
|
||||
self.assertIn("vcpu n/a", first)
|
||||
self.assertIn("guest busy 100% iowait 0%", first)
|
||||
# A plain mismatch is not a stall and gets no probe.
|
||||
self.assertNotIn("stall probe", rows[4]["detail"])
|
||||
|
||||
def test_vcpu_thread_ticks(self):
|
||||
tid = threading.get_native_id()
|
||||
before = qmp._thread_ticks([tid])
|
||||
end = time.process_time() + 0.3
|
||||
while time.process_time() < end:
|
||||
pass
|
||||
self.assertGreater(qmp._thread_ticks([tid]), before)
|
||||
self.assertIsNone(qmp._thread_ticks([2 ** 22 + 12345]))
|
||||
|
||||
def test_unconsumed_input_is_a_stall(self):
|
||||
self.assertTrue(qmp.is_stall(qmp.input_verdict(SimpleNamespace(), False)[1]))
|
||||
self.assertTrue(qmp.is_stall("control channel: bridge: no reply from warden-ui within 30 s: hit"))
|
||||
self.assertFalse(qmp.is_stall("obj moved: box=1,2,3x4"))
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=1)
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regression tests for build/fetch-kernel-tarball.sh (#1588).
|
||||
#
|
||||
# Runs the real script, copied into a fixture dir so its own HERE-relative pin
|
||||
# lookup finds a pin we control, with a fake curl first on PATH: no network,
|
||||
# and the outcome of each fetch is exact. Covers:
|
||||
# - curl is bounded (connect timeout, stall abort, total cap), so a server
|
||||
# that answers and then stalls cannot hold the job until its timeout;
|
||||
# - a failed fetch leaves no partial tarball behind, so the next run fetches
|
||||
# again instead of taking the partial file as present;
|
||||
# - a good fetch is verified and kept; a present, matching tarball is reused.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
SCRIPT="$HERE/../../build/fetch-kernel-tarball.sh"
|
||||
[ -f "$SCRIPT" ] || { echo "FAIL: script not found at $SCRIPT"; exit 1; }
|
||||
KVER="$(sed -n 's/^KVER=//p' "$SCRIPT")"
|
||||
[ -n "$KVER" ] || { echo "FAIL: no KVER in $SCRIPT"; exit 1; }
|
||||
|
||||
FAIL=0
|
||||
ok() { printf '[PASS] %s\n' "$1"; }
|
||||
bad() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
|
||||
|
||||
TMP="$(mktemp -d)"
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
|
||||
setup() { # setup <case-name> -> prints the fixture dir
|
||||
local dir="$TMP/$1"
|
||||
mkdir -p "$dir/bin"
|
||||
cp "$SCRIPT" "$dir/fetch-kernel-tarball.sh"
|
||||
printf 'good-bytes' | sha256sum | awk '{print $1}' \
|
||||
> "$dir/linux-$KVER.tar.xz.sha256"
|
||||
printf '%s' "$dir"
|
||||
}
|
||||
|
||||
# fake_curl <dir> <mode>: records its argv in <dir>/argv and its call count in
|
||||
# <dir>/count. Modes: good (writes the pinned bytes), partial (writes a few
|
||||
# bytes, then fails the way curl does on a timeout), never (must not run).
|
||||
fake_curl() {
|
||||
local dir="$1" mode="$2"
|
||||
# These single-quoted lines are the literal source of the fake program.
|
||||
# shellcheck disable=SC2016
|
||||
printf '%s\n' '#!/bin/sh' \
|
||||
'dir=$(dirname "$(dirname "$0")")' \
|
||||
'printf "%s\n" "$*" > "$dir/argv"' \
|
||||
'echo x >> "$dir/count"' \
|
||||
'out=' \
|
||||
'while [ "$#" -gt 0 ]; do' \
|
||||
' if [ "$1" = "-o" ]; then shift; out="$1"; fi' \
|
||||
' shift' \
|
||||
'done' \
|
||||
'[ -n "$out" ] || exit 2' \
|
||||
"case $mode in" \
|
||||
' good) printf good-bytes > "$out" ;;' \
|
||||
' partial) printf good > "$out"; exit 28 ;;' \
|
||||
' *) echo "curl should not have run" >&2; exit 1 ;;' \
|
||||
'esac' > "$dir/bin/curl"
|
||||
chmod +x "$dir/bin/curl"
|
||||
}
|
||||
|
||||
run() { # run <dir> <dest> -> output in $OUT, status in $RC
|
||||
local dir="$1" dest="$2"
|
||||
OUT="$(PATH="$dir/bin:$PATH" bash "$dir/fetch-kernel-tarball.sh" "$dest" 2>&1)"
|
||||
RC=$?
|
||||
}
|
||||
|
||||
# --- case A: a good fetch is bounded, verified and kept ---------------------
|
||||
dir="$(setup case-a)"
|
||||
fake_curl "$dir" good
|
||||
run "$dir" "$dir/linux.tar.xz"
|
||||
if [ "$RC" -eq 0 ] && [ -f "$dir/linux.tar.xz" ] \
|
||||
&& printf '%s' "$OUT" | grep -q 'tarball sha256 verified'; then
|
||||
ok "good fetch: verified and kept"
|
||||
else
|
||||
bad "good fetch: verified and kept (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
for flag in --connect-timeout --speed-limit --speed-time --max-time; do
|
||||
if grep -q -- "$flag" "$dir/argv"; then
|
||||
ok "curl carries $flag"
|
||||
else
|
||||
bad "curl carries $flag (argv: $(cat "$dir/argv"))"
|
||||
fi
|
||||
done
|
||||
if ls "$dir"/linux.tar.xz.download.* >/dev/null 2>&1; then
|
||||
bad "good fetch: no download temp file left"
|
||||
else
|
||||
ok "good fetch: no download temp file left"
|
||||
fi
|
||||
|
||||
# --- case B: a failed fetch leaves nothing, and the next run fetches again --
|
||||
dir="$(setup case-b)"
|
||||
fake_curl "$dir" partial
|
||||
run "$dir" "$dir/linux.tar.xz"
|
||||
if [ "$RC" -ne 0 ] && [ ! -e "$dir/linux.tar.xz" ] \
|
||||
&& ! ls "$dir"/linux.tar.xz.download.* >/dev/null 2>&1; then
|
||||
ok "failed fetch: no partial tarball left"
|
||||
else
|
||||
bad "failed fetch: no partial tarball left (rc=$RC, files: $(ls "$dir"))"
|
||||
fi
|
||||
fake_curl "$dir" good
|
||||
run "$dir" "$dir/linux.tar.xz"
|
||||
if [ "$RC" -eq 0 ] && [ "$(wc -l < "$dir/count")" -eq 2 ]; then
|
||||
ok "run after a failed fetch downloads again and passes"
|
||||
else
|
||||
bad "run after a failed fetch downloads again and passes (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
# --- case C: a present, matching tarball is reused without curl -------------
|
||||
dir="$(setup case-c)"
|
||||
printf 'good-bytes' > "$dir/linux.tar.xz"
|
||||
fake_curl "$dir" never
|
||||
run "$dir" "$dir/linux.tar.xz"
|
||||
if [ "$RC" -eq 0 ] && [ ! -e "$dir/count" ]; then
|
||||
ok "present tarball: reused, curl never invoked"
|
||||
else
|
||||
bad "present tarball: reused, curl never invoked (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
[ "$FAIL" -eq 0 ] && echo "fetch-kernel-tarball tests passed"
|
||||
exit "$FAIL"
|
||||
Reference in New Issue
Block a user