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_gpu_bench_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_gpu_bench_test.sh` 166 lines ยท 9065 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # qemu_ck_gpu_bench_test.sh -- QEMU test for the GPU bench console, driven by the real Spark tool 3 # (tools/ck_gpu_bench.c) over a COM1 socket. QEMU is an emulator: the BARs are RAM stand-ins 4 # (CK_X86_BENCH_TEST=1, see native/kernel/x86/bench_x86.c), not PCI hardware. A PASS qualifies 5 # nothing about the AMD GPU, and the UDP/tg3 transport is not exercised here. 6 # 7 # The kernel is built as the lab image with the test transport and the test key (CK_TEST_SLOT_KEY=1 8 # is the swap owner key; the bench key is the test key in bench_proto.h). The tool connects, waits 9 # for "bench: GPU bench console ready", then sends the script below. Every reply is HMAC-checked by 10 # the tool with its own SHA-256 (a kernel/tool HMAC mismatch fails the run). 11 # 12 # Checks: 13 # ping round trip; dword config read; BAR read and write (write logged before/after in the 14 # kernel); allowlist refusal (RANGE); TSC poll (OK and TIMEOUT); read-modify-write; 15 # replay refused (same counter); bad HMAC refused (AUTH); stale counter refused (AUTH); 16 # all-ones reply stops the tool (device gone): the command after it is never sent. 17 # Final line: AIENOS_GPU_BENCH: PASS|FAIL|NOT_RUN exit 0/1/2/3 18 set -euo pipefail 19 repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 20 cd "${repo_root}" 21 tag="AIENOS_GPU_BENCH" 22 code_fd="${OVMF_CODE:-/usr/share/OVMF/OVMF_CODE_4M.fd}" 23 vars_fd="${OVMF_VARS:-/usr/share/OVMF/OVMF_VARS_4M.fd}" 24 cross="" 25 if [ "$(uname -m)" != "x86_64" ]; then cross="x86_64-linux-gnu-"; fi 26 for t in qemu-system-x86_64 mformat mmd mcopy timeout "${cross}gcc" "${cross}ld"; do 27 command -v "${t}" >/dev/null || { echo "${tag}: NOT_RUN (${t} missing)"; exit 2; } 28 done 29 [[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "${tag}: NOT_RUN (no OVMF)"; exit 2; } 30 31 . "${repo_root}/scripts/lib_gate_hold.sh" 32 if ! gh_quiet_check || ! gh_lock_take qemu_ck_gpu_bench_test "${AIENOS_GATE_MINUTES:-60}"; then 33 echo "${tag}: NOT_RUN (${gh_why})" 34 exit 3 35 fi 36 work="$(mktemp -d)" 37 qpid="" 38 cleanup() { 39 [[ -z "${qpid}" ]] || kill "${qpid}" 2>/dev/null || true 40 # a red run keeps its logs for diagnosis 41 if [[ "${fails:-0}" -gt 0 ]]; then 42 keepdir="${HOME}/handoffs/gpu-bench-logs/${tag}-$(date -u +%Y%m%dT%H%M%SZ)" 43 mkdir -p "${keepdir}" && cp "${work}"/*.log "${work}"/*.txt "${keepdir}/" 2>/dev/null && echo "logs kept: ${keepdir}" 44 fi 45 rm -rf "${work}" 46 gh_lock_release 47 } 48 trap cleanup EXIT 49 50 out="${work}/out" 51 commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" 52 make -s -C native/kernel X86_CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" \ 53 CK_X86_REPORT=1 CK_TEST_SLOT_KEY=1 CK_X86_BENCH=1 CK_X86_BENCH_TEST=1 imac-kernel >/dev/null 54 make -s -C native/kernel OUT="${out}" ck-gpu-bench >/dev/null 55 TOOL="${out}/host/ck_gpu_bench" 56 57 img="${work}/esp.img" 58 truncate -s 64M "${img}" 59 mformat -i "${img}" -F :: 60 mmd -i "${img}" ::/EFI ::/EFI/BOOT 61 mcopy -i "${img}" "${out}/IMACKERN-LAB.EFI" ::/EFI/BOOT/BOOTX64.EFI 62 63 # The script. Register numbers are DWORD indexes: 18432 = 0x4800 (panel allowlist), 64 # 256 = 0x100 (not allowlisted), 4095 = 0x0FFF (the emulated all-ones register). 65 # Allowlist edges (dce_11_2_d.h, smu_7_1_3_d.h): 6660 = 0x1A04 GRPH_PRIMARY_SURFACE_ADDRESS and 66 # 6674 = 0x1A12 GRPH_FLIP_CONTROL (both ends of the DCP0 surface range), 148 = 0x94 SMC_MESSAGE_0, 67 # 149 = 0x95 SMC_RESP_0, 164 = 0xA4 SMC_MSG_ARG_0; refused neighbours 6659 = 0x1A03 GRPH_SWAP_CNTL, 68 # 6675 = 0x1A13, 150 = 0x96 SMC_MESSAGE_1, 165 = 0xA5 SMC_MSG_ARG_1. 69 # The two polls on 0x4800 (holding 0xABCD0001): the first matches the high half; the second waits 70 # for a low half of 0x0002 that never comes, so it must end in TIMEOUT. 71 cat > "${work}/test.bench" <<'BENCH' 72 ping 73 pci_cfg 0 74 bar5_read 16 75 bar5_write 18432 0xABCD0001 76 bar5_read 18432 77 bar5_write 256 1 78 bar0_write 5 0x42 79 bar0_read 5 80 bar5_poll 18432 0xFFFF0000 0xABCD0000 100 81 bar5_poll 18432 0x0000FFFF 0x00000002 50 82 bar5_rmw 18432 0x0000FF00 0x00005500 83 bar5_write 6660 0x11110001 84 bar5_write 6674 0x11110002 85 bar5_write 148 0x11110003 86 bar5_write 149 0x11110004 87 bar5_write 164 0x11110005 88 bar5_write 6659 1 89 bar5_write 6675 1 90 bar5_write 150 1 91 bar5_write 165 1 92 pci_cfg 256 93 replay 94 badauth ping 95 stale ping 96 ping 97 bar5_read 4095 98 ping 99 BENCH 100 101 sock="${work}/com1.sock" 102 serial_log="${work}/serial.log" 103 cp "${vars_fd}" "${work}/vars.fd" 104 qemu-system-x86_64 -M q35 -accel tcg -cpu max -smp 4 -m 1024 \ 105 -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ 106 -drive if=pflash,format=raw,file="${work}/vars.fd" \ 107 -drive if=none,id=esp,format=raw,file="${img}" -device ide-hd,drive=esp,bus=ide.0 \ 108 -device qemu-xhci -device usb-kbd \ 109 -nographic -monitor none -serial unix:"${sock}",server=on,wait=on -no-reboot >"${serial_log}" 2>&1 & 110 qpid=$! 111 for _ in $(seq 1 100); do [[ -S "${sock}" ]] && break; sleep 0.2; done 112 113 fails=0 114 pass() { echo "PASS $1"; } 115 fail() { echo "FAIL $1"; fails=$((fails + 1)); } 116 chk() { # name regex file 117 if grep -aqE -- "$2" "$3"; then pass "$1"; else fail "$1 (no line matching: $2)"; fi 118 } 119 120 tool_rc=0 121 timeout "${AIENOS_BENCH_TOOL_TIMEOUT:-1500}" "${TOOL}" --serial "${sock}" \ 122 --transcript "${work}/transcript.txt" "${work}/test.bench" \ 123 >"${work}/tool.out" 2>"${work}/tool.err" || tool_rc=$? 124 kill "${qpid}" 2>/dev/null || true; wait "${qpid}" 2>/dev/null || true; qpid="" 125 126 tr -d '\r' < "${work}/tool.out" > "${work}/tool.txt" 127 echo "--- tool output ---"; cat "${work}/tool.txt" 128 echo "--- tool stderr ---"; cat "${work}/tool.err" 129 130 chk "kernel: bench console up (test build, emulated BARs)" "bench: GPU bench console ready" "${work}/transcript.txt" 131 chk "ping round trip" "^ping OK: result=0x00000000" "${work}/tool.txt" 132 chk "config read (dword 0 = 1002:67ef)" "^pci_cfg OK: result=0x67ef1002" "${work}/tool.txt" 133 chk "BAR5 read of a known word" "^bar5_read OK: result=0xc0ffee00" "${work}/tool.txt" 134 chk "BAR5 write on the allowlist (before 0, after ABCD0001)" "^bar5_write OK: result=0xabcd0001 before=0x00000000" "${work}/tool.txt" 135 chk "kernel logged the write before and after" "bench: bar5_write reg=0x4800 0x00000000 -> 0xabcd0001" "${work}/transcript.txt" 136 chk "BAR5 read back the written value" "^bar5_read OK: result=0xabcd0001" "${work}/tool.txt" 137 chk "BAR5 write off the allowlist refused (RANGE)" "^bar5_write ERR_RANGE: result=0x00000000" "${work}/tool.txt" 138 chk "GRPH primary surface address 0x1A04 writable" "^bar5_write OK: result=0x11110001 before=0x00000000" "${work}/tool.txt" 139 chk "GRPH flip control 0x1A12 writable (top of the range)" "^bar5_write OK: result=0x11110002 before=0x00000000" "${work}/tool.txt" 140 chk "SMC_MESSAGE_0 0x94 writable" "^bar5_write OK: result=0x11110003 before=0x00000000" "${work}/tool.txt" 141 chk "SMC_RESP_0 0x95 writable" "^bar5_write OK: result=0x11110004 before=0x00000000" "${work}/tool.txt" 142 chk "SMC_MSG_ARG_0 0xA4 writable" "^bar5_write OK: result=0x11110005 before=0x00000000" "${work}/tool.txt" 143 chk "kernel logged the GRPH write" "bench: bar5_write reg=0x1a04 0x00000000 -> 0x11110001" "${work}/transcript.txt" 144 ranges=$(grep -ac "^bar5_write ERR_RANGE" "${work}/tool.txt" || true) 145 if [[ "${ranges}" == "5" ]]; then pass "writes just outside each new range refused (0x1A03, 0x1A13, 0x96, 0xA5, plus 0x100): 5 RANGE"; else fail "bar5_write RANGE refusals: ${ranges} (expected 5)"; fi 146 chk "BAR0 write and read back" "^bar0_read OK: result=0x00000042" "${work}/tool.txt" 147 chk "TSC poll satisfied" "^bar5_poll OK: result=0xabcd0001" "${work}/tool.txt" 148 chk "TSC poll timed out" "^bar5_poll ERR_TIMEOUT" "${work}/tool.txt" 149 chk "read-modify-write" "^bar5_rmw OK: result=0xabcd5501 before=0xabcd0001" "${work}/tool.txt" 150 chk "config offset out of range refused" "^pci_cfg ERR_RANGE" "${work}/tool.txt" 151 chk "replay refused (same counter)" "^replay ERR_AUTH" "${work}/tool.txt" 152 chk "bad HMAC refused" "^badauth ping ERR_AUTH" "${work}/tool.txt" 153 chk "stale counter refused" "^stale ping ERR_AUTH" "${work}/tool.txt" 154 chk "all-ones read reported (device gone)" "^bar5_read ERR_ALLONES" "${work}/tool.txt" 155 if grep -aq "device gone (all-ones); stopping" "${work}/tool.err"; then pass "tool stopped at the all-ones reply"; else fail "tool stopped at the all-ones reply"; fi 156 pings=$(grep -ac "^ping " "${work}/tool.txt" || true) 157 if [[ "${pings}" == "2" ]]; then pass "the ping after the all-ones reply was never sent (2 ping replies, not 3)"; else fail "ping replies: ${pings} (expected 2)"; fi 158 reqs=$(grep -ac "^ABCHREQ " "${work}/transcript.txt" || true) 159 results=$(grep -acE " (OK|ERR_[A-Z]+): result=" "${work}/tool.txt" || true) 160 if [[ "${reqs}" == "${results}" && "${results}" -gt 0 ]]; then pass "one reply per request on the link (${results})"; else fail "requests ${reqs} vs results ${results}"; fi 161 if grep -aq "HMAC mismatch\|no response" "${work}/tool.err"; then fail "kernel and tool disagree on an HMAC or a reply"; else pass "every kernel reply carries the HMAC the tool expects"; fi 162 if [[ "${tool_rc}" == "1" ]]; then pass "tool exit 1 (the ALLONES stop)"; else fail "tool exit ${tool_rc} (expected 1)"; fi 163 164 [[ ${fails} -eq 0 ]] && echo "${tag}: PASS" && exit 0 165 echo "${tag}: FAIL (${fails} failures)" 166 exit 1