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 start_lttng_tracing_ok
$session_name
111 diag
"Shm: clean state"
112 file_count
=$
(find $shm_path -mindepth 1 -maxdepth 1 |
wc -l)
113 test $file_count -eq "0"
114 ok $?
"No file created on set-up"
116 # Look for per-pid folder structure
117 # Start first test app
118 diag
"Shm: check folder creation and structure"
121 first_app_pid
=$APPS_PID
122 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
124 file_count
=$
(echo "$shm_session_path"|
wc -l)
125 test $file_count -eq "1"
126 ok $?
"Path $shm_session_path created on application creation"
128 first_pid_path
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1)
129 ok $?
"Pid path exists: $first_pid_path"
131 file_count
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1 |
wc -l)
132 test $file_count -eq "1"
133 ok $?
"Expect 1 pid registration folder got $file_count"
135 # Check for buffer and metadata presence in ust/pid/appfolder
136 file_count
=$
(find $first_pid_path/ -mindepth 1 -maxdepth 1 |
wc -l)
137 test $file_count -ne "0"
138 ok $?
"Expect > 0 buffer and metadata files got $file_count"
140 # Start second application pid
141 diag
"Shm: check basic creation of second ust application"
144 second_pid_path
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1)
145 ok $?
"Pid path exist found $second_pid_path"
147 file_count
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1 |
wc -l)
148 test $file_count -eq "2"
149 ok $?
"Expect 2 pid registration folder got $file_count"
151 # Stop first test application and check for cleanup
152 stop_test_app
"$first_app_pid"
153 verify_path_dont_exists
"$first_pid_path"
154 ok $?
"First pid cleanup"
156 # Stop all applications and check for full cleanup
158 verify_path_dont_exists
"$shm_session_path"
162 destroy_lttng_session_ok
$session_name
167 function test_shm_path_per_uid
()
169 diag
"Shm: ust per-uid test"
170 local session_name
=shm_path_per_uid
171 local channel_name
=channel_per_uid
172 local shm_path
=$
(mktemp
-d)
176 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
177 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
179 start_lttng_tracing_ok
$session_name
181 diag
"Shm: test clean state"
182 file_count
=$
(find $shm_path -mindepth 1 -maxdepth 1 |
wc -l)
183 test $file_count -eq "0"
184 ok $?
"No files created on set-up"
186 # Look for per-pid folder structure
187 # Start first test app
188 diag
"Shm: check folder creation and structure"
191 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
192 file_count
=$
(echo "$shm_session_path"|
wc -l)
193 test $file_count -eq "1"
194 ok $?
"Path $shm_session_path created on application creation"
196 uid_path
=$
(find $shm_session_path/ust
/uid
-mindepth 1 -maxdepth 1)
197 ok $?
"uid path exist found $uid_path"
199 file_count
=$
(find $shm_session_path/ust
/uid
-mindepth 1 -maxdepth 1 |
wc -l)
200 test $file_count -eq "1"
201 ok $?
"Expect 1 uid registration folder got $file_count"
203 # Stop all applications and check for uid presence
205 file_count
=$
(find $shm_session_path/ust
/uid
-mindepth 1 -maxdepth 1 |
wc -l)
206 test $file_count -eq "1"
207 ok $?
"Expect 1 uid registration folder got $file_count"
210 destroy_lttng_session_ok
$session_name
211 verify_path_dont_exists
"$shm_session_path"
218 function test_lttng_crash
()
220 diag
"Lttng-crash: basic recuperation"
221 local session_name
=crash_test
222 local channel_name
=channel_crash
223 local shm_path
=$
(mktemp
-d)
224 local shm_path_symlink
=$
(mktemp
-d)
225 local event_name
="tp:tptest"
227 # Create a session in snapshot mode to deactivate any use of consumerd
229 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
230 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
231 enable_ust_lttng_event_ok
$session_name $event_name $channel_name
232 start_lttng_tracing_ok
$session_name
236 stop_lttng_tracing_ok
238 crash_recup_count
=$
($LTTNG_CRASH $shm_path |
wc -l)
239 test $crash_recup_count -eq "10"
240 ok $?
"Expect 10 recup event from buffers got $crash_recup_count"
243 cp -rs $shm_path/.
$shm_path_symlink
244 crash_recup_count
=$
($LTTNG_CRASH $shm_path_symlink |
wc -l)
245 test $crash_recup_count -eq "10"
246 ok $?
"Expect 10 recup event from symlink buffers got $crash_recup_count"
249 destroy_lttng_session_ok
$session_name
252 rm -rf $shm_path_symlink
255 function test_lttng_crash_extraction
()
257 diag
"Lttng-crash: extraction to path"
258 local session_name
=crash_test
259 local channel_name
=channel_crash
260 local shm_path
=$
(mktemp
-d)
261 local extraction_dir_path
=$
(mktemp
-d)
262 local extraction_path
=$extraction_dir_path/extract
263 local event_name
="tp:tptest"
265 # Create a session in snapshot mode to deactivate any use of consumerd
267 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
268 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
269 enable_ust_lttng_event_ok
$session_name $event_name $channel_name
271 start_lttng_tracing_ok
$session_name
274 stop_lttng_tracing_ok
276 $LTTNG_CRASH -x $extraction_path $shm_path
277 ok $?
"Extraction of crashed buffers to path"
279 # Test extracted trace
280 trace_match_only
$event_name 10 $extraction_path
283 destroy_lttng_session_ok
$session_name
286 rm -rf $extraction_dir_path
289 function test_shm_path_per_pid_sigint
()
291 diag
"Shm: ust per-pid test sigint"
292 local session_name
=shm_path_per_pid
293 local channel_name
=channel_per_pid
294 local shm_path
=$
(mktemp
-d)
299 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
300 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-pid"
302 start_lttng_tracing_ok
$session_name
306 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
308 # Stop sessiond with sigint
309 stop_lttng_sessiond SIGINT
311 # Looking for a full cleanup
312 verify_path_dont_exists
"$shm_session_path"
313 ok $?
"Full cleanup on sigint"
320 function test_shm_path_per_uid_sigint
()
322 diag
"Shm: ust per-uid test sigint"
323 local session_name
=shm_path_per_uid_sigint
324 local channel_name
=channel_per_uid_sigint
325 local shm_path
=$
(mktemp
-d)
330 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
331 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
333 start_lttng_tracing_ok
$session_name
337 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
339 # Test full cleanup on SIGINT
340 stop_lttng_sessiond SIGINT
342 # Looking for a full cleanup
343 verify_path_dont_exists
"$shm_session_path"
344 ok $?
"Full cleanup on sigint"
351 function test_lttng_crash_extraction_sigkill
()
353 diag
"Lttng-crash: extraction with sigkill"
354 local session_name
=crash_test
355 local channel_name
=channel_crash
356 local shm_path
=$
(mktemp
-d)
357 local extraction_dir_path
=$
(mktemp
-d)
358 local extraction_path
=$extraction_dir_path/extract
359 local event_name
="tp:tptest"
363 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
364 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
365 enable_ust_lttng_event_ok
$session_name $event_name $channel_name
366 start_lttng_tracing_ok
$session_name
371 sigstop_lttng_sessiond
372 sigstop_lttng_consumerd
374 # Kill the consumers then sessiond with sigkill
375 stop_lttng_consumerd SIGKILL
376 stop_lttng_sessiond SIGKILL
378 $LTTNG_CRASH -x $extraction_path $shm_path
380 ok
$ret "Extraction of crashed buffers to path $extraction_path"
382 # Test extracted trace
383 trace_match_only
$event_name 10 $extraction_path
388 rm -rf $extraction_dir_path
391 function interrupt_cleanup
()
393 diag
"*** Cleaning-up test ***"
400 test_shm_path_per_uid
401 test_shm_path_per_pid
402 test_shm_path_per_pid_sigint
403 test_shm_path_per_uid_sigint
405 test_lttng_crash_extraction
406 test_lttng_crash_extraction_sigkill
409 trap interrupt_cleanup SIGTERM SIGINT
411 for fct_test
in ${TESTS[@]};
414 if [ $?
-ne 0 ]; then
420 OUTPUT_DEST
=/dev
/null
2>&1