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 / seed / text / tests / gate.sh
| 1 | #!/bin/sh |
| 2 | # gate.sh -- seed/text/text.om against an independent oracle (tests/gen.om, seeded Omega). |
| 3 | # Builds the case generator gen.om and txdrv (om2 + text.om + txdrv.om) with seed/out/omc, writes the |
| 4 | # fixed and seeded random cases with their expected answers, and requires every answer of text.om to |
| 5 | # equal the oracle's. Then twelve mutants of text.om, each removing or bending one rule, must each |
| 6 | # produce at least one wrong answer. Also checks boundary cases and slice-guard mutants. |
| 7 | # Prints TEXTGATE PASS rows=N mutants=M boundaries=B. |
| 8 | # Exit 0 PASS, 1 FAIL, 3 NOT_RUN (interrupted by HUP, INT or TERM). |
| 9 | # Migration debt: this driver is still sh, with perl for the mutant edits; it is not ported to .om yet. |
| 10 | set -eu |
| 11 | R=$(CDPATH= cd -- "$(dirname "$0")/../../.." && pwd) |
| 12 | cd "$R" |
| 13 | S=seed/out/omc |
| 14 | notrun() { printf 'NOT_RUN text gate: %s\n' "$*"; exit 3; } |
| 15 | bad() { printf 'FAIL: %s\n' "$*" >&2; exit 1; } |
| 16 | [ -x "$S" ] || bad "$S missing; run sh seed/omega-from-seed.sh first" |
| 17 | mkdir -p build/seed/text |
| 18 | T=$(mktemp -d build/seed/text/run.XXXXXX) |
| 19 | trap 'rm -rf "$T"' EXIT |
| 20 | trap 'notrun interrupted' HUP INT TERM |
| 21 | "$S" < seed/text/tests/gen.om > "$T/gen" 2> "$T/build.err" || bad "omc refused seed/text/tests/gen.om: $(cat "$T/build.err")" |
| 22 | chmod +x "$T/gen" |
| 23 | "$T/gen" "$T" > "$T/gen.log" || bad "seed/text/tests/gen.om exited $? (80: a write failed)" |
| 24 | |
| 25 | build() { # build TEXT.om OUT |
| 26 | { printf 'om2\n'; cat "$1" seed/text/tests/txdrv.om; } > "$T/drv.om" |
| 27 | "$S" < "$T/drv.om" > "$2" 2> "$T/build.err" || bad "omc refused the driver with $1: $(cat "$T/build.err")" |
| 28 | chmod +x "$2" |
| 29 | } |
| 30 | # runall DRIVER: 0 when every cases file gives exactly its want file; on 1, k names the first file that does not |
| 31 | # and st is the driver's exit status on it (0: it ran and its answers differ; 100+N: trap N) |
| 32 | runall() { |
| 33 | for c in "$T"/cases-*.bin; do |
| 34 | k=${c##*/cases-}; k=${k%.bin} |
| 35 | st=0; "$1" < "$c" > "$T/got.txt" 2>/dev/null || st=$? |
| 36 | [ "$st" -eq 0 ] || return 1 |
| 37 | cmp -s "$T/got.txt" "$T/want-$k.txt" || return 1 |
| 38 | done |
| 39 | return 0 |
| 40 | } |
| 41 | |
| 42 | build seed/text/text.om "$T/txdrv" |
| 43 | runall "$T/txdrv" || { trap - EXIT HUP INT TERM; bad "text.om disagrees with the oracle on $T/cases-$k.bin: driver exit $st; compare $T/got.txt with $T/want-$k.txt ($T kept)"; } |
| 44 | rows=$(cat "$T"/want-*.txt | wc -l) |
| 45 | printf 'PASS %s cases equal the oracle (%s)\n' "$rows" "$(cat "$T/gen.log")" |
| 46 | |
| 47 | m=0 |
| 48 | mutant() { # mutant NAME PERL-EXPR |
| 49 | perl -0pe "$2" seed/text/text.om > "$T/mut.om" |
| 50 | cmp -s seed/text/text.om "$T/mut.om" && bad "mutant $1 did not apply" |
| 51 | build "$T/mut.om" "$T/mutdrv" |
| 52 | runall "$T/mutdrv" && bad "mutant $1 survived" |
| 53 | m=$((m + 1)); printf 'PASS mutant caught: %s\n' "$1" |
| 54 | } |
| 55 | mutant "decimal overflow boundary" 's/gt d 5\n/gt d 6\n/' |
| 56 | mutant "surrogates accepted after ED" 's/if eq s 5\nhi = uchar 159/if eq s 5\nhi = uchar 191/' |
| 57 | mutant "overlong accepted after E0" 's/if eq s 4\nlo = uchar 160/if eq s 4\nlo = uchar 128/' |
| 58 | mutant "needle at the very end missed" 's/stop = add sub hn m 1/stop = sub hn m/' |
| 59 | mutant "shorter prefix sorts last" 's/if lt len a len b\nret int -1/if lt len a len b\nret int 1/' |
| 60 | mutant "-2^63 refused" 's/if gt x 9223372036854775808/if ge x 9223372036854775808/' |
| 61 | mutant "truncated sequence accepted" 's/if ne st 0\nret lead\nend\nret stop/ret stop/' |
| 62 | mutant "3-byte lead keeps too few bits" 's/cp = ulong and c 15/cp = ulong and c 7/' |
| 63 | mutant "U+D800 encoded" 's/if and ge cp 55296/if and ge cp 55297/' |
| 64 | mutant "3-byte lead written as 4-byte" 's/lead = 224/lead = 240/' |
| 65 | mutant "U+07FF sized as 3 bytes" 's/if lt cp 2048/if lt cp 2047/' |
| 66 | mutant "backquote read as a hex digit" 's/if and ge c 97 le c 102/if and ge c 96 le c 102/' |
| 67 | # Boundary contracts are exercised through the same exact-status conductor as OM-2. |
| 68 | # The cases include invalid caller ranges and the named function-mode text refusal. |
| 69 | "$S" < seed/qualification/om2/gate.om > "$T/boundary-gate" |
| 70 | chmod +x "$T/boundary-gate" |
| 71 | pin=$(sha256sum "$S" | cut -d' ' -f1) |
| 72 | "$T/boundary-gate" "$R/$S" "$pin" seed/text/tests/boundary.cases "$T/boundary" > "$T/boundary.log" 2>&1 || { |
| 73 | cat "$T/boundary.log" |
| 74 | trap - EXIT HUP INT TERM |
| 75 | bad "text boundary contract failed ($T kept)" |
| 76 | } |
| 77 | cat "$T/boundary.log" |
| 78 | boundaries=$(sed -n 's/^OM2GATE PASS cases=\([0-9]*\) .*/\1/p' "$T/boundary.log") |
| 79 | [ -n "$boundaries" ] || bad "missing boundary verdict" |
| 80 | # Each mutant changes a refusing original (exit 103) into a clean return (exit 0). |
| 81 | # A signal, compile error or another exit is not counted as the expected kill. |
| 82 | boundary_mutant() { |
| 83 | perl -0pe "$2" seed/text/text.om > "$T/boundary-mut.om" |
| 84 | cmp -s seed/text/text.om "$T/boundary-mut.om" && bad "boundary mutant $1 did not apply" |
| 85 | cat seed/text/tests/boundaries.om "$T/boundary-mut.om" > "$T/boundary-mut.src" |
| 86 | "$S" < "$T/boundary-mut.src" > "$T/boundary-mut" 2> "$T/build.err" || bad "boundary mutant did not compile: $(cat "$T/build.err")" |
| 87 | chmod +x "$T/boundary-mut" |
| 88 | st=0 |
| 89 | "$T/boundary-mut" "$3" > "$T/boundary-mut.out" 2> "$T/boundary-mut.err" || st=$? |
| 90 | [ "$st" = 0 ] && [ ! -s "$T/boundary-mut.out" ] && [ ! -s "$T/boundary-mut.err" ] || bad "boundary mutant $1 did not produce its expected wrong clean return ($st)" |
| 91 | m=$((m + 1)); printf 'PASS boundary mutant caught: %s (original 103, mutant 0)\n' "$1" |
| 92 | } |
| 93 | boundary_mutant "offset guard removed" 's/if gt o l\ntrap 3\nend\n//' 1 |
| 94 | boundary_mutant "length guard removed" 's/if gt n sub l o\ntrap 3\nend\n//' 2 |
| 95 | printf 'TEXTGATE PASS rows=%s mutants=%s boundaries=%s\n' "$rows" "$m" "$boundaries" |