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_fpu_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_fpu_test.sh` 168 lines ยท 9293 bytes Raw Blame History 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 # Boot the AIENOS C kernel with the FP/SIMD Rust probe linked in (QEMU AArch64, 18 # UEFI/AAVMF, EL2 like Machine 1) and check that the kernel, built 19 # -mgeneral-regs-only, ran ONE floating-point/SIMD-enabled Rust unit 20 # (crates/aienos-fpu-probe: f32 dot product, exp approximation, NEON 4-lane 21 # add) and printed its results (aienos#34 lane 0). 22 # Last line: AIENOS_CK_FPU: PASS|FAIL|NOT_RUN (read by scripts/ck_gates.sh). 23 # NOT_RUN (never a silent pass) when cargo, the aarch64-unknown-none Rust 24 # target, qemu or AAVMF is missing, the QEMU gate lock (~/workspace/ 25 # .qemu-gate-lock) is held by another gate run, or the machine quiet flag 26 # (~/workspace/.spark-quiet) exists; this script never writes the quiet flag. 27 # QEMU is not hardware: a PASS here qualifies nothing physical. 28 # 29 # FAIL when the script re-checks the serial lines itself and finds: no 30 # "fpu:" line, rc != 0, any of the five result words different from the known 31 # bit patterns (dot=68.0, NEON 11/22/33/44), exp(1) outside 1e-4 of e, a 32 # kernel-printed PASS the script does not reproduce, a panic/fault report, a 33 # missing "kernel: alive", or a non-zero QEMU exit. 34 # 35 # Usage: bash scripts/qemu_ck_fpu_test.sh the gate 36 # bash scripts/qemu_ck_fpu_test.sh --self-test canned logs, no QEMU/build 37 # Environment: AIENOS_QEMU_TIMEOUT (180 s), AIENOS_GATE_LOCK, AIENOS_GATE_MINUTES, 38 # AIENOS_QUIET_FLAG (read only), 39 # AIENOS_LOG_DIR, AIENOS_QEMU_VERBOSE. 40 set -euo pipefail 41 42 repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 43 cd "${repo_root}" 44 verdict_name=AIENOS_CK_FPU 45 46 # fpu_check_log FILE: PASS/FAIL line per check; sets fpu_failed=1 on failure. 47 fpu_check_log() { 48 local f="$1" line re bits dot e rc 49 ok() { echo "PASS $*"; } 50 bad() { echo "FAIL $*"; fpu_failed=1; } 51 re='^fpu: el1_cpacr=0x([0-9a-f]+) rc=(-?[0-9]+) dot_bits=0x([0-9a-f]+) exp1_bits=0x([0-9a-f]+) neon_bits=0x([0-9a-f]+),0x([0-9a-f]+),0x([0-9a-f]+),0x([0-9a-f]+)$' 52 if [[ "$(grep -cE "${re}" "${f}" || true)" != 1 ]]; then 53 bad "exactly one well-formed fpu: result line" 54 else 55 line="$(grep -E "${re}" "${f}")" 56 rc="$(sed -E "s/${re}/\\2/" <<<"${line}")" 57 dot="$(sed -E "s/${re}/\\3/" <<<"${line}")" 58 e="$(sed -E "s/${re}/\\4/" <<<"${line}")" 59 bits="$(sed -E "s/${re}/\\5,\\6,\\7,\\8/" <<<"${line}")" 60 [[ "${rc}" == 0 ]] && ok "probe returned 0" || bad "probe returned ${rc}" 61 [[ "${dot}" == `42880000` ]] && ok "f32 dot product = 68.0 exactly (0x42880000)" || bad "dot product bits 0x${dot}, expected 0x42880000" 62 [[ "${bits}" == `41300000`,`41b00000`,`42040000`,`42300000` ]] && ok "NEON vaddq_f32 lanes = 11,22,33,44" || bad "NEON lanes ${bits}" 63 # exp(1) within 1e-4 of e: e = 0x402df854; ulp near e is 2^-22, so 1e-4 is about 420 ulps. 64 local d=$(( 0x${e} - 0x402df854 )); (( d < 0 )) && d=$(( -d )) 65 if (( d <= 420 )); then ok "exp(1) bits 0x${e} within 1e-4 of e"; else bad "exp(1) bits 0x${e} too far from e"; fi 66 local cp="$(sed -E "s/${re}/\\1/" <<<"${line}")" 67 [[ $(( 0x${cp} >> 20 & 3 )) == 3 ]] && ok "CPACR_EL1.FPEN = 0b11 at EL1" || bad "CPACR_EL1.FPEN is not 0b11 (0x${cp})" 68 fi 69 grep -qx 'AIENOS_CK_FPU: PASS' "${f}" && ok "kernel reported AIENOS_CK_FPU: PASS" || bad "kernel did not report AIENOS_CK_FPU: PASS" 70 grep -q "kernel: alive" "${f}" && ok "kernel alive" || bad "kernel never reached kernel: alive" 71 if grep -qE 'report_kind: (panic|fault)' "${f}"; then bad "panic or fault report"; else ok "no panic or fault"; fi 72 } 73 74 if [[ "${1:-}" == --self-test ]]; then 75 tmp="$(mktemp -d)"; trap 'rm -rf "${tmp}"' EXIT 76 good() { printf 'kernel: alive\nfpu: el1_cpacr=0x300000 rc=0 dot_bits=0x42880000 exp1_bits=0x402df84e neon_bits=0x41300000,0x41b00000,0x42040000,0x42300000\nAIENOS_CK_FPU: PASS\nreport_kind: final\n'; } 77 st=0 78 chk() { fpu_failed=0; out="$(fpu_check_log "$3")"; grep -q '^FAIL' <<<"${out}" && fpu_failed=1 79 if [[ "$2" == pass && ${fpu_failed} == 0 ]] || [[ "$2" == fail && ${fpu_failed} == 1 ]]; then echo "PASS self-test $1"; else echo "FAIL self-test $1"; st=1; fi; } 80 good >"${tmp}/g"; chk good pass "${tmp}/g" 81 sed 's/dot_bits=0x42880000/dot_bits=0x42880001/' "${tmp}/g" >"${tmp}/a"; chk wrong-dot fail "${tmp}/a" 82 sed 's/exp1_bits=0x402df84e/exp1_bits=0x40300000/' "${tmp}/g" >"${tmp}/b"; chk wrong-exp fail "${tmp}/b" 83 sed 's/0x42040000,0x42300000/0x42040000,0x42300001/' "${tmp}/g" >"${tmp}/c"; chk wrong-neon fail "${tmp}/c" 84 sed 's/rc=0/rc=2/' "${tmp}/g" >"${tmp}/d"; chk rc-nonzero fail "${tmp}/d" 85 sed 's/el1_cpacr=0x300000/el1_cpacr=0x100000/' "${tmp}/g" >"${tmp}/e"; chk fpen-not-3 fail "${tmp}/e" 86 grep -v '^AIENOS_CK_FPU' "${tmp}/g" >"${tmp}/f"; chk no-kernel-verdict fail "${tmp}/f" 87 grep -v '^fpu:' "${tmp}/g" >"${tmp}/h"; chk no-result-line fail "${tmp}/h" 88 { cat "${tmp}/g"; echo "report_kind: fault"; } >"${tmp}/i"; chk fault fail "${tmp}/i" 89 [[ ${st} == 0 ]] && { echo "AIENOS_CK_FPU_SELF_TEST: PASS"; exit 0; } 90 echo "AIENOS_CK_FPU_SELF_TEST: FAIL"; exit 1 91 fi 92 93 notrun() { echo "NOT_RUN $*"; echo "${verdict_name}: NOT_RUN ($*)"; exit 2; } 94 command -v qemu-system-aarch64 >/dev/null || notrun "qemu-system-aarch64 not installed" 95 code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" 96 vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" 97 [[ -r "${code_fd}" && -r "${vars_fd}" ]] || notrun "AAVMF firmware not found" 98 command -v cargo >/dev/null || notrun "cargo not installed" 99 if ! rustc --print target-list 2>/dev/null | grep -qx aarch64-unknown-none \ 100 || ! [[ -d "$(rustc --print sysroot)/lib/rustlib/aarch64-unknown-none/lib" ]]; then 101 notrun "Rust target aarch64-unknown-none not installed (rustup target add aarch64-unknown-none)" 102 fi 103 104 cross="" 105 if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi 106 commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" 107 out="${repo_root}/target/native-kernel-fpu" 108 lib="${repo_root}/target/fpu-probe/aarch64-unknown-none/release/libaienos_fpu_probe.a" 109 CARGO_TARGET_DIR="${repo_root}/target/fpu-probe" cargo build -q --release --target aarch64-unknown-none \ 110 --manifest-path crates/aienos-fpu-probe/Cargo.toml 111 make -s -C native/kernel CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" CK_RUST_LIBS="${lib}" >/dev/null 112 113 # Machine-wide quiet flag: read only, never written here (Drake's rule: no 114 # agent raises it without approval). If someone holds it: NOT_RUN. 115 # Machine quiet flag (read only) and the QEMU gate lock (one gate at a time): 116 # scripts/lib_gate_hold.sh (aienos#278). 117 . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib_gate_hold.sh" 118 if ! gh_quiet_check; then 119 echo "NOT_RUN ${gh_why}" 120 echo "${verdict_name}: NOT_RUN" 121 exit 3 122 fi 123 if ! gh_lock_take qemu_ck_fpu_test "${AIENOS_GATE_MINUTES:-60}"; then 124 echo "NOT_RUN ${gh_why}" 125 echo "${verdict_name}: NOT_RUN" 126 exit 3 127 fi 128 # Release only this run's own gate lock record, at most once. 129 release_lock() { gh_lock_release; } 130 work="$(mktemp -d)" 131 cleanup() { rm -rf "${work}"; release_lock; } 132 trap cleanup EXIT 133 mkdir -p "${work}/esp/EFI/BOOT" "${work}/esp/EFI/AIENOS" 134 touch "${work}/esp/EFI/AIENOS/BOOTREPORT.TXT" 135 cp "${out}/BOOTAA64.EFI" "${work}/esp/EFI/BOOT/BOOTAA64.EFI" 136 cp "${vars_fd}" "${work}/vars.fd" 137 log="${work}/serial.log" 138 139 started=$(date +%s) 140 set +e 141 timeout "${AIENOS_QEMU_TIMEOUT:-180}" qemu-system-aarch64 \ 142 -M virt,virtualization=on,gic-version=3 -accel tcg,thread=single -cpu max -smp 2 -m 2048 \ 143 -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ 144 -drive if=pflash,format=raw,file="${work}/vars.fd" \ 145 -drive if=none,id=esp,format=raw,file=fat:rw:"${work}/esp" \ 146 -device virtio-blk-pci,drive=esp \ 147 -device ramfb -display none -nic none \ 148 -serial file:"${log}" -no-reboot 149 qemu_status=$? 150 set -e 151 elapsed=$(( $(date +%s) - started )) 152 release_lock 153 154 tr -d '\r' <"${log}" >"${work}/serial.txt" 155 [[ -z "${AIENOS_LOG_DIR:-}" ]] || cp "${work}/serial.txt" "${AIENOS_LOG_DIR}/qemu_ck_fpu_serial.log" 156 echo "qemu exit ${qemu_status} after ${elapsed} s (commit ${commit:0:12})" 157 158 fpu_failed=0 159 results="$(fpu_check_log "${work}/serial.txt")" || true 160 grep -q '^FAIL' <<<"${results}" && fpu_failed=1 161 printf '%s\n' "${results}" 162 if [[ "${qemu_status}" == 0 ]]; then echo "PASS QEMU exit 0 (PSCI reset)"; else echo "FAIL QEMU exit ${qemu_status}"; fpu_failed=1; fi 163 grep -E '^fpu: ' "${work}/serial.txt" || true 164 if [[ "${fpu_failed}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then 165 echo "---- serial console ----"; cat "${work}/serial.txt" 166 fi 167 if [[ "${fpu_failed}" == 0 ]]; then echo "AIENOS_CK_FPU: PASS"; exit 0; fi 168 echo "AIENOS_CK_FPU: FAIL"; exit 1