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 / docs / design / tools / dogfood-wizard.sh

173 lines · 9032 bytes Raw Blame History
1#!/usr/bin/env bash
2# dogfood-wizard.sh -- use Allen's setup wizard (L267) the way a person would, in QEMU only, and keep what they
3# would see and hear: a screenshot of every screen (and one every 2 s while the night plays), the sound as a
4# .wav, and when each screen arrived. Six first runs: both intents (games, AI) times the three ways of getting
5# an AI (a model on this computer, an AienOS computer nearby, connect my own service through the relay).
6#
7# quiet-build bash docs/design/tools/dogfood-wizard.sh SRC_DIR OUT_DIR
8#
9# SRC_DIR is a clean copy of the wizard's branch (git archive of a pushed commit), never someone's worktree.
10# It is built there with the wizard's own make targets. Output per run: OUT_DIR/<run>/NN-<step>.png,
11# boot-TTT.png, sound.wav, console.log, relay.log, steps.tsv (seconds since power-on, step), and
12# OUT_DIR/summary.tsv. Exit 0 when every run reached "done", 1 otherwise, 2 when it could not run.
13set -u
14src="$(cd "${1:?SRC_DIR}" && pwd)"
15out="${2:?OUT_DIR}"
16mkdir -p "${out}"
17out="$(cd "${out}" && pwd)"
18code_fd="${OVMF_CODE:-/usr/share/OVMF/OVMF_CODE_4M.fd}"
19vars_fd="${OVMF_VARS:-/usr/share/OVMF/OVMF_VARS_4M.fd}"
20server="${ALLEN_MODEL:-127.0.0.1:18091}"
21key="sk-Dogfood_0000-not-real"
22cross=""
23[[ "$(uname -m)" != "x86_64" ]] && cross="x86_64-linux-gnu-"
24for t in qemu-system-x86_64 mformat mmd mcopy cargo curl "${cross}gcc"; do
25 command -v "${t}" >/dev/null || { echo "dogfood: NOT_RUN (${t} missing)"; exit 2; }
26done
27curl -s --max-time 5 "http://${server}/v1/models" | grep -q '"id"' || { echo "dogfood: NOT_RUN (no model server at ${server})"; exit 2; }
28
29cd "${src}"
30build="${out}/build"
31mkdir -p "${build}"
32make -s -C native/kernel X86_CROSS="${cross}" OUT="${build}" AIENOS_COMMIT="$(cat "${src}/.commit" 2>/dev/null || echo unknown)" \
33 CK_X86_HOSTDESC=1 imac-kernel >"${build}/make.log" 2>&1 || { echo "dogfood: FAIL (launcher kernel does not build)"; tail -5 "${build}/make.log"; exit 1; }
34make -s -C native/kernel OUT="${build}" gpt-image >>"${build}/make.log" 2>&1 || { echo "dogfood: FAIL (gpt-image)"; exit 1; }
35CARGO_TARGET_DIR="${build}/cargo" cargo build -q --release --offline -p allen-courier 2>"${build}/cargo.err" ||
36 { echo "dogfood: FAIL (relay does not build)"; tail -5 "${build}/cargo.err"; exit 1; }
37relay="${build}/cargo/release/allen-courier"
38fx="${src}/native/kernel/svc/tests/fixtures/setup"
39
40. "${src}/scripts/lib_gate_hold.sh"
41if ! gh_quiet_check || ! gh_lock_take dogfood_wizard_l282 "${AIENOS_GATE_MINUTES:-60}"; then
42 echo "dogfood: NOT_RUN (${gh_why})"
43 exit 3
44fi
45work="$(mktemp -d)"
46qpid="" rpid="" cpid=""
47cleanup() {
48 for p in ${qpid} ${rpid} ${cpid}; do kill "${p}" 2>/dev/null || true; done
49 rm -rf "${work}"
50 gh_lock_release
51}
52trap cleanup EXIT
53
54esp="${work}/esp.img"
55truncate -s 64M "${esp}"
56mformat -i "${esp}" -F ::
57mmd -i "${esp}" ::/EFI ::/EFI/BOOT
58mcopy -i "${esp}" "${build}/IMACKERN-HOST.EFI" ::/EFI/BOOT/BOOTX64.EFI
59
60t0=0
61now() { awk -v a="$(date +%s.%N)" -v b="${t0}" 'BEGIN { printf "%.1f", a - b }'; }
62mon() { local l; exec 3>"${work}/mon.in"; for l in "$@"; do echo "${l}" >&3; sleep 0.15; done; exec 3>&-; }
63keys() { local k c=(); for k in "$@"; do c+=("sendkey ${k}"); done; mon "${c[@]}"; echo "$(now) keys $*" >>"${dir}/steps.tsv"; }
64type_text() {
65 local c i ks=()
66 for ((i = 0; i < ${#1}; i++)); do
67 c="${1:i:1}"
68 case "${c}" in
69 " ") ks+=(spc) ;; [a-z0-9]) ks+=("${c}") ;; :) ks+=(shift-semicolon) ;; /) ks+=(slash) ;;
70 .) ks+=(dot) ;; -) ks+=(minus) ;; _) ks+=(shift-minus) ;; [A-Z]) ks+=("shift-${c,,}") ;; *) echo "type_text: no key for '${c}'" >&2; return 1 ;;
71 esac
72 done
73 keys "${ks[@]}"
74}
75shot() { # name
76 rm -f "${work}/shot.png"
77 mon "screendump ${work}/shot.png -f png"
78 # QEMU writes the png slowly under emulation: take it only once the file ends with its closing chunk (IEND)
79 for _ in $(seq 1 100); do
80 [[ -s "${work}/shot.png" ]] && tail -c 4 "${work}/shot.png" | xxd -p | grep -q '^ae426082$' && break
81 sleep 0.2
82 done
83 if tail -c 4 "${work}/shot.png" 2>/dev/null | xxd -p | grep -q '^ae426082$'; then
84 cp "${work}/shot.png" "${dir}/$1.png"
85 else
86 echo "$(now) shot $1 incomplete, dropped" >>"${dir}/steps.tsv"
87 fi
88}
89step() { tr -d '\r' <"${dir}/console.log" | grep -aoE '^wizard: step [a-z]+' | tail -1 | cut -d' ' -f3; }
90wait_step() { # seconds: wait for a step other than ${cur}
91 local i s
92 for ((i = 0; i < $1 * 5; i++)); do s="$(step)"; [[ -n "${s}" && "${s}" != "${cur}" ]] && { echo "${s}"; return 0; }; sleep 0.2; done
93 echo "${cur}"
94}
95
96# run name fixture intent(games|ai) source(local|peer|own) wire(0|1)
97run() {
98 local name="$1" fixture="$2" intent="$3" source="$4" wire="$5" n=0 s cur="" boot=0 extra=() stuck=0
99 dir="${out}/${name}"
100 mkdir -p "${dir}"
101 : >"${dir}/console.log"
102 printf 'seconds\tevent\n' >"${dir}/steps.tsv"
103 cp "${vars_fd}" "${work}/vars"
104 cp "${esp}" "${work}/esp"
105 "${build}/host/ck_gpt_image" create "${work}/disk.hdd" 512 2048 one-old >/dev/null
106 rm -f "${work}/mon.in" "${work}/mon.out"
107 mkfifo "${work}/mon.in" "${work}/mon.out"
108 [[ ${wire} == 1 ]] && extra=(-serial unix:"${work}/wire.sock",server=on,wait=off)
109 t0="$(date +%s.%N)"
110 qemu-system-x86_64 -M q35 -accel tcg -cpu max -smp 2 -m 1024 \
111 -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \
112 -drive if=pflash,format=raw,file="${work}/vars" \
113 -drive if=none,id=esp,format=raw,file="${work}/esp" -device ide-hd,drive=esp,bus=ide.0 \
114 -drive if=none,id=hdd,format=raw,file="${work}/disk.hdd" \
115 -device ide-hd,drive=hdd,bus=ide.1,model="APPLE HDD ST1000DM003" \
116 -device qemu-xhci,id=xhci -device usb-kbd,bus=xhci.0,port=1 \
117 -audiodev wav,id=snd,path="${dir}/sound.wav" -device ich9-intel-hda -device hda-output,audiodev=snd \
118 -fw_cfg name=opt/aienos/host,file="${fixture}" \
119 -chardev pipe,id=mon,path="${work}/mon" -mon chardev=mon,mode=readline \
120 -display none -nic none -serial file:"${dir}/console.log" "${extra[@]}" \
121 -no-reboot 2>"${dir}/qemu.err" &
122 qpid=$!
123 cat "${work}/mon.out" >/dev/null &
124 cpid=$!
125 if [[ ${wire} == 1 ]]; then
126 sleep 1
127 "${relay}" --socket "${work}/wire.sock" --model "${server}" --work "${work}/answers" >"${dir}/relay.log" 2>&1 &
128 rpid=$!
129 fi
130 # the night and Allen's arrival: a picture every 2 s until the wizard's first screen (at most 300 s)
131 while [[ -z "$(step)" ]] && ((boot < 300)); do
132 sleep 2; boot=$((boot + 2)); shot "boot-$(printf %03d ${boot})"
133 kill -0 "${qpid}" 2>/dev/null || break
134 done
135 cur=""
136 while :; do
137 s="$(wait_step 30)"
138 if [[ "${s}" == "${cur}" ]]; then
139 stuck=1; echo "$(now) stuck at ${cur} (no new step in 30 s)" >>"${dir}/steps.tsv"; shot "$(printf %02d ${n})-stuck-${cur}"; break
140 fi
141 cur="${s}"; n=$((n + 1))
142 echo "$(now) step ${cur}" >>"${dir}/steps.tsv"
143 sleep 3; shot "$(printf %02d ${n})-${cur}" # after the words have eased in
144 case "${cur}:${intent}:${source}" in
145 hello:*) s="$(wait_step 12)"; [[ "${s}" == "${cur}" ]] && keys ret ;; # does hello move on by itself?
146 intent:games:*) keys 1 ;;
147 intent:ai:*) keys down; sleep 1; shot "$(printf %02d ${n})-${cur}-down"; keys ret ;; # the arrow path
148 scan:* | consent:* | each:* | games:* | ai:*) keys ret ;;
149 llm:*:peer) s="$(wait_step 15)" ;; # one AI nearby: picked by itself
150 llm:*:local) keys 1 ;;
151 llm:*:own) keys 2; sleep 1; shot "$(printf %02d ${n})-${cur}-another"; keys 2 ;;
152 service:*) keys 3 ;;
153 url:*) type_text "http://${server}"; sleep 1; shot "$(printf %02d ${n})-${cur}-typed"; keys ret ;;
154 key:*) type_text "${key}"; sleep 1; shot "$(printf %02d ${n})-${cur}-typed"; keys ret ;;
155 ready:*) keys ret ;;
156 done:*) sleep 4; shot "$(printf %02d ${n})-after-done"; break ;;
157 *) keys ret ;;
158 esac
159 done
160 kill "${qpid}" "${cpid}" ${rpid} 2>/dev/null; wait "${qpid}" 2>/dev/null; rpid=""
161 grep -aqF "${key}" "${dir}/console.log" "${dir}/relay.log" 2>/dev/null && echo "$(now) KEY LEAKED into a log" >>"${dir}/steps.tsv"
162 printf '%s\t%s\t%s\t%s\t%s\t%s\n' "${name}" "${intent}" "${source}" "${cur}" "${stuck}" "$(stat -c %s "${dir}/sound.wav" 2>/dev/null || echo 0)" >>"${out}/summary.tsv"
163}
164
165printf 'run\tintent\tsource\tlast_step\tstuck\twav_bytes\n' >"${out}/summary.tsv"
166run games-peer "${fx}/games-pc.txt" games peer 0
167run games-local "${fx}/ai-pc.txt" games local 0
168run games-own "${fx}/spark.txt" games own 1
169run ai-local "${fx}/ai-pc.txt" ai local 0
170run ai-peer "${fx}/games-pc.txt" ai peer 0
171run ai-own "${fx}/spark.txt" ai own 1
172cat "${out}/summary.tsv"
173awk -F'\t' 'NR > 1 && $4 != "done" { bad = 1 } END { exit bad }' "${out}/summary.tsv"