test_multiplayer.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. # Runs a multiplayer server and connects a headless client, devtest unittests are executed.
  3. dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  4. gameid=${gameid:-devtest}
  5. minetest=$dir/../bin/minetest
  6. testspath=$dir/../tests
  7. conf_client1=$testspath/client1.conf
  8. conf_server=$testspath/server.conf
  9. worldpath=$testspath/world
  10. waitfor () {
  11. n=30
  12. while [ $n -gt 0 ]; do
  13. [ -f "$1" ] && return 0
  14. sleep 0.5
  15. ((n-=1))
  16. done
  17. echo "Waiting for ${1##*/} timed out"
  18. pkill -P $$
  19. exit 1
  20. }
  21. [ -e "$minetest" ] || { echo "executable $minetest missing"; exit 1; }
  22. rm -f "$testspath/log.txt"
  23. rm -rf "$worldpath"
  24. mkdir -p "$worldpath/worldmods"
  25. printf '%s\n' >"$testspath/client1.conf" \
  26. video_driver=null name=client1 viewing_range=10 \
  27. enable_{sound,minimap,shaders}=false
  28. printf '%s\n' >"$testspath/server.conf" \
  29. max_block_send_distance=1 active_block_range=1 \
  30. devtest_unittests_autostart=true helper_mode=devtest
  31. ln -s "$dir/helper_mod" "$worldpath/worldmods/"
  32. echo "Starting server"
  33. "$minetest" --debugger --server --config "$conf_server" --world "$worldpath" --gameid $gameid 2>&1 \
  34. | sed -u 's/^/(server) /' | tee -a "$testspath/log.txt" &
  35. waitfor "$worldpath/startup"
  36. echo "Starting client"
  37. "$minetest" --debugger --config "$conf_client1" --go --address 127.0.0.1 2>&1 \
  38. | sed -u 's/^/(client) /' | tee -a "$testspath/log.txt" &
  39. waitfor "$worldpath/done"
  40. echo "Waiting for client and server to exit"
  41. wait
  42. if [ -f "$worldpath/test_failure" ]; then
  43. echo "There were test failures."
  44. exit 1
  45. fi
  46. # gdb|lldb
  47. if grep -Eq "(Thread .* received signal|thread .* stop reason =)" "$testspath/log.txt"; then
  48. echo "Debugger reported error."
  49. exit 1
  50. fi
  51. echo "Success"
  52. exit 0