interplane.Get Omega
Read in your language

omega-bridge

Omega-first language interoperability: checked conversion backends and native language bindings

Brought by drakestapleton

branch main Branches Tags History

omega-bridge / tests / native / v2 / dev / aien.c

58 lines · 2209 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2/* CPU-only oracle: every ioctl uses fd -1. No device is opened.
3 * Request/count vectors come from omega-mv seed/host/aien-ioctl-matrix.json. */
4#include "omega_native.h"
5#include <errno.h>
6#include <stdint.h>
7#include <stdio.h>
8#include <sys/ioctl.h>
9
10/* QEMU10.0.14 rejects these untranslated requests before validating fd -1.
11 * This is an explicit emulator oracle, never a native-kernel fallback. */
12#ifdef OMEGA_AIEN_QEMU10_ORACLE
13#define AIEN_EXPECT_ERRNO ENOTTY
14#else
15#define AIEN_EXPECT_ERRNO EBADF
16#endif
17
18typedef uint32_t (*call_fn)(uint64_t *, uint64_t, uint64_t);
19struct check {
20 call_fn call;
21 unsigned long request;
22 uint64_t count, shorter, longer;
23};
24
25int main(void) {
26 static const struct check checks[] = {
27 {omega2_aiinfo, UINT32_C(2154840336), 112, 111, 113},
28 {omega2_aialloc, UINT32_C(3224387873), 48, 47, 49},
29 {omega2_aifree, UINT32_C(3222815010), 24, 23, 25},
30 {omega2_aicreate, UINT32_C(3225960739), 72, 71, 73},
31 {omega2_aidrop, UINT32_C(3222815012), 24, 23, 25},
32 };
33 unsigned char payload[4096] = {0};
34 const uint64_t sentinel = UINT64_C(0x123456789abcdef0);
35 for (size_t i = 0; i < sizeof checks / sizeof checks[0]; ++i) {
36 const struct check *check = &checks[i];
37 errno = 0;
38 if (ioctl(-1, check->request, payload) != -1 || errno != AIEN_EXPECT_ERRNO)
39 return 44;
40 int64_t expected = -(int64_t)errno;
41 uint64_t result = sentinel;
42 if (check->call(&result, -1, check->count) != 0 ||
43 (int64_t)result != expected)
44 return 41;
45 result = sentinel;
46 if (check->call(&result, -1, check->shorter) != 3 || result != sentinel)
47 return 42;
48 result = sentinel;
49 if (check->call(&result, -1, check->longer) != 3 || result != sentinel)
50 return 43;
51 }
52#ifdef OMEGA_AIEN_QEMU10_ORACLE
53 puts("NATIVE-AIEN-IOCTL EMULATED PASS (five exact ENOTTY C differentials, short/long traps; native/driver NOT_RUN)");
54#else
55 puts("NATIVE-AIEN-IOCTL PASS (five invalid-fd C differentials, exact short/long traps; driver NOT_RUN)");
56#endif
57 return 0;
58}