diff --git a/crates/aienos-boot/Cargo.toml b/crates/aienos-boot/Cargo.toml index 1782ac25..6baaedef 100644 --- a/crates/aienos-boot/Cargo.toml +++ b/crates/aienos-boot/Cargo.toml @@ -24,6 +24,9 @@ nvme-read = ["handoff"] # P3 candidate: native NVMe write + flush qualification on top of nvme-read. # Only scripts/qemu_nvme_rw_test.sh enables it; hardware staging never does. nvme-write = ["nvme-read"] +# P3 candidate: Store-over-NVMe qualification (test-only). QEMU only. +# scripts/qemu_store_crash_test.sh enables it; hardware staging never does. +store-qual = ["nvme-write"] # SEED-0B qualification build (ADR 0014 ยง6): the kernel trusts the public, # TEST ONLY RFC 8032 qualification key in addition to the (empty) production # set, and every report says so. Without it, every artifact candidate is diff --git a/crates/aienos-boot/src/handoff.rs b/crates/aienos-boot/src/handoff.rs index e1377af1..bb9ec4ed 100644 --- a/crates/aienos-boot/src/handoff.rs +++ b/crates/aienos-boot/src/handoff.rs @@ -560,6 +560,9 @@ mod usb_keyboard; #[cfg(feature = "nvme-read")] mod nvme_read; +#[cfg(feature = "store-qual")] +mod store_qual; + /// Commit this image was built from; `scripts/stage_one_time_boot.sh` sets it. const COMMIT: &str = match option_env!("AIENOS_COMMIT") { Some(commit) => commit, diff --git a/crates/aienos-boot/src/nvme_read.rs b/crates/aienos-boot/src/nvme_read.rs index 7d247b59..b9198d31 100644 --- a/crates/aienos-boot/src/nvme_read.rs +++ b/crates/aienos-boot/src/nvme_read.rs @@ -15,6 +15,10 @@ //! any SMMU or driver setup, and [`run`] sets it again only when //! [`dma_gate::dma_grant`] allows it. +#[cfg(feature = "store-qual")] +use crate::store_qual::{ + genesis_units, BoundedNvme, CONFIG_LBA, MODE_VERIFY, STORE_BASE_LBA, STORE_REGION_BLOCKS, +}; use aienos_kernel::acpi::{self, EcamWindow}; use aienos_kernel::arch::aarch64::{ clean_dcache_range, clean_invalidate_dcache_range, counter_frequency_hz, counter_ticks, MmioReg, @@ -625,6 +629,9 @@ pub fn run( #[cfg(feature = "nvme-write")] run_write_phase(screen, &mut controller, block_count); + #[cfg(feature = "store-qual")] + run_store_phase(screen, controller, block_count); + revoke_dma(screen, &mut ecam, &at); } @@ -775,3 +782,227 @@ fn report_smmu_fault( say(screen, entry.as_str()); } } + +// --------------------------------------------------------------------------- +// Store-over-NVMe qualification (test-only, `store-qual`). +// +// Chain: NvmeController -> BoundedNvme -> StoreDeviceAdapter -> Store. +// Requires the atomic-root predicate to PASS for the 4096-byte geometry. +// Mode is selected by a control block at STORE region CONFIG_LBA. +// --------------------------------------------------------------------------- + +#[cfg(feature = "store-qual")] +type QualController = NvmeController; + +#[cfg(feature = "store-qual")] +type QualAdapter = aienos_kernel::store::device::StoreDeviceAdapter< + BoundedNvme, +>; + +#[cfg(feature = "store-qual")] +fn qualify_fail(screen: &mut Option, reason: &str) { + let mut l = aienos_kernel::report::ReportBuf::<192>::new(); + let _ = writeln!(l, "STORE_NVME_INTEGRATION_QEMU: FAIL ({reason})"); + say(screen, l.as_str()); +} + +#[cfg(feature = "store-qual")] +fn run_store_phase(screen: &mut Option, mut controller: QualController, block_count: u64) { + use aienos_kernel::nvme::atomicity::AtomicityDecision; + use aienos_kernel::store::checkpoint::Checkpoint; + use aienos_kernel::store::engine::{ObjectInput, Store}; + + // Qualified geometry: the 4096-byte Store unit must be one logical block. + if controller.block_size() != 4096 { + qualify_fail(screen, "geometry is not 4096-byte LBA"); + return; + } + + // Atomic-root predicate must PASS, else fail closed. + let atomic = |d| matches!(d, AtomicityDecision::Atomic { .. }); + let ok = controller + .atomicity() + .map(|a| atomic(a.store_root_decision(0)) && atomic(a.store_root_decision(1))) + .unwrap_or(false); + if !ok { + qualify_fail(screen, "atomic-root predicate"); + return; + } + + // Control block. + let mut cfg = [0u8; 4096]; + if controller.read_blocks(CONFIG_LBA, &mut cfg).is_err() { + qualify_fail(screen, "control block read"); + return; + } + let mode = cfg[0]; + let settle = cfg[1]; + + if STORE_BASE_LBA + .checked_add(STORE_REGION_BLOCKS) + .is_none_or(|end| end > block_count) + { + qualify_fail(screen, "region outside namespace"); + return; + } + + let bounded = BoundedNvme::new(controller, STORE_BASE_LBA, STORE_REGION_BLOCKS); + let mut adapter = match aienos_kernel::store::device::StoreDeviceAdapter::new(bounded) { + Ok(a) => a, + Err(e) => { + let mut l = aienos_kernel::report::ReportBuf::<192>::new(); + let _ = writeln!(l, "STORE_NVME_INTEGRATION_QEMU: FAIL (adapter {e:?})"); + say(screen, l.as_str()); + return; + } + }; + let region_units = adapter.region_units(); + + if mode == MODE_VERIFY { + verify_reopen(screen, adapter, settle); + return; + } + + // Provision canonical genesis if the region is unformatted. + let mut probe = [0u8; 4096]; + let provisioned = adapter.read_unit(0, &mut probe).is_ok() && probe.iter().any(|b| *b != 0); + if !provisioned { + let units = genesis_units(region_units); + for (i, unit) in units.iter().enumerate() { + if let Err(e) = adapter.write_unit(i as u64, unit) { + let mut l = aienos_kernel::report::ReportBuf::<192>::new(); + let _ = writeln!(l, "STORE_NVME_INTEGRATION_QEMU: FAIL (genesis write {e:?})"); + say(screen, l.as_str()); + return; + } + } + if let Err(e) = adapter.flush() { + let mut l = aienos_kernel::report::ReportBuf::<192>::new(); + let _ = writeln!(l, "STORE_NVME_INTEGRATION_QEMU: FAIL (genesis flush {e:?})"); + say(screen, l.as_str()); + return; + } + } + + let mut store = match Store::open(adapter) { + Ok(s) => s, + Err(e) => { + let mut l = aienos_kernel::report::ReportBuf::<192>::new(); + let _ = writeln!(l, "STORE_NVME_INTEGRATION_QEMU: FAIL (open {e:?})"); + say(screen, l.as_str()); + return; + } + }; + + let mut integration = aienos_kernel::report::ReportBuf::<256>::new(); + let _ = writeln!( + integration, + "STORE_NVME_INTEGRATION_QEMU: PASS (generation={} state={:?} region_units={})", + store.generation(), + store.mount_state(), + region_units + ); + say(screen, integration.as_str()); + + // Settle transactions to advance committed generations (slot reuse). + for _ in 0..settle { + let bytes = (store.generation() + 1).to_le_bytes(); + let obj = ObjectInput { + kind: 3, + version: 1, + bytes: &bytes, + }; + if let Err(e) = store.transact(&[obj]) { + let mut l = aienos_kernel::report::ReportBuf::<192>::new(); + let _ = writeln!(l, "STORE_NVME_INTEGRATION_QEMU: FAIL (settle {e:?})"); + say(screen, l.as_str()); + return; + } + } + + // Target transaction: emit CHECKPOINT lines; the host may kill us at one. + let bytes = (store.generation() + 1).to_le_bytes(); + let obj = ObjectInput { + kind: 3, + version: 1, + bytes: &bytes, + }; + let hook = |cp: Checkpoint| { + let mut l = aienos_kernel::report::ReportBuf::<64>::new(); + let _ = writeln!(l, "CHECKPOINT: {}", cp.as_str()); + say(screen, l.as_str()); + // Observation hold only: give the host crash controller time to see the + // marker and kill the VM at this exact checkpoint. No flush, no write, + // no ordering change. + let hz = counter_frequency_hz(); + if hz > 0 { + let start = counter_ticks(); + while counter_ticks().wrapping_sub(start) < hz / 2 { + core::hint::spin_loop(); + } + } + }; + match store.transact_with_hook(&[obj], hook) { + Ok(()) => { + let mut l = aienos_kernel::report::ReportBuf::<128>::new(); + let _ = writeln!( + l, + "STORE_CHECKPOINT_QEMU: PASS (generation={})", + store.generation() + ); + say(screen, l.as_str()); + } + Err(e) => { + let mut l = aienos_kernel::report::ReportBuf::<128>::new(); + let _ = writeln!(l, "STORE_CHECKPOINT_QEMU: FAIL ({e:?})"); + say(screen, l.as_str()); + } + } +} + +#[cfg(feature = "store-qual")] +fn verify_reopen(screen: &mut Option, adapter: QualAdapter, settle: u8) { + use aienos_kernel::store::engine::Store; + use aienos_kernel::store::v1::ObjectId; + + let upper = u64::from(settle) + 2; + let mut store = match Store::open(adapter) { + Ok(s) => s, + Err(e) => { + let mut l = aienos_kernel::report::ReportBuf::<192>::new(); + let _ = writeln!(l, "STORE_REOPEN_QEMU: FAIL (open {e:?})"); + say(screen, l.as_str()); + return; + } + }; + let generation = store.generation(); + let state = store.mount_state(); + let mut l = aienos_kernel::report::ReportBuf::<192>::new(); + let _ = writeln!( + l, + "STORE_REOPEN_QEMU: generation={} state={:?} upper={}", + generation, state, upper + ); + say(screen, l.as_str()); + + let mut valid = (1..=upper).contains(&generation); + if valid && generation >= 2 { + let bytes = generation.to_le_bytes(); + valid = match ObjectId::calculate(3, 1, &bytes) { + Ok(oid) => store.read_object(oid).map(|v| v == bytes).unwrap_or(false), + Err(_) => false, + }; + } + if valid && settle >= 3 && generation >= 4 { + let mut r = aienos_kernel::report::ReportBuf::<96>::new(); + let _ = writeln!(r, "STORE_SLOT_REUSE_QEMU: PASS (generation={generation})"); + say(screen, r.as_str()); + } + let mut done = aienos_kernel::report::ReportBuf::<160>::new(); + let _ = writeln!( + done, + "STORE_REOPEN_QEMU: {} (generation={generation})", + if valid { "PASS" } else { "FAIL" } + ); + say(screen, done.as_str()); +} diff --git a/crates/aienos-boot/src/store_qual.rs b/crates/aienos-boot/src/store_qual.rs new file mode 100644 index 00000000..2ef5ce61 --- /dev/null +++ b/crates/aienos-boot/src/store_qual.rs @@ -0,0 +1,131 @@ +//! Test-only Store-over-NVMe qualification plumbing. +//! +//! Bounded block device over the native NVMe controller plus canonical Store v1 +//! genesis bytes. No production Store, NVMe, or recovery semantics are changed. + +extern crate alloc; + +use aienos_kernel::block::{BlockDevice, BlockError}; +use aienos_kernel::nvme::driver::{Delay, DmaMemory, NvmeController}; +use aienos_kernel::nvme::Registers; + +/// Bounded Store region base LBA and size, in logical blocks. +pub const STORE_BASE_LBA: u64 = 64; +pub const STORE_REGION_BLOCKS: u64 = 256; +/// Control block LBA the host script writes to select the qualification mode. +pub const CONFIG_LBA: u64 = 32; + +pub const MODE_VERIFY: u8 = 2; + +/// Adds a fixed LBA offset and rejects accesses past the bounded region. +pub struct BoundedNvme { + inner: NvmeController, + base_lba: u64, + blocks: u64, +} + +impl BoundedNvme { + pub fn new(inner: NvmeController, base_lba: u64, blocks: u64) -> Self { + Self { + inner, + base_lba, + blocks, + } + } +} + +impl BlockDevice for BoundedNvme { + fn block_size(&self) -> u32 { + self.inner.block_size() + } + fn block_count(&self) -> u64 { + self.blocks + } + fn read_blocks(&mut self, lba: u64, buffer: &mut [u8]) -> Result<(), BlockError> { + let bs = self.inner.block_size() as usize; + if bs == 0 || !buffer.len().is_multiple_of(bs) { + return Err(BlockError::InvalidInput); + } + let count = (buffer.len() / bs) as u64; + if lba.checked_add(count).is_none_or(|end| end > self.blocks) { + return Err(BlockError::OutOfRange); + } + self.inner.read_blocks(self.base_lba + lba, buffer) + } + fn write_blocks(&mut self, lba: u64, buffer: &[u8]) -> Result<(), BlockError> { + let bs = self.inner.block_size() as usize; + if bs == 0 || !buffer.len().is_multiple_of(bs) { + return Err(BlockError::InvalidInput); + } + let count = (buffer.len() / bs) as u64; + if lba.checked_add(count).is_none_or(|end| end > self.blocks) { + return Err(BlockError::OutOfRange); + } + self.inner.write_blocks(self.base_lba + lba, buffer) + } + fn flush(&mut self) -> Result<(), BlockError> { + self.inner.flush() + } +} + +pub const STORE_UNIT_BYTES: usize = 4096; + +/// Canonical Store v1 genesis: Superblock A only (slot B is left all zero so +/// the first transaction exercises the "inactive slot initially zero" case), +/// an empty catalog at unit 2, and the CommitRecord at unit 3. +pub fn genesis_units(region_units: u64) -> [[u8; STORE_UNIT_BYTES]; 4] { + use aienos_kernel::store::v1::{ + object_unit_count, Catalog, CommitRecord, ObjectId, Superblock, OBJECT_KIND_CATALOG, + OBJECT_VERSION_V1, + }; + + let catalog = Catalog { + entries: alloc::vec::Vec::new(), + }; + let catalog_bytes = catalog.encode().expect("catalog encode"); + let catalog_id = ObjectId::calculate(OBJECT_KIND_CATALOG, OBJECT_VERSION_V1, &catalog_bytes) + .expect("catalog id"); + let catalog_units = object_unit_count(catalog_bytes.len() as u64).expect("catalog units"); + let catalog_first = 2u64; + let commit_unit = catalog_first + u64::from(catalog_units); + let high_water = commit_unit + 1; + let uuid = [0x5Au8; 16]; + + let commit = CommitRecord { + store_uuid: uuid, + region_units, + generation: 1, + previous_generation: 0, + previous_commit_id: ObjectId([0u8; 32]), + previous_catalog_id: ObjectId([0u8; 32]), + catalog_id, + catalog_first_unit: catalog_first, + catalog_byte_length: catalog_bytes.len() as u64, + catalog_unit_count: catalog_units, + catalog_entry_count: 0, + committed_high_water: high_water, + }; + let commit_bytes = commit.encode().expect("commit encode"); + let commit_id = commit.object_id().expect("commit id"); + + let superblock = Superblock { + store_uuid: uuid, + slot_id: 0, + region_units, + generation: 1, + commit_record_id: commit_id, + commit_record_unit: commit_unit, + catalog_id, + catalog_first_unit: catalog_first, + catalog_byte_length: catalog_bytes.len() as u64, + catalog_unit_count: catalog_units, + catalog_entry_count: 0, + committed_high_water: high_water, + }; + + let mut out = [[0u8; STORE_UNIT_BYTES]; 4]; + out[0].copy_from_slice(&superblock.encode().expect("superblock encode")); + out[2][..catalog_bytes.len()].copy_from_slice(&catalog_bytes); + out[3][..commit_bytes.len()].copy_from_slice(&commit_bytes); + out +} diff --git a/evidence/store_nvme_qemu_2026-09-25.md b/evidence/store_nvme_qemu_2026-09-25.md new file mode 100644 index 00000000..75e94acd --- /dev/null +++ b/evidence/store_nvme_qemu_2026-09-25.md @@ -0,0 +1,70 @@ +# Store-over-NVMe QEMU crash/reboot qualification (2026-09-25) + +Lane: `feat/p3-store-nvme-qemu`, base canonical `main` `c851d01`. +Test-only. QEMU only. No ADR 0015, recovery, Store-format, NVMe-policy, or +Machine 1 changes. + +## Integration path + +`NvmeController` -> `BoundedNvme` (base LBA 64, 256 blocks) -> +`StoreDeviceAdapter` -> `Store`, exercised in-guest by +`run_store_phase` under feature `store-qual`. + +- Geometry: 4096-byte LBA (atomic-root qualified namespace). +- Atomic-root predicate required PASS before any Store media write. +- Genesis: canonical v1, Superblock A only (slot B left zero), empty catalog at + unit 2, CommitRecord at unit 3, high-water 4. +- Checkpoint hook emits `CHECKPOINT: ` and holds ~0.5 s (observation only; + no flush, no write, no ordering change) so the host can kill at the marker. + +## Result: STORE_V1_QEMU: PASS + +Integration smoke: provision + one transaction + reopen all PASS. + +Crash campaign (host kills QEMU with SIGKILL at the checkpoint marker, reboots, +reopens through the real NVMe path): + +| settle | checkpoint | recovered | state | expected | +|---:|---|---:|---|---| +| 0 | before_first_write | 1 | Valid | {1,2} | +| 0 | after_payloads | 1 | Valid | {1,2} | +| 0 | after_catalog | 1 | Valid | {1,2} | +| 0 | after_commit_record | 1 | Valid | {1,2} | +| 0 | after_first_flush | 1 | Valid | {1,2} | +| 0 | after_superblock_write | 2 | Valid | {1,2} | +| 0 | after_final_flush | 2 | Valid | {1,2} | +| 3 | before_first_write | 4 | Valid | {4,5} | +| 3 | after_payloads | 4 | Valid | {4,5} | +| 3 | after_catalog | 4 | Valid | {4,5} | +| 3 | after_commit_record | 4 | Valid | {4,5} | +| 3 | after_first_flush | 4 | Valid | {4,5} | +| 3 | after_superblock_write | 5 | Valid | {4,5} | +| 3 | after_final_flush | 5 | Valid | {4,5} | + +Recovery is N before the inactive-superblock write and N+1 after it; every +recovered root is a fully valid generation with its application object intact. +The host asserts the strict per-checkpoint boundary (N before the superblock +write, {N,N+1} at `after_superblock_write`, N+1 at `after_final_flush`) and +requires the guest's `STORE_REOPEN_QEMU: PASS` / `STORE_SLOT_REUSE_QEMU: PASS` +markers before scoring a row OK. +`settle=3` cycles both Superblock slots A -> B -> A -> B. + +## Markers + +``` +STORE_NVME_INTEGRATION_QEMU: PASS +STORE_CHECKPOINT_CRASH_QEMU: PASS +STORE_REOPEN_QEMU: PASS +STORE_SLOT_REUSE_QEMU: PASS +STORE_V1_QEMU: PASS +P3_STORE_QEMU: NOT CLAIMED +``` + +`P3_STORE_QEMU` is not claimed: it requires the native-NVMe persistence +conditions, which the Spark SSD does not meet (512-byte LBA, 1-block guarantee). + +## Reproduce + +```bash +bash scripts/qemu_store_crash_test.sh +``` diff --git a/scripts/qemu_store_crash_test.sh b/scripts/qemu_store_crash_test.sh new file mode 100755 index 00000000..302fc0ee --- /dev/null +++ b/scripts/qemu_store_crash_test.sh @@ -0,0 +1,175 @@ +#!/usr/bin/env bash +# System Store v1 over the native NVMe driver: QEMU crash/reboot campaign. +# +# Geometry: 4096-byte LBA (the atomic-root qualified namespace). The Store root +# write is one logical block, satisfying the atomic-root predicate. +# +# Chain exercised in-guest: NvmeController -> BoundedNvme -> StoreDeviceAdapter +# -> Store. For each canonical checkpoint the guest begins generation N+1, the +# host kills QEMU abruptly at the checkpoint marker, then reboots and reopens +# from media; recovery must be generation N or N+1 with a valid graph. +# +# Test-only. QEMU only. No ADR 0015, recovery, Store-format, NVMe-policy, or +# Machine 1 changes. +set -uo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "${repo_root}" + +code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" +vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" +command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; exit 2; } +[[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "AAVMF firmware not found"; exit 2; } + +boot_timeout="${AIENOS_QEMU_TIMEOUT:-180}" +img_bytes=67108864 +lba_bytes=4096 +bounds_lba=$(( img_bytes / lba_bytes )) +cfg_lba=32 +machine="virt,virtualization=on,gic-version=3,iommu=smmuv3" +target_dir="target/qemu-store-crash" + +commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" +AIENOS_COMMIT="${commit}" AIENOS_RESTART_SECS=1 cargo build --quiet --release \ + -p aienos-boot --target aarch64-unknown-uefi --features store-qual --bin aienos-handoff \ + --target-dir "${target_dir}" || { echo "build failed"; exit 2; } + +work="$(mktemp -d)" +qemu_pid="" +cleanup() { [[ -n "${qemu_pid}" ]] && kill -9 "${qemu_pid}" 2>/dev/null || true; rm -rf "${work}"; } +trap cleanup EXIT +mkdir -p "${work}/esp/EFI/BOOT" "${work}/esp/EFI/AIENOS" +touch "${work}/esp/EFI/AIENOS/BOOTREPORT.TXT" +cp "${target_dir}/aarch64-unknown-uefi/release/aienos-handoff.efi" "${work}/esp/EFI/BOOT/BOOTAA64.EFI" + +image="${work}/nvme.img" +serial="${work}/serial.log" +cfgfile="${work}/cfg.bin" + +fresh_image() { rm -f "${image}"; truncate -s "${img_bytes}" "${image}"; } + +write_cfg() { # mode settle + python3 -c "open('${cfgfile}','wb').write(bytes([$1,$2]) + bytes(4094))" + dd if="${cfgfile}" of="${image}" bs="${lba_bytes}" seek="${cfg_lba}" conv=notrunc status=none +} + +# run_qemu [kill] +run_qemu() { + cp -f "${vars_fd}" "${work}/vars.fd" + rm -f "${serial}" + qemu-system-aarch64 \ + -M "${machine}" -accel tcg,thread=single -cpu max -smp 4 -m 2048 \ + -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ + -drive if=pflash,format=raw,file="${work}/vars.fd" \ + -drive if=none,id=esp,format=raw,file=fat:rw:"${work}/esp" \ + -device virtio-blk-pci,drive=esp \ + -drive if=none,id=nvme0,format=raw,file="${image}" \ + -device nvme,drive=nvme0,serial=aienos-store-crash,logical_block_size=${lba_bytes},physical_block_size=${lba_bytes} \ + -display none -nic none -serial file:"${serial}" -no-reboot & + qemu_pid=$! + local deadline=$(( $(date +%s) + boot_timeout )) + while (( $(date +%s) < deadline )); do + grep -q -- "$1" "${serial}" 2>/dev/null && break + kill -0 "${qemu_pid}" 2>/dev/null || break + sleep 0.1 + done + if [[ "${2:-}" == "kill" ]]; then + kill -9 "${qemu_pid}" 2>/dev/null || true + fi + wait "${qemu_pid}" 2>/dev/null || true + qemu_pid="" +} + +checkpoints=(before_first_write after_payloads after_catalog after_commit_record \ + after_first_flush after_superblock_write after_final_flush) + +fail=0 +integration_pass=0 +crash_pass=0 +reopen_pass=0 +slot_pass=0 +: > "${work}/results.txt" + +# --- integration smoke (no crash): provision, transact, reopen ------------- +fresh_image; write_cfg 1 0 +run_qemu "STORE_CHECKPOINT_QEMU" +if grep -q "STORE_NVME_INTEGRATION_QEMU: PASS" "${serial}" && \ + grep -q "STORE_CHECKPOINT_QEMU: PASS" "${serial}"; then + integration_pass=1; echo "PASS integration smoke (provision + transact)" +else + echo "FAIL integration smoke"; fail=1 + grep -E "STORE_NVME_INTEGRATION_QEMU|STORE_CHECKPOINT_QEMU" "${serial}" | sed 's/^/ /' +fi +write_cfg 2 0 +run_qemu "STORE_REOPEN_QEMU:" +if grep -q "STORE_REOPEN_QEMU: PASS" "${serial}"; then echo "PASS reopen smoke"; else echo "FAIL reopen smoke"; fail=1; fi + +# --- crash campaign -------------------------------------------------------- +# Per-checkpoint expectation from the implementation: the inactive-superblock +# write is the durable commit point. Before it, recovery must be N; at it the +# Store contract permits N or N+1 (emulator durability); after the final flush +# it must be N+1. +expect_for() { # checkpoint settle + case "$1" in + after_superblock_write) echo "N_NP1" ;; + after_final_flush) echo "NP1" ;; + *) echo "N" ;; + esac +} + +for settle in 0 3; do + N=$(( 1 + settle )); NP1=$(( 2 + settle )) + for cp in "${checkpoints[@]}"; do + fresh_image; write_cfg 1 "${settle}" + run_qemu "CHECKPOINT: ${cp}" kill + saw_cp=0; grep -q -- "CHECKPOINT: ${cp}" "${serial}" && saw_cp=1 + write_cfg 2 "${settle}" + run_qemu "STORE_REOPEN_QEMU:" + guest_reopen=0; grep -q "STORE_REOPEN_QEMU: PASS" "${serial}" && guest_reopen=1 + guest_slot=1 + if [[ "${settle}" -ge 3 ]]; then + guest_slot=0; grep -q "STORE_SLOT_REUSE_QEMU: PASS" "${serial}" && guest_slot=1 + fi + gen="$(grep -oE "STORE_REOPEN_QEMU: generation=[0-9]+" "${serial}" | tail -1 | grep -oE '[0-9]+$')" + st="$(grep -oE "STORE_REOPEN_QEMU: generation=[0-9]+ state=[A-Za-z]+" "${serial}" | tail -1 | sed 's/.*state=//')" + exp="$(expect_for "${cp}")" + gen_ok=0 + case "${exp}" in + N) [[ "${gen}" == "${N}" ]] && gen_ok=1 ;; + NP1) [[ "${gen}" == "${NP1}" ]] && gen_ok=1 ;; + N_NP1) [[ "${gen}" == "${N}" || "${gen}" == "${NP1}" ]] && gen_ok=1 ;; + esac + ok=0 + if [[ "${saw_cp}" == "1" && "${gen_ok}" == "1" && "${guest_reopen}" == "1" && "${guest_slot}" == "1" ]]; then ok=1; fi + printf 'settle=%s cp=%-18s saw=%s guest_reopen=%s guest_slot=%s recovered=%s state=%s expect=%s -> %s\n' \ + "${settle}" "${cp}" "${saw_cp}" "${guest_reopen}" "${guest_slot}" "${gen:-none}" "${st:-none}" "${exp}" \ + "$([ "${ok}" = 1 ] && echo OK || echo BAD)" >> "${work}/results.txt" + if [[ "${ok}" != "1" ]]; then fail=1; fi + done +done + +crash_pass=1; reopen_pass=1; slot_pass=1 +grep -q ' -> BAD' "${work}/results.txt" && { crash_pass=0; reopen_pass=0; } +grep -qE '^settle=3 .* -> OK$' "${work}/results.txt" || slot_pass=0 +grep -q ' BAD$' "${work}/results.txt" && slot_pass=0 + +echo "---- crash campaign results ----" +cat "${work}/results.txt" +if [[ "${fail}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then + echo "---- final serial ----"; cat "${serial}" +fi + +echo +[[ "${integration_pass}" == 1 ]] && echo "STORE_NVME_INTEGRATION_QEMU: PASS" || echo "STORE_NVME_INTEGRATION_QEMU: FAIL" +[[ "${crash_pass}" == 1 && "${fail}" == 0 ]] && echo "STORE_CHECKPOINT_CRASH_QEMU: PASS" || echo "STORE_CHECKPOINT_CRASH_QEMU: FAIL" +[[ "${reopen_pass}" == 1 && "${fail}" == 0 ]] && echo "STORE_REOPEN_QEMU: PASS" || echo "STORE_REOPEN_QEMU: FAIL" +[[ "${slot_pass}" == 1 ]] && echo "STORE_SLOT_REUSE_QEMU: PASS" || echo "STORE_SLOT_REUSE_QEMU: FAIL" + +if [[ "${fail}" == 0 && "${integration_pass}" == 1 && "${crash_pass}" == 1 && "${reopen_pass}" == 1 && "${slot_pass}" == 1 ]]; then + echo "STORE_V1_QEMU: PASS" +else + echo "STORE_V1_QEMU: NOT EARNED" + echo "P3_STORE_QEMU: NOT CLAIMED (QEMU campaign; native persistence conditions separate)" + exit 1 +fi +echo "P3_STORE_QEMU: NOT CLAIMED (QEMU campaign; native persistence conditions separate)"