#!/usr/bin/env bash # Phase 6 local platform gate: fixed-buffer recv + SEND_ZC echo integrity. set -euo pipefail ROOT="$(cd "$(dirname "$0")/../.." && pwd)" ECHO="${1:-$ROOT/build/naut_echo}" PORT="${NAUT_ECHO_PORT:-39127}" LOG="$(mktemp /tmp/naut_echo_scale.XXXXXX)" cleanup() { [ -n "${server:-}" ] && kill -TERM "$server" 2>/dev/null || true [ -n "${server:-}" ] && wait "$server" 2>/dev/null || true rm -f "$LOG" } trap cleanup EXIT NAUT_SQPOLL=1 "$ECHO" "$PORT" >"$LOG" 2>&1 & server=$! for _ in $(seq 1 100); do grep -q "echo listening" "$LOG" && break kill -0 "$server" 2>/dev/null || { echo "FAIL: echo server exited"; cat "$LOG"; exit 1; } sleep 0.05 done grep -q "echo listening" "$LOG" || { echo "FAIL: echo server did not listen"; cat "$LOG"; exit 1; } BYTES=$((256 * 1024 * 1024)) CONNS=8 python3 "$ROOT/tests/integration/echo_client.py" "$PORT" "$BYTES" "$CONNS" kill -TERM "$server" wait "$server" server="" grep -q "bytes echoed" "$LOG" || { echo "FAIL: echo server did not shut down cleanly"; cat "$LOG"; exit 1; } grep "bytes echoed" "$LOG" # Server-side accounting must match exactly: every byte the client sent was # echoed back, and no connection was dropped mid-stream. (A truncated echo is # also caught client-side, but asserting the count here makes a server-side # drop a hard, deterministic failure rather than a timing-dependent one.) echoed=$(grep -oE '[0-9]+ bytes echoed' "$LOG" | grep -oE '^[0-9]+') if [ "$echoed" != "$BYTES" ]; then echo "FAIL: echoed $echoed bytes, expected $BYTES (a connection was dropped)" cat "$LOG"; exit 1 fi conns=$(grep -oE '[0-9]+ conns' "$LOG" | grep -oE '^[0-9]+') if [ "$conns" != "$CONNS" ]; then echo "FAIL: served $conns connections, expected $CONNS"; cat "$LOG"; exit 1 fi # Report whether the SQPOLL path was actually exercised (it falls back cleanly # where the kernel/privileges disallow it — informational, not a failure). if grep -q "sqpoll" "$LOG"; then echo "PASS: io_uring SQPOLL fixed-buffer/SEND_ZC echo path is byte-correct" else echo "PASS: io_uring echo path byte-correct (SQPOLL unavailable, used fallback)" fi