Tests: kill the spin test binary (and its gdb) on exit

- code_window_tests.sh and debugger_tests.sh launch a spin binary
  (loops forever for the step debugger) and never killed it; two
  spins were left at ~100% CPU each, 80+ minutes after their tests
  finished.
- kill_spin() (path-scoped to the test's own WORK/spin, via
  /proc/<pid>/exe, so an unrelated spin is never touched) kills the
  spin, waits for its gdb parent to exit, and kills the gdb if it
  lingers. Wired into kill_app() and the EXIT trap, plus a pre-test
  cleanup that kills stale spins from aborted runs.
- Verified: code_window_tests.sh run twice, ALL PASS both times, no
  spin/gdb/lightgui/Xvfb left afterwards; the 41-minute stale spin
  from the earlier run was cleaned up by the pre-test cleanup.
- debugger_tests.sh ALL PASS, no spin/gdb left.
This commit is contained in:
cnmcdee committed 2026-11-29 19:54:09 +00:00
1 parent 3f319d5a55
commit 0fae25f216
2 files changed
+79 -1

No files matched your search

+38 -1
View File
@@ -28,6 +28,42 @@ WORK="$ROOT/tests/codewin/work"
rm -rf "$WORK"
mkdir -p "$WORK/homeA" "$WORK/homeB" "$WORK/homeC"
# Kill the test's own `spin` binary (a program that loops forever so
# the step debugger has something to attach to) and its gdb parent if
# it lingers. Matched by executable path — never by bare name — so an
# unrelated process that happens to be named `spin` is never touched.
# The exe may show as "path (deleted)" when the work dir was rm -rf'd
# under a still-running process; strip that suffix before comparing.
kill_spin() {
_spin="${1:-$WORK/spin}"
for _p in $(pgrep -x spin 2>/dev/null); do
_exe=$(readlink "/proc/$_p/exe" 2>/dev/null || true)
_exe=${_exe% (deleted)}
[ "$_exe" = "$_spin" ] || continue
_gdb=$(ps -o ppid= -p "$_p" 2>/dev/null | tr -d ' ')
kill "$_p" 2>/dev/null
# Give gdb a moment to exit on its own once its child dies.
for _i in $(seq 1 10); do
kill -0 "$_p" 2>/dev/null || break
sleep 0.2
done
kill -0 "$_p" 2>/dev/null && kill -9 "$_p" 2>/dev/null
# If the gdb parent is still alive and is really gdb, kill it.
if [ -n "$_gdb" ] && [ "$_gdb" != "1" ]; then
_gcmd=$(ps -o comm= -p "$_gdb" 2>/dev/null || true)
if [ "$_gcmd" = "gdb" ]; then
kill "$_gdb" 2>/dev/null
sleep 1
kill -0 "$_gdb" 2>/dev/null && kill -9 "$_gdb" 2>/dev/null
fi
fi
done
}
# Pre-test cleanup: a leftover `spin` from an earlier aborted run would
# otherwise keep burning a core at ~100% forever.
kill_spin
say() { printf '%s\n' "$*"; }
pass() { say "PASS $1"; }
fail() { say "FAIL $1"; FAIL=1; }
@@ -92,6 +128,7 @@ kill_app() {
pkill -x lightgui 2>/dev/null
wait $APP 2>/dev/null
sleep 1
kill_spin
}
count_red() { # $1=png $2=x0 $3=x1 [$4=band] -> stdout count (+band line)
python3 "$ROOT/tests/codewin/count_red.py" "$1" "$2" "$3" "${4:-}"
@@ -126,7 +163,7 @@ kill -0 $XVPID 2>/dev/null || {
say "FAIL our Xvfb $XDISP died at startup (display taken?)"
exit 1
}
trap 'kill_app; kill $XVPID 2>/dev/null' EXIT
trap 'kill_app; kill_spin; kill $XVPID 2>/dev/null' EXIT
# === Run A: breakpoint in main ============================================
say "== Run A: breakpoint in main (prog.c:16) =="
+41
View File
@@ -14,6 +14,45 @@ WORK="$D/work"
mkdir -p "$WORK"
FAIL=0
# Kill the test's own `spin` binary (a program that loops forever so
# the step debugger has something to attach to) and its gdb parent if
# it lingers. Matched by executable path — never by bare name — so an
# unrelated process that happens to be named `spin` is never touched.
# The exe may show as "path (deleted)" when the work dir was rm -rf'd
# under a still-running process; strip that suffix before comparing.
kill_spin() {
_spin="${1:-$WORK/spin}"
for _p in $(pgrep -x spin 2>/dev/null); do
_exe=$(readlink "/proc/$_p/exe" 2>/dev/null || true)
_exe=${_exe% (deleted)}
[ "$_exe" = "$_spin" ] || continue
_gdb=$(ps -o ppid= -p "$_p" 2>/dev/null | tr -d ' ')
kill "$_p" 2>/dev/null
# Give gdb a moment to exit on its own once its child dies.
for _i in $(seq 1 10); do
kill -0 "$_p" 2>/dev/null || break
sleep 0.2
done
kill -0 "$_p" 2>/dev/null && kill -9 "$_p" 2>/dev/null
# If the gdb parent is still alive and is really gdb, kill it.
if [ -n "$_gdb" ] && [ "$_gdb" != "1" ]; then
_gcmd=$(ps -o comm= -p "$_gdb" 2>/dev/null || true)
if [ "$_gcmd" = "gdb" ]; then
kill "$_gdb" 2>/dev/null
sleep 1
kill -0 "$_gdb" 2>/dev/null && kill -9 "$_gdb" 2>/dev/null
fi
fi
done
}
# Pre-test cleanup: a leftover `spin` from an earlier aborted run would
# otherwise keep burning a core at ~100% forever.
kill_spin
# Cleanup on interrupt/timeout/failure too (the harness session API
# stops gdb on destruction, but a killed run can still leak spin).
trap 'kill_spin' EXIT
say() { printf '%s\n' "$*"; }
# --- build test targets ----------------------------------------------------
@@ -93,5 +132,7 @@ if [ "${1:-}" != "--no-gui" ]; then
if [ "$OK2" = "1" ]; then say "PASS gui_debugger_settings_dialog_opens"; else say "FAIL gui_debugger_settings_dialog_opens"; cat "$WORK/gui_settings.log"; FAIL=1; fi
fi
kill_spin
trap - EXIT
say "== debugger_tests.sh: $([ "$FAIL" = 0 ] && echo ALL PASS || echo FAILURES PRESENT) =="
exit $FAIL