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 * 2)))
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
$EVENT_NAME $TRACE_PATH/
197 if [ $?
-eq 0 ]; then
198 # Only delete if successful
205 function test_ust_local_snapshot_small_discard_buffers
()
209 OLDCPUSET
=$
(taskset
-p $$
)
211 diag
"Test local UST snapshots with small discard buffers"
212 taskset
-p 0x1 $$
1>/dev
/null
2>&1 # CPU 0 only
213 create_lttng_session_no_output
$SESSION_NAME
214 enable_mmap_small_discard_ust_channel
$SESSION_NAME $CHANNEL_NAME
215 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
216 start_lttng_tracing_ok
$SESSION_NAME
217 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
219 # Run test apps, wait for them to complete.
223 # Take first snapshot, remember first line.
224 lttng_snapshot_record
$SESSION_NAME
225 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
226 diag
"First line (1st snapshot): $FIRST_LINE"
229 # Run test apps, wait for them to complete.
233 # Take second snapshot, remember first line.
234 lttng_snapshot_record
$SESSION_NAME
235 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
236 diag
"First line (2nd snapshot): $FIRST_LINE_2"
239 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
240 fail
"First snapshot event do not match."
242 pass
"First snapshot event match."
245 stop_lttng_tracing_ok
$SESSION_NAME
246 destroy_lttng_session_ok
$SESSION_NAME
247 taskset
-p $OLDCPUSET $$
1>/dev
/null
2>&1
250 function test_ust_local_snapshot_small_overwrite_buffers
()
254 OLDCPUSET
=$
(taskset
-p $$
)
256 diag
"Test local UST snapshots with small overwrite buffers"
257 taskset
-p 0x1 $$
1>/dev
/null
2>&1 # CPU 0 only
258 create_lttng_session_no_output
$SESSION_NAME
259 enable_mmap_small_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
260 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
261 start_lttng_tracing_ok
$SESSION_NAME
262 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
264 # Run test apps, wait for them to complete.
268 # Take first snapshot, remember first line.
269 lttng_snapshot_record
$SESSION_NAME
270 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
271 diag
"First line (1st snapshot): $FIRST_LINE"
274 # Run test apps, wait for them to complete.
278 # Take second snapshot, remember first line.
279 lttng_snapshot_record
$SESSION_NAME
280 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
281 diag
"First line (2nd snapshot): $FIRST_LINE_2"
284 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
285 pass
"First snapshot event do not match."
287 fail
"First snapshot event match."
290 stop_lttng_tracing_ok
$SESSION_NAME
291 destroy_lttng_session_ok
$SESSION_NAME
292 taskset
-p $OLDCPUSET $$
1>/dev
/null
2>&1
295 function test_ust_local_snapshot_max_size
()
299 page_size
=`getconf PAGE_SIZE`
300 num_cpus
=$
(conf_proc_count
)
302 # The minimum subbuf size is the platform PAGE_SIZE
303 subbuf_size
=$
(($page_size*2))
305 # The minimum size limit is min(subbuf_size) * nb_streams
306 max_size
=$
(($subbuf_size*$num_cpus))
308 diag
"Test local UST snapshots with max size $max_size"
309 create_lttng_session_no_output
$SESSION_NAME
311 enable_mmap_overwrite_subbuf_ust_channel
$SESSION_NAME $CHANNEL_NAME $subbuf_size
313 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
314 start_lttng_tracing_ok
$SESSION_NAME
316 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" "" $max_size
318 # Returns once the application has at least fired ONE tracepoint.
321 lttng_snapshot_record
$SESSION_NAME
324 sum_size_tracefiles
=$
(find $TRACE_PATH -name "${CHANNEL_NAME}_*" \
325 -exec stat
-c '%s' {} \
; |
awk '{s = s + $1}END{print s}')
327 if [ "$sum_size_tracefiles" -gt "$max_size" ]; then
328 fail
"Tracefiles size sum validation"
329 diag
"Tracefiles size sum: $sum_size_tracefiles Expected max: $max_size"
331 pass
"Tracefiles size sum validation"
334 stop_lttng_tracing_ok
$SESSION_NAME
335 destroy_lttng_session_ok
$SESSION_NAME
338 validate_trace
$EVENT_NAME $TRACE_PATH/
340 if [ $?
-eq 0 ]; then
341 # Only delete if successful
348 function test_ust_local_snapshot_large_metadata
()
350 LM_EVENT
="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5"
351 LM_PATH
="$TESTDIR/utils/testapp"
352 LM_NAME
="gen-ust-nevents"
353 LM_BIN
="$LM_PATH/$LM_NAME/$LM_NAME"
355 diag
"Test local UST snapshots with > 4kB metadata"
356 create_lttng_session_no_output
$SESSION_NAME
357 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
358 enable_ust_lttng_event_ok
$SESSION_NAME $LM_EVENT $CHANNEL_NAME
359 start_lttng_tracing_ok
$SESSION_NAME
360 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
361 $LM_BIN --iter 1 --wait 1
362 ok $?
"Start application to trace"
363 lttng_snapshot_record
$SESSION_NAME
364 stop_lttng_tracing_ok
$SESSION_NAME
365 destroy_lttng_session_ok
$SESSION_NAME
368 validate_trace
$LM_EVENT $TRACE_PATH/
369 if [ $?
-eq 0 ]; then
370 # Only delete if successful
375 function enable_channel_per_uid_mmap_overwrite
()
380 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
--buffers-uid -u $channel_name -s $sess_name --output mmap
--overwrite >/dev
/null
2>&1
381 ok $?
"Enable channel $channel_name per UID for session $sess_name"
384 function test_ust_per_uid_local_snapshot
()
388 diag
"Test per-uid local UST snapshots"
389 create_lttng_session_no_output
$SESSION_NAME
390 enable_channel_per_uid_mmap_overwrite
$SESSION_NAME $CHANNEL_NAME
391 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
392 start_lttng_tracing_ok
$SESSION_NAME
393 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
395 # Returns once the application has at least fired ONE tracepoint.
398 lttng_snapshot_record
$SESSION_NAME
399 stop_lttng_tracing_ok
$SESSION_NAME
400 destroy_lttng_session_ok
$SESSION_NAME
403 validate_trace
$EVENT_NAME $TRACE_PATH/
404 if [ $?
-eq 0 ]; then
405 # Only delete if successful
412 function test_ust_per_uid_local_snapshot_post_mortem
()
417 diag
"Test local UST snapshots post-mortem"
418 create_lttng_session_no_output
$SESSION_NAME
419 enable_channel_per_uid_mmap_overwrite
$SESSION_NAME $CHANNEL_NAME
420 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
421 start_lttng_tracing_ok
$SESSION_NAME
422 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
424 # Returns once the application has at least fired ONE tracepoint.
428 lttng_snapshot_record
$SESSION_NAME
429 stop_lttng_tracing_ok
$SESSION_NAME
430 destroy_lttng_session_ok
$SESSION_NAME
433 validate_trace
$EVENT_NAME $TRACE_PATH/
434 if [ $?
-eq 0 ]; then
435 # Only delete if successful
440 function test_ust_local_snapshots
()
445 diag
"Test $NR_SNAPSHOT local UST snapshots"
446 create_lttng_session_no_output
$SESSION_NAME
447 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
448 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
449 start_lttng_tracing_ok
$SESSION_NAME
450 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
452 # Returns once the application has at least fired ONE tracepoint.
455 for i
in $
(seq 1 $NR_SNAPSHOT); do
456 diag
"Snapshot $i/$NR_SNAPSHOT"
457 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
458 lttng_snapshot_record
$SESSION_NAME
460 validate_trace
$EVENT_NAME $TRACE_PATH/
461 if [ $?
-eq 0 ]; then
462 # Only delete if successful
466 stop_lttng_tracing_ok
$SESSION_NAME
467 destroy_lttng_session_ok
$SESSION_NAME
472 plan_tests
$NUM_TESTS
474 print_test_banner
"$TEST_DESC"
477 tests
=( test_ust_list_output
478 test_ust_local_snapshot
479 test_ust_local_snapshot_max_size
480 test_ust_per_uid_local_snapshot
481 test_ust_per_uid_local_snapshot_post_mortem
482 test_ust_local_snapshot_large_metadata
483 test_ust_local_snapshots
484 test_ust_local_snapshot_small_discard_buffers
485 test_ust_local_snapshot_small_overwrite_buffers
488 for fct_test
in ${tests[@]};
490 SESSION_NAME
=$
(randstring
16 0)