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_ck_lifecycle_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 | # LIFECYCLE gate for the AIENOS C kernel (native v1 plan P03 + P04 cut 1 + P05 |
| 18 | # cut 1 + P06 cut 2): rows 160-176 of native/kernel/GATES.md "LIFECYCLE resident |
| 19 | # production lifecycle". C-only. |
| 20 | # QEMU is not hardware: a PASS here qualifies nothing physical. |
| 21 | # |
| 22 | # Boots two CK_SERVICE images in QEMU AArch64 (AAVMF, NVMe disk, iommu=smmuv3), |
| 23 | # operator input over the PL011 serial from OUTSIDE the guest (pipe chardev): |
| 24 | # service make full CK_SERVICE=1: the production entry. The production key |
| 25 | # source (TPM Slot 0) refuses, so the lifecycle comes up LOCKED with |
| 26 | # the NVMe kept bound, refuses every task and a bare unlock, still |
| 27 | # answers status/help/evidence, and shuts down in order. Booted a |
| 28 | # second and third time (P04 cut 1): `unlock <64-hex recovery secret>` |
| 29 | # runs the ADR 0017 Slot 1 keyslot path: genesis on the blank disk |
| 30 | # (K_vol from the entropy service, manifest committed with the boot |
| 31 | # record), a note approved and committed, shutdown; then on the SAME |
| 32 | # disk a wrong secret is refused by the keyslot tag and the right one |
| 33 | # unwraps K_vol and reopens the Store at the next generation. The |
| 34 | # secret is echoed as '*' and never appears in the serial log. |
| 35 | # testkeys make full CK_SERVICE=1 CK_SERVICE_TEST_KEYS=1 (TEST-ONLY): the |
| 36 | # Store opens with TEST keys so READY/SERVE run: a task is proposed, |
| 37 | # approve commits it to the Store, deny and cancel drop tasks, a |
| 38 | # second task while one is pending is refused, an overlong line is |
| 39 | # refused whole, evidence counts agree, shutdown closes the Store |
| 40 | # before the NVMe release before the final report. |
| 41 | # |
| 42 | # row 160 service image: lifecycle starts after mm_usage, state=locked, |
| 43 | # store=locked; the Store stage refused with BlockedOperator and |
| 44 | # kept the NVMe bound for a later unlock; no TEST key banner |
| 45 | # row 161 locked: task and a bare unlock REFUSED (state stays locked), |
| 46 | # status/help/evidence answered |
| 47 | # row 162 locked shutdown: stop order store=was-locked after the NVMe |
| 48 | # revoke, then stage result, then final report; no panic/fault; |
| 49 | # QEMU exit 0; M1 checks |
| 50 | # row 163 testkeys image: announces TEST-ONLY banner, Store open, NVMe kept |
| 51 | # bound for the service lifetime (no dma_gate revoke before ready) |
| 52 | # row 164 serve: task -> pending with the proposed note; approve -> committed |
| 53 | # with a Store generation and object id; state back to ready |
| 54 | # row 165 deny and cancel drop pending tasks; a second task while pending is |
| 55 | # refused; approve with nothing pending is refused |
| 56 | # row 166 bounds: a 145-byte line is refused whole and never run; evidence |
| 57 | # shows tasks=3 approved=1 denied=1 cancelled=1 overlong=1 |
| 58 | # row 167 stop order: store=closed, then dma_gate nvme bus master revoked, |
| 59 | # then smmu stream back to abort, then stage lifecycle ok, then the |
| 60 | # final report; QEMU exit 0; M1 checks |
| 61 | # row 167c operator input is the POLLED serial receive of the SPCR console |
| 62 | # UART: the ready line names it (`serial pl011 at 0x9000000, polled` |
| 63 | # on QEMU virt), and after the stop order `lifecycle: input |
| 64 | # uart=pl011 rx_errors=0 overruns=0 damaged_lines=0 overlong=1`; no |
| 65 | # `REFUSED console input` line (the 16550 path is host-tested only: |
| 66 | # QEMU virt has no memory-mapped 16550, see GATES.md row 167d) |
| 67 | # row 168 unlock genesis (service image, blank disk): `unlock deadbeef` refused |
| 68 | # (64 hex digits expected); `unlock <secret>` formats a production |
| 69 | # Store with the keyslot manifest (genesis=1, generation 2, boot 1), |
| 70 | # lifecycle ready, a note approved and committed, stop order closes |
| 71 | # row 169 unlock resume (same disk): wrong secret refused (RecoverySecretRejected, |
| 72 | # disk not reformatted, still locked); right secret unwraps K_vol, |
| 73 | # Store opened at generation 3 boot_count 1, committed generation 4 |
| 74 | # row 170 secret hygiene: the typed secret is echoed as 64 '*' and the hex |
| 75 | # never appears in either serial log; no TEST key banner |
| 76 | # row 171 P05 cut 1 continuity GENESIS (unlock boot, after `unlock ok`): the |
| 77 | # production continuity service provisions the identity (AgentRoot, |
| 78 | # AgentState, Manifest incarnation 1) and the ALLEN subject (sequence 1) |
| 79 | # in one transaction (generation 3); `status` reports continuity=provisioned |
| 80 | # row 172 P05 cut 1 continuity RESUME (relock boot): the subject is RESTORED |
| 81 | # (sequence 1), the identity RESUMED at incarnation 2 (generation 6) with |
| 82 | # the same agent id; no second genesis; status continuity=resumed |
| 83 | # row 173 shape: the locked boot prints no continuity line; the test-keys image |
| 84 | # provisions before `Store open`; the service image carries the |
| 85 | # production continuity layer and no TEST mode selection (AIENCONT) |
| 86 | # row 174 P06 cut 2 (boot 5, test-keys image built with CK_INFER_LIB, model over |
| 87 | # the TEST-ONLY fw_cfg channel, -m 4096): the model and one bounded |
| 88 | # session are resident from boot (`infer: resident open rc=0`, before |
| 89 | # `lifecycle: ready`); `prompt What is the capital of France?` generates |
| 90 | # the golden reply (ids 791 6864 315 9822 374 12366 13 128009, 17 |
| 91 | # prompt ids, 25 steps) which becomes the pending proposal; `approve` |
| 92 | # commits it as one sealed reply object (kind 'R1') |
| 93 | # row 175 `prompt Say hello.` then `cancel` stops generation between steps |
| 94 | # (steps >= 1, produced 0, state ready, nothing pending); `recall` reads |
| 95 | # the newest approved object back through the sealed Store (kind=reply, |
| 96 | # the prompt and "The capital of France is Paris."); boot 6 (same |
| 97 | # disk, cold boot): continuity RESUMED, `recall` answers from the disk |
| 98 | # row 176 evidence counters (prompts=2 replies=1 gen_cancelled=1 gen_failed=0 |
| 99 | # inference=resident); stop order: `infer: resident close` and |
| 100 | # `infer: unloaded` (every frame returned) before the stop order line; |
| 101 | # QEMU exit 0; M1 checks. Separate verdict AIENOS_CK_LIFECYCLE_INFER: |
| 102 | # NOT_RUN (never a silent pass) when the model file, cargo or the Rust |
| 103 | # target aarch64-unknown-none is missing; TCG needs ~25 min for it |
| 104 | # row 179 P06 cut 4 (test-keys boot 2): `remember prefer short notes` creates |
| 105 | # the Cortex journal (one sealed header transaction) and appends one |
| 106 | # CX_CLAIM record (one sealed transaction); `facts` in the same boot |
| 107 | # lists it with the chain verified; evidence counts remembers/facts; |
| 108 | # the journal closes (heap frames returned) before the stop order |
| 109 | # row 180 production genesis boot (boot 3): the same two verbs on the |
| 110 | # production Store after the approved note; stop order requests=9 |
| 111 | # row 181 cold production boot (boot 4): `facts` alone answers the fact from |
| 112 | # the disk (records=1, digest and chain re-verified at open); the fact |
| 113 | # is never typed in that boot; the Store opens at generation 6 (journal open at 8: |
| 114 | # note 4, journal header 5, fact 6, boot record 7, continuity resume 8) |
| 115 | # row 182 P04 cut 2a SecurityManifest, TEST-key Store (boot 2): the boot |
| 116 | # transaction commits `store: security manifest sequence=1 generation=2 |
| 117 | # keyslot=none previous=genesis` (no KeySlotManifest on a TEST Store) |
| 118 | # row 183 P04 cut 2a SecurityManifest, production Store: genesis (boot 3) |
| 119 | # `sequence=1 generation=2 keyslot=bound previous=genesis`; cold resume |
| 120 | # (boot 4) `sequence=2 generation=7 keyslot=bound previous=linked` (the |
| 121 | # manifest read back verified under K_root_auth, bound the keyslot the |
| 122 | # keyed open bound, carried key_epoch 1 and the manifest count) |
| 123 | # row 184 P04 cut 2b recovery secret rotation (boot 7, the boot-3 disk, so a |
| 124 | # second cold resume at generation 6): after `unlock <ok>` (boot |
| 125 | # record 7, continuity resume 8), `rotate <ok> <new>` proves |
| 126 | # possession of the current secret, then one transaction (generation |
| 127 | # 9) commits KeySlotManifest sequence 2 (K_vol re-wrapped under the |
| 128 | # new secret, linked to manifest 1) and SecurityManifest sequence 3 |
| 129 | # binding it; `lifecycle: rotate ok state=ready`; the typed line is |
| 130 | # echoed as 129 '*'; neither secret appears in the serial log |
| 131 | # row 185 P04 cut 2b after rotation (boot 8, the boot-7 disk): the old secret |
| 132 | # is refused by the keyslot tag (RecoverySecretRejected, disk not |
| 133 | # opened); the new secret opens the Store at generation 9, the keyed |
| 134 | # open binds the chain of two manifests, SecurityManifest sequence 4 |
| 135 | # links the rotation one (keyslot=bound previous=linked), continuity |
| 136 | # RESUMES incarnation 3; no SecurityManifest refusal |
| 137 | # build the default (diagnostic) image carries no lifecycle; CK_SERVICE is |
| 138 | # refused with CK_CONSOLE_SESSION, CK_QEMU_UNSAFE_DMA and a CK_TEST_* |
| 139 | # flag; CK_SERVICE_TEST_KEYS is refused with CK_HARDWARE_STAGING |
| 140 | set -euo pipefail |
| 141 | |
| 142 | repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 143 | cd "${repo_root}" |
| 144 | final_tag="AIENOS_CK_LIFECYCLE" |
| 145 | |
| 146 | code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" |
| 147 | vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" |
| 148 | command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; echo "${final_tag}: NOT_RUN (qemu-system-aarch64 missing)"; exit 2; } |
| 149 | [[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "AAVMF firmware not found"; echo "${final_tag}: NOT_RUN (AAVMF missing)"; exit 2; } |
| 150 | |
| 151 | cross="" |
| 152 | if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi |
| 153 | commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" |
| 154 | out="${repo_root}/target/native-kernel" |
| 155 | mk() { make -s -C native/kernel CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" "$@"; } |
| 156 | mk full >/dev/null |
| 157 | mk full CK_SERVICE=1 >/dev/null |
| 158 | mk full CK_SERVICE=1 CK_SERVICE_TEST_KEYS=1 >/dev/null |
| 159 | mk gpt-image >/dev/null |
| 160 | gpt_tool="${out}/host/ck_gpt_image" |
| 161 | default_efi="${out}/full/BOOTAA64.EFI" |
| 162 | service_efi="${out}/full-service/BOOTAA64.EFI" |
| 163 | testkeys_efi="${out}/full-service-testkeys/BOOTAA64.EFI" |
| 164 | |
| 165 | . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib_gate_hold.sh" |
| 166 | if ! gh_quiet_check; then echo "NOT_RUN ${gh_why}"; echo "${final_tag}: NOT_RUN (quiet flag held)"; exit 3; fi |
| 167 | if ! gh_lock_take qemu_ck_lifecycle_test "${AIENOS_GATE_MINUTES:-75}"; then echo "NOT_RUN ${gh_why}"; echo "${final_tag}: NOT_RUN (QEMU gate lock held)"; exit 3; fi |
| 168 | top="$(mktemp -d)" |
| 169 | qemu_pid="" |
| 170 | drain_pid="" |
| 171 | cleanup() { |
| 172 | [[ -z "${qemu_pid}" ]] || kill "${qemu_pid}" 2>/dev/null || true |
| 173 | [[ -z "${drain_pid}" ]] || kill "${drain_pid}" 2>/dev/null || true |
| 174 | exec 4>&- 2>/dev/null || true |
| 175 | rm -rf "${top}" |
| 176 | gh_lock_release |
| 177 | } |
| 178 | trap cleanup EXIT |
| 179 | |
| 180 | source "${repo_root}/scripts/lib_ck_m1_checks.sh" |
| 181 | boot_timeout="${AIENOS_QEMU_TIMEOUT:-600}" |
| 182 | boot_to="${boot_timeout}" # per boot; the inference boots raise it |
| 183 | boot_mem=2048 # MiB; the inference boots need the model in RAM |
| 184 | boot_extra=() # extra QEMU arguments (the fw_cfg model channel) |
| 185 | fail=0 |
| 186 | ok() { echo "ROW $1 PASS $2"; } |
| 187 | bad() { echo "ROW $1 FAIL $2"; fail=1; } |
| 188 | has() { grep -qE -- "$1" "${work}/serial.txt"; } |
| 189 | rcheck() { if has "$3"; then ok "$1" "$2"; else bad "$1" "$2"; fi; } |
| 190 | rabsent() { if has "$3"; then bad "$1" "$2 (present)"; else ok "$1" "$2"; fi; } |
| 191 | line_of() { { grep -nE -m1 -- "$1" "${work}/serial.txt" || true; } | cut -d: -f1; } |
| 192 | before() { local a b; a="$(line_of "$3")"; b="$(line_of "$4")" |
| 193 | if [[ -n "${a}" && -n "${b}" && "${a}" -lt "${b}" ]]; then ok "$1" "$2 (lines ${a} < ${b})"; else bad "$1" "$2 (lines ${a:-none} ${b:-none})"; fi; } |
| 194 | serial_has() { tr -d '\r' 2>/dev/null <"${work}/serial.log" | grep -qE -- "$1"; } |
| 195 | wait_for() { local deadline=$(( $(date +%s) + $1 )); shift |
| 196 | while (( $(date +%s) < deadline )); do for p in "$@"; do serial_has "${p}" && return 0; done |
| 197 | kill -0 "${qemu_pid}" 2>/dev/null || break; sleep 1; done |
| 198 | for p in "$@"; do serial_has "${p}" && return 0; done; return 1; } |
| 199 | ser_line() { printf '%s\r' "$1" >&4; sleep 1.2; } |
| 200 | ser_wait() { wait_for 180 "$1" '^report_kind: (panic|fault|final)' || true; } |
| 201 | # QEMU-only recovery secrets (public test values, 32 bytes as 64 hex; never a production secret) |
| 202 | secret_ok="000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" |
| 203 | secret_bad="000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1eff" |
| 204 | secret_new="202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f" |
| 205 | |
| 206 | boot() { # name efi driver [nvme.img to reuse] |
| 207 | work="${top}/$1" |
| 208 | mkdir -p "${work}/esp/EFI/BOOT" "${work}/esp/EFI/AIENOS" |
| 209 | touch "${work}/esp/EFI/AIENOS/BOOTREPORT.TXT" |
| 210 | cp "$2" "${work}/esp/EFI/BOOT/BOOTAA64.EFI" |
| 211 | cp "${vars_fd}" "${work}/vars.fd" |
| 212 | # GPT boot disk (tools/ck_gpt_image.c, as the Store gate): protective MBR, |
| 213 | # primary + backup GPT, sentinels, AIENOS partition all zero (Store at genesis). |
| 214 | if [[ -n "${4:-}" ]]; then cp "$4" "${work}/nvme.img"; else "${gpt_tool}" create "${work}/nvme.img" 512 64 aienos-middle >/dev/null; fi |
| 215 | mkfifo "${work}/ser.in" "${work}/ser.out" |
| 216 | : >"${work}/serial.log" |
| 217 | timeout "${boot_to}" qemu-system-aarch64 \ |
| 218 | -M virt,virtualization=on,gic-version=3,iommu=smmuv3 -accel tcg,thread=single -cpu max -smp 4 -m "${boot_mem}" \ |
| 219 | -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ |
| 220 | -drive if=pflash,format=raw,file="${work}/vars.fd" \ |
| 221 | -drive if=none,id=esp,format=raw,file=fat:rw:"${work}/esp" \ |
| 222 | -device virtio-blk-pci,drive=esp \ |
| 223 | -drive if=none,id=nvme0,format=raw,file="${work}/nvme.img" \ |
| 224 | -device nvme,drive=nvme0,serial=aienos-lifecycle-test \ |
| 225 | -device ramfb -display none -nic none -monitor none \ |
| 226 | -chardev pipe,id=ser,path="${work}/ser" -serial chardev:ser -no-reboot "${boot_extra[@]}" 2>"${work}/qemu.err" & |
| 227 | qemu_pid=$! |
| 228 | cat "${work}/ser.out" >>"${work}/serial.log" & |
| 229 | drain_pid=$! |
| 230 | exec 4>"${work}/ser.in" |
| 231 | if wait_for "${boot_to}" '^lifecycle: ready state=' '^report_kind: (panic|fault|final)' && serial_has '^lifecycle: ready state='; then |
| 232 | sleep 1 |
| 233 | "$3" |
| 234 | fi |
| 235 | wait_for 120 '^report_kind: (panic|fault|final)' || true |
| 236 | set +e; wait "${qemu_pid}"; qemu_status=$?; set -e |
| 237 | qemu_pid="" |
| 238 | exec 4>&- 2>/dev/null || true |
| 239 | wait "${drain_pid}" 2>/dev/null || true |
| 240 | drain_pid="" |
| 241 | tr -d '\r' <"${work}/serial.log" >"${work}/serial.txt" |
| 242 | [[ -z "${AIENOS_LOG_DIR:-}" ]] || cp "${work}/serial.txt" "${AIENOS_LOG_DIR}/qemu_ck_lifecycle_$1.log" |
| 243 | echo "== boot $1: qemu exit ${qemu_status}" |
| 244 | } |
| 245 | |
| 246 | drive_locked() { |
| 247 | ser_line status; ser_line "task write a note"; ser_line unlock; ser_line help; ser_line evidence; ser_line shutdown |
| 248 | } |
| 249 | drive_ready() { |
| 250 | ser_line status |
| 251 | ser_line "task draft the plan" |
| 252 | ser_line "task second while pending" |
| 253 | ser_line approve |
| 254 | ser_line approve |
| 255 | ser_line "task to be denied"; ser_line deny |
| 256 | ser_line "task to be cancelled"; ser_line cancel |
| 257 | ser_line "$(printf 'x%.0s' $(seq 145))" |
| 258 | ser_line "remember prefer short notes"; ser_wait '^lifecycle: (remembered|REFUSED verb=remember)' |
| 259 | ser_line facts; ser_wait '^lifecycle: (facts records=|facts none|REFUSED verb=facts)' |
| 260 | ser_line evidence |
| 261 | ser_line shutdown |
| 262 | } |
| 263 | |
| 264 | drive_unlock() { |
| 265 | ser_line "unlock deadbeef" |
| 266 | ser_line "unlock ${secret_ok}"; ser_wait '^(lifecycle: unlock ok|lifecycle: REFUSED verb=unlock)' |
| 267 | ser_line status |
| 268 | ser_line "task write a note"; ser_line approve; ser_wait '^lifecycle: (approve committed|REFUSED verb=approve)' |
| 269 | ser_line "remember prefer short notes"; ser_wait '^lifecycle: (remembered|REFUSED verb=remember)' |
| 270 | ser_line facts; ser_wait '^lifecycle: (facts records=|facts none|REFUSED verb=facts)' |
| 271 | ser_line evidence |
| 272 | ser_line shutdown |
| 273 | } |
| 274 | # P06 cut 2: the resident model answers a prompt, the reply is approved and |
| 275 | # committed, a second prompt is cancelled between steps, recall reads the disk. |
| 276 | infer_wait="${AIENOS_QEMU_INFER_WAIT:-1800}" |
| 277 | drive_infer() { |
| 278 | ser_line status |
| 279 | ser_line "prompt What is the capital of France?" |
| 280 | wait_for "${infer_wait}" '^lifecycle: (reply pending|generation cancelled|REFUSED verb=prompt)' '^report_kind: (panic|fault|final)' || true |
| 281 | ser_line approve; ser_wait '^lifecycle: (approve committed|REFUSED verb=approve)' |
| 282 | ser_line "prompt Say hello." |
| 283 | sleep 5 |
| 284 | ser_line cancel |
| 285 | wait_for 900 '^lifecycle: (generation cancelled|reply pending|REFUSED verb=prompt)' '^report_kind: (panic|fault|final)' || true |
| 286 | ser_line evidence |
| 287 | ser_line recall |
| 288 | ser_line shutdown |
| 289 | } |
| 290 | drive_infer_recall() { |
| 291 | ser_line status; ser_line recall; ser_line evidence; ser_line shutdown |
| 292 | } |
| 293 | drive_rotate() { |
| 294 | ser_line "unlock ${secret_ok}"; ser_wait '^(lifecycle: unlock ok|lifecycle: REFUSED verb=unlock)' |
| 295 | ser_line "rotate ${secret_ok} ${secret_new}"; ser_wait '^(lifecycle: rotate ok|lifecycle: REFUSED verb=rotate)' |
| 296 | ser_line status |
| 297 | ser_line evidence |
| 298 | ser_line shutdown |
| 299 | } |
| 300 | drive_rotated() { |
| 301 | ser_line "unlock ${secret_ok}"; ser_wait '^(lifecycle: unlock ok|lifecycle: REFUSED verb=unlock)' |
| 302 | ser_line status |
| 303 | ser_line "unlock ${secret_new}"; ser_wait '^(lifecycle: unlock ok|lifecycle: REFUSED verb=unlock)' |
| 304 | ser_line status |
| 305 | ser_line facts; ser_wait '^lifecycle: (facts records=|facts none|REFUSED verb=facts)' |
| 306 | ser_line evidence |
| 307 | ser_line shutdown |
| 308 | } |
| 309 | drive_relock() { |
| 310 | ser_line "unlock ${secret_bad}"; ser_wait '^(lifecycle: unlock ok|lifecycle: REFUSED verb=unlock)' |
| 311 | ser_line status |
| 312 | ser_line "unlock ${secret_ok}"; ser_wait '^(lifecycle: unlock ok|lifecycle: REFUSED verb=unlock)' |
| 313 | ser_line status |
| 314 | ser_line facts; ser_wait '^lifecycle: (facts records=|facts none|REFUSED verb=facts)' |
| 315 | ser_line evidence |
| 316 | ser_line shutdown |
| 317 | } |
| 318 | |
| 319 | m1() { # row: the shared M1 checks read ${work}/serial.txt and set failed |
| 320 | failed=0 |
| 321 | ck_m1_checks >"${work}/m1.txt" 2>&1 || true |
| 322 | if [[ "${failed}" == 0 ]]; then ok "$1" "M1 checks"; else bad "$1" "M1 checks: $(grep -E "^FAIL" "${work}/m1.txt" | head -3 | tr "\n" " ")"; fi |
| 323 | } |
| 324 | |
| 325 | # --- build-shape checks --- |
| 326 | if grep -aqF "lifecycle: ready" "${default_efi}"; then bad build "default image carries the resident lifecycle"; else ok build "default image carries no resident lifecycle"; fi |
| 327 | if grep -aqF "TEST-ONLY service image" "${service_efi}"; then bad build "production service image carries the TEST key banner"; else ok build "production service image carries no TEST key banner"; fi |
| 328 | if grep -aqF "continuity: REFUSED" "${service_efi}" && ! grep -aqF "AIENCONT" "${service_efi}" && ! grep -aqF "RECOVERY_OPERATOR_KEY" "${service_efi}"; then ok 173 "service image carries the production continuity layer and no TEST mode selection"; else bad 173 "service image continuity shape wrong (layer missing, or AIENCONT / TEST operator key present)"; fi |
| 329 | for combo in "CK_CONSOLE_SESSION=1" "CK_QEMU_UNSAFE_DMA=1" "CK_TEST_STORE_CRASH=1"; do |
| 330 | set +e; msg="$(make -s -n -C native/kernel OUT="${top}/refuse" full CK_SERVICE=1 "${combo}" 2>&1)"; st=$?; set -e |
| 331 | if [[ "${st}" != 0 ]] && grep -qE "CK_SERVICE cannot be combined with" <<<"${msg}"; then ok build "refuses CK_SERVICE with ${combo}"; else bad build "did not refuse CK_SERVICE with ${combo} (status ${st})"; fi |
| 332 | done |
| 333 | set +e; msg="$(make -s -n -C native/kernel OUT="${top}/refuse" full CK_SERVICE=1 CK_SERVICE_TEST_KEYS=1 CK_HARDWARE_STAGING=1 2>&1)"; st=$?; set -e |
| 334 | if [[ "${st}" != 0 ]] && grep -qF "CK_SERVICE_TEST_KEYS (TEST keys) cannot be combined with CK_HARDWARE_STAGING" <<<"${msg}"; then ok build "refuses TEST keys with CK_HARDWARE_STAGING"; else bad build "did not refuse TEST keys with CK_HARDWARE_STAGING (status ${st})"; fi |
| 335 | |
| 336 | # --- boot 1: production service image, LOCKED --- |
| 337 | boot service "${service_efi}" drive_locked |
| 338 | before 160 "lifecycle after mm_usage" '^mm_usage: ' '^lifecycle: ready state=locked store=locked' |
| 339 | rcheck 160 "Store stage refused with the production key source (BlockedOperator), disk not read" '^store: REFUSED proof=keyed step="production Store key source" rc=-2002 \(service image stays LOCKED' |
| 340 | rcheck 160 "Store LOCKED keeps the NVMe bound for a later unlock" '^store: service lifetime: Store LOCKED, NVMe stays bound for `unlock <64-hex recovery secret>` or the lifecycle stop order$' |
| 341 | if [[ -n "$(line_of '^dma_gate: nvme bus master revoked')" && "$(line_of '^dma_gate: nvme bus master revoked')" -lt "$(line_of '^lifecycle: ready state=locked')" ]]; then bad 160 "NVMe revoked before the locked lifecycle (unlock would have no disk)"; else ok 160 "no NVMe revoke before the locked lifecycle"; fi |
| 342 | rabsent 160 "no TEST key banner" 'TEST-ONLY service image' |
| 343 | rcheck 161 "task refused while locked" '^lifecycle: REFUSED verb=task state=locked reason="locked: no production Store"' |
| 344 | rcheck 161 "unlock refused, still locked" '^lifecycle: REFUSED verb=unlock state=locked reason="production key source refused: still locked"' |
| 345 | rcheck 161 "unlock asked the production key source again" '^store: unlock REFUSED proof=keyed step="production Store key source" rc=-2002' |
| 346 | rcheck 161 "status answered" '^lifecycle: state=locked store=locked pending=- requests=' |
| 347 | rcheck 161 "help answered" '^lifecycle: verbs: status unlock \[<64-hex recovery secret>\] rotate <current 64-hex> <new 64-hex> task <text> prompt <text> approve deny cancel recall remember <text> prefer <text> facts update evidence help shutdown$' |
| 348 | rcheck 161 "evidence answered" '^lifecycle: evidence requests=5 refused=2 invalid=0 tasks=0 approved=0' |
| 349 | rcheck 162 "stop order with no Store" '^lifecycle: stop order store=was-locked nvme=released state=stop requests=6$' |
| 350 | before 162 "locked lifecycle ready < NVMe revoke (revoke only at the stop order)" '^lifecycle: ready state=locked' '^dma_gate: nvme bus master revoked' |
| 351 | before 162 "NVMe revoke < stop order line" '^dma_gate: nvme bus master revoked' '^lifecycle: stop order store=was-locked' |
| 352 | before 162 "stop order < stage result" '^lifecycle: stop order' '^stage lifecycle: ok rc=0$' |
| 353 | before 162 "stage result < final report" '^stage lifecycle: ok rc=0$' '^report_kind: final' |
| 354 | rabsent 162 "no panic or fault" '^report_kind: (panic|fault)' |
| 355 | rabsent 173 "no continuity line while locked" '^(continuity|allen): ' |
| 356 | if [[ "${qemu_status}" == 0 ]]; then ok 162 "QEMU exit 0"; else bad 162 "QEMU exit ${qemu_status}"; fi |
| 357 | m1 162 |
| 358 | |
| 359 | # --- boot 2: TEST-ONLY test-keys image, READY/SERVE --- |
| 360 | boot testkeys "${testkeys_efi}" drive_ready |
| 361 | rcheck 163 "TEST-ONLY banner" '^lifecycle: TEST-ONLY service image \(CK_SERVICE_TEST_KEYS=1: TEST Store keys; QEMU only, never a production boot\)$' |
| 362 | rcheck 163 "Store open, NVMe kept bound for the service lifetime" '^store: service lifetime: Store open, NVMe stays bound until the lifecycle stop order$' |
| 363 | rcheck 163 "lifecycle ready" '^lifecycle: ready state=ready store=open \(operator input: serial pl011 at 0x9000000, polled\)$' |
| 364 | rcheck 182 "TEST-key Store: security manifest sequence 1 at genesis, no keyslot" '^store: security manifest sequence=1 generation=2 keyslot=none previous=genesis$' |
| 365 | rcheck 173 "test-keys image provisions continuity at boot" '^continuity: PROVISIONED agent=[0-9a-f]{64} incarnation=1 sequence=1 cortex=0 branches=1$' |
| 366 | before 173 "PROVISIONED < Store open line" '^continuity: PROVISIONED' '^store: service lifetime: Store open' |
| 367 | if [[ -n "$(line_of '^dma_gate: nvme bus master revoked')" && "$(line_of '^dma_gate: nvme bus master revoked')" -lt "$(line_of '^lifecycle: ready state=ready')" ]]; then bad 163 "NVMe revoked before the lifecycle (service lifetime broken)"; else ok 163 "no NVMe revoke before the lifecycle"; fi |
| 368 | rcheck 164 "task proposed" '^lifecycle: task pending state=serve proposed="note: draft the plan" \(approve \| deny \| cancel\)$' |
| 369 | rcheck 164 "approve committed to the Store" '^lifecycle: approve committed gen=[0-9]+ id=[0-9a-f]{8} state=ready$' |
| 370 | rcheck 165 "second task while pending refused" '^lifecycle: REFUSED verb=task state=serve reason="a task is pending: approve, deny or cancel it first"' |
| 371 | rcheck 165 "approve with nothing pending refused" '^lifecycle: REFUSED verb=approve state=ready reason="nothing pending"' |
| 372 | rcheck 165 "deny drops" '^lifecycle: denied state=ready$' |
| 373 | rcheck 165 "cancel drops" '^lifecycle: cancelled state=ready$' |
| 374 | rcheck 166 "overlong line refused whole" '^lifecycle: REFUSED verb=invalid reason="line longer than 144 bytes"$' |
| 375 | rcheck 166 "evidence counts" '^lifecycle: evidence requests=12 refused=2 invalid=0 tasks=3 approved=1 denied=1 cancelled=1 overlong=1 last_commit_gen=[0-9]+ last_id=[0-9a-f]{8} prompts=0 replies=0 gen_cancelled=0 gen_failed=0 recalls=0 inference=none remembers=1 facts=1 cortex=open records=1$' |
| 376 | rcheck 167 "stop order closed the Store" '^lifecycle: stop order store=closed nvme=released state=stop requests=13$' |
| 377 | rcheck 167c "input counters after the stop order (PL011, polled)" '^lifecycle: input uart=pl011 rx_errors=0 overruns=0 damaged_lines=0 overlong=1 dropped=[0-9]+$' |
| 378 | before 167c "stop order line < input counters" '^lifecycle: stop order store=closed' '^lifecycle: input uart=pl011 ' |
| 379 | rabsent 167c "no console-input refusal on QEMU virt" '^lifecycle: REFUSED console input' |
| 380 | rcheck 179 "remember created the journal (header transaction, no records yet)" '^lifecycle: cortex open records=0 chunks=1 journal_bytes=32 store_gen=[0-9]+ heap_used_kib=[0-9]+ chain=ok$' |
| 381 | rcheck 179 "remembered as record 1 (one sealed transaction)" '^lifecycle: remembered id=1 t=1 store_gen=[0-9]+ bytes=18 text="prefer short notes"$' |
| 382 | rcheck 179 "facts lists the fact in the same boot" '^lifecycle: fact id=1 t=1 store_gen=[0-9]+ text="prefer short notes"$' |
| 383 | rcheck 179 "facts summary, chain verified" '^lifecycle: facts records=1 shown=1 journal_bytes=192 chain=ok$' |
| 384 | rcheck 179 "journal closed first in the stop order" '^lifecycle: cortex closed records=1 appends=2 reads=[0-9]+ refused=0 heap_peak_kib=[0-9]+$' |
| 385 | before 179 "cortex closed < stop order line" '^lifecycle: cortex closed' '^lifecycle: stop order store=closed' |
| 386 | rabsent 179 "no refusal of remember or facts" '^lifecycle: REFUSED verb=(remember|facts)' |
| 387 | before 167 "lifecycle ready < NVMe revoke (revoke only at the stop order)" '^lifecycle: ready state=ready' '^dma_gate: nvme bus master revoked' |
| 388 | before 167 "NVMe revoke < stop order line" '^dma_gate: nvme bus master revoked' '^lifecycle: stop order store=closed' |
| 389 | before 167 "stop order < stage result" '^lifecycle: stop order store=closed' '^stage lifecycle: ok rc=0$' |
| 390 | before 167 "stage result < final report" '^stage lifecycle: ok rc=0$' '^report_kind: final' |
| 391 | rabsent 167 "no panic or fault" '^report_kind: (panic|fault)' |
| 392 | if [[ "${qemu_status}" == 0 ]]; then ok 167 "QEMU exit 0"; else bad 167 "QEMU exit ${qemu_status}"; fi |
| 393 | m1 167 |
| 394 | |
| 395 | # --- boot 3: production service image, blank disk, recovery keyslot GENESIS --- |
| 396 | boot unlock "${service_efi}" drive_unlock |
| 397 | rcheck 168 "lifecycle came up locked" '^lifecycle: ready state=locked store=locked' |
| 398 | rcheck 168 "short secret refused (64 hex digits expected)" '^store: unlock REFUSED proof=keyed step="recovery secret syntax" rc=-2004 \(64 hex digits expected, got 8\)$' |
| 399 | rcheck 168 "blank disk formatted as a production store" '^store: blank disk \(all-zero anchor \+ Store head\): formatted production store$' |
| 400 | rcheck 168 "key source line: recovery keyslot genesis" '^store: key source=recovery-keyslot genesis=1 \(K_vol source: the Slot 1 recovery descriptor; TPM Slot 0 BLOCKED_HARDWARE; no rotation\)$' |
| 401 | rcheck 168 "store committed generation 2 boot 1" '^store: committed generation=2 boot_count=1$' |
| 402 | rcheck 183 "production genesis: security manifest sequence 1 binds the keyslot" '^store: security manifest sequence=1 generation=2 keyslot=bound previous=genesis$' |
| 403 | rcheck 168 "unlock ok" '^store: unlock ok source=recovery-keyslot slot=1 genesis=1 generation=2 boot_count=1$' |
| 404 | rcheck 168 "lifecycle unlocked to ready" '^lifecycle: unlock ok state=ready$' |
| 405 | rcheck 168 "status open" '^lifecycle: state=ready store=open pending=- requests=' |
| 406 | rcheck 168 "task proposed" '^lifecycle: task pending state=serve proposed="note: write a note" \(approve \| deny \| cancel\)$' |
| 407 | rcheck 168 "approve committed generation 4 (after the continuity genesis at 3)" '^lifecycle: approve committed gen=4 id=[0-9a-f]{8} state=ready$' |
| 408 | rcheck 171 "genesis inputs declared" '^continuity: genesis source=qualification provenance=store-uuid-only \(identity and ALLEN subject in one transaction\)$' |
| 409 | rcheck 171 "identity PROVISIONED incarnation 1" '^continuity: PROVISIONED agent=[0-9a-f]{64} incarnation=1 sequence=1 cortex=0 branches=1$' |
| 410 | rcheck 171 "ALLEN subject GENESIS sequence 1" '^allen: GENESIS subject=[0-9a-f]{64} sequence=1 lineage=[0-9a-f]{64} intents=0 active=0 knowledge=0$' |
| 411 | before 171 "unlock ok < PROVISIONED" '^store: unlock ok' '^continuity: PROVISIONED' |
| 412 | before 171 "PROVISIONED < lifecycle unlock ok" '^continuity: PROVISIONED' '^lifecycle: unlock ok' |
| 413 | rcheck 171 "status reports continuity" '^lifecycle: state=ready store=open pending=- requests=[0-9]+ continuity=provisioned agent=[0-9a-f]{16} incarnation=1 subject_seq=1$' |
| 414 | unlock_agent="$(grep -oE '^continuity: PROVISIONED agent=[0-9a-f]{64}' "${top}/unlock/serial.txt" | head -1 | sed 's/.*agent=//')" |
| 415 | [[ -n "${unlock_agent}" ]] || unlock_agent="NO_AGENT" |
| 416 | rcheck 168 "stop order closed the Store" '^lifecycle: stop order store=closed nvme=released state=stop requests=9$' |
| 417 | rcheck 180 "production Store: journal created after the note (header at generation 5)" '^lifecycle: cortex open records=0 chunks=1 journal_bytes=32 store_gen=5 heap_used_kib=[0-9]+ chain=ok$' |
| 418 | rcheck 180 "production Store: fact committed at generation 6" '^lifecycle: remembered id=1 t=1 store_gen=6 bytes=18 text="prefer short notes"$' |
| 419 | rcheck 180 "production Store: facts lists it" '^lifecycle: facts records=1 shown=1 journal_bytes=192 chain=ok$' |
| 420 | rcheck 180 "evidence counts the two verbs" '^lifecycle: evidence requests=8 refused=1 invalid=0 tasks=1 approved=1 denied=0 cancelled=0 overlong=0 last_commit_gen=4 last_id=[0-9a-f]{8} prompts=0 replies=0 gen_cancelled=0 gen_failed=0 recalls=0 inference=none remembers=1 facts=1 cortex=open records=1$' |
| 421 | rabsent 180 "no refusal of remember or facts" '^lifecycle: REFUSED verb=(remember|facts)' |
| 422 | before 168 "stop order < stage result" '^lifecycle: stop order store=closed' '^stage lifecycle: ok rc=0$' |
| 423 | rabsent 168 "no panic or fault" '^report_kind: (panic|fault)' |
| 424 | if [[ "${qemu_status}" == 0 ]]; then ok 168 "QEMU exit 0"; else bad 168 "QEMU exit ${qemu_status}"; fi |
| 425 | m1 168 |
| 426 | rabsent 170 "secret hex never in the serial log (genesis boot)" "${secret_ok}" |
| 427 | rcheck 170 "typed secret echoed as 64 '*'" '^> unlock \*{64}$' |
| 428 | rabsent 170 "no TEST key banner" 'TEST-ONLY service image' |
| 429 | unlock_img="${top}/unlock/nvme.img" |
| 430 | |
| 431 | # --- boot 4: same disk, wrong secret refused, right secret resumes --- |
| 432 | boot relock "${service_efi}" drive_relock "${unlock_img}" |
| 433 | rcheck 169 "lifecycle came up locked" '^lifecycle: ready state=locked store=locked' |
| 434 | rcheck 169 "wrong secret refused by the keyslot tag" '^store: unlock REFUSED proof=keyed step="recovery secret rejected \(K_vol unwrap tag failed\); disk not opened" rc=-2004 \(RecoverySecretRejected\); still LOCKED, disk not reformatted$' |
| 435 | rcheck 169 "lifecycle still locked after the wrong secret" '^lifecycle: REFUSED verb=unlock state=locked reason="production key source refused: still locked"$' |
| 436 | rcheck 169 "status still locked" '^lifecycle: state=locked store=locked pending=- requests=2 continuity=none$' |
| 437 | rabsent 169 "not reformatted" '^store: blank disk' |
| 438 | rcheck 169 "key source line: recovery keyslot resume" '^store: key source=recovery-keyslot genesis=0 ' |
| 439 | rcheck 169 "store opened at generation 6 (keyslot + boot record + continuity genesis + note + journal header + fact), boot_count 1" '^store: opened generation=6 boot_count=1 prev_commit=[0-9a-f]+ anchor=valid-resume$' |
| 440 | rcheck 169 "store committed generation 7 boot 2" '^store: committed generation=7 boot_count=2$' |
| 441 | rcheck 183 "production resume: security manifest sequence 2 links the genesis one, keyslot bound" '^store: security manifest sequence=2 generation=7 keyslot=bound previous=linked$' |
| 442 | rabsent 183 "no SecurityManifest refusal in any boot" '^store: (unlock )?REFUSED proof=keyed step="SecurityManifest' |
| 443 | rcheck 169 "unlock ok, no genesis" '^store: unlock ok source=recovery-keyslot slot=1 genesis=0 generation=7 boot_count=2$' |
| 444 | rcheck 172 "ALLEN subject RESTORED sequence 1" '^allen: RESTORED subject=[0-9a-f]{64} sequence=1 lineage=[0-9a-f]{64} intents=0 active=0 knowledge=0$' |
| 445 | rcheck 172 "identity RESUMED incarnation 2, same agent as the genesis boot" "^continuity: RESUMED agent=${unlock_agent} incarnation=2 sequence=2 cortex=0 branches=1\$" |
| 446 | rabsent 172 "no second genesis" '^continuity: (PROVISIONED|genesis)' |
| 447 | rabsent 172 "no degraded mount" '^continuity: (degraded|RESUMED_READONLY|REFUSED)' |
| 448 | before 172 "unlock ok < RESUMED" '^store: unlock ok' '^continuity: RESUMED' |
| 449 | before 172 "RESUMED < lifecycle unlock ok" '^continuity: RESUMED' '^lifecycle: unlock ok' |
| 450 | rcheck 172 "status reports resumed" "^lifecycle: state=ready store=open pending=- requests=[0-9]+ continuity=resumed agent=${unlock_agent:0:16} incarnation=2 subject_seq=1\$" |
| 451 | rcheck 169 "lifecycle unlocked to ready" '^lifecycle: unlock ok state=ready$' |
| 452 | rcheck 169 "evidence: one refused unlock" '^lifecycle: evidence requests=6 refused=1 invalid=0 tasks=0 approved=0' |
| 453 | rcheck 169 "stop order closed the Store" '^lifecycle: stop order store=closed nvme=released state=stop requests=7$' |
| 454 | rcheck 181 "cold boot: journal opened from the disk, chain verified (1 record, 2 chunks)" '^lifecycle: cortex open records=1 chunks=2 journal_bytes=192 store_gen=8 heap_used_kib=[0-9]+ chain=ok$' |
| 455 | rcheck 181 "cold boot: the fact answers from the disk, not restated" '^lifecycle: fact id=1 t=1 store_gen=6 text="prefer short notes"$' |
| 456 | rcheck 181 "cold boot: facts summary" '^lifecycle: facts records=1 shown=1 journal_bytes=192 chain=ok$' |
| 457 | rabsent 181 "cold boot: the fact was never typed in this boot" '^> remember ' |
| 458 | rabsent 181 "cold boot: nothing remembered in this boot" '^lifecycle: remembered ' |
| 459 | rcheck 181 "cold boot: evidence shows facts only" '^lifecycle: evidence requests=6 refused=1 invalid=0 tasks=0 approved=0 denied=0 cancelled=0 overlong=0 last_commit_gen=0 last_id=00000000 prompts=0 replies=0 gen_cancelled=0 gen_failed=0 recalls=0 inference=none remembers=0 facts=1 cortex=open records=1$' |
| 460 | rcheck 181 "cold boot: journal closed before the stop order" '^lifecycle: cortex closed records=1 appends=0 reads=[0-9]+ refused=0 heap_peak_kib=[0-9]+$' |
| 461 | before 181 "cold boot: cortex closed < stop order" '^lifecycle: cortex closed' '^lifecycle: stop order store=closed' |
| 462 | rabsent 169 "no panic or fault" '^report_kind: (panic|fault)' |
| 463 | if [[ "${qemu_status}" == 0 ]]; then ok 169 "QEMU exit 0"; else bad 169 "QEMU exit ${qemu_status}"; fi |
| 464 | m1 169 |
| 465 | rabsent 170 "secret hex never in the serial log (resume boot)" "${secret_ok}" |
| 466 | rabsent 170 "wrong secret hex never in the serial log" "${secret_bad}" |
| 467 | |
| 468 | # --- boot 7 (runs right after boot 4): same disk, rotate the recovery secret (P04 cut 2b) --- |
| 469 | boot rotate "${service_efi}" drive_rotate "${unlock_img}" |
| 470 | rcheck 184 "lifecycle came up locked" '^lifecycle: ready state=locked store=locked' |
| 471 | rcheck 184 "store opened at generation 6 (the boot-3 disk), boot_count 1" '^store: opened generation=6 boot_count=1 prev_commit=[0-9a-f]+ anchor=valid-resume$' |
| 472 | rcheck 184 "boot transaction: security manifest sequence 2" '^store: security manifest sequence=2 generation=7 keyslot=bound previous=linked$' |
| 473 | rcheck 184 "unlock ok with the current secret" '^store: unlock ok source=recovery-keyslot slot=1 genesis=0 generation=7 boot_count=2$' |
| 474 | rcheck 184 "continuity RESUMED incarnation 2" "^continuity: RESUMED agent=${unlock_agent} incarnation=2 sequence=2 cortex=0 branches=1\$" |
| 475 | rcheck 184 "rotation committed: KeySlotManifest sequence 2, SecurityManifest sequence 3, one generation (9)" '^store: rotated recovery keyslot manifest_sequence=2 security_sequence=3 generation=9 \(previous secret retired\)$' |
| 476 | rcheck 184 "lifecycle rotate ok, state ready" '^lifecycle: rotate ok state=ready$' |
| 477 | rabsent 184 "rotate not refused" '^(lifecycle: REFUSED verb=rotate|store: rotate REFUSED)' |
| 478 | rcheck 184 "typed rotate line echoed as 129 '*'" '^> rotate \*{129}$' |
| 479 | rcheck 184 "status ready after rotation" "^lifecycle: state=ready store=open pending=- requests=3 continuity=resumed agent=${unlock_agent:0:16} incarnation=2 subject_seq=1\$" |
| 480 | rcheck 184 "stop order closed the Store" '^lifecycle: stop order store=closed nvme=released state=stop requests=[0-9]+$' |
| 481 | rabsent 184 "no panic or fault" '^report_kind: (panic|fault)' |
| 482 | if [[ "${qemu_status}" == 0 ]]; then ok 184 "QEMU exit 0"; else bad 184 "QEMU exit ${qemu_status}"; fi |
| 483 | m1 184 |
| 484 | rabsent 184 "current secret hex never in the serial log (rotation boot)" "${secret_ok}" |
| 485 | rabsent 184 "new secret hex never in the serial log (rotation boot)" "${secret_new}" |
| 486 | rotate_img="${top}/rotate/nvme.img" |
| 487 | |
| 488 | # --- boot 8 (before the inference boots 5 and 6): same disk, the old secret is retired, the new one resumes --- |
| 489 | boot rotated "${service_efi}" drive_rotated "${rotate_img}" |
| 490 | rcheck 185 "lifecycle came up locked" '^lifecycle: ready state=locked store=locked' |
| 491 | rcheck 185 "old secret refused by the keyslot tag of the newest manifest" '^store: unlock REFUSED proof=keyed step="recovery secret rejected \(K_vol unwrap tag failed\); disk not opened" rc=-2004 \(RecoverySecretRejected\); still LOCKED, disk not reformatted$' |
| 492 | rcheck 185 "lifecycle still locked after the old secret" '^lifecycle: REFUSED verb=unlock state=locked reason="production key source refused: still locked"$' |
| 493 | rcheck 185 "status still locked" '^lifecycle: state=locked store=locked pending=- requests=2 continuity=none$' |
| 494 | rcheck 185 "store opened at generation 9 (rotation committed), boot_count 2" '^store: opened generation=9 boot_count=2 prev_commit=[0-9a-f]+ anchor=valid-resume$' |
| 495 | rcheck 185 "security manifest sequence 4 links the rotation one, keyslot bound" '^store: security manifest sequence=4 generation=10 keyslot=bound previous=linked$' |
| 496 | rabsent 185 "no SecurityManifest refusal after rotation" '^store: (unlock )?REFUSED proof=keyed step="SecurityManifest' |
| 497 | rcheck 185 "new secret unlock ok, no genesis" '^store: unlock ok source=recovery-keyslot slot=1 genesis=0 generation=10 boot_count=3$' |
| 498 | rcheck 185 "continuity RESUMED incarnation 3" "^continuity: RESUMED agent=${unlock_agent} incarnation=3 sequence=3 cortex=0 branches=1\$" |
| 499 | rabsent 185 "no second genesis" '^continuity: (PROVISIONED|genesis)' |
| 500 | rabsent 185 "not reformatted" '^store: blank disk' |
| 501 | rcheck 185 "lifecycle unlocked to ready" '^lifecycle: unlock ok state=ready$' |
| 502 | rcheck 185 "the fact still answers from the disk after rotation" '^lifecycle: fact id=1 t=1 store_gen=6 text="prefer short notes"$' |
| 503 | rcheck 185 "evidence: one refused unlock" '^lifecycle: evidence requests=6 refused=1 invalid=0 ' |
| 504 | rcheck 185 "stop order closed the Store" '^lifecycle: stop order store=closed nvme=released state=stop requests=7$' |
| 505 | rabsent 185 "no panic or fault" '^report_kind: (panic|fault)' |
| 506 | if [[ "${qemu_status}" == 0 ]]; then ok 185 "QEMU exit 0"; else bad 185 "QEMU exit ${qemu_status}"; fi |
| 507 | m1 185 |
| 508 | rabsent 185 "old secret hex never in the serial log (post-rotation boot)" "${secret_ok}" |
| 509 | rabsent 185 "new secret hex never in the serial log (post-rotation boot)" "${secret_new}" |
| 510 | |
| 511 | # --- boots 5 and 6: test-keys image with the resident inference session (P06 cut 2) --- |
| 512 | infer_tag="AIENOS_CK_LIFECYCLE_INFER" |
| 513 | infer_boots="" |
| 514 | model="${AIENOS_MODEL:-${HOME}/models/aien-mail/Llama-3.2-1B-Instruct-Q4_K_M.gguf}" |
| 515 | infer_notrun="" |
| 516 | [[ -r "${model}" ]] || infer_notrun="model file ${model} missing" |
| 517 | [[ -n "${infer_notrun}" ]] || command -v cargo >/dev/null || infer_notrun="cargo not installed" |
| 518 | if [[ -z "${infer_notrun}" ]] && { ! rustc --print target-list 2>/dev/null | grep -qx aarch64-unknown-none \ |
| 519 | || ! [[ -d "$(rustc --print sysroot)/lib/rustlib/aarch64-unknown-none/lib" ]]; }; then |
| 520 | infer_notrun="Rust target aarch64-unknown-none not installed (rustup target add aarch64-unknown-none)" |
| 521 | fi |
| 522 | [[ -z "${AIENOS_LIFECYCLE_SKIP_INFER:-}" ]] || infer_notrun="AIENOS_LIFECYCLE_SKIP_INFER set" |
| 523 | if [[ -n "${infer_notrun}" ]]; then |
| 524 | echo "${infer_tag}: NOT_RUN (${infer_notrun})" |
| 525 | else |
| 526 | fail_before_infer="${fail}" |
| 527 | lib="${repo_root}/target/infer-kernel/aarch64-unknown-none/release/libaienos_infer_kernel.a" |
| 528 | CARGO_TARGET_DIR="${repo_root}/target/infer-kernel" cargo build -q --release --target aarch64-unknown-none \ |
| 529 | --manifest-path crates/aienos-infer-kernel/Cargo.toml |
| 530 | out_infer="${out}-lifecycle-infer" # own OUT: same FULL_NAME as the plain test-keys image |
| 531 | make -s -C native/kernel CROSS="${cross}" OUT="${out_infer}" AIENOS_COMMIT="${commit}" full CK_SERVICE=1 CK_SERVICE_TEST_KEYS=1 CK_INFER_LIB="${lib}" >/dev/null |
| 532 | infer_efi="${out_infer}/full-service-testkeys/BOOTAA64.EFI" |
| 533 | if grep -aqF "infer: resident open" "${infer_efi}" && ! grep -aqF "infer: resident open" "${testkeys_efi}"; then ok 174 "only the CK_INFER_LIB service image carries the resident session"; else bad 174 "resident session shape wrong (missing from the inference image, or present in the plain test-keys image)"; fi |
| 534 | re_open='^infer: resident open rc=0 tensors=147 vocab=128256 layers=16 kv_capacity=1024 max_new=256 max_prompt_bytes=752 heap_reserve_kib=64 heap_used_kib=[0-9]+ open_us=[0-9]+$' |
| 535 | re_recall='^lifecycle: recall gen=[0-9]+ kind=reply id=[0-9a-f]{8} bytes=[0-9]+ text="aienos\.reply\.v1.prompt: What is the capital of France\?.reply: The capital of France is Paris\.' |
| 536 | frames_kept() { # row label: the unload line returned every frame (free after = free before) |
| 537 | local l b a; l="$(grep -E -m1 '^infer: unloaded ' "${work}/serial.txt" || true)" |
| 538 | b="$(sed -nE 's/.* frames_free_before=([0-9]+).*/\1/p' <<<"${l}")"; a="$(sed -nE 's/.* frames_free_after=([0-9]+).*/\1/p' <<<"${l}")" |
| 539 | if [[ -n "${b}" && "${b}" == "${a}" ]] && grep -qE '^infer: unloaded .* rc=0,0$' <<<"${l}"; then ok "$1" "$2 (${b} = ${a})"; else bad "$1" "$2 (before=${b:-none} after=${a:-none})"; fi; } |
| 540 | boot_to="${AIENOS_QEMU_INFER_TIMEOUT:-2700}"; boot_mem=4096; boot_extra=(-fw_cfg "name=opt/aienos/model,file=${model}") |
| 541 | boot infer "${infer_efi}" drive_infer |
| 542 | infer_boots="infer" |
| 543 | rcheck 174 "TEST-ONLY fw_cfg model source declared" '^infer_source_mode: TEST-ONLY QEMU fw_cfg model ingest' |
| 544 | rcheck 174 "resident session open with the declared limits" "${re_open}" |
| 545 | before 174 "resident open < lifecycle ready" '^infer: resident open rc=0' '^lifecycle: ready state=ready store=open' |
| 546 | rcheck 174 "TEST-ONLY banner" '^lifecycle: TEST-ONLY service image' |
| 547 | rcheck 174 "generating line" '^lifecycle: generating prompt="What is the capital of France\?" \(cancel stops it between steps\)$' |
| 548 | rcheck 174 "golden reply ids (17 prompt ids, 25 steps)" '^lifecycle: reply ids=791 6864 315 9822 374 12366 13 128009 tokens=8 prompt_ids=17 steps=25 us=[0-9]+$' |
| 549 | rcheck 174 "reply is the pending proposal" '^lifecycle: reply pending state=serve proposed="reply: The capital of France is Paris\.\??" \(approve \| deny \| cancel\)$' |
| 550 | rcheck 174 "approve committed the reply object" '^lifecycle: approve committed gen=[0-9]+ id=[0-9a-f]{8} state=ready$' |
| 551 | rcheck 175 "second prompt cancelled between steps (produced 0, nothing pending)" '^lifecycle: generation cancelled steps=[1-9][0-9]* prompt_ids=[0-9]+ produced=0 us=[0-9]+ state=ready$' |
| 552 | rabsent 175 "the cancel was not refused" '^lifecycle: REFUSED verb=cancel' |
| 553 | rabsent 175 "no prompt refused" '^lifecycle: REFUSED verb=prompt' |
| 554 | rcheck 175 "recall (same boot) reads the reply back through the sealed Store" "${re_recall}" |
| 555 | rcheck 176 "evidence counters" '^lifecycle: evidence requests=5 refused=0 invalid=0 tasks=0 approved=1 denied=0 cancelled=0 overlong=0 last_commit_gen=[0-9]+ last_id=[0-9a-f]{8} prompts=2 replies=1 gen_cancelled=1 gen_failed=0 recalls=0 inference=resident remembers=0 facts=0 cortex=none records=0$' |
| 556 | rcheck 176 "resident close" '^infer: resident close rc=0 heap_used_kib=[0-9]+ heap_peak_kib=[0-9]+$' |
| 557 | frames_kept 176 "unload returned every frame" |
| 558 | before 176 "resident close < unload line" '^infer: resident close rc=0' '^infer: unloaded ' |
| 559 | before 176 "unload line < stop order" '^infer: unloaded ' '^lifecycle: stop order store=closed' |
| 560 | rcheck 176 "stop order closed the Store" '^lifecycle: stop order store=closed nvme=released state=stop requests=7$' |
| 561 | before 176 "stop order < stage result" '^lifecycle: stop order store=closed' '^stage lifecycle: ok rc=0$' |
| 562 | rabsent 176 "no panic or fault" '^report_kind: (panic|fault)' |
| 563 | if [[ "${qemu_status}" == 0 ]]; then ok 176 "QEMU exit 0"; else bad 176 "QEMU exit ${qemu_status}"; fi |
| 564 | m1 176 |
| 565 | infer_img="${top}/infer/nvme.img" |
| 566 | # boot 6: same disk, cold boot; recall answers from the disk, nothing in memory |
| 567 | boot_to="${AIENOS_QEMU_INFER_TIMEOUT:-2700}"; boot_mem=4096 |
| 568 | boot infer-recall "${infer_efi}" drive_infer_recall "${infer_img}" |
| 569 | infer_boots="infer infer-recall" |
| 570 | boot_to="${boot_timeout}"; boot_mem=2048; boot_extra=() |
| 571 | rcheck 175 "cold boot: resident session open again" "${re_open}" |
| 572 | rcheck 175 "cold boot: continuity RESUMED on the same disk" '^continuity: RESUMED agent=[0-9a-f]{64} incarnation=2 ' |
| 573 | rabsent 175 "cold boot: no second genesis" '^continuity: PROVISIONED' |
| 574 | rcheck 175 "cold boot: recall returns the approved reply from the disk" "${re_recall}" |
| 575 | rcheck 175 "cold boot: evidence shows one recall, no prompt" '^lifecycle: evidence requests=3 refused=0 invalid=0 tasks=0 approved=0 denied=0 cancelled=0 overlong=0 last_commit_gen=0 last_id=00000000 prompts=0 replies=0 gen_cancelled=0 gen_failed=0 recalls=1 inference=resident remembers=0 facts=0 cortex=none records=0$' |
| 576 | frames_kept 175 "cold boot: unload returned every frame" |
| 577 | rcheck 175 "cold boot: stop order closed the Store" '^lifecycle: stop order store=closed nvme=released state=stop requests=4$' |
| 578 | rabsent 175 "cold boot: no panic or fault" '^report_kind: (panic|fault)' |
| 579 | if [[ "${qemu_status}" == 0 ]]; then ok 175 "cold boot: QEMU exit 0"; else bad 175 "cold boot: QEMU exit ${qemu_status}"; fi |
| 580 | m1 175 |
| 581 | if [[ "${fail}" == "${fail_before_infer}" ]]; then echo "${infer_tag}: PASS (QEMU only; hardware NOT_RUN)"; else echo "${infer_tag}: FAIL"; fi |
| 582 | fi |
| 583 | |
| 584 | if [[ "${fail}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then |
| 585 | for b in service testkeys unlock relock rotate rotated ${infer_boots}; do echo "---- ${b} serial (lifecycle lines) ----"; grep -E '^(lifecycle|store|continuity|allen|infer|stage lifecycle|dma_gate|smmu: nvme|report_kind|mm_usage)' "${top}/${b}/serial.txt" | head -80 || true; done |
| 586 | fi |
| 587 | if [[ "${fail}" == 0 ]]; then echo "${final_tag}: PASS (QEMU only; hardware NOT_RUN)"; exit 0; fi |
| 588 | echo "${final_tag}: FAIL"; exit 1 |