Artifact 1a4485478c49e47fca6e31c9e06b45b10fd6540b328ad7cbc047901234ab6aff:
- Executable file
tools/test-native.sh
— part of check-in
[11f47eadde]
at
2026-11-18 11:58:22
on branch trunk
— Record S0/S1 qualification groundwork before product code
Contract maps and pinned Pi reference, local C qualification fixtures, MC/DC and Fil-C remote lifecycle tooling, and the context transaction substrate probe. No product harness code yet. (user: dmestas, size: 5933) [annotate] [blame] [check-ins using]
#!/bin/sh # S0 native qualification harness (test-only; no production runtime exists). # Modes: normal | sanitize | replay | fuzz # Every mode is bounded and runs in the foreground. Exit 0 pass, 1 fail, # 2 gated (a required tool is absent; never a silent pass). set -eu usage() { printf 'usage: %s [normal|sanitize|replay|fuzz]\n' "$0" >&2 exit 1 } MODE=${1:-normal} case "$MODE" in normal|sanitize|replay|fuzz) ;; *) usage ;; esac ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) QUAL="$ROOT/test/qualification" FUZZDIR="$ROOT/test/fuzz" OUT="$ROOT/build/qualification" CC=${CC:-cc} STD=${STD:--std=c11} WARN="-Wall -Wextra -Wpedantic -Werror -Wshadow -Wconversion -Wstrict-prototypes -Wmissing-prototypes -Wvla -Wcast-qual" CFLAGS=${CFLAGS:-"-O2 -g $STD $WARN"} SANFLAGS=${SANFLAGS:--fsanitize=address,undefined -fno-omit-frame-pointer -O1 -g $STD $WARN} LDFLAGS=${LDFLAGS:-} if [ "$MODE" != fuzz ] && ! command -v "$CC" >/dev/null 2>&1; then printf 'GATED: compiler not found: %s\n' "$CC" >&2 exit 2 fi compile() { # compile OUT SRC... (uses CFLAGS) out=$1 shift # Record the same expanded arguments used for compilation, not guessed defaults. # shellcheck disable=SC2086 printf '%s\n' "$CC" $CFLAGS $LDFLAGS "$@" -o "$out" > "$out.argv" # shellcheck disable=SC2086 "$CC" $CFLAGS $LDFLAGS "$@" -o "$out" } compile_san() { # compile_san OUT SRC... out=$1 shift # shellcheck disable=SC2086 printf '%s\n' "$CC" $SANFLAGS $LDFLAGS "$@" -o "$out" > "$out.argv" # shellcheck disable=SC2086 "$CC" $SANFLAGS $LDFLAGS "$@" -o "$out" } run_normal() { mkdir -p "$OUT/native" printf '== normal: compiler %s\n' "$("$CC" --version 2>/dev/null | head -n 1)" # shellcheck disable=SC2086 compile "$OUT/native/test_qualification" "$QUAL/fixture.c" "$QUAL/oracle.c" \ "$QUAL/test_qualification.c" # shellcheck disable=SC2086 compile "$OUT/native/test_oracle_mutant" "$QUAL/fixture.c" "$QUAL/oracle.c" \ "$QUAL/test_oracle_mutant.c" # shellcheck disable=SC2086 compile "$OUT/native/replay" "$QUAL/fixture.c" "$QUAL/oracle.c" "$QUAL/replay.c" "$OUT/native/test_qualification" "$OUT/native/test_oracle_mutant" printf 'normal: OK\n' } run_sanitize() { mkdir -p "$OUT/sanitize" printf '== sanitize: compiler %s\n' "$("$CC" --version 2>/dev/null | head -n 1)" printf 'sanitize: ASan+UBSan; leak detection NOT CLAIMED (unsupported on macOS)\n' # shellcheck disable=SC2086 compile_san "$OUT/sanitize/test_qualification" "$QUAL/fixture.c" "$QUAL/oracle.c" \ "$QUAL/test_qualification.c" # shellcheck disable=SC2086 compile_san "$OUT/sanitize/test_oracle_mutant" "$QUAL/fixture.c" "$QUAL/oracle.c" \ "$QUAL/test_oracle_mutant.c" ASAN_OPTIONS=${ASAN_OPTIONS:-detect_leaks=0:abort_on_error=1} UBSAN_OPTIONS=${UBSAN_OPTIONS:-halt_on_error=1:print_stacktrace=1} export ASAN_OPTIONS UBSAN_OPTIONS "$OUT/sanitize/test_qualification" "$OUT/sanitize/test_oracle_mutant" printf 'sanitize: OK (no ASan/UBSan report; leaks not asserted)\n' } run_replay() { mkdir -p "$OUT/native" # Always rebuild: invoking replay directly must not silently use an old oracle. compile "$OUT/native/replay" "$QUAL/fixture.c" "$QUAL/oracle.c" "$QUAL/replay.c" set -- "$FUZZDIR"/corpus/* if [ ! -e "$1" ]; then printf 'replay: GATED - no corpus files under %s\n' "$FUZZDIR/corpus" >&2 exit 2 fi "$OUT/native/replay" "$@" printf 'replay: OK\n' } locate_fuzzer_cc() { for cand in ${FUZZ_CC:-} clang /opt/homebrew/opt/llvm/bin/clang \ /usr/local/opt/llvm/bin/clang; do [ -n "$cand" ] || continue command -v "$cand" >/dev/null 2>&1 || continue probe="$OUT/fuzz_probe" printf 'int LLVMFuzzerTestOneInput(const unsigned char *d, unsigned long s){(void)d;(void)s;return 0;}\n' > "$OUT/fuzz_probe.c" if "$cand" -fsanitize=fuzzer "$OUT/fuzz_probe.c" -o "$probe" >/dev/null 2>&1; then printf '%s' "$cand" return 0 fi done return 1 } run_fuzz() { mkdir -p "$OUT/fuzz" if ! FUZZCC=$(locate_fuzzer_cc); then printf 'fuzz: GATED - no clang with a libFuzzer runtime found\n' >&2 printf 'fuzz: set FUZZ_CC to a libFuzzer-capable clang to enable\n' >&2 exit 2 fi printf '== fuzz: compiler %s\n' "$("$FUZZCC" --version 2>/dev/null | head -n 1)" RUN=$(mktemp -d "$OUT/fuzz/run.XXXXXX") corpus="$RUN/corpus" mkdir -p "$corpus" "$RUN/artifacts" printf '%s\n' "$RUN" > "$OUT/fuzz/latest-run.txt" set -- "$FUZZDIR"/corpus/* if [ ! -f "$1" ]; then printf 'fuzz: GATED - saved seed corpus is missing\n' >&2 exit 2 fi cp "$@" "$corpus"/ # Bounded native smoke: self-deadline and max input size, no load processes. # shellcheck disable=SC2086 printf '%s\n' "$FUZZCC" $CFLAGS -I"$QUAL" -fsanitize=fuzzer,address,undefined \ $LDFLAGS "$QUAL/fixture.c" "$QUAL/oracle.c" "$FUZZDIR/fuzz_ops.c" \ -o "$RUN/fuzz_ops" > "$RUN/fuzz_ops.argv" # shellcheck disable=SC2086 "$FUZZCC" $CFLAGS -I"$QUAL" -fsanitize=fuzzer,address,undefined $LDFLAGS \ "$QUAL/fixture.c" "$QUAL/oracle.c" "$FUZZDIR/fuzz_ops.c" -o "$RUN/fuzz_ops" if "$RUN/fuzz_ops" "$corpus" \ -seed=1 -max_total_time=10 -max_len=60 -verbosity=0 -print_final_stats=1 \ -rss_limit_mb=512 -timeout=5 \ -artifact_prefix="$RUN/artifacts/" > "$RUN/output.log" 2>&1; then grep 'stat::' "$RUN/output.log" printf 'fuzz: OK (bounded smoke); evidence: %s\n' "$RUN" else status=$? cat "$RUN/output.log" >&2 printf 'fuzz: FAIL; evidence: %s\n' "$RUN" >&2 return "$status" fi } case "$MODE" in normal) run_normal ;; sanitize) run_sanitize ;; replay) run_replay ;; fuzz) run_fuzz ;; esac