@@ -145,6 +145,7 @@ source "$ROOT/scripts/path-safety.sh"
145145MAKE_ARGS=()
146146BUILD_DIR=" build/c"
147147SANITIZE_GIVEN=0
148+ SANITIZE_VALUE=" "
148149prev_arg=" "
149150for arg in " $@ " ; do
150151 case " $arg " in
@@ -154,7 +155,11 @@ for arg in "$@"; do
154155 --tsan) ;; # already handled
155156 --suites|--suites=* ) ;; # already handled (value skipped via prev_arg below)
156157 BUILD_DIR=* ) BUILD_DIR=" ${arg# BUILD_DIR=} " ; MAKE_ARGS+=(" $arg " ) ;;
157- SANITIZE=* ) SANITIZE_GIVEN=1; MAKE_ARGS+=(" $arg " ) ;;
158+ SANITIZE=* )
159+ SANITIZE_GIVEN=1
160+ SANITIZE_VALUE=" ${arg# SANITIZE=} "
161+ MAKE_ARGS+=(" $arg " )
162+ ;;
158163 * =* )
159164 if [[ " ${prev_arg:- } " != " --suites" ]]; then
160165 MAKE_ARGS+=(" $arg " ) # forward any VAR=VAL to make
@@ -174,6 +179,42 @@ if [ "$SANITIZE_GIVEN" -eq 0 ] && [ "${MSYSTEM:-}" = "CLANGARM64" ]; then
174179 MAKE_ARGS+=(" SANITIZE=-fsanitize=undefined -fsanitize-trap=undefined -fstack-protector-strong -fno-omit-frame-pointer" )
175180fi
176181
182+ EXPECTED_SANITIZED=1
183+ if [ " $SANITIZE_GIVEN " -eq 1 ]; then
184+ case " $SANITIZE_VALUE " in
185+ * [![:space:]]* ) EXPECTED_SANITIZED=1 ;;
186+ * ) EXPECTED_SANITIZED=0 ;;
187+ esac
188+ fi
189+
190+ # Refuse to run suites when the built runner disagrees with the lane that
191+ # produced it. Exact output keeps missing, duplicate, or future unhandled
192+ # fields fail-closed instead of silently weakening the gate.
193+ assert_test_runner_build_config () {
194+ local runner=" $1 "
195+ local expected_sanitized=" $2 "
196+ local expected=" sanitized=$expected_sanitized test_seams=1"
197+ local marker=" __cbm_build_config_end__"
198+ local captured=" "
199+ local actual=" "
200+ local probe_ok=0
201+
202+ if captured=" $( " $runner " --build-config && printf ' %s' " $marker " ) " ; then
203+ probe_ok=1
204+ actual=" ${captured% " $marker " } "
205+ else
206+ actual=" $captured "
207+ fi
208+ if [ " $probe_ok " -ne 1 ] || [ " $actual " != " $expected " $' \n ' ]; then
209+ local reported=" ${actual// $' \n ' / \\ n} "
210+ printf ' ERROR: build config mismatch for %s\n' " $runner " >&2
211+ printf ' expected: %s\n' " $expected " >&2
212+ printf ' reported: %s\n' " ${reported:- <empty>} " >&2
213+ printf ' %s\n' ' Refusing to run suites; check sanitizer flags and CBM_SANITIZED_BUILD wiring.' >&2
214+ return 1
215+ fi
216+ }
217+
177218print_env " test.sh"
178219
179220# ── TSan mode (--tsan): the data-race gate ──
@@ -182,6 +223,7 @@ print_env "test.sh"
182223if [ " $TSAN " -eq 1 ]; then
183224 echo " === test.sh: TSan leg (make test-tsan) ==="
184225 make -j" $NPROC " -f Makefile.cbm " $BUILD_DIR /test-runner-tsan" ${MAKE_ARGS[@]+" ${MAKE_ARGS[@]} " }
226+ assert_test_runner_build_config " $BUILD_DIR /test-runner-tsan" 1
185227 make -f Makefile.cbm test-tsan ${MAKE_ARGS[@]+" ${MAKE_ARGS[@]} " }
186228 exit " $? "
187229fi
192234if [ -n " $SUITES " ]; then
193235 echo " === test.sh: ITERATION mode — suites: $SUITES (incremental build) ==="
194236 make -j" $NPROC " -f Makefile.cbm " $BUILD_DIR /test-runner" ${MAKE_ARGS[@]+" ${MAKE_ARGS[@]} " }
237+ assert_test_runner_build_config " $BUILD_DIR /test-runner" " $EXPECTED_SANITIZED "
195238 # shellcheck disable=SC2086 # suite list is deliberately word-split
196239 " $BUILD_DIR /test-runner" $SUITES
197240 exit " $? "
@@ -307,6 +350,7 @@ BUILD_DIR="$BUILD_DIR" scripts/clean.sh
307350# pass/fail/skip totals aggregate to the same numbers as the sequential run).
308351# CBM_TEST_SEQUENTIAL=1 restores the single-process runner.
309352make -j" $NPROC " -f Makefile.cbm " $BUILD_DIR /test-runner" ${MAKE_ARGS[@]+" ${MAKE_ARGS[@]} " }
353+ assert_test_runner_build_config " $BUILD_DIR /test-runner" " $EXPECTED_SANITIZED "
310354if [ " ${CBM_TEST_SEQUENTIAL:- 0} " = " 1" ]; then
311355 make -f Makefile.cbm test ${MAKE_ARGS[@]+" ${MAKE_ARGS[@]} " }
312356else
0 commit comments