test_multiplayer.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  3. 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. gdbrun () {
  21. gdb -q -ex 'set confirm off' -ex 'r' -ex 'bt' -ex 'quit' --args "$@"
  22. }
  23. [ -e $minetest ] || { echo "executable $minetest missing"; exit 1; }
  24. rm -rf $worldpath
  25. mkdir -p $worldpath/worldmods/test
  26. printf '%s\n' >$testspath/client1.conf \
  27. video_driver=null name=client1 viewing_range=10 \
  28. enable_{sound,minimap,shaders}=false
  29. printf '%s\n' >$testspath/server.conf \
  30. max_block_send_distance=1
  31. cat >$worldpath/worldmods/test/init.lua <<"LUA"
  32. core.after(0, function()
  33. io.close(io.open(core.get_worldpath() .. "/startup", "w"))
  34. end)
  35. core.register_on_joinplayer(function(player)
  36. io.close(io.open(core.get_worldpath() .. "/player_joined", "w"))
  37. core.request_shutdown("", false, 2)
  38. end)
  39. LUA
  40. echo "Starting server"
  41. gdbrun $minetest --server --config $conf_server --world $worldpath --gameid $gameid 2>&1 | sed -u 's/^/(server) /' &
  42. waitfor $worldpath/startup
  43. echo "Starting client"
  44. gdbrun $minetest --config $conf_client1 --go --address 127.0.0.1 2>&1 | sed -u 's/^/(client) /' &
  45. waitfor $worldpath/player_joined
  46. echo "Waiting for client and server to exit"
  47. wait
  48. echo "Success"
  49. exit 0