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_native_rollback_test.sh

378 lines · 19232 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_native_rollback_test.sh
18# M0 Native-Boot Rollback Verification Test in QEMU AArch64 (AAVMF UEFI).
19#
20# Deterministically exercises one-time native candidate selection and rollback
21# semantics across six required failure and completion branches without
22# touching physical hardware:
23# 1. normal AIENOS candidate exit/reset
24# 2. candidate panic/fault
25# 3. candidate timeout/hang followed by host reset
26# 4. malformed/rejected candidate image
27# 5. absence of candidate image
28# 6. repeated host reboot after one-time candidate has been consumed
29#
30# Uses disposable NVRAM variable storage (vars.fd) and temporary ESP filesystems.
31# Enforces Zero Disk Secrets and strict rollback invariants.
32
33set -euo pipefail
34
35REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
36cd "${REPO_ROOT}"
37
38# Per-invariant judges for the Default OS boot logs. The guest (rollback_mock.rs
39# run_default) prints a PASS line for each invariant it checked itself and a FAIL
40# line otherwise. A host label may only say PASS when the log carries that
41# invariant's own evidence and no FAIL line for it.
42log_consumed_ok() { # LOG: BootNext was consumed
43 [[ -f "$1" ]] || return 1
44 grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "$1" 2>/dev/null && \
45 grep -q "PASS NATIVE_ROLLBACK_BOOTNEXT_CONSUMED" "$1" && \
46 ! grep -q "FAIL NATIVE_ROLLBACK_BOOTNEXT_STILL_PRESENT" "$1"
47}
48log_unchanged_ok() { # LOG: BootOrder still starts with the Default entry 0001
49 [[ -f "$1" ]] || return 1
50 grep -q "DEFAULT_OS: BOOT_ORDER\[0\]=0001" "$1" 2>/dev/null && \
51 grep -q "PASS NATIVE_ROLLBACK_DEFAULT_UNCHANGED" "$1" && \
52 ! grep -q "FAIL NATIVE_ROLLBACK_DEFAULT_ORDER_ALTERED" "$1"
53}
54
55if [[ "${1:-}" == --self-test ]]; then
56 st=0; t="$(mktemp -d)"; trap 'rm -rf "${t}"' EXIT
57 good() { printf 'DEFAULT_OS: BOOT_CURRENT=0001\nDEFAULT_OS: BOOT_ORDER[0]=0001\nDEFAULT_OS: BOOT_NEXT=CONSUMED_PASS\nPASS NATIVE_ROLLBACK_BOOTNEXT_CONSUMED\nPASS NATIVE_ROLLBACK_DEFAULT_UNCHANGED\n'; }
58 expect() { # name want(0|1) function log
59 local rc=0; "$3" "$4" || rc=$?
60 if [[ "${rc}" == "$2" ]]; then echo "PASS $1 -> exit ${rc}"; else echo "FAIL $1: wanted ${2}, got ${rc}"; st=1; fi
61 }
62 good >"${t}/good.log"
63 expect "good Default boot: BootNext consumed" 0 log_consumed_ok "${t}/good.log"
64 expect "good Default boot: BootOrder unchanged" 0 log_unchanged_ok "${t}/good.log"
65 # Mutant: the firmware boot order was altered. The old host check ignored this and still printed DEFAULT_UNCHANGED: PASS.
66 good | sed -e 's/BOOT_ORDER\[0\]=0001/BOOT_ORDER[0]=0002/' -e 's/^PASS NATIVE_ROLLBACK_DEFAULT_UNCHANGED$/FAIL NATIVE_ROLLBACK_DEFAULT_ORDER_ALTERED/' >"${t}/order.log"
67 expect "mutant: BootOrder altered -> DEFAULT_UNCHANGED not PASS" 1 log_unchanged_ok "${t}/order.log"
68 expect "mutant: BootOrder altered leaves the BootNext label alone" 0 log_consumed_ok "${t}/order.log"
69 # Mutant: BootNext still present.
70 good | sed -e 's/CONSUMED_PASS/STILL_PRESENT/' -e 's/^PASS NATIVE_ROLLBACK_BOOTNEXT_CONSUMED$/FAIL NATIVE_ROLLBACK_BOOTNEXT_STILL_PRESENT/' >"${t}/next.log"
71 expect "mutant: BootNext still present -> CONSUMED not PASS" 1 log_consumed_ok "${t}/next.log"
72 # Mutant: the guest never printed the invariant lines (only the old unchanged markers).
73 printf 'DEFAULT_OS: BOOT_CURRENT=0001\nDEFAULT_OS: BOOT_NEXT=CONSUMED_PASS\nPASS NATIVE_ROLLBACK_REPEAT_BOOT\n' >"${t}/old.log"
74 expect "mutant: log with only the old markers -> DEFAULT_UNCHANGED not PASS" 1 log_unchanged_ok "${t}/old.log"
75 expect "mutant: missing log file -> not PASS" 1 log_unchanged_ok "${t}/absent.log"
76 if [[ ${st} == 0 ]]; then echo "NATIVE_ROLLBACK_SELF_TEST: PASS"; exit 0; fi
77 echo "NATIVE_ROLLBACK_SELF_TEST: FAIL"; exit 1
78fi
79
80CODE_FD="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}"
81VARS_FD="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}"
82
83command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; exit 2; }
84[[ -r "${CODE_FD}" && -r "${VARS_FD}" ]] || { echo "AAVMF firmware not found"; exit 2; }
85
86echo "============================================================"
87echo "AIENOS M0 Native-Boot Rollback Test Suite (QEMU AArch64)"
88echo "Host: $(uname -n) | Firmware: $(basename "${CODE_FD}")"
89echo "============================================================"
90
91# Build the rollback mock harness binary
92echo "Building aienos-rollback-mock..."
93cargo build --quiet --release -p aienos-boot --target aarch64-unknown-uefi --features handoff --bin aienos-rollback-mock
94MOCK_BIN="target/aarch64-unknown-uefi/release/aienos-rollback-mock.efi"
95[[ -f "${MOCK_BIN}" ]] || { echo "Failed to build aienos-rollback-mock.efi"; exit 1; }
96
97WORK_DIR="$(mktemp -d)"
98cleanup() {
99 rm -rf "${WORK_DIR}"
100}
101trap cleanup EXIT
102
103failed=0
104pass() { echo "PASS $1"; }
105fail() { echo "FAIL $1"; failed=1; }
106
107run_qemu_boot() {
108 local esp_dir="$1"
109 local vars_file="$2"
110 local log_file="$3"
111 local timeout_secs="${4:-20}"
112
113 set +e
114 timeout "${timeout_secs}" qemu-system-aarch64 \
115 -M virt,virtualization=on,gic-version=3 -accel tcg,thread=single -cpu max -smp 2 -m 512 \
116 -drive if=pflash,format=raw,readonly=on,file="${CODE_FD}" \
117 -drive if=pflash,format=raw,file="${vars_file}" \
118 -drive if=none,id=esp,format=raw,file=fat:rw:"${esp_dir}" \
119 -device virtio-blk-pci,drive=esp \
120 -display none -nic none \
121 -serial file:"${log_file}" -no-reboot
122 local exit_code=$?
123 set -e
124 return "${exit_code}"
125}
126
127# ==============================================================================
128# SUBTEST 1: Normal Candidate Execution & Clean Return
129# ==============================================================================
130echo ""
131echo "--- [Subtest 1: Normal Candidate Execution & Rollback] ---"
132SUB1_DIR="${WORK_DIR}/subtest1"
133mkdir -p "${SUB1_DIR}/esp/EFI/BOOT" "${SUB1_DIR}/esp/EFI/AIENOS" "${SUB1_DIR}/esp/EFI/DEFAULT"
134cp "${VARS_FD}" "${SUB1_DIR}/vars.fd"
135cp "${MOCK_BIN}" "${SUB1_DIR}/esp/EFI/BOOT/BOOTAA64.EFI"
136cp "${MOCK_BIN}" "${SUB1_DIR}/esp/EFI/AIENOS/candidate.efi"
137cp "${MOCK_BIN}" "${SUB1_DIR}/esp/EFI/DEFAULT/default.efi"
138echo "normal" > "${SUB1_DIR}/esp/EFI/AIENOS/ROLLBACK_MODE.TXT"
139
140# Boot 1: Stager sets Boot0001, Boot0000, BootOrder=[0001], BootNext=0000, resets
141run_qemu_boot "${SUB1_DIR}/esp" "${SUB1_DIR}/vars.fd" "${SUB1_DIR}/boot1_stage.log" 20 || true
142# Boot 2: Firmware runs BootNext=0000 (Candidate). Candidate prints, resets
143run_qemu_boot "${SUB1_DIR}/esp" "${SUB1_DIR}/vars.fd" "${SUB1_DIR}/boot2_candidate.log" 20 || true
144# Boot 3: Firmware runs BootOrder[0]=0001 (Default). Default verifies return
145run_qemu_boot "${SUB1_DIR}/esp" "${SUB1_DIR}/vars.fd" "${SUB1_DIR}/boot3_default.log" 20 || true
146
147# Check NVRAM binary contains BootNext, BootOrder, Boot0000, Boot0001 after staging
148# (UEFI variable names are stored as UTF-16LE: each ASCII byte followed by NUL.)
149for var_name in BootNext BootOrder Boot0000 Boot0001; do
150 utf16le_pattern=""
151 for ((i = 0; i < ${#var_name}; i++)); do
152 utf16le_pattern+="${var_name:i:1}\\x00"
153 done
154 if ! LC_ALL=C grep -qaP "${utf16le_pattern}" "${SUB1_DIR}/vars.fd"; then
155 echo "${var_name} not in vars.fd after stage" >&2
156 exit 1
157 fi
158done
159
160if grep -q "PASS M0_ROLLBACK_STAGED: boot_order=0001 boot_next=0000" "${SUB1_DIR}/boot1_stage.log" && \
161 grep -q 'BdsDxe: starting Boot0000 "AIENOS Candidate"' "${SUB1_DIR}/boot2_candidate.log" && \
162 grep -q "AIENOS_CANDIDATE: NORMAL_TERMINATION_REQUESTED" "${SUB1_DIR}/boot2_candidate.log" && \
163 grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${SUB1_DIR}/boot3_default.log" && \
164 grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB1_DIR}/boot3_default.log" && \
165 grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB1_DIR}/boot3_default.log"; then
166 pass "AAVMF BdsDxe firmware one-shot BootNext dispatch & NVRAM persistence verified (Boot0000 -> Boot0001)"
167 echo "AAVMF_BOOTNEXT_NVRAM: PASS"
168 echo "NATIVE_ROLLBACK_NORMAL: PASS"
169else
170 fail "Normal candidate rollback failed"
171 echo "NATIVE_ROLLBACK_NORMAL: FAIL"
172fi
173
174# ==============================================================================
175# SUBTEST 2: Candidate Crash / Fault & Return
176# ==============================================================================
177echo ""
178echo "--- [Subtest 2: Candidate Fault / Panic & Rollback] ---"
179SUB2_DIR="${WORK_DIR}/subtest2"
180mkdir -p "${SUB2_DIR}/esp/EFI/BOOT" "${SUB2_DIR}/esp/EFI/AIENOS" "${SUB2_DIR}/esp/EFI/DEFAULT"
181cp "${VARS_FD}" "${SUB2_DIR}/vars.fd"
182cp "${MOCK_BIN}" "${SUB2_DIR}/esp/EFI/BOOT/BOOTAA64.EFI"
183cp "${MOCK_BIN}" "${SUB2_DIR}/esp/EFI/AIENOS/candidate.efi"
184cp "${MOCK_BIN}" "${SUB2_DIR}/esp/EFI/DEFAULT/default.efi"
185echo "fault" > "${SUB2_DIR}/esp/EFI/AIENOS/ROLLBACK_MODE.TXT"
186
187# Boot 1: Stager
188run_qemu_boot "${SUB2_DIR}/esp" "${SUB2_DIR}/vars.fd" "${SUB2_DIR}/boot1_stage.log" 20 || true
189# Boot 2: Candidate panics / faults and resets
190run_qemu_boot "${SUB2_DIR}/esp" "${SUB2_DIR}/vars.fd" "${SUB2_DIR}/boot2_candidate.log" 20 || true
191# Boot 3: Default OS recovers
192run_qemu_boot "${SUB2_DIR}/esp" "${SUB2_DIR}/vars.fd" "${SUB2_DIR}/boot3_default.log" 20 || true
193
194if grep -q 'BdsDxe: starting Boot0000 "AIENOS Candidate"' "${SUB2_DIR}/boot2_candidate.log" && \
195 grep -q "AIENOS_CANDIDATE: INDUCED_FAULT_PANIC" "${SUB2_DIR}/boot2_candidate.log" && \
196 grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${SUB2_DIR}/boot3_default.log" && \
197 grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB2_DIR}/boot3_default.log" && \
198 grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB2_DIR}/boot3_default.log"; then
199 pass "Faulted candidate consumed BootNext and returned to Default via AAVMF BootOrder"
200 echo "NATIVE_ROLLBACK_FAULT: PASS"
201else
202 fail "Faulted candidate rollback failed"
203 echo "NATIVE_ROLLBACK_FAULT: FAIL"
204fi
205
206# ==============================================================================
207# SUBTEST 3: Candidate Hang / Timeout Followed by Reset
208# ==============================================================================
209echo ""
210echo "--- [Subtest 3: Candidate Hang / Timeout & Rollback] ---"
211SUB3_DIR="${WORK_DIR}/subtest3"
212mkdir -p "${SUB3_DIR}/esp/EFI/BOOT" "${SUB3_DIR}/esp/EFI/AIENOS" "${SUB3_DIR}/esp/EFI/DEFAULT"
213cp "${VARS_FD}" "${SUB3_DIR}/vars.fd"
214cp "${MOCK_BIN}" "${SUB3_DIR}/esp/EFI/BOOT/BOOTAA64.EFI"
215cp "${MOCK_BIN}" "${SUB3_DIR}/esp/EFI/AIENOS/candidate.efi"
216cp "${MOCK_BIN}" "${SUB3_DIR}/esp/EFI/DEFAULT/default.efi"
217echo "timeout" > "${SUB3_DIR}/esp/EFI/AIENOS/ROLLBACK_MODE.TXT"
218
219# Boot 1: Stager
220run_qemu_boot "${SUB3_DIR}/esp" "${SUB3_DIR}/vars.fd" "${SUB3_DIR}/boot1_stage.log" 20 || true
221
222# Boot 2: Candidate enters hang spin-loop. Watchdog terminates after entering hang.
223boot2_log="${SUB3_DIR}/boot2_candidate.log"
224qemu-system-aarch64 \
225 -M virt,virtualization=on,gic-version=3 -accel tcg,thread=single -cpu max -smp 2 -m 512 \
226 -drive if=pflash,format=raw,readonly=on,file="${CODE_FD}" \
227 -drive if=pflash,format=raw,file="${SUB3_DIR}/vars.fd" \
228 -drive if=none,id=esp,format=raw,file=fat:rw:"${SUB3_DIR}/esp" \
229 -device virtio-blk-pci,drive=esp \
230 -display none -nic none \
231 -serial file:"${boot2_log}" -no-reboot &
232QEMU_PID=$!
233
234# Wait until candidate enters spin loop, then force reset (simulating hardware watchdog)
235hung=0
236for _ in $(seq 1 40); do
237 sleep 0.5
238 if [[ -f "${boot2_log}" ]] && grep -q "ENTERING_HANG_SPIN_LOOP" "${boot2_log}"; then
239 hung=1
240 kill -9 "${QEMU_PID}" 2>/dev/null || true
241 wait "${QEMU_PID}" 2>/dev/null || true
242 break
243 fi
244done
245
246if [[ "${hung}" -ne 1 ]]; then
247 kill -9 "${QEMU_PID}" 2>/dev/null || true
248 wait "${QEMU_PID}" 2>/dev/null || true
249fi
250
251# Boot 3: Default OS boots on next power cycle
252run_qemu_boot "${SUB3_DIR}/esp" "${SUB3_DIR}/vars.fd" "${SUB3_DIR}/boot3_default.log" 20 || true
253
254if [[ "${hung}" -eq 1 ]] && \
255 grep -q 'BdsDxe: starting Boot0000 "AIENOS Candidate"' "${SUB3_DIR}/boot2_candidate.log" && \
256 grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${SUB3_DIR}/boot3_default.log" && \
257 grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB3_DIR}/boot3_default.log" && \
258 grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB3_DIR}/boot3_default.log"; then
259 pass "Hung candidate reset consumed BootNext and returned to Default via AAVMF BootOrder"
260 echo "NATIVE_ROLLBACK_TIMEOUT: PASS"
261else
262 fail "Hung candidate timeout rollback failed"
263 echo "NATIVE_ROLLBACK_TIMEOUT: FAIL"
264fi
265
266# ==============================================================================
267# SUBTEST 4: Malformed / Corrupted Candidate Image
268# ==============================================================================
269echo ""
270echo "--- [Subtest 4: Malformed / Corrupted Image Fallback] ---"
271SUB4_DIR="${WORK_DIR}/subtest4"
272mkdir -p "${SUB4_DIR}/esp/EFI/BOOT" "${SUB4_DIR}/esp/EFI/AIENOS" "${SUB4_DIR}/esp/EFI/DEFAULT"
273cp "${VARS_FD}" "${SUB4_DIR}/vars.fd"
274cp "${MOCK_BIN}" "${SUB4_DIR}/esp/EFI/BOOT/BOOTAA64.EFI"
275# Candidate file is corrupted bytes (invalid PE header)
276printf "\x7fELFcorrupt_pe_header_payload_junk\x00\x00\x00" > "${SUB4_DIR}/esp/EFI/AIENOS/candidate.efi"
277cp "${MOCK_BIN}" "${SUB4_DIR}/esp/EFI/DEFAULT/default.efi"
278echo "malformed" > "${SUB4_DIR}/esp/EFI/AIENOS/ROLLBACK_MODE.TXT"
279
280# Boot 1: Stager
281run_qemu_boot "${SUB4_DIR}/esp" "${SUB4_DIR}/vars.fd" "${SUB4_DIR}/boot1_stage.log" 20 || true
282# Boot 2: Firmware attempts BootNext, rejects invalid PE image, falls back to Default
283run_qemu_boot "${SUB4_DIR}/esp" "${SUB4_DIR}/vars.fd" "${SUB4_DIR}/boot2_fallback.log" 20 || true
284
285if grep -q "failed to load Boot0000" "${SUB4_DIR}/boot2_fallback.log" && \
286 grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${SUB4_DIR}/boot2_fallback.log" && \
287 grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB4_DIR}/boot2_fallback.log" && \
288 grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB4_DIR}/boot2_fallback.log"; then
289 pass "Malformed image rejected by AAVMF firmware with fallback to Default via BootOrder"
290 echo "NATIVE_ROLLBACK_REJECTED: PASS"
291else
292 fail "Malformed image fallback failed"
293 echo "NATIVE_ROLLBACK_REJECTED: FAIL"
294fi
295
296# ==============================================================================
297# SUBTEST 5: Absent Candidate Image
298# ==============================================================================
299echo ""
300echo "--- [Subtest 5: Absent Candidate Image Fallback] ---"
301SUB5_DIR="${WORK_DIR}/subtest5"
302mkdir -p "${SUB5_DIR}/esp/EFI/BOOT" "${SUB5_DIR}/esp/EFI/AIENOS" "${SUB5_DIR}/esp/EFI/DEFAULT"
303cp "${VARS_FD}" "${SUB5_DIR}/vars.fd"
304cp "${MOCK_BIN}" "${SUB5_DIR}/esp/EFI/BOOT/BOOTAA64.EFI"
305# No candidate file placed
306cp "${MOCK_BIN}" "${SUB5_DIR}/esp/EFI/DEFAULT/default.efi"
307echo "absent" > "${SUB5_DIR}/esp/EFI/AIENOS/ROLLBACK_MODE.TXT"
308
309# Boot 1: Stager sets Boot0000 to missing_candidate.efi
310run_qemu_boot "${SUB5_DIR}/esp" "${SUB5_DIR}/vars.fd" "${SUB5_DIR}/boot1_stage.log" 20 || true
311# Boot 2: Firmware fails to load absent Boot0000, falls back to Default
312run_qemu_boot "${SUB5_DIR}/esp" "${SUB5_DIR}/vars.fd" "${SUB5_DIR}/boot2_fallback.log" 20 || true
313
314if grep -q "failed to load Boot0000" "${SUB5_DIR}/boot2_fallback.log" && \
315 grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${SUB5_DIR}/boot2_fallback.log" && \
316 grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB5_DIR}/boot2_fallback.log" && \
317 grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB5_DIR}/boot2_fallback.log"; then
318 pass "Absent candidate image handled cleanly with fallback to Default via BootOrder"
319else
320 fail "Absent candidate image fallback failed"
321fi
322
323# ==============================================================================
324# SUBTEST 6: Repeated Host Reboot After Consumption (No Boot Loop Invariant)
325# ==============================================================================
326echo ""
327echo "--- [Subtest 6: Repeated Boot Post-Consumption (No Loop Invariant)] ---"
328SUB6_DIR="${WORK_DIR}/subtest6"
329mkdir -p "${SUB6_DIR}/esp/EFI/BOOT" "${SUB6_DIR}/esp/EFI/AIENOS" "${SUB6_DIR}/esp/EFI/DEFAULT"
330cp "${VARS_FD}" "${SUB6_DIR}/vars.fd"
331cp "${MOCK_BIN}" "${SUB6_DIR}/esp/EFI/BOOT/BOOTAA64.EFI"
332cp "${MOCK_BIN}" "${SUB6_DIR}/esp/EFI/AIENOS/candidate.efi"
333cp "${MOCK_BIN}" "${SUB6_DIR}/esp/EFI/DEFAULT/default.efi"
334echo "normal" > "${SUB6_DIR}/esp/EFI/AIENOS/ROLLBACK_MODE.TXT"
335
336# Boot 1: Stager
337run_qemu_boot "${SUB6_DIR}/esp" "${SUB6_DIR}/vars.fd" "${SUB6_DIR}/boot1_stage.log" 20 || true
338# Boot 2: Candidate
339run_qemu_boot "${SUB6_DIR}/esp" "${SUB6_DIR}/vars.fd" "${SUB6_DIR}/boot2_candidate.log" 20 || true
340# Boot 3: First return to Default OS (Default increments cycle to 1 and requests cold reset)
341run_qemu_boot "${SUB6_DIR}/esp" "${SUB6_DIR}/vars.fd" "${SUB6_DIR}/boot3_default1.log" 20 || true
342# Boot 4: Second consecutive boot of Default OS (proves system stays on Default, no loops)
343run_qemu_boot "${SUB6_DIR}/esp" "${SUB6_DIR}/vars.fd" "${SUB6_DIR}/boot4_default2.log" 20 || true
344
345b3="${SUB6_DIR}/boot3_default1.log"; b4="${SUB6_DIR}/boot4_default2.log"
346if grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${b3}" && \
347 grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${b4}" && \
348 grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${b4}" && \
349 grep -q "PASS NATIVE_ROLLBACK_REPEAT_BOOT" "${b4}"; then
350 pass "Subsequent reboot stayed on Default OS via AAVMF BootOrder without re-executing candidate"
351else
352 fail "Repeated boot failed to stay on Default OS"
353fi
354# Each invariant label is judged from its own evidence in BOTH Default boots.
355sub6_consumed=FAIL; sub6_unchanged=FAIL
356if log_consumed_ok "${b3}" && log_consumed_ok "${b4}"; then sub6_consumed=PASS; else fail "BootNext was not proven consumed in both Default boots"; fi
357if log_unchanged_ok "${b3}" && log_unchanged_ok "${b4}"; then sub6_unchanged=PASS; else fail "Default BootOrder was not proven unchanged in both Default boots"; fi
358echo "NATIVE_ROLLBACK_BOOTNEXT_CONSUMED: ${sub6_consumed}"
359echo "NATIVE_ROLLBACK_DEFAULT_UNCHANGED: ${sub6_unchanged}"
360
361echo ""
362echo "============================================================"
363if [[ "${failed}" == 0 ]]; then
364 echo "AAVMF_BOOTNEXT_NVRAM: PASS"
365 echo "NATIVE_ROLLBACK_NORMAL: PASS"
366 echo "NATIVE_ROLLBACK_FAULT: PASS"
367 echo "NATIVE_ROLLBACK_TIMEOUT: PASS"
368 echo "NATIVE_ROLLBACK_REJECTED: PASS"
369 echo "NATIVE_ROLLBACK_BOOTNEXT_CONSUMED: PASS"
370 echo "NATIVE_ROLLBACK_DEFAULT_UNCHANGED: PASS"
371 echo "M0_NATIVE_ROLLBACK_QEMU: PASS"
372 echo "M0_ROLLBACK_QEMU: PASS"
373 exit 0
374else
375 echo "M0_NATIVE_ROLLBACK_QEMU: FAIL"
376 echo "M0_ROLLBACK_QEMU: FAIL"
377 exit 1
378fi