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-mv/blob/main/tests/runtime/aienos_cap_abi_test.c # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / runtime / aienos_cap_abi_test.c` 122 lines ยท 6133 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* 18 * aienos_cap_abi_test.c -- OMEGA_AIENOS_CAP_ABI: src/runtime/aienos_cap.h, the 19 * hand-kept copy the runtime compiles against, must match the pinned Aienux 20 * header aienos_capability.h (aienos.lock), the one libaienos_capability.a is 21 * built from. Built and run only by tests/runtime/aienos_cap_abi.sh 22 * (make test-aienos-cap-abi), which writes, for the copy under test: 23 * omega_view.h the copy, unchanged 24 * omega_protos.h the copy without its struct definitions and include guard 25 * aca_list.h X-lists of its struct typedefs, their fields, its functions 26 * aca_exist.h #ifndef/#error for each valued macro it defines 27 * aca_rename.h O_ names for its struct and function-pointer typedefs, 28 * aca_unrename.h o_ names for its functions (and the #undefs) 29 * 30 * Every check is a compile-time error; the run repeats the layout rows only to 31 * count them for the GATE lines: 32 * 1. existence: each function and valued macro of the copy is declared by 33 * the pinned header; 34 * 2. layout: each struct typedef has the same sizeof and _Alignof, and each 35 * field the same offsetof, sizeof and kind (integer type and signedness, 36 * pointer or array element type, or which struct), so an equal-size 37 * reordered or retyped struct is refused; 38 * 3. constants: the copy's macros redefine the pinned ones; a different body 39 * is a redefinition error (-Werror); 40 * 4. prototypes: the copy's function and function-pointer declarations are 41 * redeclared over the pinned types; a different parameter or return type 42 * is a conflicting-types error. 43 */ 44 #include 45 #include 46 #include 47 48 #include "aienos_capability.h" 49 #include "aca_exist.h" 50 #include "aca_list.h" 51 52 /* 1. functions: taken from the pinned declarations (the copy is not in yet). */ 53 #define ACA_EXISTS(f) (void)&f; n++; 54 static int pinned_functions(void) { 55 int n = 0; 56 ACA_FUNCS(ACA_EXISTS) 57 return n; 58 } 59 60 /* The copy, under O_/o_ names; its macros redefine the pinned ones (check 3). */ 61 #include "aca_rename.h" 62 #include "omega_view.h" 63 #include "aca_unrename.h" 64 65 /* 2. layout. */ 66 #define ACA_INT_KINDS(X) \ 67 X(_Bool, 1) X(char, 2) X(signed char, 3) X(unsigned char, 4) X(short, 5) \ 68 X(unsigned short, 6) X(int, 7) X(unsigned int, 8) X(long, 9) X(unsigned long, 10) \ 69 X(long long, 11) X(unsigned long long, 12) X(float, 13) X(double, 14) X(long double, 15) 70 #define ACA_KIND_INT(T, k) T: k, T *: 100 + k, const T *: 200 + k, 71 #define ACA_KIND_STRUCT(T, k) \ 72 T: 1000 + k, O_##T: 1000 + k, T *: 1100 + k, O_##T *: 1100 + k, \ 73 const T *: 1200 + k, const O_##T *: 1200 + k, 74 #define ACA_KIND(e) \ 75 _Generic((e), ACA_INT_KINDS(ACA_KIND_INT) ACA_STRUCTS(ACA_KIND_STRUCT) default: 0) 76 #define ACA_M(T, f) (((T *)0)->f) 77 78 #define ACA_STRUCT_ASSERT(T, k) \ 79 _Static_assert(sizeof(O_##T) == sizeof(T), "sizeof " #T); \ 80 _Static_assert(_Alignof(O_##T) == _Alignof(T), "_Alignof " #T); 81 #define ACA_FIELD_ASSERT(T, f) \ 82 _Static_assert(offsetof(O_##T, f) == offsetof(T, f), "offsetof " #T "." #f); \ 83 _Static_assert(sizeof ACA_M(O_##T, f) == sizeof ACA_M(T, f), "sizeof " #T "." #f); \ 84 _Static_assert(ACA_KIND(ACA_M(O_##T, f)) == ACA_KIND(ACA_M(T, f)), "kind " #T "." #f); 85 ACA_STRUCTS(ACA_STRUCT_ASSERT) 86 ACA_FIELDS(ACA_FIELD_ASSERT) 87 88 typedef struct { 89 const char *what; 90 size_t copy[3], pinned[3]; /* offset or alignment, size, kind */ 91 } AcaRow; 92 #define ACA_STRUCT_ROW(T, k) \ 93 {#T, {_Alignof(O_##T), sizeof(O_##T), 1000 + k}, {_Alignof(T), sizeof(T), 1000 + k}}, 94 #define ACA_FIELD_ROW(T, f) \ 95 {#T "." #f, \ 96 {offsetof(O_##T, f), sizeof ACA_M(O_##T, f), (size_t)ACA_KIND(ACA_M(O_##T, f))}, \ 97 {offsetof(T, f), sizeof ACA_M(T, f), (size_t)ACA_KIND(ACA_M(T, f))}}, 98 static const AcaRow ROWS[] = {ACA_STRUCTS(ACA_STRUCT_ROW) ACA_FIELDS(ACA_FIELD_ROW)}; 99 100 /* 3 and 4: the copy's declarations again, now over the pinned types. */ 101 #include "omega_protos.h" 102 103 int main(void) { 104 int rows = (int)(sizeof ROWS / sizeof ROWS[0]), ok_rows = 0; 105 for (int i = 0; i < rows; i++) { 106 const AcaRow *r = &ROWS[i]; 107 if (r->copy[0] == r->pinned[0] && r->copy[1] == r->pinned[1] && 108 r->copy[2] == r->pinned[2]) 109 ok_rows++; 110 else 111 fprintf(stderr, "FAIL %s: copy %zu/%zu/%zu pinned %zu/%zu/%zu\n", r->what, 112 r->copy[0], r->copy[1], r->copy[2], r->pinned[0], r->pinned[1], 113 r->pinned[2]); 114 } 115 int fns = pinned_functions(); 116 printf("GATE OMEGA_AIENOS_CAP_ABI_LAYOUT_PASS %s %d/%d\n", ok_rows == rows ? "PASS" : "FAIL", 117 ok_rows, rows); 118 printf("GATE OMEGA_AIENOS_CAP_ABI_DECLS_PASS %s %d/%d\n", fns == ACA_FUNC_COUNT ? "PASS" : "FAIL", 119 fns + ACA_MACRO_COUNT, 120 ACA_FUNC_COUNT + ACA_MACRO_COUNT); 121 return ok_rows == rows && fns == ACA_FUNC_COUNT ? 0 : 1; 122 }