Files
settled-reach/tests/run-ipc-benchmark
T
jpmschweitzerandClaude Opus 4.6 4f21465dbf feat(ci): test runner scripts and Makefile integration (#270)
Six test runner scripts at tests/: run-rust, run-godot, run-ipc-fixtures,
run-ipc-protocol, run-ipc-integration, run-all. Plus run-ipc-benchmark
for Layer 3 timing. All produce structured JSON stdout, support --filter,
and exit 0/non-zero. Makefile targets updated to delegate to scripts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 12:47:58 +01:00

60 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# tests/run-ipc-benchmark: IPC round-trip latency benchmark (#342, D-020)
#
# Runs server/tests/ipc_bench.rs via `cargo test --release --test ipc_bench`.
# Parses IPC_BENCH_RESULT:{json} from output and outputs the result JSON.
#
# Latency budget: p99 <= 5ms (D-020: "~1-5ms serialization latency per tick").
#
# NOTE (#342): Handshake step is stubbed in ipc_bench.rs pending #555 (server
# protocol handshake) and #556 (client handshake). Full clean timing requires
# a working handshake before the measurement loop starts.
#
# Exit: 0 = benchmark passed (p99 within threshold), non-zero = failure
# Stdout: {"p50_ms":N,"p95_ms":N,"p99_ms":N,"threshold_ms":5,"passed":true,"rounds":100}
set -euo pipefail
ITERATIONS=100
THRESHOLD_MS=5
while [[ $# -gt 0 ]]; do
case "$1" in
--iterations) ITERATIONS="${2:-100}"; shift 2 ;;
--iterations=*) ITERATIONS="${1#--iterations=}"; shift ;;
--threshold-ms) THRESHOLD_MS="${2:-5}"; shift 2 ;;
--filter) shift 2 ;; # ignored — benchmark has no test filter
--filter=*) shift ;;
*) echo "Unknown argument: $1" >&2; exit 2 ;;
esac
done
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
START_MS=$(date +%s%3N)
TMPOUT=$(mktemp)
set +e
cd "$REPO_ROOT/server" && \
cargo test --release --test ipc_bench -- --ignored --nocapture 2>&1 | tee "$TMPOUT" >&2
EXIT_CODE=${PIPESTATUS[0]}
set -e
END_MS=$(date +%s%3N)
DURATION_MS=$((END_MS - START_MS))
# Extract IPC_BENCH_RESULT:{json} line from output
RESULT_LINE=$(grep "^IPC_BENCH_RESULT:" "$TMPOUT" | tail -1 || true)
rm -f "$TMPOUT"
if [[ -n "$RESULT_LINE" ]]; then
# Strip the prefix and output the JSON
echo "${RESULT_LINE#IPC_BENCH_RESULT:}"
else
# No result line — test failed to produce output
printf '{"p50_ms":0,"p95_ms":0,"p99_ms":0,"threshold_ms":%d,"passed":false,"error":"no benchmark output — server binary may not be built (run make build-server)"}\n' \
"$THRESHOLD_MS"
EXIT_CODE=1
fi
exit $EXIT_CODE