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")
162 diag
"Test UST snapshot output listing"
163 create_lttng_session_no_output
$SESSION_NAME
164 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
165 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
167 start_lttng_tracing_ok
$SESSION_NAME
169 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" ${output_names[0]}
171 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output \
172 -s $SESSION_NAME 2>&1 |
grep ${output_names[0]} > /dev
/null
173 ok $?
"Snapshot named ${output_names[0]} present in list-output listing"
175 snapshot_del_output
$SESSION_NAME ${output_names[0]}
177 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" ${output_names[1]}
179 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output \
180 -s $SESSION_NAME 2>&1 |
grep ${output_names[1]} > /dev
/null
182 ok $?
"Snapshot named ${output_names[1]} present in list-output listing"
184 stop_lttng_tracing_ok
$SESSION_NAME
185 destroy_lttng_session_ok
$SESSION_NAME
188 function test_ust_local_snapshot
()
193 diag
"Test local UST snapshots"
194 create_lttng_session_no_output
$SESSION_NAME
195 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
196 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
197 start_lttng_tracing_ok
$SESSION_NAME
198 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
200 # Returns once the application has at least fired ONE tracepoint.
203 lttng_snapshot_record
$SESSION_NAME
204 stop_lttng_tracing_ok
$SESSION_NAME
205 destroy_lttng_session_ok
$SESSION_NAME
208 validate_trace
$EVENT_NAME $TRACE_PATH/
209 if [ $?
-eq 0 ]; then
210 # Only delete if successful
217 function test_ust_local_snapshot_small_discard_buffers
()
221 OLDCPUSET
=$
(taskset
-p $$
)
223 diag
"Test local UST snapshots with small discard buffers"
224 taskset
-p 0x1 $$
1>/dev
/null
2>&1 # CPU 0 only
225 create_lttng_session_no_output
$SESSION_NAME
226 enable_mmap_small_discard_ust_channel
$SESSION_NAME $CHANNEL_NAME
227 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
228 start_lttng_tracing_ok
$SESSION_NAME
229 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
231 # Run test apps, wait for them to complete.
235 # Take first snapshot, remember first line.
236 lttng_snapshot_record
$SESSION_NAME
237 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
238 diag
"First line (1st snapshot): $FIRST_LINE"
241 # Run test apps, wait for them to complete.
245 # Take second snapshot, remember first line.
246 lttng_snapshot_record
$SESSION_NAME
247 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
248 diag
"First line (2nd snapshot): $FIRST_LINE_2"
251 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
252 fail
"First snapshot event do not match."
254 pass
"First snapshot event match."
257 stop_lttng_tracing_ok
$SESSION_NAME
258 destroy_lttng_session_ok
$SESSION_NAME
259 taskset
-p $OLDCPUSET $$
1>/dev
/null
2>&1
262 function test_ust_local_snapshot_small_overwrite_buffers
()
266 OLDCPUSET
=$
(taskset
-p $$
)
268 diag
"Test local UST snapshots with small overwrite buffers"
269 taskset
-p 0x1 $$
1>/dev
/null
2>&1 # CPU 0 only
270 create_lttng_session_no_output
$SESSION_NAME
271 enable_mmap_small_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
272 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
273 start_lttng_tracing_ok
$SESSION_NAME
274 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
276 # Run test apps, wait for them to complete.
280 # Take first snapshot, remember first line.
281 lttng_snapshot_record
$SESSION_NAME
282 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
283 diag
"First line (1st snapshot): $FIRST_LINE"
286 # Run test apps, wait for them to complete.
290 # Take second snapshot, remember first line.
291 lttng_snapshot_record
$SESSION_NAME
292 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
293 diag
"First line (2nd snapshot): $FIRST_LINE_2"
296 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
297 pass
"First snapshot event do not match."
299 fail
"First snapshot event match."
302 stop_lttng_tracing_ok
$SESSION_NAME
303 destroy_lttng_session_ok
$SESSION_NAME
304 taskset
-p $OLDCPUSET $$
1>/dev
/null
2>&1
307 function test_ust_local_snapshot_max_size
()
311 page_size
=`getconf PAGE_SIZE`
312 num_cpus
=$
(conf_proc_count
)
314 # The minimum subbuf size is the platform PAGE_SIZE
315 subbuf_size
=$
(($page_size*2))
317 # The minimum size limit is min(subbuf_size) * nb_streams
318 max_size
=$
(($subbuf_size*$num_cpus))
320 diag
"Test local UST snapshots with max size $max_size"
321 create_lttng_session_no_output
$SESSION_NAME
323 enable_mmap_overwrite_subbuf_ust_channel
$SESSION_NAME $CHANNEL_NAME $subbuf_size
325 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
326 start_lttng_tracing_ok
$SESSION_NAME
328 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" "" $max_size
330 # Returns once the application has at least fired ONE tracepoint.
333 lttng_snapshot_record
$SESSION_NAME
336 sum_size_tracefiles
=$
(find $TRACE_PATH -name "${CHANNEL_NAME}_*" \
337 -exec stat
-c '%s' {} \
; |
awk '{s = s + $1}END{print s}')
339 if [ "$sum_size_tracefiles" -gt "$max_size" ]; then
340 fail
"Tracefiles size sum validation"
341 diag
"Tracefiles size sum: $sum_size_tracefiles Expected max: $max_size"
344 pass
"Tracefiles size sum validation"
346 stop_lttng_tracing_ok
$SESSION_NAME
347 destroy_lttng_session_ok
$SESSION_NAME
350 validate_trace
$EVENT_NAME $TRACE_PATH/
352 if [ $?
-eq 0 ]; then
353 # Only delete if successful
360 function test_ust_local_snapshot_large_metadata
()
364 LM_EVENT
="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5"
365 LM_PATH
="$TESTDIR/utils/testapp"
366 LM_NAME
="gen-ust-nevents"
367 LM_BIN
="$LM_PATH/$LM_NAME/$LM_NAME"
369 diag
"Test local UST snapshots with > 4kB metadata"
370 create_lttng_session_no_output
$SESSION_NAME
371 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
372 enable_ust_lttng_event_ok
$SESSION_NAME $LM_EVENT $CHANNEL_NAME
373 start_lttng_tracing_ok
$SESSION_NAME
374 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
376 ok $?
"Start application to trace"
377 lttng_snapshot_record
$SESSION_NAME
378 stop_lttng_tracing_ok
$SESSION_NAME
379 destroy_lttng_session_ok
$SESSION_NAME
382 validate_trace
$LM_EVENT $TRACE_PATH/
383 if [ $?
-eq 0 ]; then
384 # Only delete if successful
389 function enable_channel_per_uid_mmap_overwrite
()
396 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
--buffers-uid -u $channel_name -s $sess_name --output mmap
--overwrite >/dev
/null
2>&1
397 ok $?
"Enable channel $channel_name per UID for session $sess_name"
400 function test_ust_per_uid_local_snapshot
()
402 diag
"Test per-uid local UST snapshots"
403 create_lttng_session_no_output
$SESSION_NAME
404 enable_channel_per_uid_mmap_overwrite
$SESSION_NAME $CHANNEL_NAME
405 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
406 start_lttng_tracing_ok
$SESSION_NAME
407 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
409 # Returns once the application has at least fired ONE tracepoint.
412 lttng_snapshot_record
$SESSION_NAME
413 stop_lttng_tracing_ok
$SESSION_NAME
414 destroy_lttng_session_ok
$SESSION_NAME
417 validate_trace
$EVENT_NAME $TRACE_PATH/
418 if [ $?
-eq 0 ]; then
419 # Only delete if successful
426 function test_ust_per_uid_local_snapshot_post_mortem
()
431 diag
"Test local UST snapshots post-mortem"
432 create_lttng_session_no_output
$SESSION_NAME
433 enable_channel_per_uid_mmap_overwrite
$SESSION_NAME $CHANNEL_NAME
434 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
435 start_lttng_tracing_ok
$SESSION_NAME
436 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
438 # Returns once the application has at least fired ONE tracepoint.
442 lttng_snapshot_record
$SESSION_NAME
443 stop_lttng_tracing_ok
$SESSION_NAME
444 destroy_lttng_session_ok
$SESSION_NAME
447 validate_trace
$EVENT_NAME $TRACE_PATH/
448 if [ $?
-eq 0 ]; then
449 # Only delete if successful
454 function test_ust_local_snapshots
()
459 diag
"Test $NR_SNAPSHOT local UST snapshots"
460 create_lttng_session_no_output
$SESSION_NAME
461 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
462 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
463 start_lttng_tracing_ok
$SESSION_NAME
464 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
466 # Returns once the application has at least fired ONE tracepoint.
469 for i
in $
(seq 1 $NR_SNAPSHOT); do
470 diag
"Snapshot $i/$NR_SNAPSHOT"
471 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
472 lttng_snapshot_record
$SESSION_NAME
474 validate_trace
$EVENT_NAME $TRACE_PATH/
475 if [ $?
-eq 0 ]; then
476 # Only delete if successful
480 stop_lttng_tracing_ok
$SESSION_NAME
481 destroy_lttng_session_ok
$SESSION_NAME
486 plan_tests
$NUM_TESTS
488 print_test_banner
"$TEST_DESC"
491 tests
=( test_ust_list_output
492 test_ust_local_snapshot
493 test_ust_local_snapshot_max_size
494 test_ust_per_uid_local_snapshot
495 test_ust_per_uid_local_snapshot_post_mortem
496 test_ust_local_snapshot_large_metadata
497 test_ust_local_snapshots
498 test_ust_local_snapshot_small_discard_buffers
499 test_ust_local_snapshot_small_overwrite_buffers
502 for fct_test
in ${tests[@]};
504 SESSION_NAME
=$
(randstring
16 0)