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 / tilelab / gate.sh
| 1 | #!/bin/sh |
| 2 | # seed/tilelab/gate.sh -- host gate for the native .om tile planner and streaming-softmax algebra. |
| 3 | # Run from the repo root after seed/omega-from-seed.sh: sh seed/tilelab/gate.sh |
| 4 | # Compiles seed/tilelab/tilelab.om with seed/out/omc (sha checked against seed/out/omc.sha256), runs every |
| 5 | # case in seed/tilelab/cases.txt, and requires stdout and exit status to equal seed/tilelab/expected.txt |
| 6 | # byte for byte. expected.txt is the program's frozen output (a regression pin); the planner picks, bytes, |
| 7 | # costs, direct value and softmax error figures in it were reproduced independently in Wolfram Language |
| 8 | # (seed/tilelab/WOLFRAM.md lists each value and query; the rest is pinned, not verified). Then checks that each softmax mutant fails for its own reason: |
| 9 | # mut 1 only on one_err, mut 2 on seq_err and tree_err, mut 3 only on tree_err. |
| 10 | # Prints PASS tilelab and exits 0, or FAIL and exits 1. |
| 11 | set -eu |
| 12 | R=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd) |
| 13 | cd "$R" |
| 14 | D=seed/tilelab |
| 15 | B=build/seed/tilelab |
| 16 | mkdir -p "$B" |
| 17 | bad() { printf 'FAIL tilelab: %s\n' "$*" >&2; exit 1; } |
| 18 | |
| 19 | want=$(cut -c1-64 seed/out/omc.sha256) |
| 20 | have=$(sha256sum < seed/out/omc | cut -c1-64) |
| 21 | [ "$want" = "$have" ] || bad "seed/out/omc is $have, omc.sha256 says $want" |
| 22 | seed/out/omc < "$D/tilelab.om" > "$B/tilelab" || bad "omc refused tilelab.om" |
| 23 | chmod +x "$B/tilelab" |
| 24 | printf 'omc %s\ntilelab %s\n' "$have" "$(sha256sum < "$B/tilelab" | cut -c1-64)" |
| 25 | |
| 26 | : > "$B/observed.txt" |
| 27 | while IFS= read -r args; do |
| 28 | case "$args" in ''|'#'*) continue ;; esac |
| 29 | # word splitting of $args is intended: each line is one argument vector |
| 30 | # shellcheck disable=SC2086 |
| 31 | out=$("$B/tilelab" $args | grep -v '^cfg ' || true) |
| 32 | # shellcheck disable=SC2086 |
| 33 | "$B/tilelab" $args > /dev/null && rc=0 || rc=$? |
| 34 | printf '$ tilelab %s\n%s\nrc=%s\n' "$args" "$out" "$rc" >> "$B/observed.txt" |
| 35 | done < "$D/cases.txt" |
| 36 | # the picked cfg row with its byte model, per planner shape (checked against Wolfram) |
| 37 | for s in "1024 1024 1024" "4096 4096 4096" "2048 8192 2048" "100 100 100" "8192 8192 8192"; do |
| 38 | # shellcheck disable=SC2086 |
| 39 | p=$("$B/tilelab" 1 $s | sed -n 's/^pick cfg \(rt=[0-9]* ct=[0-9]* wm=[0-9]* wn=[0-9]* band=[0-9]*\)$/\1 /p') |
| 40 | # shellcheck disable=SC2086 |
| 41 | "$B/tilelab" 1 $s | grep "^cfg $p" | head -n 1 | sed "s/^/row $s: /" >> "$B/observed.txt" |
| 42 | done |
| 43 | cmp -s "$B/observed.txt" "$D/expected.txt" || { diff "$D/expected.txt" "$B/observed.txt" >&2 || true; bad "output differs from expected.txt"; } |
| 44 | |
| 45 | col() { "$B/tilelab" 2 "$1" | sed -n "s/.* $2=\([0-9]*\).*/\1/p"; } |
| 46 | tol=2000000 |
| 47 | over() { [ "$(col "$1" "$2")" -gt "$tol" ]; } |
| 48 | over 0 seq_err_ppt && bad "mut 0 seq_err over tolerance" |
| 49 | over 0 tree_err_ppt && bad "mut 0 tree_err over tolerance" |
| 50 | over 1 seq_err_ppt && bad "mut 1 fails for a reason other than tile-local normalisation" |
| 51 | over 1 one_err_ppt || bad "mut 1 one_err not over tolerance" |
| 52 | over 2 seq_err_ppt || bad "mut 2 seq_err not over tolerance" |
| 53 | over 2 tree_err_ppt || bad "mut 2 tree_err not over tolerance" |
| 54 | over 3 seq_err_ppt && bad "mut 3 fails for a reason other than tree order" |
| 55 | over 3 tree_err_ppt || bad "mut 3 tree_err not over tolerance" |
| 56 | # All representable unsigned budgets remain valid, including the former failure sentinel. |
| 57 | "$B/tilelab" 1 8 8 8 18446744073709551615 > "$B/max-regs.txt" || bad "maximum ulong REGS refused" |
| 58 | grep -q '^pick cfg ' "$B/max-regs.txt" || bad "maximum ulong REGS did not produce a plan" |
| 59 | if "$B/tilelab" 1 8 8 8 "" > "$B/empty-regs.txt"; then rc=0; else rc=$?; fi |
| 60 | [ "$rc" -eq 3 ] || bad "empty REGS returned $rc, wanted usage refusal 3" |
| 61 | printf 'tilelab: usage: tilelab 1 M N K [REGS] | tilelab 2 [MUT]\n' > "$B/usage.txt" |
| 62 | cmp -s "$B/empty-regs.txt" "$B/usage.txt" || bad "empty REGS emitted a plan or unexpected diagnostic" |
| 63 | |
| 64 | # The .om fixture removes one guard at a time; both controls must actually compile and |
| 65 | # produce a successful plan for the otherwise-refused audit input (not merely fail). |
| 66 | seed/out/omc < "$D/parser_mutant.om" > "$B/parser-mutant" || bad "omc refused parser_mutant.om" |
| 67 | chmod +x "$B/parser-mutant" |
| 68 | for mut in 1 2; do |
| 69 | "$B/parser-mutant" "$mut" < "$D/tilelab.om" > "$B/mutant-$mut.om" || bad "could not remove parser guard $mut" |
| 70 | seed/out/omc < "$B/mutant-$mut.om" > "$B/mutant-$mut" || bad "omc refused parser mutant $mut" |
| 71 | chmod +x "$B/mutant-$mut" |
| 72 | if [ "$mut" -eq 1 ]; then |
| 73 | "$B/mutant-$mut" 1 18446744073709551617 8 8 > "$B/mutant-$mut.txt" || bad "overflow control did not reach the planner" |
| 74 | else |
| 75 | "$B/mutant-$mut" 1 1024 1024 1024 extra > "$B/mutant-$mut.txt" || bad "REGS control did not reach the planner" |
| 76 | fi |
| 77 | grep -q '^pick cfg ' "$B/mutant-$mut.txt" || bad "parser control $mut did not restore invalid-input acceptance" |
| 78 | done |
| 79 | printf 'PASS tilelab %s cases, 3/3 softmax mutants fail for the intended reason, 2/2 parser guards challenged\n' "$(grep -c '^\$ ' "$B/observed.txt")" |