]> git.lizzy.rs Git - dragonfireclient.git/blob - util/test_multiplayer.sh
Hide "Autosave Screen Size" on Android
[dragonfireclient.git] / util / test_multiplayer.sh
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
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
22 gdbrun () {
23         gdb -q -batch -ex 'set confirm off' -ex 'r' -ex 'bt' --args "$@"
24 }
25
26 [ -e $minetest ] || { echo "executable $minetest missing"; exit 1; }
27
28 rm -rf $worldpath
29 mkdir -p $worldpath/worldmods/test
30
31 printf '%s\n' >$testspath/client1.conf \
32         video_driver=null name=client1 viewing_range=10 \
33         enable_{sound,minimap,shaders}=false
34
35 printf '%s\n' >$testspath/server.conf \
36         max_block_send_distance=1 devtest_unittests_autostart=true
37
38 cat >$worldpath/worldmods/test/init.lua <<"LUA"
39 core.after(0, function()
40         io.close(io.open(core.get_worldpath() .. "/startup", "w"))
41 end)
42 local function callback(test_ok)
43         if not test_ok then
44                 io.close(io.open(core.get_worldpath() .. "/test_failure", "w"))
45         end
46         io.close(io.open(core.get_worldpath() .. "/done", "w"))
47         core.request_shutdown("", false, 2)
48 end
49 if core.settings:get_bool("devtest_unittests_autostart") then
50         unittests.on_finished = callback
51 else
52         core.register_on_joinplayer(function() callback(true) end)
53 end
54 LUA
55 printf '%s\n' >$worldpath/worldmods/test/mod.conf \
56         name=test optional_depends=unittests
57
58 echo "Starting server"
59 gdbrun $minetest --server --config $conf_server --world $worldpath --gameid $gameid 2>&1 | sed -u 's/^/(server) /' &
60 waitfor $worldpath/startup
61
62 echo "Starting client"
63 gdbrun $minetest --config $conf_client1 --go --address 127.0.0.1 2>&1 | sed -u 's/^/(client) /' &
64 waitfor $worldpath/done
65
66 echo "Waiting for client and server to exit"
67 wait
68
69 if [ -f $worldpath/test_failure ]; then
70         echo "There were test failures."
71         exit 1
72 fi
73 echo "Success"
74 exit 0