interplane.Get Omega
Read in your language

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

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)
9set -u
10R=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd); cd "$R" || exit 2
11OMC=${OMC:-$R/seed/out/omc}; case $OMC in /*) ;; *) OMC=$(pwd)/$OMC ;; esac
12if [ -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
15fi
16case $W in /*) ;; *) W=$(pwd)/$W ;; esac
17[ -x "$OMC" ] || { echo "test-mutate.sh: compiler $OMC missing" >&2; exit 2; }
18pass=0; fail=0
19ok() { pass=$((pass+1)); printf 'PASS %s\n' "$1"; }
20no() { 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.
23scratch() {
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).
32drive() {
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.
38expect() {
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
46scratch ok-read "lvl-ignores-3xx verify-disabled"
47drive ok-read OMC="$OMC"
48expect 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'
49scratch ok-default "stale-allows-equal"
50env -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
51expect 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
53scratch ok-ack "ack-no-counter-advance"
54drive ok-ack OMC="$OMC"
55expect 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"
58scratch bad-omc "lvl-ignores-3xx"
59drive bad-omc OMC=/nonexistent/omc
60expect compiler-missing 2 'prerequisite missing: compiler'
61printf '#!/bin/sh\nexit 1\n' > "$W/failing-omc"; chmod 755 "$W/failing-omc"
62scratch bad-omc2 "lvl-ignores-3xx"
63drive bad-omc2 OMC="$W/failing-omc"
64expect compiler-fails-baseline-build 5 'BASELINE build failed'
65if 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
66printf 'not a program\n' > "$W/text-omc"; chmod 644 "$W/text-omc"
67scratch bad-omc3 "lvl-ignores-3xx"
68drive bad-omc3 OMC="$W/text-omc"
69expect compiler-not-executable 2 'prerequisite missing: compiler'
70
71# 3. a mutation that does not change the source is not a mutant
72scratch unapplied "lvl-ignores-3xx"
73sed '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"
74drive unapplied OMC="$OMC"
75expect 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
78scratch invalid "lvl-ignores-3xx"
79sed '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"
80drive invalid OMC="$OMC"
81expect 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
84STUBPASS='#!/bin/sh
85echo "TOTAL pass=1 fail=0 skip=0"
86exit 0
87'
88scratch survivor "lvl-ignores-3xx"
89printf '%s' "$STUBPASS" > "$W/survivor/tools/trit/test.sh"
90drive survivor OMC="$OMC"
91expect 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
94STUBDIE='#!/bin/sh
95HERE=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
96if cmp -s "$HERE/trit.om" "$REF_TRIT_OM"; then echo "TOTAL pass=1 fail=0 skip=0"; exit 0; fi
97echo "test.sh: no trit binary" >&2; exit 2
98'
99scratch harness-dies "lvl-ignores-3xx"
100printf '%s' "$STUBDIE" > "$W/harness-dies/tools/trit/test.sh"
101drive harness-dies OMC="$OMC"
102expect test-runner-crash-not-a-kill 4 'test.sh harness-error' 'HARNESS ERROR (test.sh)' 'mutate.sh: FAIL harness error'
103if 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
105STUBEXIT1='#!/bin/sh
106HERE=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
107if cmp -s "$HERE/trit.om" "$REF_TRIT_OM"; then echo "TOTAL pass=1 fail=0 skip=0"; exit 0; fi
108echo "TOTAL pass=1 fail=0 skip=0"; exit 1
109'
110scratch harness-exit1 "lvl-ignores-3xx"
111printf '%s' "$STUBEXIT1" > "$W/harness-exit1/tools/trit/test.sh"
112drive harness-exit1 OMC="$OMC"
113expect 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
116STUBDIFF='#!/bin/sh
117HERE=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
118if cmp -s "$HERE/../trit.om" "$REF_TRIT_OM"; then echo "DIFF agree=200/200 seed=3"; exit 0; fi
119exit 1
120'
121scratch diff-dies "lvl-ignores-3xx"
122printf '%s' "$STUBDIFF" > "$W/diff-dies/tools/trit/proof/difftest.sh"
123drive diff-dies OMC="$OMC"
124expect difftest-crash-not-a-kill 4 'difftest harness-error' 'HARNESS ERROR (difftest)'
125
126# 8. a failing baseline stops the run before any mutant
127STUBFAIL='#!/bin/sh
128echo "FAIL x: broken"; echo "TOTAL pass=0 fail=1 skip=0"; exit 1
129'
130scratch base-fails "lvl-ignores-3xx"
131printf '%s' "$STUBFAIL" > "$W/base-fails/tools/trit/test.sh"
132drive base-fails OMC="$OMC"
133expect baseline-failure-stops 5 'BASELINE did not pass'
134if 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
136printf 'TOTAL pass=%d fail=%d logs=%s\n' "$pass" "$fail" "$W"
137[ "$fail" = 0 ]