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 / ck_imac_report_test.sh
| 1 | #!/bin/sh |
| 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 | # ck_imac_report_test.sh -- test of the iMac kernel's LAB-ONLY network report. |
| 18 | # 1. Build check: the default image (make imac-kernel) links no report code |
| 19 | # and no frame transmit; the opt-in lab image (CK_X86_REPORT=1) has them. |
| 20 | # 2. Host checks of x86/report_x86.c: the allowlist filter (sentinel chat, |
| 21 | # key, token and memory lines, control bytes and over-long lines never |
| 22 | # reach the exported copy or a frame; allowed lines survive byte for |
| 23 | # byte) and the frames (Ethernet broadcast, IPv4, UDP with a checksum, |
| 24 | # "v=2 auth=none" part headers), and the late-diagnostics boundary: an |
| 25 | # allowlisted line written after 16 KiB of console survives, conversation |
| 26 | # lines around it do not, and a full console copy ends in a truncation note. |
| 27 | # 3. The receiver tools/ck_imac_report_listen.c rebuilds the report byte for |
| 28 | # byte from parts sent out of order and repeated (and a full 64-part report), labels it |
| 29 | # unauthenticated, and refuses every older header (the retired v=1 raw-console format and the old name). |
| 30 | # Hosted only; the BCM57766 itself cannot be emulated, and nothing here |
| 31 | # touches a real network interface (the round trip runs over 127.0.0.1). |
| 32 | # Ends with "AIENOS_IMAC_REPORT: PASS", "AIENOS_IMAC_REPORT: FAIL <why>" or |
| 33 | # "AIENOS_IMAC_REPORT: NOT_RUN <why>" (no x86_64 toolchain for step 1). |
| 34 | set -u |
| 35 | cd "$(dirname "$0")/.." |
| 36 | K=native/kernel |
| 37 | W=$(mktemp -d "${TMPDIR:-/tmp}/ck_imac_report.XXXXXX") |
| 38 | trap 'kill $LP 2>/dev/null; rm -rf "$W"' EXIT |
| 39 | LP= |
| 40 | fail() { echo "AIENOS_IMAC_REPORT: FAIL $*"; exit 1; } |
| 41 | CC=${HOSTCC:-cc} |
| 42 | CF="-std=gnu11 -O2 -Wall -Wextra -Werror" |
| 43 | |
| 44 | # 1. Build check, into a scratch output directory. |
| 45 | X="" |
| 46 | [ "$(uname -m)" = x86_64 ] || X="x86_64-linux-gnu-" |
| 47 | for t in "${X}gcc" "${X}ld" "${X}nm"; do |
| 48 | command -v "$t" >/dev/null || { echo "AIENOS_IMAC_REPORT: NOT_RUN ($t missing)"; exit 2; } |
| 49 | done |
| 50 | SYMS='ck_x86_report_(hold|frame|filter|parts|seal)|ck_x86_tg3_(send|drain)|net_udp_build' |
| 51 | make -s -C $K X86_CROSS="$X" OUT="$W/build" imac-kernel >"$W/build.log" 2>&1 || |
| 52 | fail "default imac-kernel build: $(tail -3 "$W/build.log")" |
| 53 | make -s -C $K X86_CROSS="$X" OUT="$W/build" CK_X86_REPORT=1 CK_TEST_SLOT_KEY=1 imac-kernel >>"$W/build.log" 2>&1 || |
| 54 | fail "lab imac-kernel build: $(tail -3 "$W/build.log")" |
| 55 | d=$("${X}nm" "$W/build/imackern/imackern.elf" | grep -E " ($SYMS)\$" || true) |
| 56 | [ -z "$d" ] || fail "default image has report symbols: $(echo $d)" |
| 57 | grep -aq "AIENOS-REPORT" "$W/build/IMACKERN.EFI" && fail "default image carries the report header" |
| 58 | l=$("${X}nm" "$W/build/imackern-lab/imackern.elf" | grep -cE " ($SYMS)\$" || true) |
| 59 | [ "$l" = 8 ] || fail "lab image has $l of 8 report symbols" |
| 60 | grep -aq "AIENOS-REPORT v=2 auth=none " "$W/build/IMACKERN-LAB.EFI" || fail "lab image lacks the v=2 auth=none header" |
| 61 | echo "build: default image report_symbols=0, lab image report_symbols=8" |
| 62 | |
| 63 | # 2. Host checks of the filter and frames. |
| 64 | $CC $CF -o "$W/listen" $K/tools/ck_imac_report_listen.c || fail "listener does not build" |
| 65 | $CC $CF -DCK_X86_REPORT_HOST -I$K/x86 -I$K/tests -Inative/net -o "$W/test" \ |
| 66 | $K/tests/test_imac_report.c $K/x86/report_x86.c native/net/aienos_net.c || fail "test does not build" |
| 67 | "$W/test" || fail "filter and frame checks" |
| 68 | |
| 69 | # 3. Listener round trip over loopback. |
| 70 | PORT=$((47100 + $$ % 800)) |
| 71 | mkdir -p "$W/out" |
| 72 | "$W/listen" $PORT "$W/out" 20 2>/dev/null & |
| 73 | LP=$! |
| 74 | i=0 |
| 75 | until grep -q "^ready port=$PORT" "$W/out/listen.log" 2>/dev/null; do |
| 76 | i=$((i + 1)); [ $i -gt 50 ] && fail "listener not ready: $(cat "$W/out/listen.log" 2>/dev/null)" |
| 77 | sleep 0.1 |
| 78 | done |
| 79 | grep -q '^note: iMac reports are UNAUTHENTICATED UDP broadcasts (auth=none)' "$W/out/listen.log" || |
| 80 | fail "listener does not label reports unauthenticated" |
| 81 | "$W/test" legacy $PORT >/dev/null || fail "legacy send" |
| 82 | "$W/test" send $PORT "$W/sent.txt" >/dev/null || fail "send" |
| 83 | "$W/test" sendfull $PORT "$W/sentfull.txt" >/dev/null || fail "send of the full 64-part report" |
| 84 | i=0 |
| 85 | until grep -q "^complete run=0123456789abcdef auth=none " "$W/out/listen.log"; do |
| 86 | i=$((i + 1)); [ $i -gt 50 ] && fail "report not completed: $(cat "$W/out/listen.log")" |
| 87 | sleep 0.1 |
| 88 | done |
| 89 | cmp -s "$W/sent.txt" "$W/out/imac-0123456789abcdef.unauthenticated.txt" || fail "rebuilt report differs" |
| 90 | i=0 |
| 91 | until grep -q "^complete run=0000000000000009 auth=none " "$W/out/listen.log"; do |
| 92 | i=$((i + 1)); [ $i -gt 50 ] && fail "full 64-part report not completed: $(tail -3 "$W/out/listen.log")" |
| 93 | sleep 0.1 |
| 94 | done |
| 95 | cmp -s "$W/sentfull.txt" "$W/out/imac-0000000000000009.unauthenticated.txt" || fail "rebuilt full report differs" |
| 96 | tail -1 "$W/sentfull.txt" | grep -q '^report: console_copy_full dropped_bytes=[0-9]*$' || fail "full report lacks the truncation note" |
| 97 | [ "$(grep -c '^complete ' "$W/out/listen.log")" = 2 ] || fail "report written more than once" |
| 98 | [ "$(grep -c '^ignored .*retired older report header$' "$W/out/listen.log")" = 1 ] || |
| 99 | fail "listener did not refuse the v=1 datagram" |
| 100 | ls "$W/out" | grep -q '00000000000000ff' && fail "listener wrote the v=1 datagram" |
| 101 | grep '^ignored' "$W/out/listen.log" | grep -vq 'retired older' && fail "listener ignored a valid part" |
| 102 | echo "AIENOS_IMAC_REPORT: PASS" |