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 / evidence / own-gpu-driver / rung2 / window1_sim_test.sh
| 1 | #!/usr/bin/env bash |
| 2 | # window1_sim_test.sh: host check of the window-1 start-up tool (native/linux/aien-gpu/aien_gsp_boot.c) built against the |
| 3 | # simulated SEC2 + GSP and a fake GSP on the status queue (-DAIEN_GSP_BOOT_SIM). No GPU, no module. |
| 4 | # 1. every verdict path: INIT-DONE, sequencer request, no answer, corrupt queue, SEC2 busy, FMC error, core dead, |
| 5 | # plan only, a package with a wrong-size file, an arena too small for the plan; |
| 6 | # 2. every register the tool touched in those runs is on the module's allowlist (aien_gpu.c AIEN-GPU-ALLOW block): |
| 7 | # reads on the read list, writes on the write list, and one SEC2 doorbell per start-up. |
| 8 | # Usage: window1_sim_test.sh SIM_BINARY AIEN_GPU_C |
| 9 | set -u |
| 10 | BIN=$1 SHIM=$2 |
| 11 | T=$(mktemp -d) |
| 12 | trap 'rm -r "$T"' EXIT |
| 13 | fail=0 |
| 14 | ok() { echo "PASS $*"; } |
| 15 | bad() { echo "FAIL $*"; fail=1; } |
| 16 | |
| 17 | # fake package: fixed bytes of the right sizes (the simulator checks none of the firmware content) |
| 18 | P=$T/pkg; mkdir "$P" |
| 19 | mk() { head -c "$2" /dev/zero | tr '\0' "$3" > "$P/$1"; } |
| 20 | mk rm_elf.bin 3000000 '\001'; mk rm_sig.bin 4096 '\002'; mk bootloader.bin 196608 '\003'; mk fmc.bin 9000 '\004' |
| 21 | mk fmc_hash.bin 48 '\005'; mk fmc_pkey.bin 384 '\006'; mk fmc_sig.bin 384 '\007'; mk system_info.bin 936 '\010' |
| 22 | |
| 23 | run() { # name expected-verdict expected-exit args... |
| 24 | local name=$1 want=$2 wexit=$3; shift 3 |
| 25 | local out rc |
| 26 | out=$("$BIN" --pkg "$P" --app-version 7 --out "$T/$name" --polls 50 --pause-us 0 --wait-ms 300 "$@" 2>"$T/$name.err") |
| 27 | rc=$? |
| 28 | if [[ "$out" == *"AIEN_GSP_BOOT: $want"* && $rc -eq $wexit ]]; then ok "$name: $want (exit $rc)" |
| 29 | else bad "$name: got '$out' exit $rc, want '$want' exit $wexit ($(head -c 300 "$T/$name.err"))"; fi |
| 30 | } |
| 31 | run init "INIT-DONE" 0 --sim-events init |
| 32 | run seq "SEQUENCER-REQUESTED" 1 --sim-events seq |
| 33 | run seqregs "INIT-DONE" 0 --sim-events seq-regs |
| 34 | run silent "NO-INIT-DONE" 1 --sim-events none |
| 35 | run junk "STATUS-QUEUE-ERROR" 1 --sim-events junk |
| 36 | run busy "STOPPED-AT E_BUSY" 1 --sim-cfg busy |
| 37 | run fmcerr "STOPPED-AT E_FMC" 1 --sim-cfg fmc-error |
| 38 | run dead "STOPPED-AT E_RISCV" 1 --sim-cfg riscv-dead |
| 39 | run planonly "PLAN-ONLY" 0 --plan-only |
| 40 | run small "BUILD-REFUSED" 2 --sim-arena-mib 2 |
| 41 | [[ ! -s "$T/small/regs.txt" ]] && ok "arena too small: no register touched" || bad "arena too small touched registers" |
| 42 | |
| 43 | # the INIT-DONE run kept its evidence |
| 44 | for f in plan.txt result.txt messages.txt regs.txt cot_packet.bin log-LOGINIT.bin rpc-shared.bin; do |
| 45 | [[ -s "$T/init/$f" ]] && ok "init wrote $f" || bad "init did not write $f" |
| 46 | done |
| 47 | grep -q "function=0x1001" "$T/init/messages.txt" && ok "INIT_DONE recorded in messages.txt" || bad "INIT_DONE not in messages.txt" |
| 48 | [[ $(stat -c %s "$T/init/cot_packet.bin") -eq 868 ]] && ok "COT packet 868 bytes" || bad "COT packet size" |
| 49 | grep -q "verdict=INIT-DONE" "$T/init/result.txt" && ok "result.txt carries the verdict" || bad "result.txt verdict" |
| 50 | |
| 51 | # notify page: a package value is sent as is; a zero field gets the first arena page (sim arena pa 0x4000000000) |
| 52 | q64() { od -An -tx8 -j48 -N8 "$1" | tr -d ' '; } |
| 53 | [[ $(q64 "$T/init/system_info.sent.bin") == 0808080808080808 ]] && ok "package notify address sent unchanged" || bad "notify field changed: $(q64 "$T/init/system_info.sent.bin")" |
| 54 | cp -r "$P" "$T/pkg3"; printf '\0\0\0\0\0\0\0\0' | dd of="$T/pkg3/system_info.bin" bs=1 seek=48 conv=notrunc status=none |
| 55 | "$BIN" --pkg "$T/pkg3" --app-version 7 --out "$T/notify" --plan-only > /dev/null 2>&1 |
| 56 | [[ $(q64 "$T/notify/system_info.sent.bin") == 0000004000000000 ]] && grep -q "notify_page pa=0x4000000000" "$T/notify/plan.txt" \ |
| 57 | && ok "zero notify field filled with the zeroed first arena page" || bad "notify page: $(q64 "$T/notify/system_info.sent.bin")" |
| 58 | cmp -s <(head -c 48 "$T/pkg3/system_info.bin") <(head -c 48 "$T/notify/system_info.sent.bin") \ |
| 59 | && cmp -s <(tail -c +57 "$T/pkg3/system_info.bin") <(tail -c +57 "$T/notify/system_info.sent.bin") \ |
| 60 | && ok "no other GspSystemInfo byte changed" || bad "notify patch touched other bytes" |
| 61 | |
| 62 | # refusal before any register access: a 935-byte GspSystemInfo |
| 63 | cp -r "$P" "$T/pkg2"; head -c 935 "$P/system_info.bin" > "$T/pkg2/system_info.bin" |
| 64 | out=$("$BIN" --pkg "$T/pkg2" --app-version 7 --out "$T/short" 2>/dev/null); rc=$? |
| 65 | [[ "$out" == *"PACKAGE-REFUSED"* && $rc -eq 2 && ! -s "$T/short/regs.txt" ]] && ok "935-byte GspSystemInfo refused, no register touched" || bad "short system_info: '$out' rc $rc" |
| 66 | |
| 67 | # allowlist: the module must let through what the tool uses, and nothing else it writes |
| 68 | sed -n '/AIEN-GPU-ALLOW-BEGIN/,/AIEN-GPU-ALLOW-END/p' "$SHIM" > "$T/allow.c" |
| 69 | rdl=$(sed -n '/aien_gpu_rd_ok/,/};/p' "$T/allow.c" | grep -o '0x[0-9a-f]\{8\}' | sed 's/^0x00//' | sort -u) |
| 70 | wrl=$(sed -n '/aien_gpu_wr_ok/,/};/p' "$T/allow.c" | grep -o '0x[0-9a-f]\{8\}' | sed 's/^0x00//' | sort -u) |
| 71 | used_r=$(cat "$T"/*/regs.txt | awk '$1=="R"{print $2}' | sort -u) |
| 72 | used_w=$(cat "$T"/*/regs.txt | awk '$1=="W"{print $2}' | sort -u) |
| 73 | miss_r=$(comm -23 <(echo "$used_r") <(echo "$rdl")); miss_w=$(comm -23 <(echo "$used_w") <(echo "$wrl")) |
| 74 | [[ -n "$rdl" && -z "$miss_r" ]] && ok "every read the tool made is on the module read list ($(echo "$used_r" | wc -l) registers)" || bad "reads not allowed: $miss_r" |
| 75 | [[ -n "$wrl" && -z "$miss_w" ]] && ok "every write the tool made is on the module write list ($(echo "$used_w" | wc -l) registers)" || bad "writes not allowed: $miss_w" |
| 76 | extra_w=$(comm -13 <(echo "$used_w") <(echo "$wrl") | tr '\n' ' ') |
| 77 | [[ -z "$extra_w" ]] && ok "every write-allowlist register is used by some path" || bad "write list extras: '$extra_w'" |
| 78 | init_qh=$(awk '$1=="W" && $2=="110c00"' "$T/init/regs.txt" | wc -l) |
| 79 | [[ $init_qh -eq 0 ]] && ok "start-up itself does not write GSP QHEAD0" || bad "init wrote QHEAD0 $init_qh times" |
| 80 | seq_qh=$(awk '$1=="W" && $2=="110c00"' "$T/seqregs/regs.txt" | wc -l) |
| 81 | [[ $seq_qh -ge 1 ]] && ok "sequencer path wrote GSP QHEAD0" || bad "seqregs did not write QHEAD0" |
| 82 | doorbells=$(awk '$1=="W" && $2=="840c00"' "$T/init/regs.txt" | wc -l) |
| 83 | [[ $doorbells -eq 1 ]] && ok "one SEC2 doorbell per start-up" || bad "doorbells in one start-up: $doorbells" |
| 84 | |
| 85 | echo "WINDOW1_SIM_TEST: $([[ $fail -eq 0 ]] && echo PASS || echo FAIL)" |
| 86 | exit $fail |