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_continuity_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_continuity_test.sh` 230 lines ยท 10131 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 # M4 continuity qualification in QEMU (ADR 0016, Proposed): the same AIEN 18 # identity and committed memory survive cold restarts over System Store v1 on 19 # the native NVMe driver, and no boot path ever mints a replacement identity. 20 # 21 # Geometry: 4096-byte LBA (atomic-root qualified namespace). Every boot is a 22 # fresh QEMU process (cold restart); only the NVMe image persists. 23 # 24 # Emits CONTINUITY_QEMU: PASS only when every step passes. QEMU only; no 25 # Machine 1 claim. The continuity encodings are format version 0 (Proposed). 26 set -uo pipefail 27 28 repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 29 cd "${repo_root}" 30 31 code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" 32 vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" 33 command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; exit 2; } 34 [[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "AAVMF firmware not found"; exit 2; } 35 36 boot_timeout="${AIENOS_QEMU_TIMEOUT:-180}" 37 img_bytes=`67108864` 38 lba_bytes=4096 39 cfg_offset=$(( 32 * lba_bytes )) 40 store_offset=$(( 64 * lba_bytes )) 41 machine="virt,virtualization=on,gic-version=3,iommu=smmuv3" 42 target_dir="target/qemu-continuity" 43 44 echo "=== Building aienos-handoff (continuity-qual) and aienos-store-tool ===" 45 commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" 46 git diff --quiet HEAD 2>/dev/null || commit="${commit}-dirty" 47 AIENOS_COMMIT="${commit}" AIENOS_RESTART_SECS=1 cargo build --quiet --release \ 48 -p aienos-boot --target aarch64-unknown-uefi --features continuity-qual --bin aienos-handoff \ 49 --target-dir "${target_dir}" || { echo "build failed"; exit 2; } 50 cargo build --quiet --release -p aienos-store-tool || { echo "store tool build failed"; exit 2; } 51 tool="target/release/aienos-store-tool" 52 53 work="$(mktemp -d)" 54 qemu_pid="" 55 cleanup() { [[ -n "${qemu_pid}" ]] && kill -9 "${qemu_pid}" 2>/dev/null || true; rm -rf "${work}"; } 56 trap cleanup EXIT 57 mkdir -p "${work}/esp/EFI/BOOT" "${work}/esp/EFI/AIENOS" 58 touch "${work}/esp/EFI/AIENOS/BOOTREPORT.TXT" 59 cp "${target_dir}/aarch64-unknown-uefi/release/aienos-handoff.efi" "${work}/esp/EFI/BOOT/BOOTAA64.EFI" 60 61 image="${work}/nvme.img" 62 serial="${work}/serial.log" 63 fail=0 64 65 fresh_image() { rm -f "${image}"; truncate -s "${img_bytes}" "${image}"; } 66 write_cfg() { "${tool}" cfg "${image}" "${cfg_offset}" "$1" 0 >/dev/null || { echo "cfg write failed"; exit 2; }; } 67 digest() { sha256sum "${image}" | cut -d' ' -f1; } 68 pass() { echo "PASS $1"; } 69 bad() { echo "FAIL $1"; fail=1; } 70 71 # run_qemu [kill]: one cold boot; returns when QEMU exits (or is killed). 72 run_qemu() { 73 cp -f "${vars_fd}" "${work}/vars.fd" 74 rm -f "${serial}" 75 qemu-system-aarch64 \ 76 -M "${machine}" -accel tcg,thread=single -cpu max -smp 4 -m 2048 \ 77 -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ 78 -drive if=pflash,format=raw,file="${work}/vars.fd" \ 79 -drive if=none,id=esp,format=raw,file=fat:rw:"${work}/esp" \ 80 -device virtio-blk-pci,drive=esp \ 81 -drive if=none,id=nvme0,format=raw,file="${image}" \ 82 -device nvme,drive=nvme0,serial=aienos-continuity,logical_block_size=${lba_bytes},physical_block_size=${lba_bytes} \ 83 -display none -nic none -serial file:"${serial}" -no-reboot & 84 qemu_pid=$! 85 local deadline=$(( $(date +%s) + boot_timeout )) 86 while (( $(date +%s) < deadline )); do 87 grep -q -- "$1" "${serial}" 2>/dev/null && break 88 kill -0 "${qemu_pid}" 2>/dev/null || break 89 sleep 0.1 90 done 91 if [[ "${2:-}" == "kill" ]]; then 92 kill -9 "${qemu_pid}" 2>/dev/null || true 93 fi 94 wait "${qemu_pid}" 2>/dev/null || true 95 qemu_pid="" 96 } 97 98 # boot_mode : cfg + cold boot until the guest resets. "Writes nothing" 99 # checks hash the image after write_cfg, so only guest writes can change it. 100 boot_mode() { write_cfg "$1"; run_qemu "AIENOS_NEVER_PRINTED_MARKER"; } 101 102 # cont : the last "CONTINUITY: WORD ..." line of this boot (empty if none). 103 cont() { tr -d '\r' <"${serial}" | grep -oE "CONTINUITY: $1( .*)?$" | tail -1; } 104 field() { sed -nE "s/.* $1=([0-9a-f]+).*/\1/p" <<<"$2"; } 105 106 echo "=== 1. Refusals: no boot path mints an identity ===" 107 fresh_image 108 write_cfg 6; before=$(digest); run_qemu "AIENOS_NEVER_PRINTED_MARKER"; after=$(digest) 109 if [[ -n "$(cont 'STOP \(store Unformatted\)')" && "${before}" == "${after}" ]]; then 110 pass "resume on blank media stops (store Unformatted) and writes nothing" 111 else 112 bad "resume on blank media: $(tr -d '\r' <"${serial}" | grep 'CONTINUITY:' | head -2)" 113 fi 114 115 fresh_image 116 write_cfg 1; run_qemu "STORE_CHECKPOINT_QEMU" # formatted Store with data, no identity 117 grep -q "STORE_CHECKPOINT_QEMU: PASS" "${serial}" || bad "could not build a formatted, unprovisioned store" 118 write_cfg 6; before=$(digest); run_qemu "AIENOS_NEVER_PRINTED_MARKER"; after=$(digest) 119 if [[ -n "$(cont UNPROVISIONED)" && "${before}" == "${after}" ]]; then 120 pass "resume on a formatted but unprovisioned store stops UNPROVISIONED and writes nothing" 121 else 122 bad "unprovisioned resume: $(tr -d '\r' <"${serial}" | grep 'CONTINUITY:' | head -2)" 123 fi 124 125 echo "=== 2. Provisioning happens once ===" 126 fresh_image 127 boot_mode 5 128 line=$(cont PROVISIONED) 129 agent=$(field agent "${line}") 130 if [[ ${#agent} == 64 && "${line}" == *"incarnation=1 sequence=1 cortex=0 branches=1 "* ]]; then 131 pass "provisioned agent ${agent:0:16}... (incarnation 1, empty memory, root branch)" 132 else 133 bad "provision: ${line:-$(tr -d '\r' <"${serial}" | grep 'CONTINUITY:' | head -2)}" 134 fi 135 provisioned_img="${work}/provisioned.img"; cp "${image}" "${provisioned_img}" 136 137 write_cfg 5; before=$(digest); run_qemu "AIENOS_NEVER_PRINTED_MARKER"; after=$(digest) 138 if [[ -n "$(cont 'STOP \(AlreadyProvisioned\)')" && "${before}" == "${after}" ]]; then 139 pass "a second provisioning request is refused and writes nothing" 140 else 141 bad "re-provision: $(tr -d '\r' <"${serial}" | grep 'CONTINUITY:' | head -2)" 142 fi 143 144 cp "${image}" "${work}/keep.img"; fresh_image; boot_mode 5 145 other=$(field agent "$(cont PROVISIONED)") 146 if [[ ${#other} == 64 && "${other}" != "${agent}" ]]; then 147 pass "independent provisioning draws a different identity from RNDR" 148 else 149 bad "second fresh provisioning gave '${other}'" 150 fi 151 cp "${work}/keep.img" "${image}" 152 153 echo "=== 3. Memory and lineage survive cold restarts ===" 154 boot_mode 7 155 r=$(cont RESUMED); m=$(cont REMEMBERED) 156 memory=$(field memory "${m}") 157 if [[ "$(field agent "${r}")" == "${agent}" && "${r}" == *"incarnation=2 sequence=2 cortex=0 branches=1 "* && \ 158 "$(field agent "${m}")" == "${agent}" && "${m}" == *"incarnation=2 sequence=3 cortex=1 branches=2 "* ]]; then 159 pass "resume + remember: incarnation 2, one Cortex fact and one forked branch committed" 160 else 161 bad "remember: resumed='${r}' remembered='${m}'" 162 fi 163 164 inc=3; seq=4 165 for n in 1 2; do 166 boot_mode 6 167 r=$(cont RESUMED) 168 if [[ "$(field agent "${r}")" == "${agent}" && "$(field memory "${r}")" == "${memory}" && \ 169 "${r}" == *"incarnation=${inc} sequence=${seq} cortex=1 branches=2 "* ]]; then 170 pass "cold restart ${n}: same agent, same memory ${memory}, same lineage, incarnation ${inc}" 171 else 172 bad "cold restart ${n}: '${r}'" 173 fi 174 inc=$(( inc + 1 )); seq=$(( seq + 1 )) 175 done 176 base="${work}/remembered.img"; cp "${image}" "${base}" 177 178 echo "=== 4. SIGKILL at every Store checkpoint of a continuity commit ===" 179 cp "${base}" "${image}"; boot_mode 8 180 new_memory=$(field memory "$(cont COMMITTED)") 181 [[ -n "${new_memory}" && "${new_memory}" != "${memory}" ]] || bad "reference commit did not produce new memory" 182 checkpoints=(before_first_write after_payloads after_catalog after_commit_record \ 183 after_first_flush after_superblock_write after_final_flush) 184 for cp in "${checkpoints[@]}"; do 185 cp "${base}" "${image}"; write_cfg 8 186 run_qemu "CHECKPOINT: ${cp}" kill 187 saw=0; grep -q -- "CHECKPOINT: ${cp}" "${serial}" && saw=1 188 boot_mode 6 189 r=$(cont RESUMED); got=$(field memory "${r}") 190 case "${cp}" in 191 after_final_flush) want="${new_memory}" ;; 192 after_superblock_write) want="either" ;; 193 *) want="${memory}" ;; 194 esac 195 ok=0 196 if [[ "${saw}" == 1 && "$(field agent "${r}")" == "${agent}" ]]; then 197 if [[ "${want}" == either ]]; then 198 [[ "${got}" == "${memory}" || "${got}" == "${new_memory}" ]] && ok=1 199 else 200 [[ "${got}" == "${want}" ]] && ok=1 201 fi 202 fi 203 state="old"; [[ "${got}" == "${new_memory}" ]] && state="new" 204 if [[ "${ok}" == 1 ]]; then 205 pass "kill at ${cp}: same agent, ${state} memory" 206 else 207 bad "kill at ${cp}: saw=${saw} '${r}'" 208 fi 209 done 210 211 echo "=== 5. Degraded mount resumes read-only ===" 212 cp "${base}" "${image}" 213 "${tool}" inject "${image}" "${store_offset}" inactive seeded_garbage >/dev/null || bad "inject failed" 214 write_cfg 6; before=$(digest); run_qemu "AIENOS_NEVER_PRINTED_MARKER"; after=$(digest) 215 r=$(cont RESUMED_READONLY) 216 if [[ "$(field agent "${r}")" == "${agent}" && "$(field memory "${r}")" == "${memory}" && "${before}" == "${after}" ]]; then 217 pass "malformed peer superblock: same agent and memory, read-only, nothing written" 218 else 219 bad "degraded: '${r:-$(tr -d '\r' <"${serial}" | grep 'CONTINUITY:' | head -2)}'" 220 fi 221 222 echo 223 echo "=== Summary (commit ${commit}) ===" 224 if [[ "${fail}" == 0 ]]; then 225 echo "CONTINUITY_QEMU: PASS" 226 else 227 echo "CONTINUITY_QEMU: FAIL" 228 exit 1 229 fi 230 echo "CONTINUITY_NATIVE: NOT CLAIMED (Machine 1 waits on TRUST-1)"