2022-04-18 17:28:37 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
arg_verbose=0
|
2022-05-26 12:28:55 +00:00
|
|
|
arg_valgrind_memcheck=0
|
2022-04-18 17:28:37 +00:00
|
|
|
|
|
|
|
for arg in "$@"
|
|
|
|
do
|
2022-06-17 21:03:03 +00:00
|
|
|
if [ "$arg" == "-h" ] || [ "$arg" == "--help" ]
|
2022-04-18 17:28:37 +00:00
|
|
|
then
|
2022-06-17 21:03:03 +00:00
|
|
|
echo "usage: $(basename "$0") [OPTION..] [build dir]"
|
|
|
|
echo "description:"
|
|
|
|
echo " Runs a simple integration test of the client and server"
|
|
|
|
echo " binaries from the given build dir"
|
|
|
|
echo "options:"
|
|
|
|
echo " --help|-h show this help"
|
|
|
|
echo " --verbose|-v verbose output"
|
|
|
|
echo " --valgrind-memcheck use valgrind's memcheck to run server and client"
|
|
|
|
exit 0
|
|
|
|
elif [ "$arg" == "-v" ] || [ "$arg" == "--verbose" ]
|
|
|
|
then
|
|
|
|
arg_verbose=1
|
|
|
|
elif [ "$arg" == "--valgrind-memcheck" ]
|
|
|
|
then
|
|
|
|
arg_valgrind_memcheck=1
|
2022-04-18 17:28:37 +00:00
|
|
|
else
|
2022-06-06 09:55:30 +00:00
|
|
|
echo "Error: unknown arg '$arg'"
|
2022-06-17 21:03:03 +00:00
|
|
|
exit 1
|
2022-04-18 17:28:37 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2022-06-06 09:55:30 +00:00
|
|
|
if [ ! -f DDNet ]
|
2022-04-18 17:28:37 +00:00
|
|
|
then
|
2022-06-06 09:55:30 +00:00
|
|
|
echo "Error: client binary not found DDNet' not found"
|
2022-04-18 17:28:37 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2022-06-06 09:55:30 +00:00
|
|
|
if [ ! -f DDNet-Server ]
|
2022-04-18 17:28:37 +00:00
|
|
|
then
|
2022-06-06 09:55:30 +00:00
|
|
|
echo "Error: server binary not found DDNet-Server' not found"
|
2022-04-18 17:28:37 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-05-26 12:28:55 +00:00
|
|
|
got_killed=0
|
|
|
|
|
2022-04-18 17:28:37 +00:00
|
|
|
function kill_all() {
|
2022-05-26 12:28:55 +00:00
|
|
|
# needed to fix hang fifo with additional ctrl+c
|
|
|
|
if [ "$got_killed" == "1" ]
|
|
|
|
then
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
got_killed=1
|
|
|
|
|
2022-04-18 17:28:37 +00:00
|
|
|
if [ "$arg_verbose" == "1" ]
|
|
|
|
then
|
|
|
|
echo "[*] shutting down test clients and server ..."
|
|
|
|
fi
|
2022-05-26 12:28:55 +00:00
|
|
|
|
2022-04-18 17:28:37 +00:00
|
|
|
sleep 1
|
2022-07-13 14:40:43 +00:00
|
|
|
if [[ ! -f fail_server.txt ]]
|
|
|
|
then
|
|
|
|
echo "[*] shutting down server"
|
|
|
|
echo "shutdown" > server.fifo
|
|
|
|
fi
|
|
|
|
local i
|
|
|
|
for ((i=1;i<3;i++))
|
|
|
|
do
|
|
|
|
if [[ ! -f fail_client$i.txt ]]
|
|
|
|
then
|
|
|
|
echo "[*] shutting down client$i"
|
|
|
|
echo "quit" > "client$i.fifo"
|
|
|
|
fi
|
|
|
|
done
|
2022-04-18 17:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function cleanup() {
|
|
|
|
kill_all
|
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
function fail()
|
|
|
|
{
|
|
|
|
sleep 1
|
|
|
|
tail -n2 "$1".log > fail_"$1".txt
|
|
|
|
echo "$1 exited with code $2" >> fail_"$1".txt
|
|
|
|
echo "[-] $1 exited with code $2"
|
|
|
|
}
|
|
|
|
|
|
|
|
# TODO: check for open ports instead
|
|
|
|
port=17822
|
|
|
|
|
2022-05-25 23:22:14 +00:00
|
|
|
if [[ $OSTYPE == 'darwin'* ]]; then
|
2022-05-26 12:28:55 +00:00
|
|
|
DETECT_LEAKS=0
|
2022-05-25 23:22:14 +00:00
|
|
|
else
|
2022-05-26 12:28:55 +00:00
|
|
|
DETECT_LEAKS=1
|
2022-05-25 23:22:14 +00:00
|
|
|
fi
|
|
|
|
|
2022-06-06 09:55:30 +00:00
|
|
|
export UBSAN_OPTIONS=suppressions=../ubsan.supp:log_path=./SAN:print_stacktrace=1:halt_on_errors=0
|
2022-05-25 23:22:14 +00:00
|
|
|
export ASAN_OPTIONS=log_path=./SAN:print_stacktrace=1:check_initialization_order=1:detect_leaks=$DETECT_LEAKS:halt_on_errors=0
|
2022-06-06 09:55:30 +00:00
|
|
|
export LSAN_OPTIONS=suppressions=../lsan.supp:print_suppressions=0
|
2022-04-18 17:28:37 +00:00
|
|
|
|
2022-05-26 12:28:55 +00:00
|
|
|
function print_results() {
|
|
|
|
if [ "$arg_valgrind_memcheck" == "1" ]; then
|
|
|
|
if grep "ERROR SUMMARY" server.log client1.log client2.log | grep -q -v "ERROR SUMMARY: 0"; then
|
|
|
|
grep "^==" server.log client1.log client2.log
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if test -n "$(find . -maxdepth 1 -name 'SAN.*' -print -quit)"
|
|
|
|
then
|
|
|
|
cat SAN.*
|
|
|
|
return 1
|
|
|
|
fi
|
2022-04-18 17:28:37 +00:00
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2022-06-06 09:55:30 +00:00
|
|
|
rm -rf integration_test
|
|
|
|
mkdir -p integration_test/data/maps
|
|
|
|
cp data/maps/coverage.map integration_test/data/maps
|
2022-06-23 10:41:31 +00:00
|
|
|
cp data/maps/Tutorial.map integration_test/data/maps
|
2022-06-06 09:55:30 +00:00
|
|
|
cd integration_test || exit 1
|
|
|
|
|
2022-06-06 22:10:19 +00:00
|
|
|
{
|
|
|
|
echo $'add_path $CURRENTDIR'
|
|
|
|
echo $'add_path $USERDIR'
|
|
|
|
echo $'add_path $DATADIR'
|
|
|
|
echo $'add_path ../data'
|
|
|
|
} > storage.cfg
|
|
|
|
|
2022-05-26 12:28:55 +00:00
|
|
|
if [ "$arg_valgrind_memcheck" == "1" ]; then
|
2022-06-06 09:55:30 +00:00
|
|
|
tool="valgrind --tool=memcheck --gen-suppressions=all --suppressions=../memcheck.supp --track-origins=yes"
|
2022-05-26 12:28:55 +00:00
|
|
|
client_args="cl_menu_map \"\";"
|
|
|
|
else
|
|
|
|
tool=""
|
|
|
|
client_args=""
|
|
|
|
fi
|
2022-04-18 17:28:37 +00:00
|
|
|
|
2022-06-23 10:41:31 +00:00
|
|
|
function wait_for_fifo() {
|
|
|
|
local fifo="$1"
|
|
|
|
local tries="$2"
|
|
|
|
local fails=0
|
|
|
|
# give the client time to launch and create the fifo file
|
|
|
|
# but assume after X secs that the client crashed before
|
|
|
|
# being able to create the file
|
|
|
|
while [[ ! -p "$fifo" ]]
|
|
|
|
do
|
|
|
|
fails="$((fails+1))"
|
|
|
|
if [ "$arg_verbose" == "1" ]
|
|
|
|
then
|
|
|
|
echo "[!] client fifos not found (attempts $fails/$tries)"
|
|
|
|
fi
|
|
|
|
if [ "$fails" -gt "$tries" ]
|
|
|
|
then
|
|
|
|
print_results
|
|
|
|
echo "[-] Error: client possibly crashed on launch"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-08-26 18:58:08 +00:00
|
|
|
echo "[*] launch server"
|
2022-06-06 09:55:30 +00:00
|
|
|
$tool ../DDNet-Server \
|
2022-04-18 17:28:37 +00:00
|
|
|
"sv_input_fifo server.fifo;
|
2022-06-05 09:05:30 +00:00
|
|
|
sv_rcon_password rcon;
|
2022-04-18 17:28:37 +00:00
|
|
|
sv_map coverage;
|
|
|
|
sv_sqlite_file ddnet-server.sqlite;
|
2022-06-23 10:41:31 +00:00
|
|
|
logfile server.log;
|
2022-06-26 06:59:40 +00:00
|
|
|
sv_register 0;
|
2022-06-23 10:41:31 +00:00
|
|
|
sv_port $port" > stdout_server.txt 2> stderr_server.txt || fail server "$?" &
|
2022-04-18 17:28:37 +00:00
|
|
|
|
2022-08-26 18:58:08 +00:00
|
|
|
echo "[*] launch client 1"
|
2022-06-06 09:55:30 +00:00
|
|
|
$tool ../DDNet \
|
2022-04-18 17:28:37 +00:00
|
|
|
"cl_input_fifo client1.fifo;
|
|
|
|
player_name client1;
|
|
|
|
cl_download_skins 0;
|
2022-06-01 10:15:38 +00:00
|
|
|
gfx_fullscreen 0;
|
2023-06-27 08:20:06 +00:00
|
|
|
snd_enable 0;
|
2022-06-23 10:41:31 +00:00
|
|
|
logfile client1.log;
|
2022-05-26 12:28:55 +00:00
|
|
|
$client_args
|
2022-06-23 10:41:31 +00:00
|
|
|
connect localhost:$port" > stdout_client1.txt 2> stderr_client1.txt || fail client1 "$?" &
|
2022-04-18 17:28:37 +00:00
|
|
|
|
2022-05-26 12:28:55 +00:00
|
|
|
if [ "$arg_valgrind_memcheck" == "1" ]; then
|
2023-06-27 09:08:34 +00:00
|
|
|
wait_for_fifo client1.fifo 180
|
2023-07-15 10:04:38 +00:00
|
|
|
sleep 40
|
2022-05-26 12:28:55 +00:00
|
|
|
else
|
2022-06-23 10:41:31 +00:00
|
|
|
wait_for_fifo client1.fifo 50
|
2022-06-05 08:52:32 +00:00
|
|
|
sleep 1
|
2022-05-26 12:28:55 +00:00
|
|
|
fi
|
2022-04-18 17:28:37 +00:00
|
|
|
|
2022-08-26 18:58:08 +00:00
|
|
|
echo "[*] start demo recording"
|
|
|
|
echo "record server" > server.fifo
|
|
|
|
echo "record client1" > client1.fifo
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
echo "[*] launch client 2"
|
2022-06-06 09:55:30 +00:00
|
|
|
$tool ../DDNet \
|
2022-04-18 17:28:37 +00:00
|
|
|
"cl_input_fifo client2.fifo;
|
|
|
|
player_name client2;
|
|
|
|
cl_download_skins 0;
|
2022-06-01 10:15:38 +00:00
|
|
|
gfx_fullscreen 0;
|
2023-06-27 08:20:06 +00:00
|
|
|
snd_enable 0;
|
2022-06-23 10:41:31 +00:00
|
|
|
logfile client2.log;
|
2022-05-26 12:28:55 +00:00
|
|
|
$client_args
|
2022-06-23 10:41:31 +00:00
|
|
|
connect localhost:$port" > stdout_client2.txt 2> stderr_client2.txt || fail client2 "$?" &
|
2022-04-18 17:28:37 +00:00
|
|
|
|
2022-05-26 12:28:55 +00:00
|
|
|
if [ "$arg_valgrind_memcheck" == "1" ]; then
|
2023-06-27 09:08:34 +00:00
|
|
|
wait_for_fifo client2.fifo 180
|
2023-07-15 10:04:38 +00:00
|
|
|
sleep 40
|
2022-05-26 12:28:55 +00:00
|
|
|
else
|
2022-06-23 10:41:31 +00:00
|
|
|
wait_for_fifo client2.fifo 50
|
2022-06-05 08:52:32 +00:00
|
|
|
sleep 2
|
2022-05-26 12:28:55 +00:00
|
|
|
fi
|
2022-04-18 17:28:37 +00:00
|
|
|
|
2022-06-05 09:05:30 +00:00
|
|
|
echo "[*] test chat and chat commands"
|
|
|
|
echo "say hello world" > client1.fifo
|
|
|
|
echo "rcon_auth rcon" > client1.fifo
|
|
|
|
sleep 1
|
|
|
|
tr -d '\n' > client1.fifo << EOF
|
|
|
|
say "/mc
|
|
|
|
;top5
|
|
|
|
;rank
|
|
|
|
;team 512
|
|
|
|
;emote happy -999
|
|
|
|
;pause
|
|
|
|
;points
|
|
|
|
;mapinfo
|
|
|
|
;list
|
|
|
|
;whisper client2 hi
|
|
|
|
;kill
|
|
|
|
;settings cheats
|
|
|
|
;timeout 123
|
|
|
|
;timer broadcast
|
|
|
|
;cmdlist
|
|
|
|
;saytime"
|
|
|
|
EOF
|
2022-06-05 17:37:08 +00:00
|
|
|
sleep 1
|
2022-08-26 18:58:08 +00:00
|
|
|
|
2022-06-05 09:05:30 +00:00
|
|
|
echo "[*] test rcon commands"
|
|
|
|
tr -d '\n' > client1.fifo << EOF
|
|
|
|
rcon say hello from admin;
|
|
|
|
rcon broadcast test;
|
|
|
|
rcon status;
|
|
|
|
rcon echo test;
|
|
|
|
muteid 1 900 spam;
|
|
|
|
unban_all;
|
|
|
|
EOF
|
|
|
|
sleep 1
|
2022-08-26 18:58:08 +00:00
|
|
|
|
|
|
|
echo "[*] stop demo recording"
|
|
|
|
echo "stoprecord" > server.fifo
|
|
|
|
echo "stoprecord" > client1.fifo
|
|
|
|
sleep 1
|
|
|
|
|
2022-06-23 10:41:31 +00:00
|
|
|
echo "[*] test map change"
|
|
|
|
echo "rcon sv_map Tutorial" > client1.fifo
|
2022-08-26 18:58:08 +00:00
|
|
|
if [ "$arg_valgrind_memcheck" == "1" ]; then
|
2023-07-15 10:04:38 +00:00
|
|
|
sleep 60
|
2022-08-26 18:58:08 +00:00
|
|
|
else
|
|
|
|
sleep 15
|
|
|
|
fi
|
2022-06-05 09:05:30 +00:00
|
|
|
|
2022-08-26 18:58:08 +00:00
|
|
|
echo "[*] play demos"
|
|
|
|
echo "play demos/server.demo" > client1.fifo
|
|
|
|
echo "play demos/client1.demo" > client2.fifo
|
|
|
|
if [ "$arg_valgrind_memcheck" == "1" ]; then
|
2023-07-15 10:04:38 +00:00
|
|
|
sleep 40
|
2022-08-26 18:58:08 +00:00
|
|
|
else
|
2023-07-15 10:04:38 +00:00
|
|
|
sleep 10
|
2022-08-26 18:58:08 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Kill all processes first so all outputs are fully written
|
|
|
|
kill_all
|
|
|
|
wait
|
|
|
|
sleep 1
|
2022-06-05 09:05:30 +00:00
|
|
|
|
2022-09-14 17:37:55 +00:00
|
|
|
if ! grep -qE '^[0-9]{4}-[0-9]{2}-[0-9]{2} ([0-9]{2}:){2}[0-9]{2} I chat: 0:-2:client1: hello world$' server.log
|
2022-06-05 09:05:30 +00:00
|
|
|
then
|
|
|
|
touch fail_chat.txt
|
|
|
|
echo "[-] Error: chat message not found in server log"
|
|
|
|
fi
|
2022-08-26 18:58:08 +00:00
|
|
|
|
2022-06-05 09:05:30 +00:00
|
|
|
if ! grep -q 'cmdlist' client1.log || \
|
|
|
|
! grep -q 'pause' client1.log || \
|
|
|
|
! grep -q 'rank' client1.log || \
|
|
|
|
! grep -q 'points' client1.log
|
|
|
|
then
|
|
|
|
touch fail_chatcommand.txt
|
|
|
|
echo "[-] Error: did not find output of /cmdlist command"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! grep -q "hello from admin" server.log
|
|
|
|
then
|
|
|
|
touch fail_rcon.txt
|
|
|
|
echo "[-] Error: admin message not found in server log"
|
|
|
|
fi
|
2022-06-05 08:52:32 +00:00
|
|
|
|
2022-09-14 17:37:55 +00:00
|
|
|
if ! grep -q "demo_player: Stopped playback" client1.log
|
2022-08-26 18:58:08 +00:00
|
|
|
then
|
|
|
|
touch fail_demo_server.txt
|
|
|
|
echo "[-] Error: demo playback of server demo in client 1 was not started/finished"
|
|
|
|
fi
|
2022-09-14 17:37:55 +00:00
|
|
|
if ! grep -q "demo_player: Stopped playback" client2.log
|
2022-08-26 18:58:08 +00:00
|
|
|
then
|
|
|
|
touch fail_demo_client.txt
|
|
|
|
echo "[-] Error: demo playback of client demo in client 2 was not started/finished"
|
|
|
|
fi
|
2022-04-18 17:28:37 +00:00
|
|
|
|
|
|
|
ranks="$(sqlite3 ddnet-server.sqlite < <(echo "select * from record_race;"))"
|
2022-05-25 23:22:14 +00:00
|
|
|
num_ranks="$(echo "$ranks" | wc -l | xargs)"
|
2022-04-18 17:28:37 +00:00
|
|
|
if [ "$ranks" == "" ]
|
|
|
|
then
|
|
|
|
touch fail_ranks.txt
|
|
|
|
echo "[-] Error: no ranks found in database"
|
2022-05-25 23:22:14 +00:00
|
|
|
elif [ "$num_ranks" != "1" ]
|
2022-04-18 17:28:37 +00:00
|
|
|
then
|
|
|
|
touch fail_ranks.txt
|
2022-05-25 23:22:14 +00:00
|
|
|
echo "[-] Error: expected 1 rank got $num_ranks"
|
2022-04-18 17:28:37 +00:00
|
|
|
elif ! echo "$ranks" | grep -q client1
|
|
|
|
then
|
|
|
|
touch fail_ranks.txt
|
|
|
|
echo "[-] Error: expected a rank from client1 instead got:"
|
|
|
|
echo " $ranks"
|
|
|
|
fi
|
|
|
|
|
2022-06-23 10:41:31 +00:00
|
|
|
for logfile in client1.log client2.log server.log
|
|
|
|
do
|
|
|
|
if [ "$arg_valgrind_memcheck" == "1" ]
|
|
|
|
then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
if [ ! -f "$logfile" ]
|
|
|
|
then
|
|
|
|
echo "[-] Error: logfile '$logfile' not found."
|
|
|
|
touch fail_logs.txt
|
|
|
|
continue
|
|
|
|
fi
|
2022-06-28 14:26:40 +00:00
|
|
|
logdiff="$(diff -u <(sort "$logfile") <(sort "stdout_$(basename "$logfile" .log).txt"))"
|
2022-06-23 10:41:31 +00:00
|
|
|
if [ "$logdiff" != "" ]
|
|
|
|
then
|
|
|
|
echo "[-] Error: logfile '$logfile' differs from stdout"
|
2022-06-24 23:39:59 +00:00
|
|
|
echo "$logdiff"
|
2022-06-23 10:41:31 +00:00
|
|
|
echo "[-] Error: logfile '$logfile' differs from stdout" >> fail_logs.txt
|
|
|
|
echo "$logdiff" >> fail_logs.txt
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
for stderr in ./stderr_*.txt
|
|
|
|
do
|
|
|
|
if [ ! -f "$stderr" ]
|
|
|
|
then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
if [ "$(cat "$stderr")" == "" ]
|
|
|
|
then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
echo "[!] Warning: $stderr"
|
|
|
|
cat "$stderr"
|
|
|
|
done
|
|
|
|
|
2022-04-18 17:28:37 +00:00
|
|
|
if test -n "$(find . -maxdepth 1 -name 'fail_*' -print -quit)"
|
|
|
|
then
|
2022-08-28 14:22:16 +00:00
|
|
|
for fail in fail_*
|
|
|
|
do
|
|
|
|
cat "$fail"
|
|
|
|
done
|
2022-05-26 12:28:55 +00:00
|
|
|
print_results
|
2022-04-18 17:28:37 +00:00
|
|
|
echo "[-] Test failed. See errors above."
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "[*] all tests passed"
|
|
|
|
fi
|
|
|
|
|
2022-05-26 12:28:55 +00:00
|
|
|
print_results || exit 1
|