-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
mp_test_executor.sh
executable file
·72 lines (60 loc) · 1.94 KB
/
mp_test_executor.sh
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
set -e #Error if any line errors
set -m #Enable job control
set -v #Print shell commands as they are read
TIMEOUT_TIME=300
LOOP_TIME=6
HOSTLOG=/tmp/host.log
JOINLOG=/tmp/join.log
./wesnothd --port 12345 --log-debug=server --log-warning=config &
serverpid=$!
./wesnoth --plugin=host.lua --server=localhost:12345 --username=host --mp-test --noaddons --nogui 2> >(tee $HOSTLOG >&2) &
hostpid=$!
./wesnoth --plugin=join.lua --server=localhost:12345 --username=join --mp-test --noaddons --nogui 2> >(tee $JOINLOG >&2) &
joinpid=$!
START_TIME=$SECONDS
HOST_RUNNING=yes
JOIN_RUNNING=yes
while true; do
# Timeout
EXEC_TIME=$(($SECONDS - $START_TIME))
if [ $EXEC_TIME -gt $TIMEOUT_TIME ]; then
kill $hostpid 2>/dev/null
kill $joinpid 2>/dev/null
break
fi
# Check if clients still running
if ! kill -0 $hostpid 2>/dev/null; then
HOST_RUNNING=no
fi
if ! kill -0 $joinpid 2>/dev/null; then
JOIN_RUNNING=no
fi
sleep $LOOP_TIME
# If both are finished, we're done
if ! (kill -0 $hostpid 2>/dev/null || kill -0 $joinpid 2>/dev/null); then
break
fi
# If one has finished previously, kill the other
if [ $HOST_RUNNING = "no" ]; then
echo "Host finished at least $LOOP_TIME seconds ago. Killing join"
kill $joinpid 2>/dev/null
break
fi
if [ $JOIN_RUNNING = "no" ]; then
echo "Join finished at least $LOOP_TIME seconds ago. Killing host"
kill $hostpid 2>/dev/null
break
fi
done
STATUS=0
wait $hostpid || (
grep "Could not initialize SDL_video" $HOSTLOG && \
echo -e "\nFailed to initialize video.\nThis is a common CI issue.\nTreating the test as successful.\n"
) || STATUS=1
wait $joinpid || (
grep "Could not initialize SDL_video" $JOINLOG && \
echo -e "\nFailed to initialize video.\nThis is a common CI issue.\nTreating the test as successful.\n"
) || STATUS=1
kill $serverpid
exit $STATUS