Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07db1b9ec0 | ||
|
|
eb0691d84f | ||
|
|
4636f0fe4c | ||
|
|
fe29ece741 | ||
|
|
b30621e372 | ||
|
|
0cf46ba1a4 |
@@ -148,6 +148,8 @@ jobs:
|
||||
# on the debug channel. All offline (a stub qemu-system-arm on
|
||||
# PATH), so it runs on every push/PR, not only a real boot.
|
||||
run: bash qemu/tests/run-sh-args-test.sh
|
||||
- name: rig init honours reboot/poweroff/halt (#5)
|
||||
run: bash qemu/tests/init-power-signals-test.sh
|
||||
- name: mkimage.sh SEED_DIR regression test
|
||||
# Only ui-drive.sh --seed (a real VM boot) exercises this hook
|
||||
# otherwise; this builds the same unprivileged mkfs.ext4 image and
|
||||
@@ -340,10 +342,16 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: install analyzers
|
||||
# The job image's Python is PEP 668 "externally managed", so a plain
|
||||
# pip install is refused. GitHub's hosted runners set this same
|
||||
# variable; here every job runs in a throwaway container on a
|
||||
# throwaway VM (the GARM runners), so nothing outlives the job.
|
||||
env:
|
||||
PIP_BREAK_SYSTEM_PACKAGES: "1"
|
||||
run: |
|
||||
sudo apt-get update -qq && sudo apt-get install -y -qq cppcheck shellcheck
|
||||
pip install --quiet lizard ruff
|
||||
sudo npm install --silent -g jscpd
|
||||
sudo env "PATH=$PATH" npm install --silent -g jscpd
|
||||
curl -fsSL -o /tmp/scc.tar.gz \
|
||||
https://github.com/boyter/scc/releases/download/v3.6.0/scc_Linux_x86_64.tar.gz
|
||||
sudo tar -C /usr/local/bin -xzf /tmp/scc.tar.gz scc
|
||||
|
||||
@@ -66,7 +66,7 @@ tree_path() {
|
||||
}
|
||||
|
||||
rc=0
|
||||
while IFS=$'\t' read -r name url commit desc; do
|
||||
while IFS=$'\t' read -r name url commit _desc; do
|
||||
case "$name" in ''|\#*) continue ;; esac
|
||||
path="$(tree_path "$name")"
|
||||
|
||||
|
||||
+3
-3
@@ -52,8 +52,8 @@ while [ $# -gt 0 ]; do
|
||||
esac
|
||||
done
|
||||
|
||||
[ -n "$KERNEL" ] && [ -f "$KERNEL" ] || { echo "FATAL: --kernel: no such file" >&2; exit 1; }
|
||||
[ -n "$DTB" ] && [ -f "$DTB" ] || { echo "FATAL: --dtb: no such file" >&2; exit 1; }
|
||||
{ [ -n "$KERNEL" ] && [ -f "$KERNEL" ]; } || { echo "FATAL: --kernel: no such file" >&2; exit 1; }
|
||||
{ [ -n "$DTB" ] && [ -f "$DTB" ]; } || { echo "FATAL: --dtb: no such file" >&2; exit 1; }
|
||||
[ -n "$OUT" ] || { echo "FATAL: --out is required" >&2; exit 1; }
|
||||
command -v mkimage >/dev/null || {
|
||||
echo "FATAL: mkimage not on PATH (Debian/Ubuntu: u-boot-tools)" >&2; exit 1; }
|
||||
@@ -76,7 +76,7 @@ if [ -z "$RTOOL" ]; then
|
||||
[ -x "$c" ] && { RTOOL="$c"; break; }
|
||||
done
|
||||
fi
|
||||
[ -n "$RTOOL" ] && [ -x "$RTOOL" ] || {
|
||||
{ [ -n "$RTOOL" ] && [ -x "$RTOOL" ]; } || {
|
||||
echo "FATAL: resource_tool not found; pass --resource-tool PATH" >&2; exit 1; }
|
||||
|
||||
WORKDIR="$(mktemp -d)"
|
||||
|
||||
@@ -41,3 +41,24 @@ warden_slot() {
|
||||
esac
|
||||
echo "$slot"
|
||||
}
|
||||
|
||||
# PID 1 must answer busybox's reboot/poweroff/halt itself: they only signal
|
||||
# PID 1 (TERM, USR2, USR1), and the kernel drops any signal PID 1 has no
|
||||
# handler for. A panel's busybox init handles them; without this the rig
|
||||
# ignored a plain `reboot` (bfe-core1106-sdk#5). The -f forms skip init, and
|
||||
# the kernel still prints its orderly "reboot: Restarting system" line.
|
||||
# WARDEN_REBOOT_CMD / WARDEN_POWEROFF_CMD exist for the host test only.
|
||||
warden_trap_power_signals() {
|
||||
trap 'echo "init: reboot requested"; sync; ${WARDEN_REBOOT_CMD:-reboot -f}' TERM
|
||||
trap 'echo "init: poweroff requested"; sync; ${WARDEN_POWEROFF_CMD:-poweroff -f}' USR2
|
||||
trap 'echo "init: halt requested"; sync; ${WARDEN_POWEROFF_CMD:-poweroff -f}' USR1
|
||||
}
|
||||
|
||||
# Idle forever in a way a trapped signal interrupts at once: a foreground
|
||||
# `sleep` would hold the trap until it returned, up to an hour later.
|
||||
warden_idle_forever() {
|
||||
while :; do
|
||||
sleep 3600 &
|
||||
wait $!
|
||||
done
|
||||
}
|
||||
|
||||
@@ -239,5 +239,7 @@ if grep -qw warden.shell /proc/cmdline; then
|
||||
poweroff -f
|
||||
fi
|
||||
|
||||
# Hold: daemons run, console idles, scenarios drive the VM from outside.
|
||||
while :; do sleep 3600; done
|
||||
# Hold: daemons run, console idles, scenarios drive the VM from outside. As
|
||||
# PID 1 this shell must honour reboot/poweroff/halt itself (#5).
|
||||
warden_trap_power_signals
|
||||
warden_idle_forever
|
||||
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regression test for bfe-core1106-sdk#5: the rig's PID 1 script ignored
|
||||
# busybox reboot/poweroff/halt, which only signal PID 1. Runs the real
|
||||
# helpers from qemu/rootfs/etc/warden-lib.sh in a plain sh with stub
|
||||
# commands, idles it the way /sbin/init does, sends each signal and requires
|
||||
# the matching action within two seconds.
|
||||
set -uo pipefail
|
||||
# Job control: each case's shell leads its own process group, so cleanup can
|
||||
# kill the whole group. An orphaned `sleep 3600` would otherwise keep this
|
||||
# script's output pipe open for an hour when a case fails.
|
||||
set -m
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
LIB="$HERE/../rootfs/etc/warden-lib.sh"
|
||||
SH="${WARDEN_TEST_SH:-sh}"
|
||||
WORK="$(mktemp -d)" || exit 1
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
FAIL=0
|
||||
|
||||
run_case() { # run_case <signal> <expected marker> <label>
|
||||
local sig="$1" want="$2" label="$3" out="$WORK/$1.out"
|
||||
: > "$out"
|
||||
WARDEN_REBOOT_CMD="eval echo reboot >> $out; exit 0" \
|
||||
WARDEN_POWEROFF_CMD="eval echo poweroff >> $out; exit 0" \
|
||||
"$SH" -c ". '$LIB'; warden_trap_power_signals; warden_idle_forever" &
|
||||
local pid=$!
|
||||
sleep 0.5
|
||||
kill -"$sig" "$pid"
|
||||
local n=0
|
||||
while ! grep -qx "$want" "$out" && [ "$n" -lt 20 ]; do
|
||||
sleep 0.1; n=$((n + 1))
|
||||
done
|
||||
if grep -qx "$want" "$out"; then
|
||||
echo "[PASS] $label"
|
||||
else
|
||||
echo "[FAIL] $label (got: $(tr '\n' ' ' < "$out"))"; FAIL=1
|
||||
fi
|
||||
kill -KILL -- "-$pid" 2>/dev/null
|
||||
wait "$pid" 2>/dev/null
|
||||
}
|
||||
|
||||
run_case TERM reboot "SIGTERM (busybox reboot) reboots at once"
|
||||
run_case USR2 poweroff "SIGUSR2 (busybox poweroff) powers off at once"
|
||||
run_case USR1 poweroff "SIGUSR1 (busybox halt) powers off at once"
|
||||
|
||||
exit "$FAIL"
|
||||
@@ -98,15 +98,21 @@ printf '#!/usr/bin/env python3\nimport sys; sys.exit(1)\n' > "$FLARE_EDGE/tools/
|
||||
# without a subshell: run_rig's RIG_OUT/RIG_RC writes land here directly, so
|
||||
# nothing needs to be re-serialized as text and re-parsed back out below.
|
||||
FLARE_EDGE="$FLARE_EDGE" TEST_MAKE_RS_SOCK='' run_rig "$work"
|
||||
[ "$RIG_RC" -ne 0 ] \
|
||||
&& pass "case A: never-appeared rs.sock fails the run (rc=$RIG_RC)" \
|
||||
|| fail "case A: never-appeared rs.sock fails the run: rc=$RIG_RC, out: $RIG_OUT"
|
||||
printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 bus socket never appeared' \
|
||||
&& pass "case A: FATAL names the missing rs.sock" \
|
||||
|| fail "case A: FATAL names the missing rs.sock: $RIG_OUT"
|
||||
printf '%s\n' "$RIG_OUT" | grep -qF '== rs485 simulator:' \
|
||||
&& fail "case A: printed the rs485-live success line over a bus that was never up: $RIG_OUT" \
|
||||
|| pass "case A: never claims the bus is live"
|
||||
if [ "$RIG_RC" -ne 0 ]; then
|
||||
pass "case A: never-appeared rs.sock fails the run (rc=$RIG_RC)"
|
||||
else
|
||||
fail "case A: never-appeared rs.sock fails the run: rc=$RIG_RC, out: $RIG_OUT"
|
||||
fi
|
||||
if printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 bus socket never appeared'; then
|
||||
pass "case A: FATAL names the missing rs.sock"
|
||||
else
|
||||
fail "case A: FATAL names the missing rs.sock: $RIG_OUT"
|
||||
fi
|
||||
if printf '%s\n' "$RIG_OUT" | grep -qF '== rs485 simulator:'; then
|
||||
fail "case A: printed the rs485-live success line over a bus that was never up: $RIG_OUT"
|
||||
else
|
||||
pass "case A: never claims the bus is live"
|
||||
fi
|
||||
|
||||
# --- case B: rs.sock is up but socat never creates rs.pty -------------------
|
||||
work="$SCRATCH/b"; build_rig "$work"
|
||||
@@ -117,12 +123,16 @@ FAKEBIN="$SCRATCH/fakebin-b"; mkdir -p "$FAKEBIN"
|
||||
printf '#!/usr/bin/env bash\necho "FAKE SOCAT: simulated failure" >&2\nexit 1\n' > "$FAKEBIN/socat"
|
||||
chmod +x "$FAKEBIN/socat"
|
||||
FLARE_EDGE="$FLARE_EDGE" TEST_MAKE_RS_SOCK=1 PATH="$FAKEBIN:$PATH" run_rig "$work"
|
||||
[ "$RIG_RC" -ne 0 ] \
|
||||
&& pass "case B: socat never linking rs.pty fails the run (rc=$RIG_RC)" \
|
||||
|| fail "case B: socat never linking rs.pty fails the run: rc=$RIG_RC, out: $RIG_OUT"
|
||||
printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 socat never created rs.pty' \
|
||||
&& pass "case B: FATAL names the missing rs.pty" \
|
||||
|| fail "case B: FATAL names the missing rs.pty: $RIG_OUT"
|
||||
if [ "$RIG_RC" -ne 0 ]; then
|
||||
pass "case B: socat never linking rs.pty fails the run (rc=$RIG_RC)"
|
||||
else
|
||||
fail "case B: socat never linking rs.pty fails the run: rc=$RIG_RC, out: $RIG_OUT"
|
||||
fi
|
||||
if printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 socat never created rs.pty'; then
|
||||
pass "case B: FATAL names the missing rs.pty"
|
||||
else
|
||||
fail "case B: FATAL names the missing rs.pty: $RIG_OUT"
|
||||
fi
|
||||
|
||||
# --- case C: rs.sock+rs.pty are up but mbsim.py crashes before rs.ctl -------
|
||||
work="$SCRATCH/c"; build_rig "$work"
|
||||
@@ -135,15 +145,21 @@ sys.stderr.write("FAKE MBSIM: simulated crash before opening the control socket\
|
||||
sys.exit(1)
|
||||
EOS
|
||||
FLARE_EDGE="$FLARE_EDGE" TEST_MAKE_RS_SOCK=1 TEST_MBSIM_PID_FILE='' run_rig "$work"
|
||||
[ "$RIG_RC" -ne 0 ] \
|
||||
&& pass "case C: mbsim.py crashing before rs.ctl fails the run (rc=$RIG_RC)" \
|
||||
|| fail "case C: mbsim.py crashing before rs.ctl fails the run: rc=$RIG_RC, out: $RIG_OUT"
|
||||
printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 simulator (mbsim.py) never came up' \
|
||||
&& pass "case C: FATAL names the dead simulator" \
|
||||
|| fail "case C: FATAL names the dead simulator: $RIG_OUT"
|
||||
printf '%s\n' "$RIG_OUT" | grep -qF 'FAKE MBSIM: simulated crash' \
|
||||
&& pass "case C: mbsim.log is dumped on failure" \
|
||||
|| fail "case C: mbsim.log is dumped on failure: $RIG_OUT"
|
||||
if [ "$RIG_RC" -ne 0 ]; then
|
||||
pass "case C: mbsim.py crashing before rs.ctl fails the run (rc=$RIG_RC)"
|
||||
else
|
||||
fail "case C: mbsim.py crashing before rs.ctl fails the run: rc=$RIG_RC, out: $RIG_OUT"
|
||||
fi
|
||||
if printf '%s\n' "$RIG_OUT" | grep -qF 'FATAL: rs485 simulator (mbsim.py) never came up'; then
|
||||
pass "case C: FATAL names the dead simulator"
|
||||
else
|
||||
fail "case C: FATAL names the dead simulator: $RIG_OUT"
|
||||
fi
|
||||
if printf '%s\n' "$RIG_OUT" | grep -qF 'FAKE MBSIM: simulated crash'; then
|
||||
pass "case C: mbsim.log is dumped on failure"
|
||||
else
|
||||
fail "case C: mbsim.log is dumped on failure: $RIG_OUT"
|
||||
fi
|
||||
|
||||
# --- case D: a sim process that ignores SIGTERM is still reaped ------------
|
||||
work="$SCRATCH/d"; build_rig "$work"
|
||||
|
||||
@@ -195,7 +195,7 @@ if [ -n "$RS485_DEVICES" ]; then
|
||||
# simulator the serial device it expects; mbsim then answers the guest's
|
||||
# Modbus polls with the corpus profiles' own register maps.
|
||||
command -v socat >/dev/null || { echo "FATAL: --rs485-devices needs socat" >&2; exit 1; }
|
||||
[ -n "${FLARE_EDGE:-}" ] && [ -f "$FLARE_EDGE/tools/modbus-sim/mbsim.py" ] || {
|
||||
{ [ -n "${FLARE_EDGE:-}" ] && [ -f "$FLARE_EDGE/tools/modbus-sim/mbsim.py" ]; } || {
|
||||
echo "FATAL: --rs485-devices needs FLARE_EDGE to point at a flare-edge checkout (mbsim.py)" >&2; exit 1; }
|
||||
wait_for_path "$WORK/rs.sock"
|
||||
[ -S "$WORK/rs.sock" ] || {
|
||||
|
||||
Reference in New Issue
Block a user