interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / tests / gates / run.sh

307 lines · 16551 bytes Raw Blame History
1#!/usr/bin/env 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# tests/gates/run.sh: the one entry point for the local verification gates of aienos.
18# Every step runs the SAME command as the hosted job it replaced. #427 removed those workflows
19# (ck-kernel.yml, native-suites.yml, crypto-boundary.yml, infer-crate.yml, crumb.yml, ci.yml). The
20# only hosted run left is the portable smoke set in the advisory AIEN Checks job
21# (aien-verification.yml); the workflow names below say where each command came from.
22# Manifests under tests/gates/ name this script plus one step word, so no manifest needs shell
23# expansion (ADR 0028 P6).
24set -euo pipefail
25ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
26cd "$ROOT"
27step="${1:?usage: tests/gates/run.sh <step>}"
28obs() { printf 'AIEN-OBS %s %s\n' "$1" "$2"; }
29
30# The removed hosted jobs kept the quiet flag and the QEMU gate lock in the runner's temp dir,
31# never in ~/workspace (ck-kernel.yml, native-suites.yml). Same here.
32TMP="$(mktemp -d /tmp/aienos-gate.XXXXXX)"
33trap 'rm -rf "$TMP"' EXIT
34export AIENOS_QUIET_FLAG="$TMP/spark-quiet"
35export AIENOS_GATE_LOCK="$TMP/qemu-gate-lock"
36
37# native-suites.yml: make must succeed AND every suite must print its own pass marker, and
38# never NOT_RUN. $1 = suite dir, $2 = make targets, $3 = required marker regexes joined by |.
39native_suite() {
40 local suite="$1" targets="$2" req="$3" log="$TMP/suite.log" found=0
41 set -o pipefail
42 # native/crypto has no .gitignore for its out/ (the other suites do), so the build output
43 # would stay in the tree; the hosted job throws its checkout away. Remove an out/ that this
44 # step created, and only when git does not already ignore it. The gate itself is unchanged.
45 if [ ! -e "native/$suite/out" ] && ! git check-ignore -q "native/$suite/out"; then
46 CLEAN_OUT="$ROOT/native/$suite/out"
47 trap 'rm -rf "$TMP" "$CLEAN_OUT"' EXIT
48 fi
49 # shellcheck disable=SC2086
50 make -C "native/$suite" $targets 2>&1 | tee "$log"
51 while IFS= read -r m; do
52 grep -qE "$m" "$log" || { echo "missing marker: $m"; obs markers_missing 1; exit 1; }
53 echo "found: $m"; found=$((found + 1))
54 done < <(printf '%s\n' "$req" | tr '|' '\n')
55 if grep -q 'NOT_RUN' "$log"; then echo 'NOT_RUN in log'; obs not_run_in_log true; exit 1; fi
56 obs markers_found "$found"
57 obs not_run_in_log false
58}
59
60# One test script inside a step. It counts only when it exits 0 AND prints every required line
61# whole (several print NOT_RUN and exit 0, 2 or 3; that is never a pass). Each failure is
62# counted in $script_fail so the step runs every script and fails at the end.
63# Usage: must_pass NAME LINE_REGEX... -- COMMAND...
64script_pass=0
65script_fail=0
66must_pass() {
67 local name="$1" log rc=0 r req=()
68 shift
69 while [ "$1" != -- ]; do req+=("$1"); shift; done
70 shift
71 log="$TMP/script-$name.log"
72 echo "== $name: $*"
73 "$@" 2>&1 | tee "$log" || rc=$?
74 if [ "$rc" != 0 ]; then
75 echo "script $name: exit $rc, not PASS"; script_fail=$((script_fail + 1)); return 0
76 fi
77 for r in "${req[@]}"; do
78 if ! grep -aqxE -- "$r" "$log"; then
79 echo "script $name: no line matching '$r', not PASS"; script_fail=$((script_fail + 1)); return 0
80 fi
81 done
82 echo "script $name: PASS"; script_pass=$((script_pass + 1))
83}
84scripts_verdict() {
85 obs scripts_pass "$script_pass"
86 obs scripts_fail "$script_fail"
87 [ "$script_fail" = 0 ]
88}
89
90# pinned_omc COMMIT SHA256: make AIEN_OMC the seeded Omega compiler with that hash. AIEN_OMC wins
91# when it has the hash; otherwise the committed compiler at COMMIT is taken from the sibling
92# checkout ../omega-mv (a clone of ~/git/omega-mv.git). Neither available: exit 3, never a pass.
93# PIN at the repository root names the one compiler build ("omega-mv <sha1>", "omc-sha256 <omc
94# sha256>", the format pin-follow.sh moves) for native/disk, native/net/tcp and tools/hwgates;
95# moving it moves all three.
96pin_of() { pinned_omc "$(sed -n 's/^omega-mv //p' "$1")" "$(sed -n 's/^omc-sha256 //p' "$1")"; }
97pinned_omc() {
98 local pc="$1" ps="$2" h=""
99 if [ -n "${AIEN_OMC:-}" ] && [ -r "$AIEN_OMC" ]; then h=$(sha256sum "$AIEN_OMC" | cut -d' ' -f1); fi
100 if [ "$h" != "$ps" ]; then
101 if [ -d ../omega-mv ] && git -C ../omega-mv show "$pc:seed/out/omc" > "$TMP/omc" 2>/dev/null; then
102 chmod +x "$TMP/omc"; export AIEN_OMC="$TMP/omc"
103 h=$(sha256sum "$AIEN_OMC" | cut -d' ' -f1)
104 fi
105 fi
106 if [ "$h" != "$ps" ]; then
107 echo "run.sh: no omc with sha256 $ps (set AIEN_OMC, or clone ~/git/omega-mv.git beside this tree as ../omega-mv)" >&2
108 obs omc_pinned false
109 exit 3
110 fi
111 obs omc_pinned true
112}
113
114case "$step" in
115 # crumb-verify (gate CRUMB-VERIFY) is retired (DRA-97, 2026-11-07): Crumbs are off the active
116 # workflow, so no gate checks crumb freshness. The .crumb files and crumb.lock stay as history.
117 # ck-kernel.yml, host steps (ubuntu-24.04-arm there, AArch64 here)
118 ck-host-tests)
119 make -C native/kernel test sanitize
120 bash scripts/ck_swap_disk_bound_test.sh
121 bash scripts/ck_imac_lab_services_test.sh
122 bash scripts/check_local_model.sh --self-test
123 # Host-only kernel regressions (no QEMU machine, no model server, no network beyond loopback
124 # and a private namespace). ck_courier_udp_frame needs sudo -n for unshare --net.
125 must_pass fat_boot 'AIENOS_FAT_BOOT: PASS' -- bash scripts/ck_fat_boot_test.sh
126 must_pass allen_memory 'AIENOS_ALLEN_MEMORY: PASS' -- bash scripts/ck_allen_memory_test.sh
127 must_pass allen_canvas 'AIENOS_ALLEN_CANVAS: PASS' -- bash scripts/ck_allen_canvas_test.sh
128 must_pass allen_code 'AIENOS_ALLEN_CODE: PASS' -- bash scripts/ck_allen_code_test.sh
129 must_pass allen_ui 'AIENOS_ALLEN_UI: PASS' -- bash scripts/ck_allen_ui_test.sh
130 must_pass boot_show 'AIENOS_BOOT_SHOW: PASS' -- bash scripts/ck_boot_show_test.sh
131 must_pass courier_udp_frame 'COURIER_FRAMES: PASS .*' \
132 'COURIER_FRAME_ACK_CONTROL: PASS withholding GOT triggers real LINE retransmission' \
133 -- env -u KEEP_LOGS bash scripts/ck_courier_udp_frame_test.sh
134 must_pass courier_udp 'AIENOS_COURIER_UDP: PASS' -- env -u ALLEN_MODEL bash scripts/ck_courier_udp_test.sh
135 must_pass imac_bsdp 'AIENOS_IMAC_BSDP: PASS' -- bash scripts/ck_imac_bsdp_test.sh
136 must_pass imac_report 'AIENOS_IMAC_REPORT: PASS' -- bash scripts/ck_imac_report_test.sh
137 must_pass imac_security 'AIENOS_IMAC_SECURITY: PASS' -- bash scripts/ck_imac_security_test.sh
138 must_pass setup_wizard 'AIENOS_SETUP_WIZARD: PASS' -- bash scripts/ck_setup_wizard_test.sh
139 must_pass sky 'AIENOS_SKY: PASS' -- bash scripts/ck_sky_test.sh
140 must_pass sky_sharpness 'AIENOS_SKY_SHARPNESS: PASS' -- bash scripts/ck_sky_sharpness_test.sh
141 must_pass virtio_av 'AIENOS_VIRTIO_AV: PASS' -- bash scripts/ck_virtio_av_test.sh
142 must_pass mind_phases 'AIENOS_MIND_PHASES: PASS' -- sh scripts/ck_mind_phases_test.sh "$TMP/mind-phases"
143 scripts_verdict
144 ;;
145 ck-stage-tests) make -C native/kernel stage-test stage-sanitize ;;
146 ck-gate-selftest) bash scripts/ck_gates.sh --self-test ;;
147 ck-hold-selftest) bash scripts/gate_hold_selftest.sh ;;
148 ck-owner-keys) bash scripts/ck_owner_keys_check.sh ;;
149 # ck-kernel.yml, QEMU TCG gates: every gate with a C implementation except FPU and INFER
150 ck-qemu-gates)
151 mkdir -p "$TMP/ck-receipt"
152 set +e
153 bash scripts/ck_gates.sh --out "$TMP/ck-receipt" | tee "$TMP/ck-gates.txt"
154 rc=${PIPESTATUS[0]}
155 set -e
156 echo "ck_gates.sh exit ${rc}"
157 [ "${rc}" = 0 ] || exit 1
158 required=$(sed -n "/^CK_GATE_TABLE='/,/^'/p" scripts/ck_gates.sh | awk -F'|' 'NF==3 && $2!="missing" && $1!="FPU" && $1!="INFER" {print $1}')
159 [ -n "${required}" ] || { echo "could not read the gate table"; exit 1; }
160 fail=0; n=0
161 for g in ${required}; do
162 if grep -q "^AIENOS_CK_${g}: PASS" "$TMP/ck-gates.txt"; then echo "required gate ${g}: PASS"; n=$((n + 1))
163 else echo "required gate ${g}: not PASS"; fail=1; fi
164 done
165 obs required_gates_pass "$n"
166 # Self-contained QEMU tests of the iMac kernel: no model server (allen_code replays its
167 # recorded replies), no hardware; gpu_bench's BARs are RAM stand-ins. Each takes the gate lock.
168 must_pass allen_memory_qemu 'AIENOS_ALLEN_MEMORY_QEMU: PASS' -- bash scripts/qemu_ck_allen_memory_test.sh
169 must_pass imac_bootdisk 'AIENOS_IMAC_BOOTDISK: PASS' -- bash scripts/qemu_ck_imac_bootdisk_test.sh
170 must_pass imac_swap 'AIENOS_IMAC_SWAP: PASS' -- bash scripts/qemu_ck_imac_swap_test.sh
171 must_pass imac_kernel 'AIENOS_IMAC_KERNEL: PASS' -- env AIENOS_IMAC_DMAR=0 bash scripts/qemu_ck_imac_kernel_test.sh
172 must_pass imac_keyboard 'AIENOS_IMAC_KEYBOARD: PASS' -- bash scripts/qemu_ck_imac_keyboard_test.sh
173 must_pass boot_show_qemu 'AIENOS_CK_BOOT_SHOW: PASS' -- bash scripts/qemu_ck_boot_show_test.sh aarch64 tcg
174 must_pass gpu_bench 'AIENOS_GPU_BENCH: PASS' -- bash scripts/qemu_ck_gpu_bench_test.sh
175 must_pass local_tools 'LOCAL_TOOLS: PASS cpu=qemu64' 'LOCAL_TOOLS: PASS cpu=max' \
176 -- env LOCAL_TOOLS_OUT="$TMP/local-tools" bash scripts/qemu_ck_local_tools_test.sh
177 must_pass allen_code_qemu 'AIENOS_ALLEN_CODE_QEMU: PASS' -- env ALLEN_CODE_LIVE=0 bash scripts/qemu_ck_allen_code_test.sh
178 scripts_verdict || fail=1
179 exit ${fail}
180 ;;
181 # Not hosted: QEMU tests that need outside inputs. A missing input is a FAIL, never a pass.
182 # ALLEN_MODEL host:port of an OpenAI-shape model server answering /health
183 # (allen_courier, allen_wizard); no default, so the shared server
184 # is only ever used when the operator names it
185 # LOCAL_MODEL_WEIGHTS pinned stories15M.bin (local_model checks its sha256)
186 # LOCAL_MODEL_TOKENIZER pinned tokenizer.bin
187 ck-qemu-external)
188 missing=0
189 for v in ALLEN_MODEL LOCAL_MODEL_WEIGHTS LOCAL_MODEL_TOKENIZER; do
190 if [ -z "${!v:-}" ]; then echo "::error::ck-qemu-external needs $v" >&2; missing=$((missing + 1)); fi
191 done
192 for v in LOCAL_MODEL_WEIGHTS LOCAL_MODEL_TOKENIZER; do
193 if [ -n "${!v:-}" ] && [ ! -r "${!v}" ]; then echo "::error::$v=${!v} is not a readable file" >&2; missing=$((missing + 1)); fi
194 done
195 obs inputs_missing "$missing"
196 [ "$missing" = 0 ] || exit 1
197 must_pass allen_courier 'AIENOS_ALLEN_COURIER: PASS' -- bash scripts/qemu_ck_allen_courier_test.sh
198 must_pass allen_wizard 'AIENOS_ALLEN_WIZARD: PASS' -- bash scripts/qemu_ck_allen_wizard_test.sh
199 must_pass local_model 'LOCAL_MODEL: PASS cpu=qemu64' 'LOCAL_MODEL: PASS cpu=max' \
200 -- env -u LOCAL_MODEL_CPUS LOCAL_MODEL_OUT="$TMP/local-model" bash scripts/qemu_ck_local_model_test.sh
201 scripts_verdict
202 ;;
203 ck-b7b-probe)
204 bash scripts/qemu_ck_b7b_probe_test.sh --self-test
205 bash scripts/qemu_ck_b7b_probe_test.sh
206 bash scripts/qemu_ck_b7b_probe_test.sh --positive
207 # #469 SMMU stream-ownership fault check: real out-of-window NVMe DMA must raise an event
208 # with the decoded SID/address, the canary page stays intact, the recovery read succeeds.
209 bash scripts/qemu_ck_b7b_probe_test.sh --events
210 ;;
211 # Hardware-gate register (docs/HARDWARE_GATES.md): fixtures, checker mutants, the register, its
212 # receipts, a size alarm and planted-bad copies. Needs the compiler named in PIN.
213 hw-gates)
214 pin_of PIN
215 sh tools/hwgates/gate.sh
216 ;;
217 # Bounded read-only NVMe protocol in seeded Omega (#472): host cases, guard mutants and
218 # disposable-QEMU cases (the test prints its counts). Physical NVMe stays NOT_RUN.
219 omega-nvme)
220 pin_of PIN
221 must_pass omega_nvme 'PASS Omega NVMe host \+ QEMU \+ guard mutants; physical NOT_RUN' \
222 -- env OMEGA_NVME_EVIDENCE="$TMP/omega-nvme" sh native/disk/tests/omega_nvme_test.sh
223 scripts_verdict
224 ;;
225 # Native TCP stack in seeded Omega (L232): the hosted hostile corpus (exact-state cases plus
226 # 2,000,000 seeded mutated frames), built with the compiler named in PIN. No QEMU; the
227 # QEMU profiles stay in native/net/tcp/gate.sh.
228 tcp-corpus)
229 pin_of PIN
230 cat native/net/tcp/tcp.om native/net/tcp/corpus.om | "$AIEN_OMC" > "$TMP/tcp-corpus"
231 chmod +x "$TMP/tcp-corpus"
232 must_pass tcp_corpus 'CORPUS_PASS checks=[0-9]+ .*' -- "$TMP/tcp-corpus" 2000000
233 scripts_verdict
234 ;;
235 # native-suites.yml matrix
236 native-net) native_suite net "test sanitize mutants" 'AIENOS_NET_SECURE_TESTS: PASS|NET_SANITIZE: PASS|NET_SECURE_MUTANTS: [0-9]+/[0-9]+ killed' ;;
237 native-sig) native_suite sig "test sanitize mutants" 'AIENOS_SIG_NATIVE: PASS|AIENOS_SIG_MUTANTS: PASS' ;;
238 native-crypto) native_suite crypto "test sanitize mutants" 'AIENOS_CRYPTO_NATIVE: PASS|AIENOS_CRYPTO_MUTANTS: PASS' ;;
239 native-m5) native_suite m5 "test sanitize mutants" 'M5_NATIVE: PASS|M5_NATIVE_MUTANTS: PASS' ;;
240 native-disk) native_suite disk "test sanitize mutants" 'AIENOS_DISK_NATIVE: PASS|AIENOS_DISK_SANITIZE: PASS|AIENOS_DISK_MUTANTS: PASS' ;;
241 native-argus) native_suite argus "test sanitize" 'GATE CONTAIN_TEST PASS|GATE CONTAIN_DETERMINISM PASS' ;;
242 native-capability) native_suite capability "mutants" 'AIENOS_CAP_MUTANTS: PASS' ;;
243 disk-qemu)
244 set -o pipefail
245 bash scripts/qemu_native_nvme_test.sh 2>&1 | tee "$TMP/qemu.log"
246 # The script exits 0 on NOT_RUN; only an explicit PASS counts.
247 grep -qx 'AIENOS_STORE_NVME_QEMU: PASS' "$TMP/qemu.log"
248 ;;
249 # crypto-boundary.yml (one job, four commands)
250 crypto-boundary)
251 cargo test --locked --offline -p aienos-crypto
252 cargo test --locked --offline -p aienos-kernel crypto::
253 cargo clippy --locked --offline -p aienos-crypto --all-targets -- -D warnings
254 cargo check --locked --offline -p aienos-kernel --target aarch64-unknown-none --no-default-features
255 ;;
256 # infer-crate.yml (one job: fmt, clippy, test, no_std build)
257 infer-crate)
258 export AIENOS_MODEL="${AIENOS_MODEL:-/nonexistent/no-model.gguf}" # hosted runner has no model file; forward tests SKIP
259 test -f crates/aienos-infer/Cargo.toml
260 cargo fmt -p aienos-infer --check
261 cargo clippy -p aienos-infer --all-targets -- -D warnings
262 cargo test -p aienos-infer
263 cargo build -p aienos-infer --target aarch64-unknown-none
264 ;;
265 # Not hosted (the hosted runner has no model file): the real Llama forward comparisons in
266 # crates/aienos-infer/tests/forward.rs, release build. The sandbox finds the model at
267 # $HOME/models (aien-run-exec bind-mounts the operator's ~/models read-only there).
268 # A missing model or any SKIPPED line is a FAIL, never a silent pass.
269 infer-forward)
270 model="${AIENOS_MODEL:-$HOME/models/aien-mail/Llama-3.2-1B-Instruct-Q4_K_M.gguf}"
271 if [ ! -f "$model" ]; then
272 echo "::error::model file $model not present; infer-forward needs the real model" >&2
273 obs model_present false
274 exit 1
275 fi
276 obs model_present true
277 export AIENOS_MODEL="$model"
278 set -o pipefail
279 cargo test --release -p aienos-infer --test forward 2>&1 | tee "$TMP/forward.log"
280 if grep -q 'SKIPPED' "$TMP/forward.log"; then
281 echo "::error::forward tests printed SKIPPED" >&2
282 obs skipped_in_log true
283 exit 1
284 fi
285 obs skipped_in_log false
286 ;;
287 # ci.yml (disabled on GitHub since the CK workflow took over): the suites it still names
288 store-native) make -C native/store test mutants ;;
289 verify-all)
290 export AIENOS_MODEL="${AIENOS_MODEL:-/nonexistent/no-model.gguf}" # hosted parity: the debug workspace sweep skips forward tests (they run in infer-forward)
291 bash scripts/verify_all.sh
292 ;;
293 zero-disk-secrets)
294 echo "Auditing repository for prohibited plaintext secret files..."
295 if find . -maxdepth 4 -name ".env*" -not -path "*/.git/*" -not -path "*/target/*" -not -path "*/vendor/*" | grep -q .; then
296 echo "::error::Prohibited plaintext .env file found. Use an approved AIEN SecretProvider."
297 obs env_files_found true
298 exit 1
299 fi
300 obs env_files_found false
301 echo "Zero plaintext .env files verified."
302 ;;
303 *)
304 echo "run.sh: unknown step '$step'" >&2
305 exit 2
306 ;;
307esac