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_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.
27set -euo pipefail
28
29repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
30cd "${repo_root}"
31
32code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}"
33vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}"
34command -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
37boot_timeout="${AIENOS_QEMU_TIMEOUT:-180}"
38img_bytes=67108864
39lba_bytes=4096
40bounds_lba=$(( img_bytes / lba_bytes ))
41machine="virt,virtualization=on,gic-version=3,iommu=smmuv3"
42target_dir="target/qemu-nvme-atomicity"
43
44commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)"
45AIENOS_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
49work="$(mktemp -d)"
50qemu_pid=""
51cleanup() { [[ -n "${qemu_pid}" ]] && kill "${qemu_pid}" 2>/dev/null || true; rm -rf "${work}"; }
52trap cleanup EXIT
53mkdir -p "${work}/esp/EFI/BOOT" "${work}/esp/EFI/AIENOS"
54touch "${work}/esp/EFI/AIENOS/BOOTREPORT.TXT"
55cp "${target_dir}/aarch64-unknown-uefi/release/aienos-handoff.efi" "${work}/esp/EFI/BOOT/BOOTAA64.EFI"
56
57image="${work}/nvme.img"
58truncate -s "${img_bytes}" "${image}"
59echo "nvme image: ${img_bytes} bytes, ${bounds_lba} x ${lba_bytes} B LBAs"
60
61cp "${vars_fd}" "${work}/vars.fd"
62rm -f "${work}/serial.log"
63qemu-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 &
73qemu_pid=$!
74
75deadline=$(( $(date +%s) + boot_timeout ))
76while (( $(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
79done
80kill "${qemu_pid}" 2>/dev/null || true
81wait "${qemu_pid}" 2>/dev/null || true
82
83serial="$(tr -d '\r' <"${work}/serial.log" 2>/dev/null || true)"
84failed=0
85check() { if printf '%s' "${serial}" | grep -q -- "$2"; then echo "PASS $1"; else echo "FAIL $1"; failed=1; fi; }
86
87echo "---- observed ----"
88printf '%s\n' "${serial}" | grep -E 'NVME_IDENTIFY_QEMU|NVME_GEOMETRY_QEMU|NVME_ATOMICITY_IDENTIFY_QEMU|NVME_STORE_ROOT_ATOMICITY_QEMU' || true
89echo "-------------------"
90check "controller and namespace identify completed" "NVME_IDENTIFY_QEMU: PASS"
91check "namespace geometry is 4096-byte LBA" "NVME_GEOMETRY_QEMU: PASS (nsid=1 block_count=${bounds_lba} block_size=${lba_bytes})"
92check "atomicity Identify observed with 4096-byte LBA" "NVME_ATOMICITY_IDENTIFY_QEMU: block_size=${lba_bytes} lbads=12"
93check "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; }