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-bridge/blob/main/tests/native/kinds.sh
# omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
Sign in to star 0 stars 0 watching
About Files History Releases Proposed changes Issues For developers
branch `main` Branches Tags History
`omega-bridge / tests / native / kinds.sh`
63 lines ยท 4188 bytes Raw Blame History
1 #!/bin/sh
2 # f32 and ushort array kinds of the native call ABI (docs/NATIVE-ABI.md): two Omega units with f32/ushort
3 # view and edit arrays, called from C and compared to C-computed values, the refusals for those kinds,
4 # and a negative control (fsum's add turned into sub) that must fail. Same pinned compiler as run.sh.
5 # The generator's one argument names the output (c, python, rust); a missing argument is a refusal.
6 set -eu
7 PIN=`734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61`
8 ROOT=$(cd "$(dirname "$0")/../.." && pwd)
9 T=$ROOT/tests/native
10 O=$ROOT/build/native-kinds
11 OMC=${OMEGA_NATIVE_OMC:?set OMEGA_NATIVE_OMC to the seeded omc (omega seed/out/omc, sha256 $PIN)}
12 got=$(sha256sum < "$OMC" | cut -d' ' -f1)
13 [ "$got" = "$PIN" ] || { echo "FAIL omc sha256 $got, pinned $PIN"; exit 1; }
14 rm -rf "$O"; mkdir -p "$O/mut"
15 "$OMC" < "$ROOT/src/native.om" > "$O/native"; chmod +x "$O/native"
16 frame() { # frame
17 "$OMC" < "$2" > "$1/fsum.bin"; "$OMC" < "$T/halve.om" > "$1/halve.bin"
18 { cat "$2"; printf '\0'; printf '%08d' "$(wc -c < "$1/fsum.bin")"; cat "$1/fsum.bin"
19 cat "$T/halve.om"; printf '\0'; printf '%08d' "$(wc -c < "$1/halve.bin")"; cat "$1/halve.bin"; }
20 }
21 pylib() { # pylib : the python word's binding and its library, side by side
22 mkdir -p "$1/py"; frame "$1" "$2" | "$O/native" python > "$1/py/omega_native.py"
23 frame "$1" "$2" | "$O/native" c > "$1/py/omega_native.c"
24 cc -std=gnu11 -O2 -Wall -Wextra -Werror -fPIC -shared -o "$1/py/libomega_native.so" "$1/py/omega_native.c"
25 }
26 build() { # build
27 frame "$1" "$2" | "$O/native" c > "$1/omega_native.c"
28 cc -std=gnu11 -O2 -Wall -Wextra -Werror -o "$1/kinds" "$T/kinds.c" "$1/omega_native.c"
29 }
30 build "$O" "$T/fsum.om"
31 "$O/kinds"
32 # Declaration texts for the same frame. Python names the element types. Rust types f32/ushort as
33 # byte pointers (docs/NATIVE-ABI.md); a fragment-index overrun would not contain these markers.
34 frame "$O" "$T/fsum.om" | "$O/native" python > "$O/omega_native.py"
35 grep -q '_a7 = ctypes.POINTER(ctypes.c_float)' "$O/omega_native.py"
36 grep -q '_a10 = ctypes.POINTER(ctypes.c_uint16)' "$O/omega_native.py"
37 grep -q 'omega_fsum.argtypes = \[_res, _a8, _u64, _a10, _u64, _a7, _u64\]' "$O/omega_native.py"
38 frame "$O" "$T/fsum.om" | "$O/native" rust > "$O/omega_native.rs"
39 grep -q 'o_a: \*const u8, o_a_len: u64, o_h: \*const u8, o_h_len: u64, o_d: \*mut u8, o_d_len: u64' "$O/omega_native.rs"
40 # The f32/ushort kinds called through the generated Python binding, with refusal controls.
41 pylib "$O" "$T/fsum.om"
42 if python3 -I "$T/pykinds.py" "$O/py" > "$O/py.log" 2>&1; then echo "PASS python binding: f32/ushort calls and refusals ($(grep -c '^PASS' "$O/py.log") checks)"
43 else echo "FAIL python binding"; cat "$O/py.log"; exit 1; fi
44 # A uint array is still outside the subset: exit 110, and the previous C file is untouched.
45 cp "$O/omega_native.c" "$O/keep.c"
46 printf 'fn bad a view uint 1 to ulong\nret 0\nend\n' > "$O/bad.om"
47 "$OMC" < "$O/bad.om" > "$O/bad.bin"
48 rc=0
49 { cat "$O/bad.om"; printf '\0'; printf '%08d' "$(wc -c < "$O/bad.bin")"; cat "$O/bad.bin"; } | "$O/native" c > "$O/bad.out" 2>"$O/bad.err" || rc=$?
50 if [ "$rc" = 110 ] && [ ! -s "$O/bad.out" ] && cmp -s "$O/omega_native.c" "$O/keep.c"; then
51 echo "PASS view uint refused (exit 110), previous output untouched"
52 else
53 echo "FAIL view uint refusal (exit $rc)"; cat "$O/bad.err"; exit 1
54 fi
55 sed 's/^put d i add get a i bitcast f32 h2b get h i$/put d i sub get a i bitcast f32 h2b get h i/' "$T/fsum.om" > "$O/mut/fsum.om"
56 grep -q '^put d i sub' "$O/mut/fsum.om" || { echo "FAIL mutant not applied"; exit 1; }
57 build "$O/mut" "$O/mut/fsum.om"
58 if "$O/mut/kinds" > "$O/mut/log" 2>&1; then echo "FAIL mutant fsum (add -> sub) not caught"; exit 1; fi
59 echo "PASS mutant fsum (add -> sub) caught ($(grep -c '^FAIL' "$O/mut/log") failing checks)"
60 pylib "$O/mut" "$O/mut/fsum.om"
61 if python3 -I "$T/pykinds.py" "$O/mut/py" > "$O/mut/py.log" 2>&1; then echo "FAIL mutant fsum not caught through the python binding"; exit 1; fi
62 echo "PASS mutant fsum (add -> sub) caught through the python binding ($(grep -c '^FAIL' "$O/mut/py.log") failing checks)"
63 echo "NATIVE-KINDS PASS"