Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/compiler/osc0b_model_receipt.sh # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / compiler / osc0b_model_receipt.sh` 138 lines ยท 7294 bytes Raw Blame History 1 #!/bin/sh 2 # SPDX-License-Identifier: Apache-2.0 3 # Copyright 2026 Drake Stapleton (AIEN / aien-dev) 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # OSC-0B exit gate receipt (OMEGA_SYSTEMS_CORE_CODE_AUDIT.md II.11, III.8). 18 # 1. refuses a dirty tree (any tracked or untracked change): receipts record an exact commit 19 # 2. builds tests/compiler/test_osc_model.c + src/compiler/model/*.c twice, outside the tree: 20 # plain -O2, and ASan/UBSan (-fno-sanitize-recover=all) 21 # 3. runs the plain build at the gate size (>= 10^6 seeded sequences) and the 22 # sanitizer build on the same seed (full size unless OSC0B_ASAN_SEQUENCES is set) 23 # 4. requires OSC0B_MODEL_PASS, zero false accepts / wrong names / false rejects, 24 # and the same sweep digest from both builds on the full size 25 # 5. writes a content-addressed receipt evidence/OSC-1/receipts/osc0b-model-.json 26 # Never overwrites existing evidence. Timing is not recorded (receipt stays content-stable). 27 # Env: CC (default cc), OSC0B_SEED (hex, default the test's built-in seed), OSC0B_ASAN_SEQUENCES. 28 set -eu 29 ROOT=$(cd "$(dirname "$0")/../.." && pwd -P) 30 cd "$ROOT" 31 EVD=evidence/OSC-1/receipts 32 CC=${CC:-cc} 33 SRCS="src/compiler/model/osc_model.h src/compiler/model/osc_model.c src/compiler/model/osc_model_gen.h src/compiler/model/osc_model_gen.c tests/compiler/test_osc_model.c" 34 CFLAGS="-std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -Isrc -Isrc/compiler -Isrc/compiler/model" 35 36 die() { echo "osc0b-model-receipt: REFUSED: $*" >&2; exit 2; } 37 38 [ -z "$(git status --porcelain --untracked-files=all)" ] || die "dirty tree; commit first (receipts record an exact commit)" 39 COMMIT=$(git rev-parse HEAD) 40 case "$COMMIT" in *[!0-9a-f]*|"") die "cannot read HEAD";; esac 41 for f in $SRCS; do [ -f "$f" ] || die "missing $f"; done 42 43 T=$(mktemp -d) 44 trap 'rm -rf "$T"' EXIT 45 nice "$CC" $CFLAGS -O2 -o "$T/plain" tests/compiler/test_osc_model.c src/compiler/model/osc_model.c src/compiler/model/osc_model_gen.c \ 46 >"$T/build.log" 2>&1 || { tail -20 "$T/build.log"; die "plain build failed"; } 47 nice "$CC" $CFLAGS -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=all -o "$T/asan" \ 48 tests/compiler/test_osc_model.c src/compiler/model/osc_model.c src/compiler/model/osc_model_gen.c \ 49 >"$T/build_asan.log" 2>&1 || { tail -20 "$T/build_asan.log"; die "sanitizer build failed"; } 50 51 SEED_ARG=${OSC0B_SEED:-} 52 if [ -n "$SEED_ARG" ]; then 53 nice "$T/plain" "$SEED_ARG" >"$T/plain.out" 2>&1 || { tail -20 "$T/plain.out"; die "plain run failed"; } 54 else 55 nice "$T/plain" >"$T/plain.out" 2>&1 || { tail -20 "$T/plain.out"; die "plain run failed"; } 56 fi 57 [ "$(tail -1 "$T/plain.out")" = OSC0B_MODEL_PASS ] || { tail -20 "$T/plain.out"; die "plain run did not print OSC0B_MODEL_PASS"; } 58 59 SUM=$(grep '^OSC0B_MODEL_SEED=' "$T/plain.out" | tail -1) 60 field() { echo "$SUM" | sed -n "s/.*$1=\([0-9a-fx]*\).*/\1/p"; } 61 SEED=$(field OSC0B_MODEL_SEED); SEQ=$(field SEQUENCES); STEPS=$(field STEPS) 62 FA=$(field FALSE_ACCEPTS); WN=$(field WRONG_NAME); FR=$(field FALSE_REJECTS) 63 for v in "$SEED" "$SEQ" "$STEPS" "$FA" "$WN" "$FR"; do [ -n "$v" ] || die "cannot parse summary line: $SUM"; done 64 [ "$FA" = 0 ] && [ "$WN" = 0 ] && [ "$FR" = 0 ] || die "nonzero false accepts/wrong names/false rejects" 65 [ "$SEQ" -ge `1000000` ] || die "fewer than 10^6 sequences ($SEQ)" 66 VLINE=$(grep '^OSC0B_MODEL_VALID ' "$T/plain.out" | tail -1) 67 VALID=$(echo "$VLINE" | sed -n 's/.* sequences=\([0-9]*\).*/\1/p') 68 DIGEST=$(echo "$VLINE" | sed -n 's/.* digest=\([0-9a-f]*\).*/\1/p') 69 UNIT=$(grep '^OSC0B_MODEL_UNIT ' "$T/plain.out" | tail -1) 70 UCASES=$(echo "$UNIT" | sed -n 's/.*cases=\([0-9]*\).*/\1/p') 71 UFAIL=$(echo "$UNIT" | sed -n 's/.*failed=\([0-9]*\).*/\1/p') 72 [ -n "$VALID" ] && [ -n "$DIGEST" ] && [ -n "$UCASES" ] && [ "$UFAIL" = 0 ] || die "cannot parse valid/unit lines" 73 74 ASEQ=${OSC0B_ASAN_SEQUENCES:-$SEQ} 75 nice "$T/asan" "$SEED" "$ASEQ" >"$T/asan.out" 2>&1 || { tail -20 "$T/asan.out"; die "sanitizer run failed"; } 76 ALAST=$(tail -1 "$T/asan.out") 77 case "$ALAST" in OSC0B_MODEL_PASS|OSC0B_MODEL_SMOKE_PASS) ;; *) tail -20 "$T/asan.out"; die "sanitizer run: $ALAST";; esac 78 ADIGEST=$(grep '^OSC0B_MODEL_VALID ' "$T/asan.out" | sed -n 's/.* digest=\([0-9a-f]*\).*/\1/p') 79 if [ "$ASEQ" = "$SEQ" ]; then 80 [ "$ADIGEST" = "$DIGEST" ] || die "sanitizer sweep digest $ADIGEST != plain $DIGEST" 81 DIGEST_MATCH=true 82 else 83 DIGEST_MATCH=null 84 fi 85 86 R="$T/receipt.json" 87 { 88 printf '{\n' 89 printf ' "schema": "omega.osc0b.model.receipt.v1",\n' 90 printf ' "verdict": "PASS",\n' 91 printf ' "gate": "OSC-0B exit: II.11 model rejects every named invalid transition across >= 10^6 seeded random sequences, zero false accepts",\n' 92 printf ' "repo_commit": "%s",\n' "$COMMIT" 93 printf ' "tree_clean": true,\n' 94 printf ' "host_arch": "%s",\n' "$(uname -m)" 95 printf ' "compiler": "%s",\n' "$("$CC" --version 2>/dev/null | head -1 | sed 's/"/\\"/g')" 96 printf ' "seed": "0x%s",\n' "$SEED" 97 printf ' "sequences": %s,\n' "$SEQ" 98 printf ' "valid_sequences": %s,\n' "$VALID" 99 printf ' "steps": %s,\n' "$STEPS" 100 printf ' "false_accepts": %s,\n' "$FA" 101 printf ' "wrong_name": %s,\n' "$WN" 102 printf ' "false_rejects": %s,\n' "$FR" 103 printf ' "sweep_digest": "%s",\n' "$DIGEST" 104 printf ' "unit_cases": %s,\n' "$UCASES" 105 printf ' "unit_failed": 0,\n' 106 printf ' "classes": {\n' 107 N=$(grep -c '^OSC0B_MODEL_CLASS ' "$T/plain.out") 108 [ "$N" = 13 ] || die "expected 13 class lines, got $N" 109 i=0 110 grep '^OSC0B_MODEL_CLASS ' "$T/plain.out" | while read -r _ name inj cor wro acc; do 111 i=$((i + 1)) 112 sep=,; [ "$i" = 13 ] && sep= 113 printf ' "%s": {"injected": %s, "rejected_correct": %s, "rejected_wrong_name": %s, "accepted": %s}%s\n' \ 114 "$name" "${inj#*=}" "${cor#*=}" "${wro#*=}" "${acc#*=}" "$sep" 115 done 116 printf ' },\n' 117 printf ' "sanitizer_run": {"flags": "-fsanitize=address,undefined -fno-sanitize-recover=all", "sequences": %s, "result": "%s", "digest_matches_plain": %s},\n' \ 118 "$ASEQ" "$ALAST" "$DIGEST_MATCH" 119 printf ' "sources_sha256": {\n' 120 n=0; total=$(echo $SRCS | wc -w) 121 for f in $SRCS; do 122 n=$((n + 1)); sep=,; [ "$n" = "$total" ] && sep= 123 printf ' "%s": "%s"%s\n' "$f" "$(sha256sum "$f" | cut -d' ' -f1)" "$sep" 124 done 125 printf ' },\n' 126 printf ' "timing_measured": false\n' 127 printf '}\n' 128 } >"$R" 129 # every class must meet the per-class floor with zero misses 130 grep '^OSC0B_MODEL_CLASS ' "$T/plain.out" | while read -r _ name inj cor wro acc; do 131 [ "${inj#*=}" -ge 10000 ] && [ "${cor#*=}" = "${inj#*=}" ] || { echo "class $name below floor or missed" >&2; exit 1; } 132 done || die "per-class floor" 133 134 mkdir -p "$EVD" 135 RSHA=$(sha256sum "$R" | cut -d' ' -f1) 136 OUT="$EVD/osc0b-model-$RSHA.json" 137 [ -e "$OUT" ] || cp "$R" "$OUT" 138 echo "osc0b-model-receipt: PASS seed=0x$SEED sequences=$SEQ steps=$STEPS receipt=$OUT"