test_multiplayer.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. executable=$dir/../bin/luanti
  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 "$executable" ] || { echo "executable $executable 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,post_processing}=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. "${serverconf:-}"
  32. ln -s "$dir/helper_mod" "$worldpath/worldmods/"
  33. echo "Starting server"
  34. "$executable" --debugger --server --config "$conf_server" --world "$worldpath" --gameid $gameid 2>&1 \
  35. | sed -u 's/^/(server) /' | tee -a "$testspath/log.txt" &
  36. waitfor "$worldpath/startup"
  37. echo "Starting client"
  38. "$executable" --debugger --config "$conf_client1" --go --address 127.0.0.1 2>&1 \
  39. | sed -u 's/^/(client) /' | tee -a "$testspath/log.txt" &
  40. waitfor "$worldpath/done"
  41. echo "Waiting for client and server to exit"
  42. wait
  43. if [ -f "$worldpath/test_failure" ]; then
  44. echo "There were test failures."
  45. exit 1
  46. fi
  47. # gdb|lldb
  48. if grep -Eq "(Thread .* received signal|thread .* stop reason =)" "$testspath/log.txt"; then
  49. echo "Debugger reported error."
  50. exit 1
  51. fi
  52. echo "Success"
  53. exit 0