#!/bin/sh # Bring the local API stand-in up, run the driver against it, tear it down. # Exits non-zero when anything fails. $1 is the driver, the rest is a prefix # to run it under (valgrind, gdb, ...). set -eu here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) driver=$1 shift fifo=$(mktemp -u) mkfifo "$fifo" python3 "$here/server.py" 0 >"$fifo" & server=$! cleanup() { kill "$server" 2>/dev/null || true wait "$server" 2>/dev/null || true rm -f "$fifo" } trap cleanup EXIT INT TERM port=$(head -n 1 "$fifo") if [ -z "$port" ]; then echo "server did not start" >&2 exit 1 fi echo "server on 127.0.0.1:$port" "$@" "$driver" "http://127.0.0.1:$port"