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_ck_boot_show_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_ck_boot_show_test.sh` 173 lines ยท 8701 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # qemu_ck_boot_show_test.sh -- the boot sequence (native/kernel/ui/boot_show.c: 3 # the night, two black holes circling and merging, the chirp) in the aarch64 4 # VM the aienos-run window shows: QEMU virt + AAVMF, the screen a 5 # virtio-gpu-pci and the speakers a virtio-sound-pci, both behind the smmuv3 6 # vIOMMU (their DMA confined like every device's), sound captured to a WAV. 7 # usage: qemu_ck_boot_show_test.sh [aarch64|x86_64] [tcg|kvm] (default aarch64 tcg; kvm: aarch64 on an 8 # aarch64 host with /dev/kvm). x86_64: QEMU q35 + OVMF, the screen virtio-vga (OVMF gives its linear 9 # framebuffer, the kernel draws there), the speakers virtio-sound-pci; that kernel has no IOMMU support 10 # yet, so its sound DMA is not confined (it says so on its console), and check 1 is the GOP screen line. 11 # Checks: 12 # 1. the screen came up on virtio-gpu inside its confined DMA window 13 # 2. the night ran its full 15.2 s and the receipt line counts frames and 14 # dropped 60 Hz slots (printed: the frame-rate receipt for this machine) 15 # 3. a screendump taken mid-night is not blank (stars are lit) 16 # 4. the sound went out on virtio-sound: started, fed, stopped, nothing refused 17 # 5. the WAV QEMU wrote holds the whole chirp, sample for sample the formula 18 # the kernel played from (ui/chirp.c), checked by ui/tools/boot_show_check.c 19 # Not proven here (stated, not hidden): the speed of any real machine; TCG 20 # emulates the CPU, so its frame rate is QEMU's, not the hardware's. 21 # Ends with "AIENOS_CK_BOOT_SHOW: PASS|FAIL|NOT_RUN". 22 set -euo pipefail 23 repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 24 cd "${repo_root}" 25 arch="${1:-aarch64}" 26 accel="${2:-tcg}" 27 case "${arch}" in tcg | kvm) accel="${arch}"; arch=aarch64 ;; esac # the one-argument form: aarch64 28 command -v socat >/dev/null || { echo "socat not installed (screendump)"; echo "AIENOS_CK_BOOT_SHOW: NOT_RUN"; exit 2; } 29 commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" 30 dev="disable-legacy=on" 31 case "${arch}" in 32 aarch64) 33 code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" 34 vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" 35 qemu=qemu-system-aarch64 36 case "${accel}" in 37 tcg) accel_args=(-accel tcg -cpu max); machine="virt,virtualization=on,gic-version=3,iommu=smmuv3" ;; 38 kvm) 39 [[ -w /dev/kvm && "$(uname -m)" == aarch64 ]] || { echo "NOT_RUN no usable /dev/kvm on an aarch64 host"; echo "AIENOS_CK_BOOT_SHOW: NOT_RUN"; exit 2; } 40 accel_args=(-accel kvm -cpu host); machine="virt,gic-version=3,iommu=smmuv3" ;; 41 *) echo "usage: $0 [aarch64|x86_64] [tcg|kvm]"; exit 2 ;; 42 esac 43 dev="disable-legacy=on,iommu_platform=on" # behind the smmuv3: DMA confined 44 out="${repo_root}/target/native-kernel" 45 cross="" 46 if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi 47 make -s -C native/kernel CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" full CK_BOOT_SHOW=1 >/dev/null 48 efi="${out}/full-boot-show/BOOTAA64.EFI" 49 screen_line='^virtio_gpu: screen ' 50 ;; 51 x86_64) 52 code_fd="${OVMF_CODE:-/usr/share/OVMF/OVMF_CODE_4M.fd}" 53 vars_fd="${OVMF_VARS:-/usr/share/OVMF/OVMF_VARS_4M.fd}" 54 qemu=qemu-system-x86_64 55 [[ "${accel}" == tcg ]] || { echo "NOT_RUN x86_64 runs under tcg on this host"; echo "AIENOS_CK_BOOT_SHOW: NOT_RUN"; exit 2; } 56 accel_args=(-accel tcg -cpu max); machine=q35 57 out="${repo_root}/target/native-kernel-imac-kernel" 58 cross="" 59 if [ "$(uname -m)" != "x86_64" ]; then cross="x86_64-linux-gnu-"; fi 60 make -s -C native/kernel X86_CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" imac-kernel CK_BOOT_SHOW=1 >/dev/null 61 efi="${out}/IMACKERN-BOOT-SHOW.EFI" 62 screen_line='^screen: gop ' 63 ;; 64 *) echo "usage: $0 [aarch64|x86_64] [tcg|kvm]"; exit 2 ;; 65 esac 66 command -v "${qemu}" >/dev/null || { echo "${qemu} not installed"; echo "AIENOS_CK_BOOT_SHOW: NOT_RUN"; exit 2; } 67 [[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "UEFI firmware not found"; echo "AIENOS_CK_BOOT_SHOW: NOT_RUN"; exit 2; } 68 make -s -C native/kernel OUT="${out}" gpt-image >/dev/null 69 check="${out}/host/boot_show_check" 70 mkdir -p "${out}/host" 71 cc -std=gnu11 -O2 -Wall -Wextra -Werror -o "${check}" native/kernel/ui/tools/boot_show_check.c native/kernel/ui/chirp.c -lm 72 73 . "${repo_root}/scripts/lib_gate_hold.sh" 74 if ! gh_quiet_check || ! gh_lock_take "qemu_ck_boot_show_test" "${AIENOS_GATE_MINUTES:-30}"; then 75 echo "NOT_RUN ${gh_why}" 76 echo "AIENOS_CK_BOOT_SHOW: NOT_RUN" 77 exit 3 78 fi 79 top="$(mktemp -d)" 80 qpid="" 81 cleanup() { 82 if [[ -n "${qpid}" ]]; then kill "${qpid}" 2>/dev/null || true; wait "${qpid}" 2>/dev/null || true; fi 83 rm -rf "${top}" 84 gh_lock_release 85 } 86 trap cleanup EXIT 87 88 keep="${repo_root}/target/boot-show/${arch}-${accel}" 89 mkdir -p "${keep}" 90 image="${top}/nvme.img" 91 "${out}/host/ck_gpt_image" create "${image}" 512 64 aienos-middle >/dev/null 92 mkdir -p "${top}/esp/EFI/BOOT" "${top}/esp/EFI/AIENOS" 93 touch "${top}/esp/EFI/AIENOS/BOOTREPORT.TXT" 94 if [[ "${arch}" == aarch64 ]]; then cp "${efi}" "${top}/esp/EFI/BOOT/BOOTAA64.EFI"; else cp "${efi}" "${top}/esp/EFI/BOOT/BOOTX64.EFI"; fi 95 cp "${vars_fd}" "${top}/vars.fd" 96 log="${top}/serial.log" 97 if [[ "${arch}" == aarch64 ]]; then 98 disks=(-drive if=none,id=esp,format=raw,file=fat:rw:"${top}/esp" -device virtio-blk-pci,drive=esp 99 -drive if=none,id=nvme0,format=raw,file="${image}" -device nvme,drive=nvme0,serial=aienos-boot-show) 100 screen=(-device "virtio-gpu-pci,${dev}") 101 mem=2048 102 else 103 disks=(-drive if=none,id=esp,format=raw,file=fat:rw:"${top}/esp" -device ide-hd,drive=esp,bus=ide.0) 104 screen=(-device virtio-vga) 105 mem=1024 106 fi 107 "${qemu}" -M "${machine}" "${accel_args[@]}" -smp 4 -m "${mem}" \ 108 -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ 109 -drive if=pflash,format=raw,file="${top}/vars.fd" \ 110 "${disks[@]}" "${screen[@]}" \ 111 -audiodev "wav,id=snd0,path=${top}/chirp.wav,out.frequency=48000,out.channels=2,out.format=s16" \ 112 -device "virtio-sound-pci,audiodev=snd0,${dev}" \ 113 -display none -nic none -serial "file:${log}" -qmp "unix:${top}/qmp.sock,server,nowait" -no-reboot & 114 qpid=$! 115 116 qmp() { printf '{"execute":"qmp_capabilities"}\n%s\n' "$1" | socat - "UNIX-CONNECT:${top}/qmp.sock" >/dev/null 2>&1 || true; } 117 wait_for() { # pattern, seconds 118 local end=$((SECONDS + $2)) 119 while ((SECONDS < end)); do 120 grep -qE "$1" "${log}" 2>/dev/null && return 0 121 kill -0 "${qpid}" 2>/dev/null || return 1 122 sleep 0.2 123 done 124 return 1 125 } 126 fail=0 127 ok() { echo "PASS $*"; } 128 bad() { echo "FAIL $*"; fail=1; } 129 130 if wait_for "${screen_line}" "${AIENOS_QEMU_TIMEOUT:-300}"; then 131 ok "$(grep -m1 "${screen_line}" "${log}")" 132 if [[ "${arch}" == aarch64 ]]; then 133 grep -m1 '^dma_gate: virtio_gpu granted' "${log}" >/dev/null && ok "$(grep -m1 '^dma_gate: virtio_gpu granted' "${log}")" || 134 bad "virtio_gpu DMA not confined" 135 fi 136 wait_for '^boot-show: the night starts' 120 || bad "the night never started" 137 sleep 8 # 8 s into the night: both holes are circling and the stars are out 138 qmp "{\"execute\":\"screendump\",\"arguments\":{\"filename\":\"${top}/night.ppm\"}}" 139 else 140 bad "no screen line (${screen_line})" 141 grep -E '^(virtio_gpu|dma_gate|boot-show|stage)' "${log}" | head -20 || true 142 fi 143 if wait_for '^boot-show: [0-9]+x[0-9]+ via' 120; then 144 line="$(grep -m1 -E '^boot-show: [0-9]+x[0-9]+ via' "${log}")" 145 ok "${line}" 146 [[ "${line}" =~ "in 15200 ms" && "${line}" =~ "of 912 slots" ]] || bad "the night did not run its 15.2 s" 147 else 148 bad "no boot-show receipt line" 149 grep -E '^(boot-show|virtio|sound)' "${log}" | head -20 || true 150 fi 151 if wait_for '^(sound: |virtio_snd: )' 30 && grep -q '^sound: virtio played the chirp' "${log}"; then 152 sl="$(grep -m1 '^sound: virtio played' "${log}")" 153 ok "${sl}" 154 [[ "${sl}" =~ ", 0 refused, stop ok" ]] || bad "sound stream refused or not stopped cleanly" 155 else 156 bad "no virtio sound played line" 157 grep -E '^(sound|virtio_snd|dma_gate: virtio_snd)' "${log}" | head -10 || true 158 fi 159 qmp '{"execute":"quit"}' 160 wait "${qpid}" 2>/dev/null || true 161 qpid="" 162 cp "${log}" "${keep}/serial.log" 163 [[ -f "${top}/chirp.wav" ]] && cp "${top}/chirp.wav" "${keep}/chirp.wav" 164 if [[ -f "${top}/night.ppm" ]]; then 165 cp "${top}/night.ppm" "${keep}/night.ppm" 166 if r="$("${check}" ppm "${top}/night.ppm")"; then ok "${r} (screendump 8 s into the night)"; else bad "${r}"; fi 167 else 168 bad "no screendump" 169 fi 170 if r="$("${check}" wav "${top}/chirp.wav" 2>&1)"; then ok "${r}"; else bad "${r}"; fi 171 echo "kept: ${keep} (serial.log, night.ppm, chirp.wav)" 172 if ((fail)); then echo "AIENOS_CK_BOOT_SHOW: FAIL"; exit 1; fi 173 echo "AIENOS_CK_BOOT_SHOW: PASS"