summaryrefslogtreecommitdiff
path: root/src/debug_smoke_test.sh
blob: d8ef2287ec1214adba06577186eebcae6e9d4623 (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
#!/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"