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/ck_courier_udp_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 / ck_courier_udp_test.sh` 97 lines ยท 4641 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # ck_courier_udp_test.sh -- host test of Allen's Ethernet courier. 3 # 4 # The kernel's own courier code (native/kernel/x86/courier_udp_x86.c, built with 5 # -DCK_COURIER_HOST) talks UDP to the real relay (crates/allen-courier --udp), 6 # which asks a model server. Five runs: a clean wire; wires that lose about 1 frame 7 # in 3 and 1 in 2 each way; a model server that answers "busy" (503) twice before 8 # it answers; and one that sits silent for 4 s before it starts (the relay must 9 # keep sending WAIT meanwhile). The model here is a small stand-in so the run is 10 # exact and quick. With ALLEN_MODEL=host:port (the real server) a last run 11 # sends the same job to the real model. The real kernel cannot run this in QEMU 12 # (QEMU has no Broadcom chip), so this is the check of the courier's protocol. 13 # Ends with "AIENOS_COURIER_UDP: PASS" or "AIENOS_COURIER_UDP: FAIL ". 14 set -u 15 cd "$(dirname "$0")/.." 16 K=native/kernel 17 tag=AIENOS_COURIER_UDP 18 fail() { echo "${tag}: FAIL $*"; exit 1; } 19 W=$(mktemp -d "${TMPDIR:-/tmp}/ck_courier_udp.XXXXXX") 20 pids=() 21 cleanup() { 22 for p in ${pids[@]+"${pids[@]}"}; do kill "$p" 2>/dev/null || true; done 23 [ -n "${KEEP_LOGS:-}" ] && cp -r "$W" "${KEEP_LOGS}" 2>/dev/null 24 rm -rf "$W" 25 } 26 trap cleanup EXIT 27 28 ${HOSTCC:-cc} -std=c11 -D_DEFAULT_SOURCE -O2 -Wall -Wextra -Werror -DCK_COURIER_HOST -I$K/x86 -Inative/net \ 29 -o "$W/test" $K/x86/tests/courier_udp_test.c $K/x86/courier_udp_x86.c native/net/aienos_net.c || 30 fail "the test does not build" 31 if [ -n "${ALLEN_RELAY:-}" ]; then 32 relay="$ALLEN_RELAY" # a relay built elsewhere 33 else 34 cargo build -q --release --offline -p allen-courier 2>"$W/cargo.err" || { tail -5 "$W/cargo.err"; fail "the relay does not build"; } 35 relay="${CARGO_TARGET_DIR:-target}/release/allen-courier" 36 fi 37 38 rustc --edition=2021 -D warnings -O -o "$W/model-fixture" "$K/x86/tests/courier_model_fixture.rs" || 39 fail "the model fixture does not build" 40 free_port() { "$W/model-fixture" --free-udp-port; } 41 42 # The fixture binds loopback before publishing its port. Its readiness wait 43 # is bounded and also notices an early failure, instead of guessing a delay. 44 start_model() { # port-file busy-count delay-seconds 45 "$W/model-fixture" "$1" "$2" "$3" >"$1.log" 2>&1 & 46 model_pid=$! 47 pids+=("$model_pid") 48 for _ in {1..100}; do 49 [[ -s "$1" ]] && return 0 50 kill -0 "$model_pid" 2>/dev/null || fail "model fixture exited before binding" 51 sleep 0.05 52 done 53 fail "model fixture did not publish its port" 54 } 55 56 printf 'JOB 1 chat Answer as Allen.\thello allen, how was your day\tself=Allen\tname=Drake\tstarts=20\tnote asked: hi / said: Hello\n' >"$W/job.txt" 57 58 run() { # label model drop_every 59 local label="$1" model="$2" drop="$3" rp 60 rp=$(free_port) 61 "$relay" --udp "$rp" --model "$model" --work "$W/work" --log-dir "$W/log-$label" --busy-wait "${ALLEN_WAIT:-90}" >"$W/relay-$label.log" 2>&1 & 62 rpid=$! 63 pids+=("$rpid") 64 sleep 0.5 65 "$W/test" "$rp" "$drop" "$W/job.txt" "${ALLEN_WAIT:-90}" | tee "$W/test-$label.log" | grep -a -E "hello after|first part|PASS|FAIL" | sed "s/^/[$label] /" 66 grep -aq "COURIER_UDP: PASS" "$W/test-$label.log" || fail "run $label" 67 sleep 0.4 # the relay writes its log line a moment after the last part 68 kill "$rpid" 2>/dev/null || true 69 wait "$rpid" 2>/dev/null 70 } 71 72 start_model "$W/clean.port" 0 0 73 mp=$(cat "$W/clean.port") 74 fake1=$model_pid 75 run clean "127.0.0.1:$mp" 0 76 run lossy "127.0.0.1:$mp" 3 77 run lossy2 "127.0.0.1:$mp" 2 78 grep -aq "job resends [1-9]" "$W/test-lossy2.log" || fail "the lost job was not sent again" 79 kill "$fake1" 2>/dev/null || true 80 wait "$fake1" 2>/dev/null 81 start_model "$W/busy.port" 2 0 82 mp2=$(cat "$W/busy.port") 83 run busy "127.0.0.1:$mp2" 0 84 grep -aqE "waits 2|waits [2-9]" "$W/relay-busy.log" || fail "the relay did not wait out the busy answers" 85 echo "[busy] relay waited out the busy answers: $(grep -a 'waits' "$W/relay-busy.log" | head -1 | sed 's/.*first in/first in/')" 86 start_model "$W/slow.port" 0 4 87 mp3=$(cat "$W/slow.port") 88 run slow "127.0.0.1:$mp3" 0 89 grep -aqE "[1-9][0-9]* waits" "$W/test-slow.log" || fail "the relay kept no word going while the model sat on the request" 90 echo "[slow] the relay sent WAIT while the model sat silent: $(grep -aoE '[0-9]+ waits' "$W/test-slow.log" | head -1)" 91 [ -s "$W"/log-clean/*.jsonl ] || fail "no line in the learning log" 92 grep -aq '"ask":"hello allen, how was your day"' "$W"/log-clean/*.jsonl || fail "the learning log lacks the question" 93 echo "learning log line: $(head -c 300 "$W"/log-clean/*.jsonl)" 94 if [ -n "${ALLEN_MODEL:-}" ]; then 95 run real "$ALLEN_MODEL" 0 96 fi 97 echo "${tag}: PASS"