interplane.Get Omega
Read in your language

omega-mcp

aien-dev/omega-mcp

Brought by drakestapleton

branch main Branches Tags History

omega-mcp / gates / pincheck-cases.sh

77 lines · 4417 bytes Raw Blame History
1#!/bin/sh
2# gates/pincheck-cases.sh : cases for build/pincheck (gates/pincheck.om). Run in the repository root
3# after build.sh (it uses build/pincheck and build/omc). Two scratch directories: the first has a
4# copy of PIN, and a file restating the first 8 characters of the revision and one restating the omc
5# sha256 are each refused (exit 1). The second has a fixture PIN whose revision and sha256 both
6# start with 8 digits, so these hold at any real pin: the all-digit 8-character prefixes, 12- and
7# 16-character prefixes, an upper-case prefix and both full values are each refused (exit 1), as is
8# another hash-like word (the general rule); dates, counts, 8-digit near misses of the prefixes and the
9# hex alphabet pass (exit 0). Five mutants of gates/pincheck.om (a restating word must hold a letter
10# again, prefixes shorter than 9 ignored, only the first character compared, the sha256 compared at
11# the revision's offset, no A-F folding) are compiled with build/omc and each must get at least one
12# fixture case wrong. Prints PASS/FAIL per case and `pincheck-cases: pass=N fail=M`; exit 0 only when
13# every case gives its expected result.
14set -u
15R=$(cd "$(dirname "$0")/.." && pwd)
16P=$R/build/pincheck
17O=$R/build/omc
18[ -x "$P" ] && [ -x "$O" ] || { echo "pincheck-cases: run sh build.sh first" >&2; exit 2; }
19W=$(mktemp -d "${TMPDIR:-/tmp}/pincheck-cases.XXXXXX") || exit 2
20trap 'rm -rf "$W"' EXIT
21pass=0 fail=0
22ok() { echo "PASS $*"; pass=$((pass + 1)); }
23bad() { echo "FAIL $*"; fail=$((fail + 1)); }
24want() { # want NAME RC DIR FILE
25 out=$(cd "$3" && echo "$4" | "$P" 2>&1); rc=$?
26 if [ $rc -eq "$2" ]; then ok "$1 (exit $rc)"; else bad "$1: exit $rc, want $2: $out"; fi
27}
28rev=$(sed -n 's/^omega-mv //p' "$R/PIN")
29sha=$(sed -n 's/^omc-sha256 //p' "$R/PIN")
30mkdir -p "$W/c"
31cp "$R/PIN" "$W/c/PIN"
32printf 'built with omega-mv %s\n' "$(echo "$rev" | cut -c1-8)" > "$W/c/rev.md"
33printf 'omc sha256 %s\n' "$sha" > "$W/c/sha.md"
34want control-rev 1 "$W/c" rev.md
35want control-sha 1 "$W/c" sha.md
36# fixture values built from short pieces, so this file names no 7-character word of them
37d8=$((2718 * 10000 + 2818))
38s8=$((3141 * 10000 + 5926))
39drev=$d8$(printf %s 0a1b 2c3d 4e5f 6a7b 8c9d 0e1f 2a3b 4c5d)
40dsha=$s8$(printf %s 5e6f 7a8b 9c0d 1e2f 3a4b 5c6d 7e8f 9a0b 1c2d 3e4f 5a6b 7c8d 9e0f 1a2b)
41mkdir -p "$W/d"
42printf 'omega-mv %s\nomc-sha256 %s\n' "$drev" "$dsha" > "$W/d/PIN"
43printf 'built with omega-mv %s\n' "$d8" > "$W/d/r8.md"
44printf 'omc %s (sha256 prefix)\n' "$s8" > "$W/d/s8.md"
45printf 'rev %s\n' "$(echo "$drev" | cut -c1-12)" > "$W/d/r12.md"
46printf 'omc %s\n' "$(echo "$dsha" | cut -c1-16)" > "$W/d/s16.md"
47printf 'omega-mv %s\n' "$drev" > "$W/d/rfull.md"
48printf 'omc-sha256 %s\n' "$dsha" > "$W/d/sfull.md"
49printf 'REV %s\n' "$(echo "$drev" | cut -c1-12 | tr a-f A-F)" > "$W/d/upper.md"
50printf 'an older compiler %s\n' "$(printf %s c0ff ee12)" > "$W/d/other.md"
51printf 'landed %s, %s rows; %s and %s are not the pin; %s\n' $((2026 * 10000 + 1111)) $((1000 * 10000)) \
52 $((d8 + 1)) $((s8 + 1)) "$(printf %s 0123 4567 89ab cdef)" > "$W/d/numbers.md"
53cases="r8:1 s8:1 r12:1 s16:1 rfull:1 sfull:1 upper:1 other:1 numbers:0"
54for c in $cases; do want "fixture-${c%:*}" "${c#*:}" "$W/d" "${c%:*}.md"; done
55wrong() { # wrong BIN: the fixture cases BIN gets wrong
56 for c in $cases; do
57 (cd "$W/d" && echo "${c%:*}.md" | "$1" > /dev/null 2>&1); rc=$?
58 [ $rc -eq "${c#*:}" ] || printf '%s ' "${c%:*}"
59 done
60}
61mutant() { # mutant NAME SED-ARGS...: compile gates/pincheck.om edited by sed; it must be caught
62 n=$1; shift
63 sed "$@" "$R/gates/pincheck.om" > "$W/$n.om"
64 if cmp -s "$R/gates/pincheck.om" "$W/$n.om"; then bad "mutant $n: the edit did not apply"; return; fi
65 "$O" < "$W/$n.om" > "$W/$n" 2> "$W/$n.err"
66 if [ $? -ne 0 ] || [ -s "$W/$n.err" ]; then bad "mutant $n does not compile: $(cat "$W/$n.err")"; return; fi
67 chmod +x "$W/$n"
68 got=$(wrong "$W/$n")
69 if [ -n "$got" ]; then ok "mutant $n caught by: $got"; else bad "mutant $n passes every fixture case"; fi
70}
71mutant m-letter -e 's/^if eq get st q_hexf 0$/if or eq get st q_hexf 0 or eq get st q_dig 0 eq get st q_let 0/'
72mutant m-floor -e 's/^if lt n 7$/if lt n 9/'
73mutant m-first -e 's/^if ne get tok i get pin add o i$/if ne get tok 0 get pin o/'
74mutant m-shaoff -e 's/^r = tokat 61 n$/r = tokat 9 n/'
75mutant m-nofold -e 's/^d = add c 32$/d = c/'
76echo "pincheck-cases: pass=$pass fail=$fail"
77[ $fail -eq 0 ] && [ $pass -eq 16 ]