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_c4_requal_mutants_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 | # Conversion proof: tools/c4_requal_mutants.sh (now an adapter over |
| 18 | # tools/mutation_runner.sh) must behave exactly like the pinned old script |
| 19 | # (commit e6298806f1c7ccd874d123350d639ad8bba6edc7, omega#216, the newest main |
| 20 | # commit that still holds the unconverted script with M03 retired and the |
| 21 | # rewritten M13). Host only, CPU only. PREREQUISITE: build/aienos-authority |
| 22 | # must exist (run 'make test-c4-requal' first); both sweeps build 15 mutants |
| 23 | # (M01 to M16 minus the retired M03), so this is slow. Env ONLY="M01 M05" |
| 24 | # narrows both sweeps to the same ids. |
| 25 | # |
| 26 | # Compared: stdout, exit code, the JSON receipt (byte for byte), and the |
| 27 | # per-mutant verdict list (id + KILLED/SURVIVED*/ERROR from the stderr lines). |
| 28 | # Normalised (volatile only): the receipt path in the stdout summary line |
| 29 | # (each sweep writes to its own file) and /tmp/c4mut.* or /tmp/mutrun.* scratch |
| 30 | # directory names. |
| 31 | # |
| 32 | # ONE more field is masked, the failing-case COUNT: the N in a KILLED note |
| 33 | # "N failing case(s), first: ..." becomes <n> in BOTH old and new, in the stderr |
| 34 | # lines and the JSON receipt, and only when N is an integer >= 1. Evidence that |
| 35 | # the count is not stable even for the OLD script alone: the C4 harness has 24 |
| 36 | # SIGKILL cases (tests/runtime/rx_c4_requal.c:645 kill_sweep(24); the kill delay |
| 37 | # and nanosleep/kill are at :305-308) whose outcome depends on timing. Forge |
| 38 | # diagnostic log test-queue-logs/DEEP6-conv-c4-diag-light-072723.log lines |
| 39 | # 21-36: raw harness fail counts per run were 9 10 10 9 9 (old-style dir) and |
| 40 | # 10 10 9 12 12 (runner-style dir), old script M06 gave 10 and 10 while the |
| 41 | # converted one gave 11 and 8, and the sorted non-kill FAIL lines were identical |
| 42 | # in all 10 runs. The count is descriptive: KILLED is decided by the exit code |
| 43 | # and nf>0 (tools/mutation_runner.sh lines 150-155), never by the value of N. |
| 44 | # A 0 count, a missing count, a non-number and a changed first failing case stay |
| 45 | # visible differences; so does every other field (status, id, file, checks text, |
| 46 | # order, row count, exit code, summary line). The negatives below prove it. |
| 47 | set -u |
| 48 | root=$(cd "$(dirname "$0")/.." && pwd) |
| 49 | cd "$root" || exit 2 |
| 50 | old=tools/_c4_requal_mutants_old.$$.sh |
| 51 | tmp=$(mktemp -d "${TMPDIR:-/tmp}/c4equiv.XXXXXX") || exit 2 |
| 52 | trap 'rm -rf "$tmp" "$root/$old"' EXIT INT TERM |
| 53 | git show e6298806f1c7ccd874d123350d639ad8bba6edc7:tools/c4_requal_mutants.sh > "$old" || { echo "FAIL cannot extract pinned old script"; exit 2; } |
| 54 | chmod +x "$old" |
| 55 | |
| 56 | norm() { # file -> normalised on stdout |
| 57 | sed -e "s#$tmp/[A-Za-z0-9_.]*json#OUT.json#g" -e 's#/tmp/c4mut\.[A-Za-z0-9]*#TMP#g' \ |
| 58 | -e 's#/tmp/mutrun\.[A-Za-z0-9]*#TMP#g' "$1" |
| 59 | } |
| 60 | # stdin -> stdout: the one masked field. The count must follow ( or " or a space |
| 61 | # (stderr "(9 failing case(s), first: " and JSON "note": "9 failing case(s), first: "), |
| 62 | # start with 1-9 (so 0, an empty count and a non-number are not masked) and be |
| 63 | # followed by ", first: " (the KILLED-with-FAIL-lines note shape). |
| 64 | mask() { |
| 65 | sed -e 's/\([(" ]\)[1-9][0-9]* failing case(s), first: /\1<n> failing case(s), first: /' |
| 66 | } |
| 67 | verdicts() { # stderr file -> "id STATUS" per mutant |
| 68 | sed -n 's/^\(M[0-9][0-9]*\) \(KILLED\|SURVIVED_REDUNDANT\|SURVIVED_GAP\|SURVIVED\|ERROR\) .*/\1 \2/p' "$1" |
| 69 | } |
| 70 | # same <fileA> <fileB> <label>: succeeds only if identical |
| 71 | same() { if cmp -s "$1" "$2"; then return 0; else echo "DIFF $3"; diff "$1" "$2" | head -5; return 1; fi; } |
| 72 | |
| 73 | sh tools/c4_requal_mutants.sh "$tmp/new.json" > "$tmp/new.out" 2> "$tmp/new.err"; echo $? > "$tmp/new.rc" |
| 74 | sh "$old" "$tmp/old.json" > "$tmp/old.out" 2> "$tmp/old.err"; echo $? > "$tmp/old.rc" |
| 75 | norm "$tmp/old.out" > "$tmp/old.out.n"; norm "$tmp/new.out" > "$tmp/new.out.n" |
| 76 | verdicts "$tmp/old.err" > "$tmp/old.v"; verdicts "$tmp/new.err" > "$tmp/new.v" |
| 77 | norm "$tmp/old.err" | mask > "$tmp/old.err.n"; norm "$tmp/new.err" | mask > "$tmp/new.err.n" |
| 78 | mask < "$tmp/old.json" > "$tmp/old.json.m"; mask < "$tmp/new.json" > "$tmp/new.json.m" |
| 79 | |
| 80 | fails=0 |
| 81 | n=$(wc -l < "$tmp/old.v") |
| 82 | [ "$n" -gt 0 ] || { echo "FAIL old sweep produced no verdicts"; fails=$((fails + 1)); } |
| 83 | same "$tmp/old.out.n" "$tmp/new.out.n" "stdout" || fails=$((fails + 1)) |
| 84 | same "$tmp/old.rc" "$tmp/new.rc" "exit code" || fails=$((fails + 1)) |
| 85 | same "$tmp/old.json.m" "$tmp/new.json.m" "JSON receipt (failing-case count masked)" || fails=$((fails + 1)) |
| 86 | same "$tmp/old.v" "$tmp/new.v" "per-mutant verdict list" || fails=$((fails + 1)) |
| 87 | same "$tmp/old.err.n" "$tmp/new.err.n" "stderr lines (failing-case count masked)" || fails=$((fails + 1)) |
| 88 | |
| 89 | # Negative checks: the comparison must be able to fail. |
| 90 | neg=0 |
| 91 | { cat "$tmp/old.v"; echo 'M00 KILLED'; } > "$tmp/neg.v" |
| 92 | same "$tmp/old.v" "$tmp/neg.v" "neg-verdict" >/dev/null 2>&1 && { echo "FAIL negative: altered verdict not detected"; neg=1; } |
| 93 | { cat "$tmp/old.json"; echo x; } | mask > "$tmp/neg.json.m" |
| 94 | same "$tmp/old.json.m" "$tmp/neg.json.m" "neg-json" >/dev/null 2>&1 && { echo "FAIL negative: altered JSON not detected"; neg=1; } |
| 95 | echo 1 > "$tmp/neg.rc"; echo 0 > "$tmp/neg0.rc" |
| 96 | same "$tmp/neg.rc" "$tmp/neg0.rc" "neg-rc" >/dev/null 2>&1 && { echo "FAIL negative: altered exit code not detected"; neg=1; } |
| 97 | |
| 98 | # The mask is narrow. Synthetic lines in the real stderr and JSON shapes (the |
| 99 | # sweep may not contain a counted note when ONLY narrows it). se/js print one |
| 100 | # line from <status> <count> <first failing case>; mdiff succeeds when the two |
| 101 | # lines are identical AFTER the mask. |
| 102 | se() { printf 'M06 %s choose the NEWEST durable state record (%s failing case(s), first: %s)\n' "$1" "$2" "$3"; } |
| 103 | js() { printf ' {"id": "M06", "file": "src/runtime/rx_compose.c", "checks": "x", "status": "%s", "note": "%s failing case(s), first: %s"},\n' "$1" "$2" "$3"; } |
| 104 | mdiff() { printf '%s\n' "$1" | mask > "$tmp/ma"; printf '%s\n' "$2" | mask > "$tmp/mb"; cmp -s "$tmp/ma" "$tmp/mb"; } |
| 105 | # controls: a differing count of >= 1 IS masked (else the mask is dead), also across digit lengths |
| 106 | mdiff "$(se KILLED 9 A)" "$(se KILLED 8 A)" || { echo "FAIL control: stderr count 9 vs 8 not masked"; neg=1; } |
| 107 | mdiff "$(js KILLED 10 A)" "$(js KILLED 12 A)" || { echo "FAIL control: JSON count 10 vs 12 not masked"; neg=1; } |
| 108 | # (a) a changed first failing case is still different |
| 109 | mdiff "$(se KILLED 9 A)" "$(se KILLED 9 B)" && { echo "FAIL negative: changed first failing case (stderr) not detected"; neg=1; } |
| 110 | mdiff "$(js KILLED 9 A)" "$(js KILLED 8 B)" && { echo "FAIL negative: changed first failing case (JSON) not detected"; neg=1; } |
| 111 | # (b) 0 failing case(s), a missing count and a non-number are still different from 8 |
| 112 | mdiff "$(se KILLED 0 A)" "$(se KILLED 8 A)" && { echo "FAIL negative: 0 vs 8 failing case(s) (stderr) not detected"; neg=1; } |
| 113 | mdiff "$(js KILLED 0 A)" "$(js KILLED 8 A)" && { echo "FAIL negative: 0 vs 8 failing case(s) (JSON) not detected"; neg=1; } |
| 114 | mdiff "$(se KILLED '' A)" "$(se KILLED 8 A)" && { echo "FAIL negative: missing count not detected"; neg=1; } |
| 115 | mdiff "$(se KILLED x A)" "$(se KILLED 8 A)" && { echo "FAIL negative: non-number count not detected"; neg=1; } |
| 116 | # (c) a changed status is still different (the verdict list negative above covers the list; these cover the masked stderr and JSON compares) |
| 117 | mdiff "$(se KILLED 9 A)" "$(se SURVIVED 9 A)" && { echo "FAIL negative: changed status (stderr) not detected"; neg=1; } |
| 118 | mdiff "$(js KILLED 9 A)" "$(js SURVIVED 9 A)" && { echo "FAIL negative: changed status (JSON) not detected"; neg=1; } |
| 119 | [ $neg -eq 0 ] && echo "ok negative checks (altered verdict, JSON, exit code; mask controls; changed first case, 0 / missing / non-number count and changed status each reported different)" |
| 120 | fails=$((fails + neg)) |
| 121 | |
| 122 | if [ $fails -eq 0 ]; then |
| 123 | echo "c4 conversion equivalence: PASS ($n mutants compared; stdout, exit code, JSON, verdicts identical, failing-case counts masked)" |
| 124 | exit 0 |
| 125 | fi |
| 126 | echo "c4 conversion equivalence: FAIL ($fails difference(s), $n mutants compared)" |
| 127 | exit 1 |