test_multiplayer.sh 1.3 KB

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