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/aienux/blob/main/native/omega/platform/gate.sh # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / omega / platform / gate.sh` 242 lines ยท 10481 bytes Raw Blame History 1 #!/bin/sh 2 # SPDX-License-Identifier: Apache-2.0 3 # Copyright 2026 Drake Stapleton (AIEN / aien-dev) 4 # 5 # Host verification oracle only. No hardware access; the implementation under 6 # test is readback.om. POSIX sh, awk, od, sha256sum, nice and the pinned omc. 7 # 8 # Usage: sh native/omega/platform/gate.sh /absolute/pinned/omc EXPECTED_SHA256 OUT_DIR 9 # 10 # Builds unit.om and a descriptor-parity program generated from 11 # cppc-fixture.json (twenty CPUs, twelve selected CPPC descriptors each, plus 12 # seven thermal zones), requires both to compile and exit 0, then compiles six 13 # single-site mutants of readback.om and requires each to compile and exit 14 # nonzero. A compiler failure is never counted as a killed mutant. 15 # Writes per-program .om, binary, .compile.stderr, .stdout, .stderr and 16 # results.json into OUT_DIR. 17 set -eu 18 export LC_ALL=C 19 # cd prints the directory when CDPATH supplies it, which would corrupt $(cd ...). 20 unset CDPATH 21 22 die() { printf 'PLATFORM READBACK FAIL: %s\n' "$*" >&2; exit 1; } 23 24 [ "$#" -eq 3 ] || die "usage: gate.sh OMC EXPECTED_SHA256 OUT_DIR" 25 here=$(cd "$(dirname "$0")" && pwd -P) 26 omc=$1 27 expected=$2 28 mkdir -p "$3" 29 out=$(cd "$3" && pwd -P) 30 31 [ -f "$omc" ] || die "compiler not found: $omc" 32 got=$(sha256sum < "$omc" | cut -d' ' -f1) 33 [ "$got" = "$expected" ] || die "compiler pin mismatch (got $got)" 34 case "$omc" in /*) ;; *) omc=$(cd "$(dirname "$omc")" && pwd -P)/$(basename "$omc") ;; esac 35 36 source=$here/readback.om 37 unit=$here/unit.om 38 fixture=$here/cppc-fixture.json 39 for f in "$source" "$unit" "$fixture"; do 40 [ -f "$f" ] || die "missing input $f" 41 # The byte concatenations below rely on each input ending in a newline. 42 [ "$(tail -c 1 "$f" | od -An -c | tr -d ' ')" = '\n' ] || die "$f does not end in a newline" 43 done 44 45 # Descriptor-parity program from the fixture. The reader is a small 46 # recursive-descent JSON parser: strings without escapes or control characters, 47 # objects, arrays, JSON numbers and the literals true, false and null. It 48 # requires a cpus array of exactly 20 objects, each with a registers array of 49 # exactly 21 objects whose space, bits, offset, address and access fields are 50 # strings (no duplicate keys anywhere), hex values written 0x..., a known 51 # address space, offset 0 and the access width implied by the space. 52 parity=$out/descriptor-parity.checks 53 count=$out/descriptor-parity.count 54 awk -v countfile="$count" ' 55 function fail(m) { printf "PLATFORM READBACK FAIL: fixture: %s\n", m > "/dev/stderr"; failed = 1; exit 1 } 56 function hexval(s, i, v) { 57 if (s !~ /^0[xX][0-9A-Fa-f]+$/) fail("not a 0x hex value: " s) 58 s = substr(s, 3); sub(/^0+/, "", s) 59 if (length(s) > 13) fail("hex value too wide: " s) 60 v = 0 61 for (i = 1; i <= length(s); i++) v = v * 16 + index("`0123456789abcdef`", tolower(substr(s, i, 1))) - 1 62 return v 63 } 64 function tokenize( n, p, q, c) { 65 n = length(text); p = 1; nt = 0 66 while (p <= n) { 67 c = substr(text, p, 1) 68 if (c == " " || c == "\t" || c == "\n" || c == "\r") { p++; continue } 69 if (index("[]{}:,", c)) { tt[++nt] = c; tv[nt] = c; p++; continue } 70 if (c == "\"") { 71 q = p + 1 72 while (q <= n && substr(text, q, 1) != "\"") { 73 if (substr(text, q, 1) == "\\") fail("escaped strings are not supported") 74 if (substr(text, q, 1) ~ /[\001-\037]/) fail("control character in a string") 75 q++ 76 } 77 if (q > n) fail("unterminated string") 78 tt[++nt] = "s"; tv[nt] = substr(text, p + 1, q - p - 1); p = q + 1; continue 79 } 80 q = p 81 while (q <= n && substr(text, q, 1) ~ /[-+.0-9A-Za-z]/) q++ 82 if (q == p) fail("unexpected character " c) 83 tt[++nt] = "v"; tv[nt] = substr(text, p, q - p); p = q 84 if (tv[nt] !~ /^(true|false|null|-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][-+]?[0-9]+)?)$/) fail("not a JSON value: " tv[nt]) 85 } 86 } 87 function want(t) { if (P > nt || tt[P] != t) fail("expected " t " at token " P); P++ } 88 # Parses one value at depth d (path[1..d] names where it sits). 89 function value(d, t, key, idx, seen) { 90 if (P > nt) fail("unexpected end of input") 91 t = tt[P] 92 # Every cpus and registers element must be an object, so a stray scalar 93 # cannot pad or shape the counts below. 94 if (path[1] == "cpus") { 95 if (d == 1 && t != "[") fail("cpus is not an array") 96 if (d == 2 && t != "{") fail("cpu " path[2] " is not an object") 97 if (d == 3 && path[3] == "registers" && t != "[") fail("cpu " path[2] ": registers is not an array") 98 if (d == 4 && path[3] == "registers" && t != "{") fail("cpu " path[2] " register " path[4] " is not an object") 99 } 100 if (t == "s" || t == "v") { 101 if (d == 5 && path[1] == "cpus" && path[3] == "registers") { 102 if (t != "s") fail("register field " path[5] " is not a string") 103 reg[path[2], path[4], path[5]] = tv[P] 104 } 105 P++; return 106 } 107 if (t == "{") { 108 P++ 109 if (d == 2 && path[1] == "cpus") ncpu = path[2] + 1 110 if (d == 4 && path[1] == "cpus" && path[3] == "registers") nreg[path[2]] = path[4] + 1 111 if (P <= nt && tt[P] == "}") { P++; return } 112 for (;;) { 113 if (P > nt || tt[P] != "s") fail("object key expected at token " P) 114 key = tv[P]; P++ 115 seen = d SUBSEP objid[d] SUBSEP key 116 if (seen in dup) fail("duplicate key " key) 117 dup[seen] = 1 118 want(":") 119 path[d + 1] = key; objid[d + 1] = ++nobj 120 value(d + 1) 121 if (P <= nt && tt[P] == ",") { P++; continue } 122 want("}"); return 123 } 124 } 125 if (t == "[") { 126 P++ 127 if (d == 1 && path[1] == "cpus") cpus_seen = 1 128 if (d == 3 && path[1] == "cpus" && path[3] == "registers") nreg[path[2]] = 0 129 if (P <= nt && tt[P] == "]") { P++; return } 130 for (idx = 0; ; idx++) { 131 path[d + 1] = idx; objid[d + 1] = ++nobj 132 value(d + 1) 133 if (P <= nt && tt[P] == ",") { P++; continue } 134 want("]"); return 135 } 136 } 137 fail("value expected at token " P) 138 } 139 { text = text $0 "\n" } 140 END { 141 if (failed) exit 1 142 tokenize() 143 P = 1; objid[0] = 0 144 if (nt == 0 || tt[1] != "{") fail("top level is not an object") 145 value(0) 146 if (P <= nt) fail("trailing data after the top-level object") 147 if (!cpus_seen) fail("no cpus array") 148 if (ncpu != 20) fail("expected 20 cpus, found " ncpu + 0) 149 split("space bits offset address access", F, " ") 150 for (c = 0; c < 20; c++) { 151 if (nreg[c] != 21) fail("cpu " c ": expected 21 registers, found " nreg[c] + 0) 152 for (r = 0; r < 21; r++) 153 for (k = 1; k <= 5; k++) 154 if (!((c, r, F[k]) in reg)) fail("cpu " c " register " r ": missing " F[k]) 155 } 156 print "fn main to int" 157 seq = 0 158 split("0 1 2 3 4 10 11 12 13 18 19 20", sel, " ") 159 for (c = 0; c < 20; c++) { 160 for (j = 1; j <= 12; j++) { 161 f = sel[j] + 0 162 sp = reg[c, f, "space"] 163 if (sp == "SystemMemory") space = 0 164 else if (sp == "FFixedHW") space = 127 165 else fail("cpu " c " field " f ": unknown space " sp) 166 bits = hexval(reg[c, f, "bits"]) 167 addr = hexval(reg[c, f, "address"]) 168 if (hexval(reg[c, f, "offset"]) != 0) fail("cpu " c " field " f ": offset is not 0") 169 if (hexval(reg[c, f, "access"]) != (space == 0 ? 3 : 0)) fail("cpu " c " field " f ": access width does not match the space") 170 seq++ 171 printf "if ne plstart 1 %d %d %d 0\nret 1\nend\n", c, f, seq 172 printf "if ne plack %d %d %.0f %.0f 3132 1 0\nret 2\nend\n", seq, space, addr, bits 173 print "if or ne get Pl 5 3132 ne get Pl 6 1"; print "ret 3"; print "end" 174 } 175 } 176 # Thermal zone registers (fixed addresses, not from the fixture). 177 split("0x1C238818 0x1C238820 0x1C238824 0x1C238828 0x1C23882C 0x1C238830 0x1C238834", zone, " ") 178 for (z = 1; z <= 7; z++) { 179 seq++ 180 printf "if ne plstart 0 %d 0 %d 0\nret 4\nend\n", z - 1, seq 181 printf "if ne plack %d 0 %.0f 32 3132 1 0\nret 5\nend\n", seq, hexval(zone[z]) 182 } 183 print "ret 0"; print "end" 184 print seq > countfile 185 } 186 ' "$fixture" > "$parity" || die "fixture rejected" 187 seq=$(cat "$count") 188 case "$seq" in ''|*[!0-9]*) die "fixture reader returned no descriptor count" ;; esac 189 190 results='' 191 run() { # name input_file expect(pass|fail) 192 name=$1 input=$2 expect=$3 193 src=$out/$name.om 194 bin=$out/$name 195 cp "$input" "$src" 196 rc=0 197 nice -n 15 "$omc" < "$src" > "$bin" 2> "$out/$name.compile.stderr" || rc=$? 198 [ "$rc" -eq 0 ] || die "$name: compile failed (exit $rc), not a valid mutant kill" 199 chmod 755 "$bin" 200 rc=0 201 nice -n 15 "$bin" > "$out/$name.stdout" 2> "$out/$name.stderr" || rc=$? 202 case "$expect" in 203 pass) [ "$rc" -eq 0 ] || die "$name: unexpected exit $rc" ;; 204 fail) [ "$rc" -ne 0 ] || die "$name: unexpected exit $rc" ;; 205 esac 206 sum=$(sha256sum < "$bin" | cut -d' ' -f1) 207 entry=$(printf ' {\n "name": "%s",\n "compile_exit": 0,\n "run_exit": %d,\n "sha256": "%s"\n }' "$name" "$rc" "$sum") 208 if [ -n "$results" ]; then results="$results, 209 $entry"; else results=$entry; fi 210 } 211 212 cat "$source" "$unit" > "$out/unit.input" 213 cat "$source" "$parity" > "$out/descriptor-parity.input" 214 run unit "$out/unit.input" pass 215 run descriptor-parity "$out/descriptor-parity.input" pass 216 217 # Each mutant changes exactly one literal site in readback.om. 218 nmut=0 219 mutant() { # name old new test(unit|parity) 220 name=$1 old=$2 new=$3 test=$4 221 awk -v old="$old" -v new="$new" ' 222 function count(s, n, i) { n = 0; while ((i = index(s, old)) > 0) { n++; s = substr(s, i + length(old)) } return n } 223 function repl(s, r, i) { r = ""; while ((i = index(s, old)) > 0) { r = r substr(s, 1, i - 1) new; s = substr(s, i + length(old)) } return r s } 224 { line[NR] = $0; total += count($0) } 225 END { 226 if (total != 1) { printf "PLATFORM READBACK FAIL: mutant site occurs %d times: %s\n", total, old > "/dev/stderr"; exit 1 } 227 for (k = 1; k <= NR; k++) print repl(line[k]) 228 }' "$source" > "$out/$name.mutated" || die "mutant $name: site is not unique" 229 if [ "$test" = parity ]; then t=$parity; else t=$unit; fi 230 cat "$out/$name.mutated" "$t" > "$out/$name.input" 231 run "$name" "$out/$name.input" fail 232 nmut=$((nmut + 1)) 233 } 234 mutant stale-ack 'if or ne seq get Pl 1 ne space get Pl 2' 'if ne space get Pl 2' unit 235 mutant wrong-address 'if or ne addr get Pl 3 ne bits get Pl 4' 'if ne bits get Pl 4' unit 236 mutant write-selector 'if lt field 5' 'if lt field 6' unit 237 mutant wide-raw 'if gt raw `4294967295`' 'if gt raw `18446744073709551615`' unit 238 mutant thermal-address 'ret `472090648`' 'ret `472090649`' parity 239 mutant cppc-stride 'mul unit 232' 'mul unit 233' parity 240 241 printf '[\n%s\n]\n' "$results" > "$out/results.json" 242 printf 'PLATFORM READBACK PASS: %d descriptor reads; boundary suite; %d runnable mutants rejected\n' "$seq" "$nmut"