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_continuity_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 | # CK gate M4_CONTINUITY: C kernel continuity (resolve/provision/resume/commit) |
| 18 | # on a 4096-byte-LBA NVMe image under QEMU, one cold QEMU process per boot. |
| 19 | # Oracle: scripts/qemu_continuity_test.sh (Rust). Contract section 6.1. |
| 20 | # Mode selection: contract K-7 (see scripts/lib_ck_cont_qemu.sh). QEMU is not |
| 21 | # hardware. Run only through the heavy forge. Usage: [--mutant NAME] |
| 22 | set -uo pipefail |
| 23 | cd "$(dirname "${BASH_SOURCE[0]}")/.." |
| 24 | repo_root="$(pwd)" |
| 25 | gate_name=M4_CONTINUITY |
| 26 | script_tag=qemu_ck_continuity |
| 27 | # shellcheck source=scripts/lib_ck_cont_qemu.sh |
| 28 | source scripts/lib_ck_cont_qemu.sh |
| 29 | cq_init "$@" |
| 30 | cq_build |
| 31 | [[ "${cq_mode}" == mutant ]] || cq_default_image_checks |
| 32 | cq_quiet_and_trap |
| 33 | [[ "${cq_mode}" == mutant || "${hw_ok}" == 1 ]] || fail=1 |
| 34 | new_disk |
| 35 | |
| 36 | view_ok() { # line word inc seq cortex branches |
| 37 | [[ "$1" =~ ^CONTINUITY:\ $2\ agent=[0-9a-f]{64}\ incarnation=$3\ sequence=$4\ cortex=$5\ branches=$6\ memory=[0-9a-f]{16}$ ]] |
| 38 | } |
| 39 | |
| 40 | # 81 blank media, resume |
| 41 | fresh_image; plan 6 |
| 42 | boot; l=$(out '^CONTINUITY: ') |
| 43 | if [[ "${l}" == "CONTINUITY: STOP (store Unformatted)" ]] && unchanged; then pass "81 blank media resume: ${l}, image unchanged"; else bad "81 blank resume: '${l}' unchanged=$(unchanged && echo y || echo n)"; fi |
| 44 | |
| 45 | # 82 formatted store, no root (mode 1 = ordinary Store boot formats it) |
| 46 | fresh_image; plan 1; boot; plan 6 |
| 47 | boot; l=$(out '^CONTINUITY: ') |
| 48 | if [[ "${l}" == "CONTINUITY: UNPROVISIONED" ]] && unchanged; then pass "82 formatted store, no root: UNPROVISIONED, image unchanged"; else bad "82 unprovisioned: '${l}'"; fi |
| 49 | |
| 50 | # 83 provision on a fresh disk |
| 51 | fresh_image; plan 5 |
| 52 | boot; l=$(out '^CONTINUITY: ') |
| 53 | if view_ok "${l}" PROVISIONED 1 1 0 1; then agent=$(agent_of "${l}"); pass "83 provision: PROVISIONED agent=${agent:0:16}.. incarnation=1 sequence=1"; else bad "83 provision: '${l}'"; agent=""; fi |
| 54 | prov_image="${top}/prov.img"; cp "${image}" "${prov_image}" |
| 55 | |
| 56 | # 83a provision again |
| 57 | plan 5 |
| 58 | boot; l=$(out '^CONTINUITY: ') |
| 59 | if [[ "${l}" == "CONTINUITY: STOP (AlreadyProvisioned)" ]] && unchanged; then pass "83a second provision refused, image unchanged"; else bad "83a second provision: '${l}'"; fi |
| 60 | |
| 61 | # 83b independent provisioning gives a different agent |
| 62 | fresh_image; plan 5 |
| 63 | boot; l2=$(out '^CONTINUITY: ') |
| 64 | a2=$(agent_of "${l2}") |
| 65 | if [[ -n "${agent}" && -n "${a2}" && "${a2}" != "${agent}" ]]; then pass "83b second fresh disk gets a different agent"; else bad "83b agents equal or missing"; fi |
| 66 | |
| 67 | # 84 resume (commits incarnation 2) then remember |
| 68 | image="${prov_image}"; plan 7 |
| 69 | boot; l=$(out '^CONTINUITY: RESUMED ') |
| 70 | view_ok "${l}" RESUMED 2 2 0 1 && [[ "$(agent_of "${l}")" == "${agent}" ]] && r_ok=1 || r_ok=0 |
| 71 | l_rem=$(out '^CONTINUITY: REMEMBERED ') |
| 72 | if [[ "${r_ok}" == 1 ]] && view_ok "${l_rem}" REMEMBERED 2 3 1 2; then pass "84 resume + remember: incarnation=2 sequence=2 then sequence=3 cortex=1 branches=2"; else bad "84: '${l}' / '${l_rem}'"; fi |
| 73 | mem=$(field memory "${l_rem}") |
| 74 | rem_image="${top}/rem.img"; cp "${image}" "${rem_image}" |
| 75 | |
| 76 | # 85, 85a cold restarts |
| 77 | plan 6 |
| 78 | boot; l=$(out '^CONTINUITY: RESUMED ') |
| 79 | if view_ok "${l}" RESUMED 3 4 1 2 && [[ "$(agent_of "${l}")" == "${agent}" && "$(field memory "${l}")" == "${mem}" ]]; then pass "85 cold restart 1: same agent and memory, incarnation=3 sequence=4"; else bad "85: '${l}' want mem ${mem}"; fi |
| 80 | boot; l=$(out '^CONTINUITY: RESUMED ') |
| 81 | if view_ok "${l}" RESUMED 4 5 1 2 && [[ "$(agent_of "${l}")" == "${agent}" && "$(field memory "${l}")" == "${mem}" ]]; then pass "85a cold restart 2: incarnation=4 sequence=5"; else bad "85a: '${l}'"; fi |
| 82 | |
| 83 | # 86 reference: the new memory after one uninterrupted mode 8 commit |
| 84 | work_image="${top}/work.img"; cp "${rem_image}" "${work_image}"; image="${work_image}"; plan 8 |
| 85 | boot; l=$(out '^CONTINUITY: COMMITTED ') |
| 86 | new_mem=$(field memory "${l}") |
| 87 | if [[ -n "${new_mem}" && "${new_mem}" != "${mem}" ]]; then pass "86 reference: uninterrupted commit gives new memory ${new_mem}"; else bad "86 reference commit: '${l}'"; fi |
| 88 | |
| 89 | # 86a-86i kill at each checkpoint, then cold resume |
| 90 | i=0 |
| 91 | for cp in before_first_write after_payload_objects after_catalog after_commit_record after_first_flush \ |
| 92 | after_inactive_superblock after_final_flush before_anchor after_anchor; do |
| 93 | case "${cp}" in |
| 94 | after_inactive_superblock) want=either ;; |
| 95 | after_final_flush|before_anchor|after_anchor) want=new ;; |
| 96 | *) want=old ;; |
| 97 | esac |
| 98 | cp "${rem_image}" "${work_image}"; image="${work_image}" |
| 99 | plan 8 "cp=${cp}" |
| 100 | boot_kill "${cp}" |
| 101 | seen=$(grep -c "^CHECKPOINT: ${cp}\$" "${work}/serial.txt" || true) |
| 102 | plan 6 |
| 103 | boot; l=$(out '^CONTINUITY: ') |
| 104 | got=$(field memory "${l}") |
| 105 | case "${want}" in |
| 106 | old) okm=$([[ "${got}" == "${mem}" ]] && echo 1 || echo 0) ;; |
| 107 | new) okm=$([[ "${got}" == "${new_mem}" ]] && echo 1 || echo 0) ;; |
| 108 | either) okm=$([[ "${got}" == "${mem}" || "${got}" == "${new_mem}" ]] && echo 1 || echo 0) ;; |
| 109 | esac |
| 110 | i=$(( i + 1 )) |
| 111 | if [[ "${seen}" -ge 1 && "${l}" =~ ^CONTINUITY:\ RESUMED\ && "$(agent_of "${l}")" == "${agent}" && "${okm}" == 1 ]]; then |
| 112 | pass "86.${i} kill at ${cp}: marker seen, same agent, ${want} memory" |
| 113 | else |
| 114 | bad "86.${i} kill at ${cp}: seen=${seen} want=${want} got='${l}'" |
| 115 | fi |
| 116 | done |
| 117 | |
| 118 | # 87 malformed peer: read-only resume |
| 119 | cp "${rem_image}" "${work_image}"; image="${work_image}" |
| 120 | "${cont_tool}" inject-peer "${image}" 4096 >/dev/null || bad "87 inject-peer tool failed" |
| 121 | plan 6 |
| 122 | boot; l=$(out '^CONTINUITY: ') |
| 123 | if view_ok "${l}" RESUMED_READONLY 2 3 1 2 && [[ "$(agent_of "${l}")" == "${agent}" && "$(field memory "${l}")" == "${mem}" ]] && unchanged; then |
| 124 | pass "87 malformed peer: RESUMED_READONLY, same agent and memory, image unchanged" |
| 125 | else bad "87 malformed peer: '${l}'"; fi |
| 126 | |
| 127 | echo "rows ${rows_ok}/${rows}; M1 failures: ${m1_fail}" |
| 128 | if [[ "${cq_mode}" == mutant ]]; then |
| 129 | release_flag |
| 130 | if [[ "${fail}" == 0 ]]; then verdict SURVIVED; else verdict "KILLED (gate failed)"; fi |
| 131 | exit 0 |
| 132 | fi |
| 133 | [[ "${hw_ok:-1}" == 1 && "${fail}" == 0 ]] && verdict PASS || verdict FAIL |
| 134 | [[ "${fail}" == 0 ]] |