From 10c81a7d667b8eb04fbb8b590435c3599fc69595 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 1 Oct 2026 22:15:25 -0500 Subject: [PATCH 1/3] tools: tensor mutation sweep runs on the shared runner [host NOT_RUN] Stacked on omega#204. Same 20 main + 6 store mutants, same stdout and exit codes; adds tests/test_tensor_conversion_equiv.sh (old vs new at 2dc9dd8). Co-Authored-By: Claude Sonnet 5.5 --- tests/test_tensor_conversion_equiv.sh | 52 ++++++++++ tools/tensor_mutations.sh | 138 ++++++++++++-------------- 2 files changed, 115 insertions(+), 75 deletions(-) create mode 100755 tests/test_tensor_conversion_equiv.sh diff --git a/tests/test_tensor_conversion_equiv.sh b/tests/test_tensor_conversion_equiv.sh new file mode 100755 index 000000000..045b877d6 --- /dev/null +++ b/tests/test_tensor_conversion_equiv.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# Proof that tools/tensor_mutations.sh, now an adapter over +# tools/mutation_runner.sh, behaves like the legacy sweep. Host only, CPU only. +# Runs the OLD script (pinned commit 2dc9dd8) and the NEW script on the same +# tree and requires identical stdout, identical exit code and an identical +# per-mutant verdict list (name + KILLED/SURVIVED/ERROR). +# +# Normalised text: none. The sweeps print no temp paths or timings on stdout +# (scratch dirs are only used internally), so stdout is compared byte for byte. +# (The sweep has no JSON output; the c4 sweep is the only one that does.) +set -u +root=$(cd "$(dirname "$0")/.." && pwd) +cd "$root" || exit 2 +PIN=2dc9dd8 +old=tools/tensor_mutations_legacy.$$.sh +tmp=$(mktemp -d "${TMPDIR:-/tmp}/tensor-equiv.XXXXXX") || exit 2 +trap 'rm -rf "$tmp" "$root/$old"' EXIT INT TERM +git show "$PIN:tools/tensor_mutations.sh" > "$old" || { echo "FAIL cannot extract $PIN:tools/tensor_mutations.sh"; exit 2; } +chmod +x "$old" +fails=0 +ok() { if [ "$2" = 0 ]; then echo "ok $1"; else echo "FAIL $1"; fails=$((fails + 1)); fi; } + +# verdicts FILE: "name VERDICT" per MUTATION line, in order. +verdicts() { + sed -n 's/^MUTATION \([A-Za-z0-9_ ]*\): caught.*/\1 KILLED/p; + s/^MUTATION \([A-Za-z0-9_ ]*\): NOT CAUGHT.*/\1 SURVIVED/p; + s/^MUTATION \([A-Za-z0-9_ ]*\): \(NOT APPLIED\|does not build\).*/\1 ERROR/p; + s/^MUTATION \(store baseline\): .*/\1 ERROR/p' "$1" +} + +sh "$old" > "$tmp/old.out" 2>/dev/null; echo $? > "$tmp/old.rc" +tools/tensor_mutations.sh > "$tmp/new.out" 2>/dev/null; echo $? > "$tmp/new.rc" +verdicts "$tmp/old.out" > "$tmp/old.v" +verdicts "$tmp/new.out" > "$tmp/new.v" +n=$(wc -l < "$tmp/new.v") + +cmp -s "$tmp/old.out" "$tmp/new.out"; ok "stdout identical old vs new" $? +cmp -s "$tmp/old.rc" "$tmp/new.rc"; ok "exit code identical old vs new ($(cat "$tmp/old.rc") vs $(cat "$tmp/new.rc"))" $? +cmp -s "$tmp/old.v" "$tmp/new.v"; ok "per-mutant verdict list identical" $? +[ "$n" -ge 26 ]; ok "compared at least 26 mutants (20 main + 6 store), got $n" $? +[ "$(wc -l < "$tmp/old.v")" = "$n" ]; ok "old and new list the same number of mutants" $? + +# Negative checks: the comparison must be able to fail. +sed '0,/: caught/s//: NOT CAUGHT/' "$tmp/new.out" > "$tmp/alt.out" +cmp -s "$tmp/old.out" "$tmp/alt.out"; [ $? -ne 0 ]; ok "negative: altered stdout is reported different" $? +verdicts "$tmp/alt.out" > "$tmp/alt.v" +cmp -s "$tmp/old.v" "$tmp/alt.v"; [ $? -ne 0 ]; ok "negative: altered verdict list is reported different" $? +echo $(( $(cat "$tmp/old.rc") + 1 )) > "$tmp/alt.rc" +cmp -s "$tmp/old.rc" "$tmp/alt.rc"; [ $? -ne 0 ]; ok "negative: altered exit code is reported different" $? + +if [ "$fails" -ne 0 ]; then echo "tensor conversion equivalence: FAIL ($fails)"; exit 1; fi +echo "tensor conversion equivalence: PASS ($n mutants compared)" diff --git a/tools/tensor_mutations.sh b/tools/tensor_mutations.sh index 871c36878..c0cca5df2 100755 --- a/tools/tensor_mutations.sh +++ b/tools/tensor_mutations.sh @@ -1,9 +1,10 @@ #!/bin/sh -# M20 OMEGA_TENSOR mutation sweep. For each rule marked MUT: in -# src/tensor/*.c, copy src/tensor to a scratch directory, break that one rule, -# rebuild the CPU test against the copy and require the test to FAIL. -# A mutation that does not apply, or that the tests do not catch, fails the -# sweep. CPU only, no device. Shell only (no Python). +# M20 OMEGA_TENSOR mutation sweep, a thin adapter over tools/mutation_runner.sh. +# For each rule marked MUT: in src/tensor/*.c the runner copies the tree +# to a scratch directory, breaks that one rule, rebuilds the CPU test there and +# requires the test to FAIL. A mutation that does not apply, does not build or +# is not caught fails the sweep. The adapter maps the runner verdicts back to +# the legacy stdout lines. CPU only, no device. Shell only (no Python). set -u cd "$(dirname "$0")/.." || exit 2 SCRATCH=$(mktemp -d "${TMPDIR:-/tmp}/tensor-mut.XXXXXX") || exit 2 @@ -43,87 +44,74 @@ REDUCE_AXES_DESCENDING|omega_tensor.c|s/for (uint32_t d = in.rank; d-- > 0;)/for REDUCE_AXES_KEEPDIMS|omega_tensor.c|s/keep\[n\] = keepdims;/keep[n] = keepdims \&\& false;/ SUM_TO_SHAPE_SIZE1|omega_tensor.c|s/ax\[n\] = d; keep\[n\] = true; n++;/(void)0;/' +STORE_MUTATIONS='TSTORE_HASH_VERIFY|s/memcmp(dig, sl->payload_sha, 32) != 0 || memcmp(vid, sl->value_id, 32) != 0/0/ +TSTORE_SHORT_RECORD|s/len != HDR_BYTES + count \* REC_BYTES/0/ +TSTORE_GEN_RESET|s/sl->gen = r->gen + 1;/sl->gen = 1;/ +TSTORE_RENAME_BEFORE_WRITE|s/const char \*wpath = tmp;/const char *wpath = final;/ +TSTORE_RECORD_SUM|s/memcmp(sum, in + REC_SUM, 32) != 0/0/ +TSTORE_HEADER_SUM|s/memcmp(sum, st->jbuf + HDR_SUM, 32) != 0/0/' +STORE_SRCS="src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c src/tensor/omega_tensor_reduce_seam.c" +# The runner reads its own env var ONLY; the legacy sweep never did. +unset ONLY +fail=0 +total=0 + +# run_block ROWSFILE BUILDCMD TESTCMD: run the shared runner (marker reader, +# baseline check on) and print one legacy "MUTATION : ..." line per +# mutant, in row order. Returns 3 if the unmutated baseline does not pass. +# Legacy notes that need no mapping beyond the verdict: KILLED note +# " failing case(s), first: ..." becomes "caught ( failing checks)", +# "harness exit" (nonzero exit, no FAIL line) becomes "caught (0 failing +# checks)". The 5-line build-log head the old script printed on a build error +# is replaced by the runner's one-line build error note. +run_block() { + rb_rows=$1 + "tools/mutation_runner.sh" -k marker -m "$rb_rows" -t "$3" -b "$2" -c "src tests" -f FAIL -B \ + > "$SCRATCH/rb.out" 2> "$SCRATCH/rb.err" + if grep -q 'unmutated baseline does not pass' "$SCRATCH/rb.out"; then + cat "$SCRATCH/rb.err"; return 3 + fi + while IFS= read -r rb_l; do + rb_id=${rb_l%% *}; rb_r=${rb_l#* }; rb_st=${rb_r%% *} + rb_note=${rb_l#*\(}; rb_note=${rb_note%)} + total=$((total + 1)) + case $rb_st in + KILLED) + rb_n=$(printf '%s\n' "$rb_note" | sed -n 's/^\([0-9][0-9]*\) failing case.*/\1/p') + echo "MUTATION $rb_id: caught (${rb_n:-0} failing checks)" ;; + SURVIVED*) echo "MUTATION $rb_id: NOT CAUGHT (tests still pass)"; fail=1 ;; + *) + case $rb_note in + "build failed"*) echo "$rb_note"; echo "MUTATION $rb_id: does not build (fix the sed expression)" ;; + *) echo "MUTATION $rb_id: NOT APPLIED (marker or pattern missing)" ;; + esac + fail=1 ;; + esac + done < "$SCRATCH/rb.err" +} + +# Main block. Rows are name|file|sed expression; the file column is relative +# to src/tensor, the runner wants it relative to the tree root. +printf '%s\n' "$MUTATIONS" | sed 's#^\([A-Z0-9_]*\)|#\1|src/tensor/#' > "$SCRATCH/main.rows" # Baseline: the unmutated build must PASS, otherwise every mutant would # look "caught" (e.g. the test refusing an unsuitable FP environment). -if ! gcc $FLAGS -Isrc -Isrc/tensor -o "$SCRATCH/base" tests/test_omega_tensor.c \ - src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c src/tensor/omega_tensor_reduce_seam.c $DEPS \ - > "$SCRATCH/base.log" 2>&1 || ! "$SCRATCH/base" > "$SCRATCH/base.run" 2>&1; then - head -5 "$SCRATCH/base.log" "$SCRATCH/base.run" 2>/dev/null +if ! run_block "$SCRATCH/main.rows" \ + "gcc $FLAGS -Isrc -Isrc/tensor -o .tensor_t tests/test_omega_tensor.c src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c src/tensor/omega_tensor_reduce_seam.c $DEPS" \ + ./.tensor_t; then echo "tensor mutation sweep: FAIL (unmutated baseline does not pass)"; exit 1 fi -fail=0 -total=0 -old_ifs=$IFS -IFS=' -' -for m in $MUTATIONS; do - IFS=$old_ifs - IFS='|' read -r name file expr < "$SCRATCH/build.log" 2>&1; then - head -5 "$SCRATCH/build.log" - echo "MUTATION $name: does not build (fix the sed expression)"; fail=1; continue - fi - if "$SCRATCH/t" > "$SCRATCH/run.log" 2>&1; then - echo "MUTATION $name: NOT CAUGHT (tests still pass)"; fail=1 - else - echo "MUTATION $name: caught ($(grep -c '^FAIL' "$SCRATCH/run.log") failing checks)" - fi -done -IFS=$old_ifs # M20 receipt writer mutants (MUT: markers in tools/m20_receipt.sh), own sweep. tools/m20_receipt_mutations.sh || fail=1 # Crash-safe storage lifetime (omega_tensor_store.c): each mutant rebuilds # tests/test_omega_tensor_store.c against the mutated copy and must FAIL it. # (Skipping the fsync before rename is not observable without power loss, so -# it is not a mutant here.) -STORE_MUTATIONS='TSTORE_HASH_VERIFY|s/memcmp(dig, sl->payload_sha, 32) != 0 || memcmp(vid, sl->value_id, 32) != 0/0/ -TSTORE_SHORT_RECORD|s/len != HDR_BYTES + count \* REC_BYTES/0/ -TSTORE_GEN_RESET|s/sl->gen = r->gen + 1;/sl->gen = 1;/ -TSTORE_RENAME_BEFORE_WRITE|s/const char \*wpath = tmp;/const char *wpath = final;/ -TSTORE_RECORD_SUM|s/memcmp(sum, in + REC_SUM, 32) != 0/0/ -TSTORE_HEADER_SUM|s/memcmp(sum, st->jbuf + HDR_SUM, 32) != 0/0/' -STORE_SRCS="src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c src/tensor/omega_tensor_reduce_seam.c" -if ! gcc $FLAGS -Isrc -Isrc/tensor -o "$SCRATCH/sbase" tests/test_omega_tensor_store.c \ - src/tensor/omega_tensor_store.c $STORE_SRCS $DEPS > "$SCRATCH/sbase.log" 2>&1 \ - || ! "$SCRATCH/sbase" > "$SCRATCH/sbase.run" 2>&1; then - head -5 "$SCRATCH/sbase.log" "$SCRATCH/sbase.run" 2>/dev/null +# it is not a mutant here.) Rows are name|expr, the file is implied. +printf '%s\n' "$STORE_MUTATIONS" | sed 's#^\([A-Z0-9_]*\)|#\1|src/tensor/omega_tensor_store.c|#' > "$SCRATCH/store.rows" +if ! run_block "$SCRATCH/store.rows" \ + "gcc $FLAGS -Isrc -Isrc/tensor -o .tstore_t tests/test_omega_tensor_store.c src/tensor/omega_tensor_store.c $STORE_SRCS $DEPS" \ + ./.tstore_t; then echo "MUTATION store baseline: unmutated store test does not pass"; fail=1 -else - IFS=' -' - for m in $STORE_MUTATIONS; do - IFS=$old_ifs - name=${m%%|*} - expr=${m#*|} - total=$((total + 1)) - cp src/tensor/omega_tensor_store.c "$SCRATCH/store.c" - sed -i "/MUT:$name/ $expr" "$SCRATCH/store.c" - if cmp -s src/tensor/omega_tensor_store.c "$SCRATCH/store.c"; then - echo "MUTATION $name: NOT APPLIED (marker or pattern missing)"; fail=1; continue - fi - if ! gcc $FLAGS -Isrc -Isrc/tensor -o "$SCRATCH/st" tests/test_omega_tensor_store.c \ - "$SCRATCH/store.c" $STORE_SRCS $DEPS > "$SCRATCH/sbuild.log" 2>&1; then - head -5 "$SCRATCH/sbuild.log" - echo "MUTATION $name: does not build (fix the sed expression)"; fail=1; continue - fi - if "$SCRATCH/st" > "$SCRATCH/srun.log" 2>&1; then - echo "MUTATION $name: NOT CAUGHT (tests still pass)"; fail=1 - else - echo "MUTATION $name: caught ($(grep -c '^FAIL' "$SCRATCH/srun.log") failing checks)" - fi - done - IFS=$old_ifs fi if [ "$fail" -ne 0 ]; then echo "tensor mutation sweep: FAIL"; exit 1; fi From 4279e6720a150b75fbd211b805764b5d276ad4b1 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 1 Oct 2026 23:16:01 -0500 Subject: [PATCH 2/3] tools: tensor adapter fails if the runner reports fewer verdicts than rows; proof case [host NOT_RUN] Cause: run_block never compared the verdict lines it read from the runner with the rows it handed over. A runner that died, was killed or reported nothing left the loop with zero iterations, fail stayed 0 and the sweep printed PASS (0 of 0 ...) with exit 0. The legacy script walked the rows itself and could not do that. Fix: run_block counts the verdicts it read and compares them with the number of rows (grep -c '|'); a mismatch prints a MUTATION line and sets fail=1. The baseline early return is unchanged. The equivalence test gets a dead-runner counterexample (scratch tree, stub runner that exits 2, M20 sweep stubbed to succeed) asserting nonzero exit, no PASS and the new line. The "20 main" label becomes 21 main rows (wording only). Not run: nothing was compiled or executed, parse check only (sh -n). Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01DsjWa6csUe4NxndCTmugHu --- tests/test_tensor_conversion_equiv.sh | 18 +++++++++++++++++- tools/tensor_mutations.sh | 12 +++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/test_tensor_conversion_equiv.sh b/tests/test_tensor_conversion_equiv.sh index 045b877d6..99d6d09e6 100755 --- a/tests/test_tensor_conversion_equiv.sh +++ b/tests/test_tensor_conversion_equiv.sh @@ -37,7 +37,7 @@ n=$(wc -l < "$tmp/new.v") cmp -s "$tmp/old.out" "$tmp/new.out"; ok "stdout identical old vs new" $? cmp -s "$tmp/old.rc" "$tmp/new.rc"; ok "exit code identical old vs new ($(cat "$tmp/old.rc") vs $(cat "$tmp/new.rc"))" $? cmp -s "$tmp/old.v" "$tmp/new.v"; ok "per-mutant verdict list identical" $? -[ "$n" -ge 26 ]; ok "compared at least 26 mutants (20 main + 6 store), got $n" $? +[ "$n" -ge 26 ]; ok "compared at least 26 mutants (21 main + 6 store), got $n" $? [ "$(wc -l < "$tmp/old.v")" = "$n" ]; ok "old and new list the same number of mutants" $? # Negative checks: the comparison must be able to fail. @@ -48,5 +48,21 @@ cmp -s "$tmp/old.v" "$tmp/alt.v"; [ $? -ne 0 ]; ok "negative: altered verdict li echo $(( $(cat "$tmp/old.rc") + 1 )) > "$tmp/alt.rc" cmp -s "$tmp/old.rc" "$tmp/alt.rc"; [ $? -ne 0 ]; ok "negative: altered exit code is reported different" $? +# Negative check for the adapter's row-count guard: a runner that dies reports +# no verdicts, and the sweep must then FAIL, never print PASS (0 of 0). The +# adapter does cd "$(dirname "$0")/..", so a scratch tree holding a copy of it +# beside a stub runner that just exits 2 runs it against a dead runner. The M20 +# sweep is stubbed to succeed, so only the row-count guard can fail this run. +dead="$tmp/dead" +mkdir -p "$dead/tools" +cp tools/tensor_mutations.sh "$dead/tools/tensor_mutations.sh" +printf '#!/bin/sh\nexit 2\n' > "$dead/tools/mutation_runner.sh" +printf '#!/bin/sh\nexit 0\n' > "$dead/tools/m20_receipt_mutations.sh" +chmod +x "$dead/tools/tensor_mutations.sh" "$dead/tools/mutation_runner.sh" "$dead/tools/m20_receipt_mutations.sh" +sh "$dead/tools/tensor_mutations.sh" > "$dead/out" 2>/dev/null; drc=$? +[ "$drc" -ne 0 ]; ok "negative: dead runner makes the sweep exit nonzero (got $drc)" $? +grep -q 'PASS' "$dead/out"; [ $? -ne 0 ]; ok "negative: dead runner never prints PASS" $? +grep -q 'runner reported 0 verdicts for 21 rows' "$dead/out"; ok "negative: dead runner reports the verdict shortfall (0 verdicts for 21 main rows)" $? + if [ "$fails" -ne 0 ]; then echo "tensor conversion equivalence: FAIL ($fails)"; exit 1; fi echo "tensor conversion equivalence: PASS ($n mutants compared)" diff --git a/tools/tensor_mutations.sh b/tools/tensor_mutations.sh index c0cca5df2..514932c32 100755 --- a/tools/tensor_mutations.sh +++ b/tools/tensor_mutations.sh @@ -59,6 +59,7 @@ total=0 # run_block ROWSFILE BUILDCMD TESTCMD: run the shared runner (marker reader, # baseline check on) and print one legacy "MUTATION : ..." line per # mutant, in row order. Returns 3 if the unmutated baseline does not pass. +# Sets fail=1 if the runner reported fewer or more verdict lines than rows. # Legacy notes that need no mapping beyond the verdict: KILLED note # " failing case(s), first: ..." becomes "caught ( failing checks)", # "harness exit" (nonzero exit, no FAIL line) becomes "caught (0 failing @@ -71,10 +72,11 @@ run_block() { if grep -q 'unmutated baseline does not pass' "$SCRATCH/rb.out"; then cat "$SCRATCH/rb.err"; return 3 fi + rb_seen=0 while IFS= read -r rb_l; do rb_id=${rb_l%% *}; rb_r=${rb_l#* }; rb_st=${rb_r%% *} rb_note=${rb_l#*\(}; rb_note=${rb_note%)} - total=$((total + 1)) + total=$((total + 1)); rb_seen=$((rb_seen + 1)) case $rb_st in KILLED) rb_n=$(printf '%s\n' "$rb_note" | sed -n 's/^\([0-9][0-9]*\) failing case.*/\1/p') @@ -88,6 +90,14 @@ run_block() { fail=1 ;; esac done < "$SCRATCH/rb.err" + # The legacy sweep walked the rows itself, so a row could not be skipped. + # A runner that died, was killed or reported nothing must not pass silently: + # one verdict line per row is required. + rb_want=$(grep -c '|' "$rb_rows") + if [ "$rb_seen" -ne "$rb_want" ]; then + echo "MUTATION $rb_rows: runner reported $rb_seen verdicts for $rb_want rows (runner died or reported nothing)" + fail=1 + fi } # Main block. Rows are name|file|sed expression; the file column is relative From b3ff1532cbd81f2102a84327d76e99b43870e3b0 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Fri, 2 Oct 2026 02:05:10 -0500 Subject: [PATCH 3/3] tests: tensor conversion equivalence re-pinned after omega#191 and omega#192 added six rows [host NOT_RUN] omega#191 added CMP_FALSE_NEG_ZERO, CMP_EQ_NAN_TRUE and WHERE_ACCEPTS_HALF and omega#192 added REDUCE_AXES_DESCENDING, REDUCE_AXES_KEEPDIMS and SUM_TO_SHAPE_SIZE1 to the tensor mutation table, so main now has 27 main rows (was 21). The equivalence test pinned the old script at 2dc9dd8 (21 rows). It now pins the old script at ab66c17, the newest main commit that still has the unconverted sweep with all 27 rows. The comparison is unchanged: stdout, exit code and per-mutant verdict list old versus new, plus every negative check. The row counts are no longer typed in: the test reads them from the pinned script's own tables (floor = main + store rows, dead-runner message uses the table's row count), so a later row added by someone else changes the expected counts, not this test. Two checks are added: the MUTATIONS and STORE_MUTATIONS tables must be identical in the pinned and the converted script, with a negative case that an altered table is reported different, and a guard that both tables were found in the pin. Not run here: the forge runs the queued job. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01DsjWa6csUe4NxndCTmugHu --- tests/test_tensor_conversion_equiv.sh | 43 +++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/tests/test_tensor_conversion_equiv.sh b/tests/test_tensor_conversion_equiv.sh index 99d6d09e6..6596ee754 100755 --- a/tests/test_tensor_conversion_equiv.sh +++ b/tests/test_tensor_conversion_equiv.sh @@ -1,9 +1,19 @@ #!/bin/sh # Proof that tools/tensor_mutations.sh, now an adapter over # tools/mutation_runner.sh, behaves like the legacy sweep. Host only, CPU only. -# Runs the OLD script (pinned commit 2dc9dd8) and the NEW script on the same -# tree and requires identical stdout, identical exit code and an identical -# per-mutant verdict list (name + KILLED/SURVIVED/ERROR). +# Runs the OLD script (pinned commit ab66c17, omega#192, the last main commit +# with the unconverted sweep and the current 27-row table) and the NEW script +# on the same tree and requires identical stdout, identical exit code and an +# identical per-mutant verdict list (name + KILLED/SURVIVED/ERROR). It also +# requires the MUTATIONS and STORE_MUTATIONS tables to be identical in both +# scripts. The old copy is written into tools/ of this tree, so old and new +# both call this tree's own tools/m20_receipt_mutations.sh (already an adapter +# on the runner since omega#207); only the tensor sweep itself differs between +# old and new. The verdict list holds the main rows, the 11 M20 receipt rows +# and the store rows (currently 27 + 11 + 6 = 44). The row counts the test +# expects are read from the pinned script's own tables, never typed in here. +# When a later PR adds table rows, the tables stop matching the pin: re-pin to +# the newest main commit that still has the unconverted script. # # Normalised text: none. The sweeps print no temp paths or timings on stdout # (scratch dirs are only used internally), so stdout is compared byte for byte. @@ -11,7 +21,7 @@ set -u root=$(cd "$(dirname "$0")/.." && pwd) cd "$root" || exit 2 -PIN=2dc9dd8 +PIN=ab66c171fd5b553d3910b47c3ecf9fecde117fd8 old=tools/tensor_mutations_legacy.$$.sh tmp=$(mktemp -d "${TMPDIR:-/tmp}/tensor-equiv.XXXXXX") || exit 2 trap 'rm -rf "$tmp" "$root/$old"' EXIT INT TERM @@ -28,6 +38,21 @@ verdicts() { s/^MUTATION \(store baseline\): .*/\1 ERROR/p' "$1" } +# table_text NAME FILE: the NAME='...' table of a sweep script, one row per +# line (the assignment ends at the first line that ends with a single quote). +# table_rows NAME FILE: how many rows it holds (every row contains a '|'). +table_text() { + awk -v v="$1" 'index($0, v "=\047") == 1 { p = 1 } p { print } p && /\047$/ { exit }' "$2" +} +table_rows() { table_text "$1" "$2" | grep -c '|'; } +main_rows=$(table_rows MUTATIONS "$old") +store_rows=$(table_rows STORE_MUTATIONS "$old") +new_main_rows=$(table_rows MUTATIONS tools/tensor_mutations.sh) +table_text MUTATIONS "$old" > "$tmp/old.main.table" +table_text MUTATIONS tools/tensor_mutations.sh > "$tmp/new.main.table" +table_text STORE_MUTATIONS "$old" > "$tmp/old.store.table" +table_text STORE_MUTATIONS tools/tensor_mutations.sh > "$tmp/new.store.table" + sh "$old" > "$tmp/old.out" 2>/dev/null; echo $? > "$tmp/old.rc" tools/tensor_mutations.sh > "$tmp/new.out" 2>/dev/null; echo $? > "$tmp/new.rc" verdicts "$tmp/old.out" > "$tmp/old.v" @@ -37,7 +62,11 @@ n=$(wc -l < "$tmp/new.v") cmp -s "$tmp/old.out" "$tmp/new.out"; ok "stdout identical old vs new" $? cmp -s "$tmp/old.rc" "$tmp/new.rc"; ok "exit code identical old vs new ($(cat "$tmp/old.rc") vs $(cat "$tmp/new.rc"))" $? cmp -s "$tmp/old.v" "$tmp/new.v"; ok "per-mutant verdict list identical" $? -[ "$n" -ge 26 ]; ok "compared at least 26 mutants (21 main + 6 store), got $n" $? +[ "$main_rows" -gt 0 ] && [ "$store_rows" -gt 0 ]; ok "found both tables in the pinned script ($main_rows main rows, $store_rows store rows)" $? +cmp -s "$tmp/old.main.table" "$tmp/new.main.table"; ok "MUTATIONS table identical old vs new ($new_main_rows rows)" $? +cmp -s "$tmp/old.store.table" "$tmp/new.store.table"; ok "STORE_MUTATIONS table identical old vs new" $? +floor=$((main_rows + store_rows)) +[ "$n" -ge "$floor" ]; ok "compared at least $floor mutants ($main_rows main + $store_rows store), got $n" $? [ "$(wc -l < "$tmp/old.v")" = "$n" ]; ok "old and new list the same number of mutants" $? # Negative checks: the comparison must be able to fail. @@ -47,6 +76,8 @@ verdicts "$tmp/alt.out" > "$tmp/alt.v" cmp -s "$tmp/old.v" "$tmp/alt.v"; [ $? -ne 0 ]; ok "negative: altered verdict list is reported different" $? echo $(( $(cat "$tmp/old.rc") + 1 )) > "$tmp/alt.rc" cmp -s "$tmp/old.rc" "$tmp/alt.rc"; [ $? -ne 0 ]; ok "negative: altered exit code is reported different" $? +{ cat "$tmp/new.main.table"; echo 'EXTRA_ROW|omega_tensor.c|s/a/b/'; } > "$tmp/alt.main.table" +cmp -s "$tmp/old.main.table" "$tmp/alt.main.table"; [ $? -ne 0 ]; ok "negative: altered table is reported different" $? # Negative check for the adapter's row-count guard: a runner that dies reports # no verdicts, and the sweep must then FAIL, never print PASS (0 of 0). The @@ -62,7 +93,7 @@ chmod +x "$dead/tools/tensor_mutations.sh" "$dead/tools/mutation_runner.sh" "$de sh "$dead/tools/tensor_mutations.sh" > "$dead/out" 2>/dev/null; drc=$? [ "$drc" -ne 0 ]; ok "negative: dead runner makes the sweep exit nonzero (got $drc)" $? grep -q 'PASS' "$dead/out"; [ $? -ne 0 ]; ok "negative: dead runner never prints PASS" $? -grep -q 'runner reported 0 verdicts for 21 rows' "$dead/out"; ok "negative: dead runner reports the verdict shortfall (0 verdicts for 21 main rows)" $? +grep -q "runner reported 0 verdicts for $new_main_rows rows" "$dead/out"; ok "negative: dead runner reports the verdict shortfall (0 verdicts for $new_main_rows main rows)" $? if [ "$fails" -ne 0 ]; then echo "tensor conversion equivalence: FAIL ($fails)"; exit 1; fi echo "tensor conversion equivalence: PASS ($n mutants compared)"