@@ -7,14 +7,14 @@ for arg in "$@"
7
7
do
8
8
if [ " $arg " == " -h" ] || [ " $arg " == " --help" ]
9
9
then
10
- echo " usage: $( basename " $0 " ) [OPTION..] [build dir] "
10
+ echo " usage: $( basename " $0 " ) [OPTION..]"
11
11
echo " description:"
12
12
echo " Runs a simple integration test of the client and server"
13
- echo " binaries from the given build dir "
13
+ echo " binaries from the current build directory. "
14
14
echo " options:"
15
- echo " --help|-h show this help"
16
- echo " --verbose|-v verbose output"
17
- echo " --valgrind-memcheck use valgrind's memcheck to run server and client"
15
+ echo " --help|-h show this help"
16
+ echo " --verbose|-v verbose output"
17
+ echo " --valgrind-memcheck use valgrind's memcheck to run server and client"
18
18
exit 0
19
19
elif [ " $arg " == " -v" ] || [ " $arg " == " --verbose" ]
20
20
then
23
23
then
24
24
arg_valgrind_memcheck=1
25
25
else
26
- echo " Error: unknown arg '$arg '"
26
+ echo " Error: unknown argument '$arg '"
27
27
exit 1
28
28
fi
29
29
done
30
30
31
31
if [ ! -f DDNet ]
32
32
then
33
- echo " Error: client binary not found DDNet' not found"
33
+ echo " [-] Error: client binary ' DDNet' not found"
34
34
exit 1
35
35
fi
36
36
if [ ! -f DDNet-Server ]
37
37
then
38
- echo " Error: server binary not found DDNet-Server' not found"
38
+ echo " [-] Error: server binary ' DDNet-Server' not found"
39
39
exit 1
40
40
fi
41
41
42
+ echo " [*] Setup"
42
43
got_killed=0
43
44
44
45
function kill_all() {
@@ -51,24 +52,27 @@ function kill_all() {
51
52
52
53
if [ " $arg_verbose " == " 1" ]
53
54
then
54
- echo " [*] shutting down test clients and server ... "
55
+ echo " [*] Shutting down test clients and server"
55
56
fi
56
-
57
57
sleep 1
58
+
58
59
if [[ ! -f fail_server.txt ]]
59
60
then
60
- echo " [*] shutting down server"
61
+ echo " [*] Shutting down server"
61
62
echo " shutdown" > server.fifo
62
63
fi
64
+ sleep 1
65
+
63
66
local i
64
67
for (( i= 1 ;i< 3 ;i++ ))
65
68
do
66
69
if [[ ! -f fail_client$i .txt ]]
67
70
then
68
- echo " [*] shutting down client$i "
71
+ echo " [*] Shutting down client$i "
69
72
echo " quit" > " client$i .fifo"
70
73
fi
71
74
done
75
+ sleep 1
72
76
}
73
77
74
78
function cleanup() {
@@ -85,8 +89,8 @@ function fail()
85
89
echo " [-] $1 exited with code $2 "
86
90
}
87
91
88
- # TODO: check for open ports instead
89
- port=17822
92
+ # Get unused port from the system by binding to port 0 and immediately closing the socket again
93
+ port=$( python3 -c ' import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close() ' ) ;
90
94
91
95
if [[ $OSTYPE == ' darwin' * ]]; then
92
96
DETECT_LEAKS=0
@@ -100,13 +104,18 @@ export LSAN_OPTIONS=suppressions=../lsan.supp:print_suppressions=0
100
104
101
105
function print_results() {
102
106
if [ " $arg_valgrind_memcheck " == " 1" ]; then
103
- if grep " ERROR SUMMARY" server.log client1.log client2.log | grep -q -v " ERROR SUMMARY: 0" ; then
104
- grep " ^==" server.log client1.log client2.log
107
+ # Wait to ensure that the error summary was written to the stderr files because valgrind takes some time
108
+ # TODO: Instead wait for all started processes to finish
109
+ sleep 20
110
+ if grep " == ERROR SUMMARY: " stderr_server.txt stderr_client1.txt stderr_client2.txt | grep -q -v " ERROR SUMMARY: 0" ; then
111
+ echo " [-] Error: Valgrind has detected the following errors:"
112
+ grep " ^==" stderr_server.txt stderr_client1.txt stderr_client2.txt
105
113
return 1
106
114
fi
107
115
else
108
116
if test -n " $( find . -maxdepth 1 -name ' SAN.*' -print -quit) "
109
117
then
118
+ echo " [-] Error: ASAN has detected the following errors:"
110
119
cat SAN.*
111
120
return 1
112
121
fi
@@ -127,39 +136,54 @@ cd integration_test || exit 1
127
136
echo $' add_path ../data'
128
137
} > storage.cfg
129
138
139
+ tool=" "
140
+ client_args=" cl_download_skins 0;
141
+ gfx_fullscreen 0;
142
+ snd_enable 0;"
143
+
130
144
if [ " $arg_valgrind_memcheck " == " 1" ]; then
131
145
tool=" valgrind --tool=memcheck --gen-suppressions=all --suppressions=../memcheck.supp --track-origins=yes"
132
- client_args=" cl_menu_map \"\" ;"
133
- else
134
- tool=" "
135
- client_args=" "
146
+ client_args=" $client_args cl_menu_map \"\" ;"
136
147
fi
137
148
138
149
function wait_for_fifo() {
139
150
local fifo=" $1 "
140
151
local tries=" $2 "
141
152
local fails=0
142
- # give the client time to launch and create the fifo file
143
- # but assume after X secs that the client crashed before
153
+ # give the server/ client time to launch and create the fifo file
154
+ # but assume after X secs that the server/ client crashed before
144
155
# being able to create the file
145
156
while [[ ! -p " $fifo " ]]
146
157
do
147
158
fails=" $(( fails+ 1 )) "
148
159
if [ " $arg_verbose " == " 1" ]
149
160
then
150
- echo " [!] client fifos not found (attempts $fails /$tries )"
161
+ echo " [!] Note: $fifo not found (attempts $fails /$tries )"
151
162
fi
152
163
if [ " $fails " -gt " $tries " ]
153
164
then
165
+ echo " [-] Error: $( basename " $fifo " .fifo) possibly crashed on launch"
166
+ kill_all
154
167
print_results
155
- echo " [-] Error: client possibly crashed on launch"
156
168
exit 1
157
169
fi
158
170
sleep 1
159
171
done
160
172
}
161
173
162
- echo " [*] launch server"
174
+ function wait_for_launch() {
175
+ local fifo=" $1 "
176
+ local baseDuration=" $2 "
177
+ if [ " $arg_valgrind_memcheck " == " 1" ]; then
178
+ wait_for_fifo " $fifo " $(( 40 * baseDuration))
179
+ sleep $(( 8 * baseDuration))
180
+ else
181
+ wait_for_fifo " $fifo " $(( 10 * baseDuration))
182
+ sleep " $baseDuration "
183
+ fi
184
+ }
185
+
186
+ echo " [*] Launch server"
163
187
$tool ../DDNet-Server \
164
188
" sv_input_fifo server.fifo;
165
189
sv_rcon_password rcon;
@@ -169,50 +193,34 @@ $tool ../DDNet-Server \
169
193
sv_register 0;
170
194
sv_port $port " > stdout_server.txt 2> stderr_server.txt || fail server " $? " &
171
195
172
- echo " [*] launch client 1"
196
+ wait_for_launch server.fifo 1
197
+
198
+ echo " [*] Launch client 1"
173
199
$tool ../DDNet \
174
200
" cl_input_fifo client1.fifo;
175
201
player_name client1;
176
- cl_download_skins 0;
177
- gfx_fullscreen 0;
178
- snd_enable 0;
179
202
logfile client1.log;
180
203
$client_args
181
204
connect localhost:$port " > stdout_client1.txt 2> stderr_client1.txt || fail client1 " $? " &
182
205
183
- if [ " $arg_valgrind_memcheck " == " 1" ]; then
184
- wait_for_fifo client1.fifo 180
185
- sleep 40
186
- else
187
- wait_for_fifo client1.fifo 50
188
- sleep 1
189
- fi
206
+ wait_for_launch client1.fifo 5
190
207
191
- echo " [*] start demo recording"
208
+ echo " [*] Start demo recording"
192
209
echo " record server" > server.fifo
193
210
echo " record client1" > client1.fifo
194
211
sleep 1
195
212
196
- echo " [*] launch client 2"
213
+ echo " [*] Launch client 2"
197
214
$tool ../DDNet \
198
215
" cl_input_fifo client2.fifo;
199
216
player_name client2;
200
- cl_download_skins 0;
201
- gfx_fullscreen 0;
202
- snd_enable 0;
203
217
logfile client2.log;
204
218
$client_args
205
219
connect localhost:$port " > stdout_client2.txt 2> stderr_client2.txt || fail client2 " $? " &
206
220
207
- if [ " $arg_valgrind_memcheck " == " 1" ]; then
208
- wait_for_fifo client2.fifo 180
209
- sleep 40
210
- else
211
- wait_for_fifo client2.fifo 50
212
- sleep 2
213
- fi
221
+ wait_for_launch client2.fifo 5
214
222
215
- echo " [*] test chat and chat commands"
223
+ echo " [*] Test chat and chat commands"
216
224
echo " say hello world" > client1.fifo
217
225
echo " rcon_auth rcon" > client1.fifo
218
226
sleep 1
@@ -236,7 +244,7 @@ say "/mc
236
244
EOF
237
245
sleep 1
238
246
239
- echo " [*] test rcon commands"
247
+ echo " [*] Test rcon commands"
240
248
tr -d ' \n' > client1.fifo << EOF
241
249
rcon say hello from admin;
242
250
rcon broadcast test;
@@ -247,20 +255,20 @@ unban_all;
247
255
EOF
248
256
sleep 1
249
257
250
- echo " [*] stop demo recording"
258
+ echo " [*] Stop demo recording"
251
259
echo " stoprecord" > server.fifo
252
260
echo " stoprecord" > client1.fifo
253
261
sleep 1
254
262
255
- echo " [*] test map change"
263
+ echo " [*] Test map change"
256
264
echo " rcon sv_map Tutorial" > client1.fifo
257
265
if [ " $arg_valgrind_memcheck " == " 1" ]; then
258
266
sleep 60
259
267
else
260
268
sleep 15
261
269
fi
262
270
263
- echo " [*] play demos"
271
+ echo " [*] Play demos"
264
272
echo " play demos/server.demo" > client1.fifo
265
273
echo " play demos/client1.demo" > client2.fifo
266
274
if [ " $arg_valgrind_memcheck " == " 1" ]; then
271
279
272
280
# Kill all processes first so all outputs are fully written
273
281
kill_all
274
- wait
275
- sleep 1
276
282
277
283
if ! grep -qE ' ^[0-9]{4}-[0-9]{2}-[0-9]{2} ([0-9]{2}:){2}[0-9]{2} I chat: 0:-2:client1: hello world$' server.log
278
284
then
331
337
fi
332
338
if [ ! -f " $logfile " ]
333
339
then
334
- echo " [-] Error: logfile '$logfile ' not found. "
340
+ echo " [-] Error: logfile '$logfile ' not found"
335
341
touch fail_logs.txt
336
342
continue
337
343
fi
@@ -366,10 +372,9 @@ then
366
372
cat " $fail "
367
373
done
368
374
print_results
369
- echo " [-] Test failed. See errors above. "
375
+ echo " [-] Test failed. See errors above"
370
376
exit 1
371
- else
372
- echo " [*] all tests passed"
373
377
fi
374
378
379
+ echo " [*] All tests passed"
375
380
print_results || exit 1
0 commit comments