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 / om / receipt / parity / run.sh

96 lines · 5695 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0
3# Parity of om/receipt/receipt.om against the C it ports (src/omega_receipt.c + omega_receipt.h), by
4# RECORDED oracle output: this script does not build or run any C. corpus.py regenerates the corpus,
5# the .om harness runs every stream, and each stream's output must have the line count and sha256 in
6# parity/expected.txt, which is the C oracle driver's output recorded when the port was made (the
7# driver is not in the tree; README.md says how to rerun it). Then small mutants of receipt.om must
8# each run to completion and change their stream's hash (the corpus discriminates). With OMEGA_BRIDGE
9# set, the five entry points are also cut into function-mode units (unit.py), bound by the pinned
10# omega-bridge generator and compiled as C (bindability).
11# OMEGA_OMC seed-born omc, sha256 pinned below (exit 3 NOT_RUN without it)
12# OMEGA_BRIDGE optional: an aien-dev/omega-bridge checkout whose src/native.om matches the pin
13set -eu
14OMC_PIN=26540e6de62402d5784b30b24d7c6faae488137c1f8a4b3e784fd0b5d5528991
15NATIVE_PIN=2c2c53f61d4ab302f1a2092c3c32189335dd53f6cf2b388f47a475f99f2c3940
16P=$(cd "$(dirname "$0")" && pwd)
17OM=$P/../receipt.om
18[ -n "${OMEGA_OMC:-}" ] || { echo "RECEIPT-PARITY NOT_RUN: set OMEGA_OMC"; exit 3; }
19[ "$(sha256sum < "$OMEGA_OMC" | cut -c1-64)" = "$OMC_PIN" ] || { echo "RECEIPT-PARITY NOT_RUN: omc is not the pinned compiler"; exit 3; }
20command -v python3 > /dev/null || { echo "RECEIPT-PARITY NOT_RUN: python3 missing"; exit 3; }
21T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
22python3 "$P/corpus.py" "$T/corp" > "$T/counts"
23"$OMEGA_OMC" < "$OM" > "$T/rc"; chmod +x "$T/rc"
24grep -v '^#' "$P/expected.txt" | while read -r s n want; do
25 rc=0; "$T/rc" < "$T/corp/$s.bin" > "$T/$s.out" || rc=$?
26 got=$(sha256sum < "$T/$s.out" | cut -c1-64)
27 lines=$(wc -l < "$T/$s.out")
28 if [ "$rc" = 0 ] && [ "$got" = "$want" ] && [ "$lines" = "$n" ]; then
29 echo "PASS $s: $n lines identical to the recorded C oracle output ($(grep "^$s " "$T/counts" | cut -d' ' -f2) records)"
30 else
31 echo "FAIL $s: exit $rc, $lines lines, sha256 $got (want $n, $want)"; echo x >> "$T/failed"
32 fi
33done
34[ ! -e "$T/failed" ] || { echo "RECEIPT-PARITY FAIL"; exit 1; }
35
36# Mutants: name | stream | exact text in receipt.om (\n for a newline) | replacement.
37# Killed = the mutant harness exits 0 with the expected line count and a different sha256.
38cat > "$T/mutants" <<'EOF'
39json_dup_key|json|if dupkey js n f k|if eq k 0
40json_depth|json|if gt d 6|if gt d 7
41json_surrogate_utf8|json|if and ge cp 2048 not and ge cp 55296 le cp 57343|if ge cp 2048
42json_pair_offset|json|ret fail wk 7 add p 4|ret fail wk 7 p
43json_leading_zero|json|if gt sub q d0 1|if gt sub q d0 2
44deny_unknown|shapes|if eq k 999\nret failk wk 22 0|if false\nret failk wk 22 0
45schema|shapes|if not nameq js wk get wk 64 59|if false
46env_class|shapes|if ne dcmp js get wk 77 get wk 68 0|if false
47pass_needs_assertion|shapes|if and eq m 0 eq get wk 103 0|if false
48prod_test_only|shapes|if eq get a 8 1\nret fail wk 60 0|if false\nret fail wk 60 0
49canon_sort|shapes|put wk 7 0\nmsort js wk m|put wk 7 0
50id_compare|shapes|if not same|if false
51escape_f|shapes|if eq e 102\nret 12|if eq e 102\nret 13
52set_dedup|fields|ret ne dcmp js x y 0|ret true
53mutation_order|fields|if gt so sev get wk 105|if false
54u64_overflow|fields|if gt x div sub 18446744073709551615 dg 10|if false
55upper_hex|rust|ret sub c 55|ret 16
56b3_root|rust|put w 74 or get w 74 8|put w 74 or get w 74 0
57canon_window|big|if and ge t lo lt t add lo 1048576|if and ge t lo lt t add lo 1048575
58tier_test_only|tier|if eq need 0\nret 1|if eq need 0\nret 0
59EOF
60while IFS='|' read -r name s old new; do
61 python3 - "$OM" "$T/m.om" "$old" "$new" <<'PY'
62import sys
63src, dst, old, new = sys.argv[1], sys.argv[2], sys.argv[3].replace("\\n", "\n"), sys.argv[4].replace("\\n", "\n")
64s = open(src).read()
65assert s.count(old + "\n") == 1, "mutant text not found exactly once: " + old
66open(dst, "w").write(s.replace(old + "\n", new + "\n"))
67PY
68 "$OMEGA_OMC" < "$T/m.om" > "$T/m"; chmod +x "$T/m"
69 rc=0; "$T/m" < "$T/corp/$s.bin" > "$T/m.out" 2> /dev/null || rc=$?
70 got=$(sha256sum < "$T/m.out" | cut -c1-64)
71 lines=$(wc -l < "$T/m.out")
72 want=$(grep "^$s " "$P/expected.txt" | cut -d' ' -f3)
73 n=$(grep "^$s " "$P/expected.txt" | cut -d' ' -f2)
74 if [ "$rc" != 0 ] || [ "$lines" != "$n" ] || [ "$got" = "$want" ]; then
75 echo "mutant $name NOT killed on $s (exit $rc, $lines lines, sha256 $got)"; echo x >> "$T/failed"; continue
76 fi
77 dl=$(paste -d'\n' "$T/m.out" "$T/$s.out" | awk 'NR % 2 == 1 { a = $0; next } a != $0' | wc -l)
78 echo "mutant $name killed on $s (exit 0, $dl of $n lines differ)"
79done < "$T/mutants"
80[ ! -e "$T/failed" ] || { echo "RECEIPT-PARITY FAIL"; exit 1; }
81
82if [ -z "${OMEGA_BRIDGE:-}" ]; then
83 echo "RECEIPT-PARITY PASS (bindability NOT_RUN: set OMEGA_BRIDGE)"; exit 0
84fi
85[ "$(sha256sum < "$OMEGA_BRIDGE/src/native.om" | cut -c1-64)" = "$NATIVE_PIN" ] || { echo "RECEIPT-PARITY PASS (bindability NOT_RUN: native.om is not the pinned generator)"; exit 0; }
86"$OMEGA_OMC" < "$OMEGA_BRIDGE/src/native.om" > "$T/native"; chmod +x "$T/native"
87: > "$T/units"
88for u in rcparse rccanon rcverify rctier rcsat; do
89 python3 "$P/unit.py" "$OM" "$u" > "$T/u.om"
90 "$OMEGA_OMC" < "$T/u.om" > "$T/u.bin"
91 { cat "$T/u.om"; printf '\0'; printf '%08d' "$(wc -c < "$T/u.bin")"; cat "$T/u.bin"; } >> "$T/units"
92done
93"$T/native" < "$T/units" > "$T/units.c"
94cc -std=gnu11 -O2 -Wall -Wextra -Werror -c "$T/units.c" -o "$T/units.o"
95echo "bindability: 5 function-mode units accepted by native.om and compiled ($(grep -c ') uint32_t omega_[a-z0-9]*(uint64_t \*result' "$T/units.c") exported functions)"
96echo "RECEIPT-PARITY PASS"