omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / tests / native / v2 / run.sh
| 1 | #!/bin/sh |
| 2 | # Native call ABI v2 qualification (docs/NATIVE-ABI.md, ABI v2). OMEGA_NATIVE_OMC builds the generator |
| 3 | # (pinned by tools/native). OMEGA_NATIVE_OMC2 compiles the ABI/hoist units: omega-mv hoist/865-main |
| 4 | # @7286d61d. OMEGA_NATIVE_HOST_OMC2 compiles section 11's host units: omega-mv #1008 @2992a68b. |
| 5 | # Neither upstream compiler contains the other's feature; both digests are checked below. Host-free |
| 6 | # --host parity still uses the hoisting compiler on both sides. No check is skipped for either role. |
| 7 | # A missing language toolchain is NOT_RUN, never PASS. `run.sh measure` also runs the cost measurement. |
| 8 | set -eu |
| 9 | ROOT=$(cd "$(dirname "$0")/../../.." && pwd) |
| 10 | T=$ROOT/tests/native/v2 |
| 11 | O=$ROOT/build/native-v2 |
| 12 | PIN=$(sed -n 's/^PIN=//p' "$ROOT/tools/native") |
| 13 | OMC=${OMEGA_NATIVE_OMC:?set OMEGA_NATIVE_OMC to the seeded omc (omega seed/out/omc, sha256 $PIN)} |
| 14 | OMC2=${OMEGA_NATIVE_OMC2:?set OMEGA_NATIVE_OMC2 to omega-mv hoist/865-main @7286d61d seed/out/omc} |
| 15 | HOST_OMC2=${OMEGA_NATIVE_HOST_OMC2:?set OMEGA_NATIVE_HOST_OMC2 to omega-mv #1008 @2992a68b seed/out/omc} |
| 16 | OMC2_PIN=078200466af2dc0452da7793b186d91bc9539f0cf5fafa15bcdb2a48e3bedef7 |
| 17 | HOST_OMC2_PIN=c000ec029fb85847084a82e345cb7b384cc678a735ed37e9fcbc0f557534b911 |
| 18 | DEVICE_OMC2=${OMEGA_NATIVE_DEVICE_OMC2:?set OMEGA_NATIVE_DEVICE_OMC2 to the context-format device compiler} |
| 19 | DEVICE_OMC2_PIN=6d1b1cf5a44803389a831b67f750ea4cd1c9f53edfde9d6d9241d7352887f1f8 |
| 20 | export OMEGA_NATIVE_OMC OMEGA_NATIVE_OMC2="$OMC2" |
| 21 | got=$(sha256sum < "$OMC" | cut -d' ' -f1) |
| 22 | [ "$got" = "$PIN" ] || { echo "FAIL omc sha256 $got, pinned $PIN"; exit 1; } |
| 23 | for role in hoist host; do |
| 24 | if [ "$role" = hoist ]; then compiler=$OMC2; pin=$OMC2_PIN; else compiler=$HOST_OMC2; pin=$HOST_OMC2_PIN; fi |
| 25 | digest=$(sha256sum < "$compiler" | cut -d' ' -f1) |
| 26 | [ "$digest" = "$pin" ] || { echo "FAIL $role OM-2 compiler sha256 $digest, pinned $pin"; exit 1; } |
| 27 | done |
| 28 | digest=$(sha256sum < "$DEVICE_OMC2" | cut -d' ' -f1) |
| 29 | [ "$digest" = "$DEVICE_OMC2_PIN" ] || { echo "FAIL device OM-2 compiler sha256 $digest, pinned $DEVICE_OMC2_PIN"; exit 1; } |
| 30 | rm -rf "$O"; mkdir -p "$O" |
| 31 | fails=0; notrun="" |
| 32 | pass() { echo "PASS $1"; } |
| 33 | fail() { echo "FAIL $1"; fails=$((fails + 1)); } |
| 34 | echo "INFO omc $got; OM-2 compiler $OMC2 sha256 $(sha256sum < "$OMC2" | cut -d' ' -f1)" |
| 35 | echo "INFO host OM-2 compiler $HOST_OMC2 sha256 $HOST_OMC2_PIN" |
| 36 | V2="vec lay one hoist" |
| 37 | units="$ROOT/tests/native/madd.om"; for u in $V2; do units="$units $T/$u.om"; done |
| 38 | if "$ROOT/tools/native" "$O" $units > "$O/tools-native.log" 2>&1; then pass "tools/native: madd (OM-1) + vec, lay, one, hoist (OM-2): library, six bindings, omega_api.h" |
| 39 | else fail "tools/native"; cat "$O/tools-native.log"; exit 1; fi |
| 40 | W=$O/work; GEN=$W/native-gen |
| 41 | |
| 42 | # basegen REV NAME: the historical generator, with the current C runtime prelude and only |
| 43 | # private assembly-linkage directives normalized. Public wrappers, signatures, compiler bytes |
| 44 | # and declarations remain byte-compared. The REV is reachable on main: f637021 is #26 (f32 and |
| 45 | # ushort kinds), the last intended change of the existing outputs. #26 changed the python output of |
| 46 | # every unit and admitted fsum and halve, so the earlier baselines (5458684, 3d79d77) no longer apply. |
| 47 | # The object-format spelling (#27: OMBR_* macros in fr/fv, and the Python loader's library name) is |
| 48 | # normalized by piece: a "~"-separated piece of a historical fr or fv text that equals the same piece |
| 49 | # of 7af4d11's (the last generator before #27) takes that piece of blob 5115113 (src/native.om as #27 |
| 50 | # left it). Both sides of that substitution are pinned objects, never this tree's src/native.om, so a |
| 51 | # change to any fr/fv piece here still fails the byte comparison. The closing quote of a text is not |
| 52 | # part of its last piece: #27's fr has two more pieces (the macOS host-word #error), which no |
| 53 | # historical generator emits. |
| 54 | basegen() { |
| 55 | PRE=$(grep '^text pre ' "$ROOT/src/native.om"); export PRE |
| 56 | NFR=$(git -C "$ROOT" cat-file blob 51151131855ee8c805bbc7a00dd60ceaf9f63a4d | grep -E '^text (fr|fv) '); export NFR |
| 57 | OFR=$(git -C "$ROOT" show 7af4d11:src/native.om | grep -E '^text (fr|fv) '); export OFR |
| 58 | OLOAD='import ctypes, os\n'; NLOAD='import ctypes, os, sys\n'; export OLOAD NLOAD |
| 59 | OLIB='os.path.abspath(__file__)), \"libomega_native.so\"))'; export OLIB |
| 60 | NLIB='os.path.abspath(__file__)),\n \"libomega_native.dylib\" if sys.platform == \"darwin\" else \"libomega_native.so\"))'; export NLIB |
| 61 | git -C "$ROOT" show "$1:src/native.om" | awk ' |
| 62 | function lrep(s, a, b, i) { i = index(s, a); return i ? substr(s, 1, i - 1) b substr(s, i + length(a)) : s } |
| 63 | BEGIN { split(ENVIRON["NFR"], nl, "\n"); split(ENVIRON["OFR"], ol, "\n") |
| 64 | for (i in nl) { split(nl[i], w, " "); sub(/"$/, "", nl[i]); nt[w[2]] = nl[i] } |
| 65 | for (i in ol) { split(ol[i], w, " "); sub(/"$/, "", ol[i]); ot[w[2]] = ol[i] } } |
| 66 | /^text pre /{print ENVIRON["PRE"]; next} |
| 67 | /^text tb /{$0 = lrep(lrep($0, ENVIRON["OLOAD"], ENVIRON["NLOAD"]), ENVIRON["OLIB"], ENVIRON["NLIB"])} |
| 68 | /^text fr |^text fv /{gsub(/[.]globl ombr_code_/, ".local ombr_code_"); gsub(/[.]globl ombr_entry_/, ".local ombr_entry_"); gsub(/[.]globl ombr2_code_/, ".local ombr2_code_"); gsub(/[.]globl ombr2_entry_/, ".local ombr2_entry_") |
| 69 | t = $2; sub(/"$/, "") |
| 70 | n = split($0, h, "~"); split(ot[t], o, "~"); m = split(nt[t], c, "~"); s = "" |
| 71 | for (k = 1; k <= n; k++) { if (k <= m && h[k] == o[k]) h[k] = c[k]; s = s (k > 1 ? "~" : "") h[k] } |
| 72 | $0 = s "\""} |
| 73 | {print}' > "$O/native-$2.om" |
| 74 | "$OMC" < "$O/native-$2.om" > "$O/gen-$2"; chmod +x "$O/gen-$2" |
| 75 | } |
| 76 | |
| 77 | # 1. Historical ABI v1 outputs: only C admits the exact counted seven-span zero-init |
| 78 | # insertion. Every other byte, including every non-C output, remains compared unchanged. |
| 79 | if python3 "$T/span_compare.py" --self-test; then pass "exact span comparison controls" |
| 80 | else fail "exact span comparison controls"; fi |
| 81 | basegen f637021 v1 |
| 82 | same=0; diff=0; v1units=0; : > "$O/v1set.in" |
| 83 | for u in "$ROOT"/tests/native/*.om "$ROOT"/tests/native/g1/*.om; do |
| 84 | "$OMC" < "$u" > "$O/one.bin" 2> /dev/null || continue |
| 85 | { cat "$u"; printf '\0'; printf '%08d' "$(wc -c < "$O/one.bin")"; cat "$O/one.bin"; } > "$O/one.in" |
| 86 | case "$u" in */g1/*) ;; *) cat "$O/one.in" >> "$O/v1set.in"; v1units=$((v1units + 1));; esac |
| 87 | for w in c h python rust zig go; do |
| 88 | a=0; "$O/gen-v1" $w < "$O/one.in" > "$O/a.out" 2> /dev/null || a=$? |
| 89 | b=0; "$GEN" $w < "$O/one.in" > "$O/b.out" 2> /dev/null || b=$? |
| 90 | equal=0 |
| 91 | if [ $a = $b ]; then |
| 92 | if [ "$w" = c ] && [ $a = 0 ]; then |
| 93 | python3 "$T/span_compare.py" "$O/a.out" "$O/b.out" 1 && equal=1 |
| 94 | elif cmp -s "$O/a.out" "$O/b.out"; then equal=1; fi |
| 95 | fi |
| 96 | if [ $equal = 1 ]; then same=$((same + 1)); else diff=$((diff + 1)); echo "DIFF $u $w ($a/$b)"; fi |
| 97 | done |
| 98 | done |
| 99 | for w in c h python rust zig go; do |
| 100 | "$O/gen-v1" $w < "$O/v1set.in" > "$O/a.out"; "$GEN" $w < "$O/v1set.in" > "$O/b.out" |
| 101 | equal=0 |
| 102 | if [ "$w" = c ]; then |
| 103 | python3 "$T/span_compare.py" "$O/a.out" "$O/b.out" "$v1units" && equal=1 |
| 104 | elif cmp -s "$O/a.out" "$O/b.out"; then equal=1; fi |
| 105 | if [ $equal = 1 ]; then same=$((same + 1)); else diff=$((diff + 1)); echo "DIFF set $w"; fi |
| 106 | done |
| 107 | if [ $diff = 0 ]; then pass "ABI v1 historical bindings equal except counted C span zero-init (1 per unit; $v1units in set; existing runtime/private normalization): $same cases" |
| 108 | else fail "ABI v1 bindings changed in $diff cases"; fi |
| 109 | |
| 110 | # 2. Identity: each v2 unit's embedded source digest equals sha256sum of its file (oracle), the omc digest |
| 111 | # equals sha256 of the OM-2 compiler used, and work/ident.txt records every unit, the OM-1 one included. |
| 112 | ok=1 |
| 113 | for u in $V2; do |
| 114 | want="omega-ident 1 unit=$u abi=2 profile=OM-2 src=$(sha256sum < "$T/$u.om" | cut -d' ' -f1) omc=$(sha256sum < "$OMC2" | cut -d' ' -f1)" |
| 115 | grep -q -F "\"$want\"" "$O/omega_native.c" || { ok=0; echo "missing: $want"; } |
| 116 | grep -q -F "OMEGA2_IDENT_$u \"$want\"" "$O/omega_native.h" || ok=0 |
| 117 | grep -q -F "$want path=$T/$u.om" "$W/ident.txt" || ok=0 |
| 118 | done |
| 119 | grep -q "unit=madd abi=1 profile=OM-1 src=$(sha256sum < "$ROOT/tests/native/madd.om" | cut -d' ' -f1) omc=$PIN" "$W/ident.txt" || ok=0 |
| 120 | if [ $ok = 1 ]; then pass "identities: source sha256 (computed by native.om) == sha256sum, omc digest, profile; ident.txt has the OM-1 unit too" |
| 121 | else fail "identity strings"; fi |
| 122 | |
| 123 | # 3. The embedded code is the compiler's bytes, unchanged (read at ombr2_code_<unit> in the library). |
| 124 | emb() { |
| 125 | s=$(objdump -t "$1" | awk -v n="$2" '$NF==n{print $1}') |
| 126 | [ -n "$s" ] || return 1 |
| 127 | objdump -h "$1" | awk '$2 ~ /^\./ {print $3, $4, $6}' | while read -r sz vma fo; do |
| 128 | if [ $((0x$vma)) -le $((0x$s)) ] && [ $((0x$s)) -lt $((0x$vma + 0x$sz)) ]; then echo $((0x$s - 0x$vma + 0x$fo)); break; fi |
| 129 | done |
| 130 | } |
| 131 | ok=1 |
| 132 | for u in $V2; do |
| 133 | off=$(emb "$O/libomega_native.so" "ombr2_code_$u") || { ok=0; continue; } |
| 134 | [ -n "$off" ] || { ok=0; continue; } |
| 135 | dd if="$O/libomega_native.so" bs=1 skip="$off" count="$(wc -c < "$W/$u.bin")" 2> /dev/null > "$O/$u.emb" |
| 136 | cmp -s "$W/$u.bin" "$O/$u.emb" || ok=0 |
| 137 | done |
| 138 | if [ $ok = 1 ]; then pass "embedded code == compiler output, per OM-2 unit"; else fail "embedded code differs"; fi |
| 139 | # Registers the code writes, decoded: the first operand of every instruction that has a destination (not |
| 140 | # a store, compare, test or branch), and the second one too of a load pair. hoist must write x20..x26 |
| 141 | # (hadd's seven hoisted constants) and some of d8..d15 (inner's conversions; s8..s15 count); no unit's code |
| 142 | # may name x18 (the platform register, which ombr_enter does not save), x19 or x29 at all (NATIVE-ABI.md: |
| 143 | # the trampoline's trap path rests on x19). A non-hoisting OMEGA_NATIVE_OMC2 fails here. |
| 144 | dst() { objdump -D -b binary -m aarch64 "$1" | awk -F'\t' 'NF >= 4 && $3 !~ /^(st|cmp|cmn|tst|cb|tb|b$|b\.|bl|br|ret|ccmp|fcmp|prfm|hint|nop|dmb)/ {split($4, a, ","); gsub(/ /, "", a[1]); print a[1]; if ($3 ~ /^ld(n|a?x)?p/) {gsub(/ /, "", a[2]); print a[2]}}' | sort -u; } |
| 145 | dst "$W/hoist.bin" > "$O/hoist.dst" |
| 146 | hx=$(grep -c -x -E 'x2[0-6]' "$O/hoist.dst" || true); hd=$(grep -c -x -E '[ds]([89]|1[0-5])' "$O/hoist.dst" || true) |
| 147 | if [ "$hx" = 7 ] && [ "$hd" -ge 1 ]; then pass "hoist writes x20..x26 and $hd of d8..d15 (decoded destinations)" |
| 148 | else fail "hoist writes $hx of x20..x26 and $hd of d8..d15: OMEGA_NATIVE_OMC2 does not hoist (omega-mv perf/omc-loop-checks)"; fi |
| 149 | ok=1; for u in $V2; do |
| 150 | if objdump -D -b binary -m aarch64 "$W/$u.bin" | awk -F'\t' 'NF >= 4' | cut -f4 | grep -q -w -E '[xw](18|19|29)'; then ok=0; echo "INFO $u names x18, x19 or x29"; fi |
| 151 | done |
| 152 | if [ $ok = 1 ]; then pass "no OM-2 unit's code names x18, x19 or x29"; else fail "a unit's code names x18, x19 or x29"; fi |
| 153 | # The exported symbols: one omega2_ per export, one ident per unit, the OM-1 unit's omega_, nothing else. |
| 154 | nm -D --defined-only "$O/libomega_native.so" | awk '{print $3}' | grep -E '^omega' | sort > "$O/syms.txt" |
| 155 | printf '%s\n' omega2_absorb omega2_bsum omega2_digest omega2_fillv omega2_hadd omega2_halt omega2_ident_hoist omega2_ident_lay \ |
| 156 | omega2_ident_one omega2_ident_vec omega2_lsum omega2_swap8 omega2_two omega2_vcopy omega2_vlen omega2_vpart omega2_wsum omega_madd \ |
| 157 | | sort > "$O/syms.want" |
| 158 | if cmp -s "$O/syms.txt" "$O/syms.want"; then pass "exported symbols: 17 omega2_ (13 exports, 4 idents) + omega_madd; no psum, no v1 name for a v2 unit" |
| 159 | else fail "exported symbols"; diff "$O/syms.want" "$O/syms.txt" || true; fi |
| 160 | if nm --defined-only "$O/libomega_native.so" | awk '$3 ~ /^ombr2_code_/ {n++; if ($2 != "t") bad=1} END {exit bad || n != 4}'; then |
| 161 | pass "ABI v2 embedded code labels are private local text symbols" |
| 162 | else fail "ABI v2 private code linkage"; fi |
| 163 | if nm --defined-only "$O/libomega_native.so" | awk '$3 ~ /^ombr/ && $2 !~ /^[a-z]$/ {bad=1} END {exit bad}'; then |
| 164 | pass "all ABI v1/v2 private runtime, code and entry symbols have local binding" |
| 165 | else fail "nonlocal private runtime symbol"; fi |
| 166 | |
| 167 | # 4. No caller declares an Omega function by hand. |
| 168 | if grep -n -E 'uint32_t omega|fn omega|argtypes|CDLL|import "C"' "$T"/caller.* > "$O/hand.log"; then |
| 169 | fail "a caller declares an Omega function by hand"; cat "$O/hand.log" |
| 170 | else pass "no v2 caller declares an Omega function by hand"; fi |
| 171 | |
| 172 | # 5. The six language callers (oracles). |
| 173 | run() { lang=$1; shift; if "$@" > "$O/$lang.log" 2>&1; then pass "$lang caller ($(grep -c '^PASS' "$O/$lang.log") checks)"; else fail "$lang caller"; cat "$O/$lang.log"; fi; } |
| 174 | bld() { lang=$1; shift; if "$@" > "$O/$lang-build.log" 2>&1; then return 0; fi; fail "$lang build"; cat "$O/$lang-build.log"; return 1; } |
| 175 | cp "$T"/caller.* "$O/" |
| 176 | bld c cc -std=gnu11 -O2 -Wall -Wextra -Werror -pthread -I "$O" "$O/caller.c" -L"$O" -lomega_native -Wl,-rpath,"$O" -ldl -o "$O/caller_c" \ |
| 177 | && run c "$O/caller_c" |
| 178 | if OMEGA_NATIVE_CFLAGS="-nostartfiles -mbranch-protection=standard -Wl,-z,force-bti" "$ROOT/tools/native" "$O/bti" $units > "$O/bti-native.log" 2>&1 \ |
| 179 | && cmp -s "$O/bti/omega_native.c" "$O/omega_native.c" \ |
| 180 | && bld c-bti cc -std=gnu11 -O2 -Wall -Wextra -Werror -pthread -I "$O/bti" "$O/caller.c" -L"$O/bti" -lomega_native -Wl,-rpath,"$O/bti" -ldl -o "$O/bti/caller_c"; then |
| 181 | if readelf -n "$O/bti/libomega_native.so" | grep -q "feature: BTI"; then run c-bti "$O/bti/caller_c"; else fail "c-bti build carries no BTI property"; fi |
| 182 | else fail "c-bti library build"; cat "$O/bti-native.log"; fi |
| 183 | if command -v c++ > /dev/null; then |
| 184 | bld cpp c++ -std=c++17 -O2 -Wall -Wextra -Werror -I "$O" "$O/caller.cpp" -L"$O" -lomega_native -Wl,-rpath,"$O" -o "$O/caller_cpp" && run cpp "$O/caller_cpp" |
| 185 | else notrun="$notrun c++"; fi |
| 186 | if command -v python3 > /dev/null; then run python python3 -I "$O/caller.py" "$O"; else notrun="$notrun python"; fi |
| 187 | if command -v rustc > /dev/null; then |
| 188 | bld rust rustc -O --edition 2021 -D warnings "$O/caller.rs" -L "$O" -C link-arg=-Wl,-rpath,"$O" -o "$O/caller_rs" && run rust "$O/caller_rs" |
| 189 | bld rust-2024 rustc -O --edition 2024 -D warnings "$O/caller.rs" -L "$O" -C link-arg=-Wl,-rpath,"$O" -o "$O/caller_rs24" && run rust-2024 "$O/caller_rs24" |
| 190 | else notrun="$notrun rust"; fi |
| 191 | if command -v zig > /dev/null; then |
| 192 | bld zig sh -c 'cd "$1" && zig build-exe caller.zig -L. -lomega_native -lc -rpath "$1" -femit-bin=caller_zig' _ "$O" && run zig "$O/caller_zig" |
| 193 | else notrun="$notrun zig"; fi |
| 194 | gopkg() { mkdir -p "$1/omeganative"; cp "$2/omega_native.go" "$2/omega_native.h" "$3/libomega_native.so" "$1/omeganative/"; cp "$4" "$1/"; } |
| 195 | if command -v go > /dev/null; then |
| 196 | gopkg "$O/go" "$O" "$O" "$O/caller.go" |
| 197 | bld go sh -c 'cd "$1" && go mod init omegacaller > /dev/null 2>&1 && CGO_LDFLAGS="-Wl,-rpath,$1/omeganative" go build -o caller_go .' _ "$O/go" && run go "$O/go/caller_go" |
| 198 | else notrun="$notrun go"; fi |
| 199 | |
| 200 | # 6. Link-time refusal: the v1 bindings of an OM-1 unit named bsum declare omega_bsum; every language's |
| 201 | # caller built from them against the library above (where bsum is the v2 export omega2_bsum) must fail |
| 202 | # to link (Python: fail to import), for that reason. |
| 203 | L=$O/v1use; mkdir -p "$L"; cp "$T"/v1use/use.* "$L/"; cp "$O/libomega_native.so" "$L/" |
| 204 | "$OMC" < "$T/v1use/bsum.om" > "$L/bsum.bin" |
| 205 | { cat "$T/v1use/bsum.om"; printf '\0'; printf '%08d' "$(wc -c < "$L/bsum.bin")"; cat "$L/bsum.bin"; } > "$L/bsum.in" |
| 206 | for w in h:h python:py rust:rs zig:zig go:go; do "$GEN" ${w%%:*} < "$L/bsum.in" > "$L/omega_native.${w##*:}"; done |
| 207 | refl() { |
| 208 | lang=$1; pat=$2; shift 2 |
| 209 | if "$@" > "$L/$lang.log" 2>&1; then fail "$lang: a v1 caller of a v2 unit linked" |
| 210 | elif grep -q -E "$pat" "$L/$lang.log"; then pass "$lang refuses the v1 symbol at link time: $(grep -m1 -o -E "$pat" "$L/$lang.log")" |
| 211 | else fail "$lang v1 caller failed for another reason"; cat "$L/$lang.log"; fi |
| 212 | } |
| 213 | refl c "undefined reference to .omega_bsum." cc -std=gnu11 -I "$L" "$L/use.c" -L"$L" -lomega_native -o "$L/use_c" |
| 214 | command -v c++ > /dev/null && refl cpp "undefined reference to .omega_bsum." c++ -std=c++17 -I "$L" "$L/use.cpp" -L"$L" -lomega_native -o "$L/use_cpp" |
| 215 | command -v python3 > /dev/null && refl python "undefined symbol: omega_bsum" python3 -I "$L/use.py" "$L" |
| 216 | command -v rustc > /dev/null && refl rust "undefined reference to .omega_bsum.|undefined symbol: omega_bsum" rustc --edition 2021 "$L/use.rs" -L "$L" -o "$L/use_rs" |
| 217 | command -v zig > /dev/null && refl zig "undefined symbol: omega_bsum|undefined reference to .omega_bsum." sh -c 'cd "$1" && zig build-exe use.zig -L. -lomega_native -lc -femit-bin=use_zig' _ "$L" |
| 218 | if command -v go > /dev/null; then |
| 219 | gopkg "$L/go" "$L" "$L" "$L/use.go" |
| 220 | refl go "undefined reference to .omega_bsum." sh -c 'cd "$1" && go mod init omegacaller > /dev/null 2>&1 && go build -o use_go .' _ "$L/go" |
| 221 | fi |
| 222 | |
| 223 | # 7. Stale identity: bindings generated from vec.om with one note byte changed, against the library of |
| 224 | # the real vec.om. The C check sees two identities; the Python binding refuses to import. |
| 225 | S=$O/stale; mkdir -p "$S"; cp "$O/libomega_native.so" "$S/" |
| 226 | sed '1s/an OM-2 unit/An OM-2 unit/' "$T/vec.om" > "$S/vec.om" |
| 227 | { cat "$S/vec.om"; printf '\0'; printf '%08d' "$(wc -c < "$W/vec.bin")"; cat "$W/vec.bin"; printf 'omega-unit vec %s\n' "$(sha256sum < "$OMC2" | cut -d' ' -f1)"; } > "$S/vec.in" |
| 228 | "$GEN" h < "$S/vec.in" > "$S/omega_native.h"; "$GEN" python < "$S/vec.in" > "$S/omega_native.py" |
| 229 | cc -std=gnu11 -I "$S" "$T/stale.c" -L"$S" -lomega_native -Wl,-rpath,"$S" -o "$S/stale_c" |
| 230 | rc=0; "$S/stale_c" > "$S/c.log" 2>&1 || rc=$? |
| 231 | if [ $rc = 3 ] && grep -q "src=$(sha256sum < "$S/vec.om" | cut -d' ' -f1)" "$S/c.log"; then pass "stale identity: C header from another vec.om is detected (two src digests)" |
| 232 | else fail "stale identity not detected by C (exit $rc)"; cat "$S/c.log"; fi |
| 233 | cc -std=gnu11 -I "$O" "$T/stale.c" -L"$O" -lomega_native -Wl,-rpath,"$O" -o "$S/fresh_c" |
| 234 | if "$S/fresh_c"; then pass "stale identity control: the matching header passes"; else fail "stale control"; fi |
| 235 | if command -v python3 > /dev/null; then |
| 236 | if python3 -I -c "import sys; sys.path.insert(0, '$S'); import omega_native" > "$S/py.log" 2>&1; then fail "python imported a stale binding" |
| 237 | elif grep -q "ImportError: libomega_native.so is not the library" "$S/py.log"; then pass "stale identity: the Python binding refuses to import" |
| 238 | else fail "python stale import failed for another reason"; cat "$S/py.log"; fi |
| 239 | fi |
| 240 | |
| 241 | # 8. Generator refusals for OM-2 input (exit 110, no output) and a control. |
| 242 | code=$W/vec.bin |
| 243 | f2() { printf '%s' "$1"; printf '\0'; printf '%08d' "$(wc -c < "$2")"; cat "$2"; printf '%s' "$3"; } |
| 244 | TR="omega-unit u $(printf '%064d' 0) |
| 245 | " |
| 246 | refuse() { |
| 247 | rc=0; "$GEN" c < "$O/ref.in" > "$O/ref.out" 2> /dev/null || rc=$? |
| 248 | if [ "$rc" = 110 ] && [ ! -s "$O/ref.out" ]; then pass "generator refuses $1"; else fail "generator accepted $1 (exit $rc)"; fi |
| 249 | } |
| 250 | B='om2 |
| 251 | export fn e1 d view uchar * to ulong |
| 252 | ret 0 |
| 253 | end |
| 254 | ' |
| 255 | f2 "$B" "$code" "$TR" > "$O/ref.in"; rc=0; "$GEN" c < "$O/ref.in" > "$O/ref.out" 2> /dev/null || rc=$? |
| 256 | if [ $rc = 0 ] && grep -q 'omega2_e1(uint64_t \*result, const uint8_t \*o_d, uint64_t o_d_len)' "$O/ref.out"; then pass "generator accepts the control OM-2 unit" |
| 257 | else fail "generator refused the control (exit $rc)"; fi |
| 258 | f2 "$B" "$code" "" > "$O/ref.in"; refuse "an OM-2 unit without its omega-unit line" |
| 259 | f2 "$B" "$code" "omega-unit u 0123 |
| 260 | " > "$O/ref.in"; refuse "a short omc digest" |
| 261 | f2 "$B" "$code" "omega-unit u $(printf '%063dG' 0) |
| 262 | " > "$O/ref.in"; refuse "a non-hex omc digest" |
| 263 | f2 "$B" "$code" "omega-unit a-b $(printf '%064d' 0) |
| 264 | " > "$O/ref.in"; refuse "a unit name that is not a C identifier" |
| 265 | { f2 "$B" "$code" "$TR"; f2 "$(echo "$B" | sed 's/e1/e2/') |
| 266 | " "$code" "$TR"; } > "$O/ref.in"; refuse "a repeated unit name" |
| 267 | { f2 "$B" "$code" "$TR"; f2 "$B" "$code" "omega-unit v $(printf '%064d' 0) |
| 268 | "; } > "$O/ref.in"; refuse "an export name repeated across units" |
| 269 | f2 'om2 diag |
| 270 | export fn e1 d view uchar * to ulong |
| 271 | ret 0 |
| 272 | end |
| 273 | ' "$code" "$TR" > "$O/ref.in"; refuse "an om2 diag unit" |
| 274 | f2 'om2 |
| 275 | export fn e1 a view uchar * b view uchar * c view uchar * d view uchar * to ulong |
| 276 | ret 0 |
| 277 | end |
| 278 | ' "$code" "$TR" > "$O/ref.in"; refuse "eight slots (four unsized views)" |
| 279 | f2 'om2 |
| 280 | export fn e1 c edit nolay to void |
| 281 | end |
| 282 | ' "$code" "$TR" > "$O/ref.in"; refuse "an undeclared layout" |
| 283 | f2 'om2 |
| 284 | export fn e1 o out ulong 8193 to void |
| 285 | end |
| 286 | ' "$code" "$TR" > "$O/ref.in"; refuse "out buffers over 65536 bytes" |
| 287 | f2 'om2 |
| 288 | export fn e1 x uint to ulong |
| 289 | ret 0 |
| 290 | end |
| 291 | ' "$code" "$TR" > "$O/ref.in"; refuse "a uint scalar parameter" |
| 292 | f2 'om2 |
| 293 | export fn e1 d view uchar * to uint |
| 294 | ret 0 |
| 295 | end |
| 296 | ' "$code" "$TR" > "$O/ref.in"; refuse "a uint result" |
| 297 | f2 'om2 |
| 298 | export fn e1 d_len view uchar * to ulong |
| 299 | ret 0 |
| 300 | end |
| 301 | ' "$code" "$TR" > "$O/ref.in"; refuse "a parameter name ending in _len" |
| 302 | printf 'x\0\0\0\0' > "$O/w4.bin" |
| 303 | f2 'om2 |
| 304 | export fn e1 to void |
| 305 | end |
| 306 | export fn e2 to void |
| 307 | end |
| 308 | ' "$O/w4.bin" "$TR" > "$O/ref.in"; refuse "two exports in a 4-byte code" |
| 309 | f2 'note bridge c-type nolay x |
| 310 | om2 |
| 311 | export fn e1 to void |
| 312 | end |
| 313 | ' "$code" "$TR" > "$O/ref.in"; refuse "a c-type note naming no layout" |
| 314 | |
| 315 | # 9. Negative controls: one check of the C prelude removed in a copy of the generator must make the C |
| 316 | # caller fail, on the checks that cover it. |
| 317 | mut() { |
| 318 | name=$1; ex=$2; pat=$3; M=$O/mut-$name; mkdir -p "$M" |
| 319 | sed "$ex" "$ROOT/src/native.om" > "$M/native.om" |
| 320 | n=$(diff "$ROOT/src/native.om" "$M/native.om" | grep -c '^<' || true) |
| 321 | [ "$n" = 1 ] || { fail "mutant $name changed $n lines"; return 0; } |
| 322 | "$OMC" < "$M/native.om" > "$M/gen"; chmod +x "$M/gen" |
| 323 | "$M/gen" c < "$W/units.in" > "$M/omega_native.c"; "$M/gen" h < "$W/units.in" > "$M/omega_native.h" |
| 324 | cmp -s "$M/omega_native.c" "$O/omega_native.c" && { fail "mutant $name: library unchanged"; return 0; } |
| 325 | cp "$O/omega_api.h" "$M/" |
| 326 | cc -std=gnu11 -O2 -fPIC -shared -Wl,-soname,libomega_native.so -include "$M/omega_native.h" -o "$M/libomega_native.so" "$M/omega_native.c" |
| 327 | cc -std=gnu11 -O2 -pthread -I "$M" "$O/caller.c" -L"$M" -lomega_native -Wl,-rpath,"$M" -ldl -o "$M/caller_c" |
| 328 | if "$M/caller_c" > "$M/c.log" 2>&1; then fail "mutant $name not caught" |
| 329 | elif grep -q -E "^FAIL $pat" "$M/c.log"; then pass "mutant $name caught ($(grep -c '^FAIL' "$M/c.log") failing checks, e.g. $(grep -m1 -E "^FAIL $pat" "$M/c.log" | cut -c6-70))" |
| 330 | else fail "mutant $name failed elsewhere"; grep '^FAIL' "$M/c.log"; fi |
| 331 | } |
| 332 | mut wrap '/^text fv /s/ || n \* es > UINTPTR_MAX - lo)/)/' '#748 golden: vpart len 2\^64-1' |
| 333 | mut overlap '/^text fv /s/if ((sp\[i\].w == 1 || sp\[j\].w == 1 ||/if ((/' 'vcopy edit == view' |
| 334 | mut outcopy '/^text fv /s/memmove(o\[i\].dst, buf\[i\], o\[i\].n);/;/' 'digest: tag' |
| 335 | |
| 336 | # 9b. The trampoline alone: tramp.c includes the generated omega_native.c and calls ombr_enter directly |
| 337 | # (no C wrapper that could keep a register for itself) with a hand-assembled unit that writes x20..x29 and |
| 338 | # d8..d15, returning and trapping. Twice: the hosted trampoline (text pre, the library's) and the |
| 339 | # freestanding one (text fp, tools/native --freestanding on the OM-1 unit smadd). Then, in each, one |
| 340 | # mutant per restore pair in ombr_leave, each removed in a copy of the generator (x29: restored no more, |
| 341 | # x30 still): every one must make tramp fail. |
| 342 | tb() { cc -std=gnu11 -O2 -Wall -Wextra -Werror -include "$1/omega_native.h" -I "$1" "$T/tramp.c" -o "$1/tramp" > "$1/tramp-build.log" 2>&1; } |
| 343 | FPO=$O/fp |
| 344 | if "$ROOT/tools/native" --freestanding "$FPO" "$ROOT/tests/native/smadd.om" > "$O/fp-native.log" 2>&1; then : |
| 345 | else fail "tools/native --freestanding smadd"; cat "$O/fp-native.log"; fi |
| 346 | for k in pre fp; do |
| 347 | D=$O; [ $k = pre ] || D=$FPO |
| 348 | if tb "$D" && "$D/tramp" > "$D/tramp.log" 2>&1; then pass "trampoline (text $k) called directly: $(grep -c '^PASS' "$D/tramp.log") checks (return, trap)" |
| 349 | else fail "trampoline (text $k) called directly"; cat "$D/tramp-build.log" "$D/tramp.log"; fi |
| 350 | done |
| 351 | # tmut K NAME SED: the mutant of text K (pre: hosted library, units.in; fp: freestanding, smadd). |
| 352 | tmut() { |
| 353 | k=$1; name=$2; M=$O/tmut-$k-$name; mkdir -p "$M" |
| 354 | if [ $k = pre ]; then D=$O; U=$W/units.in; c=c; else D=$FPO; U=$FPO/work/units.in; c=freest; fi |
| 355 | sed "/^text $k /$3" "$ROOT/src/native.om" > "$M/native.om" |
| 356 | n=$(diff "$ROOT/src/native.om" "$M/native.om" | grep -c '^<' || true) |
| 357 | [ "$n" = 1 ] || { fail "trampoline mutant $k $name changed $n lines"; return 0; } |
| 358 | "$OMC" < "$M/native.om" > "$M/gen"; chmod +x "$M/gen" |
| 359 | "$M/gen" $c < "$U" > "$M/omega_native.c"; "$M/gen" h < "$U" > "$M/omega_native.h" |
| 360 | cmp -s "$M/omega_native.c" "$D/omega_native.c" && { fail "trampoline mutant $k $name: output unchanged"; return 0; } |
| 361 | tb "$M" || { fail "trampoline mutant $k $name: build"; cat "$M/tramp-build.log"; return 0; } |
| 362 | if timeout 10 "$M/tramp" > "$M/tramp.log" 2>&1; then fail "trampoline mutant $k $name not caught" |
| 363 | else pass "trampoline mutant $k $name caught ($(grep -c '^FAIL' "$M/tramp.log") failing checks$(grep -q 'TRAMP FAIL' "$M/tramp.log" || echo ', crashed'))"; fi |
| 364 | } |
| 365 | for k in pre fp; do |
| 366 | tmut $k x19x20 's/ldp x19,x20,\[sp,#16\]\\\\n//' |
| 367 | tmut $k x21x22 's/ldp x21,x22,\[sp,#32\]\\\\n//' |
| 368 | tmut $k x23x24 's/ldp x23,x24,\[sp,#48\]\\\\n//' |
| 369 | tmut $k x25x26 's/ldp x25,x26,\[sp,#64\]\\\\n//' |
| 370 | tmut $k x27x28 's/ldp x27,x28,\[sp,#80\]\\\\n//' |
| 371 | tmut $k d8d9 's/ldp d8,d9,\[sp,#96\]\\\\n//' |
| 372 | tmut $k d10d11 's/ldp d10,d11,\[sp,#112\]\\\\n//' |
| 373 | tmut $k d12d13 's/ldp d12,d13,\[sp,#128\]\\\\n//' |
| 374 | tmut $k d14d15 's/ldp d14,d15,\[sp,#144\]\\\\n//' |
| 375 | tmut $k x29 's/ldp x29,x30,\[sp\],#176\\\\n/ldr x30,[sp,#8]\\\\nadd sp,sp,#176\\\\n/' |
| 376 | done |
| 377 | |
| 378 | # 10a. The C API out of line (outputs apih, apic) for freestanding consumers. The inline header |
| 379 | # (output api) and the out-of-line pair stay byte for byte what f637021's generator |
| 380 | # (with the current prelude) wrote. Only output c admits 14 exact span initializers. |
| 381 | ok=1 |
| 382 | for w in c h python rust zig go api apih apic; do |
| 383 | "$O/gen-v1" $w < "$W/units.in" > "$O/a.out"; "$GEN" $w < "$W/units.in" > "$O/b.out" |
| 384 | if [ "$w" = c ]; then |
| 385 | python3 "$T/span_compare.py" "$O/a.out" "$O/b.out" 14 || { ok=0; echo "DIFF $w"; } |
| 386 | else |
| 387 | cmp -s "$O/a.out" "$O/b.out" || { ok=0; echo "DIFF $w"; } |
| 388 | fi |
| 389 | done |
| 390 | if [ $ok = 1 ]; then pass "historical v2-set outputs equal (only c: 14 counted span zero-inits; existing runtime/private normalization)" |
| 391 | else fail "an existing output changed against f637021"; fi |
| 392 | FS=$O/fs; mkdir -p "$FS" |
| 393 | FSCF="-std=gnu11 -ffreestanding -fno-builtin -O2 -Wall -Wextra -Werror -c" |
| 394 | # fsobj DIR: the freestanding object from DIR's omega_api_decl.h; prints its undefined symbols. |
| 395 | fsobj() { cc $FSCF -I "$1" "$T/fsuse.c" -o "$1/fsuse.o" > "$1/fs-build.log" 2>&1 && nm -u "$1/fsuse.o" | awk '{print $2}' | sort; } |
| 396 | u=$(fsobj "$O" | tr '\n' ' ') |
| 397 | if [ "$u" = "absorb bsum digest swap8 " ]; then pass "freestanding object from omega_api_decl.h: undefined symbols are only absorb bsum digest swap8 (no abort)" |
| 398 | else fail "freestanding object references: $u"; cat "$O/fs-build.log"; fi |
| 399 | cc -std=gnu11 -O2 -Wall -Wextra -Werror -Wmissing-prototypes -I "$O" -c "$O/omega_api_defs.c" -o "$FS/defs.o" |
| 400 | if nm -u "$FS/defs.o" | awk '{print $2}' | grep -qx abort && nm "$FS/defs.o" | grep -q ' T swap8$'; then |
| 401 | pass "omega_api_defs.o defines the API (swap8 ...) and holds the abort reference" |
| 402 | else fail "omega_api_defs.o"; nm "$FS/defs.o"; fi |
| 403 | sed 's/"omega_api_decl.h"/"omega_api.h"/' "$T/fsuse.c" > "$FS/fsuse_inline.c" |
| 404 | cc $FSCF -I "$O" "$FS/fsuse_inline.c" -o "$FS/fsuse_inline.o" |
| 405 | if nm -u "$FS/fsuse_inline.o" | awk '{print $2}' | grep -qx abort; then pass "control: the same object from the inline omega_api.h references abort (what the freestanding gate refuses)" |
| 406 | else fail "control: the inline object has no abort reference"; fi |
| 407 | cc -std=gnu11 -O2 -I "$O" "$T/fsmain.c" "$O/fsuse.o" "$FS/defs.o" -L"$O" -lomega_native -Wl,-rpath,"$O" -o "$FS/fsmain" |
| 408 | if "$FS/fsmain" > "$FS/run.log" 2>&1 && grep -q '^PASS fs_check 0' "$FS/run.log"; then pass "freestanding object + omega_api_defs.o + library: results correct" |
| 409 | else fail "freestanding run"; cat "$FS/run.log"; fi |
| 410 | rc=0; "$FS/fsmain" refuse > "$FS/refuse.log" 2>&1 || rc=$? |
| 411 | if [ $rc = 134 ]; then pass "out-of-line wrapper aborts on a nonzero status (SIGABRT, exit 134)"; else fail "out-of-line wrapper on a trap: exit $rc"; fi |
| 412 | # Mutants. apih: the prototype-only branch disabled, so apih writes the definitions into the header; |
| 413 | # the freestanding fixture must catch it (abort in the object, or abort undeclared there). api: the |
| 414 | # inline branch disabled, so api loses `static inline`; the byte-identity check must catch it. |
| 415 | amut() { |
| 416 | name=$1; ex=$2; M=$O/amut-$name; mkdir -p "$M" |
| 417 | sed "$ex" "$ROOT/src/native.om" > "$M/native.om" |
| 418 | n=$(diff "$ROOT/src/native.om" "$M/native.om" | grep -c '^<' || true) |
| 419 | [ "$n" = 1 ] || { fail "mutant $name changed $n lines"; return 1; } |
| 420 | "$OMC" < "$M/native.om" > "$M/gen"; chmod +x "$M/gen" |
| 421 | cp "$O/omega_native.h" "$M/" |
| 422 | for w in api apih apic; do "$M/gen" $w < "$W/units.in" > "$M/$w.out"; done |
| 423 | cp "$M/api.out" "$M/omega_api.h"; cp "$M/apih.out" "$M/omega_api_decl.h" |
| 424 | } |
| 425 | if amut apih '/^if eq get st 5 8$/s/8$/98/'; then |
| 426 | u=$(fsobj "$M" | tr '\n' ' ' || true) |
| 427 | if echo "$u" | grep -qw abort || grep -q "implicit declaration of function .abort." "$M/fs-build.log"; then |
| 428 | pass "mutant apih (definitions in the header) caught: $(echo "$u" | grep -qw abort && echo "abort undefined in the freestanding object" || grep -m1 -o "implicit declaration of function .abort." "$M/fs-build.log")" |
| 429 | else fail "mutant apih not caught ($u)"; fi |
| 430 | fi |
| 431 | if amut api '/^if eq get st 5 7$/s/7$/97/'; then |
| 432 | if cmp -s "$M/api.out" "$O/omega_api.h"; then fail "mutant api not caught: inline header unchanged" |
| 433 | elif ! grep -q 'static inline' "$M/api.out"; then pass "mutant api (inline wrappers lose static inline) caught by the byte-identity check" |
| 434 | else fail "mutant api changed something else"; fi |
| 435 | fi |
| 436 | |
| 437 | # 10b. Freestanding OM-2 (tools/native --freestanding, outputs freest + fapic): FIPS 180-4 digests, |
| 438 | # out-buffer rules, threads, the trap wrapper and the copy-back-dropped mutant. |
| 439 | if python3 "$T/../test_freestanding_om2.py" > "$O/fsom2.log" 2>&1; then pass "freestanding OM-2: $(grep -c '^PASS' "$O/fsom2.log") checks incl. copy-back mutant" |
| 440 | else fail "freestanding OM-2"; cat "$O/fsom2.log"; fi |
| 441 | # 10c. Freestanding borrowed-byte view (pathlen.om): bounded NUL scan, empty NULL, nonempty NULL |
| 442 | # refusal, guard page, six source mutants and one binding mutant, on A64 and under x86 QEMU. |
| 443 | if python3 "$T/../test_freestanding_pathlen.py" > "$O/pathlen.log" 2>&1; then pass "freestanding pathlen: $(grep -c '^PASS' "$O/pathlen.log") checks" |
| 444 | else fail "freestanding pathlen"; cat "$O/pathlen.log"; fi |
| 445 | # 11. Host words (docs/NATIVE-ABI.md, "Host words"). An OM-2 function unit may use the nine file and |
| 446 | # identity host words (omega-mv #1008) only when tools/native gets --host; native.om judges the source |
| 447 | # (note lines skipped, blank and parenthesis separators), the shell only sequences. Host-free parity |
| 448 | # uses OMC2 on both sides; only actual host units and scanner fixtures use HOST_OMC2. |
| 449 | H=$O/host; mkdir -p "$H"; HU=$T/host/hfile.om |
| 450 | hw="fclose,fopen,fstat,stat,getuid,geteuid,getgid,getegid,lstat" |
| 451 | # tnat NAME WANT ARGS...: tools/native ARGS must exit WANT; a refusal must leave nothing installed (its |
| 452 | # OUTDIR absent, or empty as tools/native leaves it when the generator refuses a unit). |
| 453 | tnat() { |
| 454 | name=$1; want=$2; shift 2; rc=0 |
| 455 | OMEGA_NATIVE_OMC2="$HOST_OMC2" "$ROOT/tools/native" "$@" > "$H/$name.log" 2>&1 || rc=$? |
| 456 | if [ $rc != "$want" ]; then fail "tools/native $name: exit $rc, want $want"; cat "$H/$name.log"; return 1; fi |
| 457 | if [ "$want" != 0 ] && [ -n "$(ls -A "$H/$name" 2> /dev/null)" ]; then fail "tools/native $name refused but installed: $(ls -A "$H/$name")"; return 1; fi |
| 458 | pass "tools/native $name: exit $want$( [ "$want" = 0 ] || printf ' (%s)' "$(tail -n 1 "$H/$name.log")")" |
| 459 | } |
| 460 | tnat nohost 110 "$H/nohost" "$HU" || true |
| 461 | tnat hostfs 110 --host --freestanding "$H/hostfs" "$HU" || true |
| 462 | tnat hostx86fs 110 --target x86linux --host --freestanding "$H/hostx86fs" "$HU" || true |
| 463 | if tnat hostok 0 --host "$H/hostok" "$ROOT/tests/native/madd.om" "$HU"; then |
| 464 | want="omega-ident 1 unit=hfile abi=2 profile=OM-2 src=$(sha256sum < "$HU" | cut -d' ' -f1) omc=$HOST_OMC2_PIN host=$hw" |
| 465 | if grep -q -F "OMEGA2_IDENT_hfile \"$want\"" "$H/hostok/omega_native.h" && grep -q -F "\"$want\"" "$H/hostok/omega_native.c" \ |
| 466 | && grep -q -F "$want path=$HU" "$H/hostok/work/ident.txt"; then pass "hfile identity names its host words: host=$hw" |
| 467 | else fail "hfile identity"; grep hfile "$H/hostok/work/ident.txt" || true; fi |
| 468 | printf 'abcde' > "$H/five"; ln -sf "$H/five" "$H/link" |
| 469 | bld host-c cc -std=gnu11 -O2 -Wall -Wextra -Werror -I "$H/hostok" "$T/host/hcall.c" -L"$H/hostok" -lomega_native -Wl,-rpath,"$H/hostok" -o "$H/hcall_c" \ |
| 470 | && run host-c "$H/hcall_c" "$H/five" "$H/missing" "$H/link" |
| 471 | if command -v rustc > /dev/null; then |
| 472 | cp "$T/host/hcall.rs" "$H/hostok/omega_native.rs" "$H/" |
| 473 | bld host-rust rustc -O --edition 2021 -D warnings "$H/hcall.rs" -L "$H/hostok" -C link-arg=-Wl,-rpath,"$H/hostok" -o "$H/hcall_rs" \ |
| 474 | && run host-rust "$H/hcall_rs" "$H/five" "$H/missing" "$H/link" |
| 475 | else notrun="$notrun host-rust"; fi |
| 476 | fi |
| 477 | # --host changes nothing for units without host words: the v2 set built with --host, every output equal. |
| 478 | if "$ROOT/tools/native" --host "$H/hostset" $units > "$H/hostset.log" 2>&1; then |
| 479 | ok=1 |
| 480 | for f in omega_native.c omega_native.h omega_native.py omega_native.rs omega_native.zig omega_native.go omega_api.h omega_api_decl.h omega_api_defs.c; do |
| 481 | cmp -s "$O/$f" "$H/hostset/$f" || { ok=0; echo "DIFF $f"; } |
| 482 | done |
| 483 | if [ $ok = 1 ]; then pass "--host is inert for the v2 set (no host words): all nine generated files byte-identical"; else fail "--host changed a unit without host words"; fi |
| 484 | else fail "tools/native hostset"; cat "$H/hostset.log" |
| 485 | fi |
| 486 | # The scanner, fed straight to native-gen: source forms HOST_OMC2 accepts (it compiles each), and |
| 487 | # sources framed with a clean unit's code to reach the forms the compilers refuse (OM-1, unlink). |
| 488 | # frame SRC BIN OUT: the tools/native framing, with the omega-unit line when SRC is OM-2. |
| 489 | frame() { |
| 490 | { cat "$1"; printf '\0'; printf '%08d' "$(wc -c < "$2")"; cat "$2" |
| 491 | [ "$(sed -n '/^ *note\( \|$\)/d; p; q' "$1")" != om2 ] || printf 'omega-unit hu %s\n' "$HOST_OMC2_PIN" |
| 492 | } > "$3" |
| 493 | } |
| 494 | # gcase NAME SRC BIN NOHOST HOST: native-gen c on the frame, without and with host, must exit NOHOST and |
| 495 | # HOST; with HOST 0, ident must carry exactly the host suffix given in HW (empty: no host= at all). |
| 496 | gcase() { |
| 497 | frame "$2" "$3" "$H/$1.in"; a=0; b=0 |
| 498 | "$GEN" c < "$H/$1.in" > /dev/null 2>&1 || a=$? |
| 499 | "$GEN" c host < "$H/$1.in" > /dev/null 2>&1 || b=$? |
| 500 | id=""; [ "$b" != 0 ] || [ "$(sed -n '/^ *note\( \|$\)/d; p; q' "$2")" != om2 ] || id=$("$GEN" ident host < "$H/$1.in") |
| 501 | case "$id" in *" host="*) got=${id##* host=};; *) got="";; esac |
| 502 | if [ $a = "$4" ] && [ $b = "$5" ] && [ "$got" = "$HW" ]; then pass "native-gen $1: exit $a without host, $b with host${HW:+, host=$HW}" |
| 503 | else fail "native-gen $1: exit $a/$b (want $4/$5), host=$got (want $HW)"; fi |
| 504 | } |
| 505 | printf 'om2\nexport fn a to ulong\nx = ulong 7\nret x\nend\n' > "$H/clean.om"; "$HOST_OMC2" < "$H/clean.om" > "$H/clean.bin" |
| 506 | printf 'fn a to ulong\nx = ulong 7\nret x\nend\n' > "$H/clean1.om"; "$OMC" < "$H/clean1.om" > "$H/clean1.bin" |
| 507 | HW="" gcase clean "$H/clean.om" "$H/clean.bin" 0 0 |
| 508 | HW="" gcase clean1 "$H/clean1.om" "$H/clean1.bin" 0 0 |
| 509 | for c in paren:'x = ulong (geteuid)' tab:"$(printf 'x = ulong\tgeteuid')" cr:"$(printf 'x = ulong geteuid\r')"; do |
| 510 | printf 'om2\nexport fn a to ulong\n%s\nret x\nend\n' "${c#*:}" > "$H/${c%%:*}.om" |
| 511 | if "$HOST_OMC2" < "$H/${c%%:*}.om" > "$H/${c%%:*}.bin" 2> /dev/null; then HW=geteuid gcase "${c%%:*}" "$H/${c%%:*}.om" "$H/${c%%:*}.bin" 110 0 |
| 512 | else fail "HOST_OMC2 refuses the ${c%%:*} form"; fi |
| 513 | done |
| 514 | printf 'om2\nnote uses unlink fopen geteuid only in a note\n note\tlstat after blanks\nexport fn a to ulong\nx = ulong 7\nret x\nend\n' > "$H/note.om" |
| 515 | "$HOST_OMC2" < "$H/note.om" > "$H/note.bin"; HW="" gcase note "$H/note.om" "$H/note.bin" 0 0 |
| 516 | printf 'om2\nexport fn a to ulong\nx = ulong 7 (note geteuid\nret x\nend\n' > "$H/pnote.om"; HW=geteuid gcase pnote "$H/pnote.om" "$H/clean.bin" 110 0 |
| 517 | printf 'om2\nexport fn a to ulong\nx = unlink 7\nret x\nend\n' > "$H/unlink.om"; HW="" gcase unlink "$H/unlink.om" "$H/clean.bin" 110 110 |
| 518 | printf 'fn a to ulong\nx = ulong geteuid\nret x\nend\n' > "$H/om1.om"; HW="" gcase om1 "$H/om1.om" "$H/clean1.bin" 110 110 |
| 519 | printf 'om2\nexport fn a to ulong\nx = ulong getuidx\nret x\nend\n' > "$H/near.om"; HW="" gcase near "$H/near.om" "$H/clean.bin" 0 0 |
| 520 | # host is not freestanding in the generator either: outputs freest and fapic refuse it (exit 110) on the |
| 521 | # clean unit they accept without it. |
| 522 | for w in freest fapic; do |
| 523 | a=0; b=0; "$GEN" $w < "$H/clean.in" > /dev/null 2>&1 || a=$?; "$GEN" $w host < "$H/clean.in" > /dev/null 2>&1 || b=$? |
| 524 | if [ $a = 0 ] && [ $b = 110 ]; then pass "native-gen $w: exit 0 without host, 110 with host" |
| 525 | else fail "native-gen $w: exit $a/$b (want 0/110)"; fi |
| 526 | done |
| 527 | # Mutant: the scan disabled in fn unit; the paren case must then pass without host, and be caught. |
| 528 | M=$O/hmut; mkdir -p "$M" |
| 529 | sed '/^hscan p q v$/s/^/note /' "$ROOT/src/native.om" > "$M/native.om" |
| 530 | if [ "$(diff "$ROOT/src/native.om" "$M/native.om" | grep -c '^<' || true)" = 1 ] && "$OMC" < "$M/native.om" > "$M/gen"; then |
| 531 | chmod +x "$M/gen"; rc=0; "$M/gen" c < "$H/paren.in" > /dev/null 2>&1 || rc=$? |
| 532 | if [ $rc = 0 ]; then pass "mutant hscan-off caught: paren case exits 0 without host (the check above wants 110)" |
| 533 | else fail "mutant hscan-off not caught (exit $rc)"; fi |
| 534 | else fail "mutant hscan-off did not apply"; fi |
| 535 | if OMEGA_NATIVE_OMC2="$DEVICE_OMC2" python3 "$T/test_single_edit.py" "$O/single-edit" > "$O/single-edit.log" 2>&1; then |
| 536 | cat "$O/single-edit.log" |
| 537 | pass "single-edit spans: four profiles, exact initialization counts and warning mutant" |
| 538 | else |
| 539 | cat "$O/single-edit.log" |
| 540 | fail "single-edit span qualification" |
| 541 | fi |
| 542 | if OMEGA_NATIVE_OMC2="$DEVICE_OMC2" python3 "$T/dev/run.py" "$O/device" > "$O/device.log" 2>&1; then |
| 543 | cat "$O/device.log" |
| 544 | pass "device words: C differential, contexts, cleanup failure, 15 host controls, 2 ABI controls, 5 ioctl controls and 11 mutants" |
| 545 | else |
| 546 | cat "$O/device.log" |
| 547 | fail "device-word qualification" |
| 548 | fi |
| 549 | |
| 550 | # 10. Cost (HOST): call overhead, stack switch, copies, small and large views. |
| 551 | if [ "${1:-}" = measure ]; then |
| 552 | cc -std=gnu11 -O2 -Wall -Wextra -Werror -pthread -I "$O" "$T/measure.c" -L"$O" -lomega_native -Wl,-rpath,"$O" -o "$O/measure" \ |
| 553 | && "$O/measure" | tee "$O/measure.log" |
| 554 | echo "INFO load: $(cat /proc/loadavg)" |
| 555 | fi |
| 556 | for l in $notrun; do echo "NOT_RUN $l caller: toolchain not installed"; done |
| 557 | if [ "$fails" -ne 0 ]; then echo "NATIVE-V2 FAIL $fails"; exit 1; fi |
| 558 | if [ -n "$notrun" ]; then echo "NATIVE-V2 NOT_RUN (not run:$notrun)"; exit 1; fi |
| 559 | echo "NATIVE-V2 PASS (not run:${notrun:- none})" |