interplane.Get Omega
Read in your language

cortex

aien-dev/cortex

Brought by drakestapleton

branch main Branches Tags History

cortex / tests / pin / run.sh

92 lines · 5405 bytes Raw Blame History
1#!/bin/sh
2# tests/pin/run.sh : the one-pin gate. PIN is the only place the compiler pin is written;
3# tools/omc.sh, build.sh's SHA256SUMS line, the gate labels and CI read it, and build/pincheck
4# (tools/pincheck.om, compiled by build.sh) refuses a tracked file that restates it.
5# sh tests/pin/run.sh (after sh build.sh)
6# Cases: the tree passes (rc 0); controls in a scratch directory with a copy of PIN: a file that
7# restates the revision prefix and one that restates the omc sha256 are each refused (rc 1), a
8# file under evidence/ that names the pin is not judged (rc 0), a malformed PIN is refused (rc 2);
9# and tools/omc.sh refuses an OMC whose sha256 differs from PIN (rc 1). A second scratch directory
10# has a fixture PIN whose revision and sha256 both start with 8 digits, so these hold at any real pin:
11# the all-digit 8-character prefixes, 12- and 16-character prefixes, an upper-case prefix and both
12# full values are each refused (rc 1); dates, counts and 8-digit near misses of the prefixes pass
13# (rc 0). Five mutants of tools/pincheck.om (a word must hold a letter again, prefixes shorter than 9
14# ignored, only the first character compared against the revision or against the sha256, no A-F
15# folding) are compiled with the pinned omc and each must get at least one fixture case wrong.
16# Exit 0 only when every case gives its expected result.
17set -u
18R=$(cd "$(dirname "$0")/../.." && pwd)
19W=${WORK:-$R/build/pin-work}
20P=$R/build/pincheck
21[ -x "$P" ] || { echo "pin: build first (sh build.sh)" >&2; exit 2; }
22rm -rf "$W" && mkdir -p "$W" || exit 2
23pass=0 fail=0
24ok() { echo "PASS $*"; pass=$((pass + 1)); }
25bad() { echo "FAIL $*"; fail=$((fail + 1)); }
26want() { # want NAME RC DIR FILES...
27 n=$1 w=$2 d=$3; shift 3
28 out=$(cd "$d" && printf '%s\n' "$@" | "$P" 2>&1); rc=$?
29 if [ $rc -eq "$w" ]; then ok "$n (rc $rc): $(echo "$out" | tail -n 1)"; else bad "$n: rc $rc, want $w: $out"; fi
30}
31want tree 0 "$R" $(cd "$R" && git ls-files)
32rev=$(awk '$1 == "omega-mv" { print $2 }' "$R/PIN")
33sha=$(awk '$1 == "omc-sha256" { print $2 }' "$R/PIN")
34mkdir -p "$W/c/evidence"
35cp "$R/PIN" "$W/c/PIN"
36printf 'built with omega-mv %s\n' "$(echo "$rev" | cut -c1-8)" > "$W/c/rev.md"
37printf 'omc sha256 %s (copied)\n' "$sha" > "$W/c/sha.md"
38printf 'this run used omc %s\n' "$sha" > "$W/c/evidence/run.log"
39printf 'no pin here: 91b3c932 is an older revision\n' > "$W/c/old.md"
40want control-rev 1 "$W/c" rev.md
41want control-sha 1 "$W/c" sha.md
42want evidence-not-judged 0 "$W/c" evidence/run.log
43want other-hash-not-judged 0 "$W/c" old.md
44mkdir -p "$W/m"
45printf 'omega-mv %s\n' "$(echo "$rev" | cut -c1-8)" > "$W/m/PIN"
46want malformed-pin 2 "$W/m" PIN
47# fixture values built from short pieces, so this file names no 7-character word of them
48d8=$((2718 * 10000 + 2818))
49s8=$((3141 * 10000 + 5926))
50drev=$d8$(printf %s 0a1b 2c3d 4e5f 6a7b 8c9d 0e1f 2a3b 4c5d)
51dsha=$s8$(printf %s 5e6f 7a8b 9c0d 1e2f 3a4b 5c6d 7e8f 9a0b 1c2d 3e4f 5a6b 7c8d 9e0f 1a2b)
52mkdir -p "$W/d"
53printf 'omega-mv %s\nomc-sha256 %s\n' "$drev" "$dsha" > "$W/d/PIN"
54printf 'built with omega-mv %s\n' "$d8" > "$W/d/r8.md"
55printf 'omc %s (sha256 prefix)\n' "$s8" > "$W/d/s8.md"
56printf 'rev %s\n' "$(echo "$drev" | cut -c1-12)" > "$W/d/r12.md"
57printf 'omc %s\n' "$(echo "$dsha" | cut -c1-16)" > "$W/d/s16.md"
58printf 'omega-mv %s\n' "$drev" > "$W/d/rfull.md"
59printf 'omc-sha256 %s\n' "$dsha" > "$W/d/sfull.md"
60printf 'REV %s\n' "$(echo "$drev" | cut -c1-12 | tr a-f A-F)" > "$W/d/upper.md"
61printf 'landed %s, %s rows; %s and %s are not the pin\n' $((2026 * 10000 + 1111)) $((1000 * 10000)) $((d8 + 1)) $((s8 + 1)) > "$W/d/numbers.md"
62cases="r8:1 s8:1 r12:1 s16:1 rfull:1 sfull:1 upper:1 numbers:0"
63for c in $cases; do want "fixture-${c%:*}" "${c#*:}" "$W/d" "${c%:*}.md"; done
64wrong() { # wrong BIN: the fixture cases BIN gets wrong
65 for c in $cases; do
66 (cd "$W/d" && echo "${c%:*}.md" | "$1" > /dev/null 2>&1); rc=$?
67 [ $rc -eq "${c#*:}" ] || printf '%s ' "${c%:*}"
68 done
69}
70OMC=$(sh "$R/tools/omc.sh") || exit 2
71mutant() { # mutant NAME SED-ARGS...: compile tools/pincheck.om edited by sed; it must be caught
72 n=$1; shift
73 sed "$@" "$R/tools/pincheck.om" > "$W/$n.om"
74 if cmp -s "$R/tools/pincheck.om" "$W/$n.om"; then bad "mutant $n: the edit did not apply"; return; fi
75 { echo om2; cat "$W/$n.om"; } | "$OMC" > "$W/$n" 2> "$W/$n.err"
76 if [ $? -ne 0 ] || [ -s "$W/$n.err" ]; then bad "mutant $n does not compile: $(cat "$W/$n.err")"; return; fi
77 chmod +x "$W/$n"
78 got=$(wrong "$W/$n")
79 if [ -n "$got" ]; then ok "mutant $n caught by: $got"; else bad "mutant $n passes every fixture case"; fi
80}
81mutant m-letter -e 's/^if eq get st q_hex 1$/if and eq get st q_hex 1 hasletter/' \
82 -e '/^fn endword to void$/i fn hasletter to bool\nfor i ulong 64\nif ge i get st q_len\nbreak\nend\nif gt get tok i 57\nret true\nend\nend\nret false\nend'
83mutant m-floor -e 's/^if lt n 7$/if lt n 9/'
84mutant m-revfirst -e 's/^if ne get tok i get rev i$/if ne get tok 0 get rev 0/'
85mutant m-shafirst -e 's/^if ne get tok i get sha i$/if ne get tok 0 get sha 0/'
86mutant m-nofold -e 's/^d = add c 32$/d = c/'
87printf 'not a compiler\n' > "$W/fake-omc"
88if OMC=$W/fake-omc sh "$R/tools/omc.sh" > /dev/null 2>&1; then bad "omc.sh accepted a binary whose sha256 is not the one in PIN"
89else ok "omc.sh refuses a binary whose sha256 is not the one in PIN"; fi
90rm -rf "$W"
91echo "pin: pass=$pass fail=$fail"
92[ $fail -eq 0 ] && [ $pass -eq 20 ]