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 / scripts / qemu_ck_boot_test.sh

125 lines · 5959 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# Boot the AIENOS C kernel core (native/boot + native/kernel, Lane 18) in QEMU
18# AArch64 with UEFI (AAVMF) and check the serial console with the same QEMU
19# invocation and the same patterns as scripts/qemu_boot_test.sh (the Rust
20# kernel's test). The guest starts at EL2 like Machine 1 and PSCI reset ends
21# the run (-no-reboot). QEMU is not hardware: a PASS here qualifies nothing
22# physical.
23#
24# Differences from qemu_boot_test.sh, all deliberate:
25# - builds with make (gcc + binutils), not cargo;
26# - prints NOT_RUN while the machine quiet flag (AIENOS_QUIET_FLAG) is held,
27# which it only reads, or while another gate holds the QEMU gate lock
28# (AIENOS_GATE_LOCK); both through scripts/lib_gate_hold.sh (aienos#278);
29# - the five M3 checks (threads, el0, preempt, placement, ipc) use the same
30# patterns and give their own verdict AIENOS_CK_M3, which is PASS only if
31# all five pass AND every M1 check of the same boot passes (no fault, no
32# panic, QEMU exit 0); the C kernel prints one extra line, ipc_detail,
33# which no check reads (native/kernel/GATES.md rows 16-20 list the
34# differences in how the C kernel does the work);
35# - two added checks: guard_page (the C kernel's guard-page fault self test)
36# and kernel entropy ("entropy: rndr ..."; no fallback source exists);
37# - stricter: any QEMU exit status other than 0 fails (the Rust script fails
38# only on the timeout status 124); PSCI reset with -no-reboot exits 0;
39# - the checks live in scripts/lib_ck_m1_checks.sh (shared with the Store gate);
40# - last two lines are AIENOS_CK_M3: and AIENOS_CK_M1: PASS|FAIL|NOT_RUN;
41# - AIENOS_QEMU_CPU overrides "-cpu max" for a manual negative run (e.g.
42# neoverse-n1, which has no FEAT_RNG/RNDR: M1 must FAIL on the entropy
43# row). scripts/ck_gates.sh unsets it, so receipts always use -cpu max.
44# - AIENOS_QEMU_GIC=2 boots QEMU with gic-version=2 (the Raspberry Pi 5 GIC-400
45# shape: GICv2, memory-mapped CPU interface) and the checks expect "gic: v2";
46# default 3 (GB10 shape).
47# Needs qemu-system-aarch64 and AAVMF (Ubuntu: qemu-system-arm qemu-efi-aarch64).
48set -euo pipefail
49
50repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
51cd "${repo_root}"
52
53code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}"
54vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}"
55command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; echo "AIENOS_CK_M3: NOT_RUN"; echo "AIENOS_CK_M1: NOT_RUN"; exit 2; }
56[[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "AAVMF firmware not found"; echo "AIENOS_CK_M3: NOT_RUN"; echo "AIENOS_CK_M1: NOT_RUN"; exit 2; }
57
58cross=""
59if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi
60commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)"
61out="${repo_root}/target/native-kernel"
62make -s -C native/kernel CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" >/dev/null
63
64# Machine quiet flag (read only) and the QEMU gate lock (one gate at a time):
65# scripts/lib_gate_hold.sh (aienos#278).
66. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib_gate_hold.sh"
67if ! gh_quiet_check || ! gh_lock_take qemu_ck_boot_test "${AIENOS_GATE_MINUTES:-60}"; then
68 echo "NOT_RUN ${gh_why}"
69 echo "AIENOS_CK_M3: NOT_RUN"
70 echo "AIENOS_CK_M1: NOT_RUN"
71 exit 3
72fi
73# Release only this run's own gate lock record, at most once.
74release_flag() { gh_lock_release; }
75work="$(mktemp -d)"
76cleanup() {
77 rm -rf "${work}"
78 release_flag
79}
80trap cleanup EXIT
81mkdir -p "${work}/esp/EFI/BOOT" "${work}/esp/EFI/AIENOS"
82touch "${work}/esp/EFI/AIENOS/BOOTREPORT.TXT"
83cp "${out}/BOOTAA64.EFI" "${work}/esp/EFI/BOOT/BOOTAA64.EFI"
84cp "${vars_fd}" "${work}/vars.fd"
85log="${work}/serial.log"
86
87# Issue #61: single-threaded TCG completed 120/120 soak boots; MTTCG hung in 1/40.
88qemu_accel=(-accel tcg,thread=single)
89qemu_cpu="${AIENOS_QEMU_CPU:-max}"
90
91started=$(date +%s)
92set +e
93timeout "${AIENOS_QEMU_TIMEOUT:-180}" qemu-system-aarch64 \
94 -M virt,virtualization=on,gic-version="${AIENOS_QEMU_GIC:-3}" "${qemu_accel[@]}" -cpu "${qemu_cpu}" -smp 4 -m 2048 \
95 -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \
96 -drive if=pflash,format=raw,file="${work}/vars.fd" \
97 -drive if=none,id=esp,format=raw,file=fat:rw:"${work}/esp" \
98 -device virtio-blk-pci,drive=esp \
99 -device ramfb -display none -nic none \
100 -serial file:"${log}" -no-reboot
101qemu_status=$?
102set -e
103elapsed=$(( $(date +%s) - started ))
104# Release the machine as soon as QEMU is gone.
105release_flag
106
107tr -d '\r' <"${log}" >"${work}/serial.txt"
108[[ -z "${AIENOS_LOG_DIR:-}" ]] || cp "${work}/serial.txt" "${AIENOS_LOG_DIR}/qemu_ck_boot_serial.log"
109failed=0
110# shellcheck source=scripts/lib_ck_m1_checks.sh
111source "${repo_root}/scripts/lib_ck_m1_checks.sh"
112echo "qemu exit ${qemu_status} after ${elapsed} s (commit ${commit:0:12}, -cpu ${qemu_cpu})"
113ck_m1_checks
114m3_failed=0
115ck_m3_checks
116
117if [[ "${failed}" != 0 || "${m3_failed}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then
118 echo "---- serial console ----"
119 cat "${work}/serial.txt"
120fi
121m3_verdict=PASS
122[[ "${m3_failed}" == 0 && "${failed}" == 0 ]] || m3_verdict=FAIL
123echo "AIENOS_CK_M3: ${m3_verdict}"
124[[ "${failed}" == 0 ]] && echo "AIENOS_CK_M1: PASS" || echo "AIENOS_CK_M1: FAIL"
125[[ "${failed}" == 0 && "${m3_verdict}" == PASS ]] || exit 1