Skip to content

Commit 8397420

Browse files
author
miranov25
committed
Phase 13.11.DF v2.2: Add run_tests.sh, cleanup obsolete files
run_tests.sh: - Parallel unit tests + scan generation + validation - 3 configs: Gaussian uniform, Gaussian quantile, linear - Invariant checks on scan_summary.txt - Usage: bash run_tests.sh [--skip-generate] [N_ITER] Removed: obsolete debug/perf PNGs (regenerable via perf_figure_threshold.py)
1 parent 85b22ce commit 8397420

1 file changed

Lines changed: 182 additions & 0 deletions

File tree

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
#!/bin/bash
2+
# run_tests.sh — Phase 13.11.DF regression test suite
3+
# Runs unit tests + parallel scan generation + parallel validation
4+
# All outputs colocated: scan_<name>_<n>/ contains .root + figures + summary
5+
#
6+
# Usage:
7+
# bash run_tests.sh # full run, 100 iter
8+
# bash run_tests.sh --skip-generate # reuse existing .root files
9+
# bash run_tests.sh --skip-generate 1000 # validate existing 1000-iter files
10+
# bash run_tests.sh 1000 # full run, 1000 iter
11+
12+
set -e
13+
14+
# ── Parse args ─────────────────────────────────────────────────────
15+
SKIP_GEN=false
16+
N_ITER=100
17+
for arg in "$@"; do
18+
case $arg in
19+
--skip-generate) SKIP_GEN=true ;;
20+
[0-9]*) N_ITER=$arg ;;
21+
esac
22+
done
23+
24+
GIT_DESC=$(git describe --always --dirty 2>/dev/null || echo "unknown")
25+
26+
echo "======================================================================"
27+
echo "REGRESSION TEST SUITE — Phase 13.11.DF"
28+
echo "Git: $GIT_DESC"
29+
echo "Date: $(date -Iseconds)"
30+
echo "N_iter: $N_ITER"
31+
echo "======================================================================"
32+
33+
# ── Directories: scan + figures + summary colocated ────────────────
34+
DIR_GAUSS="scan_gauss_${N_ITER}"
35+
DIR_QUANT="scan_quantile_${N_ITER}"
36+
DIR_LINEAR="scan_linear_${N_ITER}"
37+
38+
mkdir -p "$DIR_GAUSS" "$DIR_QUANT" "$DIR_LINEAR"
39+
40+
# ── Step 1: Unit tests (fast, serial) ──────────────────────────────
41+
echo ""
42+
echo "=== [1/3] Unit tests ==="
43+
pytest tests/ -x -q --tb=short
44+
echo "Unit tests: PASSED"
45+
46+
# ── Step 2: Generate scan trees (parallel) ─────────────────────────
47+
if [[ "$SKIP_GEN" == false ]]; then
48+
echo ""
49+
echo "=== [2/3] Generating scan trees (parallel) ==="
50+
T0=$SECONDS
51+
52+
python generate_scan_tree.py \
53+
--mode uniform --distribution gaussian \
54+
--n_iter $N_ITER \
55+
--output "$DIR_GAUSS/scan.root" &
56+
PID_GAUSS=$!
57+
58+
python generate_scan_tree.py \
59+
--mode quantile --fit_coordinate bin \
60+
--nbins_min 20 --nbins_max 500 \
61+
--n_iter $N_ITER \
62+
--output "$DIR_QUANT/scan.root" &
63+
PID_QUANT=$!
64+
65+
python generate_scan_tree.py \
66+
--mode uniform --distribution linear \
67+
--n_iter $N_ITER \
68+
--output "$DIR_LINEAR/scan.root" &
69+
PID_LINEAR=$!
70+
71+
FAIL=0
72+
wait $PID_GAUSS || { echo "FAIL: Gaussian generation"; FAIL=1; }
73+
wait $PID_QUANT || { echo "FAIL: Quantile generation"; FAIL=1; }
74+
wait $PID_LINEAR || { echo "FAIL: Linear generation"; FAIL=1; }
75+
76+
if [[ $FAIL -ne 0 ]]; then
77+
echo "Generation FAILED — aborting."
78+
exit 1
79+
fi
80+
echo "Generation: $((SECONDS - T0))s (3 parallel jobs)"
81+
else
82+
echo ""
83+
echo "=== [2/3] Skipping generation (--skip-generate) ==="
84+
fi
85+
86+
# ── Step 3: Validate scan trees (parallel) ─────────────────────────
87+
echo ""
88+
echo "=== [3/3] Validating scan trees (parallel) ==="
89+
T0=$SECONDS
90+
91+
python validate_scan.py \
92+
--input "$DIR_GAUSS/scan.root" \
93+
--output "$DIR_GAUSS/" \
94+
> "$DIR_GAUSS/scan_summary.txt" 2>&1 &
95+
PID_V_GAUSS=$!
96+
97+
python validate_scan.py \
98+
--input "$DIR_QUANT/scan.root" \
99+
--output "$DIR_QUANT/" \
100+
> "$DIR_QUANT/scan_summary.txt" 2>&1 &
101+
PID_V_QUANT=$!
102+
103+
python validate_scan.py \
104+
--input "$DIR_LINEAR/scan.root" \
105+
--output "$DIR_LINEAR/" \
106+
> "$DIR_LINEAR/scan_summary.txt" 2>&1 &
107+
PID_V_LINEAR=$!
108+
109+
FAIL=0
110+
wait $PID_V_GAUSS || { echo "FAIL: Gaussian validation"; FAIL=1; }
111+
wait $PID_V_QUANT || { echo "FAIL: Quantile validation"; FAIL=1; }
112+
wait $PID_V_LINEAR || { echo "FAIL: Linear validation"; FAIL=1; }
113+
114+
echo "Validation: $((SECONDS - T0))s (3 parallel jobs)"
115+
116+
# ── Step 4: Invariant checks ──────────────────────────────────────
117+
echo ""
118+
echo "=== Invariant checks ==="
119+
FAIL=0
120+
121+
check_invariant() {
122+
local LABEL=$1
123+
local FILE=$2
124+
125+
if [[ ! -f "$FILE" ]]; then
126+
echo " FAIL: $LABEL — summary missing: $FILE"
127+
FAIL=1
128+
return
129+
fi
130+
131+
echo " --- $LABEL ---"
132+
133+
# Spectra ratio: expect ~1.0 ± 0.05
134+
local SPEC=$(grep "spectra" "$FILE" | grep "smooth_v5" | head -1)
135+
if [[ -n "$SPEC" ]]; then
136+
echo " $SPEC"
137+
else
138+
echo " WARNING: no v5 spectra line found"
139+
fi
140+
141+
# S4c slope: expect ~1.0 ± 0.15
142+
local S4C=$(grep "S4c.*global.*smooth_v5" "$FILE" | head -1)
143+
if [[ -n "$S4C" ]]; then
144+
echo " $S4C"
145+
fi
146+
147+
# Check for crashes (Python traceback)
148+
if grep -q "Traceback" "$FILE"; then
149+
echo " FAIL: Python traceback detected!"
150+
FAIL=1
151+
fi
152+
153+
# Check all figures saved
154+
local N_SAVED=$(grep -c "Saved:" "$FILE" || true)
155+
echo " Figures saved: $N_SAVED"
156+
if [[ $N_SAVED -lt 5 ]]; then
157+
echo " FAIL: too few figures ($N_SAVED < 5)"
158+
FAIL=1
159+
fi
160+
}
161+
162+
check_invariant "Gaussian uniform" "$DIR_GAUSS/scan_summary.txt"
163+
check_invariant "Gaussian quantile" "$DIR_QUANT/scan_summary.txt"
164+
check_invariant "Linear uniform" "$DIR_LINEAR/scan_summary.txt"
165+
166+
# ── Summary ────────────────────────────────────────────────────────
167+
echo ""
168+
echo "======================================================================"
169+
if [[ $FAIL -ne 0 ]]; then
170+
echo "RESULT: FAILED — see above"
171+
exit 1
172+
else
173+
echo "RESULT: ALL PASSED"
174+
fi
175+
echo "Git: $GIT_DESC"
176+
echo "Total time: ${SECONDS}s"
177+
echo ""
178+
echo "Output directories:"
179+
echo " $DIR_GAUSS/"
180+
echo " $DIR_QUANT/"
181+
echo " $DIR_LINEAR/"
182+
echo "======================================================================"

0 commit comments

Comments
 (0)