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
()
90 local timeout_try_limit
=100
91 local timeout_try_count
=0
94 while find $path -mindepth 1 -maxdepth 1 &>/dev
/null
; do
95 if [[ $timeout_try_count -gt $timeout_try_limit ]]; then
99 timeout_try_count
=$
((timeout_try_count
+1))
105 function test_shm_path_per_pid
()
107 diag
"Shm: ust per-pid test"
108 local session_name
=shm_path_per_pid
109 local channel_name
=channel_per_pid
110 local shm_path
=$
(mktemp
-d)
114 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
115 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-pid"
117 diag
"Shm: clean state"
118 file_count
=$
(find $shm_path -mindepth 1 -maxdepth 1 |
wc -l)
119 test $file_count -eq "0"
120 ok $?
"No file created on set-up"
122 # Look for per-pid folder structure
123 # Start first test app
124 diag
"Shm: check folder creation and structure"
127 first_app_pid
=$APPS_PID
128 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
130 file_count
=$
(echo "$shm_session_path"|
wc -l)
131 test $file_count -eq "1"
132 ok $?
"Path $shm_session_path created on application creation"
134 first_pid_path
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1)
135 ok $?
"Pid path exists: $first_pid_path"
137 file_count
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1 |
wc -l)
138 test $file_count -eq "1"
139 ok $?
"Expect 1 pid registration folder got $file_count"
141 # Check for buffer and metadata presence in ust/pid/appfolder
142 file_count
=$
(find $first_pid_path/ -mindepth 1 -maxdepth 1 |
wc -l)
143 test $file_count -ne "0"
144 ok $?
"Expect > 0 buffer and metadata files got $file_count"
146 # Start second application pid
147 diag
"Shm: check basic creation of second ust application"
150 second_pid_path
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1)
151 ok $?
"Pid path exist found $second_pid_path"
153 file_count
=$
(find $shm_session_path/ust
/pid
-mindepth 1 -maxdepth 1 |
wc -l)
154 test $file_count -eq "2"
155 ok $?
"Expect 2 pid registration folder got $file_count"
157 # Stop first test application and check for cleanup
158 stop_test_app
"$first_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 diag
"Shm: test clean state"
186 file_count
=$
(find $shm_path -mindepth 1 -maxdepth 1 |
wc -l)
187 test $file_count -eq "0"
188 ok $?
"No files created on set-up"
190 # Look for per-pid folder structure
191 # Start first test app
192 diag
"Shm: check folder creation and structure"
195 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
196 file_count
=$
(echo "$shm_session_path"|
wc -l)
197 test $file_count -eq "1"
198 ok $?
"Path $shm_session_path created on application creation"
200 uid_path
=$
(find $shm_session_path/ust
/uid
-mindepth 1 -maxdepth 1)
201 ok $?
"uid path exist found $uid_path"
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"
207 # Stop all applications and check for uid presence
209 file_count
=$
(find $shm_session_path/ust
/uid
-mindepth 1 -maxdepth 1 |
wc -l)
210 test $file_count -eq "1"
211 ok $?
"Expect 1 uid registration folder got $file_count"
214 destroy_lttng_session_ok
$session_name
215 verify_path_dont_exists
"$shm_session_path"
222 function test_lttng_crash
()
224 diag
"Lttng-crash: basic recuperation"
225 local session_name
=crash_test
226 local channel_name
=channel_crash
227 local shm_path
=$
(mktemp
-d)
228 local shm_path_symlink
=$
(mktemp
-d)
229 local event_name
="tp:tptest"
231 # Create a session in snapshot mode to deactivate any use of consumerd
233 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
234 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
235 enable_ust_lttng_event_ok
$session_name $event_name $channel_name
236 start_lttng_tracing_ok
$session_name
242 crash_recup_count
=$
($LTTNG_CRASH $shm_path |
wc -l)
243 test $crash_recup_count -eq "10"
244 ok $?
"Expect 10 recup event from buffers got $crash_recup_count"
247 cp -rs $shm_path/.
$shm_path_symlink
248 crash_recup_count
=$
($LTTNG_CRASH $shm_path_symlink |
wc -l)
249 test $crash_recup_count -eq "10"
250 ok $?
"Expect 10 recup event from symlink buffers got $crash_recup_count"
253 destroy_lttng_session_ok
$session_name
256 rm -rf $shm_path_symlink
259 function test_lttng_crash_extraction
()
261 diag
"Lttng-crash: extraction to path"
262 local session_name
=crash_test
263 local channel_name
=channel_crash
264 local shm_path
=$
(mktemp
-d)
265 local extraction_dir_path
=$
(mktemp
-d)
266 local extraction_path
=$extraction_dir_path/extract
267 local event_name
="tp:tptest"
269 # Create a session in snapshot mode to deactivate any use of consumerd
271 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
272 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
273 enable_ust_lttng_event_ok
$session_name $event_name $channel_name
275 start_lttng_tracing_ok
$session_name
280 $LTTNG_CRASH -x $extraction_path $shm_path
281 ok $?
"Extraction of crashed buffers to path"
283 # Test extracted trace
284 trace_match_only
$event_name 10 $extraction_path
287 destroy_lttng_session_ok
$session_name
290 rm -rf $extraction_dir_path
293 function test_shm_path_per_pid_sigint
()
295 diag
"Shm: ust per-pid test sigint"
296 local session_name
=shm_path_per_pid
297 local channel_name
=channel_per_pid
298 local shm_path
=$
(mktemp
-d)
303 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
304 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-pid"
308 shm_session_path
=$
(find $shm_path -mindepth 1 -maxdepth 1)
310 # Stop sessiond with sigint
311 stop_lttng_sessiond SIGINT
313 # Looking for a full cleanup
314 verify_path_dont_exists
"$shm_session_path"
315 ok $?
"Full cleanup on sigint"
322 function test_shm_path_per_uid_sigint
()
324 diag
"Shm: ust per-uid test sigint"
325 local session_name
=shm_path_per_uid_sigint
326 local channel_name
=channel_per_uid_sigint
327 local shm_path
=$
(mktemp
-d)
332 create_lttng_session_ok
$session_name $OUTPUT_DIR "--shm-path $shm_path"
333 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
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 # Kill the consumers then sessiond with sigkill
372 stop_lttng_consumerd SIGKILL
373 stop_lttng_sessiond SIGKILL
375 $LTTNG_CRASH -x $extraction_path $shm_path
377 ok
$ret "Extraction of crashed buffers to path $extraction_path"
379 # Test extracted trace
380 trace_match_only
$event_name 10 $extraction_path
385 rm -rf $extraction_dir_path
389 test_shm_path_per_uid
390 test_shm_path_per_pid
391 test_shm_path_per_pid_sigint
392 test_shm_path_per_uid_sigint
394 test_lttng_crash_extraction
395 test_lttng_crash_extraction_sigkill
399 for fct_test
in ${TESTS[@]};
402 if [ $?
-ne 0 ]; then
408 OUTPUT_DEST
=/dev
/null
2>&1