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 / scripts / qemu_ck_pipe_test.sh

108 lines · 6579 bytes Raw Blame History
1#!/usr/bin/env bash
2# AIENOS_CK_PIPE gate (AIENOS-NATIVE-PIPE-1, aienos-mv#428): the native pipe primitive (native/kernel/core/pipe.c) driven
3# from inside the C kernel. A TEST-ONLY image (make CK_PIPE_TEST=1, refused with CK_HARDWARE_STAGING) runs
4# core/pipe_test.c after "kernel: alive": a producer and a consumer task, step functions interleaved by the kernel's
5# run-queue scheduler, each holding one pipe end in its own capability table, then the negative cases. The boot then
6# goes on as usual to its report and PSCI reset.
7#
8# Label: QEMU (aarch64 virt), TEST build, not physical. Nothing here ran on a Spark or any real machine; a PASS
9# qualifies nothing physical.
10# Checks (one boot):
11# payload_nul_byte_for_byte 160 KiB with every fifth byte NUL arrives byte for byte, no temporary file
12# backpressure_would_block a slow consumer fills the 64 KiB pipe; the producer sees WOULD_BLOCK
13# eof_after_last_writer the consumer reads EOF (0 bytes, OK) after the producer closes
14# bounded_memory never more than the pipe capacity buffered
15# blocking_wait_wake_through_scheduler the blocking variant parks and is woken through the scheduler
16# broken_pipe_no_reader write with no reader -> BROKEN_PIPE, no bytes
17# revoked_write_refused_no_bytes_after write after revoke -> REVOKED, nothing delivered after it
18# revoke_midstream_no_data_after the consumer revokes mid-transfer; no read succeeds afterwards
19# stale_handle_after_close a closed handle stays STALE after its slot is reused
20# unknown_op_not_supported unknown op / other ABI version -> NOT_SUPPORTED before any effect
21# cancel_interrupts_once cancel -> INTERRUPTED once with no byte moved
22# every check: both capability tables and the pipe pool empty afterwards (tables_empty=1).
23# Last line: AIENOS_CK_PIPE: PASS|FAIL|NOT_RUN.
24set -euo pipefail
25
26repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
27cd "${repo_root}"
28verdict=AIENOS_CK_PIPE
29code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}"
30vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}"
31command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; echo "${verdict}: NOT_RUN"; exit 2; }
32[[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "AAVMF firmware not found"; echo "${verdict}: NOT_RUN"; exit 2; }
33
34cross=""
35if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi
36commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)"
37out="${AIENOS_CK_OUT_PIPE:-${repo_root}/target/native-kernel-test-pipe}"
38make -s -C native/kernel CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" CK_PIPE_TEST=1 >/dev/null
39
40# Machine quiet flag (read only) and the QEMU gate lock (one gate at a time):
41# scripts/lib_gate_hold.sh (aienos#278).
42. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib_gate_hold.sh"
43if ! gh_quiet_check || ! gh_lock_take qemu_ck_pipe_test "${AIENOS_GATE_MINUTES:-60}"; then
44 echo "NOT_RUN ${gh_why}"
45 echo "${verdict}: NOT_RUN"
46 exit 3
47fi
48# Release only this run's own gate lock record, at most once.
49release_flag() { gh_lock_release; }
50work="$(mktemp -d)"
51cleanup() { rm -rf "${work}"; release_flag; }
52trap cleanup EXIT
53mkdir -p "${work}/esp/EFI/BOOT" "${work}/esp/EFI/AIENOS"
54touch "${work}/esp/EFI/AIENOS/BOOTREPORT.TXT"
55cp "${out}/BOOTAA64.EFI" "${work}/esp/EFI/BOOT/BOOTAA64.EFI"
56cp "${vars_fd}" "${work}/vars.fd"
57log="${work}/serial.log"
58
59started=$(date +%s)
60set +e
61timeout "${AIENOS_QEMU_TIMEOUT:-300}" qemu-system-aarch64 \
62 -M virt,virtualization=on,gic-version=3 -accel tcg,thread=single -cpu max -smp 4 -m 2048 \
63 -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \
64 -drive if=pflash,format=raw,file="${work}/vars.fd" \
65 -drive if=none,id=esp,format=raw,file=fat:rw:"${work}/esp" \
66 -device virtio-blk-pci,drive=esp \
67 -device ramfb -display none -nic none \
68 -serial file:"${log}" -no-reboot
69qemu_status=$?
70set -e
71elapsed=$(( $(date +%s) - started ))
72release_flag
73
74serial="${work}/serial.txt"
75tr -d '\r' <"${log}" >"${serial}"
76[[ -z "${AIENOS_LOG_DIR:-}" ]] || cp "${serial}" "${AIENOS_LOG_DIR}/qemu_ck_pipe_serial.log"
77failed=0
78pass() { echo "PASS $1"; }
79fail() { echo "FAIL $1"; failed=1; }
80has() { grep -qE -- "$2" "$1"; }
81check() { if has "${serial}" "$2"; then pass "$1"; else fail "$1"; fi; }
82echo "qemu exit ${qemu_status} after ${elapsed} s (commit ${commit:0:12})"
83[[ "${qemu_status}" == 0 ]] && pass "QEMU exit status 0 (PSCI reset)" || fail "QEMU exit status ${qemu_status} (124 = timeout)"
84
85label='QEMU \(aarch64 virt\), TEST build, not physical'
86check "left firmware and entered the kernel" "kernel: alive"
87check "the image announces the TEST-ONLY pipe self-test" "^pipe_test: TEST-ONLY pipe self-test begin abi_version=1 capacity=65536 pool_pipes=4 payload=163840; ${label}\$"
88for c in payload_nul_byte_for_byte backpressure_would_block eof_after_last_writer bounded_memory \
89 blocking_wait_wake_through_scheduler broken_pipe_no_reader revoked_write_refused_no_bytes_after \
90 revoke_midstream_no_data_after stale_handle_after_close unknown_op_not_supported cancel_interrupts_once; do
91 check "${c}" "^pipe_check: name=${c} result=PASS tables_empty=1; ${label}\$"
92done
93check "payload detail: all 163840 bytes, NUL bytes counted, zero mismatches" "^pipe_detail: nonblocking bytes=163840 sent=163840 nul=[1-9][0-9]* expected_nul=[1-9][0-9]* mismatches=0 would_block=[1-9]"
94check "blocking detail: waits and wakeups observed" "^pipe_detail: blocking bytes=163840 .* waits=[1-9][0-9]* wakeups=[1-9]"
95check "revoked write refused, zero bytes delivered" "^pipe_detail: revoked write=REVOKED n=0 read=REVOKED n=0 bytes_delivered=0\$"
96check "broken pipe detail" "^pipe_detail: broken_pipe write_after_reader_close=BROKEN_PIPE n=0\$"
97check "self-test summary: 11 checks, 0 failed" "^pipe_test: done checks=11 failed=0 capacity=65536 pool_pipes=4; ${label}\$"
98if has "${serial}" "^pipe_check: .* result=FAIL"; then fail "no pipe check failed"; else pass "no pipe check failed"; fi
99check "the boot went on to its report" "report_kind: final"
100if has "${serial}" "report_kind: (panic|fault)"; then fail "panic or fault reported"; else pass "no kernel panic or fault report"; fi
101
102if [[ "${failed}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then
103 echo "---- serial console (pipe lines) ----"
104 grep -E "^(pipe_|kernel: alive|report_kind|panic)" "${serial}" || true
105fi
106[[ "${failed}" == 0 ]] && { echo "${verdict}: PASS"; exit 0; }
107echo "${verdict}: FAIL"
108exit 1