aien-train
AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.
Brought by drakestapleton
aien-train / tests / si19 / run-omexp.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: AGPL-3.0-only |
| 3 | # aien-train#24 ORIG-1 host glue (POSIX sh, disclosed): materialize the pinned sources, |
| 4 | # verify SHA-256, build the omexp test and driver with the pinned seeded compiler, run the |
| 5 | # admission/refusal tests, generate the SYNTHETIC fixture, admit it, and (when RECORDS is |
| 6 | # set) admit the local owner dataset. Every check and verdict is in the .om units. |
| 7 | # Host CPU only. No GPU, network, service or model process is touched. |
| 8 | set -u |
| 9 | ROOT=$(cd "$(dirname "$0")/../.." && pwd) |
| 10 | OUT=${OUT:-$ROOT/evidence/SI19-ORIG1/run} |
| 11 | OMC=${OMC:-$HOME/workspace/omega-toc/seed/out/omc} |
| 12 | OMC2=${OMC2:-$HOME/workspace/omega-seedqual-20261025/seed/out/omc} |
| 13 | BRIDGE=${OMEGA_BRIDGE_GIT:-$HOME/workspace/omega-bridge} |
| 14 | OMEGA=${OMEGA_MV_GIT:-$HOME/workspace/omega} |
| 15 | QUIET=${QUIET:-quiet-build} |
| 16 | BUILD=${BUILD:-$(mktemp -d "${TMPDIR:-/tmp}/si19orig1.XXXXXX")} |
| 17 | RECORDS=${RECORDS:-} |
| 18 | OMC_SHA=191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9 |
| 19 | mkdir -p "$OUT" "$BUILD/deps" |
| 20 | SUM="$OUT/summary.txt" |
| 21 | : > "$SUM" |
| 22 | note() { echo "$*" | tee -a "$SUM"; } |
| 23 | fail() { note "SI19_ORIG1_RUN_FAIL $*"; exit 1; } |
| 24 | |
| 25 | note "build_dir=$BUILD" |
| 26 | note "source_commit=$(git -C "$ROOT" rev-parse HEAD)" |
| 27 | note "host=$(uname -srm)" |
| 28 | git -C "$BRIDGE" show 7e1d0d61755ec1a0bbf20941a18379861b5b9d0d:native/ref32/add32.om > "$BUILD/deps/add32.om" || fail materialize add32 |
| 29 | git -C "$BRIDGE" show 7e1d0d61755ec1a0bbf20941a18379861b5b9d0d:native/ref32/mul32.om > "$BUILD/deps/mul32.om" || fail materialize mul32 |
| 30 | git -C "$OMEGA" show 3a995ba8dace538c1532c747d829ca6e4a73582d:native/ecosystem663/metadata.om > "$BUILD/deps/metadata.om" || fail materialize metadata |
| 31 | git -C "$ROOT" show c9782bfdcf1885082d1fa6c483473f2a514096ad:native/ecosystem6/affine.om > "$BUILD/deps/affine.om" || fail materialize affine |
| 32 | (cd "$BUILD/deps" && sha256sum -c "$ROOT/docs/si19/deps.sha256") > "$OUT/deps-check.txt" 2>&1 || fail dependency hash |
| 33 | set -- $(sha256sum "$OMC") |
| 34 | [ "$1" = "$OMC_SHA" ] || fail "compiler hash $1" |
| 35 | note "compiler_sha256=$1" |
| 36 | |
| 37 | LIB="$BUILD/deps/add32.om $BUILD/deps/mul32.om $BUILD/deps/metadata.om $BUILD/deps/affine.om $ROOT/native/si19/fixture.om $ROOT/native/si19/world.om $ROOT/native/si19/omexp.om $ROOT/native/si19/omexpfix.om" |
| 38 | |
| 39 | # build NAME CALLER [LIBRARY...]: compile one concatenated unit; status in OUT. |
| 40 | build() { |
| 41 | name=$1; caller=$2; shift 2 |
| 42 | [ $# -gt 0 ] || set -- $LIB |
| 43 | cat "$@" "$caller" > "$BUILD/$name.om" |
| 44 | "$QUIET" "$OMC" < "$BUILD/$name.om" > "$BUILD/$name.elf" 2> "$OUT/$name.compile.stderr" |
| 45 | rc=$? |
| 46 | echo "$rc" > "$OUT/$name.compile.rc" |
| 47 | [ "$rc" -eq 0 ] || return "$rc" |
| 48 | head -c 4 "$BUILD/$name.elf" | od -An -c | grep -q 'E L F' || return 70 |
| 49 | chmod 700 "$BUILD/$name.elf" |
| 50 | } |
| 51 | |
| 52 | ms() { date +%s%N; } |
| 53 | |
| 54 | build omexp-test "$ROOT/tests/si19/omexp-test.om" || fail compile omexp-test |
| 55 | build omexp "$ROOT/native/si19/omexpmain.om" || fail compile omexp |
| 56 | if [ -x "$OMC2" ]; then |
| 57 | "$QUIET" "$OMC2" < "$BUILD/omexp-test.om" > "$BUILD/omexp-test-r6.elf" 2> "$OUT/omexp-test-r6.compile.stderr" |
| 58 | echo $? > "$OUT/omexp-test-r6.compile.rc" |
| 59 | chmod 700 "$BUILD/omexp-test-r6.elf" |
| 60 | note "r6_compiler_sha256=$(sha256sum "$OMC2" | cut -c1-64) compile_rc=$(cat "$OUT/omexp-test-r6.compile.rc")" |
| 61 | fi |
| 62 | |
| 63 | t0=$(ms) |
| 64 | "$BUILD/omexp-test.elf" > "$OUT/omexp-test.stdout" 2> "$OUT/omexp-test.stderr" |
| 65 | rc=$?; t1=$(ms) |
| 66 | echo "$rc" > "$OUT/omexp-test.rc" |
| 67 | note "omexp-test rc=$rc wall_ms=$(( (t1 - t0) / 1000000 )) $(cat "$OUT/omexp-test.stdout")" |
| 68 | [ "$rc" -eq 0 ] || fail omexp-test |
| 69 | if [ -x "$BUILD/omexp-test-r6.elf" ]; then |
| 70 | "$BUILD/omexp-test-r6.elf" > "$OUT/omexp-test-r6.stdout" 2> "$OUT/omexp-test-r6.stderr" |
| 71 | echo $? > "$OUT/omexp-test-r6.rc" |
| 72 | note "omexp-test-r6 rc=$(cat "$OUT/omexp-test-r6.rc") $(cat "$OUT/omexp-test-r6.stdout")" |
| 73 | fi |
| 74 | |
| 75 | ALLOW=${ALLOW:-$ROOT/docs/si19/orig1-datasets.txt} |
| 76 | allow_block() { { cat "$ALLOW"; head -c 4096 /dev/zero; } | head -c 4096; } |
| 77 | |
| 78 | # gen SEED COUNT NAME: the SYNTHETIC fixture to BUILD/NAME.bin |
| 79 | gen() { |
| 80 | { printf 'G'; le8 "$1"; le8 "$2"; } | "$BUILD/omexp.elf" 3> "$BUILD/$3.bin" > "$OUT/gen-$3.stdout" 2> "$OUT/gen-$3.stderr" |
| 81 | rc=$? |
| 82 | echo "$rc" > "$OUT/gen-$3.rc" |
| 83 | note "gen-$3 rc=$rc $(tr '\n' ' ' < "$OUT/gen-$3.stdout")" |
| 84 | return "$rc" |
| 85 | } |
| 86 | # le8 N: 8 little-endian bytes of N using only POSIX tools. |
| 87 | le8() { |
| 88 | v=$1; i=0 |
| 89 | while [ $i -lt 8 ]; do |
| 90 | printf "\\$(printf '%03o' $((v % 256)))" |
| 91 | v=$((v / 256)); i=$((i + 1)) |
| 92 | done |
| 93 | } |
| 94 | |
| 95 | # inspect NAME FILE: admit a record file and print the baselines. |
| 96 | inspect() { |
| 97 | t0=$(ms) |
| 98 | { printf 'I'; allow_block; cat "$2"; } | "$BUILD/omexp.elf" > "$OUT/inspect-$1.stdout" 2> "$OUT/inspect-$1.stderr" |
| 99 | rc=$?; t1=$(ms) |
| 100 | echo "$rc" > "$OUT/inspect-$1.rc" |
| 101 | note "inspect-$1 rc=$rc wall_ms=$(( (t1 - t0) / 1000000 ))" |
| 102 | return "$rc" |
| 103 | } |
| 104 | # v2 NAME FILE: v2 admission (ORIG1-CONTRACT-v2.md) with counted refusal reasons and splits. |
| 105 | v2() { |
| 106 | t0=$(ms) |
| 107 | { printf 'V'; allow_block; cat "$2"; } | "$BUILD/omexp.elf" > "$OUT/v2-$1.stdout" 2> "$OUT/v2-$1.stderr" |
| 108 | rc=$?; t1=$(ms) |
| 109 | echo "$rc" > "$OUT/v2-$1.rc" |
| 110 | note "v2-$1 rc=$rc wall_ms=$(( (t1 - t0) / 1000000 ))" |
| 111 | return "$rc" |
| 112 | } |
| 113 | |
| 114 | gen 7 780 fixture-7-780 || fail gen |
| 115 | inspect fixture "$BUILD/fixture-7-780.bin" || fail inspect fixture |
| 116 | cat "$OUT/inspect-fixture.stdout" | tee -a "$SUM" |
| 117 | v2 fixture "$BUILD/fixture-7-780.bin" || fail v2 fixture |
| 118 | cat "$OUT/v2-fixture.stdout" | tee -a "$SUM" |
| 119 | printf 'S' | "$BUILD/omexp.elf" > "$OUT/splits.txt" 2> "$OUT/splits.stderr" || fail splits |
| 120 | cmp -s "$OUT/splits.txt" "$ROOT/docs/si19/orig1-v2-splits.txt" || fail "split table differs from docs/si19/orig1-v2-splits.txt" |
| 121 | note "v2_split_table=$(sha256sum "$OUT/splits.txt" | cut -c1-64) families=$(wc -l < "$OUT/splits.txt") identical_to_docs=yes" |
| 122 | |
| 123 | # Refusals through the process path: a foreign file and a damaged record. |
| 124 | head -c 256 /dev/zero > "$BUILD/zero.bin" |
| 125 | inspect zero "$BUILD/zero.bin" |
| 126 | [ "$?" -eq 66 ] || fail zero file admitted |
| 127 | { cat "$BUILD/fixture-7-780.bin"; head -c 256 /dev/zero; } > "$BUILD/unlisted.bin" |
| 128 | inspect unlisted "$BUILD/unlisted.bin" |
| 129 | [ "$?" -eq 66 ] || fail unlisted damaged file admitted |
| 130 | cp "$BUILD/fixture-7-780.bin" "$BUILD/forged.bin" |
| 131 | printf '\001' | dd of="$BUILD/forged.bin" bs=1 seek=248 conv=notrunc 2> /dev/null |
| 132 | inspect forged "$BUILD/forged.bin" |
| 133 | [ "$?" -eq 66 ] || fail forged mismatch admitted |
| 134 | printf '\001' | dd of="$BUILD/forged.bin" bs=1 seek=248 conv=notrunc 2> /dev/null |
| 135 | cp "$BUILD/fixture-7-780.bin" "$BUILD/unauth.bin" |
| 136 | printf '\001' | dd of="$BUILD/unauth.bin" bs=1 seek=88 conv=notrunc 2> /dev/null |
| 137 | inspect unauth "$BUILD/unauth.bin" |
| 138 | [ "$?" -eq 67 ] || fail unlisted hash admitted |
| 139 | cat "$OUT/inspect-zero.stdout" "$OUT/inspect-unlisted.stdout" "$OUT/inspect-forged.stdout" "$OUT/inspect-unauth.stdout" | tee -a "$SUM" |
| 140 | |
| 141 | if [ -n "$RECORDS" ]; then |
| 142 | note "owner_records=$RECORDS sha256=$(sha256sum "$RECORDS" | cut -c1-64) bytes=$(wc -c < "$RECORDS")" |
| 143 | inspect owner "$RECORDS" || fail inspect owner |
| 144 | cat "$OUT/inspect-owner.stdout" | tee -a "$SUM" |
| 145 | v2 owner "$RECORDS" || fail v2 owner |
| 146 | cat "$OUT/v2-owner.stdout" | tee -a "$SUM" |
| 147 | else |
| 148 | note "owner_records=NOT_RUN (RECORDS unset)" |
| 149 | fi |
| 150 | |
| 151 | # Leakage audit (mode A, local analysis): AUDIT_A = the earlier file, AUDIT_B = the later one. |
| 152 | if [ -n "${AUDIT_A:-}" ] && [ -n "${AUDIT_B:-}" ]; then |
| 153 | na=$(( $(wc -c < "$AUDIT_A") / 256 )) |
| 154 | { printf 'A'; le8 "$na"; cat "$AUDIT_A" "$AUDIT_B"; } | "$BUILD/omexp.elf" > "$OUT/audit.stdout" 2> "$OUT/audit.stderr" |
| 155 | rc=$?; echo "$rc" > "$OUT/audit.rc" |
| 156 | note "audit rc=$rc a_sha256=$(sha256sum "$AUDIT_A" | cut -c1-64) b_sha256=$(sha256sum "$AUDIT_B" | cut -c1-64)" |
| 157 | cat "$OUT/audit.stdout" | tee -a "$SUM" |
| 158 | [ "$rc" -eq 0 ] || fail audit |
| 159 | else |
| 160 | note "audit=NOT_RUN (AUDIT_A/AUDIT_B unset)" |
| 161 | fi |
| 162 | |
| 163 | # Fault injection: each altered unit must compile and fail the unchanged test. |
| 164 | i=0 |
| 165 | while IFS='|' read -r file orig alt; do |
| 166 | [ -n "$file" ] || continue |
| 167 | i=$((i + 1)) |
| 168 | src="$ROOT/native/si19/$file" |
| 169 | n=$(grep -c -x -F -- "$orig" "$src") |
| 170 | [ "$n" -eq 1 ] || fail "mutant$i matches $n" |
| 171 | mdir="$BUILD/mutant$i"; mkdir -p "$mdir" |
| 172 | awk -v o="$orig" -v a="$alt" '$0 == o { print a; next } { print }' "$src" > "$mdir/$file" |
| 173 | mlib="" |
| 174 | for f in $LIB; do |
| 175 | if [ "$(basename "$f")" = "$file" ]; then mlib="$mlib $mdir/$file"; else mlib="$mlib $f"; fi |
| 176 | done |
| 177 | build "mutant$i" "$ROOT/tests/si19/omexp-test.om" $mlib || fail "mutant$i compile" |
| 178 | "$BUILD/mutant$i.elf" > "$OUT/mutant$i.stdout" 2> "$OUT/mutant$i.stderr" |
| 179 | rc=$? |
| 180 | echo "$rc" > "$OUT/mutant$i.rc" |
| 181 | note "mutant$i $file rc=$rc $(cat "$OUT/mutant$i.stdout") :: $alt" |
| 182 | [ "$rc" -eq 1 ] || fail "mutant$i survived" |
| 183 | done <<'EOF' |
| 184 | omexp.om|if ne oxword r 31 0|if ne oxword r 31 1 |
| 185 | omexp.om|if ne oxword r add 24 a 1|if ne oxword r add 24 a 0 |
| 186 | omexp.om|ret -11|ret 0 |
| 187 | omexp.om|if le oxseq r oxseq sub r 1|if lt oxseq r oxseq sub r 1 |
| 188 | omexp.om|if and eq b 82 eq k 7|if and eq b 82 eq k 8 |
| 189 | omexp.om|put XF 3 long shr mul lm ln 8|put XF 3 long shr mul lm lm 8 |
| 190 | omexp.om|if ne oxword r 12 31|if eq oxword r 12 0 |
| 191 | omexp.om|d = true|d = false |
| 192 | omexp.om|if or gt oxfam r 5 gt oxcore r 1|if or gt oxfam r 5 gt oxcore r 2 |
| 193 | omexp.om|ret oxhspl oxfl oxm r oxfl oxn r|ret rem oxfam r 3 |
| 194 | omexp.om|if ge oxword r add 16 a 1099511627776|if ge oxword r add 16 a 1099511627777 |
| 195 | omexp.om|ret int -11|ret 0 |
| 196 | omexp.om|if ge oxseq sub r 1 oxseq r|if gt oxseq sub r 1 oxseq r |
| 197 | omexp.om|ret eq oxpress q p|ret true |
| 198 | omexp.om|ret and eq oxcore q oxcore r eq oxpress q oxpress r|ret eq oxcore q oxcore r |
| 199 | omexp.om|if eq oxbest q oxbest r|if ne oxbest q oxbest r |
| 200 | EOF |
| 201 | |
| 202 | (cd "$OUT" && sha256sum -- *.stdout *.rc *.compile.stderr deps-check.txt) > "$OUT/raw.sha256" |
| 203 | (cd "$BUILD" && sha256sum -- *.bin omexp.elf omexp-test.elf omexp.om omexp-test.om) > "$OUT/build.sha256" |
| 204 | note "SI19_ORIG1_RUN_PASS" |