blob: 6883391638012a332c5564059321c2bfa246efa1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#!/usr/bin/env bash
# lib9p/tests/runtest - Test harness for the 9P `test_server`
#
# Copyright (C) 2025 Luke T. Shumaker <lukeshu@lukeshu.com>
# SPDX-License-Identifier: AGPL-3.0-or-later
set -euE -o pipefail
build_aux=$(realpath --canonicalize-missing -- "${BASH_SOURCE[0]}/../../../build-aux")
if [[ $# != 2 ]]; then
echo >&2 "Usage: $0 CLIENTSCRIPT EXPLOG"
exit 2
fi
clientscript="$1"
explog="$2"
cleanup=()
cleanup() {
{ set +x; } &>/dev/null
local i
for ((i = ${#cleanup[@]} - 1; i >= 0; i--)); do
eval "set -x; ${cleanup[$i]}"
{ set +x; } &>/dev/null
done
}
trap cleanup EXIT
logfile=$(mktemp -t lib9p-log.XXXXXXXXXX)
cleanup+=("rm -f -- ${logfile@Q}")
port=$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()')
set -x
"${build_aux}/valgrind" ./tests/test_server/test_server "$port" "$logfile" &
server_pid=$!
cleanup+=("kill $server_pid || true; wait $server_pid || true")
while [[ -d /proc/$server_pid ]] && ! (readlink /proc/$server_pid/fd/* 2>/dev/null | grep -q ^socket:); do sleep 0.1; done
if [[ "$(head -c2 -- "$clientscript")" == '#!' ]]; then
"$clientscript" "$port"
else
"${build_aux}/valgrind" "$clientscript" "$port"
fi
wait "$server_pid"
cleanup=("${cleanup[@]::1}")
diff -u -- <(grep -e '^[<>]' -- "$explog") "$logfile"
|