test_multiplayer.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 -batch -ex 'set confirm off' -ex 'r' -ex 'bt' --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 devtest_unittests_autostart=true
  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. local function callback(test_ok)
  36. if not test_ok then
  37. io.close(io.open(core.get_worldpath() .. "/test_failure", "w"))
  38. end
  39. io.close(io.open(core.get_worldpath() .. "/done", "w"))
  40. core.request_shutdown("", false, 2)
  41. end
  42. if core.settings:get_bool("devtest_unittests_autostart") then
  43. unittests.on_finished = callback
  44. else
  45. core.register_on_joinplayer(function() callback(true) end)
  46. end
  47. LUA
  48. printf '%s\n' >$worldpath/worldmods/test/mod.conf \
  49. name=test optional_depends=unittests
  50. echo "Starting server"
  51. gdbrun $minetest --server --config $conf_server --world $worldpath --gameid $gameid 2>&1 | sed -u 's/^/(server) /' &
  52. waitfor $worldpath/startup
  53. echo "Starting client"
  54. gdbrun $minetest --config $conf_client1 --go --address 127.0.0.1 2>&1 | sed -u 's/^/(client) /' &
  55. waitfor $worldpath/done
  56. echo "Waiting for client and server to exit"
  57. wait
  58. if [ -f $worldpath/test_failure ]; then
  59. echo "There were test failures."
  60. exit 1
  61. fi
  62. echo "Success"
  63. exit 0