summaryrefslogtreecommitdiff
path: root/src/precommit_check.sh
blob: c2d7d41f07222796f409791161aca2f18a819797 (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
#!/bin/sh
# Pre-commit build/test gate: TEST=1 self-test suite + DEBUG=1 random-sample
# smoke test (debug_smoke_test.sh). Restores a normal release build
# afterward so the working directory isn't left with a TEST/DEBUG-flavored
# binary as a side effect of running this.
#
# NOT wired as an automatic git hook by default -- see CLAUDE.md's
# "Pre-commit testing" section for why (rebuild time, binary-clobbering
# risk if something else is using ./typhoon or ./_typhoon). Run by hand:
#   ./precommit_check.sh

cd "$(dirname "$0")" || exit 1
LOGDIR=/tmp/typhoon/precommit
mkdir -p "$LOGDIR"

FAIL=0
TOTAL_START=$(date +%s)

echo "=== [1/3] Self-test build (gmake TEST=1) ==="
STEP_START=$(date +%s)
gmake clean > "$LOGDIR/clean_test.log" 2>&1
gmake -j5 TEST=1 GENETIC=1 SIXTYFOUR=1 > "$LOGDIR/build_test.log" 2>&1
if [ $? -ne 0 ]; then
    echo "    BUILD FAILED -- see $LOGDIR/build_test.log"
    FAIL=1
else
    ./typhoon --batch --command "" > "$LOGDIR/test_run.log" 2>&1
    STATUS=$?
    if [ "$STATUS" -ne 0 ] || grep -qi "assertion failure" "$LOGDIR/test_run.log"; then
        echo "    SELF-TEST FAILED (exit=$STATUS) -- see $LOGDIR/test_run.log"
        FAIL=1
    else
        echo "    self-test passed"
    fi
fi
STEP_END=$(date +%s)
echo "    [$((STEP_END - STEP_START))s]"

echo "=== [2/3] DEBUG smoke test (10 random ECM positions, sd 4) ==="
STEP_START=$(date +%s)
gmake clean > "$LOGDIR/clean_debug.log" 2>&1
gmake -j5 GENETIC=1 DEBUG=1 MP=1 SIXTYFOUR=1 > "$LOGDIR/build_debug.log" 2>&1
if [ $? -ne 0 ]; then
    echo "    BUILD FAILED -- see $LOGDIR/build_debug.log"
    FAIL=1
else
    ./debug_smoke_test.sh ./_typhoon 4 10
    [ $? -ne 0 ] && FAIL=1
fi
STEP_END=$(date +%s)
echo "    [$((STEP_END - STEP_START))s]"

echo "=== [3/3] Restoring normal release build (GENETIC=1 PERF_COUNTERS=1 MP=1 SIXTYFOUR=1) ==="
STEP_START=$(date +%s)
gmake clean > "$LOGDIR/clean_release.log" 2>&1
gmake -j5 GENETIC=1 PERF_COUNTERS=1 MP=1 SIXTYFOUR=1 > "$LOGDIR/build_release.log" 2>&1
if [ $? -ne 0 ]; then
    echo "    BUILD FAILED -- see $LOGDIR/build_release.log"
    FAIL=1
fi
STEP_END=$(date +%s)
echo "    [$((STEP_END - STEP_START))s]"

TOTAL_END=$(date +%s)
echo
echo "Total: $((TOTAL_END - TOTAL_START))s"
if [ "$FAIL" -ne 0 ]; then
    echo "PRE-COMMIT CHECK FAILED"
    exit 1
fi
echo "PRE-COMMIT CHECK PASSED"
echo "git commit"
echo "./update_head_reference.sh"