ci / kernel-build (push) Skipped
ci / patches-apply (push) Successful in 59s
ci / test (pull_request) Successful in 29s
ci / bench (pull_request) Successful in 5s
ci / bench (push) Successful in 13s
ci / qemu-tools (push) Successful in 1m56s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / patches-apply (pull_request) Successful in 1m5s
ci / kernel-symbols (push) Successful in 4m0s
ci / quality (pull_request) Successful in 1m51s
ci / test (push) Successful in 15s
ci / mcdc (push) Successful in 30s
ci / prune-artifacts (push) Skipped
ci / mcdc (pull_request) Successful in 30s
ci / qemu-tools (pull_request) Successful in 1m18s
ci / badges (pull_request) Skipped
ci / quality (push) Successful in 2m5s
ci / badges (push) Skipped
ci / kernel-symbols (pull_request) Successful in 5m14s
flowc compiles a flow's `override` action to `override TOPIC DOC|null`, and a test-flavor warden-ui answers the override verb on test/req/ui, but the rig driver had no such verb and the control bridge only reached the UI's old FIFO, so a flow using it failed with an unknown command (flare-edge #2054). qmp.py `override` sends the request through the control bridge: the args JSON in `@hookdoc` / `@hookdoc+` pieces of 2000 bytes (the ctl port is a cooked tty that cuts a line at 4095 bytes; a document may be 16 KiB), then `@hook override`. The bridge runs the payload's wthctl as bus user testhook and answers its reply. ok:true passes, ok:false fails with the hook's err, and a request that never reached the hook (no client, no bus, no reply, a reply that is not a hook envelope) is fatal. The rig bus writes a testhook credential. Only plain words reach the client. ctl-bridge-test.sh covers the pieces, single use of the args, the word filter, ok:false, no reply and no client, now also under busybox sh in CI; test_qmp_drive.py covers the verb's ok, fail and fatal rows. Refs flare-edge #2054. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
184 lines
7.5 KiB
Bash
Executable File
184 lines
7.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Host test for the rig's control bridge, warden_ctl_bridge in
|
|
# qemu/rootfs/etc/warden-lib.sh (flare-edge #1448). A fake warden-ui reads
|
|
# the FIFO and renames each reply into place, as warden_debug.c does; some
|
|
# commands answer late. Checks: a reply slower than the old 5 s bound still
|
|
# arrives, a timeout answers the explicit no-reply line, and the late reply
|
|
# of a timed-out command is never handed to the next command. A fake hook
|
|
# client stands in for wthctl behind `@hookdoc` / `@hook` (the test hook
|
|
# over the device bus, flare-edge #2054).
|
|
set -uo pipefail
|
|
# Job control: the fake UI leads its own process group, so one kill stops
|
|
# its pending sleep too.
|
|
set -m
|
|
|
|
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
LIB="$HERE/../rootfs/etc/warden-lib.sh"
|
|
# Unquoted where it runs: WARDEN_TEST_SH may be "busybox sh", the rig's shell.
|
|
SH="${WARDEN_TEST_SH:-sh}"
|
|
WORK="$(mktemp -d)" || exit 1
|
|
UI_PID=
|
|
stop_ui() {
|
|
[ -n "$UI_PID" ] || return 0
|
|
{ kill -KILL -- "-$UI_PID"; wait "$UI_PID"; } 2>/dev/null
|
|
UI_PID=
|
|
}
|
|
cleanup() {
|
|
stop_ui
|
|
rm -rf "$WORK"
|
|
}
|
|
trap cleanup EXIT
|
|
FAIL=0
|
|
CHECKS=0
|
|
|
|
check() { # check <label> <command...>
|
|
CHECKS=$((CHECKS + 1))
|
|
if "${@:2}"; then
|
|
echo "[PASS] $1"
|
|
else
|
|
echo "[FAIL] $1"
|
|
FAIL=1
|
|
fi
|
|
}
|
|
|
|
# The fake UI: "slowN" answers after N tenths of a second, anything else at
|
|
# once. Replies are "reply:<command>", written to a temp file and renamed.
|
|
start_ui() {
|
|
mkfifo "$WORK/ctl"
|
|
(
|
|
while :; do
|
|
IFS= read -r cmd < "$WORK/ctl" || continue
|
|
case "$cmd" in
|
|
slow*) sleep "$(awk -v t="${cmd#slow}" 'BEGIN { print t / 10 }')" ;;
|
|
esac
|
|
printf 'reply:%s\n' "$cmd" > "$WORK/dbg.tmp"
|
|
mv "$WORK/dbg.tmp" "$WORK/dbg"
|
|
done
|
|
) &
|
|
UI_PID=$!
|
|
}
|
|
|
|
run_bridge() { # run_bridge <name> <wait s or ""> <lines...>
|
|
local name="$1" wait="$2"
|
|
shift 2
|
|
# $SH unquoted (it may be "busybox sh"); the quoted script is meant literally.
|
|
# shellcheck disable=SC2086,SC2016
|
|
printf '%s\n' "$@" |
|
|
env WARDEN_CTL_FIFO="$WORK/ctl" WARDEN_CTL_REPLY="$WORK/dbg" \
|
|
${wait:+WARDEN_CTL_WAIT_S="$wait"} \
|
|
$SH -c '. "$1"; warden_ctl_bridge' sh "$LIB" > "$WORK/$name.out" 2> "$WORK/$name.err"
|
|
}
|
|
|
|
same() { # same <file> <expected lines...>
|
|
local file="$1"
|
|
shift
|
|
diff <(printf '%s\n' "$@") "$file" > "$WORK/diff" || { cat "$WORK/diff"; return 1; }
|
|
}
|
|
|
|
start_ui
|
|
|
|
# A 1 s bound, a 1.5 s reply: the explicit no-reply line, then the next
|
|
# command gets ITS reply, not the late one (the desync behind #1448).
|
|
run_bridge timeout 1 fast1 slow15 fast2
|
|
check "timeout answers no-reply; the late reply is not the next answer" \
|
|
same "$WORK/timeout.out" reply:fast1 '<<END>>' \
|
|
'bridge: no reply from warden-ui within 1 s: slow15' '<<END>>' \
|
|
reply:fast2 '<<END>>'
|
|
|
|
# The default bound: a 6 s reply (over the old 5 s) still arrives, and the
|
|
# console note gives its time.
|
|
run_bridge slow "" slow60 after
|
|
check "default bound: a 6 s reply arrives" \
|
|
same "$WORK/slow.out" reply:slow60 '<<END>>' reply:after '<<END>>'
|
|
check "slow reply logged on stderr" grep -Eq "^ctl bridge: slow reply, [5-7] s of polling: slow60\$" "$WORK/slow.err"
|
|
check "fast reply not logged" bash -c "! grep -q after '$WORK/slow.err'"
|
|
|
|
# @cat is answered by the bridge itself, with a newline after the file.
|
|
printf '{"a":1}' > "$WORK/status.json"
|
|
run_bridge cat 1 "@cat $WORK/status.json" "@cat $WORK/missing"
|
|
check "@cat answers the file and a missing-file line" \
|
|
same "$WORK/cat.out" '{"a":1}' '<<END>>' "bridge: no such file: $WORK/missing" '<<END>>'
|
|
|
|
# No FIFO: one line, no wait.
|
|
stop_ui
|
|
rm -f "$WORK/ctl"
|
|
run_bridge nofifo 1 page
|
|
check "missing FIFO answers at once" \
|
|
same "$WORK/nofifo.out" 'bridge: warden-ui control FIFO not present' '<<END>>'
|
|
|
|
# @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
|
|
|
|
# @hookdoc / @hookdoc+ / @hook: the fake client logs its argv one per line
|
|
# and answers by verb (ok:true, ok:false with exit 1, or no reply, exit 2).
|
|
cat > "$WORK/wthctl" <<'FAKE'
|
|
#!/bin/sh
|
|
log="$(dirname "$0")/hook.log"
|
|
printf '%s\n' "$@" "--" >> "$log"
|
|
for last; do :; done
|
|
case "$*" in
|
|
*" refuse "*) echo '{"v":1,"ok":false,"err":{"code":"E_NOT_FOUND"}}'; exit 1 ;;
|
|
*" silent "*) echo "wthctl: no reply (-3)" >&2; exit 2 ;;
|
|
esac
|
|
printf '{"v":1,"ok":true,"data":{"args":%s}}\n' "$last"
|
|
FAKE
|
|
chmod +x "$WORK/wthctl"
|
|
run_hook() { # run_hook <name> <client> <lines...>
|
|
local name="$1" client="$2"
|
|
shift 2
|
|
rm -f "$WORK/hook.log" "$WORK/hook.args"
|
|
# $SH unquoted (it may be "busybox sh"); the quoted script is meant literally.
|
|
# shellcheck disable=SC2086,SC2016
|
|
printf '%s\n' "$@" |
|
|
env WARDEN_CTL_FIFO="$WORK/ctl" WARDEN_CTL_REPLY="$WORK/dbg" WARDEN_CTL_WAIT_S=1 \
|
|
WARDEN_CTL_HOOKDOC="$WORK/hook.args" WARDEN_WTHCTL="$client" WARDEN_BUS_RUN="$WORK/bus" \
|
|
$SH -c '. "$1"; warden_ctl_bridge' sh "$LIB" > "$WORK/$name.out" 2> "$WORK/$name.err"
|
|
}
|
|
|
|
run_hook pieces "$WORK/wthctl" '@hookdoc {"topic":"io/state/x",' '@hookdoc+ "doc":{"why":"two words"}}' \
|
|
'@hook override' '@hook override'
|
|
check "@hookdoc pieces join into one request; the args are used once" \
|
|
same "$WORK/pieces.out" 'hookdoc: 22 bytes' '<<END>>' 'hookdoc: 49 bytes' '<<END>>' \
|
|
'{"v":1,"ok":true,"data":{"args":{"topic":"io/state/x","doc":{"why":"two words"}}}}' '<<END>>' \
|
|
'{"v":1,"ok":true,"data":{"args":{}}}' '<<END>>'
|
|
check "the client gets the bus socket, the testhook credential, the verb and the args" \
|
|
same "$WORK/hook.log" "$WORK/bus/bus.sock" "$WORK/bus/cred/testhook" override \
|
|
'{"topic":"io/state/x","doc":{"why":"two words"}}' -- \
|
|
"$WORK/bus/bus.sock" "$WORK/bus/cred/testhook" override '{}' --
|
|
|
|
run_hook words "$WORK/wthctl" '@hook --to flared guard_evidence' '@hook override;touch x' \
|
|
'@hook ov*' '@hook ' '@hookdoc+ {}'
|
|
check "client words pass one by one; a word with other characters is refused" \
|
|
same "$WORK/words.out" '{"v":1,"ok":true,"data":{"args":{}}}' '<<END>>' \
|
|
'bridge: bad hook request: override;touch x' '<<END>>' 'bridge: bad hook request: ov*' '<<END>>' \
|
|
'bridge: bad hook request: ' '<<END>>' \
|
|
'bridge: @hookdoc+ without a @hookdoc before it' '<<END>>'
|
|
check "the refused words never ran the client" \
|
|
same "$WORK/hook.log" "$WORK/bus/bus.sock" "$WORK/bus/cred/testhook" --to flared guard_evidence '{}' --
|
|
|
|
run_hook answers "$WORK/wthctl" '@hook refuse' '@hook silent'
|
|
check "ok:false is the hook's answer; no reply is a bridge line" \
|
|
same "$WORK/answers.out" '{"v":1,"ok":false,"err":{"code":"E_NOT_FOUND"}}' '<<END>>' \
|
|
'bridge: hook request got no answer (client exit 2): wthctl: no reply (-3)' '<<END>>'
|
|
|
|
run_hook noclient "$WORK/absent" '@hookdoc {}' '@hook override' '@hook override'
|
|
check "no client in the payload answers a bridge line and drops the args" \
|
|
same "$WORK/noclient.out" 'hookdoc: 2 bytes' '<<END>>' \
|
|
"bridge: no hook client in the payload ($WORK/absent)" '<<END>>' \
|
|
"bridge: no hook client in the payload ($WORK/absent)" '<<END>>'
|
|
check "the args file is gone after a request" test ! -e "$WORK/hook.args"
|
|
|
|
if [ "$FAIL" = 0 ]; then
|
|
echo "ctl-bridge tests: OK ($CHECKS checks)"
|
|
else
|
|
echo "ctl-bridge tests: FAILED"
|
|
exit 1
|
|
fi
|