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 / scripts / qemu_ck_b7b_probe_test.sh
| 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 | # B7b preparation probe gate (aienos#286). Boots the C kernel core image built |
| 18 | # with CK_B7B_PROBE=1 in QEMU AArch64 (UEFI/AAVMF, EL2, iommu=smmuv3) and checks |
| 19 | # the probe lines of core/smmu_svc.c ck_b7b_probe. QEMU is not hardware: a PASS |
| 20 | # here qualifies nothing physical; on the DGX Spark the probe is the attended B7b |
| 21 | # step and needs Drake's go (docs/GB10_IORT_DECODE.md section 10). |
| 22 | # |
| 23 | # Modes: |
| 24 | # (default) probe image as it would boot on the Spark: segment 15 rid |
| 25 | # 0x100. QEMU virt has no segment 15, so the probe must refuse, |
| 26 | # fail closed: route none, confine rc=-3 (nostream), nothing |
| 27 | # confined, "AIENOS_B7B_PROBE: REFUSED", the boot goes on (the |
| 28 | # SMP summary follows) and ends without a panic. |
| 29 | # Last line AIENOS_CK_B7B_PROBE: PASS|FAIL|NOT_RUN. |
| 30 | # --positive TEST-ONLY image (CK_B7B_PROBE_TEST_SEGMENT0=1) probing segment |
| 31 | # 0 rid 0x100: the route names instance 0 stream 0x100, the |
| 32 | # confinement is granted on one page, IDR0/IDR1 are read with a |
| 33 | # SIDSIZE that covers stream 0x100, the unconfine returns 0 and |
| 34 | # the summary is CONFINED_AND_RELEASED. |
| 35 | # Last line AIENOS_CK_B7B_PROBE_POSITIVE: PASS|FAIL|NOT_RUN. |
| 36 | # --events TEST-ONLY full image plus disposable NVMe/GPT disk. The |
| 37 | # existing negative DMA test must produce a decoded event for |
| 38 | # its exact SID/address, and every live queue is drained before |
| 39 | # the final report. No physical GPU behavior is exercised. |
| 40 | # --self-test canned serial logs for every failure mode below plus the |
| 41 | # Makefile refusals of the probe flags; no QEMU, no compile. |
| 42 | # Last line AIENOS_CK_B7B_PROBE_SELF_TEST: PASS|FAIL. |
| 43 | # Environment: AIENOS_QEMU_TIMEOUT (180 s), AIENOS_QUIET_FLAG (read only), |
| 44 | # AIENOS_GATE_LOCK / AIENOS_GATE_MINUTES, AIENOS_LOG_DIR, AIENOS_QEMU_VERBOSE. |
| 45 | # Prints NOT_RUN (exit 3) while the quiet flag or the QEMU gate lock is held. |
| 46 | set -euo pipefail |
| 47 | |
| 48 | repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 49 | cd "${repo_root}" |
| 50 | |
| 51 | mode=gate |
| 52 | case "${1:-}" in |
| 53 | "") ;; |
| 54 | --positive) mode=positive ;; |
| 55 | --events) mode=events ;; |
| 56 | --self-test) mode=self ;; |
| 57 | *) echo "usage: $0 [--positive|--events|--self-test]" >&2; exit 2 ;; |
| 58 | esac |
| 59 | test_marker="TEST-ONLY B7b probe on PCI segment 0" |
| 60 | |
| 61 | # check_refused FILE: the Spark-target probe on a machine without segment 15. |
| 62 | check_refused() { |
| 63 | local f="$1" |
| 64 | ok() { echo "PASS $*"; } |
| 65 | bad() { echo "FAIL $*"; failed=1; } |
| 66 | [[ "$(grep -cE '^b7b_probe: start segment=15 rid=0x100 window_bytes=4096 no_dma=yes$' "${f}" || true)" == 1 ]] \ |
| 67 | && ok "one probe start, segment 15 rid 0x100" || bad "expected exactly one 'b7b_probe: start segment=15 rid=0x100' line" |
| 68 | grep -qE '^b7b_probe: route none \(smmus=[0-9]+\)$' "${f}" && ok "IORT has no route for segment 15" || bad "no 'route none' line" |
| 69 | grep -qE '^b7b_probe: confine refused rc=-3 \(nostream\); nothing granted$' "${f}" \ |
| 70 | && ok "confinement refused with nostream" || bad "no 'confine refused rc=-3 (nostream)' line" |
| 71 | if grep -qE '^b7b_probe: confined ' "${f}"; then bad "something was confined"; else ok "nothing confined"; fi |
| 72 | [[ "$(grep -cE '^AIENOS_B7B_PROBE: ' "${f}" || true)" == 1 ]] && grep -qE '^AIENOS_B7B_PROBE: REFUSED$' "${f}" \ |
| 73 | && ok "one summary: REFUSED" || bad "summary is not exactly one 'AIENOS_B7B_PROBE: REFUSED'" |
| 74 | if grep -qF "${test_marker}" "${f}"; then bad "TEST-ONLY segment-0 image booted"; else ok "Spark-target probe image (no TEST-ONLY marker)"; fi |
| 75 | common_tail "${f}" |
| 76 | } |
| 77 | |
| 78 | # check_positive FILE: TEST-ONLY segment-0 probe on QEMU's SMMUv3. |
| 79 | check_positive() { |
| 80 | local f="$1" line sidsize |
| 81 | ok() { echo "PASS $*"; } |
| 82 | bad() { echo "FAIL $*"; failed=1; } |
| 83 | grep -qF "${test_marker}" "${f}" && ok "TEST-ONLY image announced itself" || bad "no TEST-ONLY announcement" |
| 84 | [[ "$(grep -cE '^b7b_probe: start segment=0 rid=0x100 window_bytes=4096 no_dma=yes$' "${f}" || true)" == 1 ]] \ |
| 85 | && ok "one probe start, segment 0 rid 0x100" || bad "expected exactly one 'b7b_probe: start segment=0 rid=0x100' line" |
| 86 | grep -qE '^b7b_probe: route instance=0 base=0x[0-9a-f]+ stream=0x100 rmr_nodes=0 \(smmus=1\)$' "${f}" \ |
| 87 | && ok "route: instance 0, stream 0x100" || bad "no route line for instance 0 stream 0x100" |
| 88 | grep -qE '^b7b_probe: confined stream=0x100 smmu_base=0x[0-9a-f]+ iova=0x[0-9a-f]*000 len=0x1000$' "${f}" \ |
| 89 | && ok "one page confined on stream 0x100" || bad "no 'confined stream=0x100 ... len=0x1000' line" |
| 90 | line="$(grep -E '^b7b_probe: instance=0 idr0=0x[0-9a-f]{8} idr1=0x[0-9a-f]{8} st_level=[0-3] sidsize=[0-9]+$' "${f}" || true)" |
| 91 | sidsize="$(sed -nE 's/.* sidsize=([0-9]+)$/\1/p' <<<"${line}")" |
| 92 | if [[ -n "${sidsize}" && "${sidsize}" -ge 9 ]]; then ok "IDR0/IDR1 read, SIDSIZE ${sidsize} covers stream 0x100"; else bad "no IDR line with SIDSIZE >= 9"; fi |
| 93 | grep -qE '^b7b_probe: unconfine rc=0 \(ok\); stream 0x100 aborts again$' "${f}" && ok "unconfine rc=0" || bad "unconfine did not return 0" |
| 94 | [[ "$(grep -cE '^AIENOS_B7B_PROBE: ' "${f}" || true)" == 1 ]] && grep -qE '^AIENOS_B7B_PROBE: CONFINED_AND_RELEASED$' "${f}" \ |
| 95 | && ok "one summary: CONFINED_AND_RELEASED" || bad "summary is not exactly one 'AIENOS_B7B_PROBE: CONFINED_AND_RELEASED'" |
| 96 | common_tail "${f}" |
| 97 | } |
| 98 | |
| 99 | # common_tail FILE: the probe ran after "kernel: alive", the boot went on to the |
| 100 | # SMP summary, and no panic or exception report followed. |
| 101 | common_tail() { |
| 102 | local f="$1" a p s |
| 103 | a="$(grep -nE '^kernel: alive$' "${f}" | head -1 | cut -d: -f1)" |
| 104 | p="$(grep -nE '^b7b_probe: start ' "${f}" | head -1 | cut -d: -f1)" |
| 105 | s="$(grep -nE '^smp: cpus=' "${f}" | head -1 | cut -d: -f1)" |
| 106 | if [[ -n "${a}" && -n "${p}" && -n "${s}" && "${a}" -lt "${p}" && "${p}" -lt "${s}" ]]; then |
| 107 | ok "probe ran after 'kernel: alive' and the boot went on (SMP summary follows)" |
| 108 | else |
| 109 | bad "probe not between 'kernel: alive' and the SMP summary (alive=${a:-none} probe=${p:-none} smp=${s:-none})" |
| 110 | fi |
| 111 | if grep -qE '^report_kind: panic|^panic:|^exception:' "${f}"; then bad "panic or exception after the probe"; else ok "no panic or exception"; fi |
| 112 | } |
| 113 | |
| 114 | check_events() { |
| 115 | local f="$1" line sid addr begin end final |
| 116 | check_positive "${f}" |
| 117 | line="$(grep -E '^smmu_negative: refused dma outside window .*faults=[1-9][0-9]* type=0x10 .*page=intact .*recovery_read=ok' "${f}" || true)" |
| 118 | if [[ "${line}" =~ sid=(0x[0-9a-f]+)[[:space:]]addr=(0x[0-9a-f]+) ]]; then |
| 119 | sid="${BASH_REMATCH[1]}"; addr="${BASH_REMATCH[2]}" |
| 120 | grep -qE "^b7b_event: instance=0 base=0x9050000 sid=${sid} type=0x10 name=F_TRANSLATION addr=${addr} raw=[0-9a-f]{16},[0-9a-f]{16},[0-9a-f]{16},[0-9a-f]{16}$" "${f}" \ |
| 121 | && ok "real out-of-window NVMe DMA has matching decoded event" || bad "missing matching SID/address decoded event" |
| 122 | else |
| 123 | bad "no successful negative DMA oracle" |
| 124 | fi |
| 125 | begin="$(grep -n '^b7b_events: final begin all_sids=yes$' "${f}" | cut -d: -f1)" |
| 126 | end="$(grep -n '^b7b_events: final end$' "${f}" | cut -d: -f1)" |
| 127 | final="$(grep -n '^report_kind: final$' "${f}" | cut -d: -f1)" |
| 128 | if [[ "${begin}" =~ ^[0-9]+$ && "${end}" =~ ^[0-9]+$ && "${final}" =~ ^[0-9]+$ ]] \ |
| 129 | && (( begin < end && end < final )); then |
| 130 | ok "one final queue readout before final report" |
| 131 | else |
| 132 | bad "final readout missing, duplicated or out of order" |
| 133 | fi |
| 134 | grep -qE '^b7b_events: instance=0 base=0x9050000 events=[0-9]+ overflow=0 pending=0$' "${f}" \ |
| 135 | && ok "live queue drained without loss" || bad "no live queue completion" |
| 136 | if grep -qE '^b7b_events: .*overflow=1|^b7b_events: .*pending=1' "${f}"; then |
| 137 | bad "queue loss or incomplete readout" |
| 138 | fi |
| 139 | } |
| 140 | |
| 141 | self_test() { |
| 142 | local tmp st_fail=0 |
| 143 | tmp="$(mktemp -d)" |
| 144 | trap 'rm -rf "${tmp}"' RETURN |
| 145 | expect() { # NAME pass|fail CHECKER FILE |
| 146 | local out; failed=0 |
| 147 | out="$("$3" "$4")"; failed=0; grep -q '^FAIL' <<<"${out}" && failed=1 |
| 148 | if [[ "$2" == pass && "${failed}" == 0 ]] || [[ "$2" == fail && "${failed}" == 1 ]]; then |
| 149 | echo "PASS self-test $1 -> $2" |
| 150 | else |
| 151 | echo "FAIL self-test $1 expected $2: $(grep '^FAIL' <<<"${out}" | head -2 | paste -sd';' -)"; st_fail=1 |
| 152 | fi |
| 153 | } |
| 154 | cat >"${tmp}/refused" <<'LOG' |
| 155 | kernel: alive |
| 156 | kernel_el: EL1h |
| 157 | b7b_probe: start segment=15 rid=0x100 window_bytes=4096 no_dma=yes |
| 158 | b7b_probe: route none (smmus=1) |
| 159 | b7b_probe: confine refused rc=-3 (nostream); nothing granted |
| 160 | AIENOS_B7B_PROBE: REFUSED |
| 161 | smp: cpus=2 checked_in=2 psci_errors=0 distinct_mpidrs=2 wait_us=10 result=ok |
| 162 | report_kind: final |
| 163 | LOG |
| 164 | cat >"${tmp}/positive" <<'LOG' |
| 165 | kernel: alive |
| 166 | b7b_probe: TEST-ONLY B7b probe on PCI segment 0 (QEMU positive path); never hardware evidence |
| 167 | b7b_probe: start segment=0 rid=0x100 window_bytes=4096 no_dma=yes |
| 168 | b7b_probe: route instance=0 base=0x9050000 stream=0x100 rmr_nodes=0 (smmus=1) |
| 169 | b7b_probe: confined stream=0x100 smmu_base=0x9050000 iova=0x7f000000 len=0x1000 |
| 170 | b7b_probe: instance=0 idr0=0x0a0d7fbf idr1=0x00e73210 st_level=1 sidsize=16 |
| 171 | b7b_probe: unconfine rc=0 (ok); stream 0x100 aborts again |
| 172 | AIENOS_B7B_PROBE: CONFINED_AND_RELEASED |
| 173 | smp: cpus=2 checked_in=2 psci_errors=0 distinct_mpidrs=2 wait_us=10 result=ok |
| 174 | report_kind: final |
| 175 | LOG |
| 176 | expect refused-good pass check_refused "${tmp}/refused" |
| 177 | expect positive-good pass check_positive "${tmp}/positive" |
| 178 | # Refusal gate: anything granted, wrong target, forged summary, missing lines, panic, wrong order, TEST image. |
| 179 | expect positive-log-on-refusal-gate fail check_refused "${tmp}/positive" |
| 180 | sed 's/^b7b_probe: confine refused.*/b7b_probe: confined stream=0x100 smmu_base=0x9050000 iova=0x7f000000 len=0x1000/' "${tmp}/refused" >"${tmp}/r1"; expect refused-but-confined fail check_refused "${tmp}/r1" |
| 181 | sed 's/segment=15/segment=14/' "${tmp}/refused" >"${tmp}/r2"; expect wrong-segment fail check_refused "${tmp}/r2" |
| 182 | sed 's/rc=-3 (nostream)/rc=-2 (failed)/' "${tmp}/refused" >"${tmp}/r3"; expect refused-other-reason fail check_refused "${tmp}/r3" |
| 183 | grep -v '^AIENOS_B7B_PROBE' "${tmp}/refused" >"${tmp}/r4"; expect no-summary fail check_refused "${tmp}/r4" |
| 184 | { cat "${tmp}/refused"; echo "AIENOS_B7B_PROBE: REFUSED"; } >"${tmp}/r5"; expect two-summaries fail check_refused "${tmp}/r5" |
| 185 | grep -v '^smp: cpus=' "${tmp}/refused" >"${tmp}/r6"; expect boot-stopped fail check_refused "${tmp}/r6" |
| 186 | { cat "${tmp}/refused"; echo "report_kind: panic"; } >"${tmp}/r7"; expect panic fail check_refused "${tmp}/r7" |
| 187 | grep -v '^kernel: alive' "${tmp}/refused" >"${tmp}/r8"; expect not-after-alive fail check_refused "${tmp}/r8" |
| 188 | sed 's/^b7b_probe: route none.*/b7b_probe: route instance=1 base=0x13000000 stream=0x100 rmr_nodes=1 (smmus=3)/' "${tmp}/refused" >"${tmp}/r9"; expect route-found-on-refusal fail check_refused "${tmp}/r9" |
| 189 | { echo "${test_marker} (QEMU positive path); never hardware evidence"; cat "${tmp}/refused"; } >"${tmp}/r10"; expect test-image-on-gate fail check_refused "${tmp}/r10" |
| 190 | # Positive path: missing announcement, unconfine failure, short SIDSIZE, no IDR line, wrong length, forged summary. |
| 191 | grep -v 'TEST-ONLY' "${tmp}/positive" >"${tmp}/p1"; expect positive-no-announcement fail check_positive "${tmp}/p1" |
| 192 | sed 's/unconfine rc=0 (ok)/unconfine rc=-4 (earg)/' "${tmp}/positive" >"${tmp}/p2"; expect unconfine-fails fail check_positive "${tmp}/p2" |
| 193 | sed 's/sidsize=16/sidsize=8/' "${tmp}/positive" >"${tmp}/p3"; expect sidsize-too-small fail check_positive "${tmp}/p3" |
| 194 | grep -v 'idr0=' "${tmp}/positive" >"${tmp}/p4"; expect no-idr-line fail check_positive "${tmp}/p4" |
| 195 | sed 's/len=0x1000/len=0x2000/' "${tmp}/positive" >"${tmp}/p5"; expect wrong-window fail check_positive "${tmp}/p5" |
| 196 | sed 's/CONFINED_AND_RELEASED/FAIL/' "${tmp}/positive" >"${tmp}/p6"; expect positive-summary-fail fail check_positive "${tmp}/p6" |
| 197 | grep -v '^report_kind: final$' "${tmp}/positive" >"${tmp}/events" |
| 198 | cat >>"${tmp}/events" <<'LOG' |
| 199 | b7b_event: instance=0 base=0x9050000 sid=0x108 type=0x10 name=F_TRANSLATION addr=0x12345000 raw=0000010800000010,0000000000000000,0000000012345000,0000000000000000 |
| 200 | smmu_negative: refused dma outside window iova=0x12345000 faults=1 type=0x10 sid=0x108 addr=0x12345000 page=intact cmd_rc=-1 recovery_read=ok |
| 201 | b7b_events: final begin all_sids=yes |
| 202 | b7b_events: instance=0 base=0x9050000 events=0 overflow=0 pending=0 |
| 203 | b7b_events: final end |
| 204 | report_kind: final |
| 205 | LOG |
| 206 | expect events-good pass check_events "${tmp}/events" |
| 207 | grep -v '^b7b_event:' "${tmp}/events" >"${tmp}/e1"; expect events-no-readout fail check_events "${tmp}/e1" |
| 208 | sed '/^b7b_event:/s/sid=0x108/sid=0x109/' "${tmp}/events" >"${tmp}/e2"; expect events-wrong-sid fail check_events "${tmp}/e2" |
| 209 | sed '/^b7b_event:/s/addr=0x12345000/addr=0x12346000/' "${tmp}/events" >"${tmp}/e3"; expect events-wrong-address fail check_events "${tmp}/e3" |
| 210 | sed 's/overflow=0/overflow=1/' "${tmp}/events" >"${tmp}/e4"; expect events-overflow fail check_events "${tmp}/e4" |
| 211 | sed 's/pending=0/pending=1/' "${tmp}/events" >"${tmp}/e5"; expect events-pending fail check_events "${tmp}/e5" |
| 212 | |
| 213 | # Makefile refusals: parse-time $(error), nothing is compiled (make -n). |
| 214 | refuse() { # NAME MESSAGE MAKE-ARGS... |
| 215 | local name="$1" msg="$2" out rc; shift 2 |
| 216 | out="$(make -n -s -C native/kernel "$@" OUT="${tmp}/o_${name}" 2>&1)"; rc=$? |
| 217 | if [[ ${rc} != 0 ]] && grep -qF "${msg}" <<<"${out}" && [[ ! -e "${tmp}/o_${name}" ]]; then |
| 218 | echo "PASS self-test Makefile refuses ${name}" |
| 219 | else |
| 220 | echo "FAIL self-test Makefile did not refuse ${name} (rc=${rc}): ${out:0:200}"; st_fail=1 |
| 221 | fi |
| 222 | } |
| 223 | refuse probe-bad-value "CK_B7B_PROBE must be empty or 1" CK_B7B_PROBE=2 |
| 224 | refuse seg0-without-probe "CK_B7B_PROBE_TEST_SEGMENT0 needs CK_B7B_PROBE=1" CK_B7B_PROBE_TEST_SEGMENT0=1 |
| 225 | refuse seg0-with-staging "CK_B7B_PROBE_TEST_SEGMENT0 (TEST-only QEMU positive path) cannot be combined with CK_HARDWARE_STAGING" \ |
| 226 | CK_B7B_PROBE=1 CK_B7B_PROBE_TEST_SEGMENT0=1 CK_HARDWARE_STAGING=1 |
| 227 | refuse probe-with-unsafe-dma "CK_B7B_PROBE cannot be combined with CK_QEMU_UNSAFE_DMA" CK_B7B_PROBE=1 CK_QEMU_UNSAFE_DMA=1 |
| 228 | refuse events-without-probe "CK_B7B_EVENT_READOUT requires CK_B7B_PROBE=1" CK_B7B_EVENT_READOUT=1 |
| 229 | refuse events-bad-value "CK_B7B_EVENT_READOUT must be empty or 1" CK_B7B_PROBE=1 CK_B7B_EVENT_READOUT=2 |
| 230 | if grep -qE '^#if defined\(CK_B7B_PROBE_TEST_SEGMENT0\) && defined\(CK_HARDWARE_STAGING\)$' native/kernel/core/smmu_svc.c; then |
| 231 | echo "PASS self-test core/smmu_svc.c also refuses the segment-0 probe in a hardware staging compile" |
| 232 | else |
| 233 | echo "FAIL self-test core/smmu_svc.c lacks the #error guard"; st_fail=1 |
| 234 | fi |
| 235 | |
| 236 | [[ ${st_fail} == 0 ]] && { echo "AIENOS_CK_B7B_PROBE_SELF_TEST: PASS"; exit 0; } |
| 237 | echo "AIENOS_CK_B7B_PROBE_SELF_TEST: FAIL"; exit 1 |
| 238 | } |
| 239 | if [[ "${mode}" == self ]]; then |
| 240 | set +e |
| 241 | self_test |
| 242 | fi |
| 243 | |
| 244 | # --------------------------------------------------------------- QEMU boot |
| 245 | verdict_name=AIENOS_CK_B7B_PROBE |
| 246 | [[ "${mode}" == positive ]] && verdict_name=AIENOS_CK_B7B_PROBE_POSITIVE |
| 247 | [[ "${mode}" == events ]] && verdict_name=AIENOS_CK_B7B_EVENTS |
| 248 | |
| 249 | code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" |
| 250 | vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" |
| 251 | command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; echo "${verdict_name}: NOT_RUN"; exit 2; } |
| 252 | [[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "AAVMF firmware not found"; echo "${verdict_name}: NOT_RUN"; exit 2; } |
| 253 | |
| 254 | cross="" |
| 255 | if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi |
| 256 | commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" |
| 257 | if [[ "${mode}" == events ]]; then |
| 258 | out="${repo_root}/target/native-kernel-test-b7b-events" |
| 259 | make -s -C native/kernel full gpt-image CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" \ |
| 260 | CK_B7B_PROBE=1 CK_B7B_PROBE_TEST_SEGMENT0=1 CK_B7B_EVENT_READOUT=1 >/dev/null |
| 261 | elif [[ "${mode}" == positive ]]; then |
| 262 | out="${repo_root}/target/native-kernel-test-b7b-seg0" |
| 263 | make -s -C native/kernel CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" CK_B7B_PROBE=1 CK_B7B_PROBE_TEST_SEGMENT0=1 >/dev/null |
| 264 | else |
| 265 | out="${repo_root}/target/native-kernel-b7b-probe" |
| 266 | make -s -C native/kernel CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" CK_B7B_PROBE=1 >/dev/null |
| 267 | fi |
| 268 | |
| 269 | . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib_gate_hold.sh" |
| 270 | if ! gh_quiet_check || ! gh_lock_take "qemu_ck_b7b_probe_test" "${AIENOS_GATE_MINUTES:-60}"; then |
| 271 | echo "NOT_RUN ${gh_why}" |
| 272 | echo "${verdict_name}: NOT_RUN" |
| 273 | exit 3 |
| 274 | fi |
| 275 | release_flag() { gh_lock_release; } |
| 276 | work="$(mktemp -d)" |
| 277 | cleanup() { |
| 278 | rm -rf "${work}" |
| 279 | release_flag |
| 280 | } |
| 281 | trap cleanup EXIT |
| 282 | mkdir -p "${work}/esp/EFI/BOOT" "${work}/esp/EFI/AIENOS" |
| 283 | touch "${work}/esp/EFI/AIENOS/BOOTREPORT.TXT" |
| 284 | extra_devices=() |
| 285 | image="${out}/BOOTAA64.EFI" |
| 286 | if [[ "${mode}" == events ]]; then |
| 287 | image="${out}/full/BOOTAA64.EFI" |
| 288 | "${out}/host/ck_gpt_image" create "${work}/nvme.img" 512 64 aienos-middle >/dev/null |
| 289 | extra_devices=(-drive "if=none,id=nvme,format=raw,file=${work}/nvme.img" -device nvme,drive=nvme,serial=b7b-events) |
| 290 | fi |
| 291 | cp "${image}" "${work}/esp/EFI/BOOT/BOOTAA64.EFI" |
| 292 | cp "${vars_fd}" "${work}/vars.fd" |
| 293 | log="${work}/serial.log" |
| 294 | |
| 295 | # Same machine as scripts/qemu_ck_smp_test.sh plus the SMMUv3 vIOMMU (as scripts/qemu_keyboard_test.sh). |
| 296 | started=$(date +%s) |
| 297 | set +e |
| 298 | timeout "${AIENOS_QEMU_TIMEOUT:-180}" qemu-system-aarch64 \ |
| 299 | -M virt,virtualization=on,gic-version=3,iommu=smmuv3 -accel tcg,thread=single -cpu max -smp 2 -m 2048 \ |
| 300 | -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ |
| 301 | -drive if=pflash,format=raw,file="${work}/vars.fd" \ |
| 302 | -drive if=none,id=esp,format=raw,file=fat:rw:"${work}/esp" \ |
| 303 | -device virtio-blk-pci,drive=esp \ |
| 304 | "${extra_devices[@]}" \ |
| 305 | -device ramfb -display none -nic none \ |
| 306 | -serial file:"${log}" -no-reboot |
| 307 | qemu_status=$? |
| 308 | set -e |
| 309 | elapsed=$(( $(date +%s) - started )) |
| 310 | release_flag |
| 311 | |
| 312 | tr -d '\r' <"${log}" >"${work}/serial.txt" |
| 313 | [[ -z "${AIENOS_LOG_DIR:-}" ]] || cp "${work}/serial.txt" "${AIENOS_LOG_DIR}/qemu_ck_b7b_probe_${mode}_serial.log" |
| 314 | echo "qemu exit ${qemu_status} after ${elapsed} s (commit ${commit:0:12}, ${mode})" |
| 315 | |
| 316 | failed=0 |
| 317 | if [[ "${mode}" == events ]]; then |
| 318 | results="$(check_events "${work}/serial.txt")" || true |
| 319 | elif [[ "${mode}" == positive ]]; then |
| 320 | results="$(check_positive "${work}/serial.txt")" || true |
| 321 | else |
| 322 | results="$(check_refused "${work}/serial.txt")" || true |
| 323 | fi |
| 324 | grep -q '^FAIL' <<<"${results}" && failed=1 |
| 325 | printf '%s\n' "${results}" |
| 326 | if [[ "${qemu_status}" == 0 ]]; then echo "PASS QEMU exit 0 (PSCI reset)"; else echo "FAIL QEMU exit ${qemu_status}"; failed=1; fi |
| 327 | grep -E '^b7b_probe: |^AIENOS_B7B_PROBE: |^smmu: |^b7b_event|^b7b_rmr|^smmu_negative:' "${work}/serial.txt" | sed 's/^/LOG /' |
| 328 | if [[ "${failed}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then |
| 329 | echo "---- serial console ----" |
| 330 | cat "${work}/serial.txt" |
| 331 | fi |
| 332 | if [[ "${failed}" == 0 ]]; then |
| 333 | echo "${verdict_name}: PASS" |
| 334 | exit 0 |
| 335 | fi |
| 336 | echo "${verdict_name}: FAIL" |
| 337 | exit 1 |