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/v2/caller.py # 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 / v2 / caller.py` 57 lines ยท 3341 bytes Raw Blame History 1 # Native ABI v2 oracle, Python (tests/native/v2/run.sh): the generated omega_native.py only. Importing it 2 # checks every unit's identity against the library. 3 import ctypes, sys 4 sys.path.insert(0, sys.argv[1] if len(sys.argv) > 1 else ".") 5 import omega_native as om 6 7 fails = 0 8 def check(name, ok): 9 global fails 10 print(("PASS " if ok else "FAIL ") + name) 11 if not ok: 12 fails += 1 13 14 R0 = 0x5a5a5a5a5a5a5a5a 15 def res(): 16 return ctypes.c_uint64(R0) 17 18 check("ident vec", om.omega2_ident_vec() == om.OMEGA2_IDENT_vec) 19 r = res(); check("bsum abc = 294", om.omega2_bsum(ctypes.byref(r), b"abc", 3) == 0 and r.value == 294) 20 r = res(); check("bsum (None, 0) = 0", om.omega2_bsum(ctypes.byref(r), None, 0) == 0 and r.value == 0) 21 r = res(); check("bsum (None, 1) refused", om.omega2_bsum(ctypes.byref(r), None, 1) == 32 and r.value == R0) 22 raw = (ctypes.c_uint8 * 16)() 23 mis = ctypes.cast(ctypes.addressof(raw) + 1, ctypes.POINTER(ctypes.c_uint32)) 24 r = res(); check("wsum misaligned refused", om.omega2_wsum(ctypes.byref(r), mis, 1) == 32 and r.value == R0) 25 w4 = (ctypes.c_uint32 * 4)(1, 2, 3, 0xffffffff) 26 r = res(); check("wsum = `4294967301`", om.omega2_wsum(ctypes.byref(r), w4, 4) == 0 and r.value == `4294967301`) 27 r = res(); check("bsum len 2^64-1 refused", om.omega2_bsum(ctypes.byref(r), b"abc", 2**64 - 1) == 32) 28 try: 29 om.omega2_bsum(ctypes.byref(r), b"abc", 2**64) 30 check("len 2^64 raises", False) 31 except ctypes.ArgumentError: 32 check("len 2^64 raises ctypes.ArgumentError", True) 33 h = (ctypes.c_uint16 * 8)(1, 2, 3, 4) 34 r = res(); check("vcopy edit == view refused", om.omega2_vcopy(ctypes.byref(r), h, 4, h, 4) == 32) 35 h4 = ctypes.cast(ctypes.addressof(h) + 8, ctypes.POINTER(ctypes.c_uint16)) 36 r = res(); check("vcopy adjacent accepted", om.omega2_vcopy(ctypes.byref(r), h, 4, h4, 4) == 0 and r.value == 4 and h[7] == 4) 37 r = res(); check("#748 golden: vpart o 2^64-2 k 4 traps 3", om.omega2_vpart(ctypes.byref(r), bytes(16), 16, 2**64 - 2, 4) == 3 and r.value == R0) 38 s8 = (ctypes.c_uint8 * 8)(1, 2, 3, 4, 5, 6, 7, 8) 39 r = res(); st = om.omega2_swap8(ctypes.byref(r), ctypes.cast(s8, ctypes.c_char_p), 8, s8) 40 check("swap8 out == view reversed", st == 0 and list(s8) == [8, 7, 6, 5, 4, 3, 2, 1]) 41 ho = (ctypes.c_uint64 * 2)(11, 22) 42 r = res(); check("halt traps 9, out untouched", om.omega2_halt(ctypes.byref(r), ho) == 9 and list(ho) == [11, 22] and r.value == R0) 43 c = (ctypes.c_uint8 * 24)() 44 r = res(); check("absorb", om.omega2_absorb(ctypes.byref(r), c, b"abc", 3) == 0 and c[0] == 294 % 256 and c[1] == 1 and c[8] == 3) 45 o16 = (ctypes.c_uint8 * 16)() 46 r = res(); check("digest", om.omega2_digest(ctypes.byref(r), bytes(c), o16) == 0 and r.value == 3 and o16[8] == 294 % 256) 47 f3 = (ctypes.c_uint64 * 3)() 48 r = res(); check("fillv", om.omega2_fillv(ctypes.byref(r), f3, 3, 9) == 0 and list(f3) == [9, 9, 9]) 49 l3 = (ctypes.c_int64 * 3)(-5, 7, -9) 50 r = res(); check("lsum = -7 (two's complement bits)", om.omega2_lsum(ctypes.byref(r), l3, 3) == 0 and r.value == 2**64 - 7) 51 ok = True 52 for k in range(100): 53 r = res(); ok = ok and om.omega_madd(ctypes.byref(r), k, 3, 1) == 0 and r.value == 3 * k + 1 54 r = res(); ok = ok and om.omega2_bsum(ctypes.byref(r), b"abc", 3) == 0 and r.value == 294 55 check("interleaved madd (v1) and bsum (v2)", ok) 56 print(("PY-V2 FAIL " if fails else "PY-V2 PASS ") + str(fails)) 57 sys.exit(1 if fails else 0)