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

246 lines · 14966 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# CK gate M4_ALLEN: the ALLEN subject (ARCH-0035 / OS-0018, both PROPOSED) in
18# the AIENOS lifecycle, on a 4096-byte-LBA emulated NVMe image under QEMU, one
19# cold QEMU process per boot (scripts/lib_ck_cont_qemu.sh: every boot is a new
20# qemu-system-aarch64 process; the ESP folder and the UEFI vars are rebuilt for
21# every boot; only the NVMe image file carries state from one boot to the next).
22#
23# The kernel is the TEST continuity image (make full CK_TEST_CONTINUITY=1),
24# the same image and the same provisioning boundary as M4_CONTINUITY: plan
25# mode 5 with lineage= provisions the identity AND the genesis subject in one
26# Store transaction (svc/continuity_subject_provision.c); intent= adds one
27# standing intent as subject sequence 2; plan mode 6 resumes and restores the
28# subject read-only before anything is written (svc/continuity_boot.c).
29#
30# G7 native genesis the kernel creates the subject during provisioning
31# G8 exactly once provisioning a provisioned image is refused; restores never mint
32# G9 cold restart same subject, intent and lineage after QEMU process death, twice
33# G10 native path an independent host reader finds the subject ON the image; the
34# restore plan carries no subject; another image restores another subject
35# G11 corruption forked chain, flipped envelope, missing subject: refused, nothing minted
36# G12 foreign identity another installation's subject chain: refused, never adopted
37# FI power loss SIGKILL at every Store checkpoint of the genesis transaction, then a
38# cold boot: unprovisioned or identity WITH subject, never one alone
39#
40# QEMU is not hardware: a PASS qualifies nothing physical (no DGX Spark reboot,
41# no physical NVMe, no machine migration). Usage: [--mutant NAME] (the
42# subject_restore_mints and subject_accept_foreign mutants must be KILLED).
43set -uo pipefail
44cd "$(dirname "${BASH_SOURCE[0]}")/.."
45repo_root="$(pwd)"
46gate_name=M4_ALLEN
47script_tag=qemu_ck_allen
48# shellcheck source=scripts/lib_ck_cont_qemu.sh
49source scripts/lib_ck_cont_qemu.sh
50cq_init "$@"
51cq_build
52[[ "${cq_mode}" == mutant ]] || cq_default_image_checks
53cq_quiet_and_trap
54[[ "${cq_mode}" == mutant || "${hw_ok}" == 1 ]] || fail=1
55new_disk
56
57# Qualification inputs. The lineage is the digest of record 1 of the omega
58# Cortex journal the ALLEN v0 host gates seed (omega tests/allen/run.sh j1);
59# the intent is the v0 qualification goal (regime 7, 1000 ns per call).
60LINEAGE=e3f241da5ea18408653a70e3691653db216b5dcc51169b799827cf4f2699731b
61REGIME=7
62TARGET=1000
63prov_plan() { plan 5 "lineage=${LINEAGE}" "intent=${REGIME},${TARGET}" "$@"; }
64
65if [[ "${cq_mode}" != mutant ]]; then
66 if grep -aqF "ALLEN: GENESIS" "${plain_efi}"; then bad "default image carries the ALLEN TEST markers"; else pass "default image carries no ALLEN TEST markers"; fi
67fi
68
69dump() { # IMG -> the host reader's lines, on a COPY (the reader never touches the image under test)
70 local c="${top}/dump.img"; cp "$1" "${c}"
71 "${cont_tool}" subject-dump "${c}" 4096 "${2:-}" 2>&1; rm -f "${c}"
72}
73kv() { sed -nE "s/.* $1=([^ ]+).*/\1/p" <<<"$2" | head -1; }
74allen() { grep -E "^ALLEN: $1( |$)" "${work}/serial.txt" | tail -1; }
75n_allen() { grep -cE "^ALLEN: $1( |$)" "${work}/serial.txt" || true; }
76plan_text() { dd if="${image}" bs="${unit}" skip="${plan_unit}" count=1 status=none | tr -d '\0' | head -1; }
77
78# ---------------------------------------------------------------- G7 genesis
79fresh_image
80d0=$(dump "${image}")
81prov_plan
82boot
83l_prov=$(out '^CONTINUITY: ')
84l_gen=$(allen GENESIS); l_int=$(allen INTENDED); l_i=$(allen INTENT)
85agent=$(agent_of "${l_prov}")
86S1=$(kv subject "${l_gen}"); S2=$(kv subject "${l_int}"); I=$(kv id "${l_i}")
87d1=$(dump "${image}" "${top}/allen_head.bin")
88if [[ "${d0}" =~ subject-dump:\ store=Refused$ || "${d0}" =~ identity=Unprovisioned ]] \
89 && [[ "${l_prov}" =~ ^CONTINUITY:\ PROVISIONED\ agent=[0-9a-f]{64}\ incarnation=1\ sequence=1\ cortex=0\ branches=1 ]] \
90 && [[ "${l_gen}" == "ALLEN: GENESIS subject=${S1} sequence=1 agent=${agent} lineage=${LINEAGE} intents=0 active=0" ]] \
91 && [[ ${#S1} == 64 ]]; then
92 pass "G7 native genesis: blank image (${d0##*subject-dump: }) -> kernel provisioning created subject ${S1:0:16}.. sequence 1 for agent ${agent:0:16}.., lineage bound"
93else bad "G7 genesis: before='${d0}' prov='${l_prov}' gen='${l_gen}'"; fi
94if [[ "${l_int}" == "ALLEN: INTENDED subject=${S2} sequence=2 agent=${agent} lineage=${LINEAGE} intents=1 active=1" ]] \
95 && [[ "${l_i}" == "ALLEN: INTENT id=${I} kind=1 regime=${REGIME} target_ns=${TARGET} since=2" && ${#I} == 64 && "${S2}" != "${S1}" ]]; then
96 pass "G7 standing intent: sequence 2 ${S2:0:16}.. holds intent ${I:0:16}.. (regime ${REGIME}, ${TARGET} ns)"
97else bad "G7 intent: '${l_int}' / '${l_i}'"; fi
98if [[ "$(kv genesis_objects "${d1}")" == 1 && "$(kv subject_objects "${d1}")" == 2 && "$(kv subject "${d1}")" == "${S2}" \
99 && "$(kv agent "${d1}")" == "${agent}" && "$(kv lineage "${d1}")" == "${LINEAGE}" ]]; then
100 pass "G7 host reader: the image holds one genesis and one successor, head ${S2:0:16}.. (no host tool created them)"
101else bad "G7 host reader: '${d1}'"; fi
102prov_image="${top}/prov.img"; cp "${image}" "${prov_image}"
103prov_sha=$(sha "${prov_image}")
104
105# ------------------------------------------------------- G8 exactly once
106image="${top}/g8.img"; cp "${prov_image}" "${image}"
107prov_plan
108boot
109if [[ "$(out '^CONTINUITY: ')" == "CONTINUITY: STOP (AlreadyProvisioned)" && "$(n_allen GENESIS)" == 0 ]] && unchanged; then
110 pass "G8 second provisioning refused: no genesis, image unchanged"
111else bad "G8 second provisioning: '$(out '^CONTINUITY: ')' genesis=$(n_allen GENESIS)"; fi
112
113# --------------------------------------------- G9 cold restart (two restores)
114image="${top}/g9.img"; cp "${prov_image}" "${image}"
115plan 6
116rplan=$(plan_text)
117g9_ok=1
118for k in 1 2; do
119 boot; q=${qemu_status}
120 l_r=$(allen RESTORED); l_ri=$(allen INTENT); l_c=$(out '^CONTINUITY: RESUMED ')
121 inc=$(( k + 1 ))
122 if [[ "${q}" == 0 && "${l_r}" == "ALLEN: RESTORED subject=${S2} sequence=2 agent=${agent} lineage=${LINEAGE} intents=1 active=1" \
123 && "${l_ri}" == "ALLEN: INTENT id=${I} kind=1 regime=${REGIME} target_ns=${TARGET} since=2" \
124 && "$(n_allen GENESIS)" == 0 && "${l_c}" =~ incarnation=${inc}\ && "$(agent_of "${l_c}")" == "${agent}" ]]; then
125 pass "G9 cold restart ${k}: new QEMU process (previous exited ${q}), same subject ${S2:0:16}.., same intent, same lineage, incarnation ${inc}"
126 else g9_ok=0; bad "G9 cold restart ${k}: q=${q} '${l_r}' / '${l_ri}' / '${l_c}'"; fi
127done
128d9=$(dump "${image}" "${top}/allen_head_after.bin")
129if [[ "$(kv genesis_objects "${d9}")" == 1 && "$(kv subject_objects "${d9}")" == 2 && "$(kv subject "${d9}")" == "${S2}" ]] \
130 && cmp -s "${top}/allen_head.bin" "${top}/allen_head_after.bin"; then
131 pass "G9 after two restores: still one genesis, two subject objects, head object byte-identical"
132else bad "G9 after restores: '${d9}'"; fi
133
134# --------------------------------------------------------- G10 native path
135# The restore plan names only the mode; the ESP and UEFI vars are rebuilt for
136# every boot (prep); an image provisioned separately restores ITS subject.
137if [[ "${rplan}" == "AIENCONT v1 mode=6" ]]; then pass "G10 restore plan carries no subject, lineage or intent ('${rplan}')"; else bad "G10 restore plan: '${rplan}'"; fi
138fresh_image
139prov_plan; boot
140b_agent=$(agent_of "$(out '^CONTINUITY: PROVISIONED ')"); B2=$(kv subject "$(allen INTENDED)")
141b_image="${top}/b.img"; cp "${image}" "${b_image}"
142plan 6; boot
143l_b=$(allen RESTORED)
144if [[ -n "${B2}" && "${B2}" != "${S2}" && "${b_agent}" != "${agent}" && "$(kv subject "${l_b}")" == "${B2}" && "$(kv agent "${l_b}")" == "${b_agent}" ]]; then
145 pass "G10 a second image restores its own subject ${B2:0:16}.. (agent ${b_agent:0:16}..), not ${S2:0:16}..: the subject comes from the disk"
146else bad "G10 second image: B2=${B2} restored='${l_b}'"; fi
147if [[ -s "${top}/allen_head.bin" && "$(sha256sum "${top}/allen_head.bin" | cut -c1-64)" != "" ]]; then
148 pass "G10 host reader decoded the head object from the sealed Store on the image (${S2:0:16}..)"
149else bad "G10 host reader produced no head object"; fi
150
151# ------------------------------------------------------------ G11 corruption
152# a) a forked chain (a second genesis subject for the same agent)
153image="${top}/g11a.img"; cp "${prov_image}" "${image}"
154"${cont_tool}" subject-plant "${image}" 4096 fork >/dev/null || bad "G11a plant fork tool failed"
155plan 6
156for k in 1 2; do
157 boot
158 if [[ "$(allen CORRUPT)" == "ALLEN: CORRUPT (subject chain fork)" && -z "$(allen RESTORED)" && "$(n_allen GENESIS)" == 0 \
159 && -z "$(out '^CONTINUITY: RESUMED')" ]] && unchanged; then
160 pass "G11a forked chain, boot ${k}: CORRUPT, nothing restored, nothing minted, image unchanged"
161 else bad "G11a fork boot ${k}: '$(allen CORRUPT)' restored='$(allen RESTORED)' cont='$(out '^CONTINUITY: ')'"; fi
162done
163d11=$(dump "${image}")
164[[ "$(kv subject_objects "${d11}")" == 3 ]] && pass "G11a image still holds exactly the planted objects (3), no replacement" || bad "G11a objects: '${d11}'"
165# b) a flipped byte in a subject envelope
166image="${top}/g11b.img"; cp "${prov_image}" "${image}"
167"${cont_tool}" corrupt-subject "${image}" 4096 >/dev/null || bad "G11b corrupt tool failed"
168plan 6; boot
169l11b="$(out '^(ALLEN|CONTINUITY): ')"
170if [[ -z "$(allen RESTORED)" && "$(n_allen GENESIS)" == 0 && -z "$(out '^CONTINUITY: RESUMED')" ]] && unchanged \
171 && [[ "${l11b}" =~ ^(ALLEN:\ STOP|ALLEN:\ CORRUPT|CONTINUITY:\ STOP\ \(store\ Refused) ]]; then
172 pass "G11b corrupted subject envelope: refused ('${l11b}'), nothing restored or minted, image unchanged"
173else bad "G11b envelope: '${l11b}' restored='$(allen RESTORED)'"; fi
174# c) a provisioned identity without a subject (identity-only provisioning)
175fresh_image; plan 5; boot
176c_agent=$(agent_of "$(out '^CONTINUITY: PROVISIONED ')")
177plan 6
178for k in 1 2; do
179 boot
180 if [[ "$(allen ABSENT)" == "ALLEN: ABSENT (provisioned without a subject; restore never mints one)" && "$(n_allen GENESIS)" == 0 \
181 && -z "$(allen RESTORED)" && "$(agent_of "$(out '^CONTINUITY: RESUMED ')")" == "${c_agent}" ]]; then
182 pass "G11c missing subject, boot ${k}: ABSENT reported, none minted"
183 else bad "G11c missing subject boot ${k}: '$(allen 'ABSENT|RESTORED|CORRUPT|STOP')'"; fi
184done
185d11c=$(dump "${image}")
186[[ "$(kv subject_objects "${d11c}")" == 0 ]] && pass "G11c host reader: still no subject object on the image" || bad "G11c objects: '${d11c}'"
187c_image="${top}/c.img"; cp "${image}" "${c_image}"
188
189# ------------------------------------------------------ G12 foreign identity
190# a) another installation's whole subject chain beside this one's
191image="${top}/g12a.img"; cp "${prov_image}" "${image}"
192"${cont_tool}" subject-plant "${image}" 4096 foreign "${b_image}" >/dev/null || bad "G12a plant tool failed"
193plan 6; boot
194if [[ "$(allen CORRUPT)" == "ALLEN: CORRUPT (subject object belongs to another agent)" && -z "$(allen RESTORED)" \
195 && "$(n_allen GENESIS)" == 0 ]] && unchanged; then
196 pass "G12a foreign chain beside our own: CORRUPT (another agent), nothing restored or minted, image unchanged"
197else bad "G12a: '$(allen 'CORRUPT|STOP|RESTORED')'"; fi
198# b) another installation's chain on an identity that has none of its own
199image="${top}/g12b.img"; cp "${c_image}" "${image}"
200"${cont_tool}" subject-plant "${image}" 4096 foreign "${b_image}" >/dev/null || bad "G12b plant tool failed"
201plan 6; boot
202if [[ "$(allen CORRUPT)" == "ALLEN: CORRUPT (subject object belongs to another agent)" && -z "$(allen RESTORED)" \
203 && "$(n_allen GENESIS)" == 0 ]] && unchanged; then
204 pass "G12b foreign chain on a subjectless identity: refused, never adopted, nothing minted, image unchanged"
205else bad "G12b: '$(allen 'CORRUPT|STOP|RESTORED')'"; fi
206
207# ------------------------------------- FI power loss during the genesis write
208i=0
209for cp in before_first_write after_payload_objects after_catalog after_commit_record after_first_flush \
210 after_inactive_superblock after_final_flush before_anchor after_anchor; do
211 case "${cp}" in
212 after_inactive_superblock) want=either ;;
213 after_final_flush|before_anchor|after_anchor) want=new ;;
214 *) want=old ;;
215 esac
216 fresh_image
217 prov_plan "cp=${cp}"
218 boot_kill "${cp}"
219 seen=$(grep -c "^continuity: HALT at ${cp} " "${work}/serial.txt" || true)
220 plan 6; boot
221 l=$(out '^CONTINUITY: '); la=$(out '^ALLEN: ')
222 if [[ "${l}" == "CONTINUITY: UNPROVISIONED" && -z "${la}" ]]; then got=old
223 elif [[ "${l}" =~ ^CONTINUITY:\ RESUMED\ && "${la}" =~ ^ALLEN:\ RESTORED\ subject=[0-9a-f]{64}\ sequence=1\ agent=$(agent_of "${l}")\ lineage=${LINEAGE}\ intents=0\ active=0$ ]]; then got=new
224 else got=bad; fi
225 i=$(( i + 1 ))
226 if [[ "${seen}" -ge 1 && "${got}" != bad && ( "${want}" == either || "${want}" == "${got}" ) ]]; then
227 pass "FI.${i} SIGKILL at ${cp}: cold boot finds the ${got} state ($([[ ${got} == old ]] && echo unprovisioned, no subject || echo identity with its genesis subject))"
228 else bad "FI.${i} SIGKILL at ${cp}: seen=${seen} want=${want} got=${got} '${l}' / '${la}'"; fi
229 if [[ "${got}" == old && "${cp}" == before_first_write ]]; then
230 prov_plan; boot
231 [[ -n "$(allen GENESIS)" ]] && pass "FI.${i}b interrupted provisioning that committed nothing can be provisioned again" \
232 || bad "FI.${i}b re-provision: '$(out '^(ALLEN|CONTINUITY): ')'"
233 fi
234done
235
236[[ -z "${AIENOS_LOG_DIR:-}" ]] || cp "${top}/allen_head.bin" "${AIENOS_LOG_DIR}/allen_head.bin"
237# Facts for the evidence receipt (one line, parsed by the receipt writer).
238echo "ALLEN_FACTS agent=${agent} genesis=${S1} subject=${S2} intent=${I} lineage=${LINEAGE} regime=${REGIME} target_ns=${TARGET} prov_image_sha256=${prov_sha} head_object_sha256=$(sha "${top}/allen_head.bin")"
239echo "rows ${rows_ok}/${rows}; M1 failures: ${m1_fail}"
240if [[ "${cq_mode}" == mutant ]]; then
241 release_flag
242 if [[ "${fail}" == 0 ]]; then verdict SURVIVED; else verdict "KILLED (gate failed)"; fi
243 exit 0
244fi
245[[ "${hw_ok:-1}" == 1 && "${fail}" == 0 ]] && verdict PASS || verdict FAIL
246[[ "${fail}" == 0 ]]