3 # Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 TEST_DESC
="Clear - UST tracing"
10 TESTDIR
=$CURDIR/..
/..
/..
11 EVENT_NAME
="tp:tptest"
12 EVENT_STATE_DUMP_START
="lttng_ust_statedump:start"
13 EVENT_STATE_DUMP_END
="lttng_ust_statedump:end"
15 TESTAPP_PATH
="$TESTDIR/utils/testapp"
16 TESTAPP_NAME
="gen-ust-events"
17 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
21 LIVEVIEWER_TIMEOUT
=10 # Timeout in seconds
22 PAGE_SIZE
=$
(getconf PAGE_SIZE
)
23 TRACE_PATH
=$
(mktemp
-d -t tmp.test_clear_ust_trace_path.XXXXXX
)
25 # shellcheck source=../utils/utils.sh
26 source "$TESTDIR/utils/utils.sh"
28 if [ ! -x "$TESTAPP_BIN" ]; then
29 BAIL_OUT
"No UST events binary detected."
32 function clean_path
()
40 function cond_start_tracing
()
43 local tracing_active
=$2
45 if [[ $tracing_active -ne 1 ]]; then
46 start_lttng_tracing_ok
$session_name
50 function cond_stop_tracing
()
53 local tracing_active
=$2
55 if [[ $tracing_active -ne 1 ]]; then
56 stop_lttng_tracing_ok
$session_name
60 function do_clear_session
()
63 local tracing_active
=$2
65 local rotate_before
=$4
68 cond_stop_tracing
$session_name $tracing_active
69 if [[ $rotate_before -eq 1 ]]; then
70 rotate_session_ok
$SESSION_NAME
72 lttng_clear_session_ok
$SESSION_NAME
73 if [[ $clear_twice -eq 1 ]]; then
74 lttng_clear_session_ok
$SESSION_NAME
76 if [[ $rotate_after -eq 1 ]]; then
77 if [[ $tracing_active -eq 1 ]]; then
78 rotate_session_ok
$SESSION_NAME
81 rotate_session_fail
$SESSION_NAME
84 cond_start_tracing
$session_name $tracing_active
87 function test_ust_streaming
()
89 local tracing_active
=$1
91 local rotate_before
=$3
94 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
95 local channel_name
="chan"
97 diag
"Test ust streaming clear"
98 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
99 create_lttng_session_uri
$SESSION_NAME net
://localhost
100 enable_ust_lttng_channel_ok
$SESSION_NAME $channel_name --buffers-$buffer_type
101 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
102 start_lttng_tracing_ok
$SESSION_NAME
104 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
105 stop_lttng_tracing_ok
$SESSION_NAME
107 if [[ $rotate_before -eq 1 ]]; then
108 validate_trace_count
$EVENT_NAME $local_path 10
110 if [[ "$buffer_type" == "uid" ]]; then
111 validate_trace_empty
$local_path
113 validate_directory_empty
$local_path
117 destroy_lttng_session_ok
$SESSION_NAME --no-wait
120 function test_ust_streaming_no_event
()
122 local tracing_active
=$1
124 #local rotate_before=$3 ignored
125 #local rotate_after=$4
126 local buffer_type
=uid
127 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
128 local channel_name
="chan"
130 diag
"Test ust streaming clear no event"
131 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
132 create_lttng_session_uri
$SESSION_NAME net
://localhost
133 enable_ust_lttng_channel_ok
$SESSION_NAME $channel_name --buffers-$buffer_type
134 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
135 start_lttng_tracing_ok
$SESSION_NAME
137 do_clear_session
$SESSION_NAME "$tracing_active" "$clear_twice" "$rotate_before" "$rotate_after"
138 stop_lttng_tracing_ok
$SESSION_NAME
140 validate_directory_empty
"$local_path"
142 destroy_lttng_session_ok
$SESSION_NAME --no-wait
145 function test_ust_streaming_rotate_clear
()
147 local tracing_active
=$1
149 local rotate_before
=$3
150 local rotate_after
=$4
152 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
153 local channel_name
="chan"
155 diag
"Test ust streaming rotate-clear"
156 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
157 create_lttng_session_uri
$SESSION_NAME net
://localhost
158 enable_ust_lttng_channel_ok
$SESSION_NAME $channel_name --buffers-$buffer_type
159 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
160 start_lttng_tracing_ok
$SESSION_NAME
162 rotate_session_ok
$SESSION_NAME
164 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
166 stop_lttng_tracing_ok
$SESSION_NAME
168 if [[ $rotate_before -eq 1 ]]; then
173 validate_trace_count
$EVENT_NAME $local_path $expect_count
175 destroy_lttng_session_ok
$SESSION_NAME --no-wait
178 function test_ust_streaming_clear_rotate
()
180 local tracing_active
=$1
182 local rotate_before
=$3
183 local rotate_after
=$4
185 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
186 local channel_name
="chan"
188 diag
"Test ust streaming clear-rotate"
189 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
190 create_lttng_session_uri
$SESSION_NAME net
://localhost
191 enable_ust_lttng_channel_ok
$SESSION_NAME $channel_name --buffers-$buffer_type
192 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
193 start_lttng_tracing_ok
$SESSION_NAME
195 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
197 rotate_session_ok
$SESSION_NAME
199 stop_lttng_tracing_ok
$SESSION_NAME
201 if [[ $rotate_before -eq 1 ]]; then
206 validate_trace_count
$EVENT_NAME $local_path $expect_count
208 destroy_lttng_session_ok
$SESSION_NAME --no-wait
211 function test_ust_streaming_live
()
213 local tracing_active
=$1
217 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
218 local channel_name
="chan"
220 diag
"Test ust streaming live clear"
221 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type"
222 create_lttng_session_uri
$SESSION_NAME net
://localhost
"--live=${DELAYUS}"
223 enable_ust_lttng_channel_ok
$SESSION_NAME $channel_name --buffers-$buffer_type
224 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
225 start_lttng_tracing_ok
$SESSION_NAME
227 do_clear_session
$SESSION_NAME $tracing_active $clear_twice 0 0
228 stop_lttng_tracing_ok
$SESSION_NAME
230 if [[ "$buffer_type" == "uid" ]]; then
231 validate_trace_empty
$local_path
233 validate_directory_empty
$local_path
236 destroy_lttng_session_ok
$SESSION_NAME --no-wait
240 function test_ust_basic_streaming_live_viewer
()
242 local tracing_active
=$1
246 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
247 local remote_trace_path
="${HOSTNAME}/${SESSION_NAME}"
248 local channel_name
="chan"
249 local bt_output_path
=$
(mktemp
-u -t tmp.test_
${FUNCNAME[0]}_bt_output_path.XXXXXX
)
250 local bt_error_path
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_bt_error.XXXXXX")
251 local file_sync_before_exit
=$
(mktemp
-u -t tmp.test_
${FUNCNAME[0]}_sync_before_exit.XXXXXX
)
253 diag
"Test ust basic streaming live with viewer"
254 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type"
255 create_lttng_session_uri
$SESSION_NAME net
://localhost
"--live=${DELAYUS}"
256 enable_ust_lttng_channel_ok
$SESSION_NAME $channel_name --buffers-$buffer_type
257 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
258 start_lttng_tracing_ok
$SESSION_NAME
260 wait_live_trace_ready net
://localhost
262 # Connect a live viewer
263 $BABELTRACE_BIN -i lttng-live net
://localhost
/host
/$remote_trace_path --params=session-not-found-action
=end
1> $bt_output_path 2> "${bt_error_path}" &
267 wait_live_viewer_connect net
://localhost
269 $TESTAPP_BIN -i 10 --sync-before-exit $file_sync_before_exit &
272 diag
"Wait until viewer sees all 10 expected events"
274 while [ $evcount -ne 10 ]; do
275 evcount
=$
(cat $bt_output_path |
wc -l)
277 viewer_iter
=$
((viewer_iter
+ 1))
278 if [ "${viewer_iter}" -gt $
((LIVEVIEWER_TIMEOUT
* 10)) ] ; then
282 is
"${evcount}" 10 "Live viewer read $evcount events, expect 10"
284 destroy_lttng_session_ok
$SESSION_NAME --no-wait
285 touch $file_sync_before_exit
286 diag
"Waiting for application to exit"
288 pass
"Wait for application to exit"
289 diag
"Wait for viewer to exit"
291 ok $?
"Babeltrace succeeds"
292 pass
"Wait for viewer to exit"
294 rm -f $bt_output_path
295 clean_path
"${bt_error_path}"
296 rm -f $file_sync_before_exit
299 function test_ust_streaming_live_viewer
()
301 local tracing_active
=$1
305 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
306 local remote_trace_path
="${HOSTNAME}/${SESSION_NAME}"
307 local channel_name
="chan"
308 local bt_output_path
=$
(mktemp
-u -t tmp.test_
${FUNCNAME[0]}_bt_output_path.XXXXXX
)
309 local bt_error_path
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_bt_error.XXXXXX")
311 diag
"Test ust streaming live clear with viewer"
312 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type"
313 create_lttng_session_uri
$SESSION_NAME net
://localhost
"--live=${DELAYUS}"
314 enable_ust_lttng_channel_ok
$SESSION_NAME $channel_name --buffers-$buffer_type
315 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
316 start_lttng_tracing_ok
$SESSION_NAME
318 wait_live_trace_ready net
://localhost
320 # Connect a live viewer
321 $BABELTRACE_BIN -i lttng-live net
://localhost
/host
/$remote_trace_path --params=session-not-found-action
=end
1> $bt_output_path 2> "${bt_error_path}" &
324 wait_live_viewer_connect net
://localhost
327 do_clear_session
$SESSION_NAME $tracing_active $clear_twice 0 0
328 stop_lttng_tracing_ok
$SESSION_NAME
330 destroy_lttng_session_ok
$SESSION_NAME --no-wait
331 diag
"Wait for viewer to exit"
333 ok $?
"Babeltrace succeeds"
334 pass
"Wait for viewer to exit"
336 clean_path
$bt_output_path
337 clean_path
"${bt_error_path}"
340 function test_ust_streaming_live_viewer_new_metadata_after_clear
()
342 local tracing_active
=$1
346 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
347 local remote_trace_path
="${HOSTNAME}/${SESSION_NAME}"
348 local channel_name
="chan"
350 local bt_output_path
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_bt_output.XXXXXX")
351 local bt_error_path
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_bt_error.XXXXXX")
352 local file_sync_before_exit
=$
(mktemp
-u -t "tmp.${FUNCNAME[0]}_sync_before_exit.XXXXXX")
354 diag
"Test ust streaming live clear with viewer with new metadata after clear"
355 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type"
356 create_lttng_session_uri
"$SESSION_NAME" net
://localhost
"--live=${DELAYUS}"
357 enable_ust_lttng_channel_ok
"$SESSION_NAME" $channel_name "--buffers-$buffer_type"
359 # The vpid context is added to filter events based on the vpid of the
360 # test application as state dump events are used. Regenerating a
361 # state dump will cause other instrumented application on the system
362 # to trigger a state dump which would throw off checks that rely on an
364 add_context_ust_ok
"$SESSION_NAME" $channel_name "vpid"
365 enable_ust_lttng_event_ok
"$SESSION_NAME" $EVENT_NAME $channel_name
366 start_lttng_tracing_ok
"$SESSION_NAME"
368 wait_live_trace_ready net
://localhost
370 # Connect a live viewer
371 $BABELTRACE_BIN -i lttng-live
"net://localhost/host/$remote_trace_path" --params=session-not-found-action
=end
1> "$bt_output_path" 2> "$bt_error_path" &
375 wait_live_viewer_connect net
://localhost
377 $TESTAPP_BIN -i 10 --sync-before-exit "$file_sync_before_exit" &
380 diag
"Wait until viewer sees all 10 expected events"
382 while [ $evcount -ne 10 ]; do
383 evcount
=$
(wc -l < "$bt_output_path")
385 viewer_iter
=$
((viewer_iter
+ 1))
386 if [ "${viewer_iter}" -gt $
((LIVEVIEWER_TIMEOUT
* 10)) ] ; then
390 is
"${evcount}" 10 "Live viewer read $evcount events, expect 10"
392 do_clear_session
"$SESSION_NAME" "$tracing_active" "$clear_twice" 0 0
394 # Enable new events which will add their descriptions to the metadata
395 # file. This validates that, following a clear, the relay daemon rotates
396 # the metadata viewer stream to the new metadata file.
397 enable_ust_lttng_event_filter
"$SESSION_NAME" $EVENT_STATE_DUMP_START "\$ctx.vpid == $app_pid" $channel_name
398 enable_ust_lttng_event_filter
"$SESSION_NAME" $EVENT_STATE_DUMP_END "\$ctx.vpid == $app_pid" $channel_name
400 # Forcing a state dump to produce the two events enabled above
401 regenerate_statedump_ok
"$SESSION_NAME"
403 diag
"Wait until viewer sees all 12 expected events"
406 while [ $evcount -ne 12 ]; do
407 evcount
=$
(wc -l < "$bt_output_path")
409 viewer_iter
=$
((viewer_iter
+ 1))
410 if [ "${viewer_iter}" -gt $
((LIVEVIEWER_TIMEOUT
* 10)) ]; then
414 is
"${evcount}" 12 "Live viewer read $evcount events, expect 12"
416 stop_lttng_tracing_ok
"$SESSION_NAME"
418 destroy_lttng_session_ok
"$SESSION_NAME" --no-wait
420 touch "$file_sync_before_exit"
421 diag
"Waiting for application to exit"
423 pass
"Wait for application to exit"
425 diag
"Wait for viewer to exit"
427 ok $?
"Babeltrace succeeds"
428 pass
"Wait for viewer to exit"
430 clean_path
"$bt_output_path"
431 clean_path
"$bt_error_path"
432 rm -f "$file_sync_before_exit"
435 function test_ust_local
()
437 local tracing_active
=$1
439 local rotate_before
=$3
440 local rotate_after
=$4
442 local channel_name
="chan"
444 diag
"Test ust local"
445 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
446 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
447 enable_ust_lttng_channel_ok
$SESSION_NAME $channel_name --buffers-$buffer_type
448 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
449 start_lttng_tracing_ok
$SESSION_NAME
451 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
452 stop_lttng_tracing_ok
$SESSION_NAME
454 if [[ $rotate_before -eq 1 ]]; then
455 validate_trace_count
$EVENT_NAME $TRACE_PATH 10
457 if [[ "$buffer_type" == "uid" ]]; then
458 validate_trace_empty
$TRACE_PATH
461 # The sessiond always created a `ust/ directory
462 # whenever the UST domain is active
463 validate_directory_empty
$TRACE_PATH/ust
/
467 destroy_lttng_session_ok
$SESSION_NAME --no-wait
470 function test_ust_local_no_event
()
472 local tracing_active
=$1
474 #local rotate_before=$3 ignored
475 #local rotate_after=$4 ignored
477 local channel_name
="chan"
479 diag
"Test ust local no event"
480 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
481 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
482 enable_ust_lttng_channel_ok
$SESSION_NAME $channel_name "--buffers-$buffer_type"
483 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
484 start_lttng_tracing_ok
$SESSION_NAME
486 do_clear_session
$SESSION_NAME "$tracing_active" "$clear_twice" "$rotate_before" "$rotate_after"
487 stop_lttng_tracing_ok
$SESSION_NAME
489 validate_directory_empty
"$TRACE_PATH"
491 destroy_lttng_session_ok
$SESSION_NAME --no-wait
494 function test_ust_local_rotate_clear
()
496 local tracing_active
=$1
498 local rotate_before
=$3
499 local rotate_after
=$4
501 local channel_name
="chan"
503 diag
"Test ust local rotate-clear"
504 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
505 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
506 enable_ust_lttng_channel_ok
$SESSION_NAME $channel_name --buffers-$buffer_type
507 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
508 start_lttng_tracing_ok
$SESSION_NAME
510 rotate_session_ok
$SESSION_NAME
512 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
514 stop_lttng_tracing_ok
$SESSION_NAME
516 if [[ $rotate_before -eq 1 ]]; then
521 validate_trace_count
$EVENT_NAME $TRACE_PATH $expect_count
523 destroy_lttng_session_ok
$SESSION_NAME --no-wait
526 function test_ust_local_clear_rotate
()
528 local tracing_active
=$1
530 local rotate_before
=$3
531 local rotate_after
=$4
533 local channel_name
="chan"
535 diag
"Test ust local clear-rotate"
536 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
537 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
538 enable_ust_lttng_channel_ok
$SESSION_NAME $channel_name --buffers-$buffer_type
539 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
540 start_lttng_tracing_ok
$SESSION_NAME
542 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
544 rotate_session_ok
$SESSION_NAME
546 stop_lttng_tracing_ok
$SESSION_NAME
548 if [[ $rotate_before -eq 1 ]]; then
553 validate_trace_count
$EVENT_NAME $TRACE_PATH $expect_count
555 destroy_lttng_session_ok
$SESSION_NAME --no-wait
558 function do_ust_snapshot
()
560 local session_name
=$1
562 local tracing_active
=$3
565 local channel_name
="snapshot"
567 enable_ust_lttng_channel_ok
$SESSION_NAME $channel_name --buffers-$buffer_type
568 enable_ust_lttng_event_ok
$session_name $EVENT_NAME $channel_name
569 start_lttng_tracing_ok
$session_name
571 # Generate 10 events that will sit in the buffers.
574 # Take a first snapshot and validate that the events are present.
575 lttng_snapshot_record
$session_name
576 stop_lttng_tracing_ok
$session_name
577 validate_trace_count
$EVENT_NAME $trace_path 10
579 # Clean the output path
580 clean_path
$trace_path
581 start_lttng_tracing_ok
$session_name
583 do_clear_session
$SESSION_NAME $tracing_active $clear_twice 0 0
585 # Make sure the subsequent snapshot is empty and valid.
586 lttng_snapshot_record
$session_name
587 stop_lttng_tracing_ok
$session_name
588 validate_trace_empty
$trace_path
590 # Clean the output path
591 clean_path
$trace_path
592 start_lttng_tracing_ok
$session_name
594 # Make sure that everything still works, generate events and take a
597 lttng_snapshot_record
$session_name
598 stop_lttng_tracing_ok
$session_name
599 validate_trace_count
$EVENT_NAME $trace_path 10
602 function test_ust_streaming_snapshot
()
604 local tracing_active
=$1
609 diag
"Test ust streaming snapshot clear"
610 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type"
612 create_lttng_session_uri
$SESSION_NAME net
://localhost
"--snapshot"
613 do_ust_snapshot
$SESSION_NAME $TRACE_PATH $tracing_active $clear_twice $buffer_type
614 destroy_lttng_session_ok
$SESSION_NAME --no-wait
617 function test_ust_local_snapshot
()
619 local tracing_active
=$1
624 diag
"Test ust local snapshot clear"
625 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type"
627 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH "--snapshot"
628 do_ust_snapshot
$SESSION_NAME $TRACE_PATH $tracing_active $clear_twice $buffer_type
629 destroy_lttng_session_ok
$SESSION_NAME --no-wait
632 # snapshot for per-pid is tested independently of the "buffer type" parameter
633 # because an application needs to be live to appear in a snapshot.
634 function test_ust_local_snapshot_per_pid
()
636 local tracing_active
=$1
640 local channel_name
="channel0"
641 local file_sync_before_last
=$
(mktemp
-u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
642 local file_sync_before_last_touch
=$
(mktemp
-u -t "tmp.${FUNCNAME[0]}_sync_before_last_touch.XXXXXX")
643 local file_sync_before_exit
=$
(mktemp
-u -t "tmp.${FUNCNAME[0]}_sync_before_exit.XXXXXX")
644 local file_sync_before_exit_touch
=$
(mktemp
-u -t "tmp.${FUNCNAME[0]}_sync_before_exit_touch.XXXXXX")
646 diag
"Test ust local snapshot clear per pid"
647 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type"
649 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH "--snapshot"
650 enable_ust_lttng_channel_ok
$SESSION_NAME $channel_name --buffers-$buffer_type
651 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
652 start_lttng_tracing_ok
$SESSION_NAME
654 # Generate 10 events that will sit in the buffers.
655 $TESTAPP_BIN -i 10 -w 0 \
656 --sync-before-last-event ${file_sync_before_last} \
657 --sync-before-last-event-touch ${file_sync_before_last_touch} \
658 --sync-before-exit ${file_sync_before_exit} \
659 --sync-before-exit-touch ${file_sync_before_exit_touch} >/dev
/null
2>&1 &
662 # Continue only when there is only the last event remaining.
663 while [ ! -f "${file_sync_before_last_touch}" ]; do
667 # Take a first snapshot and validate that the events are present.
668 lttng_snapshot_record
$SESSION_NAME
669 stop_lttng_tracing_ok
$SESSION_NAME
670 validate_trace_count
$EVENT_NAME $TRACE_PATH 9
672 # Clean the output path
673 clean_path
$TRACE_PATH
674 start_lttng_tracing_ok
$SESSION_NAME
676 do_clear_session
$SESSION_NAME $tracing_active $clear_twice 0 0
678 # Make sure the subsequent snapshot is empty and valid.
679 lttng_snapshot_record
$SESSION_NAME
680 stop_lttng_tracing_ok
$SESSION_NAME
681 validate_trace_empty
$TRACE_PATH
683 # Validate that tracing still works and subsequent snapshots are valid.
684 # Clean the output path.
685 clean_path
$TRACE_PATH
686 start_lttng_tracing_ok
$SESSION_NAME
688 # Continue over the last event.
689 touch ${file_sync_before_last}
691 # Wait for the before exit sync point. This ensure that we went over the
693 while [ ! -f "${file_sync_before_exit_touch}" ]; do
697 # Make sure the snapshot contains the last event.
698 lttng_snapshot_record
$SESSION_NAME
699 stop_lttng_tracing_ok
$SESSION_NAME
700 validate_trace_count
$EVENT_NAME $TRACE_PATH 1
702 # Release the application.
703 touch ${file_sync_before_exit}
705 destroy_lttng_session_ok
$SESSION_NAME --no-wait
707 rm -f ${file_sync_before_last}
708 rm -f ${file_sync_before_last_touch}
709 rm -f ${file_sync_before_exit}
710 rm -f ${file_sync_before_exit_touch}
713 function test_ust_streaming_tracefile_rotation
()
715 local tracing_active
=$1
717 local rotate_before
=$3
718 local rotate_after
=$4
720 local channel_name
="rotchan"
721 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
723 diag
"Test ust streaming clear with tracefile rotation"
724 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
725 create_lttng_session_uri
$SESSION_NAME net
://localhost
726 enable_ust_lttng_channel_ok
$SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \
727 --tracefile-size=$PAGE_SIZE --tracefile-count=2 --buffers-$buffer_type
728 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
729 start_lttng_tracing_ok
$SESSION_NAME
731 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
732 stop_lttng_tracing_ok
$SESSION_NAME
734 if [[ $rotate_before -eq 1 ]]; then
735 validate_trace_count
$EVENT_NAME $local_path 10
737 if [[ "$buffer_type" == "uid" ]]; then
738 validate_trace_empty
$local_path
740 validate_directory_empty
$local_path
744 start_lttng_tracing_ok
$SESSION_NAME
746 stop_lttng_tracing_ok
748 if [[ $rotate_before -eq 1 ]]; then
749 validate_trace_count
$EVENT_NAME $local_path 30
751 validate_trace_count
$EVENT_NAME $local_path 20
754 destroy_lttng_session_ok
$SESSION_NAME --no-wait
757 # With 1 byte per event (as strict minimum), generating 200000 events
758 # guarantees filling up 2 files of 64k in size, which is the maximum
759 # page size known on Linux
760 function test_ust_streaming_tracefile_rotation_overwrite_files
()
762 local tracing_active
=$1
764 local rotate_before
=$3
765 local rotate_after
=$4
767 local channel_name
="rotchan"
768 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
770 diag
"Test ust streaming clear with tracefile rotation, overwrite files"
771 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
772 create_lttng_session_uri
$SESSION_NAME net
://localhost
773 enable_ust_lttng_channel_ok
$SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \
774 --tracefile-size=$PAGE_SIZE --tracefile-count=2 --buffers-$buffer_type
775 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
776 start_lttng_tracing_ok
$SESSION_NAME
777 taskset
-c "$(get_any_available_cpu)" $TESTAPP_BIN -i 200000
778 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
779 stop_lttng_tracing_ok
$SESSION_NAME
781 if [[ $rotate_before -eq 1 ]]; then
782 validate_trace_count_range_incl_min_excl_max
$EVENT_NAME $local_path 1 200000
784 if [[ "$buffer_type" == "uid" ]]; then
785 validate_trace_empty
$local_path
787 validate_directory_empty
$local_path
791 start_lttng_tracing_ok
$SESSION_NAME
792 taskset
-c "$(get_any_available_cpu)" $TESTAPP_BIN -i 400000
793 stop_lttng_tracing_ok
795 if [[ $rotate_before -eq 1 ]]; then
796 validate_trace_count_range_incl_min_excl_max
$EVENT_NAME $local_path 1 600000
798 validate_trace_count_range_incl_min_excl_max
$EVENT_NAME $local_path 1 200000
801 destroy_lttng_session_ok
$SESSION_NAME --no-wait
804 function test_ust_disallow_clear
()
806 diag
"Test ust disallow clear on relay daemon"
807 SESSION_NAME
=$
(randstring
16 0)
809 LTTNG_RELAYD_DISALLOW_CLEAR
=1 start_lttng_relayd
"-o $TRACE_PATH"
813 create_lttng_session_uri
$SESSION_NAME net
://localhost
814 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME
815 start_lttng_tracing_ok
$SESSION_NAME
816 lttng_clear_session_fail
$SESSION_NAME
817 destroy_lttng_session_ok
$SESSION_NAME --no-wait
821 clean_path
$TRACE_PATH
824 plan_tests
$NUM_TESTS
826 print_test_banner
"$TEST_DESC"
828 bail_out_if_no_babeltrace
830 streaming_tests
=(test_ust_streaming
831 test_ust_streaming_rotate_clear
832 test_ust_streaming_clear_rotate
833 test_ust_streaming_tracefile_rotation
834 test_ust_streaming_tracefile_rotation_overwrite_files
835 test_ust_streaming_no_event
838 live_tests
=(test_ust_streaming_live
839 test_ust_basic_streaming_live_viewer
840 test_ust_streaming_live_viewer
841 test_ust_streaming_live_viewer_new_metadata_after_clear
844 local_tests
=(test_ust_local
845 test_ust_local_rotate_clear
846 test_ust_local_clear_rotate
847 test_ust_local_no_event
850 snapshot_uid_tests
=(test_ust_streaming_snapshot
851 test_ust_local_snapshot
854 snapshot_pid_tests
=(test_ust_local_snapshot_per_pid
)
856 start_lttng_relayd
"-o $TRACE_PATH"
861 # Clear with tracing active, clear once
862 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]};
864 SESSION_NAME
=$
(randstring
16 0)
865 ${fct_test} 1 0 0 0 uid
866 clean_path
$TRACE_PATH
869 # Clear with tracing active, clear twice
870 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]};
872 SESSION_NAME
=$
(randstring
16 0)
873 ${fct_test} 1 1 0 0 uid
874 clean_path
$TRACE_PATH
877 # Clear with tracing inactive, clear once
878 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]};
880 SESSION_NAME
=$
(randstring
16 0)
881 ${fct_test} 0 0 0 0 uid
882 clean_path
$TRACE_PATH
885 # Clear with tracing inactive, clear twice
886 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]};
888 SESSION_NAME
=$
(randstring
16 0)
889 ${fct_test} 0 1 0 0 uid
890 clean_path
$TRACE_PATH
893 # Clear with tracing inactive, rotate-clear once
894 for fct_test
in ${streaming_tests[@]} ${local_tests[@]};
896 SESSION_NAME
=$
(randstring
16 0)
897 ${fct_test} 0 0 1 0 uid
898 clean_path
$TRACE_PATH
901 # Clear with tracing inactive, clear once-rotate(fail)
902 for fct_test
in ${streaming_tests[@]} ${local_tests[@]};
904 SESSION_NAME
=$
(randstring
16 0)
905 ${fct_test} 0 0 0 1 uid
906 clean_path
$TRACE_PATH
912 # Clear with tracing active, clear once
913 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]};
915 SESSION_NAME
=$
(randstring
16 0)
916 ${fct_test} 1 0 0 0 pid
917 clean_path
$TRACE_PATH
920 # Clear with tracing active, clear twice
921 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]};
923 SESSION_NAME
=$
(randstring
16 0)
924 ${fct_test} 1 1 0 0 pid
925 clean_path
$TRACE_PATH
928 # Clear with tracing inactive, clear once
929 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]};
931 SESSION_NAME
=$
(randstring
16 0)
932 ${fct_test} 0 0 0 0 pid
933 clean_path
$TRACE_PATH
936 # Clear with tracing inactive, clear twice
937 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]};
939 SESSION_NAME
=$
(randstring
16 0)
940 ${fct_test} 0 1 0 0 pid
941 clean_path
$TRACE_PATH
944 # Clear with tracing inactive, rotate-clear once
945 for fct_test
in ${streaming_tests[@]} ${local_tests[@]};
947 SESSION_NAME
=$
(randstring
16 0)
948 ${fct_test} 0 0 1 0 pid
949 clean_path
$TRACE_PATH
952 # Clear with tracing inactive, clear once-rotate(fail)
953 for fct_test
in ${streaming_tests[@]} ${local_tests[@]};
955 SESSION_NAME
=$
(randstring
16 0)
956 ${fct_test} 0 0 0 1 pid
957 clean_path
$TRACE_PATH
963 test_ust_disallow_clear