Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tools/trit/test-mutate.sh # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tools / trit / test-mutate.sh` 137 lines ยท 7497 bytes Raw Blame History 1 #!/bin/sh 2 # test-mutate.sh -- regression for the mutation driver tools/trit/mutate.sh itself (external shell 3 # verification tool, not Omega production code). The defect it guards: the driver once exited 0 with 4 # every mutant "build failed", unapplied, or surviving, and counted a crashed test runner as a kill. 5 # Each scenario runs a scratch copy of the driver (the real mutants, real seed omc unless the scenario 6 # is about the compiler) and checks the exit status AND the verdict text. Stubs replace test.sh or 7 # difftest.sh only inside the scratch copy, and only to produce one exact failure shape. 8 # Usage from the repo root: sh tools/trit/test-mutate.sh (W=dir keeps all logs; OMC optional) 9 set -u 10 R=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd); cd "$R" || exit 2 11 OMC=${OMC:-$R/seed/out/omc}; case $OMC in /*) ;; *) OMC=$(pwd)/$OMC ;; esac 12 if [ -z "${W:-}" ]; then W=$(mktemp -d "${TMPDIR:-/tmp}/trit-mutate-test.XXXXXX") || exit 2; else 13 if [ -e "$W" ] || [ -L "$W" ]; then echo "work directory already exists: $W (preserved)" >&2; exit 2; fi 14 mkdir -p "$W" || exit 2 15 fi 16 case $W in /*) ;; *) W=$(pwd)/$W ;; esac 17 [ -x "$OMC" ] || { echo "test-mutate.sh: compiler $OMC missing" >&2; exit 2; } 18 pass=0; fail=0 19 ok() { pass=$((pass+1)); printf 'PASS %s\n' "$1"; } 20 no() { fail=$((fail+1)); printf 'FAIL %s: %s\n' "$1" "$2"; } 21 22 # scratch NAME "mutant names kept": a repo copy whose driver runs only those mutants. 23 scratch() { 24 S=$W/$1; rm -rf "$S"; mkdir -p "$S/tools" "$S/seed/trace" "$S/seed/out" 25 cp -r tools/trit tools/codebook "$S/tools/"; cp seed/trace/sha256.om "$S/seed/trace/" 26 rm -f "$S/tools/trit/trit.bin" "$S/tools/codebook/codebook.bin" 27 ln -s "$OMC" "$S/seed/out/omc" 28 keep=$2 29 awk -v keep="$keep" 'BEGIN{n=split(keep,a," "); for(i=1;i<=n;i++)k[a[i]]=1} /^m /{ if(!($3 in k)) next } {print}' tools/trit/mutate.sh > "$S/tools/trit/mutate.sh" 30 } 31 # drive NAME [VAR=value ...]: run the scratch driver; sets RC and OUT (log path). 32 drive() { 33 d=$1; shift 34 OUT=$W/$d.log 35 env "$@" W="$W/$d.work" REF_TRIT_OM="$R/tools/trit/trit.om" sh "$W/$d/tools/trit/mutate.sh" > "$OUT" 2>&1; RC=$? 36 } 37 # expect NAME RC PATTERN...: exit status and every grep pattern present in the log. 38 expect() { 39 n=$1; rc=$2; shift 2 40 if [ "$RC" != "$rc" ]; then no "$n" "exit $RC, want $rc (see $OUT)"; return; fi 41 for p in "$@"; do grep -q -- "$p" "$OUT" || { no "$n" "pattern '$p' missing (see $OUT)"; return; }; done 42 ok "$n" 43 } 44 45 # 1. normal subset with an explicit compiler, then the unset-OMC default and ack-only scope 46 scratch ok-read "lvl-ignores-3xx verify-disabled" 47 drive ok-read OMC="$OMC" 48 expect read-mutants-accepted 0 'BASELINE test.sh survived, difftest survived' 'MUTANT 1 lvl-ignores-3xx \[read\]: test.sh killed, difftest killed => ok' 'mutate.sh: PASS 2/2' 49 scratch ok-default "stale-allows-equal" 50 env -u OMC W="$W/ok-default.work" sh "$W/ok-default/tools/trit/mutate.sh" > "$W/ok-default.log" 2>&1; RC=$?; OUT=$W/ok-default.log 51 expect default-omc-is-seed-omc 0 'mutate.sh: PASS 1/1' 52 # an ack mutant is outside the differential model: test.sh kills it, difftest survives, still accepted 53 scratch ok-ack "ack-no-counter-advance" 54 drive ok-ack OMC="$OMC" 55 expect ack-mutant-judged-by-test-sh 0 'ack-no-counter-advance \[ack\]: test.sh killed, difftest survived => ok' 'mutate.sh: PASS 1/1' 56 57 # 2. invalid compilers are rejected before any mutant "result" 58 scratch bad-omc "lvl-ignores-3xx" 59 drive bad-omc OMC=/nonexistent/omc 60 expect compiler-missing 2 'prerequisite missing: compiler' 61 printf '#!/bin/sh\nexit 1\n' > "$W/failing-omc"; chmod 755 "$W/failing-omc" 62 scratch bad-omc2 "lvl-ignores-3xx" 63 drive bad-omc2 OMC="$W/failing-omc" 64 expect compiler-fails-baseline-build 5 'BASELINE build failed' 65 if grep -q '^MUTANT ' "$OUT"; then no compiler-fails-no-mutant-line "mutant lines printed with a failing compiler"; else ok compiler-fails-no-mutant-line; fi 66 printf 'not a program\n' > "$W/text-omc"; chmod 644 "$W/text-omc" 67 scratch bad-omc3 "lvl-ignores-3xx" 68 drive bad-omc3 OMC="$W/text-omc" 69 expect compiler-not-executable 2 'prerequisite missing: compiler' 70 71 # 3. a mutation that does not change the source is not a mutant 72 scratch unapplied "lvl-ignores-3xx" 73 sed 's|^m trit/trit.om lvl-ignores-3xx .*|m trit/trit.om lvl-ignores-3xx '"'"'s/NO SUCH TEXT IN trit.om/x/'"'"' read|' "$W/unapplied/tools/trit/mutate.sh" > "$W/unapplied/m" && cp "$W/unapplied/m" "$W/unapplied/tools/trit/mutate.sh" 74 drive unapplied OMC="$OMC" 75 expect mutation-not-applied 3 'MUTANT 1 lvl-ignores-3xx: NOT APPLIED' 'mutant not applied or invalid' 76 77 # 4. a mutant that does not compile is invalid, not killed 78 scratch invalid "lvl-ignores-3xx" 79 sed 's|^m trit/trit.om lvl-ignores-3xx .*|m trit/trit.om lvl-ignores-3xx '"'"'s/\\z/\\n@@@ not omega\\n/'"'"' read|' "$W/invalid/tools/trit/mutate.sh" > "$W/invalid/m" && cp "$W/invalid/m" "$W/invalid/tools/trit/mutate.sh" 80 drive invalid OMC="$OMC" 81 expect mutant-build-invalid 3 'MUTANT 1 lvl-ignores-3xx: BUILD INVALID' 'mutant not applied or invalid' 82 83 # 5. a surviving mutant fails the run: test.sh that always passes 84 STUBPASS='#!/bin/sh 85 echo "TOTAL pass=1 fail=0 skip=0" 86 exit 0 87 ' 88 scratch survivor "lvl-ignores-3xx" 89 printf '%s' "$STUBPASS" > "$W/survivor/tools/trit/test.sh" 90 drive survivor OMC="$OMC" 91 expect survivor-fails-run 1 'test.sh survived' 'SURVIVED' 'mutate.sh: FAIL survivor' 92 93 # 6. a test runner that dies is a harness error, never a kill: baseline passes, mutants make it exit 2 94 STUBDIE='#!/bin/sh 95 HERE=$(CDPATH= cd -- "$(dirname "$0")" && pwd) 96 if cmp -s "$HERE/trit.om" "$REF_TRIT_OM"; then echo "TOTAL pass=1 fail=0 skip=0"; exit 0; fi 97 echo "test.sh: no trit binary" >&2; exit 2 98 ' 99 scratch harness-dies "lvl-ignores-3xx" 100 printf '%s' "$STUBDIE" > "$W/harness-dies/tools/trit/test.sh" 101 drive harness-dies OMC="$OMC" 102 expect test-runner-crash-not-a-kill 4 'test.sh harness-error' 'HARNESS ERROR (test.sh)' 'mutate.sh: FAIL harness error' 103 if grep -q 'test.sh killed' "$OUT"; then no crash-not-counted-killed "a crash was counted as killed"; else ok crash-not-counted-killed; fi 104 # exit 1 without any FAIL line or with fail=0 is also not a kill 105 STUBEXIT1='#!/bin/sh 106 HERE=$(CDPATH= cd -- "$(dirname "$0")" && pwd) 107 if cmp -s "$HERE/trit.om" "$REF_TRIT_OM"; then echo "TOTAL pass=1 fail=0 skip=0"; exit 0; fi 108 echo "TOTAL pass=1 fail=0 skip=0"; exit 1 109 ' 110 scratch harness-exit1 "lvl-ignores-3xx" 111 printf '%s' "$STUBEXIT1" > "$W/harness-exit1/tools/trit/test.sh" 112 drive harness-exit1 OMC="$OMC" 113 expect exit1-without-fail-not-a-kill 4 'test.sh harness-error' 114 115 # 7. difftest that dies (no DIFF verdict) is a harness error, not a kill 116 STUBDIFF='#!/bin/sh 117 HERE=$(CDPATH= cd -- "$(dirname "$0")" && pwd) 118 if cmp -s "$HERE/../trit.om" "$REF_TRIT_OM"; then echo "DIFF agree=200/200 seed=3"; exit 0; fi 119 exit 1 120 ' 121 scratch diff-dies "lvl-ignores-3xx" 122 printf '%s' "$STUBDIFF" > "$W/diff-dies/tools/trit/proof/difftest.sh" 123 drive diff-dies OMC="$OMC" 124 expect difftest-crash-not-a-kill 4 'difftest harness-error' 'HARNESS ERROR (difftest)' 125 126 # 8. a failing baseline stops the run before any mutant 127 STUBFAIL='#!/bin/sh 128 echo "FAIL x: broken"; echo "TOTAL pass=0 fail=1 skip=0"; exit 1 129 ' 130 scratch base-fails "lvl-ignores-3xx" 131 printf '%s' "$STUBFAIL" > "$W/base-fails/tools/trit/test.sh" 132 drive base-fails OMC="$OMC" 133 expect baseline-failure-stops 5 'BASELINE did not pass' 134 if grep -q '^MUTANT ' "$OUT"; then no baseline-failure-runs-no-mutants "mutants ran after a failed baseline"; else ok baseline-failure-runs-no-mutants; fi 135 136 printf 'TOTAL pass=%d fail=%d logs=%s\n' "$pass" "$fail" "$W" 137 [ "$fail" = 0 ]