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.sh
# 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.sh`
134 lines ยท 7448 bytes Raw Blame History
1 #!/bin/bash
2 # SPDX-License-Identifier: Apache-2.0
3 # Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # OMEGA_AIENOS_CAP_ABI: src/runtime/aienos_cap.h is a hand-kept copy of aienos
18 # native/capability/aienos_capability.h. The runtime compiles against the copy and
19 # links libaienos_capability.a built from the aienos.lock commit, so the copy must
20 # match the pinned header: struct layouts field by field, macro values, prototypes
21 # (tests/runtime/aienos_cap_abi_test.c says how each is checked).
22 #
23 # usage: aienos_cap_abi.sh
24 #
25 # The copy must PASS; each mutant below (a temporary copy of aienos_cap.h with one
26 # change) must be refused with a diagnostic naming what changed. A mutant whose
27 # pattern no longer matches is a failure of this script, never a silent skip.
28 # Shell, sed, awk and the C compiler only.
29 set -u
30 PIN=${1:?usage: aienos_cap_abi.sh }
31 HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
32 COPY=$HERE/src/runtime/aienos_cap.h
33 TEST=$HERE/tests/runtime/aienos_cap_abi_test.c
34 CC=${CC:-cc}
35 CFLAGS=${CFLAGS:--std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -O2}
36 export LC_ALL=C
37 [ -f "$PIN/aienos_capability.h" ] || { echo "error: no aienos_capability.h in $PIN"; exit 1; }
38 W=$(mktemp -d "${TMPDIR:-/tmp}/aienos-cap-abi.XXXXXX")
39 trap 'rm -rf "$W"' EXIT
40
41 # gen : the files aienos_cap_abi_test.c includes (see its comment).
42 gen() {
43 mkdir -p "$2" && cp "$1" "$2/omega_view.h" || return 1
44 sed -e '/^typedef struct {/,/^}/d' -e '/^#ifndef /d' -e '/^#endif/d' \
45 -e '/^#define [A-Za-z0-9_]*[ \t]*$/d' -e '/^#include /d' "$1" >"$2/omega_protos.h" || return 1
46 awk -v D="$2" '
47 function bad(m) { printf "aienos_cap_abi: %s:%d: %s: %s\n", FILENAME, FNR, m, $0 > "/dev/stderr"; err = 1; exit 1 }
48 function ident_before(s, re) { if (!match(s, re)) bad("no name"); s = substr(s, 1, RSTART - 1); match(s, /[A-Za-z_][A-Za-z0-9_]*$/); return substr(s, RSTART, RLENGTH) }
49 /^typedef struct \{[ \t]*$/ { ins = 1; nf = 0; next }
50 ins && /^\}/ {
51 if (!match($0, /^\}[ \t]*[A-Za-z_][A-Za-z0-9_]*[ \t]*;[ \t]*$/)) bad("struct end")
52 t = $0; sub(/^\}[ \t]*/, "", t); sub(/[ \t]*;.*$/, "", t)
53 structs = structs " X(" t ", " (++ns) ")"; ren[++nr] = t; pre[nr] = "O_"
54 for (i = 1; i <= nf; i++) fields = fields " X(" t ", " f[i] ")"
55 ins = 0; next
56 }
57 ins && /^[ \t]*$/ { next }
58 ins && /^[ \t]*(\/\*|\*)/ { next }
59 ins {
60 if ($0 !~ /^[ \t]+[A-Za-z_][A-Za-z0-9_ \t*]*[ \t*][A-Za-z_][A-Za-z0-9_]*[ \t]*(\[[^]]*\])?[ \t]*;[ \t]*$/) bad("field")
61 s = $0; sub(/[ \t]*;[ \t]*$/, "", s); sub(/[ \t]*\[[^]]*\]$/, "", s)
62 match(s, /[A-Za-z_][A-Za-z0-9_]*$/); f[++nf] = substr(s, RSTART, RLENGTH); next
63 }
64 /^typedef[^;]*\(\*[ \t]*[A-Za-z_][A-Za-z0-9_]*[ \t]*\)/ {
65 ren[++nr] = ident_before($0, "[ \t]*\\)[ \t]*\\("); pre[nr] = "O_"; next
66 }
67 /^#define[ \t]+[A-Za-z_][A-Za-z0-9_]*[ \t]+[^ \t]/ { macros[++nm] = $2; next }
68 /^[A-Za-z_][A-Za-z0-9_ \t*]*[ \t*][A-Za-z_][A-Za-z0-9_]*[ \t]*\(/ && $1 != "typedef" {
69 fn = ident_before($0, "[ \t]*\\("); funcs = funcs " X(" fn ")"; ren[++nr] = fn; pre[nr] = "o_"; ++nfn; next
70 }
71 END {
72 if (err) exit 1
73 if (ins) { print "aienos_cap_abi: unterminated struct" > "/dev/stderr"; exit 1 }
74 if (!ns || !nfn) { print "aienos_cap_abi: no struct or no function found" > "/dev/stderr"; exit 1 }
75 L = D "/aca_list.h"
76 print "#define ACA_STRUCTS(X)" structs > L; print "#define ACA_FIELDS(X)" fields > L
77 print "#define ACA_FUNCS(X)" funcs > L
78 print "#define ACA_FUNC_COUNT " nfn > L; print "#define ACA_MACRO_COUNT " nm > L
79 for (i = 1; i <= nm; i++)
80 printf "#ifndef %s\n#error \"%s is not defined by the pinned header\"\n#endif\n", macros[i], macros[i] > (D "/aca_exist.h")
81 printf "" > (D "/aca_exist.h")
82 for (i = 1; i <= nr; i++) {
83 printf "#define %s %s%s\n", ren[i], pre[i], ren[i] > (D "/aca_rename.h")
84 printf "#undef %s\n", ren[i] > (D "/aca_unrename.h")
85 }
86 }' "$1"
87 }
88
89 # check : 0 when the header matches the pinned one; output in /log.
90 check() {
91 gen "$1" "$2" >"$2.gen.log" 2>&1 || { mkdir -p "$2"; cat "$2.gen.log" >"$2/log"; return 1; }
92 # shellcheck disable=SC2086
93 $CC $CFLAGS -Werror -I"$2" -I"$PIN" -o "$2/t" "$TEST" >"$2/log" 2>&1 >"$2/log" 2>&1 "$W/$id/aienos_cap.h"
120 if cmp -s "$COPY" "$W/$id/aienos_cap.h"; then
121 echo "MUTANT $name: FAIL (pattern no longer matches src/runtime/aienos_cap.h)"
122 elif check "$W/$id/aienos_cap.h" "$W/$id/case"; then
123 echo "MUTANT $name: FAIL (accepted)"
124 elif ! grep -q -- "$expect" "$W/$id/case/log"; then
125 echo "MUTANT $name: FAIL (refused, but not for \"$expect\"):"
126 grep -E 'error' "$W/$id/case/log" | head -3
127 else
128 caught=$((caught + 1))
129 echo "MUTANT $name: refused ($(grep -m1 -- "$expect" "$W/$id/case/log" | grep -o 'error: .*' | cut -c1-90))"
130 fi
131 done <<<"$MUTANTS"
132 echo "GATE OMEGA_AIENOS_CAP_ABI_MUTANTS_PASS $([ "$caught" = "$total" ] && echo PASS || echo FAIL) $caught/$total"
133 [ "$caught" = "$total" ] || exit 1
134 echo "OMEGA_AIENOS_CAP_ABI_PASS"