sovereign-intelligence
Front door to Drake Stapleton's sovereign stack.
Brought by drakestapleton
sovereign-intelligence / build.sh
| 1 | #!/bin/sh |
| 2 | # build.sh: grow the Omega compiler from 408 hand-written bytes, then build and check everything here. |
| 3 | # |
| 4 | # sh build.sh |
| 5 | # |
| 6 | # Run from anywhere; it works in the repository that holds it and writes only to its out/ directory. |
| 7 | # Needs: POSIX sh, cmp, sha256sum. The seed chain is AArch64 machine code: on an AArch64 Linux host |
| 8 | # it runs directly; on an x86-64 Linux host it runs under qemu-aarch64 (user mode; set QEMU_A64 to its |
| 9 | # path, default qemu-aarch64-static, then qemu-aarch64). The native x86-64 compiler, omc-x86, runs |
| 10 | # directly on x86-64; on AArch64 its steps run under qemu-x86_64 when it exists, or are NOT_RUN. |
| 11 | # |
| 12 | # The one outside tool is seed/rung0/load0.sh, which turns seed0.hex into seed0.bin with the shell's |
| 13 | # own printf. No C compiler, assembler or linker writes a byte of anything this builds. |
| 14 | # |
| 15 | # Steps, each printing PASS or FAIL (a FAIL stops the build with exit 1): |
| 16 | # 1. seed0, hex1, asm2, om4 from their hand-written sources, each checked against seed/PINS.tsv; |
| 17 | # seed0 and hex1 must rebuild themselves |
| 18 | # 2. omc from omc.om: born from om4, then rebuilt by itself twice; all three equal the pin |
| 19 | # 3. omc-x86, the native x86-64 compiler, from "target x86linux" + omc.om; it must rebuild itself, |
| 20 | # and compiling omc.om with it must give exactly the AArch64 omc (diverse double compilation) |
| 21 | # 4. controls: a one-word edit of seed0.hex and a one-line edit of omc.om (a global grown by 32 KiB) must change what is |
| 22 | # born, so the pins catch them |
| 23 | # 5. compiler/si.om, built for both targets, must regenerate the committed README.md and repos.tsv |
| 24 | # byte for byte from the typed inventory and the generated Radicle state compiler/state.tsv (it |
| 25 | # refuses a typed head, branch or visibility and a listed project that is not public), and both |
| 26 | # builds must write the same si.sh; where Radicle storage is at hand, a NOTE counts the listed |
| 27 | # heads that have moved on since compiler/state.tsv was read (tools/si-state.sh) |
| 28 | # 5b. compiler/links.om, built for both targets, must accept this checkout's link table and |
| 29 | # tree, and refuse a repos.tsv whose first row carries a withdrawn crypto RID |
| 30 | # 6. tools/ledger.om, built for both targets, must print tests/ledger/expected.tsv |
| 31 | # 7. the Omega harness examples and the compiler regressions in tests/regress, on both targets |
| 32 | # (tests/examples.sh) |
| 33 | # 8. gpu/cuda-crack, on both targets: its Omega table generator regenerates isa/sm121-forms.txt, its |
| 34 | # Omega reencoder rebuilds the 70 kernels that ran on the GB10 from the tables to the chip |
| 35 | # receipt's sha256, and its four planted bugs, made by check/mutate.om, are each caught |
| 36 | # 9. tools/forkpush.om, built for both targets, must print tests/forkpush/expected.sh, refuse every |
| 37 | # tests/forkpush/bad/*.tsv, and write the same out/fork-push.sh from stack/FORKS.tsv |
| 38 | # 10. the examples of compiler words beyond the imported harness (tests/omc), on both targets |
| 39 | # 11. control: omc.om with count's slice check deleted must build a compiler that fails both trap-3 |
| 40 | # examples of count on every target that runs, while count_word still passes |
| 41 | # Last line: RC=0 when every step passed. |
| 42 | set -eu |
| 43 | R=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) |
| 44 | cd "$R" |
| 45 | O=out |
| 46 | rm -rf "$O" |
| 47 | mkdir -p "$O/seed" "$O/tmp" |
| 48 | |
| 49 | fail() { printf 'FAIL %s\n' "$*"; exit 1; } |
| 50 | pass() { printf 'PASS %s\n' "$*"; } |
| 51 | note() { printf 'NOTE %s\n' "$*"; } |
| 52 | sha() { sha256sum < "$1" | cut -c1-64; } |
| 53 | pin() { # pin NAME FILE: FILE must have the size and sha256 PINS.tsv gives NAME |
| 54 | want=$(awk -F'\t' -v n="$1" '$1 == n { print $3 }' seed/PINS.tsv) |
| 55 | [ -n "$want" ] || fail "no pin for $1" |
| 56 | got=$(sha "$2") |
| 57 | [ "$got" = "$want" ] || fail "$1: sha256 $got, pin $want" |
| 58 | } |
| 59 | |
| 60 | host=$(uname -m) |
| 61 | case $host in |
| 62 | aarch64|arm64) |
| 63 | A64="" |
| 64 | if command -v qemu-x86_64 >/dev/null 2>&1; then X86=qemu-x86_64; else X86=none; fi ;; |
| 65 | x86_64|amd64) |
| 66 | X86="" |
| 67 | A64=${QEMU_A64:-} |
| 68 | if [ -z "$A64" ]; then |
| 69 | for q in qemu-aarch64-static qemu-aarch64; do |
| 70 | if command -v "$q" >/dev/null 2>&1; then A64=$q; break; fi |
| 71 | done |
| 72 | fi |
| 73 | [ -n "$A64" ] || fail "x86-64 host without qemu-aarch64: install qemu-user (Debian/Ubuntu: apt-get install qemu-user-static) or set QEMU_A64" ;; |
| 74 | *) fail "host $host: the seed chain runs on AArch64 Linux, or on x86-64 Linux under qemu-aarch64" ;; |
| 75 | esac |
| 76 | note "host $host; AArch64 programs run ${A64:-directly}; x86-64 programs run ${X86:-directly}" |
| 77 | |
| 78 | a64() { # a64 PROG ARGS...: run an AArch64 program |
| 79 | p=$1; shift |
| 80 | if [ -n "$A64" ]; then "$A64" "$p" "$@"; else "$p" "$@"; fi |
| 81 | } |
| 82 | x86() { # x86 PROG ARGS...: run an x86-64 program |
| 83 | p=$1; shift |
| 84 | if [ -n "$X86" ]; then "$X86" "$p" "$@"; else "$p" "$@"; fi |
| 85 | } |
| 86 | mk() { chmod +x "$1"; } |
| 87 | S=seed |
| 88 | B=$O/seed |
| 89 | |
| 90 | # 1. The rungs. |
| 91 | sh $S/rung0/load0.sh $S/rung0/seed0.hex $B/seed0.bin; mk $B/seed0.bin |
| 92 | pin seed0.bin $B/seed0.bin |
| 93 | a64 $B/seed0.bin < $S/rung0/seed0.hex > $B/seed0.self |
| 94 | cmp -s $B/seed0.bin $B/seed0.self || fail "seed0 does not rebuild itself" |
| 95 | pass "seed0 $(wc -c < $B/seed0.bin | tr -d ' ') bytes from shell printf; rebuilds itself" |
| 96 | a64 $B/seed0.bin < $S/rung1/hex1.hex > $B/hex1.bin; mk $B/hex1.bin |
| 97 | pin hex1.bin $B/hex1.bin |
| 98 | a64 $B/hex1.bin < $S/rung1/hex1.hex > $B/hex1.self |
| 99 | cmp -s $B/hex1.bin $B/hex1.self || fail "hex1 does not rebuild itself" |
| 100 | pass "hex1 $(wc -c < $B/hex1.bin | tr -d ' ') bytes, born from seed0; rebuilds itself" |
| 101 | a64 $B/hex1.bin < $S/rung2/asm2.hex1 > $B/asm2.bin; mk $B/asm2.bin |
| 102 | pin asm2.bin $B/asm2.bin |
| 103 | pass "asm2 $(wc -c < $B/asm2.bin | tr -d ' ') bytes, born from hex1" |
| 104 | cat $S/rung2/table.s2 $S/rung3/table3.s2 $S/rung4/table4.s2 $S/rung4/om4.s | a64 $B/asm2.bin > $B/om4.bin; mk $B/om4.bin |
| 105 | pin om4.bin $B/om4.bin |
| 106 | pass "om4 $(wc -c < $B/om4.bin | tr -d ' ') bytes, born from asm2" |
| 107 | |
| 108 | # 2. omc, from om4 and then from itself. |
| 109 | a64 $B/om4.bin < $S/omc/omc.om > $B/stage1; mk $B/stage1 |
| 110 | a64 $B/stage1 < $S/omc/omc.om > $B/stage2; mk $B/stage2 |
| 111 | a64 $B/stage2 < $S/omc/omc.om > $B/stage3; mk $B/stage3 |
| 112 | cmp -s $B/stage1 $B/stage2 || fail "omc built by om4 differs from omc built by omc" |
| 113 | cmp -s $B/stage2 $B/stage3 || fail "omc is not a fixpoint" |
| 114 | pin omc $B/stage3 |
| 115 | cp $B/stage3 $O/omc |
| 116 | pass "omc $(wc -c < $O/omc | tr -d ' ') bytes: om4-built = omc-built = rebuilt, sha256 $(sha $O/omc)" |
| 117 | |
| 118 | # 3. omc-x86, the native x86-64 compiler, and diverse double compilation. |
| 119 | { printf 'target x86linux\n'; cat $S/omc/omc.om; } > $B/omc-x86.om |
| 120 | a64 $O/omc < $B/omc-x86.om > $B/omc-x86; mk $B/omc-x86 |
| 121 | pin omc-x86 $B/omc-x86 |
| 122 | cp $B/omc-x86 $O/omc-x86 |
| 123 | pass "omc-x86 $(wc -c < $O/omc-x86 | tr -d ' ') bytes, built by omc, sha256 $(sha $O/omc-x86)" |
| 124 | if [ "$X86" = none ]; then |
| 125 | note "NOT_RUN omc-x86 self-rebuild and diverse double compilation: no x86-64 host or qemu-x86_64" |
| 126 | else |
| 127 | x86 $O/omc-x86 < $B/omc-x86.om > $B/omc-x86.self |
| 128 | cmp -s $O/omc-x86 $B/omc-x86.self || fail "omc-x86 does not rebuild itself" |
| 129 | pass "omc-x86 rebuilds itself byte for byte" |
| 130 | x86 $O/omc-x86 < $S/omc/omc.om > $B/omc.ddc |
| 131 | cmp -s $O/omc $B/omc.ddc || fail "diverse double compilation: omc-x86 does not reproduce omc" |
| 132 | pass "diverse double compilation: omc-x86 compiles omc.om to the AArch64 omc, byte for byte" |
| 133 | fi |
| 134 | |
| 135 | # 4. Controls: the pins must catch a changed seed and a changed compiler. |
| 136 | awk 'done == 0 && /^[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]/ { c = substr($0, 1, 1); r = (c == "0") ? "1" : "0"; $0 = r substr($0, 2); done = 1 } { print }' \ |
| 137 | $S/rung0/seed0.hex > $B/seed0.mut.hex |
| 138 | cmp -s $S/rung0/seed0.hex $B/seed0.mut.hex && fail "control: the seed0.hex edit did not change it" |
| 139 | sh $S/rung0/load0.sh $B/seed0.mut.hex $B/seed0.mut.bin |
| 140 | [ "$(sha $B/seed0.mut.bin)" != "$(sha $B/seed0.bin)" ] || fail "control: an edited seed0.hex gave the pinned seed0" |
| 141 | pass "control: one edited word of seed0.hex changes seed0.bin, so its pin catches it" |
| 142 | awk 'done == 0 && $0 == "global line ulong 1" { $0 = "global line ulong 4096"; done = 1 } { print }' $S/omc/omc.om > $B/omc.mut.om |
| 143 | cmp -s $S/omc/omc.om $B/omc.mut.om && fail "control: the omc.om edit did not change it" |
| 144 | a64 $O/omc < $B/omc.mut.om > $B/omc.mut |
| 145 | [ "$(sha $B/omc.mut)" != "$(sha $O/omc)" ] || fail "control: an edited omc.om gave the pinned omc" |
| 146 | pass "control: a one-line edit of omc.om changes the compiler it builds, so its pin catches it" |
| 147 | |
| 148 | # 5. The front door: compiler/si.om must regenerate what is committed. |
| 149 | siin="compiler/inventory.tsv compiler/order.tsv compiler/state.tsv compiler/rebuild.om" |
| 150 | for t in a64 x86; do |
| 151 | if [ $t = x86 ] && [ "$X86" = none ]; then note "NOT_RUN si on x86-64"; continue; fi |
| 152 | w=$O/si-$t |
| 153 | mkdir -p $w/compiler |
| 154 | cp $siin $w/compiler/ |
| 155 | cp README.md repos.tsv layers.tsv $w/ |
| 156 | if [ $t = a64 ]; then |
| 157 | a64 $O/omc < compiler/si.om > $O/si-a64.bin |
| 158 | else |
| 159 | { printf 'target x86linux\n'; cat compiler/si.om; } | x86 $O/omc-x86 > $O/si-x86.bin |
| 160 | fi |
| 161 | mk $O/si-$t.bin |
| 162 | (cd $w && $t ../si-$t.bin compiler/inventory.tsv compiler/order.tsv compiler/state.tsv README.md repos.tsv si.sh) \ |
| 163 | || fail "si ($t) refused the committed inputs" |
| 164 | cmp -s $w/README.md README.md || fail "si ($t): README.md is not what compiler/si.om makes from the committed inputs" |
| 165 | cmp -s $w/repos.tsv repos.tsv || fail "si ($t): repos.tsv is not what compiler/si.om makes from the committed inputs" |
| 166 | pass "si ($t) regenerates README.md and repos.tsv byte for byte" |
| 167 | done |
| 168 | if [ -f $O/si-x86/si.sh ]; then |
| 169 | cmp -s $O/si-a64/si.sh $O/si-x86/si.sh || fail "si: the AArch64 and x86-64 builds write different si.sh" |
| 170 | pass "si: AArch64 and x86-64 builds write the same si.sh" |
| 171 | fi |
| 172 | cp $O/si-a64/si.sh $O/si.sh |
| 173 | note "si.sh sha256 $(sha $O/si.sh), from the Radicle state read at $(sed -n 's/^T\t//p' compiler/state.tsv); the served script is regenerated from Radicle at each site deploy" |
| 174 | if command -v rad >/dev/null 2>&1 && command -v jq >/dev/null 2>&1 && [ -d "${RAD_STORAGE:-$HOME/.radicle/storage}" ]; then |
| 175 | if sh tools/si-state.sh compiler/inventory.tsv > $O/state-now.tsv 2> $O/state-now.err; then |
| 176 | grep '^H' compiler/state.tsv | LC_ALL=C sort > $O/h-then.tsv |
| 177 | grep '^H' $O/state-now.tsv | LC_ALL=C sort > $O/h-now.tsv |
| 178 | moved=$(LC_ALL=C comm -13 $O/h-then.tsv $O/h-now.tsv | wc -l | tr -d ' ') |
| 179 | note "front door: $moved listed heads have moved on Radicle since compiler/state.tsv was read; regenerate with tools/si-state.sh (compiler/README.md)" |
| 180 | else |
| 181 | note "NOT_RUN front-door freshness: tools/si-state.sh failed: $(head -n 1 $O/state-now.err)" |
| 182 | fi |
| 183 | else |
| 184 | note "NOT_RUN front-door freshness: no rad, jq or Radicle storage here" |
| 185 | fi |
| 186 | |
| 187 | # The layer table is refused before a rebuild can run if any declared layer has no row. |
| 188 | a64 $O/omc < compiler/rebuild.om > $O/rebuild |
| 189 | mk $O/rebuild |
| 190 | a64 $O/rebuild check layers.tsv || fail "rebuild: refused layers.tsv" |
| 191 | pass "rebuild layer table" |
| 192 | |
| 193 | # 5b. The link table: compiler/links.om must accept this checkout (every repos.tsv row a valid, |
| 194 | # non-crypto RID; no project source vendored in) and refuse the same checkout with one RID broken. |
| 195 | for t in a64 x86; do |
| 196 | if [ $t = x86 ] && [ "$X86" = none ]; then note "NOT_RUN links on x86-64"; continue; fi |
| 197 | if [ $t = a64 ]; then |
| 198 | a64 $O/omc < compiler/links.om > $O/links-$t |
| 199 | else |
| 200 | { printf 'target x86linux\n'; cat compiler/links.om; } | x86 $O/omc-x86 > $O/links-$t |
| 201 | fi |
| 202 | mk $O/links-$t |
| 203 | $t $O/links-$t . > $O/links-$t.out 2>&1 || fail "links ($t) refused this checkout: $(cat $O/links-$t.out)" |
| 204 | w=$O/links-bad-$t |
| 205 | rm -rf $w && mkdir -p $w/compiler |
| 206 | awk -F'\t' 'BEGIN{OFS="\t"} NR==2{$2="rad:z2ft64" substr($2,11)} {print}' repos.tsv > $w/repos.tsv |
| 207 | ! cmp -s $w/repos.tsv repos.tsv || fail "links ($t): the crypto-RID control did not change repos.tsv" |
| 208 | if $t $O/links-$t $w > /dev/null 2> $w.err; then fail "links ($t) accepted a repos.tsv row with a crypto RID"; fi |
| 209 | grep -q 'withdrawn crypto project is never linked' $w.err || fail "links ($t) refused the crypto-RID control for another reason: $(cat $w.err)" |
| 210 | pass "links ($t) accepts this checkout and refuses a crypto RID" |
| 211 | done |
| 212 | |
| 213 | # 6. The stack ledger tool. |
| 214 | for t in a64 x86; do |
| 215 | if [ $t = x86 ] && [ "$X86" = none ]; then note "NOT_RUN ledger on x86-64"; continue; fi |
| 216 | if [ $t = a64 ]; then |
| 217 | a64 $O/omc < tools/ledger.om > $O/ledger-a64 |
| 218 | else |
| 219 | { printf 'target x86linux\n'; cat tools/ledger.om; } | x86 $O/omc-x86 > $O/ledger-x86 |
| 220 | fi |
| 221 | mk $O/ledger-$t |
| 222 | $t $O/ledger-$t < tests/ledger/input.tsv > $O/ledger-$t.out || fail "ledger ($t) refused tests/ledger/input.tsv" |
| 223 | cmp -s $O/ledger-$t.out tests/ledger/expected.tsv || fail "ledger ($t) output differs from tests/ledger/expected.tsv" |
| 224 | pass "ledger ($t) prints tests/ledger/expected.tsv" |
| 225 | done |
| 226 | |
| 227 | # 7. The Omega harness examples, on both targets. |
| 228 | sh tests/examples.sh "$O/omc" "$O/omc-x86" ${A64:+"$A64"} || fail "harness examples and regressions" |
| 229 | pass "harness examples and regressions" |
| 230 | |
| 231 | # 8. gpu/cuda-crack: the sm_121 tables and the 70 kernels that ran on the GB10, checked on the CPU. |
| 232 | # This is check/check.sh and gen/run.sh of cuda-crack, on both targets; their planted bugs are made |
| 233 | # by check/mutate.om, which must equal check.sh's own awk and od one-liners (ccmut) byte for byte. |
| 234 | C=gpu/cuda-crack |
| 235 | E3=$C/receipts/cudapp/evidence/CUDAPP-OM-ENCODER/chip-20261027T080240Z |
| 236 | T=$C/isa/sm121-forms.txt |
| 237 | (cd $C && sha256sum -c --quiet SHA256SUMS) || fail "cuda-crack: a file differs from gpu/cuda-crack/SHA256SUMS" |
| 238 | (cd $C/receipts && sha256sum -c --quiet SHA256SUMS) || fail "cuda-crack: a receipt differs from receipts/SHA256SUMS" |
| 239 | [ "$(sha $C/gen/bw_enc_sm121.om)" = fe16b024c3242d12c7c8ef759d84c34a22c7d21cba676cd987f4f3a1ff56ba86 ] \ |
| 240 | || fail "cuda-crack: gen/bw_enc_sm121.om is not the encoder of CUDApp b774723f" |
| 241 | pass "cuda-crack: $(wc -l < $C/SHA256SUMS | tr -d ' ') imported files and $(wc -l < $C/receipts/SHA256SUMS | tr -d ' ') receipts match their sha256 sums; the encoder is CUDApp b774723f's" |
| 242 | omb() { # omb TARGET OUT UNIT...: compile the units, one after another, for TARGET |
| 243 | ot=$1; oo=$2; shift 2 |
| 244 | if [ "$ot" = a64 ]; then cat "$@" | a64 $O/omc > "$oo" |
| 245 | else { printf 'target x86linux\n'; cat "$@"; } | x86 $O/omc-x86 > "$oo"; fi |
| 246 | mk "$oo" |
| 247 | } |
| 248 | ccmut() { # ccmut MODE FILE: the planted bug MODE of check/check.sh at cuda-crack 7e3c9a73, verbatim |
| 249 | case $1 in |
| 250 | 1) nop=$(awk '$1=="F" && $3==255 {print $5,$6,$7,$8,$9,$10}' "$2") |
| 251 | awk -v key="$nop" '$1=="F" && ($5" "$6" "$7" "$8" "$9" "$10)==key {if ($5 % 2 == 1) $5 = $5 - 1; else $5 = $5 + 1} {print}' "$2" ;; |
| 252 | 2) b0=$(od -An -tu1 -N1 "$2" | tr -d ' '); printf "$(printf '\\%03o' $((b0 ^ 1)))"; tail -c +2 "$2" ;; |
| 253 | 3) awk 'd == 0 && $1=="D" && $8 > 1 {$8 = $8 - 1; d = 1} {print}' "$2" ;; |
| 254 | 4) awk 'd == 0 && $1=="D" && $8 > 0 {w = int($7 / 32); $(4 + w) = $(4 + w) - 2 ^ ($7 % 32); d = 1} {print}' "$2" ;; |
| 255 | esac |
| 256 | } |
| 257 | tchk() { # tchk TABLE: reencode's exit status on TABLE's D records against its F records |
| 258 | rc=0 |
| 259 | { cat "$1"; printf 'E\n'; } | $t $w/reencode > /dev/null 2>&1 || rc=$? |
| 260 | echo $rc |
| 261 | } |
| 262 | rebuild() { # rebuild TABLE DIR: rebuild every chip kernel from TABLE into DIR; prints "kernels instructions unmatched" |
| 263 | mkdir -p "$2" |
| 264 | n=0; i=0; u=0 |
| 265 | for k in $E3/kernels-om/*.bin; do |
| 266 | { cat "$1"; printf 'E\n'; cat "$k"; } | $t $w/reencode > "$2/$(basename "$k")" 2> $w/err || true |
| 267 | read ni nu < $w/err || true |
| 268 | case "$ni:$nu" in *[!0-9:]*|:*|*:) echo "bad bad bad"; return ;; esac |
| 269 | n=$((n + 1)); i=$((i + ni)); u=$((u + nu)) |
| 270 | done |
| 271 | echo "$n $i $u" |
| 272 | } |
| 273 | tail -n +5 $T > $O/cc-forms.body |
| 274 | k1=$(ls $E3/kernels-om/*.bin | head -1) |
| 275 | for t in a64 x86; do |
| 276 | if [ $t = x86 ] && [ "$X86" = none ]; then note "NOT_RUN cuda-crack on x86-64"; continue; fi |
| 277 | w=$O/cc-$t |
| 278 | mkdir -p $w |
| 279 | omb $t $w/isa-gen $C/gen/bw_enc_sm121.om $C/gen/isa.om |
| 280 | $t $w/isa-gen > $w/forms.body || fail "cuda-crack ($t): gen/isa.om failed" |
| 281 | cmp -s $w/forms.body $O/cc-forms.body || fail "cuda-crack ($t): gen/isa.om does not regenerate isa/sm121-forms.txt" |
| 282 | pass "cuda-crack ($t): gen/isa.om probes the Omega encoder and regenerates all $(grep -c '^F' $O/cc-forms.body) forms of isa/sm121-forms.txt byte for byte" |
| 283 | omb $t $w/reencode $C/check/reencode.om |
| 284 | [ "$(tchk $T)" = 0 ] || fail "cuda-crack ($t): the D records of isa/sm121-forms.txt disagree with its F records" |
| 285 | set -- $(rebuild $T $w/k) |
| 286 | [ "$*" = "70 13520 0" ] || fail "cuda-crack ($t): rebuilt kernels, instructions, unmatched: $*; wanted 70 13520 0" |
| 287 | (cd $w/k && sha256sum *.bin) > $w/k.sha256 |
| 288 | cmp -s $w/k.sha256 $E3/kernels-om.sha256 || fail "cuda-crack ($t): kernels rebuilt from the tables differ from the chip receipt kernels-om.sha256" |
| 289 | pass "cuda-crack ($t): the tables' field records are consistent, and all 70 chip kernels (13520 instructions) rebuilt from the tables alone match the chip receipt" |
| 290 | omb $t $w/mutate $C/check/mutate.om |
| 291 | for f in $T $C/check/mutate-tests/*.txt; do |
| 292 | for m in 1 3 4; do |
| 293 | $t $w/mutate $m < "$f" > $w/mut.om.out || fail "cuda-crack ($t): mutate $m refused $f" |
| 294 | ccmut $m "$f" > $w/mut.sh.out |
| 295 | cmp -s $w/mut.om.out $w/mut.sh.out || fail "cuda-crack ($t): check/mutate.om mode $m differs from check.sh's awk on $f" |
| 296 | done |
| 297 | done |
| 298 | for k in $E3/kernels-om/*.bin; do |
| 299 | $t $w/mutate 2 < "$k" > $w/mut.om.out || fail "cuda-crack ($t): mutate 2 refused $k" |
| 300 | ccmut 2 "$k" > $w/mut.sh.out |
| 301 | cmp -s $w/mut.om.out $w/mut.sh.out || fail "cuda-crack ($t): check/mutate.om mode 2 differs from check.sh's od and printf on $k" |
| 302 | done |
| 303 | set +e |
| 304 | $t $w/mutate 2 < /dev/null > $w/mut.om.out 2> /dev/null; rc=$? |
| 305 | set -e |
| 306 | [ $rc = 1 ] && [ ! -s $w/mut.om.out ] || fail "control: mutate 2 accepted an empty kernel (exit $rc)" |
| 307 | pass "cuda-crack ($t): check/mutate.om makes check.sh's four planted bugs byte for byte (the table, $(ls $C/check/mutate-tests/*.txt | wc -l | tr -d ' ') edge cases, all 70 kernels) and refuses an empty kernel" |
| 308 | for m in 1 3 4; do $t $w/mutate $m < $T > $w/mut$m.txt; done |
| 309 | $t $w/mutate 2 < $k1 > $w/mut2.bin |
| 310 | set -- $(rebuild $w/mut1.txt $w/m1) |
| 311 | (cd $w/m1 && sha256sum *.bin) > $w/m1.sha256 |
| 312 | bad=$(diff $w/m1.sha256 $E3/kernels-om.sha256 | grep -c '^<' || true) |
| 313 | [ "$3:$bad" = "540:67" ] || fail "control ($t): a flipped fixed bit left $3 instructions unmatched and $bad kernels wrong; check/CHECK.txt has 540 and 67" |
| 314 | rc=0 |
| 315 | { cat $T; printf 'E\n'; cat $w/mut2.bin; } | $t $w/reencode > /dev/null 2>&1 || rc=$? |
| 316 | [ $rc = 4 ] || fail "control ($t): a corrupted instruction was accepted (reencode exit $rc, wanted 4)" |
| 317 | [ "$(tchk $w/mut3.txt)" = 7 ] || fail "control ($t): a field width off by one was accepted" |
| 318 | [ "$(tchk $w/mut4.txt)" = 7 ] || fail "control ($t): a field mask missing one bit was accepted" |
| 319 | pass "cuda-crack ($t) controls, as check/CHECK.txt: a flipped fixed bit fails 67 kernels, a corrupted instruction matches no form, a short field width and a short field mask are refused" |
| 320 | done |
| 321 | note "NOT_RUN cuda-crack on the GB10: running these kernels needs the chip; see gpu/cuda-crack/REPRODUCE.md" |
| 322 | |
| 323 | # 9. The fork-push generator: the script that sends my personal forks' branches to Radicle. |
| 324 | for t in a64 x86; do |
| 325 | if [ $t = x86 ] && [ "$X86" = none ]; then note "NOT_RUN forkpush on x86-64"; continue; fi |
| 326 | if [ $t = a64 ]; then |
| 327 | a64 $O/omc < tools/forkpush.om > $O/forkpush-a64 |
| 328 | else |
| 329 | { printf 'target x86linux\n'; cat tools/forkpush.om; } | x86 $O/omc-x86 > $O/forkpush-x86 |
| 330 | fi |
| 331 | mk $O/forkpush-$t |
| 332 | $t $O/forkpush-$t tests/forkpush/forks.tsv $O/fp-fixture-$t.sh || fail "forkpush ($t) refused tests/forkpush/forks.tsv" |
| 333 | cmp -s $O/fp-fixture-$t.sh tests/forkpush/expected.sh || fail "forkpush ($t) differs from tests/forkpush/expected.sh" |
| 334 | nbad=0 |
| 335 | for b in tests/forkpush/bad/*.tsv; do |
| 336 | rm -f $O/fp-bad.sh |
| 337 | if $t $O/forkpush-$t "$b" $O/fp-bad.sh 2>/dev/null; then fail "forkpush ($t) accepted $b"; fi |
| 338 | [ ! -e $O/fp-bad.sh ] || fail "forkpush ($t) wrote output for $b" |
| 339 | nbad=$((nbad + 1)) |
| 340 | done |
| 341 | $t $O/forkpush-$t stack/FORKS.tsv $O/fork-push-$t.sh || fail "forkpush ($t) refused stack/FORKS.tsv" |
| 342 | pass "forkpush ($t) prints tests/forkpush/expected.sh and refuses all $nbad bad manifests" |
| 343 | done |
| 344 | if [ -f $O/fork-push-x86.sh ]; then |
| 345 | cmp -s $O/fork-push-a64.sh $O/fork-push-x86.sh || fail "forkpush: the AArch64 and x86-64 builds write different fork-push.sh" |
| 346 | fi |
| 347 | sh -n $O/fork-push-a64.sh || fail "forkpush: the generated fork-push.sh does not parse" |
| 348 | cp $O/fork-push-a64.sh $O/fork-push.sh |
| 349 | pass "forkpush: out/fork-push.sh from stack/FORKS.tsv, $(grep -c "^fp '" $O/fork-push.sh) branches to push, sha256 $(sha $O/fork-push.sh)" |
| 350 | |
| 351 | # 10. The examples of words this repository adds to the compiler (seed/PROVENANCE.md), on both targets. |
| 352 | EXAMPLES_ROOT=tests/omc sh tests/examples.sh "$O/omc" "$O/omc-x86" ${A64:+"$A64"} || fail "tests/omc examples" |
| 353 | pass "tests/omc examples" |
| 354 | |
| 355 | # 11. Control: count without its slice check must be caught by the trap-3 examples. |
| 356 | awk '/^fn / { f = ($2 == "cnt_word") } f && $0 == "vs_chk e ro rn" { f = 0; next } { print }' $S/omc/omc.om > $B/omc.nochk.om |
| 357 | [ "$(wc -l < $B/omc.nochk.om)" -eq "$(($(wc -l < $S/omc/omc.om) - 1))" ] || fail "control: cnt_word's vs_chk line was not deleted exactly once" |
| 358 | a64 $O/omc < $B/omc.nochk.om > $B/omc-nochk || fail "control: the compiler without count's check does not build" |
| 359 | mk $B/omc-nochk |
| 360 | { printf 'target x86linux\n'; cat $B/omc.nochk.om; } | a64 $O/omc > $B/omc-x86-nochk || fail "control: omc-x86 without count's check does not build" |
| 361 | mk $B/omc-x86-nochk |
| 362 | [ "$(sha $B/omc-nochk)" != "$(sha $O/omc)" ] || fail "control: deleting count's check did not change omc" |
| 363 | if EXAMPLES_ROOT=tests/omc sh tests/examples.sh $B/omc-nochk $B/omc-x86-nochk ${A64:+"$A64"} > $B/nochk.log; then |
| 364 | fail "control: the compiler without count's slice check passed tests/omc" |
| 365 | fi |
| 366 | for t in a64 x86; do |
| 367 | if grep -q "^NOT_RUN $t " $B/nochk.log; then note "NOT_RUN control on $t"; continue; fi |
| 368 | for c in count_trap3 count_trap3_wrap; do |
| 369 | grep -q "^FAIL $t examples/$c: exit " $B/nochk.log || fail "control: $t examples/$c did not catch the missing check" |
| 370 | done |
| 371 | grep -qx "PASS $t examples/count_word" $B/nochk.log || fail "control: $t count_word failed for another reason" |
| 372 | done |
| 373 | pass "control: count without its slice check fails count_trap3 and count_trap3_wrap; count_word still passes" |
| 374 | |
| 375 | printf 'RC=0\n' |