teeworlds_network/integration_test/run.sh

137 lines
2.7 KiB
Bash
Raw Normal View History

2022-11-05 17:41:06 +00:00
#!/bin/bash
cd "$(dirname "$0")" || exit 1
2022-11-12 15:47:12 +00:00
tw_srv_bin=teeworlds_srv
tw_cl_bin=teeworlds
2022-11-06 17:26:14 +00:00
srvcfg='sv_rcon_password rcon;sv_port 8377;killme'
2022-11-05 17:41:06 +00:00
if [[ -x "$(command -v teeworlds_srv)" ]]
then
2022-11-06 17:26:14 +00:00
teeworlds_srv "$srvcfg" &> server.txt &
2022-11-05 17:41:06 +00:00
elif [[ -x "$(command -v teeworlds-server)" ]]
then
2022-11-06 17:26:14 +00:00
teeworlds-server "$srvcfg" &> server.txt &
2022-11-12 15:47:12 +00:00
tw_srv_bin='teeworlds-server'
2022-11-05 17:41:06 +00:00
elif [[ -x "$(command -v teeworlds-srv)" ]]
then
2022-11-06 17:26:14 +00:00
teeworlds-srv "$srvcfg" &> server.txt &
2022-11-12 15:47:12 +00:00
tw_srv_bin='teeworlds-srv'
2022-11-05 17:41:06 +00:00
else
echo "Error: please install a teeworlds_srv"
exit 1
fi
2022-11-12 15:47:12 +00:00
if [[ ! -x "$(command -v "$tw_cl_bin")" ]]
2022-11-06 17:26:14 +00:00
then
2022-11-12 15:47:12 +00:00
echo "Error: please install a teeworlds"
exit 1
fi
function get_test_names() {
(find client -name "*.rb";find server -name "*.rb") | tr '\n' ' '
}
function invalid_test() {
local name="$1"
echo "Error: invalid test name '$name'"
echo " valid tests: $(get_test_names)"
exit 1
}
testname="${1:-client/chat.rb}"
if ! [[ "$testname" =~ (client|server)/.*\.rb$ ]]
2022-11-06 17:26:14 +00:00
then
2022-11-12 15:47:12 +00:00
invalid_test "$testname"
fi
if [ ! -f "$testname" ]
2022-11-06 17:26:14 +00:00
then
2022-11-12 15:47:12 +00:00
testname=${testname##*integration_test/}
if [ ! -f "$testname" ]
then
invalid_test "$testname"
fi
2022-11-06 17:26:14 +00:00
fi
2022-11-12 15:47:12 +00:00
echo "[*] running test '$testname' ..."
echo "client log $(date)" > client.txt
echo "server log $(date)" > server.txt
[[ -f timeout.txt ]] && rm timeout.txt
function cleanup() {
echo "[*] shutting down server ..."
pkill -f "$tw_srv_bin $srvcfg"
[[ "$_timout_pid" != "" ]] && kill "$_timout_pid" &> /dev/null
}
trap cleanup EXIT
2022-11-06 17:26:14 +00:00
2022-11-05 17:41:06 +00:00
function fail() {
local msg="$1"
2022-11-12 15:47:12 +00:00
# the first tail get swalloed
# idk why so tail twice to ensure
# getting output
# this is a bit ugly but it works
# maybe a sleep does as well
# or I still did not get flushing
tail client.txt &>/dev/null
echo "[-] end of client log:"
2022-11-05 17:41:06 +00:00
tail client.txt
2022-11-12 15:47:12 +00:00
echo "[-] end of server log:"
2022-11-05 17:41:06 +00:00
tail server.txt
echo "$msg"
exit 1
}
2022-11-12 15:47:12 +00:00
function timeout() {
local seconds="$1"
sleep "$seconds"
echo "[-] Timeout -> killing: $testname"
touch timeout.txt
pkill -f "$testname killme"
fail "[-] Timeout"
}
timeout 3 killme &
_timout_pid=$!
if [ "$testname" == "client/chat.rb" ]
2022-11-05 17:41:06 +00:00
then
2022-11-12 15:47:12 +00:00
ruby "$testname" killme &> client.txt
2022-11-05 17:41:06 +00:00
if ! grep -q 'hello world' server.txt
then
fail "Error: did not find chat message in server log"
fi
2022-11-12 15:47:12 +00:00
elif [ "$testname" == "client/reconnect.rb" ]
2022-11-05 17:41:06 +00:00
then
2022-11-12 15:47:12 +00:00
ruby "$testname" killme &> client.txt
2022-11-05 17:41:06 +00:00
if ! grep -q 'bar' server.txt
then
fail "Error: did not find 2nd chat message in server log"
fi
2022-11-12 15:47:12 +00:00
elif [ "$testname" == "client/rcon.rb" ]
2022-11-06 17:26:14 +00:00
then
2022-11-12 15:47:12 +00:00
ruby "$testname" killme &> client.txt
2022-11-06 17:26:14 +00:00
2022-11-12 15:47:12 +00:00
sleep 0.1
if pgrep -f "$tw_srv_bin $srvcfg"
2022-11-06 17:26:14 +00:00
then
fail "Error: server still running rcon shutdown failed"
fi
2022-11-05 17:41:06 +00:00
else
echo "Error: unkown test '$testname'"
exit 1
fi
2022-11-12 15:47:12 +00:00
if [ -f timeout.txt ]
then
echo "[-] Error timouted"
exit 1
fi
2022-11-06 17:26:14 +00:00
echo "[+] Test passed"
2022-11-05 17:41:06 +00:00