Files
lightgui/tests/debugger_tests.sh
cnmcdee e6678e13b8 Debugger: fix Step Out in main, Stop on GUI apps, Run target switch, temp main bp persistence
(c) step_out() refused in the outermost frame instead of sending
    -exec-finish: new can_step_out() (frames>1, fallback on the stop
    frame level); the UI now shows a status-line note, no modal.
(d) gdb runs in synchronous mode by default, so -exec-interrupt sat
    unread while the target ran: enable mi-async at spawn, and
    interrupt() falls back to SIGINT then SIGSTOP on the inferior pid.
    Interrupt of a target in gtk_main now lands in ~0.1s (was a 5s
    timeout, timed out waiting for gdb reply).
(e) new restart_or_start(exe, args): same target restarts, a changed
    Target/Args kills the old target (via gdb kill, so it is reaped
    at once) and starts the new one. kill_target() uses gdb kill as
    primary; raw SIGKILL left a dead-but-unreaped inferior that made
    -file-exec-and-symbols fail. Failed breakpoint re-applies stay
    staged (id 0) so they come back when switching back.
(f) break-on-main breakpoint is now marked temporary: never written
    to debugger_bps.conf, never duplicated on the next session, and
    load dedupes stale duplicate main lines. add_breakpoint and the
    refresh merge preserve the temporary flag.
Tests: harness 37-41 console (step_out refused, can_step_out in a
call, break-on-main not persisted, restart_or_start switches target,
interrupt stops a running target) + gtkspin target and GTK test 37
(interrupt_gtkapp_in_gtk_main). Console 42/42, GTK 8/8.
2026-12-02 10:46:12 +00:00

143 lines
6.1 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"
cp "$D/gtkspin.cpp" "$WORK/gtkspin.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
# gtkspin: GTK app that sits in gtk_main forever (no quit timer), for the
# Stop/interrupt tests — gtkapp quits on its own after 4 s.
g++ -g -O0 -o "$WORK/gtkspin" "$WORK/gtkspin.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