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 / omc / gate-longnames.sh
| 1 | #!/bin/sh |
| 2 | # gate-longnames.sh -- names of up to 63 bytes (docs/one_layer/OMEGESE.md 9.2, error 13; 9.6, the arena). |
| 3 | # The compiler under test is seed/out/omc (OMC overrides it). |
| 4 | # 1. Every seed/omc/tests/longnames/NAME.om gives NAME.expect: "compile C", then "exit X" (the program's |
| 5 | # status; NAME.stdout, when present, is its exact stdout) or "stderr LINE" (the exact refusal). Target |
| 6 | # a64: compiled and run here (an AArch64 host). Target x86: the same compiler reads `target x86linux`, |
| 7 | # a newline, then the unit, and the program runs under qemu-x86_64; the prepended line makes every |
| 8 | # refusal line one higher (the om2 units carry their mode line after their notes, so they take it too). |
| 9 | # Without qemu-x86_64 the x86 runs are NOT_RUN and the gate ends with status 3. |
| 10 | # 2. Capacity: the long-name table is part of omc's arena (OMEGESE 9.6) and has no count of its own: |
| 11 | # 20000 distinct long globals (the table held 4096 through omc f4fa7951) compile and keep their |
| 12 | # values apart, which also takes the long-name hash through its rebuilds (every 2^(b+1) names). |
| 13 | # 3. Mutants: each one-line change of the interning in seed/omc/omc.om (a site that occurs exactly once) |
| 14 | # must build a compiler (om4 cannot be asked, so the compiler under test builds it) that fails some |
| 15 | # check of 1 or 2 on a64 (a wrong result, a refusal or a trap of the mutated compiler). A mutant that |
| 16 | # does not build, does not change the compiler, or that no check notices, fails the gate. |
| 17 | # Last line: RC=0 when everything passed. |
| 18 | set -eu |
| 19 | R=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd) |
| 20 | cd "$R" |
| 21 | S=${OMC:-seed/out/omc} |
| 22 | D=seed/omc/tests/longnames |
| 23 | [ -x "$S" ] || { printf 'FAIL: %s missing; run sh seed/omega-from-seed.sh first\n' "$S" >&2; exit 1; } |
| 24 | mkdir -p build/seed |
| 25 | B=$(mktemp -d build/seed/longnames.XXXXXX) |
| 26 | trap 'rm -rf "$B"' EXIT HUP INT TERM |
| 27 | bad() { printf 'FAIL: %s\n' "$*" >&2; exit 1; } |
| 28 | say() { printf '%s\n' "$*"; } |
| 29 | Q=$(command -v qemu-x86_64 || true) |
| 30 | |
| 31 | # check COMPILER TARGET NAME -> prints nothing and returns 0 when NAME.expect holds, else prints why |
| 32 | check() { |
| 33 | c=$1; t=$2; n=$3; f=$D/$n.om |
| 34 | want=$(sed -n 1p $D/$n.expect); res=$(sed -n 2p $D/$n.expect) |
| 35 | set +e |
| 36 | if [ $t = a64 ]; then "$c" < $f > $B/p.bin 2> $B/p.err; else { printf 'target x86linux\n'; cat $f; } | "$c" > $B/p.bin 2> $B/p.err; fi |
| 37 | rc=$? |
| 38 | set -e |
| 39 | [ "compile $rc" = "$want" ] || { echo "$t $n: compile $rc, wanted ${want#compile } ($(cat $B/p.err))"; return 1; } |
| 40 | case $res in |
| 41 | stderr*) |
| 42 | exp=${res#stderr } |
| 43 | if [ $t = x86 ]; then l=${exp#omc: line }; l=${l%%:*}; exp="omc: line $((l + 1)):${exp#omc: line *:}"; fi |
| 44 | [ "$(cat $B/p.err)" = "$exp" ] || { echo "$t $n: stderr '$(cat $B/p.err)', wanted '$exp'"; return 1; } ;; |
| 45 | exit*) |
| 46 | chmod +x $B/p.bin |
| 47 | set +e |
| 48 | if [ $t = a64 ]; then $B/p.bin > $B/p.out 2>&1; else "$Q" $B/p.bin > $B/p.out 2>&1; fi |
| 49 | x=$? |
| 50 | set -e |
| 51 | [ "exit $x" = "$res" ] || { echo "$t $n: exit $x, wanted ${res#exit }"; return 1; } |
| 52 | if [ -f $D/$n.stdout ]; then cmp -s $B/p.out $D/$n.stdout || { echo "$t $n: stdout differs"; return 1; }; fi ;; |
| 53 | *) echo "$n.expect: bad second line"; return 1 ;; |
| 54 | esac |
| 55 | } |
| 56 | # capacity COMPILER -> 0 when 20000 long globals compile and keep their values apart (exit 12) |
| 57 | gen() { awk -v n=$1 'BEGIN { for (i = 1; i <= n; i++) printf "global long_global_name_%05d uint 1\n", i |
| 58 | print "fn main to int"; print "put long_global_name_00001 0 uint 5"; printf "put long_global_name_%05d 0 uint 7\n", n |
| 59 | printf "ret int add get long_global_name_00001 0 get long_global_name_%05d 0\nend\n", n }'; } |
| 60 | gen 20000 > $B/cap20000.om |
| 61 | capacity() { |
| 62 | set +e; "$1" < $B/cap20000.om > $B/c.bin 2> $B/c.err; rc=$?; set -e |
| 63 | [ $rc = 0 ] || { echo "capacity: 20000 long globals: compile $rc ($(cat $B/c.err))"; return 1; } |
| 64 | chmod +x $B/c.bin; set +e; $B/c.bin; x=$?; set -e |
| 65 | [ $x = 12 ] || { echo "capacity: 20000 long globals: exit $x, wanted 12"; return 1; } |
| 66 | } |
| 67 | names=$(ls $D/*.om | sed 's|.*/||; s|\.om$||') |
| 68 | nr=0; nx=0; skip=0 |
| 69 | for n in $names; do |
| 70 | check "$S" a64 $n > $B/why || bad "$(cat $B/why)"; nr=$((nr + 1)) |
| 71 | if [ -z "$Q" ] && grep -q '^exit' $D/$n.expect; then skip=$((skip + 1)); continue; fi |
| 72 | check "$S" x86 $n > $B/why || bad "$(cat $B/why)"; nx=$((nx + 1)) |
| 73 | done |
| 74 | say "PASS $nr long-name units on a64, $nx on x86${Q:+ (qemu-x86_64)}" |
| 75 | capacity "$S" > $B/why || bad "$(cat $B/why)" |
| 76 | say "PASS capacity: 20000 long globals keep their values apart (exit 12)" |
| 77 | |
| 78 | # mutants: SITE|REPLACEMENT, each site exactly once in omc.om |
| 79 | k=0 |
| 80 | while IFS='|' read -r site repl; do |
| 81 | [ -n "$site" ] || continue |
| 82 | k=$((k + 1)) |
| 83 | [ "$(grep -cxF "$site" seed/omc/omc.om)" = 1 ] || bad "mutant $k: site '$site' does not occur exactly once" |
| 84 | awk -v s="$site" -v r="$repl" '$0 == s { print r; next } { print }' seed/omc/omc.om > $B/m.om |
| 85 | set +e; "$S" < $B/m.om > $B/m.omc 2> $B/m.err; rc=$?; set -e |
| 86 | [ $rc = 0 ] || bad "mutant $k ($repl): does not build ($(cat $B/m.err))" |
| 87 | chmod +x $B/m.omc |
| 88 | cmp -s $B/m.omc "$S" && bad "mutant $k ($repl): compiler unchanged" |
| 89 | caught="" |
| 90 | for n in $names; do check $B/m.omc a64 $n > $B/why || { caught=$n; break; }; done |
| 91 | [ -n "$caught" ] || { capacity $B/m.omc > $B/why || caught=capacity; } |
| 92 | [ -n "$caught" ] || bad "mutant $k ($repl): no check notices it" |
| 93 | say " killed mutant $k ($repl) by $caught: $(cat $B/why)" |
| 94 | done <<'MUT' |
| 95 | if ne a_ib add o i a_ib add s i|if eq a_ib add o i a_ib add s i |
| 96 | if ne ulong uchar get a_ar add get a_rb 18 j n|if ne ulong uchar get a_ar add get a_rb 18 j 9 |
| 97 | a_pc 18 k uchar n|a_pc 18 k uchar 9 |
| 98 | put tw 0 add 1 shl ln_intern get ts 0 n 8|put tw 0 add 1 shl mul ln_intern get ts 0 n 0 8 |
| 99 | if and gt n 8 le n 63|if and gt n 8 le n 62 |
| 100 | put a_ar add get a_rb 20 h add j 1|put a_ar add get a_rb 20 h add j 2 |
| 101 | MUT |
| 102 | say "PASS $k interning mutants each fail a check" |
| 103 | [ $skip = 0 ] || { say "NOT_RUN $skip x86 runs (no qemu-x86_64)"; exit 3; } |
| 104 | say "RC=0" |