omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / tests / native / v2 / dev / cleanup.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #define _GNU_SOURCE |
| 3 | #include "omega_native.h" |
| 4 | #include <assert.h> |
| 5 | #include <stdint.h> |
| 6 | #include <stdio.h> |
| 7 | #include <sys/mman.h> |
| 8 | #include <unistd.h> |
| 9 | /* The qualification compiler replaces only mbind's cleanup munmap with getpid, |
| 10 | * a side-effect-free nonzero result. This forces cleanup failure deterministically |
| 11 | * without changing global VMA limits or interfering with any foreign range. |
| 12 | * WolframLanguageEvaluator: 2^36 -> 68719476736, address in bytes. */ |
| 13 | int main(void) |
| 14 | { |
| 15 | omega_native_context *c = 0; |
| 16 | uint64_t h = 0, out = 99; |
| 17 | assert(omega_native_context_create(2, &c) == OMEGA_OK); |
| 18 | assert(omega2_ctx_reserve(c, &h, UINT64_C(68719476736), 4096) == OMEGA_OK); |
| 19 | assert((int64_t)h > 0); |
| 20 | int fd = memfd_create("quarantine", MFD_CLOEXEC); |
| 21 | assert(fd >= 0 && ftruncate(fd, 4096) == 0); |
| 22 | assert(omega2_ctx_attach(c, &out, h, -1) == 3 && out == 99); |
| 23 | assert(omega_native_context_destroy(c) == OMEGA_CONTEXT_BUSY); |
| 24 | assert(omega2_ctx_address(c, &out, h) == OMEGA_OK && out == UINT64_C(68719476736)); |
| 25 | out = 99; |
| 26 | assert(omega2_ctx_attach(c, &out, h, fd) == 3 && out == 99); |
| 27 | assert(omega2_ctx_fetch(c, &out, h) == 3 && out == 99); /* mapread */ |
| 28 | assert(omega2_ctx_rd(c, &out, h) == 3 && out == 99); /* mapget */ |
| 29 | assert(omega2_ctx_publish(c, &out, h, 1) == 3 && out == 99); /* mapwrite */ |
| 30 | assert(omega2_ctx_store(c, &out, h) == 3 && out == 99); /* mapset */ |
| 31 | assert(omega2_ctx_drop(c, &out, h) == OMEGA_OK && out == 0); |
| 32 | out = 99; |
| 33 | assert(omega2_ctx_address(c, &out, h) == 3 && out == 99); |
| 34 | assert(omega2_ctx_drop(c, &out, h) == 3 && out == 99); |
| 35 | assert(omega_native_context_destroy(c) == OMEGA_OK); |
| 36 | assert(close(fd) == 0); |
| 37 | puts("NATIVE-CLEANUP PASS quarantine refuses bind/read/write, busy destroy, retry drop then destroy"); |
| 38 | return 0; |
| 39 | } |