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)
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 function start_test_app
()
40 local tmp_file
=$
(mktemp
-u)
42 # Start application with a temporary file.
43 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event $tmp_file &
46 APPS_PID
="${APPS_PID} ${!}"
47 ok
$ret "Start application to trace"
49 # Wait for the application file to appear indicating that at least one
50 # tracepoint has been fired.
51 while [ ! -f "$tmp_file" ]; do
54 diag
"Removing test app temporary file $tmp_file"
58 function stop_test_apps
()
60 diag
"Stopping $TESTAPP_NAME"
61 for p
in ${APPS_PID}; do
70 function stop_test_app
()
81 function verify_path_dont_exists
()
85 while find $path -mindepth 1 -maxdepth 1 &>/dev
/null
; do
91 function test_shm_path_per_pid
()
93 diag
"Shm: ust per-pid test"
94 local session_name
=shm_path_per_pid
95 local channel_name
=channel_per_pid
96 local shm_path
=$
(mktemp
-d)
100 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
101 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-pid"
103 start_lttng_tracing_ok
$session_name
105 diag
"Shm: clean state"
106 file_count
=$
(find $shm_path -mindepth 1 -maxdepth 1 |
wc -l)
107 test $file_count -eq "0"
108 ok $?
"No file created on set-up"
110 # Look for per-pid folder structure
111 # Start first test app
112 diag
"Shm: check folder creation and structure"
115 first_app_pid
=$LAST_APP_PID
116 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
118 file_count
=$
(echo "$shm_session_path"|
wc -l)
119 test $file_count -eq "1"
120 ok $?
"Path $shm_session_path created on application creation"
122 first_pid_path
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1)
123 ok $?
"Pid path exists: $first_pid_path"
125 file_count
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1 |
wc -l)
126 test $file_count -eq "1"
127 ok $?
"Expect 1 pid registration folder got $file_count"
129 # Check for buffer and metadata presence in ust/pid/appfolder
130 file_count
=$
(find $first_pid_path/ -mindepth 1 -maxdepth 1 |
wc -l)
131 test $file_count -ne "0"
132 ok $?
"Expect > 0 buffer and metadata files got $file_count"
134 # Start second application pid
135 diag
"Shm: check basic creation of second ust application"
138 second_app_pid
=$LAST_APP_PID
139 second_pid_path
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1)
140 ok $?
"Pid path exist found $second_pid_path"
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 folder 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
168 local shm_path
=$
(mktemp
-d)
172 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
173 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
175 start_lttng_tracing_ok
$session_name
177 diag
"Shm: test clean state"
178 file_count
=$
(find $shm_path -mindepth 1 -maxdepth 1 |
wc -l)
179 test $file_count -eq "0"
180 ok $?
"No files created on set-up"
182 # Look for per-pid folder structure
183 # Start first test app
184 diag
"Shm: check folder creation and structure"
187 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
188 file_count
=$
(echo "$shm_session_path"|
wc -l)
189 test $file_count -eq "1"
190 ok $?
"Path $shm_session_path created on application creation"
192 uid_path
=$
(find $shm_session_path/ust
/uid
-mindepth 1 -maxdepth 1)
193 ok $?
"uid path exist found $uid_path"
195 file_count
=$
(find $shm_session_path/ust
/uid
-mindepth 1 -maxdepth 1 |
wc -l)
196 test $file_count -eq "1"
197 ok $?
"Expect 1 uid registration folder got $file_count"
199 # Stop all applications and check for uid presence
201 file_count
=$
(find $shm_session_path/ust
/uid
-mindepth 1 -maxdepth 1 |
wc -l)
202 test $file_count -eq "1"
203 ok $?
"Expect 1 uid registration folder got $file_count"
206 destroy_lttng_session_ok
$session_name
207 verify_path_dont_exists
"$shm_session_path"
214 function test_lttng_crash
()
216 diag
"Lttng-crash: basic recuperation"
217 local session_name
=crash_test
218 local channel_name
=channel_crash
219 local shm_path
=$
(mktemp
-d)
220 local shm_path_symlink
=$
(mktemp
-d)
221 local event_name
="tp:tptest"
223 # Create a session in snapshot mode to deactivate any use of consumerd
225 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
226 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
227 enable_ust_lttng_event_ok
$session_name $event_name $channel_name
228 start_lttng_tracing_ok
$session_name
231 $TESTAPP_BIN -i 10 -w 0
232 stop_lttng_tracing_ok
234 crash_recup_count
=$
($LTTNG_CRASH $shm_path |
wc -l)
235 test $crash_recup_count -eq "10"
236 ok $?
"Expect 10 recup event from buffers got $crash_recup_count"
239 cp -rs $shm_path/.
$shm_path_symlink
240 crash_recup_count
=$
($LTTNG_CRASH $shm_path_symlink |
wc -l)
241 test $crash_recup_count -eq "10"
242 ok $?
"Expect 10 recup event from symlink buffers got $crash_recup_count"
245 destroy_lttng_session_ok
$session_name
248 rm -rf $shm_path_symlink
251 function test_lttng_crash_extraction
()
253 diag
"Lttng-crash: extraction to path"
254 local session_name
=crash_test
255 local channel_name
=channel_crash
256 local shm_path
=$
(mktemp
-d)
257 local extraction_dir_path
=$
(mktemp
-d)
258 local extraction_path
=$extraction_dir_path/extract
259 local event_name
="tp:tptest"
261 # Create a session in snapshot mode to deactivate any use of consumerd
263 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
264 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
265 enable_ust_lttng_event_ok
$session_name $event_name $channel_name
267 start_lttng_tracing_ok
$session_name
269 $TESTAPP_BIN -i 10 -w 0
270 stop_lttng_tracing_ok
272 $LTTNG_CRASH -x $extraction_path $shm_path
273 ok $?
"Extraction of crashed buffers to path"
275 # Test extracted trace
276 trace_match_only
$event_name 10 $extraction_path
279 destroy_lttng_session_ok
$session_name
282 rm -rf $extraction_dir_path
285 function test_shm_path_per_pid_sigint
()
287 diag
"Shm: ust per-pid test sigint"
288 local session_name
=shm_path_per_pid
289 local channel_name
=channel_per_pid
290 local shm_path
=$
(mktemp
-d)
295 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
296 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-pid"
298 start_lttng_tracing_ok
$session_name
302 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
304 # Stop sessiond with sigint
305 stop_lttng_sessiond SIGINT
307 # Looking for a full cleanup
308 verify_path_dont_exists
"$shm_session_path"
309 ok $?
"Full cleanup on sigint"
316 function test_shm_path_per_uid_sigint
()
318 diag
"Shm: ust per-uid test sigint"
319 local session_name
=shm_path_per_uid_sigint
320 local channel_name
=channel_per_uid_sigint
321 local shm_path
=$
(mktemp
-d)
326 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
327 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
329 start_lttng_tracing_ok
$session_name
333 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
335 # Test full cleanup on SIGINT
336 stop_lttng_sessiond SIGINT
338 # Looking for a full cleanup
339 verify_path_dont_exists
"$shm_session_path"
340 ok $?
"Full cleanup on sigint"
347 function test_lttng_crash_extraction_sigkill
()
349 diag
"Lttng-crash: extraction with sigkill"
350 local session_name
=crash_test
351 local channel_name
=channel_crash
352 local shm_path
=$
(mktemp
-d)
353 local extraction_dir_path
=$
(mktemp
-d)
354 local extraction_path
=$extraction_dir_path/extract
355 local event_name
="tp:tptest"
359 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
360 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
361 enable_ust_lttng_event_ok
$session_name $event_name $channel_name
362 start_lttng_tracing_ok
$session_name
365 $TESTAPP_BIN -i 10 -w 0
367 sigstop_lttng_sessiond
368 sigstop_lttng_consumerd
370 # Kill the consumers then sessiond with sigkill
371 stop_lttng_consumerd SIGKILL
372 stop_lttng_sessiond SIGKILL
374 $LTTNG_CRASH -x $extraction_path $shm_path
376 ok
$ret "Extraction of crashed buffers to path $extraction_path"
378 # Test extracted trace
379 trace_match_only
$event_name 10 $extraction_path
384 rm -rf $extraction_dir_path
387 function interrupt_cleanup
()
389 diag
"*** Cleaning-up test ***"
395 test_shm_path_per_uid
396 test_shm_path_per_pid
397 test_shm_path_per_pid_sigint
398 test_shm_path_per_uid_sigint
400 test_lttng_crash_extraction
401 test_lttng_crash_extraction_sigkill
404 trap interrupt_cleanup SIGTERM SIGINT
406 for fct_test
in ${TESTS[@]};
409 if [ $?
-ne 0 ]; then
415 OUTPUT_DEST
=/dev
/null
2>&1