omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / tests / test_tensor_conversion_equiv.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # Proof that tools/tensor_mutations.sh, now an adapter over |
| 18 | # tools/mutation_runner.sh, behaves like the legacy sweep. Host only, CPU only. |
| 19 | # Runs the OLD script (pinned commit ab66c17, omega#192, the last main commit |
| 20 | # with the unconverted sweep and the current 27-row table) and the NEW script |
| 21 | # on the same tree and requires identical stdout, identical exit code and an |
| 22 | # identical per-mutant verdict list (name + KILLED/SURVIVED/ERROR). It also |
| 23 | # requires the MUTATIONS and STORE_MUTATIONS tables to be identical in both |
| 24 | # scripts. The old copy is written into tools/ of this tree, so old and new |
| 25 | # both call this tree's own tools/m20_receipt_mutations.sh (already an adapter |
| 26 | # on the runner since omega#207); only the tensor sweep itself differs between |
| 27 | # old and new. The verdict list holds the main rows, the 11 M20 receipt rows |
| 28 | # and the store rows (currently 27 + 11 + 6 = 44). The row counts the test |
| 29 | # expects are read from the pinned script's own tables, never typed in here. |
| 30 | # When a later PR adds table rows, the tables stop matching the pin: re-pin to |
| 31 | # the newest main commit that still has the unconverted script. |
| 32 | # |
| 33 | # Normalised text: none. The sweeps print no temp paths or timings on stdout |
| 34 | # (scratch dirs are only used internally), so stdout is compared byte for byte. |
| 35 | # (The sweep has no JSON output; the c4 sweep is the only one that does.) |
| 36 | set -u |
| 37 | root=$(cd "$(dirname "$0")/.." && pwd) |
| 38 | cd "$root" || exit 2 |
| 39 | PIN=ab66c171fd5b553d3910b47c3ecf9fecde117fd8 |
| 40 | old=tools/tensor_mutations_legacy.$$.sh |
| 41 | tmp=$(mktemp -d "${TMPDIR:-/tmp}/tensor-equiv.XXXXXX") || exit 2 |
| 42 | trap 'rm -rf "$tmp" "$root/$old"' EXIT INT TERM |
| 43 | git show "$PIN:tools/tensor_mutations.sh" > "$old" || { echo "FAIL cannot extract $PIN:tools/tensor_mutations.sh"; exit 2; } |
| 44 | chmod +x "$old" |
| 45 | fails=0 |
| 46 | ok() { if [ "$2" = 0 ]; then echo "ok $1"; else echo "FAIL $1"; fails=$((fails + 1)); fi; } |
| 47 | |
| 48 | # verdicts FILE: "name VERDICT" per MUTATION line, in order. |
| 49 | verdicts() { |
| 50 | sed -n 's/^MUTATION \([A-Za-z0-9_ ]*\): caught.*/\1 KILLED/p; |
| 51 | s/^MUTATION \([A-Za-z0-9_ ]*\): NOT CAUGHT.*/\1 SURVIVED/p; |
| 52 | s/^MUTATION \([A-Za-z0-9_ ]*\): \(NOT APPLIED\|does not build\).*/\1 ERROR/p; |
| 53 | s/^MUTATION \(store baseline\): .*/\1 ERROR/p' "$1" |
| 54 | } |
| 55 | |
| 56 | # table_text NAME FILE: the NAME='...' table of a sweep script, one row per |
| 57 | # line (the assignment ends at the first line that ends with a single quote). |
| 58 | # table_rows NAME FILE: how many rows it holds (every row contains a '|'). |
| 59 | table_text() { |
| 60 | awk -v v="$1" 'index($0, v "=\047") == 1 { p = 1 } p { print } p && /\047$/ { exit }' "$2" |
| 61 | } |
| 62 | table_rows() { table_text "$1" "$2" | grep -c '|'; } |
| 63 | main_rows=$(table_rows MUTATIONS "$old") |
| 64 | store_rows=$(table_rows STORE_MUTATIONS "$old") |
| 65 | new_main_rows=$(table_rows MUTATIONS tools/tensor_mutations.sh) |
| 66 | table_text MUTATIONS "$old" > "$tmp/old.main.table" |
| 67 | table_text MUTATIONS tools/tensor_mutations.sh > "$tmp/new.main.table" |
| 68 | table_text STORE_MUTATIONS "$old" > "$tmp/old.store.table" |
| 69 | table_text STORE_MUTATIONS tools/tensor_mutations.sh > "$tmp/new.store.table" |
| 70 | |
| 71 | sh "$old" > "$tmp/old.out" 2>/dev/null; echo $? > "$tmp/old.rc" |
| 72 | tools/tensor_mutations.sh > "$tmp/new.out" 2>/dev/null; echo $? > "$tmp/new.rc" |
| 73 | verdicts "$tmp/old.out" > "$tmp/old.v" |
| 74 | verdicts "$tmp/new.out" > "$tmp/new.v" |
| 75 | n=$(wc -l < "$tmp/new.v") |
| 76 | |
| 77 | cmp -s "$tmp/old.out" "$tmp/new.out"; ok "stdout identical old vs new" $? |
| 78 | cmp -s "$tmp/old.rc" "$tmp/new.rc"; ok "exit code identical old vs new ($(cat "$tmp/old.rc") vs $(cat "$tmp/new.rc"))" $? |
| 79 | cmp -s "$tmp/old.v" "$tmp/new.v"; ok "per-mutant verdict list identical" $? |
| 80 | [ "$main_rows" -gt 0 ] && [ "$store_rows" -gt 0 ]; ok "found both tables in the pinned script ($main_rows main rows, $store_rows store rows)" $? |
| 81 | cmp -s "$tmp/old.main.table" "$tmp/new.main.table"; ok "MUTATIONS table identical old vs new ($new_main_rows rows)" $? |
| 82 | cmp -s "$tmp/old.store.table" "$tmp/new.store.table"; ok "STORE_MUTATIONS table identical old vs new" $? |
| 83 | floor=$((main_rows + store_rows)) |
| 84 | [ "$n" -ge "$floor" ]; ok "compared at least $floor mutants ($main_rows main + $store_rows store), got $n" $? |
| 85 | [ "$(wc -l < "$tmp/old.v")" = "$n" ]; ok "old and new list the same number of mutants" $? |
| 86 | |
| 87 | # Negative checks: the comparison must be able to fail. |
| 88 | sed '0,/: caught/s//: NOT CAUGHT/' "$tmp/new.out" > "$tmp/alt.out" |
| 89 | cmp -s "$tmp/old.out" "$tmp/alt.out"; [ $? -ne 0 ]; ok "negative: altered stdout is reported different" $? |
| 90 | verdicts "$tmp/alt.out" > "$tmp/alt.v" |
| 91 | cmp -s "$tmp/old.v" "$tmp/alt.v"; [ $? -ne 0 ]; ok "negative: altered verdict list is reported different" $? |
| 92 | echo $(( $(cat "$tmp/old.rc") + 1 )) > "$tmp/alt.rc" |
| 93 | cmp -s "$tmp/old.rc" "$tmp/alt.rc"; [ $? -ne 0 ]; ok "negative: altered exit code is reported different" $? |
| 94 | { cat "$tmp/new.main.table"; echo 'EXTRA_ROW|omega_tensor.c|s/a/b/'; } > "$tmp/alt.main.table" |
| 95 | cmp -s "$tmp/old.main.table" "$tmp/alt.main.table"; [ $? -ne 0 ]; ok "negative: altered table is reported different" $? |
| 96 | |
| 97 | # Negative check for the adapter's row-count guard: a runner that dies reports |
| 98 | # no verdicts, and the sweep must then FAIL, never print PASS (0 of 0). The |
| 99 | # adapter does cd "$(dirname "$0")/..", so a scratch tree holding a copy of it |
| 100 | # beside a stub runner that just exits 2 runs it against a dead runner. The M20 |
| 101 | # sweep is stubbed to succeed, so only the row-count guard can fail this run. |
| 102 | dead="$tmp/dead" |
| 103 | mkdir -p "$dead/tools" |
| 104 | cp tools/tensor_mutations.sh "$dead/tools/tensor_mutations.sh" |
| 105 | printf '#!/bin/sh\nexit 2\n' > "$dead/tools/mutation_runner.sh" |
| 106 | printf '#!/bin/sh\nexit 0\n' > "$dead/tools/m20_receipt_mutations.sh" |
| 107 | chmod +x "$dead/tools/tensor_mutations.sh" "$dead/tools/mutation_runner.sh" "$dead/tools/m20_receipt_mutations.sh" |
| 108 | sh "$dead/tools/tensor_mutations.sh" > "$dead/out" 2>/dev/null; drc=$? |
| 109 | [ "$drc" -ne 0 ]; ok "negative: dead runner makes the sweep exit nonzero (got $drc)" $? |
| 110 | grep -q 'PASS' "$dead/out"; [ $? -ne 0 ]; ok "negative: dead runner never prints PASS" $? |
| 111 | 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)" $? |
| 112 | |
| 113 | if [ "$fails" -ne 0 ]; then echo "tensor conversion equivalence: FAIL ($fails)"; exit 1; fi |
| 114 | echo "tensor conversion equivalence: PASS ($n mutants compared)" |