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/scripts/qemu_boot_test.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 / 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). 23 set -euo pipefail 24 25 repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 26 cd "${repo_root}" 27 28 code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" 29 vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" 30 command -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 33 commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" 34 AIENOS_COMMIT="${commit}" AIENOS_RESTART_SECS=1 cargo build --quiet --release \ 35 -p aienos-boot --target aarch64-unknown-uefi --features handoff --bin aienos-handoff 36 37 work="$(mktemp -d)" 38 trap 'rm -rf "${work}"' EXIT 39 mkdir -p "${work}/esp/EFI/BOOT" "${work}/esp/EFI/AIENOS" 40 touch "${work}/esp/EFI/AIENOS/BOOTREPORT.TXT" 41 cp "${CARGO_TARGET_DIR:-target}"/aarch64-unknown-uefi/release/aienos-handoff.efi "${work}/esp/EFI/BOOT/BOOTAA64.EFI" 42 cp "${vars_fd}" "${work}/vars.fd" 43 log="${work}/serial.log" 44 45 # Issue #61: single-threaded TCG completed 120/120 soak boots; MTTCG hung in 1/40. 46 qemu_accel=(-accel tcg,thread=single) 47 48 started=$(date +%s) 49 set +e 50 timeout "${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 58 qemu_status=$? 59 set -e 60 elapsed=$(( $(date +%s) - started )) 61 62 tr -d '\r' <"${log}" >"${work}/serial.txt" 63 [[ -z "${AIENOS_LOG_DIR:-}" ]] || cp "${work}/serial.txt" "${AIENOS_LOG_DIR}/qemu_boot_serial.log" 64 failed=0 65 check() { # 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 } 73 echo "qemu exit ${qemu_status} after ${elapsed} s (commit ${commit:0:12})" 74 check "pre-exit report printed" "report_kind: pre_exit" 75 check "image is this commit" "aienos_commit: ${commit}" 76 check "left firmware and entered the kernel" "kernel: alive" 77 check "kernel entered EL1h" "kernel_el: EL1h" 78 check "cooperative threads interleaved" "threads: ok" 79 check "EL0 capability and fault isolation" "el0: ok write=granted forged=denied fault=contained exit=0" 80 check "timer-driven preemption across runnable tasks" "preempt: ok" 81 check "deterministic MADT placement of preempt workers" "placement: worker0=class0/core0 worker1=class0/core1" 82 check "typed IPC with attenuated revocable delegation" "ipc: ok message=delivered cap=delegated rights=attenuated forged=denied revoked=denied" 83 check "EL1 page tables and caches enabled" "mmu: enabled" 84 check "GICv3 enabled" "gic: v3" 85 if 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; } 88 else 89 echo "FAIL timer IRQ count reported" 90 failed=1 91 fi 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. 94 switch_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' 95 switch_line=$(grep -E "${switch_re}" "${work}/serial.txt" | tail -1 || true) 96 if [[ "${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 104 else 105 echo "FAIL MMU switch from firmware tables reported" 106 failed=1 107 fi 108 check "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). 113 stats_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]+)' 114 stats_line=$(grep -E "${stats_re}" "${work}/serial.txt" | tail -1 || true) 115 if [[ "${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 123 else 124 echo "FAIL tick statistics reported" 125 failed=1 126 fi 127 check "final report on the SPCR console" "report_kind: final" 128 check "no panic or fault" "report_kind: final" 129 if grep -qE "report_kind: (panic|fault)" "${work}/serial.txt"; then 130 echo "FAIL panic or fault reported" 131 failed=1 132 fi 133 if [[ "${qemu_status}" == 124 ]]; then 134 echo "FAIL timed out (no reset)" 135 failed=1 136 fi 137 138 if [[ "${failed}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then 139 echo "---- serial console ----" 140 cat "${work}/serial.txt" 141 fi 142 [[ "${failed}" == 0 ]] && echo "QEMU_BOOT: PASS" || { echo "QEMU_BOOT: FAIL"; exit 1; }