physics-mv
FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence.
Brought by drakestapleton
physics-mv / tests / run_forge_v2_gates.sh
| 1 | #!/bin/bash |
| 2 | # tests/run_forge_v2_gates.sh -- FORGE SUBSTRATE V2 host-only gates. |
| 3 | # |
| 4 | # Builds the V2 reference serializer + KAT with the pinned root SHA-256 and |
| 5 | # runs it. No hardware, no driver, no GPU lock. |
| 6 | # |
| 7 | # tests/run_forge_v2_gates.sh build, run every check, verify the |
| 8 | # committed golden-vector doc matches |
| 9 | # tests/run_forge_v2_gates.sh --regen also rewrite docs/forge-v2-golden-vectors.md |
| 10 | # |
| 11 | # Exit code 0 only when every check passes. |
| 12 | set -uo pipefail |
| 13 | |
| 14 | SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) |
| 15 | REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd -P) |
| 16 | cd "$REPO_ROOT" || exit 1 |
| 17 | |
| 18 | BUILD_DIR="$REPO_ROOT/build" |
| 19 | BIN="$BUILD_DIR/test_forge_v2_kat" |
| 20 | DOC="docs/forge-v2-golden-vectors.md" |
| 21 | FAILS=0 |
| 22 | PASSES=0 |
| 23 | |
| 24 | gate() { # name, status(0 = pass) |
| 25 | if [ "$2" -eq 0 ]; then echo "PASS $1"; PASSES=$((PASSES + 1)); |
| 26 | else echo "FAIL $1"; FAILS=$((FAILS + 1)); fi |
| 27 | } |
| 28 | |
| 29 | echo "=== FORGE SUBSTRATE V2 gates (host-only) ===" |
| 30 | mkdir -p "$BUILD_DIR" |
| 31 | |
| 32 | gcc -O2 -Wall -Wextra -Werror -std=c11 -I./forge/v2 \ |
| 33 | forge/v2/forge_substrate_v2.c sha256_clean.c tests/test_forge_v2_kat.c \ |
| 34 | -o "$BIN" |
| 35 | gate "build_gcc_O2_Wall_Wextra_Werror_std_c11" $? |
| 36 | if [ ! -x "$BIN" ]; then |
| 37 | echo "RESULT gates: $PASSES passed, $((FAILS)) failed (build failed)" |
| 38 | exit 1 |
| 39 | fi |
| 40 | |
| 41 | "$BIN" |
| 42 | gate "kat_binary_all_checks" $? |
| 43 | |
| 44 | if [ "${1:-}" = "--regen" ]; then |
| 45 | "$BIN" --dump-vectors > "$DOC" |
| 46 | gate "golden_vectors_regenerated" $? |
| 47 | fi |
| 48 | "$BIN" --dump-vectors > "$BUILD_DIR/forge-v2-golden-vectors.md" |
| 49 | diff -u "$DOC" "$BUILD_DIR/forge-v2-golden-vectors.md" > /dev/null |
| 50 | gate "golden_vector_doc_matches_binary_output" $? |
| 51 | |
| 52 | # Vendor-neutral canonical names: no vendor or product word in any V2 identifier. |
| 53 | ! grep -nE '\b[A-Za-z_]*(NVIDIA|Nvidia|nvidia|GB10|gb10|BLACKWELL|Blackwell|blackwell|CUDA|cuda|NVRM|nvrm)[A-Za-z_0-9]*\b' \ |
| 54 | forge/v2/forge_substrate_v2.h forge/v2/forge_substrate_v2.c \ |
| 55 | | grep -vE '^\S+:[0-9]+:\s*(/\*|\*)' > /dev/null |
| 56 | gate "no_vendor_names_in_v2_identifiers" $? |
| 57 | |
| 58 | # No hardware / driver / allocation in the reference code. |
| 59 | ! grep -nE '#include\s*[<"](nvrm|nv|cuda|sys/ioctl|sys/mman|fcntl)' forge/v2/*.c forge/v2/*.h tests/test_forge_v2_kat.c > /dev/null \ |
| 60 | && ! grep -nE '\b(malloc|calloc|realloc|free|ioctl|mmap|open)\s*\(' forge/v2/*.c > /dev/null |
| 61 | gate "no_hardware_access_no_heap_in_v2" $? |
| 62 | |
| 63 | # R16 loop-inventory heuristics: no endless loops and no loop naming wait/event words. |
| 64 | ! grep -nE 'while\s*\(\s*(1|true)\s*\)|for\s*\(\s*;\s*;\s*\)' forge/v2/*.c tests/test_forge_v2_kat.c > /dev/null \ |
| 65 | && ! grep -niE '(^|[^a-z])(u?sleep|nanosleep|msleep|poll|recv|heartbeat|tick|dispatch|schedule|scheduler|orchestrate|orchestrator|turns?|pulse|yield|epoll|run_until_complete|max_steps|max_turns)([^a-z]|$)' \ |
| 66 | forge/v2/*.c forge/v2/*.h tests/test_forge_v2_kat.c > /dev/null |
| 67 | gate "r16_loop_inventory_heuristics_clean" $? |
| 68 | |
| 69 | echo "RESULT gates: $PASSES passed, $FAILS failed" |
| 70 | [ "$FAILS" -eq 0 ] |