aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / scripts / qemu_native_nvme_test.sh
| 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_native_nvme_test.sh -- boot a bare-metal AArch64 payload that drives |
| 18 | # QEMU's emulated NVMe controller with the C driver in native/disk. |
| 19 | # |
| 20 | # Two namespaces on one controller: nsid 1 with 512 B LBAs, nsid 2 with |
| 21 | # 4 KiB LBAs. The payload writes, reads back, flushes, checks range refusal, |
| 22 | # resets the controller and checks the data is still there. |
| 23 | # |
| 24 | # Verdict line: AIENOS_STORE_NVME_QEMU: PASS | FAIL | NOT_RUN |
| 25 | # QEMU is an emulator. PASS here qualifies nothing about physical hardware. |
| 26 | # |
| 27 | # Respects the shared quiet flag: refuses to run (NOT_RUN, exit 0) while |
| 28 | # ~/workspace/.spark-quiet exists, which it only reads, or while another gate |
| 29 | # holds the QEMU gate lock (scripts/lib_gate_hold.sh, aienos#278). |
| 30 | set -euo pipefail |
| 31 | |
| 32 | repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 33 | qemu_timeout="${AIENOS_QEMU_TIMEOUT:-60}" |
| 34 | out_rel="out" |
| 35 | out="${repo}/native/disk/qemu/${out_rel}" |
| 36 | . "${repo}/scripts/lib_gate_hold.sh" |
| 37 | |
| 38 | if ! gh_quiet_check; then |
| 39 | echo "NOT_RUN ${gh_why}" |
| 40 | echo "AIENOS_STORE_NVME_QEMU: NOT_RUN" |
| 41 | exit 0 |
| 42 | fi |
| 43 | for tool in qemu-system-aarch64 timeout make; do |
| 44 | if ! command -v "${tool}" >/dev/null 2>&1; then |
| 45 | echo "required tool ${tool} not found" |
| 46 | echo "AIENOS_STORE_NVME_QEMU: NOT_RUN" |
| 47 | exit 0 |
| 48 | fi |
| 49 | done |
| 50 | |
| 51 | # One QEMU gate at a time; the gate lock record is removed only if it is still |
| 52 | # this run's own (never another run's hold). |
| 53 | if ! gh_lock_take qemu_native_nvme_test "${AIENOS_GATE_MINUTES:-60}"; then |
| 54 | echo "NOT_RUN ${gh_why}" |
| 55 | echo "AIENOS_STORE_NVME_QEMU: NOT_RUN" |
| 56 | exit 0 |
| 57 | fi |
| 58 | cleanup() { gh_lock_release; } |
| 59 | trap cleanup EXIT |
| 60 | |
| 61 | cross="" |
| 62 | if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi |
| 63 | if ! make -s -C "${repo}/native/disk/qemu" OUT="${out_rel}" \ |
| 64 | CC="${cross}gcc" LD="${cross}ld" NM="${cross}nm" >"${repo}/native/disk/qemu/build.log" 2>&1; then |
| 65 | tail -20 "${repo}/native/disk/qemu/build.log" |
| 66 | echo "payload build failed" |
| 67 | echo "AIENOS_STORE_NVME_QEMU: FAIL" |
| 68 | exit 1 |
| 69 | fi |
| 70 | rm -f "${repo}/native/disk/qemu/build.log" |
| 71 | |
| 72 | img1="${out}/ns1.img" |
| 73 | img2="${out}/ns2.img" |
| 74 | log="${out}/qemu.log" |
| 75 | rm -f "${img1}" "${img2}" "${log}" |
| 76 | truncate -s 64M "${img1}" |
| 77 | truncate -s 64M "${img2}" |
| 78 | |
| 79 | set +e |
| 80 | timeout --kill-after=5 "${qemu_timeout}" qemu-system-aarch64 \ |
| 81 | -M virt,highmem=off -cpu cortex-a57 -m 256M -smp 1 \ |
| 82 | -nographic -monitor none -serial stdio -no-reboot \ |
| 83 | -kernel "${out}/nvme_payload.elf" \ |
| 84 | -drive "file=${img1},if=none,id=nvm1,format=raw" \ |
| 85 | -drive "file=${img2},if=none,id=nvm2,format=raw" \ |
| 86 | -device nvme,id=nvme0,serial=aienos-lane11 \ |
| 87 | -device nvme-ns,drive=nvm1,bus=nvme0,nsid=1,logical_block_size=512,physical_block_size=512 \ |
| 88 | -device nvme-ns,drive=nvm2,bus=nvme0,nsid=2,logical_block_size=4096,physical_block_size=4096 \ |
| 89 | </dev/null >"${log}" 2>&1 |
| 90 | qrc=$? |
| 91 | set -e |
| 92 | |
| 93 | tr -d '\r' <"${log}" | grep -v '^$' | tail -25 |
| 94 | if [ "${qrc}" -eq 124 ] || [ "${qrc}" -eq 137 ]; then |
| 95 | echo "QEMU did not power off within ${qemu_timeout} s" |
| 96 | fi |
| 97 | if tr -d '\r' <"${log}" | grep -qx 'NVME_QEMU_PAYLOAD: PASS' && [ "${qrc}" -eq 0 ]; then |
| 98 | echo "(QEMU emulated NVMe only; not a physical-hardware qualification)" |
| 99 | echo "AIENOS_STORE_NVME_QEMU: PASS" |
| 100 | exit 0 |
| 101 | fi |
| 102 | echo "AIENOS_STORE_NVME_QEMU: FAIL" |
| 103 | exit 1 |