3 # Copyright (C) 2015 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
8 TEST_DESC
="LTTng-crash & shm testing"
11 TESTDIR
=$CURDIR/..
/..
/..
/
12 CRASH_BIN
="lttng-crash"
14 # Test app for ust event
15 TESTAPP_PATH
="$TESTDIR/utils/testapp"
16 TESTAPP_NAME
="gen-ust-events"
17 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
22 OUTPUT_DIR
=$
(mktemp
-d -t tmp.test_crash_shm.XXXXXX
)
28 source $TESTDIR/utils
/utils.sh
30 # Global declaration for simplification
31 LTTNG_CRASH
=$TESTDIR/..
/src
/bin
/lttng-crash
/$CRASH_BIN
33 # MUST set TESTDIR before calling those functions
36 print_test_banner
"$TEST_DESC"
38 bail_out_if_no_babeltrace
40 function start_test_app
()
42 local tmp_file
=$
(mktemp
-u -t "tmp.${FUNCNAME[0]}.XXXXXX")
44 # Start application with a temporary file.
45 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event $tmp_file &
48 APPS_PID
="${APPS_PID} ${!}"
49 ok
$ret "Start application to trace"
51 # Wait for the application file to appear indicating that at least one
52 # tracepoint has been fired.
53 while [ ! -f "$tmp_file" ]; do
56 diag
"Removing test app temporary file $tmp_file"
60 function stop_test_apps
()
62 diag
"Stopping $TESTAPP_NAME"
63 for p
in ${APPS_PID}; do
72 function stop_test_app
()
83 function verify_path_dont_exists
()
87 while find $path -mindepth 1 -maxdepth 1 &>/dev
/null
; do
93 function test_shm_path_per_pid
()
95 diag
"Shm: ust per-pid test"
96 local session_name
=shm_path_per_pid
97 local channel_name
=channel_per_pid
98 local shm_path
=$
(mktemp
-d -t "tmp.${FUNCNAME[0]}_shm.XXXXXX")
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"
105 start_lttng_tracing_ok
$session_name
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"
112 # Look for per-pid folder structure
113 # Start first test app
114 diag
"Shm: check folder creation and structure"
117 first_app_pid
=$LAST_APP_PID
118 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
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"
124 first_pid_path
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1)
125 ok $?
"Pid path exists: $first_pid_path"
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"
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"
136 # Start second application pid
137 diag
"Shm: check basic creation of second ust application"
140 second_app_pid
=$LAST_APP_PID
142 file_count
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1 |
wc -l)
143 test $file_count -eq "2"
144 ok $?
"Expect 2 pid registration folders got $file_count"
146 # Stop first test application and check for cleanup
147 stop_test_app
"$first_app_pid"
148 APPS_PID
="$second_app_pid"
149 verify_path_dont_exists
"$first_pid_path"
150 ok $?
"First pid cleanup"
152 # Stop all applications and check for full cleanup
154 verify_path_dont_exists
"$shm_session_path"
158 destroy_lttng_session_ok
$session_name
163 function test_shm_path_per_uid
()
165 diag
"Shm: ust per-uid test"
166 local session_name
=shm_path_per_uid
167 local channel_name
=channel_per_uid
169 local shm_path
=$
(mktemp
-d -t "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
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"
177 start_lttng_tracing_ok
$session_name
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"
184 # Look for per-pid folder structure
185 # Start first test app
186 diag
"Shm: check folder creation and structure"
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"
194 uid_path
=$
(find $shm_session_path/ust
/uid
-mindepth 1 -maxdepth 1)
195 ok $?
"uid path exist found $uid_path"
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"
201 # Stop all applications and check for uid presence
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"
208 destroy_lttng_session_ok
$session_name
209 verify_path_dont_exists
"$shm_session_path"
216 function test_lttng_crash
()
218 diag
"Lttng-crash: basic recuperation"
219 local session_name
=crash_test
220 local channel_name
=channel_crash
221 local shm_path
=$
(mktemp
-d -t "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
222 local shm_path_symlink
=$
(mktemp
-d -t "tmp.${FUNCNAME[0]}_shm_path_symlink.XXXXXX")
223 local event_name
="tp:tptest"
225 # Create a session in snapshot mode to deactivate any use of consumerd
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
233 $TESTAPP_BIN -i 10 -w 0
234 stop_lttng_tracing_ok
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"
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"
247 destroy_lttng_session_ok
$session_name
250 rm -rf $shm_path_symlink
253 function test_lttng_crash_extraction
()
255 diag
"Lttng-crash: extraction to path"
256 local session_name
=crash_test
257 local channel_name
=channel_crash
258 local shm_path
=$
(mktemp
-d -t "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
259 local extraction_dir_path
=$
(mktemp
-d -t "tmp.${FUNCNAME[0]}_extraction_dir_path.XXXXXX")
260 local extraction_path
=$extraction_dir_path/extract
261 local event_name
="tp:tptest"
263 # Create a session in snapshot mode to deactivate any use of consumerd
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
269 start_lttng_tracing_ok
$session_name
271 $TESTAPP_BIN -i 10 -w 0
272 stop_lttng_tracing_ok
274 $LTTNG_CRASH -x $extraction_path $shm_path
275 ok $?
"Extraction of crashed buffers to path"
277 # Test extracted trace
278 trace_match_only
$event_name 10 $extraction_path
281 destroy_lttng_session_ok
$session_name
284 rm -rf $extraction_dir_path
287 function test_shm_path_per_pid_sigint
()
289 diag
"Shm: ust per-pid test sigint"
290 local session_name
=shm_path_per_pid
291 local channel_name
=channel_per_pid
292 local shm_path
=$
(mktemp
-d -t "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
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"
300 start_lttng_tracing_ok
$session_name
304 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
306 # Stop sessiond with sigint
307 stop_lttng_sessiond SIGINT
309 # Looking for a full cleanup
310 verify_path_dont_exists
"$shm_session_path"
311 ok $?
"Full cleanup on sigint"
318 function test_shm_path_per_uid_sigint
()
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
323 local shm_path
=$
(mktemp
-d -t "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
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"
331 start_lttng_tracing_ok
$session_name
335 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
337 # Test full cleanup on SIGINT
338 stop_lttng_sessiond SIGINT
340 # Looking for a full cleanup
341 verify_path_dont_exists
"$shm_session_path"
342 ok $?
"Full cleanup on sigint"
349 function test_lttng_crash_extraction_sigkill
()
351 diag
"Lttng-crash: extraction with sigkill"
352 local session_name
=crash_test
353 local channel_name
=channel_crash
354 local shm_path
=$
(mktemp
-d -t "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
355 local extraction_dir_path
=$
(mktemp
-d -t "tmp.${FUNCNAME[0]}_extraction_dir_path.XXXXXX")
356 local extraction_path
=$extraction_dir_path/extract
357 local event_name
="tp:tptest"
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
367 $TESTAPP_BIN -i 10 -w 0
369 sigstop_lttng_sessiond
370 sigstop_lttng_consumerd
372 # Kill the consumers then sessiond with sigkill
373 stop_lttng_consumerd SIGKILL
374 stop_lttng_sessiond SIGKILL
376 $LTTNG_CRASH -x $extraction_path $shm_path
378 ok
$ret "Extraction of crashed buffers to path $extraction_path"
380 # Test extracted trace
381 trace_match_only
$event_name 10 $extraction_path
386 rm -rf $extraction_dir_path
389 function interrupt_cleanup
()
391 diag
"*** Cleaning-up test ***"
397 test_shm_path_per_pid
398 test_shm_path_per_uid
399 test_shm_path_per_pid_sigint
400 test_shm_path_per_uid_sigint
402 test_lttng_crash_extraction
403 test_lttng_crash_extraction_sigkill
406 trap interrupt_cleanup SIGTERM SIGINT
408 for fct_test
in ${TESTS[@]};
411 if [ $?
-ne 0 ]; then
417 OUTPUT_DEST
=/dev
/null
2>&1