summaryrefslogtreecommitdiff
path: root/src/debug_smoke_test.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/debug_smoke_test.sh')
-rwxr-xr-xsrc/debug_smoke_test.sh82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/debug_smoke_test.sh b/src/debug_smoke_test.sh
new file mode 100755
index 0000000..1d2ba0e
--- /dev/null
+++ b/src/debug_smoke_test.sh
@@ -0,0 +1,82 @@
+#!/bin/sh
+# Fast pre-commit smoke test: run a DEBUG=1 build over a random sample of
+# positions from the full 881-position tests/ecm.ep_ suite at a shallow
+# fixed depth, to catch assertion failures without paying full bench-depth
+# DEBUG overhead. Variety (many distinct positions) matters more here than
+# depth or suite curation -- each position starts with fresh killer/history
+# state and a different piece mix, exercising more distinct code paths per
+# second than grinding one position deeper or reusing the same fixed
+# curated suite every run. Sampling fresh positions each run (rather than a
+# fixed suite) also means repeated runs build up coverage over time instead
+# of exercising the exact same 11-90 positions forever.
+#
+# Usage: ./debug_smoke_test.sh [path-to-DEBUG-binary] [depth] [count]
+# Defaults: ./_typhoon, sd 4, 10 positions
+
+BIN="${1:-./_typhoon}"
+DEPTH="${2:-4}"
+COUNT="${3:-10}"
+SUITE=../tests/ecm.ep_
+LOGDIR=/tmp/typhoon/smoke_test
+mkdir -p "$LOGDIR"
+
+if [ ! -x "$BIN" ]; then
+ echo "ERROR: $BIN not found or not executable (build with DEBUG=1 first)"
+ exit 1
+fi
+
+if [ ! -f "$SUITE" ]; then
+ echo "ERROR: $SUITE not found (run from src/)"
+ exit 1
+fi
+
+# ecm.ep_ is NOT a clean fixed-lines-per-problem file (3517 lines / 881
+# problems is not an integer -- some records vary in length), so sample
+# whole setboard..go records, not individual lines, or a random line
+# offset shreds problems into garbled fragments (silently: the engine's
+# script command just reports "total problems: 0" rather than erroring).
+SAMPLE="$LOGDIR/sample.ep_"
+awk -v k="$COUNT" '
+BEGIN { srand() }
+{ sub(/\r$/, "") }
+/^setboard/ { rec = $0; next }
+/^go[ \t]*$/ { rec = rec "\n" $0; n++; recs[n] = rec; rec = ""; next }
+rec != "" { rec = rec "\n" $0 }
+END {
+ if (k > n) k = n
+ picked = 0
+ while (picked < k) {
+ r = int(rand() * n) + 1
+ if (!(r in used)) {
+ used[r] = 1
+ print recs[r]
+ picked++
+ }
+ }
+}' "$SUITE" > "$SAMPLE"
+
+STAMP=$(date +%Y%m%d_%H%M%S)
+LOG="$LOGDIR/sample_${STAMP}.log"
+OUT="$LOGDIR/sample_${STAMP}.out"
+SAMPLE_SAVED="$LOGDIR/sample_${STAMP}.ep_"
+cp "$SAMPLE" "$SAMPLE_SAVED"
+
+echo "=== $COUNT random positions from $SUITE (sd $DEPTH) ==="
+echo " FENs chosen (reproduce a failure with: script $SAMPLE_SAVED):"
+grep '^setboard' "$SAMPLE_SAVED" | sed 's/^setboard / /'
+
+START=$(date +%s)
+"$BIN" --cpus 1 --hash 64m --logfile "$LOG" \
+ --batch --command "force; book name /nonexistent.book.bin; sd $DEPTH; script $SAMPLE" \
+ > "$OUT" 2>&1
+STATUS=$?
+END=$(date +%s)
+echo " exit=$STATUS elapsed=$((END - START))s"
+
+if [ "$STATUS" -ne 0 ]; then
+ echo " *** ASSERTION OR CRASH DETECTED (exit=$STATUS) -- see $OUT / $LOG ***"
+ echo " positions tried (saved): $SAMPLE_SAVED"
+ echo "SMOKE TEST FAILED"
+ exit 1
+fi
+echo "SMOKE TEST PASSED"