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_boot_test.sh

142 lines · 6842 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 handoff image in QEMU AArch64 with UEFI (AAVMF) and check the
18# serial console for the pre-exit report, the kernel reaching `kernel: alive`,
19# and the final report. The guest starts at EL2 like Machine 1, and PSCI reset
20# ends the run (-no-reboot). No physical hardware is touched.
21#
22# Needs qemu-system-aarch64 and AAVMF (Ubuntu: qemu-system-arm qemu-efi-aarch64).
23set -euo pipefail
24
25repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
26cd "${repo_root}"
27
28code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}"
29vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}"
30command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; exit 2; }
31[[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "AAVMF firmware not found"; exit 2; }
32
33commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)"
34AIENOS_COMMIT="${commit}" AIENOS_RESTART_SECS=1 cargo build --quiet --release \
35 -p aienos-boot --target aarch64-unknown-uefi --features handoff --bin aienos-handoff
36
37work="$(mktemp -d)"
38trap 'rm -rf "${work}"' EXIT
39mkdir -p "${work}/esp/EFI/BOOT" "${work}/esp/EFI/AIENOS"
40touch "${work}/esp/EFI/AIENOS/BOOTREPORT.TXT"
41cp "${CARGO_TARGET_DIR:-target}"/aarch64-unknown-uefi/release/aienos-handoff.efi "${work}/esp/EFI/BOOT/BOOTAA64.EFI"
42cp "${vars_fd}" "${work}/vars.fd"
43log="${work}/serial.log"
44
45# Issue #61: single-threaded TCG completed 120/120 soak boots; MTTCG hung in 1/40.
46qemu_accel=(-accel tcg,thread=single)
47
48started=$(date +%s)
49set +e
50timeout "${AIENOS_QEMU_TIMEOUT:-180}" qemu-system-aarch64 \
51 -M virt,virtualization=on,gic-version=3 "${qemu_accel[@]}" -cpu max -smp 4 -m 2048 \
52 -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \
53 -drive if=pflash,format=raw,file="${work}/vars.fd" \
54 -drive if=none,id=esp,format=raw,file=fat:rw:"${work}/esp" \
55 -device virtio-blk-pci,drive=esp \
56 -device ramfb -display none -nic none \
57 -serial file:"${log}" -no-reboot
58qemu_status=$?
59set -e
60elapsed=$(( $(date +%s) - started ))
61
62tr -d '\r' <"${log}" >"${work}/serial.txt"
63[[ -z "${AIENOS_LOG_DIR:-}" ]] || cp "${work}/serial.txt" "${AIENOS_LOG_DIR}/qemu_boot_serial.log"
64failed=0
65check() { # description, pattern
66 if grep -q -- "$2" "${work}/serial.txt"; then
67 echo "PASS $1"
68 else
69 echo "FAIL $1"
70 failed=1
71 fi
72}
73echo "qemu exit ${qemu_status} after ${elapsed} s (commit ${commit:0:12})"
74check "pre-exit report printed" "report_kind: pre_exit"
75check "image is this commit" "aienos_commit: ${commit}"
76check "left firmware and entered the kernel" "kernel: alive"
77check "kernel entered EL1h" "kernel_el: EL1h"
78check "cooperative threads interleaved" "threads: ok"
79check "EL0 capability and fault isolation" "el0: ok write=granted forged=denied fault=contained exit=0"
80check "timer-driven preemption across runnable tasks" "preempt: ok"
81check "deterministic MADT placement of preempt workers" "placement: worker0=class0/core0 worker1=class0/core1"
82check "typed IPC with attenuated revocable delegation" "ipc: ok message=delivered cap=delegated rights=attenuated forged=denied revoked=denied"
83check "EL1 page tables and caches enabled" "mmu: enabled"
84check "GICv3 enabled" "gic: v3"
85if grep -qE 'timer_irq: ([0-9]+) ticks' "${work}/serial.txt"; then
86 ticks=$(grep -oE 'timer_irq: ([0-9]+) ticks' "${work}/serial.txt" | tail -1 | grep -oE '[0-9]+')
87 [[ "${ticks}" -ge 5 ]] && echo "PASS timer IRQ delivered at least five ticks" || { echo "FAIL timer IRQ delivered fewer than five ticks"; failed=1; }
88else
89 echo "FAIL timer IRQ count reported"
90 failed=1
91fi
92# Issue #27: the kernel left firmware's EL2 translation for AIENOS EL1 tables.
93# The script re-checks the register values itself instead of trusting switched=yes.
94switch_re='mmu_switch: firmware=EL2 firmware_mmu=on firmware_ttbr0=(0x[0-9a-f]+) aienos_root=(0x[0-9a-f]+) ttbr0_el1=(0x[0-9a-f]+) switched=yes'
95switch_line=$(grep -E "${switch_re}" "${work}/serial.txt" | tail -1 || true)
96if [[ "${switch_line}" =~ ${switch_re} ]]; then
97 fw_root="${BASH_REMATCH[1]}"; aienos_root="${BASH_REMATCH[2]}"; el1_root="${BASH_REMATCH[3]}"
98 if [[ "${aienos_root}" == "${el1_root}" && "${aienos_root}" != "${fw_root}" ]]; then
99 echo "PASS MMU switched from firmware tables (${fw_root}) to AIENOS tables (${aienos_root})"
100 else
101 echo "FAIL MMU switch values inconsistent: ${switch_line}"
102 failed=1
103 fi
104else
105 echo "FAIL MMU switch from firmware tables reported"
106 failed=1
107fi
108check "GIC bases from the ACPI MADT, GICv3 architecture and ICC system registers" \
109 "gic_madt: gicd=0x[0-9a-f]* gicr=0x[0-9a-f]* arch_rev=3 icc_sre=1"
110# Issue #28: tick statistics. The dispatcher re-arms the timer 10 ms after each
111# tick, so no interval may be shorter than half a period (a missing re-arm or a
112# missing EOI would show as an interrupt storm or no second tick).
113stats_re='timer_stats: intid=30 freq_hz=([0-9]+) period_us=([0-9]+) min_us=([0-9]+) avg_us=([0-9]+) max_us=([0-9]+)'
114stats_line=$(grep -E "${stats_re}" "${work}/serial.txt" | tail -1 || true)
115if [[ "${stats_line}" =~ ${stats_re} ]]; then
116 period="${BASH_REMATCH[2]}"; min_us="${BASH_REMATCH[3]}"; avg_us="${BASH_REMATCH[4]}"; max_us="${BASH_REMATCH[5]}"
117 if [[ "${period}" -gt 0 && $(( min_us * 2 )) -ge "${period}" && "${min_us}" -le "${avg_us}" && "${avg_us}" -le "${max_us}" ]]; then
118 echo "PASS tick statistics consistent (period ${period} us, min ${min_us} avg ${avg_us} max ${max_us})"
119 else
120 echo "FAIL tick statistics out of range: ${stats_line}"
121 failed=1
122 fi
123else
124 echo "FAIL tick statistics reported"
125 failed=1
126fi
127check "final report on the SPCR console" "report_kind: final"
128check "no panic or fault" "report_kind: final"
129if grep -qE "report_kind: (panic|fault)" "${work}/serial.txt"; then
130 echo "FAIL panic or fault reported"
131 failed=1
132fi
133if [[ "${qemu_status}" == 124 ]]; then
134 echo "FAIL timed out (no reset)"
135 failed=1
136fi
137
138if [[ "${failed}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then
139 echo "---- serial console ----"
140 cat "${work}/serial.txt"
141fi
142[[ "${failed}" == 0 ]] && echo "QEMU_BOOT: PASS" || { echo "QEMU_BOOT: FAIL"; exit 1; }