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 / tools / runtime_portability_controls.sh

67 lines · 4346 bytes Raw Blame History
1#!/bin/sh
2# Negative and positive controls for tools/runtime_portability_check.sh (omega-mv#596, slice R3).
3# usage: runtime_portability_controls.sh <scratch-dir> <table.tsv> <engine.mk>
4# Each control builds a scratch copy of the GPU source files, breaks one thing, and requires the
5# checker to FAIL with the expected message (or, for the positive control, to still PASS).
6# A check that cannot fail proves nothing. Exit 0 only when every control behaves as required.
7scratch=$1; table=$2; mk=$3
8here=$(cd "$(dirname "$0")" && pwd)
9chk="$here/runtime_portability_check.sh"
10[ -n "$scratch" ] && [ -f "$table" ] && [ -f "$mk" ] || { echo "usage: $0 <scratch-dir> <table.tsv> <engine.mk>"; exit 2; }
11ok=0
12
13fresh() { # fresh <name>: scratch root with a copy of the GPU files and the table
14 r="$scratch/$1"; rm -rf "$r"; mkdir -p "$r/src"
15 cp src/omega_gpu_* src/omega_blackwell_* src/omega_bw_* "$r/src/"
16 cp "$table" "$r/table.tsv"
17}
18expect_fail() { # expect_fail <name> <pattern> <what was broken>
19 out=$("$chk" "$scratch/$1" "$scratch/$1/table.tsv" "$mk" 2>&1); rc=$?
20 if [ $rc -eq 1 ] && printf '%s\n' "$out" | grep -q "$2"; then
21 echo "CONTROL $1: FAIL as required ($3)"; printf '%s\n' "$out" | grep "$2" | head -2 | sed 's/^/ /'
22 else
23 echo "CONTROL $1: WRONG, the checker exit was $rc and did not report '$2' ($3)"; printf '%s\n' "$out" | head -5 | sed 's/^/ /'; ok=1
24 fi
25}
26expect_pass() {
27 out=$("$chk" "$scratch/$1" "$scratch/$1/table.tsv" "$mk" 2>&1); rc=$?
28 if [ $rc -eq 0 ]; then echo "CONTROL $1: PASS as required ($2)"
29 else echo "CONTROL $1: WRONG, the checker failed ($2)"; printf '%s\n' "$out" | head -5 | sed 's/^/ /'; ok=1; fi
30}
31setclass() { # setclass <name> <src/file> <class>
32 awk -F'\t' -v f="$2" -v c="$3" 'BEGIN{OFS="\t"} $1==f{$2=c} {print}' "$scratch/$1/table.tsv" > "$scratch/$1/t.new" && mv "$scratch/$1/t.new" "$scratch/$1/table.tsv"
33}
34
35fresh unchanged; expect_pass unchanged "scratch copy of the real tree and table"
36
37fresh new-file-no-row
38printf 'int omega_gpu_zz_dummy(void) { return 0; }\n' > "$scratch/new-file-no-row/src/omega_gpu_zz_dummy.c"
39expect_fail new-file-no-row "no row in the table for src/omega_gpu_zz_dummy.c" "a new omega_gpu_ file with no row"
40
41fresh row-missing-file
42printf 'src/omega_gpu_zz_ghost.c\tPORTABLE\tghost\tNO_HOSTED_INCLUDE\n' >> "$scratch/row-missing-file/table.tsv"
43expect_fail row-missing-file "row names a missing file: src/omega_gpu_zz_ghost.c" "a row for a file that does not exist"
44
45fresh portable-includes-nvrm
46printf '#include "nvrm.h"\n' | cat - "$scratch/portable-includes-nvrm/src/omega_gpu_wait.c" > "$scratch/p.c" && mv "$scratch/p.c" "$scratch/portable-includes-nvrm/src/omega_gpu_wait.c"
47expect_fail portable-includes-nvrm "omega_gpu_wait.c: PORTABLE but includes a Linux/NVRM header: nvrm.h" "a PORTABLE file that includes nvrm.h"
48
49fresh portable-row-on-linux-file
50setclass portable-row-on-linux-file src/omega_gpu_platform_linux.c PORTABLE
51expect_fail portable-row-on-linux-file "omega_gpu_platform_linux.c: PORTABLE but includes a Linux/NVRM header" "the real Linux backend relabelled PORTABLE"
52
53fresh portable-row-on-chip-file
54setclass portable-row-on-chip-file src/omega_blackwell_qmd.h PORTABLE
55setclass portable-row-on-chip-file src/omega_gpu_attention_api.c PORTABLE
56expect_fail portable-row-on-chip-file "omega_gpu_attention_api.c: PORTABLE but includes a Blackwell chip header" "a file that includes Blackwell headers relabelled PORTABLE"
57
58fresh guarded-include
59{ printf '#ifndef OMEGA_GPU_NO_POSIX\n#include "nvrm.h"\n#include <pthread.h>\n#endif\n'; cat "$scratch/guarded-include/src/omega_gpu_engine.c"; } > "$scratch/g.c" && mv "$scratch/g.c" "$scratch/guarded-include/src/omega_gpu_engine.c"
60expect_pass guarded-include "an nvrm.h include inside #ifndef OMEGA_GPU_NO_POSIX is the hosted-only build and must not count"
61
62fresh freestanding-claim-broken
63printf '#include <stdlib.h>\n' | cat - "$scratch/freestanding-claim-broken/src/omega_gpu_fmt.c" > "$scratch/g.c" && mv "$scratch/g.c" "$scratch/freestanding-claim-broken/src/omega_gpu_fmt.c"
64expect_fail freestanding-claim-broken "omega_gpu_fmt.c: is in GPU_FS_SRCS but the include scan finds stdlib.h" "a freestanding-closure file that gained stdlib.h"
65
66[ $ok -eq 0 ] && echo "ALL CONTROLS BEHAVED AS REQUIRED" || echo "A CONTROL DID NOT BEHAVE: the check is not trustworthy"
67exit $ok