blob: f1ce4e4b803cbe622613024129df84a7b497a36d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#!/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:-5}"
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 4 --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"
# Valgrind pass: catches memory errors (e.g. overlapping-buffer sprintf/
# memcpy, invalid reads/writes) that don't trip a DEBUG ASSERT but are
# still real bugs. Reuses the same sampled positions. --cpus 1 because
# valgrind + MP threading is slow and noisy for no real benefit here --
# this is checking memory safety, not search behavior. error-exitcode=99
# distinguishes "valgrind found a problem" from a normal engine exit.
if command -v valgrind >/dev/null 2>&1; then
VGLOG="$LOGDIR/valgrind_${STAMP}.log"
VGOUT="$LOGDIR/valgrind_${STAMP}.out"
echo "=== valgrind pass over the same $COUNT positions ==="
valgrind -s --leak-check=full --error-exitcode=99 --log-file="$VGLOG" \
"$BIN" --cpus 1 --hash 64m --logfile /dev/null \
--batch --command "force; book name /nonexistent.book.bin; sd $DEPTH; script $SAMPLE" \
> "$VGOUT" 2>&1
VGSTATUS=$?
if [ "$VGSTATUS" -eq 99 ]; then
echo " *** VALGRIND ERRORS DETECTED -- see $VGLOG ***"
echo "SMOKE TEST FAILED"
exit 1
fi
echo " valgrind: clean (see $VGLOG)"
else
echo " (valgrind not found on PATH, skipping memory-error pass)"
fi
echo "SMOKE TEST PASSED"
|