interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / seed / rung3 / gate3.sh

99 lines · 5952 bytes Raw Blame History
1#!/bin/sh
2# gate3.sh -- the checks of rung 3 (seed/README.md). Run from the repo root: sh seed/rung3/gate3.sh
3# Needs build/omegese/omegese and build/omega_emit/omega_emit (the C path, built by make through
4# quiet-build) and cc for the reference runner. Nothing here writes a byte of seed/ except om3.bin,
5# which only asm2 makes. Results: build/seed/r3/evidence/. The recorded receipt evidence/SEED-0/rung3/ (and
6# seed/rung3/om3.audit) is only read: the results are compared with it at the end (seed/check/receipt.sh),
7# never written over it.
8set -eu
9R=seed/rung3; B=build/seed/r3; E=$B/evidence; REC=evidence/SEED-0/rung3
10T=tests/one_layer/exp445/dev/tasks/cases; O=tests/one_layer/omegese/dev
11mkdir -p "$B" "$E"
12fail=0
13say() { printf '%s\n' "$*" | tee -a "$E/gate3.log"; }
14bad() { say "FAIL: $*"; fail=1; }
15: > "$E/gate3.log"
16say "gate3 $(date -u +%FT%TZ) at $(git rev-parse HEAD)"
17
18# 1. asm2 builds om3; a second build gives the same bytes; the file-size field matches the file
19cat seed/rung2/table.s2 $R/table3.s2 $R/om3.s | seed/rung2/asm2.bin > $R/om3.bin
20cat seed/rung2/table.s2 $R/table3.s2 $R/om3.s | seed/rung2/asm2.bin > $B/om3.again
21chmod +x $R/om3.bin
22cmp -s $R/om3.bin $B/om3.again && say "PASS om3.bin built by asm2 twice, same bytes" || bad "two builds differ"
23size=$(stat -c %s $R/om3.bin)
24fsz=$(od -An -tu4 -j96 -N4 $R/om3.bin | tr -d ' ')
25[ "$size" = "$fsz" ] && say "PASS p_filesz $fsz = file size $size" || bad "p_filesz $fsz, file $size"
26sha256sum $R/om3.bin | tee "$E/om3.sha256" >> "$E/gate3.log"
27
28# 2. every instruction of om3 decodes (objdump, reference) to its name, registers, numbers, label
29if sh seed/check/audit2.sh $R/om3.s $R/om3.bin > $E/om3.audit; then :; fi
30tail -1 $E/om3.audit | tee -a "$E/gate3.log" | grep -q 'mismatch=0$' && say "PASS audit (objdump reference run)" || bad "audit"
31# controls: a wrong name, register, label and number in the text must each be caught
32for c in 's/^ add.x x12 x12 x0$/ sub.x x12 x12 x0/' 's/^ mov.x x21 x20$/ mov.x x21 x19/' \
33 's/^ b RD$/ b RDDONE/' 's/^ ubfm.x x1 x1 54 53$/ ubfm.x x1 x1 54 52/' \
34 's/^ str.x x12 sp 0$/ str.x x12 sp 1/'; do
35 sed "$c" $R/om3.s > $B/bad.s
36 if cmp -s $B/bad.s $R/om3.s; then bad "control edit did nothing: $c"
37 elif sh seed/check/audit2.sh $B/bad.s $R/om3.bin > $B/bad.audit; then bad "control not caught: $c"
38 else say "PASS control caught ($c): $(tail -1 $B/bad.audit)"; fi
39done
40
41# 3. the reference runner (seed/check/runner.c, links the repo C path: osc_ir decode, osc_cg, osc_rt)
42cc -O1 -Isrc -Isrc/compiler -o $B/runner seed/check/runner.c \
43 $(ls src/compiler/*.c | grep -v oscc_main.c) src/omega_om_units.c
44[ -x build/omegese/omegese ] && [ -x build/omega_emit/omega_emit ] || { bad "C path tools not built"; exit 1; }
45
46# 4. the 10 dev tasks: same results as the C path and as the expected file; word counts
47tab="$E/words.tsv"
48printf 'task\tentry\tinputs\tc_path_words\tseed_words\tseed_minus_c\n' > "$tab"
49tot_c=0; tot_s=0
50for d in dev01 dev02 dev03 dev04 dev05 dev06 dev07 dev08 dev09 dev10; do
51 entry=$(awk '$1=="entry"{print $2}' $T/$d/requirement)
52 build/omegese/omegese emit $O/$d.omegese $B/$d.json > /dev/null
53 build/omega_emit/omega_emit emit $B/$d.json $B/$d.oscir > /dev/null
54 $R/om3.bin < $O/$d.omegese > $B/$d.seed.bin
55 $B/runner $B/$d.oscir "$entry" $T/$d/hidden/inputs > $B/$d.c.out
56 $B/runner $B/$d.oscir "$entry" $T/$d/hidden/inputs $B/$d.seed.bin > $B/$d.seed.out
57 cw=$(sed -n 's/^words //p' $B/$d.c.out); sw=$(sed -n 's/^words //p' $B/$d.seed.out)
58 n=$(wc -l < $T/$d/hidden/inputs)
59 tail -n +2 $B/$d.c.out > $B/$d.c.res; tail -n +2 $B/$d.seed.out > $B/$d.seed.res
60 cut -f1 $B/$d.seed.res > $B/$d.seed.val
61 if cmp -s $B/$d.c.res $B/$d.seed.res; then say "PASS $d: $n inputs, seed = C path (value and raw x0)"
62 else bad "$d differs from the C path"; diff $B/$d.c.res $B/$d.seed.res | head -5 >> "$E/gate3.log"; fi
63 cmp -s $B/$d.seed.val $T/$d/hidden/expected && say "PASS $d: seed = expected" || bad "$d differs from expected"
64 grep -q NONCANONICAL $B/$d.seed.res && bad "$d: a result not in canonical form" || true
65 # every word the seed chain made is an instruction (objdump, reference)
66 objdump -D -z -b binary -m aarch64 -M no-aliases $B/$d.seed.bin | grep -E '^ +[0-9a-f]+:' > $B/$d.seed.dis
67 if grep -qE ' (udf|\.inst|undefined)' $B/$d.seed.dis; then bad "$d: a word that is not an instruction"; fi
68 cp $B/$d.seed.bin $E/$d.seed.bin; cp $B/$d.seed.dis $E/$d.seed.dis
69 cp $B/$d.seed.out $E/$d.seed.out; cp $B/$d.c.out $E/$d.c.out
70 printf '%s\t%s\t%s\t%s\t%s\t%s\n' $d "$entry" $n $cw $sw $((sw - cw)) >> "$tab"
71 tot_c=$((tot_c + cw)); tot_s=$((tot_s + sw))
72done
73printf 'total\t\t\t%s\t%s\t%s\n' $tot_c $tot_s $((tot_s - tot_c)) >> "$tab"
74cat "$tab" >> "$E/gate3.log"
75
76# 5. om3 refuses what is outside the subset or wrong, each with its own code
77t() { # expected-code text
78 printf '%b' "$2" > $B/ctl.omegese
79 set +e; $R/om3.bin < $B/ctl.omegese > $B/ctl.bin 2> $B/ctl.err; rc=$?; set -e
80 [ "$rc" = "$1" ] && say "PASS control exit $rc: $(cat $B/ctl.err)" || bad "control wanted exit $1, got $rc: $2"
81}
82t 3 'fn f a uint to uint\nret add a q\nend\n'
83t 4 'fn f a uint to uint\nret add a\nend\n'
84t 5 'fn f a uint to uint\nret a a\nend\n'
85t 6 'fn f a uint to uint\nret add a 12x\nend\n'
86t 7 'fn f a uint b int to uint\nret add a b\nend\n'
87t 8 'fn f a uchar to uchar\nret add a 256\nend\n'
88t 9 'fn f a int b int to int\nret div a b\nend\n'
89t 9 'fn f a uint to void\nend\n'
90t 10 'fn f a uint a uint to uint\nret a\nend\n'
91t 11 'fn f a uint to uint\nx = add 1 2\nret a\nend\n'
92t 13 'fn f a uint to uint\nabcdefghi = a\nret a\nend\n'
93t 15 'fn f a uint to uint\nret a\n'
94t 9 'fn f a uint to uint\nret a\nend\nend\n'
95t 16 'ret 5\n'
96# the recorded receipt is compared, never rewritten; the verdict below is the checks' alone
97say "$(sh seed/check/receipt.sh "$E" "$REC" $R/om3.audit || true)"
98[ $fail = 0 ] && say "GATE3 PASS" || say "GATE3 FAIL"
99exit $fail