interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / tests / test_chip_run_trap_manifest.sh

121 lines · 7819 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# Host-only check of tools/manifests/unwritten_trap.chiprun and its wrapper. No GPU, no build.
18# tests/test_chip_run_trap_manifest.sh
19# Checks: (1) manifest sets every required variable and names only existing sources;
20# (2) its gcc source list equals the old script's, pinned as a literal (git show 2dc9dd8:tools/run_unwritten_trap.sh);
21# (3) the wrapper with a missing physics dir prints REFUSED and the NOT_RUN line, exit 2;
22# (4) the module gcc flags equal the old script's; (5) the wrapper passes exit 0/1/2 through;
23# (6) the manifest sets CHILD_EXIT_PASSTHROUGH=1 and the old default args.
24# Each check is also run against a mutated manifest and must fail there.
25set -u
26HERE=$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
27MAN=$HERE/tools/manifests/unwritten_trap.chiprun
28T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
29FAILS=0
30ok() { echo "PASS $1"; }
31bad() { echo "FAIL $1"; FAILS=$((FAILS + 1)); }
32FAKE_PHYS=/nonexistent-physics-for-test
33
34# Prints "<TEST_SOURCE> <SOURCES> <EXTRA>" as one token per line, or fails.
35load_list() { ( PHYSICS=$FAKE_PHYS; . "$1" 2>/dev/null || exit 1; read -ra A <<< "$TEST_SOURCE $SOURCES $EXTRA_BUILD_SOURCES"; printf '%s\n' "${A[@]}" ); }
36check_vars() { ( PHYSICS=$FAKE_PHYS; . "$1" 2>/dev/null || exit 1
37 for v in GATE OWNER TEST_SOURCE SOURCES EXTRA_BUILD_SOURCES RUN_ARGS VERDICT_RE PASS_LINE EVIDENCE_DIR REFUSE_VERDICT_LINE REFUSE_EXIT REFUSE_DIRTY_OMEGA; do
38 [ -n "${!v:-}" ] || { echo "unset $v"; exit 1; }; done
39 [ "$REFUSE_EXIT" = 2 ] && [ "$REFUSE_VERDICT_LINE" = "OMEGA_UNWRITTEN_TRAP: NOT_RUN" ] && [ "$RUN_ARGS" = "--chip --repeats 3000" ] || { echo "old exit/line/args not kept"; exit 1; }
40 [ "$EVIDENCE_DIR" = "$HOME/workspace/evidence-out/OMEGA-UNWRITTEN-TRAP" ] && [ "${REQUIRE_ALL_PASS:-}" = 0 ] && [ "${CHILD_EXIT_PASSTHROUGH:-}" = 1 ] || { echo "evidence dir, REQUIRE_ALL_PASS or CHILD_EXIT_PASSTHROUGH wrong"; exit 1; }
41 for s in $TEST_SOURCE $SOURCES; do [ -f "$HERE/$s" ] || { echo "missing $s"; exit 1; }; done ); }
42# Old script, pinned as literals. Source: git show 2dc9dd8:tools/run_unwritten_trap.sh (the last
43# commit before the wrapper replaced it). origin/main no longer holds it once the wrapper merges.
44OLD_LIST='tests/test_omega_unwritten_trap_gb10.c
45src/omega_unwritten_trap.c
46src/omega_numeric_divsqrt_gb10.c
47src/omega_numeric_transc.c
48src/omega_numeric.c
49src/omega_numeric_provenance.c
50src/omega_blackwell_encoder.c
51src/omega_blackwell_codegen.c
52src/omega_blackwell_matmul.c
53src/omega_blackwell_qmd.c
54src/omega_om_units.c
55/nonexistent-physics-for-test/nvrm/nvrm.c
56/nonexistent-physics-for-test/m16/m16_native.c'
57# gcc flags and include paths of the old script, in order (the -o and its sources excluded).
58OLD_FLAGS='-std=gnu11
59-O2
60-Wall
61-Wextra
62-Werror
63-ffp-contract=off
64-fno-fast-math
65-pthread
66-Isrc
67-I"$PHYSICS/nvrm"
68-I"$PHYSICS/m16"
69-I"$NV/src/common/sdk/nvidia/inc"
70-I"$NV/kernel-open/common/inc"
71-I"$NV/kernel-open/nvidia-uvm"
72-I"$NV/src/nvidia/arch/nvalloc/unix/include"'
73check_list_matches_old() {
74 printf '%s\n' "$OLD_LIST" > "$T/old.list"
75 load_list "$1" > "$T/new.list" || { echo "manifest failed to load"; return 1; }
76 diff "$T/old.list" "$T/new.list" > "$T/diff.out" || { cat "$T/diff.out"; return 1; }; }
77# $1 = a copy of tools/chip_run.sh. Its gcc flags must equal OLD_FLAGS.
78check_flags_match_old() {
79 sed -n '/gcc -std=gnu11/,/-o "\$BIN"/p' "$1" | tr -s ' \\\n' '\n\n\n' | grep -E '^-' | grep -vx -- '-o' > "$T/new.flags"
80 printf '%s\n' "$OLD_FLAGS" > "$T/old.flags"
81 [ -s "$T/new.flags" ] || { echo "no gcc line found"; return 1; }
82 diff "$T/old.flags" "$T/new.flags" > "$T/diff.out" || { cat "$T/diff.out"; return 1; }; }
83# $1 = a copy of the wrapper. With a stub chip_run.sh beside it that exits $STUB_RC, the wrapper
84# must exit with exactly that code (the old script's 0 clean, 1 hits or device error, 2 NOT_RUN).
85check_wrapper_exit() {
86 local d=$T/w$RANDOM; mkdir -p "$d/tools/manifests"; cp "$1" "$d/tools/run_unwritten_trap.sh"
87 printf '#!/bin/bash\nexit "$STUB_RC"\n' > "$d/tools/chip_run.sh"; : > "$d/tools/manifests/unwritten_trap.chiprun"
88 local rc; for rc in 0 1 2; do STUB_RC=$rc bash "$d/tools/run_unwritten_trap.sh" > /dev/null 2>&1; [ "$?" = "$rc" ] || { echo "stub exit $rc came out as $?"; return 1; }; done; }
89
90# Mutants of the manifest.
91sed 's#^SOURCES="src/omega_unwritten_trap.c #SOURCES="#' "$MAN" > "$T/m_dropsrc"
92sed 's#src/omega_om_units.c#src/sha256_nope.c#' "$MAN" > "$T/m_badfile"
93sed '/^PASS_LINE=/d' "$MAN" > "$T/m_novar"
94sed 's#^REFUSE_EXIT=2#REFUSE_EXIT=1#' "$MAN" > "$T/m_exit"
95sed "s#evidence-out/OMEGA-UNWRITTEN-TRAP#evidence/unwritten_trap#" "$MAN" > "$T/m_evid"
96sed '/^CHILD_EXIT_PASSTHROUGH=/d' "$MAN" > "$T/m_nopass"
97sed 's#^RUN_ARGS="--chip --repeats 3000"#RUN_ARGS="--chip --repeats 300"#' "$MAN" > "$T/m_args"
98sed 's#-Werror #-Wno-error #' "$HERE/tools/chip_run.sh" > "$T/cr_noerror"
99sed 's#-O2 #-O3 #' "$HERE/tools/chip_run.sh" > "$T/cr_o3"
100sed 's#-fno-fast-math ##' "$HERE/tools/chip_run.sh" > "$T/cr_fastmath"
101sed 's#^exec \(.*\)$#\1; [ $? = 0 ] || exit 1#' "$HERE/tools/run_unwritten_trap.sh" > "$T/w_map"
102
103check_vars "$MAN" > "$T/o" 2>&1 && ok "1 manifest variables and source files" || { bad "1 manifest variables and source files: $(cat "$T/o")"; }
104check_list_matches_old "$MAN" > "$T/o" 2>&1 && ok "2 source list identical to old script" || bad "2 source list identical to old script: $(cat "$T/o")"
105
106for m in m_novar m_badfile m_exit m_evid m_nopass m_args; do check_vars "$T/$m" > /dev/null 2>&1 && bad "mutant $m passed check 1" || ok "mutant $m fails check 1"; done
107for m in m_dropsrc m_badfile; do check_list_matches_old "$T/$m" > /dev/null 2>&1 && bad "mutant $m passed check 2" || ok "mutant $m fails check 2"; done
108
109check_flags_match_old "$HERE/tools/chip_run.sh" > "$T/o" 2>&1 && ok "4 module gcc flags identical to old script" || bad "4 module gcc flags identical to old script: $(cat "$T/o")"
110for m in cr_noerror cr_o3 cr_fastmath; do check_flags_match_old "$T/$m" > /dev/null 2>&1 && bad "mutant $m passed check 4" || ok "mutant $m fails check 4"; done
111check_wrapper_exit "$HERE/tools/run_unwritten_trap.sh" > "$T/o" 2>&1 && ok "5 wrapper passes exit 0, 1, 2 through" || bad "5 wrapper passes exit 0, 1, 2 through: $(cat "$T/o")"
112check_wrapper_exit "$T/w_map" > /dev/null 2>&1 && bad "mutant w_map passed check 5" || ok "mutant w_map fails check 5"
113OUT=$(env -u PHYSICS_DIR PHYSICS=$FAKE_PHYS bash "$HERE/tools/run_unwritten_trap.sh" 2>&1); RC=$?
114{ [ "$RC" = 2 ] && printf '%s\n' "$OUT" | grep -q '^REFUSED: no physics checkout' && printf '%s\n' "$OUT" | grep -qx 'OMEGA_UNWRITTEN_TRAP: NOT_RUN'; } && ok "3 wrapper refuses with exit 2 and NOT_RUN line" || bad "3 wrapper refusal (rc=$RC): $OUT"
115# Mutant: the same wrapper pointed at a manifest with the wrong refuse exit must not give 2.
116cp "$T/m_exit" "$T/m_exit.chiprun"
117OUT=$(env -u PHYSICS_DIR PHYSICS=$FAKE_PHYS bash "$HERE/tools/chip_run.sh" "$T/m_exit.chiprun" 2>&1); RC=$?
118[ "$RC" = 2 ] && bad "mutant wrong REFUSE_EXIT still exits 2" || ok "mutant wrong REFUSE_EXIT does not exit 2"
119
120[ "$FAILS" = 0 ] && { echo "CHIP_RUN_TRAP_MANIFEST: PASS"; exit 0; }
121echo "CHIP_RUN_TRAP_MANIFEST: FAIL ($FAILS)"; exit 1