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/tools/test_numeric_qualify.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 / tools / test_numeric_qualify.sh` 426 lines ยท 32263 bytes Raw Blame History 1 #!/bin/bash 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 # test_numeric_qualify.sh -- host-only tests of the Gate 5 (OMEGA-NUMERIC-0) 18 # qualifier in tests/run_numeric_gates.sh: physics pin checks, gate log 19 # checks and the immutable digest-named receipt writer. No GPU, no device. 20 # Everything is written under a temporary directory, never into evidence/. 21 # The "hardware" descriptors here are made up for the test and say so 22 # (UNIT_TEST_FAKE_NOT_HARDWARE); they are never from a device. 23 # Run: make test-numeric-qualify (or run this file). 24 set -u 25 HERE=$(cd -P "$(dirname "$0")/.." && pwd) 26 # shellcheck source=tests/run_numeric_gates.sh 27 . "$HERE/tests/run_numeric_gates.sh" 28 m19r_build_canon || { echo "FAIL: cannot build tools/json_canon.c"; exit 1; } 29 TMP=$(mktemp -d) 30 trap 'chmod -R u+w "$TMP"; rm -rf "$TMP" "$M19R_TMP"' EXIT 31 fails=0 32 ok() { echo " [PASS] $1"; } 33 bad() { echo " [FAIL] $1"; fails=$((fails + 1)); } 34 check() { if eval "$2"; then ok "$1"; else bad "$1"; fi; [ -z "${SHOW_ERR:-}" ] || echo " ($M19R_ERR)"; } 35 gitc() { git -C "$1" -c user.name=Test -c user.email=test@example.invalid "${@:2}"; } 36 37 echo "physics dependency comes from physics.lock" 38 phys=$TMP/physics 39 git init -q "$phys" 40 echo old > "$phys/README" 41 gitc "$phys" add README && gitc "$phys" commit -qm "no forge yet" 42 old=$(git -C "$phys" rev-parse HEAD) 43 omega=$TMP/omega 44 git init -q "$omega" 45 echo "$old" > "$omega/physics.lock" 46 gitc "$omega" add physics.lock && gitc "$omega" commit -qm lock 47 check "pinned commit without forge/ refused" '! num_check_physics "$omega" "$phys" "$old"' 48 check " message names forge and the owner decision" '[[ $M19R_ERR == *"has no forge/forge_descriptor.h"*"owner decision"* ]]' 49 mkdir -p "$phys/forge" "$phys/nvrm" "$phys/m16" 50 for f in forge/forge_descriptor.h forge/forge_descriptor.c forge/forge_realize.c sha256_clean.c nvrm/nvrm.c m16/m16_native.c; do 51 echo "/* stub */" > "$phys/$f" 52 done 53 gitc "$phys" add -A && gitc "$phys" commit -qm "forge" 54 new=$(git -C "$phys" rev-parse HEAD) 55 check "candidate differing from physics.lock refused" '! num_check_physics "$omega" "$phys" "$new"' 56 check " message shows both commits" '[ "$M19R_ERR" = "physics.lock pins $old but --physics-candidate is $new" ]' 57 check "checkout not at the pinned commit refused" '! num_check_physics "$omega" "$phys" "$old"' 58 check " message shows both commits" '[ "$M19R_ERR" = "physics checkout $phys is at $new but physics.lock pins $old" ]' 59 check "missing physics checkout refused" '! num_check_physics "$omega" "$TMP/nowhere" "$old"' 60 echo "$new" > "$omega/physics.lock" 61 gitc "$omega" commit -qam "move pin" 62 check "matching pin with forge/ accepted" 'num_check_physics "$omega" "$phys" "$new"' 63 echo dirty >> "$phys/README" 64 check "dirty physics tree refused" '! num_check_physics "$omega" "$phys" "$new"' 65 gitc "$phys" checkout -q README 66 echo "not-a-sha" > "$omega/physics.lock" 67 check "malformed physics.lock refused" '! num_check_physics "$omega" "$phys" "$new"' 68 echo "$new" > "$omega/physics.lock" 69 70 echo "gate log checks (comparison mode from the manifest, full launches, typed counts)" 71 fake_digest=$(printf 'UNIT_TEST_FAKE_NOT_HARDWARE' | sha256sum | cut -d' ' -f1) 72 LOG_BIN_SHA=$(printf 'unit-test-binary' | sha256sum | cut -d' ' -f1) 73 LOG_RUN_ID=unit-test-run 74 mode_of() { printf '%s\n' $NUM_OP_MANIFEST | awk -F: -v o="$1" '$1 == o { print $2 }'; } 75 # good_log -- what a passing chip run prints. The run line is the binary's 76 # own (run id + digest of /proc/self/exe); everything else is made up here. 77 good_log() { 78 local id op mode c 79 echo "OMEGA_NUMERIC_RUN_JSON:{\"run_id\":\"$LOG_RUN_ID\",\"binary_sha256\":\"$LOG_BIN_SHA\"}" 80 for op in $NUM_ENCODED_OPS; do 81 mode=$(mode_of "$op") 82 echo "OMEGA_NUMERIC_REGISTRY_JSON:{\"op\":\"$op\",\"encoded\":true,\"compare\":\"$mode\",\"launches\":$([ "$op" = FFMA ] && echo 8 || echo 1)}" 83 done 84 for id in $NUM_EXPECTED_IDS; do echo "[PASS] $id"; done 85 echo "OMEGA_NUMERIC_HWDESC_JSON:{\"source\":\"FORGE_PROBE\",\"descriptor_digest\":\"$fake_digest\",\"derived_alias\":\"UNIT_TEST_FAKE_NOT_HARDWARE\"}" 86 for op in $NUM_ENCODED_OPS; do 87 mode=$(mode_of "$op") 88 case $mode in 89 SEED_BOUND) echo "OMEGA_NUMERIC_PARITY_JSON:{\"op\":\"$op\",\"tier\":\"gb10\",\"compare\":\"SEED_BOUND\",\"n\":4096,\"checked\":3000,\"out_of_bound\":0,\"skipped\":1096}";; 90 *) if [ "$op" = FFMA ]; then 91 for c in $NUM_FFMA_C; do 92 echo "OMEGA_NUMERIC_PARITY_JSON:{\"op\":\"FFMA\",\"tier\":\"gb10\",\"compare\":\"$mode\",\"c_bits\":\"$c\",\"n\":4096,\"checked\":4096,\"mismatches\":0}" 93 done 94 elif [ "$op" = REDUCE_SUM ]; then 95 echo "OMEGA_NUMERIC_PARITY_JSON:{\"op\":\"REDUCE_SUM\",\"tier\":\"gb10\",\"compare\":\"$mode\",\"reduction_order\":\"$NUM_REDUCE_ORDER\",\"n\":4096,\"checked\":128,\"mismatches\":0}" 96 else 97 echo "OMEGA_NUMERIC_PARITY_JSON:{\"op\":\"$op\",\"tier\":\"gb10\",\"compare\":\"$mode\",\"n\":4096,\"checked\":4096,\"mismatches\":0}" 98 fi;; 99 esac 100 echo "OMEGA_NUMERIC_PARITY_JSON:{\"op\":\"$op\",\"tier\":\"cpu\",\"compare\":\"BIT_EXACT\",\"n\":4096,\"checked\":4096,\"mismatches\":0}" 101 done 102 } 103 good_log > "$TMP/good.log" 104 # gb10 LOG SED -- the good log with one sed edit applied to the GB10 lines only. 105 gb10() { sed "/\"tier\":\"gb10\"/{ 106 $2 107 }" "$TMP/good.log" > "$TMP/$1.log" 108 cmp -s "$TMP/good.log" "$TMP/$1.log" && bad "fixture $1: the edit changed nothing"; } 109 check "complete passing log accepted" 'num_check_log "$TMP/good.log"' 110 check " hardware digest read from the log" '[ "$NUM_HWDIGEST" = "$fake_digest" ]' 111 check " 49 GB10 parity lines kept (FFMA x8 + 41 ops)" '[ "$(printf "%s" "$NUM_PARITY" | jq length)" = 49 ]' 112 check " run id and binary digest read from the run line" '[ "$NUM_LOG_RUN_ID" = "$LOG_RUN_ID" ] && [ "$NUM_LOG_BINARY_SHA" = "$LOG_BIN_SHA" ]' 113 sed 's/"source":"FORGE_PROBE"/"source":"FAKE_NON_HARDWARE_CPU_ONLY","fake":true/' "$TMP/good.log" > "$TMP/fake.log" 114 check "CPU-only fake descriptor refused" '! num_check_log "$TMP/fake.log"' 115 check " as not a device probe" '[[ $M19R_ERR == "hardware descriptor is not a device probe"* ]]' 116 sed 's/"derived_alias"/"fake":true,"derived_alias"/' "$TMP/good.log" > "$TMP/fake2.log" 117 check "descriptor marked fake refused" '! num_check_log "$TMP/fake2.log"' 118 sed "s/$fake_digest/$(printf '0%.0s' {1..64})/" "$TMP/good.log" > "$TMP/zero.log" 119 check "all-zero descriptor digest refused" '! num_check_log "$TMP/zero.log"' 120 grep -v '"op":"SHFL_DOWN","tier":"gb10"' "$TMP/good.log" > "$TMP/noshfl.log" 121 check "missing GB10 parity line refused" '! num_check_log "$TMP/noshfl.log"' 122 check " naming the op" '[ "$M19R_ERR" = "no GB10 parity line for SHFL_DOWN" ]' 123 gb10 onebit '/"op":"FFMA".*"c_bits":"0x7f800000"/s/"mismatches":0/"mismatches":1/' 124 check "one GB10 mismatch in one FFMA launch refused" '! num_check_log "$TMP/onebit.log"' 125 gb10 err '/"op":"FADD"/s/"n":4096.*}/"error":-4}/' 126 check "GB10 launch error refused" '! num_check_log "$TMP/err.log"' 127 gb10 mufu '/"op":"MUFU_RCP"/s/"out_of_bound":0/"out_of_bound":3/' 128 check "MUFU seed out of bound refused" '! num_check_log "$TMP/mufu.log"' 129 sed 's/^\[PASS\] FP32_SIMT_OPCODES_ENCODED/[FAIL] FP32_SIMT_OPCODES_ENCODED/' "$TMP/good.log" > "$TMP/fail.log" 130 check "a failed test refused" '! num_check_log "$TMP/fail.log"' 131 grep -v 'NEG_FTZ_DETECTED_AND_REJECTED' "$TMP/good.log" > "$TMP/miss.log" 132 check "missing expected test refused" '! num_check_log "$TMP/miss.log"' 133 { cat "$TMP/good.log"; echo "[PASS] CPU_GB10_BIT_PARITY"; } > "$TMP/dup.log" 134 check "duplicated test refused" '! num_check_log "$TMP/dup.log"' 135 { cat "$TMP/good.log"; echo "[SKIP] CPU_GB10_BIT_PARITY (needs GB10)"; } > "$TMP/skip.log" 136 check "any SKIP refused" '! num_check_log "$TMP/skip.log"' 137 { cat "$TMP/good.log"; echo "[PASS] EXTRA_UNLISTED_TEST"; } > "$TMP/extra.log" 138 check "unlisted extra test refused" '! num_check_log "$TMP/extra.log"' 139 # Finding 5: the log does not choose its own comparison. 140 gb10 relabel '/"op":"FADD"/s/"compare":"BIT_EXACT","n":4096,"checked":4096,"mismatches":0/"compare":"SEED_BOUND","n":4096,"checked":4096,"mismatches":4096,"out_of_bound":0,"skipped":0/' 141 check "FADD relabelled SEED_BOUND with 4096 mismatches refused" '! num_check_log "$TMP/relabel.log"' 142 check " comparison taken from the manifest" '[ "$M19R_ERR" = "GB10 parity for FADD: comparison \"SEED_BOUND\" but the manifest says BIT_EXACT" ]' 143 gb10 relabel2 '/"op":"FSEL"/s/"compare":"INT_EXACT"/"compare":"BIT_EXACT"/' 144 check "FSEL relabelled BIT_EXACT refused" '! num_check_log "$TMP/relabel2.log"' 145 gb10 relabel3 '/"op":"F32_TO_F16"/s/"compare":"F16_BITS"/"compare":"BIT_EXACT"/' 146 check "F32_TO_F16 relabelled BIT_EXACT refused (manifest says F16_BITS)" '! num_check_log "$TMP/relabel3.log"' 147 gb10 e1mis '/"op":"F32_TO_BF16"/s/"mismatches":0/"mismatches":3/' 148 check "F32_TO_BF16 with 3 mismatches refused" '! num_check_log "$TMP/e1mis.log"' 149 gb10 e1gone '/"op":"FFMA_V"/d' 150 check "missing FFMA_V parity line refused" '! num_check_log "$TMP/e1gone.log"' 151 gb10 strn '/"op":"FMUL"/s/"n":4096,"checked":4096/"n":"4096","checked":"4096"/' 152 check "string-typed counts refused" '! num_check_log "$TMP/strn.log"' 153 gb10 strm '/"op":"FMUL"/s/"mismatches":0/"mismatches":"0"/' 154 check "string-typed mismatches refused" '! num_check_log "$TMP/strm.log"' 155 gb10 frac '/"op":"FMUL"/s/"mismatches":0/"mismatches":0.5/' 156 check "fractional count refused" '! num_check_log "$TMP/frac.log"' 157 # Finding 6: full corpus, every launch, exact identities and multiplicities. 158 gb10 small '/"op":"FADD"/s/"n":4096,"checked":4096/"n":1,"checked":1/' 159 check "n=1 checked=1 refused" '! num_check_log "$TMP/small.log"' 160 gb10 partial '/"op":"FADD"/s/"checked":4096/"checked":4095/' 161 check "partial check (4095 of 4096) refused" '! num_check_log "$TMP/partial.log"' 162 gb10 seedsum '/"op":"MUFU_RSQ"/s/"skipped":1096/"skipped":1000/' 163 check "seed-bound checked+skipped != n refused" '! num_check_log "$TMP/seedsum.log"' 164 gb10 seedzero '/"op":"MUFU_RSQ"/s/"checked":3000,"out_of_bound":0,"skipped":1096/"checked":0,"out_of_bound":0,"skipped":4096/' 165 check "seed-bound with nothing checked refused" '! num_check_log "$TMP/seedzero.log"' 166 grep -v '"op":"FFMA","tier":"gb10".*"c_bits":"0x\(`80000000`\|`00800000`\|`bf800000`\|`7fc00000`\|`7f800000`\|`00000003`\|`80800000`\)"' "$TMP/good.log" > "$TMP/ffma1.log" 167 check "a single FFMA launch refused" '! num_check_log "$TMP/ffma1.log"' 168 check " naming the missing launches" '[[ $M19R_ERR == "FFMA launches [\"0x3f800000\"], need exactly one per c in"* ]]' 169 gb10 ffmadup '/"op":"FFMA".*"c_bits":"0x80800000"/s/0x80800000/0x3f800000/' 170 check "a duplicated FFMA c (7 distinct of 8) refused" '! num_check_log "$TMP/ffmadup.log"' 171 { cat "$TMP/good.log"; grep '"op":"FFMA","tier":"gb10".*"c_bits":"0x7fc00000"' "$TMP/good.log"; } > "$TMP/ffma9.log" 172 check "a ninth FFMA launch refused" '! num_check_log "$TMP/ffma9.log"' 173 { cat "$TMP/good.log"; grep '"op":"FADD","tier":"gb10"' "$TMP/good.log"; } > "$TMP/fadd2.log" 174 check "a second FADD launch refused" '! num_check_log "$TMP/fadd2.log"' 175 gb10 cbits '/"op":"FADD"/s/"n":4096/"c_bits":"0x3f800000","n":4096/' 176 check "c_bits on a non-FFMA op refused" '! num_check_log "$TMP/cbits.log"' 177 gb10 stray '/"op":"FADD"/s/"op":"FADD"/"op":"NOPE"/' 178 check "parity line for an op outside the manifest refused" '! num_check_log "$TMP/stray.log"' 179 sed '/OMEGA_NUMERIC_REGISTRY_JSON:{"op":"FADD"/s/"compare":"BIT_EXACT"/"compare":"SEED_BOUND"/' "$TMP/good.log" > "$TMP/reg1.log" 180 check "registry comparison differing from the manifest refused" '! num_check_log "$TMP/reg1.log"' 181 sed '/OMEGA_NUMERIC_REGISTRY_JSON:{"op":"FFMA"/s/"launches":8/"launches":1/' "$TMP/good.log" > "$TMP/reg2.log" 182 check "registry launch count differing from the manifest refused" '! num_check_log "$TMP/reg2.log"' 183 { cat "$TMP/good.log"; echo 'OMEGA_NUMERIC_REGISTRY_JSON:{"op":"NOPE","encoded":true,"compare":"BIT_EXACT","launches":1}'; } > "$TMP/reg3.log" 184 check "registry encoding an op the manifest does not list refused" '! num_check_log "$TMP/reg3.log"' 185 # LDS_STS and REDUCE_SUM: one line each, full check, declared summation order. 186 grep -v '"op":"LDS_STS","tier":"gb10"' "$TMP/good.log" > "$TMP/nolds.log" 187 check "missing LDS_STS GB10 parity line refused" '! num_check_log "$TMP/nolds.log"' 188 check " naming the op" '[ "$M19R_ERR" = "no GB10 parity line for LDS_STS" ]' 189 gb10 ldsbit '/"op":"LDS_STS"/s/"mismatches":0/"mismatches":1/' 190 check "one LDS_STS mismatch refused" '! num_check_log "$TMP/ldsbit.log"' 191 gb10 redbit '/"op":"REDUCE_SUM"/s/"mismatches":0/"mismatches":1/' 192 check "one REDUCE_SUM mismatch refused" '! num_check_log "$TMP/redbit.log"' 193 gb10 redall '/"op":"REDUCE_SUM"/s/"checked":128/"checked":4096/' 194 check "REDUCE_SUM claiming all 4096 lanes checked refused" '! num_check_log "$TMP/redall.log"' 195 check " needs n/32 = 128 warp sums" '[ "$M19R_ERR" = "GB10 parity for REDUCE_SUM: checked 4096, need 128" ]' 196 gb10 redorder '/"op":"REDUCE_SUM"/s/"reduction_order":"[A-Z0-9_]*"/"reduction_order":"SEQUENTIAL_LANE_0_TO_31"/' 197 check "REDUCE_SUM with another summation order refused" '! num_check_log "$TMP/redorder.log"' 198 check " naming both orders" '[[ $M19R_ERR == *"SEQUENTIAL_LANE_0_TO_31"*"$NUM_REDUCE_ORDER"* ]]' 199 gb10 rednoorder '/"op":"REDUCE_SUM"/s/"reduction_order":"[A-Z0-9_]*",//' 200 check "REDUCE_SUM without a declared order refused" '! num_check_log "$TMP/rednoorder.log"' 201 gb10 faddorder '/"op":"FADD"/s/"n":4096/"reduction_order":"PAIRWISE_TREE_LANE_DELTA_16_8_4_2_1","n":4096/' 202 check "a summation order on an op that does not reduce refused" '! num_check_log "$TMP/faddorder.log"' 203 { cat "$TMP/good.log"; grep '"op":"REDUCE_SUM","tier":"gb10"' "$TMP/good.log"; } > "$TMP/red2.log" 204 check "a second REDUCE_SUM launch refused" '! num_check_log "$TMP/red2.log"' 205 grep -v '^OMEGA_NUMERIC_RUN_JSON' "$TMP/good.log" > "$TMP/norun.log" 206 check "log without the binary's run line refused" '! num_check_log "$TMP/norun.log"' 207 sed 's/"binary_sha256":"[0-9a-f]*"/"binary_sha256":""/' "$TMP/good.log" > "$TMP/nobin.log" 208 check "run line without a binary digest refused" '! num_check_log "$TMP/nobin.log"' 209 210 echo "evidence directory (receipts never land in a candidate tree)" 211 keep_evd=${NUM_EVIDENCE_DIR:-} 212 M19R_PHYSICS=$phys 213 NUM_EVIDENCE_DIR= 214 check "default evidence directory accepted" 'num_check_evidence_dir "$HERE"' 215 check " is ~/workspace/evidence-out/OMEGA-NUMERIC-0" '[ "$NUM_EVIDENCE_DIR" = "$(realpath -m "$HOME/workspace/evidence-out/OMEGA-NUMERIC-0")" ]' 216 check " and lies outside this repository" '! num_under "$NUM_EVIDENCE_DIR" "$HERE"' 217 NUM_EVIDENCE_DIR=$HERE/evidence/OMEGA-NUMERIC-0 218 check "evidence directory inside this repository refused" '! num_check_evidence_dir "$HERE"' 219 check " saying receipts must live outside the trees" '[[ $M19R_ERR == *"receipts must live outside the candidate trees" ]]' 220 NUM_EVIDENCE_DIR=$omega/evidence/OMEGA-NUMERIC-0 221 check "evidence directory inside the omega candidate refused" '! num_check_evidence_dir "$omega"' 222 NUM_EVIDENCE_DIR=$omega 223 check "the omega tree itself refused" '! num_check_evidence_dir "$omega"' 224 NUM_EVIDENCE_DIR=$phys/receipts 225 check "evidence directory inside the physics checkout refused" '! num_check_evidence_dir "$omega"' 226 NUM_EVIDENCE_DIR=$TMP/evd/../omega/receipts 227 check " also when reached through .." '! num_check_evidence_dir "$omega"' 228 ln -s "$omega" "$TMP/omega-link" 229 NUM_EVIDENCE_DIR=$TMP/omega-link/receipts 230 check " also when reached through a symlink" '! num_check_evidence_dir "$omega"' 231 NUM_EVIDENCE_DIR=$omega-sibling 232 check "a sibling whose name only starts like the tree accepted" 'num_check_evidence_dir "$omega"' 233 check "script refuses an in-tree --evidence-dir with exit 2, before any run" '"$HERE/tests/run_numeric_gates.sh" --omega-candidate x --physics-candidate y --evidence-dir "$HERE/evidence/OMEGA-NUMERIC-0-intree-probe" >/dev/null 2>&1; [ $? = 2 ] && [ ! -e "$HERE/evidence/OMEGA-NUMERIC-0-intree-probe" ]' 234 NUM_EVIDENCE_DIR=$keep_evd 235 236 cpu_bin=$HERE/build/test_omega_numeric_cpu 237 if [ -x "$cpu_bin" ]; then 238 "$cpu_bin" > "$TMP/cpu.log" 2>&1 239 check "real CPU-only run log refused (no receipt without the chip)" '! num_check_log "$TMP/cpu.log"' 240 # Drift: the test binary's own registry and FFMA launches equal the manifest. 241 m19r_tagged_json "$TMP/cpu.log" OMEGA_NUMERIC_REGISTRY_JSON | jq -sc . > "$TMP/cpu.reg" 242 check "binary registry equals the shell manifest" '[ -z "$(jq -r --argjson man "$(num_manifest_json)" "$NUM_JQ_REGISTRY" "$TMP/cpu.reg")" ]' 243 check "binary FFMA c values equal the shell manifest" '[ "$(m19r_tagged_json "$TMP/cpu.log" OMEGA_NUMERIC_PARITY_JSON | jq -sc "[.[] | select(.op == \"FFMA\" and .tier == \"cpu\") | .c_bits] | sort")" = "$(num_manifest_json | jq -c ".ffma_c | sort")" ]' 244 check "binary corpus size equals the shell manifest" '[ "$(m19r_tagged_json "$TMP/cpu.log" OMEGA_NUMERIC_PARITY_JSON | jq -s "[.[] | select(.tier == \"cpu\" and .op == \"FADD\") | .n] | .[0]")" = "$NUM_CORPUS_N" ]' 245 check "binary REDUCE_SUM checked count and summation order equal the shell manifest" '[ "$(m19r_tagged_json "$TMP/cpu.log" OMEGA_NUMERIC_PARITY_JSON | jq -sc "[.[] | select(.tier == \"cpu\" and .op == \"REDUCE_SUM\") | [.checked, .reduction_order]] | .[0]")" = "$(num_manifest_json | jq -c "[.checked.REDUCE_SUM, .reduction_order.REDUCE_SUM]")" ]' 246 else 247 bad "build/test_omega_numeric_cpu missing (run make test-numeric-cpu first)" 248 fi 249 250 echo "execution record: exit status, binary and log digests, run id" 251 # A stand-in gate binary: prints STUB_LOG, then the same run line the real 252 # binary prints (run id from OMEGA_NUMERIC_RUN_ID, digest of /proc/self/exe), 253 # then exits with STUB_RC. It also writes a line to stderr after every stdout 254 # line, as the real binary's refusal messages do. It proves the plumbing, 255 # never a chip result. 256 cat > "$TMP/stub.c" <<'STUB' 257 #include 258 #include 259 #include "sha256.h" 260 int main(void) { 261 const char *log = getenv("STUB_LOG"), *rc = getenv("STUB_RC"), *id = getenv("OMEGA_NUMERIC_RUN_ID"); 262 char line[4096], hex[65] = ""; 263 uint8_t buf[65536], dig[SHA256_DIGEST_SIZE]; 264 size_t got; 265 sha256_ctx ctx; 266 FILE *f = log ? fopen(log, "r") : NULL; 267 if (f) { while (fgets(line, sizeof line, f)) { fputs(line, stdout); fputs("stub stderr chatter\n", stderr); } fclose(f); } 268 f = fopen("/proc/self/exe", "rb"); 269 if (f) { 270 sha256_init(&ctx); 271 while ((got = fread(buf, 1, sizeof buf, f)) > 0) sha256_update(&ctx, buf, got); 272 sha256_final(&ctx, dig); 273 for (int i = 0; i < SHA256_DIGEST_SIZE; i++) snprintf(hex + 2 * i, 3, "%02x", dig[i]); 274 fclose(f); 275 } 276 printf("OMEGA_NUMERIC_RUN_JSON:{\"run_id\":\"%s\",\"binary_sha256\":\"%s\"}\n", id ? id : "", hex); 277 return rc ? atoi(rc) : 0; 278 } 279 STUB 280 grep -v '^OMEGA_NUMERIC_RUN_JSON' "$TMP/good.log" > "$TMP/stub_body.log" 281 mkdir -p "$omega/evidence" 282 echo '{"historical":true}' > "$omega/evidence/m19r_gate5_omega_numeric_evidence.json" 283 gitc "$omega" add -A && gitc "$omega" commit -qm "historical evidence" 284 NUM_OMEGA_CAND=$(git -C "$omega" rev-parse HEAD) NUM_PHYSICS_CAND=$new M19R_PHYSICS=$phys 285 NUM_TS=$(date -u +%Y-%m-%dT%H:%M:%S.%6NZ) NUM_RECORD=0 286 EVD=$TMP/evidence-out/OMEGA-NUMERIC-0 NUM_EVIDENCE_DIR=$TMP/evidence-out/OMEGA-NUMERIC-0 287 export STUB_LOG=$TMP/stub_body.log 288 # fresh_run RC -- a new run directory, build the stand-in, run it like num_qualify. 289 fresh_run() { 290 NUM_RUN_ID=unit-$1-$RANDOM NUM_RUN_DIR=$TMP/run-$NUM_RUN_ID 291 mkdir -p "$NUM_RUN_DIR" 292 gcc -std=gnu11 -O2 -I"$HERE/src" -o "$NUM_RUN_DIR/test_omega_numeric" "$TMP/stub.c" "$HERE/src/omega_om_units.c" || return 1 293 NUM_BINARY_SHA=$(m19r_sha_file "$NUM_RUN_DIR/test_omega_numeric") 294 NUM_RUN_COMMIT=$NUM_OMEGA_CAND 295 STUB_RC=$1 num_execute "$omega" "$NUM_RUN_DIR/test_omega_numeric" 296 } 297 # Finding 7: a nonzero exit status disqualifies, whatever the log says. 298 check "binary printing only passing records but exiting 3 refused" '! fresh_run 3' 299 check " exit status recorded" '[ "$NUM_EXEC_RC" = 3 ] && [ "$(cat "$NUM_RUN_DIR/gate5.status")" = 3 ]' 300 check " its log passes every log check on its own" 'num_check_log "$NUM_RUN_DIR/gate5.log"' 301 check " yet no receipt from it" '! num_receipt "$omega" "$NUM_RUN_DIR/gate5.log" && [ ! -e "$NUM_RUN_DIR/receipt-preview.json" ]' 302 NUM_EXEC_RC=0 303 check " nor with the exit status variable forged to 0 (status file says 3)" '! num_receipt "$omega" "$NUM_RUN_DIR/gate5.log"' 304 305 check "binary exiting 0 accepted by the executor" 'fresh_run 0' 306 check " stderr chatter kept out of the gate log" 'num_check_log "$NUM_RUN_DIR/gate5.log" && ! grep -q chatter "$NUM_RUN_DIR/gate5.log" && grep -q chatter "$NUM_RUN_DIR/gate5.stderr" && [ "$NUM_STDERR_SHA" = "$(m19r_sha_file "$NUM_RUN_DIR/gate5.stderr")" ]' 307 check "passing run makes a PASS preview" 'num_receipt "$omega" "$NUM_RUN_DIR/gate5.log" && [ -f "$NUM_RUN_DIR/receipt-preview.json" ]' 308 pv=$NUM_RUN_DIR/receipt-preview.json 309 check " status PASS, exit status 0, digests bound" '[ "$(jq -r "(.status == \"PASS\") and (.gate_stderr_sha256 == \"$NUM_STDERR_SHA\") and (.digest_meaning | startswith(\"integrity only, not authenticity\")) and (.gate_binary_exit_status == 0) and (.candidate_binary_sha256 == \"$NUM_BINARY_SHA\") and (.gate_log_sha256 == \"$NUM_LOG_SHA\") and (.run_id == \"$NUM_RUN_ID\")" "$pv")" = true ]' 310 check " clean flags from git status, commits from git" '[ "$(jq -r "(.candidate_trees_clean == {\"omega\":true,\"physics\":true}) and (.run_git_commit == \"$NUM_OMEGA_CAND\") and (.candidate_git_commit == .run_git_commit)" "$pv")" = true ]' 311 check " observed counts 26/26/0, historical untouched, predecessor recorded" '[ "$(jq -c "[.observed_test_count,.observed_pass_count,.observed_fail_count]" "$pv")" = "[26,26,0]" ] && [ "$(cat "$omega/evidence/m19r_gate5_omega_numeric_evidence.json")" = "{\"historical\":true}" ] && [ "$(jq -r ".predecessor_historical_gate5_sha256 | length" "$pv")" = 64 ]' 312 check " no permanent receipt without --record" '[ ! -e "$EVD" ] && [ ! -e "$omega/evidence/OMEGA-NUMERIC-0" ]' 313 # Finding 4: nothing is taken on trust at receipt time. 314 cp "$TMP/good.log" "$TMP/fabricated.log" 315 check "fabricated log outside the run refused" '! num_receipt "$omega" "$TMP/fabricated.log"' 316 echo x >> "$NUM_RUN_DIR/gate5.stderr" 317 check "stderr changed after the run refused" '! num_receipt "$omega" "$NUM_RUN_DIR/gate5.log" && [[ $M19R_ERR == "gate stderr changed since the run"* ]]' 318 sed -i '$d' "$NUM_RUN_DIR/gate5.stderr" 319 cp "$NUM_RUN_DIR/gate5.log" "$TMP/keep.log" 320 cp "$TMP/good.log" "$NUM_RUN_DIR/gate5.log" 321 check "log replaced after the run refused" '! num_receipt "$omega" "$NUM_RUN_DIR/gate5.log"' 322 check " as changed since the run" '[[ $M19R_ERR == "gate log changed since the run"* ]]' 323 cp "$TMP/keep.log" "$NUM_RUN_DIR/gate5.log" 324 keep_sha=$NUM_BINARY_SHA 325 NUM_BINARY_SHA=$(printf 'other' | sha256sum | cut -d' ' -f1) 326 check "64-hex binary digest not matching the built binary refused" '! num_receipt "$omega" "$NUM_RUN_DIR/gate5.log"' 327 NUM_BINARY_SHA=$keep_sha 328 cp "$NUM_RUN_DIR/test_omega_numeric" "$TMP/keep.bin" 329 printf 'x' >> "$NUM_RUN_DIR/test_omega_numeric" 330 check "binary changed after the run refused" '! num_receipt "$omega" "$NUM_RUN_DIR/gate5.log"' 331 cp "$TMP/keep.bin" "$NUM_RUN_DIR/test_omega_numeric" 332 # A log whose run line names another binary, with every stored digest made to agree. 333 sed "s/\"binary_sha256\":\"[0-9a-f]*\"/\"binary_sha256\":\"$LOG_BIN_SHA\"/" "$TMP/keep.log" > "$NUM_RUN_DIR/gate5.log" 334 keep_log_sha=$NUM_LOG_SHA NUM_LOG_SHA=$(m19r_sha_file "$NUM_RUN_DIR/gate5.log") 335 check "log produced by a different binary refused" '! num_receipt "$omega" "$NUM_RUN_DIR/gate5.log"' 336 check " naming both digests" '[ "$M19R_ERR" = "log was produced by binary $LOG_BIN_SHA, not $NUM_BINARY_SHA" ]' 337 cp "$TMP/keep.log" "$NUM_RUN_DIR/gate5.log"; NUM_LOG_SHA=$keep_log_sha 338 keep_id=$NUM_RUN_ID NUM_RUN_ID=unit-other-run 339 mv "$NUM_RUN_DIR" "$TMP/run-$NUM_RUN_ID"; keep_dir=$NUM_RUN_DIR NUM_RUN_DIR=$TMP/run-$NUM_RUN_ID 340 check "log from another run id refused" '! num_receipt "$omega" "$NUM_RUN_DIR/gate5.log"' 341 mv "$NUM_RUN_DIR" "$keep_dir"; NUM_RUN_DIR=$keep_dir NUM_RUN_ID=$keep_id 342 NUM_RUN_COMMIT=`0000000000000000000000000000000000000000` 343 check "run commit differing from candidate refused" '! num_receipt "$omega" "$NUM_RUN_DIR/gate5.log"' 344 NUM_RUN_COMMIT=$NUM_OMEGA_CAND 345 keep_cand=$NUM_OMEGA_CAND NUM_OMEGA_CAND=$(printf '%040d' 1) 346 check "omega candidate not at HEAD refused" '! num_receipt "$omega" "$NUM_RUN_DIR/gate5.log"' 347 NUM_OMEGA_CAND=$keep_cand 348 echo dirty > "$omega/untracked" 349 check "dirty omega tree at receipt time refused" '! num_receipt "$omega" "$NUM_RUN_DIR/gate5.log"' 350 rm -f "$omega/untracked" 351 echo dirty >> "$phys/README" 352 check "dirty physics tree at receipt time refused" '! num_receipt "$omega" "$NUM_RUN_DIR/gate5.log"' 353 gitc "$phys" checkout -q README 354 check "num_tree_clean reads real git status" '[ "$(num_tree_clean "$omega")" = true ] && echo x > "$omega/untracked" && [ "$(num_tree_clean "$omega")" = false ] && rm -f "$omega/untracked"' 355 check "recheck passes again once restored" 'num_receipt "$omega" "$NUM_RUN_DIR/gate5.log"' 356 NUM_RECORD=1 357 check "PASS receipt into a repository other than this script's refused" '! num_receipt "$omega" "$NUM_RUN_DIR/gate5.log"' 358 check " and nothing written" '[ ! -e "$EVD" ] && [ ! -e "$omega/evidence/OMEGA-NUMERIC-0" ]' 359 keep_m19r=$M19R_OMEGA M19R_OMEGA=$omega 360 check "PASS receipt recorded (script repository = this tree)" 'num_receipt "$omega" "$NUM_RUN_DIR/gate5.log" && [ -f "$EVD/$NUM_DIGEST.json" ] && [ "$NUM_PERMANENT" = "$(realpath -m "$EVD")/$NUM_DIGEST.json" ]' 361 prec=$EVD/$NUM_DIGEST.json 362 check " outside the tree, which stays clean" '[ "$(num_tree_clean "$omega")" = true ] && [ "$(num_tree_clean "$phys")" = true ] && [ ! -e "$omega/evidence/OMEGA-NUMERIC-0" ]' 363 check " binds run id, both commits, clean flags and binary digest" '[ "$(jq -r "(.status == \"PASS\") and (.run_id == \"$NUM_RUN_ID\") and (.candidate_git_commit == \"$NUM_OMEGA_CAND\") and (.physics_candidate_git_commit == \"$NUM_PHYSICS_CAND\") and (.candidate_trees_clean == {\"omega\":true,\"physics\":true}) and (.candidate_binary_sha256 == \"$NUM_BINARY_SHA\")" "$prec")" = true ]' 364 check " named by its digest, mode 0444" '[ "$(jq "del(.receipt_digest)" "$prec" | "$JSON_CANON" --sha256)" = "$NUM_DIGEST" ] && [ "$(stat -c %a "$prec")" = 444 ]' 365 check " a second record of the same PASS refused" '! num_receipt "$omega" "$NUM_RUN_DIR/gate5.log" && [ "$(ls "$EVD"/*.json | wc -l)" = 1 ]' 366 NUM_EVIDENCE_DIR=$omega/evidence/OMEGA-NUMERIC-0 367 check "PASS receipt into an in-tree evidence directory refused" '! num_receipt "$omega" "$NUM_RUN_DIR/gate5.log" && [ ! -e "$omega/evidence/OMEGA-NUMERIC-0" ]' 368 # Review finding: blobs/ planted as a symlink into the candidate tree. The 369 # evidence directory itself is outside; only blobs/ points in. 370 EVS=$TMP/evidence-symlinked; mkdir -p "$EVS" "$omega/planted"; ln -s "$omega/planted" "$EVS/blobs" 371 NUM_EVIDENCE_DIR=$EVS 372 check "blobs/ symlinked into the omega tree refused" '! num_receipt "$omega" "$NUM_RUN_DIR/gate5.log" && [[ $M19R_ERR == "blob directory "*"inside"* ]]' 373 check " nothing written through the link, no receipt" '[ -z "$(ls -A "$omega/planted")" ] && ! ls "$EVS"/*.json >/dev/null 2>&1' 374 rm -rf "$EVS" "$omega/planted" 375 NUM_EVIDENCE_DIR=$EVD M19R_OMEGA=$keep_m19r 376 rm -f "$prec" 2>/dev/null || { chmod u+w "$EVD"; rm -f "$prec"; } 377 378 echo "append-only receipts" 379 NUM_EXEC_RC=3 380 # No git exclude needed: receipts live outside the tree, so it stays clean 381 # and a repeat receipt is byte-identical. 382 check "failed run writes a FAIL receipt" 'num_fail_receipt "$omega" "gate binary exited with status 3"' 383 frec=$EVD/$NUM_DIGEST.json 384 check " named by its digest, mode 0444" '[ -f "$frec" ] && [ "$(jq "del(.receipt_digest)" "$frec" | "$JSON_CANON" --sha256)" = "$NUM_DIGEST" ] && [ "$(stat -c %a "$frec")" = 444 ]' 385 check " omega tree still clean after recording (reported true in the receipt)" '[ "$(num_tree_clean "$omega")" = true ] && [ "$(jq -r .candidate_trees_clean.omega "$frec")" = true ] && [ "$(jq -r ".run_id == \"$NUM_RUN_ID\"" "$frec")" = true ]' 386 check " status FAIL with the reason and exit status" '[ "$(jq -r "(.status == \"FAIL\") and (.error == \"gate binary exited with status 3\") and (.gate_binary_exit_status == 3)" "$frec")" = true ]' 387 check " blobs kept beside it, named by hash, mode 0444" '( for p in "log:$(jq -r .gate_log_sha256 "$frec")" "stderr:$(jq -r .gate_stderr_sha256 "$frec")" "bin:$(jq -r .candidate_binary_sha256 "$frec")"; do b=$EVD/blobs/${p#*:}.${p%%:*}; [ -f "$b" ] && [ "$(m19r_sha_file "$b")" = "${p#*:}" ] && [ "$(stat -c %a "$b")" = 444 ] || exit 1; done )' 388 check " the blobs are this run's files" 'cmp -s "$EVD/blobs/$(jq -r .gate_log_sha256 "$frec").log" "$NUM_RUN_DIR/gate5.log" && cmp -s "$EVD/blobs/$(jq -r .candidate_binary_sha256 "$frec").bin" "$NUM_RUN_DIR/test_omega_numeric"' 389 orig=$(sha256sum < "$frec") 390 check "same FAIL receipt again refused (never overwritten)" '! num_fail_receipt "$omega" "gate binary exited with status 3"' 391 check " because the file exists" '[[ $M19R_ERR == *"$NUM_DIGEST"* ]]' 392 check " original bytes unchanged" '[ "$(sha256sum < "$frec")" = "$orig" ]' 393 check "a different failure appends a second receipt" 'num_fail_receipt "$omega" "another reason" && [ "$(ls "$EVD"/*.json | wc -l)" = 2 ] && [ "$(num_tree_clean "$omega")" = true ]' 394 NUM_EXEC_RC=0 395 check "PASS preview present before a late failure" 'rm -f "$NUM_RUN_DIR/receipt-preview.json" && NUM_RECORD=0 num_receipt "$omega" "$NUM_RUN_DIR/gate5.log" && [ "$(jq -r .status "$NUM_RUN_DIR/receipt-preview.json")" = PASS ]' 396 check "failure path (num_main) removes the PASS preview and records FAIL" 'num_on_failure "$omega" "late failure" 2>/dev/null && [ ! -e "$NUM_RUN_DIR/receipt-preview.json" ] && [ "$(jq -r "(.status == \"FAIL\") and (.error == \"late failure\")" "$NUM_PERMANENT")" = true ]' 397 urec=$TMP/immut/unit.json 398 check "immutable writer: first write" 'printf "{\"unit_test\":true,\"status\":\"PASS\"}" | m19r_write_immutable_receipt "$urec"' 399 check "immutable writer: overwrite refused, bytes kept" '! printf "{\"unit_test\":true,\"status\":\"FAIL\"}" | m19r_write_immutable_receipt "$urec" && [ "$(jq -r .status "$urec")" = PASS ]' 400 401 echo "GPU lock (flock) failure stops the run before any build or device access" 402 # qual_probe FLOCK_RC -- run num_qualify with flock, build and execute stubbed; 403 # the stubs leave marker files so the test sees how far the run got. 404 qual_probe() { 405 rm -f "$TMP/probe.built" "$TMP/probe.ran" 406 ( 407 M19R_OMEGA=$omega NUM_RUN_ID=unit-flock NUM_RUN_DIR=$TMP/run-flock 408 mkdir -p "$NUM_RUN_DIR" 409 flock() { return "$FLOCK_RC"; } 410 eval "real_m19r_git() $(declare -f m19r_git | tail -n +2)" 411 m19r_git() { [ -z "${GIT_BROKEN:-}" ] || return 1; real_m19r_git "$@"; } 412 num_build() { touch "$TMP/probe.built"; [ -n "${PROBE_BUILD_OK:-}" ] || return 1; : > "$3"; [ -n "${GIT_OK:-}" ] || GIT_BROKEN=1; } 413 num_execute() { touch "$TMP/probe.ran"; return 1; } 414 FLOCK_RC=$1 num_qualify 415 ) 416 } 417 check "control: with the lock taken, the run reaches the build" '! qual_probe 0 && [ -e "$TMP/probe.built" ] && [ ! -e "$TMP/probe.ran" ]' 418 check "lock failure: run refused, nothing built, nothing run on the device" '! qual_probe 1 && [ ! -e "$TMP/probe.built" ] && [ ! -e "$TMP/probe.ran" ]' 419 check "HEAD unreadable after the build: run refused before the device" '! PROBE_BUILD_OK=1 qual_probe 0 && [ -e "$TMP/probe.built" ] && [ ! -e "$TMP/probe.ran" ]' 420 check " control: with HEAD readable the run reaches the device" '! PROBE_BUILD_OK=1 GIT_OK=1 qual_probe 0 && [ -e "$TMP/probe.ran" ]' 421 422 if [ "$fails" -ne 0 ]; then 423 echo "Gate 5 qualifier tests: $fails FAILED" 424 exit 1 425 fi 426 echo "Gate 5 qualifier tests: all passed"