Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/scripts/qemu_ck_allen_wizard_test.sh # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / scripts / qemu_ck_allen_wizard_test.sh` 342 lines ยท 15618 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # qemu_ck_allen_wizard_test.sh -- Allen's setup wizard end to end in QEMU, on 3 # the three test machines of native/kernel/svc/tests/fixtures/setup. 4 # 5 # The launcher image (make imac-kernel CK_X86_HOSTDESC=1, IMACKERN-HOST.EFI) 6 # boots with the machine's host description handed over as the fw_cfg file 7 # opt/aienos/host, a disk the kernel may write Allen's section on, and keys 8 # typed from outside through the QEMU monitor: 9 # 10 # games PC "Play games smoothly" (1), the scan, then the power goes off at 11 # the consent; the next start carries on there ("Welcome back"), 12 # "Set it up", the games path, the one AI nearby picked by itself 13 # after 10 s, ready; a third start shows no wizard at all; 14 # AI PC Enter past hello, the AI by its number (2), "Show me each one" 15 # with one item skipped, two models here (the running one picked 16 # by its number), ready moves on by itself; 17 # the Spark the AI (2), "Not now", "Choose another", "Connect my own", 18 # "Another service" at http://127.0.0.1:18091 with a made-up key: 19 # the key goes down the second serial port to the relay 20 # (crates/allen-courier), which makes the one test request. 21 # 22 # Checked: the wizard's log lines ("wizard: ..."), its records on the disk 23 # (llm.conf and consent, read back from the image), screenshots of the 24 # screens, and that the key appears in none of: the console log, the relay's 25 # log, the relay's work folder, the disk. The default image is built too and 26 # must carry no fw_cfg code (the Makefile's link check). 27 # 28 # Needs qemu-system-x86_64, OVMF, mtools, an x86_64 gcc, cargo, and the model 29 # server at 127.0.0.1:18091 (otherwise NOT_RUN). Takes the gate lock like 30 # every QEMU test. Final line: AIENOS_ALLEN_WIZARD: PASS | FAIL | NOT_RUN (reason) 31 set -u 32 repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 33 cd "${repo_root}" 34 tag="AIENOS_ALLEN_WIZARD" 35 code_fd="${OVMF_CODE:-/usr/share/OVMF/OVMF_CODE_4M.fd}" 36 vars_fd="${OVMF_VARS:-/usr/share/OVMF/OVMF_VARS_4M.fd}" 37 server="${ALLEN_MODEL:-127.0.0.1:18091}" 38 fx="${repo_root}/native/kernel/svc/tests/fixtures/setup" 39 key="sk-test-5150-wizard" 40 cross="" 41 if [ "$(uname -m)" != "x86_64" ]; then cross="x86_64-linux-gnu-"; fi 42 for t in qemu-system-x86_64 mformat mmd mcopy cargo curl "${cross}gcc" "${cross}ld"; do 43 command -v "${t}" >/dev/null || { echo "${tag}: NOT_RUN (${t} missing)"; exit 2; } 44 done 45 [[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "${tag}: NOT_RUN (no OVMF)"; exit 2; } 46 if ! curl -s --max-time 5 "http://${server}/v1/models" | grep -q '"id"'; then 47 echo "${tag}: NOT_RUN (no model server at ${server})" 48 exit 2 49 fi 50 out="${repo_root}/target/native-kernel-allen-wizard" 51 mkdir -p "${out}" 52 commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" 53 make -s -C native/kernel X86_CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" imac-kernel >"${out}/make0.log" 2>&1 || 54 { echo "${tag}: FAIL (the default kernel does not build)"; tail -5 "${out}/make0.log"; exit 1; } 55 make -s -C native/kernel X86_CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" CK_X86_HOSTDESC=1 imac-kernel \ 56 >"${out}/make1.log" 2>&1 || { echo "${tag}: FAIL (the launcher kernel does not build)"; tail -5 "${out}/make1.log"; exit 1; } 57 make -s -C native/kernel OUT="${out}" gpt-image >/dev/null || { echo "${tag}: FAIL (gpt-image does not build)"; exit 1; } 58 gpt="${out}/host/ck_gpt_image" 59 cargo build -q --release --offline -p allen-courier 2>"${out}/cargo.err" || 60 { echo "${tag}: FAIL (relay does not build)"; tail -5 "${out}/cargo.err"; exit 1; } 61 relay="${repo_root}/target/release/allen-courier" 62 63 . "${repo_root}/scripts/lib_gate_hold.sh" 64 if ! gh_quiet_check || ! gh_lock_take qemu_ck_allen_wizard_test "${AIENOS_GATE_MINUTES:-40}"; then 65 echo "${tag}: NOT_RUN (${gh_why})" 66 exit 3 67 fi 68 work="$(mktemp -d)" 69 pids=() 70 cleanup() { 71 local p f 72 for p in "${pids[@]}"; do kill "${p}" 2>/dev/null || true; done 73 for f in "${work}"/*.log; do [[ -e "${f}" ]] && cp "${f}" "${out}/" 2>/dev/null; done 74 rm -rf "${work}" 75 gh_lock_release 76 } 77 trap cleanup EXIT 78 79 esp="${work}/esp.img" 80 truncate -s 64M "${esp}" 81 mformat -i "${esp}" -F :: 82 mmd -i "${esp}" ::/EFI ::/EFI/BOOT 83 mcopy -i "${esp}" "${out}/IMACKERN-HOST.EFI" ::/EFI/BOOT/BOOTX64.EFI 84 for m in games ai spark; do "${gpt}" create "${work}/${m}.hdd" 512 2048 one-old >/dev/null; done 85 86 fails=0 87 pass() { echo "PASS $1"; } 88 fail() { echo "FAIL $1"; fails=$((fails + 1)); } 89 txt() { tr -d '\r' <"${work}/$1.log" 2>/dev/null || true; } 90 has() { txt "$1" | grep -aqE -- "$2"; } 91 chk() { # run, description, pattern 92 if has "$1" "$3"; then pass "$1: $2"; else fail "$1: $2 (no match for: $3)"; fi 93 } 94 nochk() { 95 if has "$1" "$3"; then fail "$1: $2 (unexpected: $3)"; else pass "$1: $2"; fi 96 } 97 wait_for() { # run seconds pattern 98 local i 99 for ((i = 0; i < $2 * 5; i++)); do 100 has "$1" "$3" && return 0 101 sleep 0.2 102 done 103 echo " (waited $2 s for: $3)" 104 return 1 105 } 106 107 # start run fixture disk wire(0|1): one boot; the console goes to .log 108 start() { 109 local run="$1" fixture="$2" disk="$3" wire="$4" extra=() 110 cp "${vars_fd}" "${work}/${run}.vars" 111 cp "${esp}" "${work}/${run}.esp" 112 rm -f "${work}/${run}.mon.in" "${work}/${run}.mon.out" 113 mkfifo "${work}/${run}.mon.in" "${work}/${run}.mon.out" 114 : >"${work}/${run}.log" 115 if [[ ${wire} == 1 ]]; then extra=(-serial unix:"${work}/${run}.sock",server=on,wait=off); fi 116 qemu-system-x86_64 -M q35 -accel tcg -cpu max -smp 2 -m 1024 \ 117 -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ 118 -drive if=pflash,format=raw,file="${work}/${run}.vars" \ 119 -drive if=none,id=esp,format=raw,file="${work}/${run}.esp" -device ide-hd,drive=esp,bus=ide.0 \ 120 -drive if=none,id=hdd,format=raw,file="${disk}" \ 121 -device ide-hd,drive=hdd,bus=ide.1,model="APPLE HDD ST1000DM003" \ 122 -device qemu-xhci,id=xhci -device usb-kbd,bus=xhci.0,port=1 \ 123 -fw_cfg name=opt/aienos/host,file="${fixture}" \ 124 -chardev pipe,id=mon,path="${work}/${run}.mon" -mon chardev=mon,mode=readline \ 125 -display none -nic none -serial file:"${work}/${run}.log" "${extra[@]}" \ 126 -no-reboot 2>"${work}/${run}.err" & 127 pids+=($!) 128 eval "pid_${run}=$!" 129 cat "${work}/${run}.mon.out" >/dev/null & 130 pids+=($!) 131 if [[ ${wire} == 1 ]]; then 132 sleep 1 133 "${relay}" --socket "${work}/${run}.sock" --model "${server}" --work "${work}/${run}.answers" \ 134 >"${work}/${run}-relay.log" 2>&1 & 135 pids+=($!) 136 fi 137 } 138 stop() { local v="pid_$1"; kill "${!v}" 2>/dev/null || true; wait "${!v}" 2>/dev/null || true; } 139 mon() { # run line...: monitor commands 140 local run="$1" l 141 shift 142 exec 3>"${work}/${run}.mon.in" 143 for l in "$@"; do echo "${l}" >&3; sleep 0.15; done 144 exec 3>&- 145 } 146 keys() { # run qemu-key... 147 local run="$1" k cmds=() 148 shift 149 for k in "$@"; do cmds+=("sendkey ${k}"); done 150 mon "${run}" "${cmds[@]}" 151 } 152 type_text() { # run text: letters, digits, space and : / . - 153 local run="$1" text="$2" c i ks=() 154 for ((i = 0; i < ${#text}; i++)); do 155 c="${text:i:1}" 156 case "${c}" in 157 " ") ks+=(spc) ;; 158 [a-z0-9]) ks+=("${c}") ;; 159 :) ks+=(shift-semicolon) ;; 160 /) ks+=(slash) ;; 161 .) ks+=(dot) ;; 162 -) ks+=(minus) ;; 163 *) echo "type_text: no key for '${c}'" >&2; exit 2 ;; 164 esac 165 done 166 keys "${run}" "${ks[@]}" 167 } 168 shot() { # run name: a screenshot once Allen's words have settled 169 sleep "${3:-3}" 170 rm -f "${work}/shot.png" 171 mon "$1" "screendump ${work}/shot.png -f png" 172 for _ in $(seq 1 50); do [[ -s "${work}/shot.png" ]] && break; sleep 0.2; done 173 sleep 0.5 174 if [[ -s "${work}/shot.png" ]]; then cp "${work}/shot.png" "${out}/$2.png"; pass "$1: screenshot $2.png"; else fail "$1: no screenshot $2"; fi 175 } 176 # the record on the disk: the newer of the two AIENSET1 copies, as text 177 record() { # disk 178 LC_ALL=C grep -aqF AIENSET1 "$1" || return 1 179 local off best="" bg=-1 g 180 for off in $(LC_ALL=C grep -aobE 'AIENSET1' "$1" | cut -d: -f1); do 181 g=$(od -An -t u8 -j $((off + 16)) -N 8 "$1" | tr -d ' ') 182 if ((g > bg)); then bg=${g}; best=${off}; fi 183 done 184 local n 185 n=$(od -An -t u4 -j $((best + 12)) -N 4 "$1" | tr -d ' ') 186 dd if="$1" bs=1 skip=$((best + 64)) count="${n}" 2>/dev/null 187 } 188 ready_re='^wizard: step intent$' 189 190 # ---- the games PC: a power cut at the consent, then a second and a third start ---- 191 start games1 "${fx}/games-pc.txt" "${work}/games.hdd" 0 192 if wait_for games1 300 '^wizard: step hello$' && wait_for games1 30 "${ready_re}"; then 193 shot games1 wizard-qemu-games-1-intent 2 194 keys games1 1 195 wait_for games1 20 '^wizard: step scan$' 196 keys games1 ret 197 wait_for games1 20 '^wizard: saved at consent ' 198 fi 199 stop games1 200 chk games1 "the host description was read" '^wizard: host description [0-9]+ bytes, [0-9]+ items, 0 not understood$' 201 chk games1 "a first start says hello" '^wizard: step hello$' 202 chk games1 "the question by its number" '^wizard: intent games$' 203 chk games1 "saved after every step" '^wizard: saved at scan ' 204 chk games1 "saved at the consent before the power went" '^wizard: saved at consent ' 205 206 start games2 "${fx}/games-pc.txt" "${work}/games.hdd" 0 207 if wait_for games2 300 '^wizard: resumed at consent$' && wait_for games2 30 '^wizard: step consent$'; then 208 shot games2 wizard-qemu-games-2-consent 209 keys games2 ret 210 wait_for games2 20 '^wizard: step games$' 211 shot games2 wizard-qemu-games-3-games 212 keys games2 ret 213 wait_for games2 20 '^wizard: step llm$' 214 wait_for games2 40 '^wizard: step ready$' 215 shot games2 wizard-qemu-games-4-ready 216 keys games2 ret 217 wait_for games2 20 '^wizard: finished' 218 fi 219 stop games2 220 chk games2 "carries on at the consent after the power cut" '^wizard: resumed at consent$' 221 chk games2 "Set it up" '^wizard: consent all$' 222 chk games2 "the one AI nearby is picked after 10 s" '^wizard: llm auto-picked after 10 s$' 223 chk games2 "the peer is the AI" '^wizard: llm picked peer qwen3.8-27b-fp8$' 224 chk games2 "done" '^wizard: step done$' 225 chk games2 "saved as done" '^wizard: saved at done ' 226 rec="$(record "${work}/games.hdd" || true)" 227 grep -qx 'step 16' <<<"${rec}" && pass "games: the disk says setup is done" || fail "games: the disk record: ${rec:0:80}" 228 grep -qx 'base_url http://127.0.0.1:18091' <<<"${rec}" && grep -qx 'key_env none' <<<"${rec}" && 229 pass "games: llm.conf on the disk names the peer" || fail "games: no llm.conf for the peer on the disk" 230 grep -qx 'screen-refresh yes' <<<"${rec}" && pass "games: the consent record is on the disk" || fail "games: no consent record" 231 232 start games3 "${fx}/games-pc.txt" "${work}/games.hdd" 0 233 wait_for games3 300 '^keyboard: type a line and press Enter' || true 234 stop games3 235 chk games3 "a finished setup is not shown again" '^wizard: setup finished on an earlier start' 236 nochk games3 "no hello from the wizard" '^wizard: step hello$' 237 238 # ---- the AI PC ---- 239 start ai "${fx}/ai-pc.txt" "${work}/ai.hdd" 0 240 if wait_for ai 300 '^wizard: step hello$'; then 241 sleep 1 242 keys ai ret 243 wait_for ai 20 "${ready_re}" 244 keys ai 2 245 wait_for ai 20 '^wizard: step scan$' 246 keys ai ret 247 wait_for ai 20 '^wizard: step consent$' 248 keys ai down ret 249 wait_for ai 20 '^wizard: step each$' 250 keys ai ret 251 sleep 1 252 keys ai 2 253 sleep 1 254 keys ai ret 255 wait_for ai 20 '^wizard: step ai$' 256 shot ai wizard-qemu-ai-1-models 257 keys ai ret 258 wait_for ai 20 '^wizard: step llm$' 259 shot ai wizard-qemu-ai-2-pick 260 keys ai 1 261 wait_for ai 20 '^wizard: step ready$' 262 wait_for ai 40 '^wizard: step done$' 263 fi 264 stop ai 265 chk ai "Enter moves past hello" '^wizard: step intent$' 266 chk ai "the AI by its number" '^wizard: intent ai$' 267 chk ai "each one, one skipped" '^wizard: consent skip ai-gpu$' 268 chk ai "two found: chosen by hand" '^wizard: llm picked local qwen2.5-7b-instruct$' 269 nochk ai "two found: nothing picked by itself" '^wizard: llm auto-picked' 270 chk ai "ready moves on by itself" '^wizard: step done$' 271 rec="$(record "${work}/ai.hdd" || true)" 272 grep -qx 'base_url http://127.0.0.1:1234' <<<"${rec}" && pass "ai: llm.conf names the running model" || fail "ai: llm.conf: ${rec:0:120}" 273 grep -qx 'ai-gpu no' <<<"${rec}" && pass "ai: the skipped item is a no" || fail "ai: consent record" 274 275 # ---- the Spark: connect my own, the key test through the relay ---- 276 start spark "${fx}/spark.txt" "${work}/spark.hdd" 1 277 if wait_for spark 300 "${ready_re}"; then 278 wait_for spark 30 '^courier: ready, the far side said hello$' 279 keys spark 2 280 wait_for spark 20 '^wizard: step scan$' 281 keys spark ret 282 wait_for spark 20 '^wizard: step consent$' 283 keys spark 3 284 wait_for spark 20 '^wizard: step ai$' 285 keys spark ret 286 wait_for spark 20 '^wizard: step llm$' 287 keys spark 2 288 sleep 1 289 keys spark 2 290 wait_for spark 20 '^wizard: step service$' 291 keys spark 3 292 wait_for spark 20 '^wizard: step url$' 293 type_text spark "http://${server}" 294 keys spark ret 295 wait_for spark 20 '^wizard: step key$' 296 type_text spark "${key}" 297 shot spark wizard-qemu-spark-1-key 1 298 keys spark ret 299 wait_for spark 60 '^wizard: step ready$' 300 shot spark wizard-qemu-spark-2-ready 301 keys spark ret 302 wait_for spark 20 '^wizard: step done$' 303 fi 304 stop spark 305 chk spark "the wire to the host is up" '^courier: ready, the far side said hello$' 306 chk spark "the AI only" '^wizard: intent ai$' 307 chk spark "Not now" '^wizard: consent not now$' 308 chk spark "the key test went down the wire" '^wizard: key test 1 sent \(openai\)$' 309 chk spark "the key test passed" '^wizard: key test ok$' 310 chk spark "done" '^wizard: step done$' 311 if grep -aqE "^courier: key test 1 \(openai, ${#key} chars of key\) -> ok in [0-9]+ ms$" "${work}/spark-relay.log"; then 312 pass "spark: the relay made the one request and printed only the key's length" 313 else 314 fail "spark: the relay's key test line: $(grep -a 'key test' "${work}/spark-relay.log" | head -1)" 315 fi 316 rec="$(record "${work}/spark.hdd" || true)" 317 grep -qx "base_url http://${server}" <<<"${rec}" && grep -qx 'key_env AIENOS_LLM_KEY' <<<"${rec}" && 318 pass "spark: llm.conf names the service and where its key comes from" || fail "spark: llm.conf: ${rec:0:160}" 319 320 # ---- the key is nowhere ---- 321 leak="" 322 for f in "${work}"/*.log; do LC_ALL=C grep -aqF "${key}" "${f}" && leak+=" $(basename "${f}")"; done 323 [[ -d "${work}/spark.answers" ]] && LC_ALL=C grep -raqF "${key}" "${work}/spark.answers" && leak+=" relay-work-folder" 324 for d in "${work}"/*.hdd; do LC_ALL=C grep -aqF "${key}" "${d}" && leak+=" $(basename "${d}")"; done 325 [[ -z "${leak}" ]] && pass "the key is in no log, no relay file and on no disk" || fail "the key leaked into:${leak}" 326 if grep -aE '^wizard: ' "${work}"/*.log | grep -aqE 'http://|127\.0\.0\.1'; then 327 fail "an address typed into the wizard reached its log lines" 328 else 329 pass "nothing typed reaches the wizard's log lines" 330 fi 331 332 # ---- the default image carries no fw_cfg ---- 333 if [[ -s "${out}/IMACKERN.EFI" ]] && ! LC_ALL=C grep -aqE 'opt/aienos/host|QEMU0002' "${out}/IMACKERN.EFI"; then 334 pass "the default image has no host description reader" 335 else 336 fail "the default image carries fw_cfg strings" 337 fi 338 LC_ALL=C grep -aqF 'launcher image: the setup wizard reads the host description' "${out}/IMACKERN-HOST.EFI" && 339 pass "the launcher image says what it reads" || fail "the launcher image lacks its announcement" 340 341 echo "logs and screenshots: ${out}" 342 if [[ ${fails} == 0 ]]; then echo "${tag}: PASS"; else echo "${tag}: FAIL (${fails})"; exit 1; fi