Tests: use babeltrace2 for all tests
[lttng-tools.git] / tests / regression / tools / crash / test_crash
CommitLineData
4c80129b
JR
1#!/bin/bash
2#
9d16b343 3# Copyright (C) 2015 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
4c80129b 4#
9d16b343 5# SPDX-License-Identifier: LGPL-2.1-only
4c80129b 6#
4c80129b
JR
7
8TEST_DESC="LTTng-crash & shm testing"
9
10CURDIR=$(dirname $0)/
11TESTDIR=$CURDIR/../../../
12CRASH_BIN="lttng-crash"
13
14# Test app for ust event
15TESTAPP_PATH="$TESTDIR/utils/testapp"
16TESTAPP_NAME="gen-ust-events"
17TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
18NR_USEC_WAIT=0
19NR_ITER=-1
20
21# Temp file output
33e55711 22OUTPUT_DIR=$(mktemp -d --tmpdir tmp.test_crash_shm.XXXXXX)
4c80129b 23
44e941b7
MD
24LAST_APP_PID=
25
baa2c8a4 26NUM_TESTS=76
4c80129b
JR
27
28source $TESTDIR/utils/utils.sh
29
30# Global declaration for simplification
31LTTNG_CRASH=$TESTDIR/../src/bin/lttng-crash/$CRASH_BIN
32
33# MUST set TESTDIR before calling those functions
34plan_tests $NUM_TESTS
35
36print_test_banner "$TEST_DESC"
37
c125de8f
FD
38bail_out_if_no_babeltrace
39
4c80129b
JR
40function start_test_app()
41{
33e55711 42 local tmp_file=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}.XXXXXX")
4c80129b
JR
43
44 # Start application with a temporary file.
6c4a91d6 45 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event $tmp_file &
4c80129b 46 ret=$?
44e941b7 47 LAST_APP_PID="${!}"
4c80129b
JR
48 APPS_PID="${APPS_PID} ${!}"
49 ok $ret "Start application to trace"
50
51 # Wait for the application file to appear indicating that at least one
52 # tracepoint has been fired.
53 while [ ! -f "$tmp_file" ]; do
54 sleep 0.5
55 done
56 diag "Removing test app temporary file $tmp_file"
57 rm -rf $tmp_file
58}
59
60function stop_test_apps()
61{
62 diag "Stopping $TESTAPP_NAME"
63 for p in ${APPS_PID}; do
64 diag "Stopping $p"
65 kill ${p} 2>/dev/null
66 wait ${p} 2>/dev/null
67 diag "Stopped $p"
68 done
69 APPS_PID=
70}
71
72function stop_test_app()
73{
74 local pid="$1"
75 for p in ${pid}; do
76 diag "Stopping $p"
77 kill ${p} 2>/dev/null
78 wait ${p} 2>/dev/null
44e941b7 79 diag "Stopped $p"
4c80129b
JR
80 done
81}
82
83function verify_path_dont_exists()
84{
85 local path=$1
4c80129b
JR
86
87 while find $path -mindepth 1 -maxdepth 1 &>/dev/null ; do
91d98ef4 88 sleep 2
4c80129b 89 done
91d98ef4 90 return 0
4c80129b
JR
91}
92
93function test_shm_path_per_pid()
94{
95 diag "Shm: ust per-pid test"
96 local session_name=shm_path_per_pid
97 local channel_name=channel_per_pid
33e55711 98 local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm.XXXXXX")
4c80129b
JR
99
100 # Build up
101 start_lttng_sessiond
102 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
103 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-pid"
104
c02a94c4
MD
105 start_lttng_tracing_ok $session_name
106
4c80129b
JR
107 diag "Shm: clean state"
108 file_count=$(find $shm_path -mindepth 1 -maxdepth 1 | wc -l)
109 test $file_count -eq "0"
110 ok $? "No file created on set-up"
111
112 # Look for per-pid folder structure
113 # Start first test app
114 diag "Shm: check folder creation and structure"
115
116 start_test_app
44e941b7 117 first_app_pid=$LAST_APP_PID
4c80129b
JR
118 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
119
120 file_count=$(echo "$shm_session_path"| wc -l)
121 test $file_count -eq "1"
122 ok $? "Path $shm_session_path created on application creation"
123
124 first_pid_path=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1)
125 ok $? "Pid path exists: $first_pid_path"
126
127 file_count=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1 | wc -l)
128 test $file_count -eq "1"
129 ok $? "Expect 1 pid registration folder got $file_count"
130
131 # Check for buffer and metadata presence in ust/pid/appfolder
132 file_count=$(find $first_pid_path/ -mindepth 1 -maxdepth 1 | wc -l)
133 test $file_count -ne "0"
134 ok $? "Expect > 0 buffer and metadata files got $file_count"
135
136 # Start second application pid
137 diag "Shm: check basic creation of second ust application"
138
139 start_test_app
44e941b7 140 second_app_pid=$LAST_APP_PID
4c80129b
JR
141
142 file_count=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1 | wc -l)
143 test $file_count -eq "2"
baa2c8a4 144 ok $? "Expect 2 pid registration folders got $file_count"
4c80129b
JR
145
146 # Stop first test application and check for cleanup
147 stop_test_app "$first_app_pid"
44e941b7 148 APPS_PID="$second_app_pid"
4c80129b
JR
149 verify_path_dont_exists "$first_pid_path"
150 ok $? "First pid cleanup"
151
152 # Stop all applications and check for full cleanup
153 stop_test_apps
154 verify_path_dont_exists "$shm_session_path"
155 ok $? "Full cleanup"
156
157 # Tear down
158 destroy_lttng_session_ok $session_name
159 stop_lttng_sessiond
160 rm -rf $shm_path
161}
162
163function test_shm_path_per_uid()
164{
165 diag "Shm: ust per-uid test"
166 local session_name=shm_path_per_uid
167 local channel_name=channel_per_uid
33e55711
FD
168 set -x
169 local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
170 set +x
4c80129b
JR
171
172 # Build up
173 start_lttng_sessiond
174 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
175 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
176
c02a94c4
MD
177 start_lttng_tracing_ok $session_name
178
4c80129b
JR
179 diag "Shm: test clean state"
180 file_count=$(find $shm_path -mindepth 1 -maxdepth 1 | wc -l)
181 test $file_count -eq "0"
182 ok $? "No files created on set-up"
183
184 # Look for per-pid folder structure
185 # Start first test app
186 diag "Shm: check folder creation and structure"
187
188 start_test_app
189 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
190 file_count=$(echo "$shm_session_path"| wc -l)
191 test $file_count -eq "1"
192 ok $? "Path $shm_session_path created on application creation"
193
194 uid_path=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1)
195 ok $? "uid path exist found $uid_path"
196
197 file_count=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1 | wc -l)
198 test $file_count -eq "1"
199 ok $? "Expect 1 uid registration folder got $file_count"
200
201 # Stop all applications and check for uid presence
202 stop_test_apps
203 file_count=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1 | wc -l)
204 test $file_count -eq "1"
205 ok $? "Expect 1 uid registration folder got $file_count"
206
207 # Test full cleanup
208 destroy_lttng_session_ok $session_name
209 verify_path_dont_exists "$shm_session_path"
210 ok $? "Full cleanup"
211
212 stop_lttng_sessiond
213 rm -rf $shm_path
214}
215
216function test_lttng_crash()
217{
218 diag "Lttng-crash: basic recuperation"
219 local session_name=crash_test
220 local channel_name=channel_crash
33e55711
FD
221 local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
222 local shm_path_symlink=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path_symlink.XXXXXX")
4c80129b
JR
223 local event_name="tp:tptest"
224
225 # Create a session in snapshot mode to deactivate any use of consumerd
226 start_lttng_sessiond
227 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
228 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
229 enable_ust_lttng_event_ok $session_name $event_name $channel_name
230 start_lttng_tracing_ok $session_name
231
232 # Generate 10 events
6c4a91d6 233 $TESTAPP_BIN -i 10 -w 0
7fe98a98 234 stop_lttng_tracing_ok
4c80129b
JR
235
236 crash_recup_count=$($LTTNG_CRASH $shm_path | wc -l)
237 test $crash_recup_count -eq "10"
238 ok $? "Expect 10 recup event from buffers got $crash_recup_count"
239
93c4b583
JR
240 # Test with symlink
241 cp -rs $shm_path/. $shm_path_symlink
242 crash_recup_count=$($LTTNG_CRASH $shm_path_symlink | wc -l)
243 test $crash_recup_count -eq "10"
244 ok $? "Expect 10 recup event from symlink buffers got $crash_recup_count"
245
4c80129b
JR
246 # Tear down
247 destroy_lttng_session_ok $session_name
248 stop_lttng_sessiond
249 rm -rf $shm_path
93c4b583 250 rm -rf $shm_path_symlink
4c80129b
JR
251}
252
253function test_lttng_crash_extraction()
254{
255 diag "Lttng-crash: extraction to path"
256 local session_name=crash_test
257 local channel_name=channel_crash
33e55711
FD
258 local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
259 local extraction_dir_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_extraction_dir_path.XXXXXX")
4c80129b
JR
260 local extraction_path=$extraction_dir_path/extract
261 local event_name="tp:tptest"
262
263 # Create a session in snapshot mode to deactivate any use of consumerd
264 start_lttng_sessiond
265 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
266 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
267 enable_ust_lttng_event_ok $session_name $event_name $channel_name
268
269 start_lttng_tracing_ok $session_name
270 # Generate 10 events
6c4a91d6 271 $TESTAPP_BIN -i 10 -w 0
7fe98a98 272 stop_lttng_tracing_ok
4c80129b
JR
273
274 $LTTNG_CRASH -x $extraction_path $shm_path
275 ok $? "Extraction of crashed buffers to path"
276
277 # Test extracted trace
278 trace_match_only $event_name 10 $extraction_path
279
280 # Tear down
281 destroy_lttng_session_ok $session_name
282 stop_lttng_sessiond
283 rm -rf $shm_path
284 rm -rf $extraction_dir_path
285}
286
287function test_shm_path_per_pid_sigint()
288{
289 diag "Shm: ust per-pid test sigint"
290 local session_name=shm_path_per_pid
291 local channel_name=channel_per_pid
33e55711 292 local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
4c80129b
JR
293 local num_files=0
294
295 # Build up
296 start_lttng_sessiond
297 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
298 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-pid"
299
c02a94c4
MD
300 start_lttng_tracing_ok $session_name
301
4c80129b
JR
302 start_test_app
303 start_test_app
304 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
305
306 # Stop sessiond with sigint
307 stop_lttng_sessiond SIGINT
308
309 # Looking for a full cleanup
310 verify_path_dont_exists "$shm_session_path"
311 ok $? "Full cleanup on sigint"
312
313 # Tear down
314 stop_test_apps
315 rm -rf $shm_path
316}
317
318function test_shm_path_per_uid_sigint()
319{
320 diag "Shm: ust per-uid test sigint"
321 local session_name=shm_path_per_uid_sigint
322 local channel_name=channel_per_uid_sigint
33e55711 323 local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
4c80129b
JR
324 local ret=0
325
326 # Build up
327 start_lttng_sessiond
328 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
329 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
330
c02a94c4
MD
331 start_lttng_tracing_ok $session_name
332
4c80129b
JR
333 start_test_app
334 start_test_app
335 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
336
337 # Test full cleanup on SIGINT
338 stop_lttng_sessiond SIGINT
339
340 # Looking for a full cleanup
341 verify_path_dont_exists "$shm_session_path"
342 ok $? "Full cleanup on sigint"
343
344 # Tear down
345 stop_test_apps
346 rm -rf $shm_path
347}
348
349function test_lttng_crash_extraction_sigkill()
350{
351 diag "Lttng-crash: extraction with sigkill"
352 local session_name=crash_test
353 local channel_name=channel_crash
33e55711
FD
354 local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
355 local extraction_dir_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_extraction_dir_path.XXXXXX")
4c80129b
JR
356 local extraction_path=$extraction_dir_path/extract
357 local event_name="tp:tptest"
358 local ret=0
359
360 start_lttng_sessiond
361 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
362 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
363 enable_ust_lttng_event_ok $session_name $event_name $channel_name
364 start_lttng_tracing_ok $session_name
365
366 # Generate 10 events
6c4a91d6 367 $TESTAPP_BIN -i 10 -w 0
4c80129b 368
8490897a
MD
369 sigstop_lttng_sessiond
370 sigstop_lttng_consumerd
371
4c80129b
JR
372 # Kill the consumers then sessiond with sigkill
373 stop_lttng_consumerd SIGKILL
374 stop_lttng_sessiond SIGKILL
375
376 $LTTNG_CRASH -x $extraction_path $shm_path
377 ret=$?
378 ok $ret "Extraction of crashed buffers to path $extraction_path"
379
380 # Test extracted trace
381 trace_match_only $event_name 10 $extraction_path
382
383 # Tear down
384 stop_test_apps
385 rm -rf $shm_path
386 rm -rf $extraction_dir_path
387}
388
3e46b4ca
JG
389function interrupt_cleanup()
390{
391 diag "*** Cleaning-up test ***"
392 stop_test_apps
3be453c9 393 full_cleanup
3e46b4ca
JG
394}
395
4c80129b 396TESTS=(
4c80129b 397 test_shm_path_per_pid
33e55711 398 test_shm_path_per_uid
4c80129b
JR
399 test_shm_path_per_pid_sigint
400 test_shm_path_per_uid_sigint
93c4b583
JR
401 test_lttng_crash
402 test_lttng_crash_extraction
4c80129b
JR
403 test_lttng_crash_extraction_sigkill
404)
405
3e46b4ca 406trap interrupt_cleanup SIGTERM SIGINT
4c80129b
JR
407
408for fct_test in ${TESTS[@]};
409do
410 ${fct_test}
411 if [ $? -ne 0 ]; then
412 break;
413 fi
414done
415rm -rf $OUTPUT_DIR
416
417OUTPUT_DEST=/dev/null 2>&1
This page took 0.051831 seconds and 4 git commands to generate.