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
omega-mv / seed / omc / contracts / bridge-check.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Verification-only ctypes caller; it does not implement Omega contracts.""" |
| 3 | import ctypes |
| 4 | import sys |
| 5 | |
| 6 | library = ctypes.CDLL(sys.argv[1]) |
| 7 | check = library.omega2_check |
| 8 | check.argtypes = [ctypes.POINTER(ctypes.c_uint64), ctypes.c_int64] |
| 9 | check.restype = ctypes.c_uint32 |
| 10 | cases = [(-1, 9, 42), (0, 0, 0), (1, 0, 1), (9, 0, 9), |
| 11 | (10, 0, 10), (11, 10, 42), (20, 10, 42), (1, 0, 1)] |
| 12 | if len(sys.argv) == 3 and sys.argv[2] == "--wrong-expectation": |
| 13 | cases[0] = (-1, 0, 42) |
| 14 | elif len(sys.argv) != 2: |
| 15 | raise SystemExit("usage: bridge-check.py LIB [--wrong-expectation]") |
| 16 | failed = 0 |
| 17 | for argument, expected_status, expected_value in cases: |
| 18 | result = ctypes.c_uint64(42) |
| 19 | status = check(ctypes.byref(result), argument) |
| 20 | matched = (status, result.value) == (expected_status, expected_value) |
| 21 | if not matched: |
| 22 | failed += 1 |
| 23 | print("PASS" if matched else "FAIL", "argument", argument, |
| 24 | "status", status, "result", result.value, |
| 25 | "expected", expected_status, expected_value) |
| 26 | print("BRIDGE", "PASS" if failed == 0 else "FAIL", "cases", len(cases), "fail", failed) |
| 27 | raise SystemExit(0 if failed == 0 else 1) |