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)
38 source $TESTDIR/utils
/utils.sh
40 # Global declaration for simplification
41 LTTNG_CRASH
=$TESTDIR/..
/src
/bin
/lttng-crash
/$CRASH_BIN
43 # MUST set TESTDIR before calling those functions
46 print_test_banner
"$TEST_DESC"
48 function start_test_app
()
50 local tmp_file
=$
(mktemp
-u)
52 # Start application with a temporary file.
53 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
56 APPS_PID
="${APPS_PID} ${!}"
57 ok
$ret "Start application to trace"
59 # Wait for the application file to appear indicating that at least one
60 # tracepoint has been fired.
61 while [ ! -f "$tmp_file" ]; do
64 diag
"Removing test app temporary file $tmp_file"
68 function stop_test_apps
()
70 diag
"Stopping $TESTAPP_NAME"
71 for p
in ${APPS_PID}; do
80 function stop_test_app
()
91 function verify_path_dont_exists
()
95 while find $path -mindepth 1 -maxdepth 1 &>/dev
/null
; do
101 function test_shm_path_per_pid
()
103 diag
"Shm: ust per-pid test"
104 local session_name
=shm_path_per_pid
105 local channel_name
=channel_per_pid
106 local shm_path
=$
(mktemp
-d)
110 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
111 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-pid"
113 start_lttng_tracing_ok
$session_name
115 diag
"Shm: clean state"
116 file_count
=$
(find $shm_path -mindepth 1 -maxdepth 1 |
wc -l)
117 test $file_count -eq "0"
118 ok $?
"No file created on set-up"
120 # Look for per-pid folder structure
121 # Start first test app
122 diag
"Shm: check folder creation and structure"
125 first_app_pid
=$LAST_APP_PID
126 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
128 file_count
=$
(echo "$shm_session_path"|
wc -l)
129 test $file_count -eq "1"
130 ok $?
"Path $shm_session_path created on application creation"
132 first_pid_path
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1)
133 ok $?
"Pid path exists: $first_pid_path"
135 file_count
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1 |
wc -l)
136 test $file_count -eq "1"
137 ok $?
"Expect 1 pid registration folder got $file_count"
139 # Check for buffer and metadata presence in ust/pid/appfolder
140 file_count
=$
(find $first_pid_path/ -mindepth 1 -maxdepth 1 |
wc -l)
141 test $file_count -ne "0"
142 ok $?
"Expect > 0 buffer and metadata files got $file_count"
144 # Start second application pid
145 diag
"Shm: check basic creation of second ust application"
148 second_app_pid
=$LAST_APP_PID
149 second_pid_path
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1)
150 ok $?
"Pid path exist found $second_pid_path"
152 file_count
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1 |
wc -l)
153 test $file_count -eq "2"
154 ok $?
"Expect 2 pid registration folder got $file_count"
156 # Stop first test application and check for cleanup
157 stop_test_app
"$first_app_pid"
158 APPS_PID
="$second_app_pid"
159 verify_path_dont_exists
"$first_pid_path"
160 ok $?
"First pid cleanup"
162 # Stop all applications and check for full cleanup
164 verify_path_dont_exists
"$shm_session_path"
168 destroy_lttng_session_ok
$session_name
173 function test_shm_path_per_uid
()
175 diag
"Shm: ust per-uid test"
176 local session_name
=shm_path_per_uid
177 local channel_name
=channel_per_uid
178 local shm_path
=$
(mktemp
-d)
182 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
183 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
185 start_lttng_tracing_ok
$session_name
187 diag
"Shm: test clean state"
188 file_count
=$
(find $shm_path -mindepth 1 -maxdepth 1 |
wc -l)
189 test $file_count -eq "0"
190 ok $?
"No files created on set-up"
192 # Look for per-pid folder structure
193 # Start first test app
194 diag
"Shm: check folder creation and structure"
197 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
198 file_count
=$
(echo "$shm_session_path"|
wc -l)
199 test $file_count -eq "1"
200 ok $?
"Path $shm_session_path created on application creation"
202 uid_path
=$
(find $shm_session_path/ust
/uid
-mindepth 1 -maxdepth 1)
203 ok $?
"uid path exist found $uid_path"
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"
209 # Stop all applications and check for uid presence
211 file_count
=$
(find $shm_session_path/ust
/uid
-mindepth 1 -maxdepth 1 |
wc -l)
212 test $file_count -eq "1"
213 ok $?
"Expect 1 uid registration folder got $file_count"
216 destroy_lttng_session_ok
$session_name
217 verify_path_dont_exists
"$shm_session_path"
224 function test_lttng_crash
()
226 diag
"Lttng-crash: basic recuperation"
227 local session_name
=crash_test
228 local channel_name
=channel_crash
229 local shm_path
=$
(mktemp
-d)
230 local shm_path_symlink
=$
(mktemp
-d)
231 local event_name
="tp:tptest"
233 # Create a session in snapshot mode to deactivate any use of consumerd
235 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
236 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
237 enable_ust_lttng_event_ok
$session_name $event_name $channel_name
238 start_lttng_tracing_ok
$session_name
242 stop_lttng_tracing_ok
244 crash_recup_count
=$
($LTTNG_CRASH $shm_path |
wc -l)
245 test $crash_recup_count -eq "10"
246 ok $?
"Expect 10 recup event from buffers got $crash_recup_count"
249 cp -rs $shm_path/.
$shm_path_symlink
250 crash_recup_count
=$
($LTTNG_CRASH $shm_path_symlink |
wc -l)
251 test $crash_recup_count -eq "10"
252 ok $?
"Expect 10 recup event from symlink buffers got $crash_recup_count"
255 destroy_lttng_session_ok
$session_name
258 rm -rf $shm_path_symlink
261 function test_lttng_crash_extraction
()
263 diag
"Lttng-crash: extraction to path"
264 local session_name
=crash_test
265 local channel_name
=channel_crash
266 local shm_path
=$
(mktemp
-d)
267 local extraction_dir_path
=$
(mktemp
-d)
268 local extraction_path
=$extraction_dir_path/extract
269 local event_name
="tp:tptest"
271 # Create a session in snapshot mode to deactivate any use of consumerd
273 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
274 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
275 enable_ust_lttng_event_ok
$session_name $event_name $channel_name
277 start_lttng_tracing_ok
$session_name
280 stop_lttng_tracing_ok
282 $LTTNG_CRASH -x $extraction_path $shm_path
283 ok $?
"Extraction of crashed buffers to path"
285 # Test extracted trace
286 trace_match_only
$event_name 10 $extraction_path
289 destroy_lttng_session_ok
$session_name
292 rm -rf $extraction_dir_path
295 function test_shm_path_per_pid_sigint
()
297 diag
"Shm: ust per-pid test sigint"
298 local session_name
=shm_path_per_pid
299 local channel_name
=channel_per_pid
300 local shm_path
=$
(mktemp
-d)
305 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
306 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-pid"
308 start_lttng_tracing_ok
$session_name
312 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
314 # Stop sessiond with sigint
315 stop_lttng_sessiond SIGINT
317 # Looking for a full cleanup
318 verify_path_dont_exists
"$shm_session_path"
319 ok $?
"Full cleanup on sigint"
326 function test_shm_path_per_uid_sigint
()
328 diag
"Shm: ust per-uid test sigint"
329 local session_name
=shm_path_per_uid_sigint
330 local channel_name
=channel_per_uid_sigint
331 local shm_path
=$
(mktemp
-d)
336 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
337 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
339 start_lttng_tracing_ok
$session_name
343 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
345 # Test full cleanup on SIGINT
346 stop_lttng_sessiond SIGINT
348 # Looking for a full cleanup
349 verify_path_dont_exists
"$shm_session_path"
350 ok $?
"Full cleanup on sigint"
357 function test_lttng_crash_extraction_sigkill
()
359 diag
"Lttng-crash: extraction with sigkill"
360 local session_name
=crash_test
361 local channel_name
=channel_crash
362 local shm_path
=$
(mktemp
-d)
363 local extraction_dir_path
=$
(mktemp
-d)
364 local extraction_path
=$extraction_dir_path/extract
365 local event_name
="tp:tptest"
369 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
370 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
371 enable_ust_lttng_event_ok
$session_name $event_name $channel_name
372 start_lttng_tracing_ok
$session_name
377 sigstop_lttng_sessiond
378 sigstop_lttng_consumerd
380 # Kill the consumers then sessiond with sigkill
381 stop_lttng_consumerd SIGKILL
382 stop_lttng_sessiond SIGKILL
384 $LTTNG_CRASH -x $extraction_path $shm_path
386 ok
$ret "Extraction of crashed buffers to path $extraction_path"
388 # Test extracted trace
389 trace_match_only
$event_name 10 $extraction_path
394 rm -rf $extraction_dir_path
397 function interrupt_cleanup
()
399 diag
"*** Cleaning-up test ***"
406 test_shm_path_per_uid
407 test_shm_path_per_pid
408 test_shm_path_per_pid_sigint
409 test_shm_path_per_uid_sigint
411 test_lttng_crash_extraction
412 test_lttng_crash_extraction_sigkill
415 trap interrupt_cleanup SIGTERM SIGINT
417 for fct_test
in ${TESTS[@]};
420 if [ $?
-ne 0 ]; then
426 OUTPUT_DEST
=/dev
/null
2>&1