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.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: AGPL-3.0-only |
| 3 | # aien-train#19 host glue (POSIX sh, disclosed): materialize the pinned sources, |
| 4 | # verify SHA-256, concatenate, compile with the pinned seeded compiler, run, and |
| 5 | # record every status. All training, checks and verdicts are in the .om units. |
| 6 | # Host CPU only. No GPU, network, service or model process is touched. |
| 7 | set -u |
| 8 | ROOT=$(cd "$(dirname "$0")/../.." && pwd) |
| 9 | OUT=${OUT:-$ROOT/evidence/SI19/run} |
| 10 | OMC=${OMC:-$HOME/workspace/omega-ecosystem660-bridge/build/bootstrap/omc} |
| 11 | BRIDGE=${OMEGA_BRIDGE_GIT:-$HOME/workspace/omega-bridge} |
| 12 | OMEGA=${OMEGA_MV_GIT:-$HOME/workspace/omega-ecosystem663} |
| 13 | QUIET=${QUIET:-quiet-build} |
| 14 | BUILD=${BUILD:-$(mktemp -d "${TMPDIR:-/tmp}/si19.XXXXXX")} |
| 15 | OMC_SHA=191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9 |
| 16 | mkdir -p "$OUT" "$BUILD/deps" |
| 17 | SUM="$OUT/summary.txt" |
| 18 | : > "$SUM" |
| 19 | note() { echo "$*" | tee -a "$SUM"; } |
| 20 | fail() { note "SI19_RUN_FAIL $*"; exit 1; } |
| 21 | |
| 22 | note "build_dir=$BUILD" |
| 23 | note "source_commit=$(git -C "$ROOT" rev-parse HEAD)" |
| 24 | note "host=$(uname -srm)" |
| 25 | git -C "$BRIDGE" show 7e1d0d61755ec1a0bbf20941a18379861b5b9d0d:native/ref32/add32.om > "$BUILD/deps/add32.om" || fail materialize add32 |
| 26 | git -C "$BRIDGE" show 7e1d0d61755ec1a0bbf20941a18379861b5b9d0d:native/ref32/mul32.om > "$BUILD/deps/mul32.om" || fail materialize mul32 |
| 27 | git -C "$OMEGA" show 3a995ba8dace538c1532c747d829ca6e4a73582d:native/ecosystem663/metadata.om > "$BUILD/deps/metadata.om" || fail materialize metadata |
| 28 | git -C "$ROOT" show c9782bfdcf1885082d1fa6c483473f2a514096ad:native/ecosystem6/affine.om > "$BUILD/deps/affine.om" || fail materialize affine |
| 29 | (cd "$BUILD/deps" && sha256sum -c "$ROOT/docs/si19/deps.sha256") > "$OUT/deps-check.txt" 2>&1 || fail dependency hash |
| 30 | set -- $(sha256sum "$OMC") |
| 31 | [ "$1" = "$OMC_SHA" ] || fail "compiler hash $1" |
| 32 | note "compiler_sha256=$1" |
| 33 | |
| 34 | 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" |
| 35 | |
| 36 | # build NAME CALLER [LIBRARY...]: compile one concatenated unit; status in OUT. |
| 37 | build() { |
| 38 | name=$1; caller=$2; shift 2 |
| 39 | [ $# -gt 0 ] || set -- $LIB |
| 40 | cat "$@" "$caller" > "$BUILD/$name.om" |
| 41 | "$QUIET" "$OMC" < "$BUILD/$name.om" > "$BUILD/$name.elf" 2> "$OUT/$name.compile.stderr" |
| 42 | rc=$? |
| 43 | echo "$rc" > "$OUT/$name.compile.rc" |
| 44 | [ "$rc" -eq 0 ] || return "$rc" |
| 45 | head -c 4 "$BUILD/$name.elf" | od -An -c | grep -q 'E L F' || return 70 |
| 46 | chmod 700 "$BUILD/$name.elf" |
| 47 | } |
| 48 | |
| 49 | ms() { date +%s%N; } |
| 50 | |
| 51 | build world-test "$ROOT/tests/si19/world-test.om" || fail compile world-test |
| 52 | build world "$ROOT/native/si19/main.om" || fail compile world |
| 53 | readelf -l -d "$BUILD/world.elf" > "$OUT/world.readelf.txt" 2>&1 |
| 54 | |
| 55 | t0=$(ms) |
| 56 | "$BUILD/world-test.elf" > "$OUT/world-test.stdout" 2> "$OUT/world-test.stderr" |
| 57 | rc=$?; t1=$(ms) |
| 58 | echo "$rc" > "$OUT/world-test.rc" |
| 59 | note "world-test rc=$rc wall_ms=$(( (t1 - t0) / 1000000 )) $(cat "$OUT/world-test.stdout")" |
| 60 | [ "$rc" -eq 0 ] || fail world-test |
| 61 | |
| 62 | # run MODE NAME [IMAGE...]: mode byte then images on stdin; fd 3 receives an image. |
| 63 | run() { |
| 64 | mode=$1; name=$2; shift 2 |
| 65 | t0=$(ms) |
| 66 | { printf '%s' "$mode"; [ $# -gt 0 ] && cat "$@"; } | "$BUILD/world.elf" 3> "$BUILD/$name.img" > "$OUT/$name.stdout" 2> "$OUT/$name.stderr" |
| 67 | rc=$?; t1=$(ms) |
| 68 | echo "$rc" > "$OUT/$name.rc" |
| 69 | note "$name mode=$mode rc=$rc wall_ms=$(( (t1 - t0) / 1000000 ))" |
| 70 | return "$rc" |
| 71 | } |
| 72 | |
| 73 | run U uninterrupted || fail uninterrupted |
| 74 | run P partial100 || fail partial100 |
| 75 | run R resume100 "$BUILD/partial100.img" || fail resume100 |
| 76 | run Q partial300 || fail partial300 |
| 77 | run R resume300 "$BUILD/partial300.img" || fail resume300 |
| 78 | run C compare100 "$BUILD/uninterrupted.img" "$BUILD/resume100.img" || fail compare100 |
| 79 | run C compare300 "$BUILD/uninterrupted.img" "$BUILD/resume300.img" || fail compare300 |
| 80 | cat "$OUT/compare100.stdout" "$OUT/compare300.stdout" | tee -a "$SUM" |
| 81 | tail -n +3 "$OUT/resume100.stdout" > "$BUILD/r100.txt" |
| 82 | tail -n +2 "$OUT/uninterrupted.stdout" > "$BUILD/u.txt" |
| 83 | cmp -s "$BUILD/u.txt" "$BUILD/r100.txt" || fail resumed report differs |
| 84 | note "resumed_report_identical=yes" |
| 85 | |
| 86 | # Negative controls on the process path. |
| 87 | run C compare_partial "$BUILD/uninterrupted.img" "$BUILD/partial100.img" |
| 88 | [ "$?" -eq 1 ] || fail compare of different images did not refuse |
| 89 | cp "$BUILD/partial100.img" "$BUILD/damaged.img" |
| 90 | printf '\001' | dd of="$BUILD/damaged.img" bs=1 seek=20000 conv=notrunc 2> /dev/null |
| 91 | run R resume_damaged "$BUILD/damaged.img" |
| 92 | [ "$?" -eq 65 ] || fail damaged image admitted |
| 93 | head -c 51700 "$BUILD/partial100.img" > "$BUILD/short.img" |
| 94 | run R resume_short "$BUILD/short.img" |
| 95 | [ "$?" -eq 65 ] || fail truncated image admitted |
| 96 | cat "$OUT/resume_damaged.stdout" "$OUT/resume_short.stdout" | tee -a "$SUM" |
| 97 | |
| 98 | # Fault injection: each altered unit must compile and fail the unchanged test. |
| 99 | # FILE|ORIGINAL LINE|ALTERED LINE; the original must occur exactly once. |
| 100 | i=0 |
| 101 | while IFS='|' read -r file orig alt; do |
| 102 | [ -n "$file" ] || continue |
| 103 | i=$((i + 1)) |
| 104 | src="$ROOT/native/si19/$file" |
| 105 | n=$(grep -c -x -F -- "$orig" "$src") |
| 106 | [ "$n" -eq 1 ] || fail "mutant$i matches $n" |
| 107 | mdir="$BUILD/mutant$i"; mkdir -p "$mdir" |
| 108 | awk -v o="$orig" -v a="$alt" '$0 == o { print a; next } { print }' "$src" > "$mdir/$file" |
| 109 | mlib="" |
| 110 | for f in $LIB; do |
| 111 | if [ "$(basename "$f")" = "$file" ]; then mlib="$mlib $mdir/$file"; else mlib="$mlib $f"; fi |
| 112 | done |
| 113 | build "mutant$i" "$ROOT/tests/si19/world-test.om" $mlib || fail "mutant$i compile" |
| 114 | "$BUILD/mutant$i.elf" > "$OUT/mutant$i.stdout" 2> "$OUT/mutant$i.stderr" |
| 115 | rc=$? |
| 116 | echo "$rc" > "$OUT/mutant$i.rc" |
| 117 | note "mutant$i $file rc=$rc $(cat "$OUT/mutant$i.stdout") :: $alt" |
| 118 | [ "$rc" -eq 1 ] || fail "mutant$i survived" |
| 119 | done <<'EOF' |
| 120 | fixture.om|put FS add b 2 get FT 3|put FS add b 2 get FT 0 |
| 121 | world.om|put AP c wmbits get TL add t 4 0|put AP c wmbits get TL add t 5 0 |
| 122 | world.om|if not affinite ckget add add base 96 mul i 8|if not affinite ckget add add base 104 mul i 8 |
| 123 | world.om|put FS i wsdec ckget add add base 51232 mul i 8|put FS i 0 |
| 124 | world.om|wmuse arm c|wmuse arm a |
| 125 | world.om|wmrow 0 a ta|wmrow 0 a a |
| 126 | EOF |
| 127 | |
| 128 | (cd "$OUT" && sha256sum -- *.stdout *.rc *.compile.stderr deps-check.txt world.readelf.txt) > "$OUT/raw.sha256" |
| 129 | (cd "$BUILD" && sha256sum -- *.img world.elf world-test.elf world.om world-test.om) > "$OUT/build.sha256" |
| 130 | note "SI19_RUN_PASS" |