Skip to content

Commit bca4457

Browse files
committed
Add test script for server error cases
1 parent 9e14f5f commit bca4457

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

.github/workflows/linux.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
- name: Install deps
8989
run: |
9090
source ./util/ci/common.sh
91-
install_linux_deps clang-7 llvm
91+
install_linux_deps clang-7 llvm-7
9292
9393
- name: Build
9494
run: |
@@ -102,6 +102,11 @@ jobs:
102102
run: |
103103
./bin/minetest --run-unittests
104104
105+
# Do this here because we have ASan and error paths are sensitive to dangling pointers
106+
- name: Test error cases
107+
run: |
108+
./util/test_error_cases.sh
109+
105110
# Current clang version
106111
clang_18:
107112
runs-on: ubuntu-24.04

util/helper_mod/error.lua

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
error("intentional")

util/helper_mod/init.lua

+20
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,24 @@ elseif mode == "mapgen" then
4848
end
4949
core.after(0, next_, 1)
5050

51+
elseif mode == "error" then
52+
53+
local n = tonumber(core.settings:get("error_type"))
54+
local error_lua = core.get_modpath(core.get_current_modname()) .. "/error.lua"
55+
if n == 1 then
56+
print("=> error during startup <=")
57+
error("intentional")
58+
elseif n == 2 then
59+
print("=> error on first step <=")
60+
core.after(0, error, "intentional")
61+
elseif n == 3 then
62+
print("=> error in async script <=")
63+
core.register_async_dofile(error_lua)
64+
elseif n == 4 then
65+
print("=> error in mapgen script <=")
66+
core.register_mapgen_script(error_lua)
67+
else
68+
assert(false)
69+
end
70+
5171
end

util/test_error_cases.sh

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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_server=$testspath/server.conf
7+
worldpath=$testspath/world
8+
9+
[ -e "$minetest" ] || { echo "executable $minetest missing"; exit 1; }
10+
11+
write_config () {
12+
printf '%s\n' >"$conf_server" \
13+
helper_mode=error mg_name=singlenode "$@"
14+
}
15+
16+
run () {
17+
timeout 10 "$@"
18+
r=$?
19+
echo "Exit status: $r"
20+
[ $r -eq 124 ] && echo "(timed out)"
21+
if [ $r -ne 1 ]; then
22+
echo "-> Test failed"
23+
exit 1
24+
fi
25+
}
26+
27+
rm -rf "$worldpath"
28+
mkdir -p "$worldpath/worldmods"
29+
30+
ln -s "$dir/helper_mod" "$worldpath/worldmods/"
31+
32+
args=(--server --config "$conf_server" --world "$worldpath" --gameid $gameid)
33+
34+
# make sure we can tell apart sanitizer and minetest errors
35+
export ASAN_OPTIONS="exitcode=42"
36+
export MSAN_OPTIONS="exitcode=42"
37+
38+
# see helper_mod/init.lua for the different types
39+
for n in $(seq 1 4); do
40+
write_config error_type=$n
41+
run "$minetest" "${args[@]}"
42+
echo "---------------"
43+
done
44+
45+
echo "All done."
46+
exit 0

0 commit comments

Comments
 (0)