3 # Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 TEST_DESC
="Snapshots - UST tracing"
10 TESTDIR
=$CURDIR/..
/..
/..
11 EVENT_NAME
="tp:tptest"
13 CHANNEL_NAME
="snapchan"
14 TESTAPP_PATH
="$TESTDIR/utils/testapp"
15 TESTAPP_NAME
="gen-ust-events"
16 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
21 TRACE_PATH
=$
(mktemp
-d)
23 source $TESTDIR/utils
/utils.sh
25 if [ ! -x "$TESTAPP_BIN" ]; then
26 BAIL_OUT
"No UST events binary detected."
29 # Need the number of snapshot to do.
31 BAIL_OUT
"A number of snapshot is needed."
35 NUM_TESTS
=$
(($NUM_TESTS + ($NR_SNAPSHOT * 3)))
37 function start_test_app
()
39 local tmp_file
=$
(mktemp
-u)
41 # Start application with a temporary file.
42 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event $tmp_file &
44 APPS_PID
="${APPS_PID} ${!}"
45 ok
$ret "Start application to trace"
47 # Wait for the application file to appear indicating that at least one
48 # tracepoint has been fired.
49 while [ ! -f "$tmp_file" ]; do
52 diag
"Removing test app temporary file $tmp_file"
56 function wait_test_apps
()
58 diag
"Waiting for $TESTAPP_NAME"
59 for p
in ${APPS_PID}; do
64 function stop_test_apps
()
66 diag
"Stopping $TESTAPP_NAME"
67 for p
in ${APPS_PID}; do
74 function snapshot_add_output
()
82 if [ ! -z $name ]; then
83 extra_opt
+=" -n $name "
86 if [ ! -z $max_size ]; then
87 extra_opt
+=" -m $max_size "
90 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output \
91 -s $sess_name $extra_opt $trace_path > /dev
/null
2>&1
93 ok $?
"Added snapshot output $trace_path ($extra_opt)"
96 function snapshot_del_output
()
101 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output \
102 -s $sess_name $name > /dev
/null
2>&1
104 ok $?
"Deleted snapshot output named $name"
107 function enable_mmap_overwrite_subbuf_ust_channel
()
113 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name \
114 $chan_name -u --output mmap
--overwrite \
115 --subbuf-size $subbuf_size > /dev
/null
2>&1
117 ok $?
"Enable channel $channel_name for session $sess_name with subbuf size $subbuf_size"
120 function enable_mmap_small_discard_ust_channel
()
125 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name \
126 $chan_name -u --output mmap
--discard \
127 --subbuf-size $
(getconf PAGE_SIZE
) --num-subbuf 2 \
130 ok $?
"Enable channel $channel_name for session $sess_name with small discard buffers"
133 function enable_mmap_small_overwrite_ust_channel
()
138 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name \
139 $chan_name -u --output mmap
--overwrite \
140 --subbuf-size $
(getconf PAGE_SIZE
) --num-subbuf 2 \
143 ok $?
"Enable channel $channel_name for session $sess_name with small discard buffers"
146 function test_ust_list_output
()
148 output_names
=("randomname" "somesnapshot")
150 diag
"Test UST snapshot output listing"
151 create_lttng_session_no_output
$SESSION_NAME
152 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
153 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
155 start_lttng_tracing_ok
$SESSION_NAME
157 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" ${output_names[0]}
159 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output \
160 -s $SESSION_NAME 2>&1 |
grep ${output_names[0]} > /dev
/null
161 ok $?
"Snapshot named ${output_names[0]} present in list-output listing"
163 snapshot_del_output
$SESSION_NAME ${output_names[0]}
165 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" ${output_names[1]}
167 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output \
168 -s $SESSION_NAME 2>&1 |
grep ${output_names[1]} > /dev
/null
170 ok $?
"Snapshot named ${output_names[1]} present in list-output listing"
172 stop_lttng_tracing_ok
$SESSION_NAME
173 destroy_lttng_session_ok
$SESSION_NAME
176 function test_ust_local_snapshot
()
181 diag
"Test local UST snapshots"
182 create_lttng_session_no_output
$SESSION_NAME
183 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
184 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
185 start_lttng_tracing_ok
$SESSION_NAME
186 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
188 # Returns once the application has at least fired ONE tracepoint.
191 lttng_snapshot_record
$SESSION_NAME
192 stop_lttng_tracing_ok
$SESSION_NAME
193 destroy_lttng_session_ok
$SESSION_NAME
196 validate_trace_path_ust_uid_snapshot
"$TRACE_PATH" "" "snapshot-1" 0
197 validate_trace
$EVENT_NAME $TRACE_PATH/
198 if [ $?
-eq 0 ]; then
199 # Only delete if successful
206 function test_ust_local_snapshot_small_discard_buffers
()
210 OLDCPUSET
=$
(taskset
-p $$
)
212 diag
"Test local UST snapshots with small discard buffers"
213 taskset
-p 0x1 $$
1>/dev
/null
2>&1 # CPU 0 only
214 create_lttng_session_no_output
$SESSION_NAME
215 enable_mmap_small_discard_ust_channel
$SESSION_NAME $CHANNEL_NAME
216 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
217 start_lttng_tracing_ok
$SESSION_NAME
218 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
220 # Run test apps, wait for them to complete.
224 # Take first snapshot, remember first line.
225 lttng_snapshot_record
$SESSION_NAME
226 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
227 diag
"First line (1st snapshot): $FIRST_LINE"
230 # Run test apps, wait for them to complete.
234 # Take second snapshot, remember first line.
235 lttng_snapshot_record
$SESSION_NAME
236 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
237 diag
"First line (2nd snapshot): $FIRST_LINE_2"
240 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
241 fail
"First snapshot event do not match."
243 pass
"First snapshot event match."
246 stop_lttng_tracing_ok
$SESSION_NAME
247 destroy_lttng_session_ok
$SESSION_NAME
248 taskset
-p $OLDCPUSET $$
1>/dev
/null
2>&1
251 function test_ust_local_snapshot_small_overwrite_buffers
()
255 OLDCPUSET
=$
(taskset
-p $$
)
257 diag
"Test local UST snapshots with small overwrite buffers"
258 taskset
-p 0x1 $$
1>/dev
/null
2>&1 # CPU 0 only
259 create_lttng_session_no_output
$SESSION_NAME
260 enable_mmap_small_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
261 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
262 start_lttng_tracing_ok
$SESSION_NAME
263 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
265 # Run test apps, wait for them to complete.
269 # Take first snapshot, remember first line.
270 lttng_snapshot_record
$SESSION_NAME
271 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
272 diag
"First line (1st snapshot): $FIRST_LINE"
275 # Run test apps, wait for them to complete.
279 # Take second snapshot, remember first line.
280 lttng_snapshot_record
$SESSION_NAME
281 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
282 diag
"First line (2nd snapshot): $FIRST_LINE_2"
285 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
286 pass
"First snapshot event do not match."
288 fail
"First snapshot event match."
291 stop_lttng_tracing_ok
$SESSION_NAME
292 destroy_lttng_session_ok
$SESSION_NAME
293 taskset
-p $OLDCPUSET $$
1>/dev
/null
2>&1
296 function test_ust_local_snapshot_max_size
()
300 page_size
=`getconf PAGE_SIZE`
301 num_cpus
=$
(conf_proc_count
)
303 # The minimum subbuf size is the platform PAGE_SIZE
304 subbuf_size
=$
(($page_size*2))
306 # The minimum size limit is min(subbuf_size) * nb_streams
307 max_size
=$
(($subbuf_size*$num_cpus))
309 diag
"Test local UST snapshots with max size $max_size"
310 create_lttng_session_no_output
$SESSION_NAME
312 enable_mmap_overwrite_subbuf_ust_channel
$SESSION_NAME $CHANNEL_NAME $subbuf_size
314 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
315 start_lttng_tracing_ok
$SESSION_NAME
317 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" "" $max_size
319 # Returns once the application has at least fired ONE tracepoint.
322 lttng_snapshot_record
$SESSION_NAME
325 sum_size_tracefiles
=$
(find $TRACE_PATH -name "${CHANNEL_NAME}_*" \
326 -exec stat
-c '%s' {} \
; |
awk '{s = s + $1}END{print s}')
328 if [ "$sum_size_tracefiles" -gt "$max_size" ]; then
329 fail
"Tracefiles size sum validation"
330 diag
"Tracefiles size sum: $sum_size_tracefiles Expected max: $max_size"
332 pass
"Tracefiles size sum validation"
335 stop_lttng_tracing_ok
$SESSION_NAME
336 destroy_lttng_session_ok
$SESSION_NAME
339 validate_trace_path_ust_uid_snapshot
"$TRACE_PATH" "" "snapshot-1" 0
340 validate_trace
$EVENT_NAME $TRACE_PATH/
342 if [ $?
-eq 0 ]; then
343 # Only delete if successful
350 function test_ust_local_snapshot_large_metadata
()
352 LM_EVENT
="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5"
353 LM_PATH
="$TESTDIR/utils/testapp"
354 LM_NAME
="gen-ust-nevents"
355 LM_BIN
="$LM_PATH/$LM_NAME/$LM_NAME"
357 diag
"Test local UST snapshots with > 4kB metadata"
358 create_lttng_session_no_output
$SESSION_NAME
359 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
360 enable_ust_lttng_event_ok
$SESSION_NAME $LM_EVENT $CHANNEL_NAME
361 start_lttng_tracing_ok
$SESSION_NAME
362 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
363 $LM_BIN --iter 1 --wait 1
364 ok $?
"Start application to trace"
365 lttng_snapshot_record
$SESSION_NAME
366 stop_lttng_tracing_ok
$SESSION_NAME
367 destroy_lttng_session_ok
$SESSION_NAME
370 validate_trace_path_ust_uid_snapshot
"$TRACE_PATH" "" "snapshot-1" 0
371 validate_trace
$LM_EVENT $TRACE_PATH/
372 if [ $?
-eq 0 ]; then
373 # Only delete if successful
378 function enable_channel_per_uid_mmap_overwrite
()
383 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
--buffers-uid -u $channel_name -s $sess_name --output mmap
--overwrite >/dev
/null
2>&1
384 ok $?
"Enable channel $channel_name per UID for session $sess_name"
387 function test_ust_per_uid_local_snapshot
()
391 diag
"Test per-uid local UST snapshots"
392 create_lttng_session_no_output
$SESSION_NAME
393 enable_channel_per_uid_mmap_overwrite
$SESSION_NAME $CHANNEL_NAME
394 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
395 start_lttng_tracing_ok
$SESSION_NAME
396 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
398 # Returns once the application has at least fired ONE tracepoint.
401 lttng_snapshot_record
$SESSION_NAME
402 stop_lttng_tracing_ok
$SESSION_NAME
403 destroy_lttng_session_ok
$SESSION_NAME
406 validate_trace_path_ust_uid_snapshot
"$TRACE_PATH" "" "snapshot-1" 0
407 validate_trace
$EVENT_NAME $TRACE_PATH/
408 if [ $?
-eq 0 ]; then
409 # Only delete if successful
416 function test_ust_per_uid_local_snapshot_post_mortem
()
421 diag
"Test local UST snapshots post-mortem"
422 create_lttng_session_no_output
$SESSION_NAME
423 enable_channel_per_uid_mmap_overwrite
$SESSION_NAME $CHANNEL_NAME
424 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
425 start_lttng_tracing_ok
$SESSION_NAME
426 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
428 # Returns once the application has at least fired ONE tracepoint.
432 lttng_snapshot_record
$SESSION_NAME
433 stop_lttng_tracing_ok
$SESSION_NAME
434 destroy_lttng_session_ok
$SESSION_NAME
437 validate_trace_path_ust_uid_snapshot
"$TRACE_PATH" "" "snapshot-1" 0
438 validate_trace
$EVENT_NAME $TRACE_PATH/
439 if [ $?
-eq 0 ]; then
440 # Only delete if successful
445 function test_ust_local_snapshots
()
450 diag
"Test $NR_SNAPSHOT local UST snapshots"
451 create_lttng_session_no_output
$SESSION_NAME
452 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
453 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
454 start_lttng_tracing_ok
$SESSION_NAME
455 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
457 # Returns once the application has at least fired ONE tracepoint.
460 for i
in $
(seq 1 $NR_SNAPSHOT); do
461 diag
"Snapshot $i/$NR_SNAPSHOT"
462 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
463 lttng_snapshot_record
$SESSION_NAME
465 validate_trace_path_ust_uid_snapshot
"$TRACE_PATH" "" "snapshot-1" $
((i
- 1))
466 validate_trace
$EVENT_NAME $TRACE_PATH/
467 if [ $?
-eq 0 ]; then
468 # Only delete if successful
472 stop_lttng_tracing_ok
$SESSION_NAME
473 destroy_lttng_session_ok
$SESSION_NAME
478 plan_tests
$NUM_TESTS
480 print_test_banner
"$TEST_DESC"
483 tests
=( test_ust_list_output
484 test_ust_local_snapshot
485 test_ust_local_snapshot_max_size
486 test_ust_per_uid_local_snapshot
487 test_ust_per_uid_local_snapshot_post_mortem
488 test_ust_local_snapshot_large_metadata
489 test_ust_local_snapshots
490 test_ust_local_snapshot_small_discard_buffers
491 test_ust_local_snapshot_small_overwrite_buffers
494 for fct_test
in ${tests[@]};
496 SESSION_NAME
=$
(randstring
16 0)