3 # Copyright (C) - 2015 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
5 # This library is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation; version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this library; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 TEST_DESC
="LTTng-crash & shm testing"
21 TESTDIR
=$CURDIR/..
/..
/..
/
22 CRASH_BIN
="lttng-crash"
24 # Test app for ust event
25 TESTAPP_PATH
="$TESTDIR/utils/testapp"
26 TESTAPP_NAME
="gen-ust-events"
27 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
32 OUTPUT_DIR
=$
(mktemp
-d)
36 source $TESTDIR/utils
/utils.sh
38 # Global declaration for simplification
39 LTTNG_CRASH
=$TESTDIR/..
/src
/bin
/lttng-crash
/$CRASH_BIN
41 # MUST set TESTDIR before calling those functions
44 print_test_banner
"$TEST_DESC"
46 function start_test_app
()
48 local tmp_file
=$
(mktemp
-u)
50 # Start application with a temporary file.
51 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
53 APPS_PID
="${APPS_PID} ${!}"
54 ok
$ret "Start application to trace"
56 # Wait for the application file to appear indicating that at least one
57 # tracepoint has been fired.
58 while [ ! -f "$tmp_file" ]; do
61 diag
"Removing test app temporary file $tmp_file"
65 function stop_test_apps
()
67 diag
"Stopping $TESTAPP_NAME"
68 for p
in ${APPS_PID}; do
77 function stop_test_app
()
87 function verify_path_dont_exists
()
91 while find $path -mindepth 1 -maxdepth 1 &>/dev
/null
; do
97 function test_shm_path_per_pid
()
99 diag
"Shm: ust per-pid test"
100 local session_name
=shm_path_per_pid
101 local channel_name
=channel_per_pid
102 local shm_path
=$
(mktemp
-d)
106 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
107 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-pid"
109 diag
"Shm: clean state"
110 file_count
=$
(find $shm_path -mindepth 1 -maxdepth 1 |
wc -l)
111 test $file_count -eq "0"
112 ok $?
"No file created on set-up"
114 # Look for per-pid folder structure
115 # Start first test app
116 diag
"Shm: check folder creation and structure"
119 first_app_pid
=$APPS_PID
120 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
122 file_count
=$
(echo "$shm_session_path"|
wc -l)
123 test $file_count -eq "1"
124 ok $?
"Path $shm_session_path created on application creation"
126 first_pid_path
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1)
127 ok $?
"Pid path exists: $first_pid_path"
129 file_count
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1 |
wc -l)
130 test $file_count -eq "1"
131 ok $?
"Expect 1 pid registration folder got $file_count"
133 # Check for buffer and metadata presence in ust/pid/appfolder
134 file_count
=$
(find $first_pid_path/ -mindepth 1 -maxdepth 1 |
wc -l)
135 test $file_count -ne "0"
136 ok $?
"Expect > 0 buffer and metadata files got $file_count"
138 # Start second application pid
139 diag
"Shm: check basic creation of second ust application"
142 second_pid_path
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1)
143 ok $?
"Pid path exist found $second_pid_path"
145 file_count
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1 |
wc -l)
146 test $file_count -eq "2"
147 ok $?
"Expect 2 pid registration folder got $file_count"
149 # Stop first test application and check for cleanup
150 stop_test_app
"$first_app_pid"
151 verify_path_dont_exists
"$first_pid_path"
152 ok $?
"First pid cleanup"
154 # Stop all applications and check for full cleanup
156 verify_path_dont_exists
"$shm_session_path"
160 destroy_lttng_session_ok
$session_name
165 function test_shm_path_per_uid
()
167 diag
"Shm: ust per-uid test"
168 local session_name
=shm_path_per_uid
169 local channel_name
=channel_per_uid
170 local shm_path
=$
(mktemp
-d)
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 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
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
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"
300 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
302 # Stop sessiond with sigint
303 stop_lttng_sessiond SIGINT
305 # Looking for a full cleanup
306 verify_path_dont_exists
"$shm_session_path"
307 ok $?
"Full cleanup on sigint"
314 function test_shm_path_per_uid_sigint
()
316 diag
"Shm: ust per-uid test sigint"
317 local session_name
=shm_path_per_uid_sigint
318 local channel_name
=channel_per_uid_sigint
319 local shm_path
=$
(mktemp
-d)
324 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
325 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
329 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
331 # Test full cleanup on SIGINT
332 stop_lttng_sessiond SIGINT
334 # Looking for a full cleanup
335 verify_path_dont_exists
"$shm_session_path"
336 ok $?
"Full cleanup on sigint"
343 function test_lttng_crash_extraction_sigkill
()
345 diag
"Lttng-crash: extraction with sigkill"
346 local session_name
=crash_test
347 local channel_name
=channel_crash
348 local shm_path
=$
(mktemp
-d)
349 local extraction_dir_path
=$
(mktemp
-d)
350 local extraction_path
=$extraction_dir_path/extract
351 local event_name
="tp:tptest"
355 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
356 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
357 enable_ust_lttng_event_ok
$session_name $event_name $channel_name
358 start_lttng_tracing_ok
$session_name
363 sigstop_lttng_sessiond
364 sigstop_lttng_consumerd
366 # Kill the consumers then sessiond with sigkill
367 stop_lttng_consumerd SIGKILL
368 stop_lttng_sessiond SIGKILL
370 $LTTNG_CRASH -x $extraction_path $shm_path
372 ok
$ret "Extraction of crashed buffers to path $extraction_path"
374 # Test extracted trace
375 trace_match_only
$event_name 10 $extraction_path
380 rm -rf $extraction_dir_path
383 function interrupt_cleanup
()
385 diag
"*** Cleaning-up test ***"
392 test_shm_path_per_uid
393 test_shm_path_per_pid
394 test_shm_path_per_pid_sigint
395 test_shm_path_per_uid_sigint
397 test_lttng_crash_extraction
398 test_lttng_crash_extraction_sigkill
401 trap interrupt_cleanup SIGTERM SIGINT
403 for fct_test
in ${TESTS[@]};
406 if [ $?
-ne 0 ]; then
412 OUTPUT_DEST
=/dev
/null
2>&1