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_nvme_atomicity_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_nvme_atomicity_test.sh` 95 lines ยท 4517 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 # QEMU NVMe power-fail atomicity qualification for the System Store root write. 18 # 19 # Configures a disposable namespace with a 4096-byte logical block size and 20 # requires the guest to observe block_size=4096 (lbads=12) with a power-fail 21 # atomic guarantee covering the single-block Store superblock: 22 # NVME_STORE_ROOT_ATOMICITY_QEMU: PASS 23 # 24 # This does not weaken the Store contract: the 4096-byte Store unit is one 25 # logical block on this namespace. It is emulator qualification, not Machine 1 26 # evidence. Read/write durability markers are not asserted here. 27 set -euo pipefail 28 29 repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 30 cd "${repo_root}" 31 32 code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" 33 vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" 34 command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; exit 2; } 35 [[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "AAVMF firmware not found"; exit 2; } 36 37 boot_timeout="${AIENOS_QEMU_TIMEOUT:-180}" 38 img_bytes=`67108864` 39 lba_bytes=4096 40 bounds_lba=$(( img_bytes / lba_bytes )) 41 machine="virt,virtualization=on,gic-version=3,iommu=smmuv3" 42 target_dir="target/qemu-nvme-atomicity" 43 44 commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" 45 AIENOS_COMMIT="${commit}" AIENOS_RESTART_SECS=1 cargo build --quiet --release \ 46 -p aienos-boot --target aarch64-unknown-uefi --features nvme-write --bin aienos-handoff \ 47 --target-dir "${target_dir}" 48 49 work="$(mktemp -d)" 50 qemu_pid="" 51 cleanup() { [[ -n "${qemu_pid}" ]] && kill "${qemu_pid}" 2>/dev/null || true; rm -rf "${work}"; } 52 trap cleanup EXIT 53 mkdir -p "${work}/esp/EFI/BOOT" "${work}/esp/EFI/AIENOS" 54 touch "${work}/esp/EFI/AIENOS/BOOTREPORT.TXT" 55 cp "${target_dir}/aarch64-unknown-uefi/release/aienos-handoff.efi" "${work}/esp/EFI/BOOT/BOOTAA64.EFI" 56 57 image="${work}/nvme.img" 58 truncate -s "${img_bytes}" "${image}" 59 echo "nvme image: ${img_bytes} bytes, ${bounds_lba} x ${lba_bytes} B LBAs" 60 61 cp "${vars_fd}" "${work}/vars.fd" 62 rm -f "${work}/serial.log" 63 qemu-system-aarch64 \ 64 -M "${machine}" -accel tcg,thread=single -cpu max -smp 4 -m 2048 \ 65 -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ 66 -drive if=pflash,format=raw,file="${work}/vars.fd" \ 67 -drive if=none,id=esp,format=raw,file=fat:rw:"${work}/esp" \ 68 -device virtio-blk-pci,drive=esp \ 69 -drive if=none,id=nvme0,format=raw,file="${image}" \ 70 -device nvme,drive=nvme0,serial=aienos-nvme-atomicity,logical_block_size=${lba_bytes},physical_block_size=${lba_bytes} \ 71 -device ramfb -display none -nic none \ 72 -serial file:"${work}/serial.log" -no-reboot & 73 qemu_pid=$! 74 75 deadline=$(( $(date +%s) + boot_timeout )) 76 while (( $(date +%s) < deadline )) && kill -0 "${qemu_pid}" 2>/dev/null; do 77 grep -q -- "NVME_STORE_ROOT_ATOMICITY_QEMU" "${work}/serial.log" 2>/dev/null && break 78 sleep 0.2 79 done 80 kill "${qemu_pid}" 2>/dev/null || true 81 wait "${qemu_pid}" 2>/dev/null || true 82 83 serial="$(tr -d '\r' <"${work}/serial.log" 2>/dev/null || true)" 84 failed=0 85 check() { if printf '%s' "${serial}" | grep -q -- "$2"; then echo "PASS $1"; else echo "FAIL $1"; failed=1; fi; } 86 87 echo "---- observed ----" 88 printf '%s\n' "${serial}" | grep -E 'NVME_IDENTIFY_QEMU|NVME_GEOMETRY_QEMU|NVME_ATOMICITY_IDENTIFY_QEMU|NVME_STORE_ROOT_ATOMICITY_QEMU' || true 89 echo "-------------------" 90 check "controller and namespace identify completed" "NVME_IDENTIFY_QEMU: PASS" 91 check "namespace geometry is 4096-byte LBA" "NVME_GEOMETRY_QEMU: PASS (nsid=1 block_count=${bounds_lba} block_size=${lba_bytes})" 92 check "atomicity Identify observed with 4096-byte LBA" "NVME_ATOMICITY_IDENTIFY_QEMU: block_size=${lba_bytes} lbads=12" 93 check "Store root write is power-fail atomic and boundary-safe" "NVME_STORE_ROOT_ATOMICITY_QEMU: PASS" 94 95 [[ "${failed}" == 0 ]] && echo "QEMU_NVME_ATOMICITY_4K: PASS" || { echo "QEMU_NVME_ATOMICITY_4K: FAIL"; exit 1; }