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/om/meaning/test/run.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 / om / meaning / test / run.sh` 165 lines ยท 6543 bytes Raw Blame History 1 #!/bin/sh 2 # SPDX-License-Identifier: Apache-2.0 3 # Test suite for om/meaning/meaning.om (FUNCTION_ID and the graph of meaning). Usage (from the 4 # omega-mv root): 5 # sh om/meaning/test/run.sh seed/out/omc 6 # Builds into build/meaning/. Exits 0 only when every vector passes, the FUNCTION_ID goldens match an 7 # independent sha256sum of the spec section 9.3 preimage, and every mutant and negative control is 8 # detected. Final line: MEANING PASS checks=N mutants=M/M, or MEANING FAIL. 9 set -eu 10 omc=${1:?usage: run.sh OMC} 11 here=$(cd "$(dirname "$0")" && pwd) 12 lib=$(cd "$here/.." && pwd) 13 root=$(cd "$lib/../.." && pwd) 14 out="$root/build/meaning" 15 vec="$here/vectors" 16 sha2="$root/om/tls/sha2.om" 17 mkdir -p "$out" 18 nice="nice -n 19 ionice -c3" 19 checks=0 20 mut=0 21 mutok=0 22 bad=0 23 24 say() { printf '%s\n' "$*"; } 25 fail() { say "FAIL $*"; bad=1; } 26 27 # build LIB BIN: om2 line, sha2.om, LIB, the driver; compile with omc 28 build() { 29 { printf 'om2\n'; cat "$sha2" "$1" "$here/driver.om"; } > "$2.om" 30 if ! $nice "$omc" < "$2.om" > "$2" 2> "$2.err" || [ -s "$2.err" ]; then 31 say "omc refused $2.om: $(cat "$2.err")" 32 return 1 33 fi 34 chmod +x "$2" 35 } 36 37 # summary LINE -> "N F" when LINE is a complete driver summary 38 summary() { 39 printf '%s\n' "$1" | awk '$1 == "meaning" && $2 == "driver:" && $4 == "checks," && $6 == "failed" { print $3, $5 }' 40 } 41 42 # detected NAME FILE BIN: BIN reported a difference (exit 1 with F > 0 failures) or refused the 43 # input with a trap (exit 100..199); a signal (128+N within that range is not produced by omc 44 # binaries, which trap through exit) or exit 0 is not detection 45 detected() { 46 set +e 47 $nice "$3" < "$2" > "$out/$1.out" 2>&1 48 rc=$? 49 set -e 50 last=$(tail -n 1 "$out/$1.out") 51 s=$(summary "$last") 52 f=${s#* } 53 if [ "$rc" -eq 1 ] && [ -n "$s" ] && [ "$f" -gt 0 ]; then 54 say "PASS $1: detected ($(grep -c '^FAIL' "$out/$1.out") FAIL lines, first: $(grep -m 1 '^FAIL' "$out/$1.out"))" 55 return 0 56 fi 57 if [ "$rc" -ge 100 ] && [ "$rc" -le 127 ]; then 58 say "PASS $1: detected (trap, exit $rc)" 59 return 0 60 fi 61 fail "$1: not detected: exit $rc: $last" 62 return 1 63 } 64 65 # mutant NAME SED_EXPR: apply SED_EXPR to meaning.om, rebuild, require detection on the vectors 66 mutant() { 67 mut=$((mut + 1)) 68 sed "$2" "$lib/meaning.om" > "$out/mut-$1.om.lib" 69 if cmp -s "$lib/meaning.om" "$out/mut-$1.om.lib"; then 70 fail "$1: sed changed nothing" 71 return 72 fi 73 build "$out/mut-$1.om.lib" "$out/mut-$1" || { fail "$1: mutant did not compile"; return; } 74 if detected "mutant-$1" "$vec" "$out/mut-$1"; then 75 mutok=$((mutok + 1)) 76 fi 77 } 78 79 # fid W K C... -> SHA-256 of "omega.function.v1" 0x00 || 01 || W u16 || K u16 || C u64 BE each 80 fid() { 81 w=$1 82 k=$2 83 shift 2 84 { 85 printf 'omega.function.v1\000\001' 86 printf '%04x%04x' "$w" "$k" | xxd -r -p 87 for c in "$@"; do printf '%016x' "$c" | xxd -r -p; done 88 } | sha256sum | cut -d' ' -f1 89 } 90 zeros() { i=0; while [ "$i" -lt "$1" ]; do printf ' 0'; i=$((i + 1)); done; } 91 92 build "$lib/meaning.om" "$out/driver" || { say "MEANING FAIL build"; exit 1; } 93 say "omc sha256 $(sha256sum "$omc" | cut -d' ' -f1)" 94 say "sha2.om sha256 $(sha256sum "$sha2" | cut -d' ' -f1)" 95 say "meaning.om sha256 $(sha256sum "$lib/meaning.om" | cut -d' ' -f1)" 96 say "driver.om sha256 $(sha256sum "$here/driver.om" | cut -d' ' -f1)" 97 say "vectors sha256 $(sha256sum "$vec" | cut -d' ' -f1)" 98 99 # FUNCTION_ID goldens in the vectors must equal the independently built preimage hashes 100 # (x + 2 at w 64: a = 2 1 0...; zero at w 64: 66 zeros; 3x^3 + 5x + 7 at w 8: a = 7 8 9 3 0 0 0 0 0 0, 101 # the coefficient vector computed by Wolfram, spec section 9.2) 102 g1=$(fid 64 66 2 1 $(zeros 64)) 103 g2=$(fid 64 66 $(zeros 66)) 104 g3=$(fid 8 10 7 8 9 3 0 0 0 0 0 0) 105 for want in "H 0 $g1" "H 2 $g1" "H 8 $g2" "H 9 $g2" "H 19 $g3"; do 106 if grep -qx "$want" "$vec"; then 107 say "PASS golden: $want" 108 else 109 fail "golden: vectors lack \"$want\"" 110 fi 111 done 112 113 # the vectors 114 set +e 115 $nice "$out/driver" < "$vec" > "$out/vectors.out" 2>&1 116 rc=$? 117 set -e 118 last=$(tail -n 1 "$out/vectors.out") 119 s=$(summary "$last") 120 if [ "$rc" -eq 0 ] && [ -n "$s" ] && [ "${s#* }" = 0 ] && [ "${s% *}" -gt 0 ]; then 121 checks=${s% *} 122 grep '^[RG] ' "$out/vectors.out" | while IFS= read -r l; do say " $l"; done 123 say "PASS vectors: $last" 124 else 125 fail "vectors: exit $rc: $(tail -n 5 "$out/vectors.out" | tr '\n' ' ')" 126 fi 127 128 # source mutants: each must be detected by the vectors 129 # K one too small: x(x-1)...(x-8) and 0 at w 8 collapse, the iff check sees equal ids for different functions 130 mutant kof-minus-1 's/^kk = mg_kof w$/kk = sub mg_kof w 1/' 131 # Newton inverse with 4 steps (48 bits): wrong coefficients at w 64, reconstruction fails 132 mutant inverse-4-steps 's/^for i ulong 5$/for i ulong 4/' 133 # Newton inverse started from 1 instead of u (1 correct bit, 32 after 5 steps) 134 mutant inverse-start-1 's/^y = u$/y = ulong 1/' 135 # and with the all-ones constant no longer recognised: x and 255 at w 8 falls back, C 15 16 fails 136 mutant and-ones-dropped '/^if eq o 9$/,/^end$/s/^if eq c m$/if lt c 0/' 137 # and with 1 accepted as the identity: x and 1 treated as x, the iff check or the canon trap fires 138 mutant and-one-accepted '/^if eq o 9$/,/^end$/s/^if eq c m$/if eq c 1/' 139 # ApplyPayload size 161 -> 160: program_id goldens fail 140 mutant apply-payload-160 's/^mg_b32 161$/mg_b32 160/' 141 # storage sort comparator always "not greater": reverse rebuild bytes differ or load refuses order 142 mutant sort-cmp-never '/^fn mg_gt /,/^fn mg_sget /s/^ret 1$/ret 0/' 143 # FUNCTION_ID domain tag changed: the independent goldens fail 144 mutant fid-domain 's/^text mgtfd "omega.function.v1"$/text mgtfd "omega.function.v2"/' 145 146 # expectation mutants: a must-not-collapse pair asserted equal, a must-collapse pair asserted 147 # different, each must fail exactly the changed record 148 mut=$((mut + 1)) 149 sed 's/^N 1 3$/C 1 3/' "$vec" > "$out/mut-expect-c.txt" 150 if cmp -s "$vec" "$out/mut-expect-c.txt"; then fail "expect-c changed nothing" 151 elif detected mutant-expect-c "$out/mut-expect-c.txt" "$out/driver"; then mutok=$((mutok + 1)); fi 152 mut=$((mut + 1)) 153 sed 's/^C 0 1$/N 0 1/' "$vec" > "$out/mut-expect-n.txt" 154 if cmp -s "$vec" "$out/mut-expect-n.txt"; then fail "expect-n changed nothing" 155 elif detected mutant-expect-n "$out/mut-expect-n.txt" "$out/driver"; then mutok=$((mutok + 1)); fi 156 157 # negative control: a refused program defined with D is reported (pchk code 4: constant 256 at w 8) 158 printf 'D 8 x 256 add\n' > "$out/neg-define.txt" 159 detected neg-define "$out/neg-define.txt" "$out/driver" || true 160 161 if [ "$bad" -ne 0 ]; then 162 say "MEANING FAIL checks=$checks mutants=$mutok/$mut" 163 exit 1 164 fi 165 say "MEANING PASS checks=$checks mutants=$mutok/$mut"