- 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.
139 lines
5.8 KiB
Bash
Executable File
139 lines
5.8 KiB
Bash
Executable File
#!/bin/sh
|
|
# LightGUI debugger test suite.
|
|
# tests/debugger_tests.sh [--no-gui]
|
|
# Builds the console + GTK test targets and the headless harness, runs the
|
|
# console suite, the GTK suite under Xvfb, and a GUI smoke test (the real
|
|
# lightgui opens its debugger window and the Settings dialog path is
|
|
# exercised through the Debug menu ids in ui/designer.ui).
|
|
# Prints a PASS/FAIL summary; exits non-zero if anything fails.
|
|
# Run from the repo root.
|
|
set -u
|
|
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
|
D="$ROOT/tests/debugger"
|
|
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 ----------------------------------------------------
|
|
say "== building debugger test targets =="
|
|
cp "$D/console.cpp" "$WORK/console.cpp"
|
|
cp "$D/spin.cpp" "$WORK/spin.cpp"
|
|
cp "$D/gtkapp.cpp" "$WORK/gtkapp.cpp"
|
|
# Compile from the work-dir paths so DWARF records the same absolute
|
|
# source paths the harness uses for file:line breakpoints.
|
|
g++ -g -O0 -o "$WORK/console" "$WORK/console.cpp" || FAIL=1
|
|
g++ -g -O0 -o "$WORK/spin" "$WORK/spin.cpp" || FAIL=1
|
|
g++ -g -O0 -o "$WORK/gtkapp" "$WORK/gtkapp.cpp" $(pkg-config --cflags --libs gtk+-3.0) || FAIL=1
|
|
g++ -O2 -Wall -Wextra -std=c++17 -o "$WORK/dbg_harness" "$D/dbg_harness.cpp" "$ROOT/src/debugger.cpp" || FAIL=1
|
|
# lightgui itself (with the debugger window) must build clean
|
|
(cd "$ROOT" && make >/tmp/dbg_make.log 2>&1) || { say "FAIL lightgui build"; cat /tmp/dbg_make.log; FAIL=1; }
|
|
|
|
if [ "$FAIL" != "0" ]; then say "BUILD FAILED"; exit 1; fi
|
|
|
|
# --- console suite ---------------------------------------------------------
|
|
say "== console debugger suite =="
|
|
"$WORK/dbg_harness" console "$WORK" > "$WORK/console.log" 2>&1
|
|
RC=$?
|
|
cat "$WORK/console.log"
|
|
[ "$RC" != "0" ] && FAIL=1
|
|
|
|
# --- GTK suite (needs X) ---------------------------------------------------
|
|
say "== GTK debugger suite (under Xvfb) =="
|
|
xvfb-run -a "$WORK/dbg_harness" gtk "$WORK" > "$WORK/gtk.log" 2>&1
|
|
RC=$?
|
|
cat "$WORK/gtk.log"
|
|
[ "$RC" != "0" ] && FAIL=1
|
|
|
|
# --- GUI smoke test --------------------------------------------------------
|
|
if [ "${1:-}" != "--no-gui" ]; then
|
|
say "== GUI smoke test: lightgui + debugger window =="
|
|
# Debug menu + Debugger sub-menu ids must exist in the .ui
|
|
for id in menu_debug mi_debug_open mi_dbg_settings mi_debug_settings \
|
|
menu_debugger_sub mi_dbg_break_main mi_dbg_stop_entry mi_dbg_pretty; do
|
|
grep -q "id=\"$id\"" "$ROOT/ui/designer.ui" || { say "FAIL ui missing id $id"; FAIL=1; }
|
|
done
|
|
say "ui menu ids present"
|
|
# Launch lightgui on a fixed Xvfb display with the debugger window
|
|
# auto-opened, then verify the window exists via xdotool.
|
|
Xvfb :99 -screen 0 1280x900x24 >/dev/null 2>&1 &
|
|
XVPID=$!
|
|
sleep 2
|
|
(cd "$ROOT" && DISPLAY=:99 LIGHTGUI_OPEN_DEBUGGER=1 timeout 25 ./lightgui >"$WORK/gui.log" 2>&1) &
|
|
APID=$!
|
|
OK=0
|
|
for i in $(seq 1 20); do
|
|
sleep 1
|
|
if DISPLAY=:99 xdotool search --name "LightGUI Debugger" >/dev/null 2>&1; then OK=1; break; fi
|
|
done
|
|
if [ "$OK" = "1" ]; then
|
|
DISPLAY=:99 xdotool search --name "LightGUI Debugger" getwindowname %@ 2>/dev/null | head -3
|
|
# Screenshot for the record (xwd if present, else skip gracefully).
|
|
if command -v xwd >/dev/null 2>&1; then
|
|
DISPLAY=:99 xwd -root -silent -out "$WORK/debugger_window.xwd" 2>/dev/null || true
|
|
fi
|
|
fi
|
|
kill $APID 2>/dev/null
|
|
pkill -x lightgui 2>/dev/null
|
|
wait $APID 2>/dev/null
|
|
if [ "$OK" = "1" ]; then say "PASS gui_debugger_window_opens"; else say "FAIL gui_debugger_window_opens"; cat "$WORK/gui.log"; FAIL=1; fi
|
|
# Settings dialog: launch with the settings hook and look for its window.
|
|
(cd "$ROOT" && DISPLAY=:99 LIGHTGUI_OPEN_DEBUGGER_SETTINGS=1 timeout 25 ./lightgui >"$WORK/gui_settings.log" 2>&1) &
|
|
APID=$!
|
|
OK2=0
|
|
for i in $(seq 1 20); do
|
|
sleep 1
|
|
if DISPLAY=:99 xdotool search --name "Debugger Settings" >/dev/null 2>&1; then OK2=1; break; fi
|
|
done
|
|
kill $APID 2>/dev/null
|
|
pkill -x lightgui 2>/dev/null
|
|
wait $APID 2>/dev/null
|
|
kill $XVPID 2>/dev/null
|
|
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
|