3 # Copyright (C) - 2013 Julien Desfossez <jdesfossez@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
17 TEST_DESC
="Snapshots - UST tracing"
20 TESTDIR
=$CURDIR/..
/..
/..
21 EVENT_NAME
="tp:tptest"
23 CHANNEL_NAME
="snapchan"
24 TESTAPP_PATH
="$TESTDIR/utils/testapp"
25 TESTAPP_NAME
="gen-ust-events"
26 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
31 TRACE_PATH
=$
(mktemp
-d)
33 source $TESTDIR/utils
/utils.sh
35 if [ ! -x "$TESTAPP_BIN" ]; then
36 BAIL_OUT
"No UST events binary detected."
39 # Need the number of snapshot to do.
41 BAIL_OUT
"A number of snapshot is needed."
45 NUM_TESTS
=$
(($NUM_TESTS + ($NR_SNAPSHOT * 2)))
47 function start_test_app
()
49 local tmp_file
=$
(mktemp
-u)
51 # Start application with a temporary file.
52 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
54 APPS_PID
="${APPS_PID} ${!}"
55 ok
$ret "Start application to trace"
57 # Wait for the application file to appear indicating that at least one
58 # tracepoint has been fired.
59 while [ ! -f "$tmp_file" ]; do
62 diag
"Removing test app temporary file $tmp_file"
66 function wait_test_apps
()
68 diag
"Waiting for $TESTAPP_NAME"
69 for p
in ${APPS_PID}; do
74 function stop_test_apps
()
76 diag
"Stopping $TESTAPP_NAME"
77 for p
in ${APPS_PID}; do
84 function snapshot_add_output
()
92 if [ ! -z $name ]; then
93 extra_opt
+=" -n $name "
96 if [ ! -z $max_size ]; then
97 extra_opt
+=" -m $max_size "
100 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output \
101 -s $sess_name $extra_opt $trace_path > /dev
/null
2>&1
103 ok $?
"Added snapshot output $trace_path ($extra_opt)"
106 function snapshot_del_output
()
111 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output \
112 -s $sess_name $name > /dev
/null
2>&1
114 ok $?
"Deleted snapshot output named $name"
117 function enable_mmap_overwrite_subbuf_ust_channel
()
123 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name \
124 $chan_name -u --output mmap
--overwrite \
125 --subbuf-size $subbuf_size > /dev
/null
2>&1
127 ok $?
"Enable channel $channel_name for session $sess_name with subbuf size $subbuf_size"
130 function enable_mmap_small_discard_ust_channel
()
135 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name \
136 $chan_name -u --output mmap
--discard \
137 --subbuf-size $
(getconf PAGE_SIZE
) --num-subbuf 2 \
140 ok $?
"Enable channel $channel_name for session $sess_name with small discard buffers"
143 function enable_mmap_small_overwrite_ust_channel
()
148 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name \
149 $chan_name -u --output mmap
--overwrite \
150 --subbuf-size $
(getconf PAGE_SIZE
) --num-subbuf 2 \
153 ok $?
"Enable channel $channel_name for session $sess_name with small discard buffers"
156 function test_ust_list_output
()
158 output_names
=("randomname" "somesnapshot")
160 diag
"Test UST snapshot output listing"
161 create_lttng_session_no_output
$SESSION_NAME
162 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
163 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
165 start_lttng_tracing_ok
$SESSION_NAME
167 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" ${output_names[0]}
169 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output \
170 -s $SESSION_NAME 2>&1 |
grep ${output_names[0]} > /dev
/null
171 ok $?
"Snapshot named ${output_names[0]} present in list-output listing"
173 snapshot_del_output
$SESSION_NAME ${output_names[0]}
175 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" ${output_names[1]}
177 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output \
178 -s $SESSION_NAME 2>&1 |
grep ${output_names[1]} > /dev
/null
180 ok $?
"Snapshot named ${output_names[1]} present in list-output listing"
182 stop_lttng_tracing_ok
$SESSION_NAME
183 destroy_lttng_session_ok
$SESSION_NAME
186 function test_ust_local_snapshot
()
191 diag
"Test local UST snapshots"
192 create_lttng_session_no_output
$SESSION_NAME
193 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
194 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
195 start_lttng_tracing_ok
$SESSION_NAME
196 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
198 # Returns once the application has at least fired ONE tracepoint.
201 lttng_snapshot_record
$SESSION_NAME
202 stop_lttng_tracing_ok
$SESSION_NAME
203 destroy_lttng_session_ok
$SESSION_NAME
206 validate_trace
$EVENT_NAME $TRACE_PATH/
207 if [ $?
-eq 0 ]; then
208 # Only delete if successful
215 function test_ust_local_snapshot_small_discard_buffers
()
219 OLDCPUSET
=$
(taskset
-p $$
)
221 diag
"Test local UST snapshots with small discard buffers"
222 taskset
-p 0x1 $$
1>/dev
/null
2>&1 # CPU 0 only
223 create_lttng_session_no_output
$SESSION_NAME
224 enable_mmap_small_discard_ust_channel
$SESSION_NAME $CHANNEL_NAME
225 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
226 start_lttng_tracing_ok
$SESSION_NAME
227 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
229 # Run test apps, wait for them to complete.
233 # Take first snapshot, remember first line.
234 lttng_snapshot_record
$SESSION_NAME
235 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
236 diag
"First line (1st snapshot): $FIRST_LINE"
239 # Run test apps, wait for them to complete.
243 # Take second snapshot, remember first line.
244 lttng_snapshot_record
$SESSION_NAME
245 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
246 diag
"First line (2nd snapshot): $FIRST_LINE_2"
249 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
250 fail
"First snapshot event do not match."
252 pass
"First snapshot event match."
255 stop_lttng_tracing_ok
$SESSION_NAME
256 destroy_lttng_session_ok
$SESSION_NAME
257 taskset
-p $OLDCPUSET $$
1>/dev
/null
2>&1
260 function test_ust_local_snapshot_small_overwrite_buffers
()
264 OLDCPUSET
=$
(taskset
-p $$
)
266 diag
"Test local UST snapshots with small overwrite buffers"
267 taskset
-p 0x1 $$
1>/dev
/null
2>&1 # CPU 0 only
268 create_lttng_session_no_output
$SESSION_NAME
269 enable_mmap_small_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
270 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
271 start_lttng_tracing_ok
$SESSION_NAME
272 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
274 # Run test apps, wait for them to complete.
278 # Take first snapshot, remember first line.
279 lttng_snapshot_record
$SESSION_NAME
280 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
281 diag
"First line (1st snapshot): $FIRST_LINE"
284 # Run test apps, wait for them to complete.
288 # Take second snapshot, remember first line.
289 lttng_snapshot_record
$SESSION_NAME
290 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
291 diag
"First line (2nd snapshot): $FIRST_LINE_2"
294 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
295 pass
"First snapshot event do not match."
297 fail
"First snapshot event match."
300 stop_lttng_tracing_ok
$SESSION_NAME
301 destroy_lttng_session_ok
$SESSION_NAME
302 taskset
-p $OLDCPUSET $$
1>/dev
/null
2>&1
305 function test_ust_local_snapshot_max_size
()
309 page_size
=`getconf PAGE_SIZE`
310 num_cpus
=$
(conf_proc_count
)
312 # The minimum subbuf size is the platform PAGE_SIZE
313 subbuf_size
=$
(($page_size*2))
315 # The minimum size limit is min(subbuf_size) * nb_streams
316 max_size
=$
(($subbuf_size*$num_cpus))
318 diag
"Test local UST snapshots with max size $max_size"
319 create_lttng_session_no_output
$SESSION_NAME
321 enable_mmap_overwrite_subbuf_ust_channel
$SESSION_NAME $CHANNEL_NAME $subbuf_size
323 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
324 start_lttng_tracing_ok
$SESSION_NAME
326 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" "" $max_size
328 # Returns once the application has at least fired ONE tracepoint.
331 lttng_snapshot_record
$SESSION_NAME
334 sum_size_tracefiles
=$
(find $TRACE_PATH -name "${CHANNEL_NAME}_*" \
335 -exec stat
-c '%s' {} \
; |
awk '{s = s + $1}END{print s}')
337 if [ "$sum_size_tracefiles" -gt "$max_size" ]; then
338 fail
"Tracefiles size sum validation"
339 diag
"Tracefiles size sum: $sum_size_tracefiles Expected max: $max_size"
341 pass
"Tracefiles size sum validation"
344 stop_lttng_tracing_ok
$SESSION_NAME
345 destroy_lttng_session_ok
$SESSION_NAME
348 validate_trace
$EVENT_NAME $TRACE_PATH/
350 if [ $?
-eq 0 ]; then
351 # Only delete if successful
358 function test_ust_local_snapshot_large_metadata
()
360 LM_EVENT
="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5"
361 LM_PATH
="$TESTDIR/utils/testapp"
362 LM_NAME
="gen-ust-nevents"
363 LM_BIN
="$LM_PATH/$LM_NAME/$LM_NAME"
365 diag
"Test local UST snapshots with > 4kB metadata"
366 create_lttng_session_no_output
$SESSION_NAME
367 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
368 enable_ust_lttng_event_ok
$SESSION_NAME $LM_EVENT $CHANNEL_NAME
369 start_lttng_tracing_ok
$SESSION_NAME
370 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
372 ok $?
"Start application to trace"
373 lttng_snapshot_record
$SESSION_NAME
374 stop_lttng_tracing_ok
$SESSION_NAME
375 destroy_lttng_session_ok
$SESSION_NAME
378 validate_trace
$LM_EVENT $TRACE_PATH/
379 if [ $?
-eq 0 ]; then
380 # Only delete if successful
385 function enable_channel_per_uid_mmap_overwrite
()
390 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
--buffers-uid -u $channel_name -s $sess_name --output mmap
--overwrite >/dev
/null
2>&1
391 ok $?
"Enable channel $channel_name per UID for session $sess_name"
394 function test_ust_per_uid_local_snapshot
()
398 diag
"Test per-uid local UST snapshots"
399 create_lttng_session_no_output
$SESSION_NAME
400 enable_channel_per_uid_mmap_overwrite
$SESSION_NAME $CHANNEL_NAME
401 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
402 start_lttng_tracing_ok
$SESSION_NAME
403 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
405 # Returns once the application has at least fired ONE tracepoint.
408 lttng_snapshot_record
$SESSION_NAME
409 stop_lttng_tracing_ok
$SESSION_NAME
410 destroy_lttng_session_ok
$SESSION_NAME
413 validate_trace
$EVENT_NAME $TRACE_PATH/
414 if [ $?
-eq 0 ]; then
415 # Only delete if successful
422 function test_ust_per_uid_local_snapshot_post_mortem
()
427 diag
"Test local UST snapshots post-mortem"
428 create_lttng_session_no_output
$SESSION_NAME
429 enable_channel_per_uid_mmap_overwrite
$SESSION_NAME $CHANNEL_NAME
430 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
431 start_lttng_tracing_ok
$SESSION_NAME
432 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
434 # Returns once the application has at least fired ONE tracepoint.
438 lttng_snapshot_record
$SESSION_NAME
439 stop_lttng_tracing_ok
$SESSION_NAME
440 destroy_lttng_session_ok
$SESSION_NAME
443 validate_trace
$EVENT_NAME $TRACE_PATH/
444 if [ $?
-eq 0 ]; then
445 # Only delete if successful
450 function test_ust_local_snapshots
()
455 diag
"Test $NR_SNAPSHOT local UST snapshots"
456 create_lttng_session_no_output
$SESSION_NAME
457 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
458 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
459 start_lttng_tracing_ok
$SESSION_NAME
460 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
462 # Returns once the application has at least fired ONE tracepoint.
465 for i
in $
(seq 1 $NR_SNAPSHOT); do
466 diag
"Snapshot $i/$NR_SNAPSHOT"
467 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
468 lttng_snapshot_record
$SESSION_NAME
470 validate_trace
$EVENT_NAME $TRACE_PATH/
471 if [ $?
-eq 0 ]; then
472 # Only delete if successful
476 stop_lttng_tracing_ok
$SESSION_NAME
477 destroy_lttng_session_ok
$SESSION_NAME
482 plan_tests
$NUM_TESTS
484 print_test_banner
"$TEST_DESC"
487 tests
=( test_ust_list_output
488 test_ust_local_snapshot
489 test_ust_local_snapshot_max_size
490 test_ust_per_uid_local_snapshot
491 test_ust_per_uid_local_snapshot_post_mortem
492 test_ust_local_snapshot_large_metadata
493 test_ust_local_snapshots
494 test_ust_local_snapshot_small_discard_buffers
495 test_ust_local_snapshot_small_overwrite_buffers
498 for fct_test
in ${tests[@]};
500 SESSION_NAME
=$
(randstring
16 0)