3 # Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 TEST_DESC
="Clear - Kernel tracing"
10 TESTDIR
=$CURDIR/..
/..
/..
11 EVENT_NAME
="lttng_test_filter_event"
13 PAGE_SIZE
=$
(getconf PAGE_SIZE
)
14 TRACE_PATH
=$
(mktemp
--tmpdir -d tmp.test_clear_kernel_trace_path.XXXXXX
)
18 source $TESTDIR/utils
/utils.sh
20 function signal_cleanup
()
23 modprobe
--remove lttng-test
27 function clean_path
()
35 function cond_start_tracing
()
38 local tracing_active
=$2
40 if [[ $tracing_active -ne 1 ]]; then
41 start_lttng_tracing_ok
$session_name
45 function cond_stop_tracing
()
48 local tracing_active
=$2
50 if [[ $tracing_active -ne 1 ]]; then
51 stop_lttng_tracing_ok
$session_name
55 function do_clear_session
()
58 local tracing_active
=$2
60 local rotate_before
=$4
63 cond_stop_tracing
$session_name $tracing_active
64 if [[ $rotate_before -eq 1 ]]; then
65 rotate_session_ok
$SESSION_NAME
67 lttng_clear_session_ok
$SESSION_NAME
68 if [[ $clear_twice -eq 1 ]]; then
69 lttng_clear_session_ok
$SESSION_NAME
71 if [[ $rotate_after -eq 1 ]]; then
72 if [[ $tracing_active -eq 1 ]]; then
73 rotate_session_ok
$SESSION_NAME
76 rotate_session_fail
$SESSION_NAME
79 cond_start_tracing
$session_name $tracing_active
82 function test_kernel_streaming
()
84 local tracing_active
=$1
86 local rotate_before
=$3
88 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
90 diag
"Test kernel streaming clear"
91 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
92 create_lttng_session_uri
$SESSION_NAME net
://localhost
93 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
94 start_lttng_tracing_ok
$SESSION_NAME
95 # Generate 10 events that will sit in the buffers.
96 echo -n "10" > /proc
/lttng-test-filter-event
98 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
100 stop_lttng_tracing_ok
$SESSION_NAME
102 if [[ $rotate_before -eq 1 ]]; then
103 validate_trace_count
$EVENT_NAME $local_path 10
105 validate_trace_empty
$local_path
108 destroy_lttng_session_ok
$SESSION_NAME
111 function test_kernel_streaming_rotate_clear
()
113 local tracing_active
=$1
115 local rotate_before
=$3
116 local rotate_after
=$4
117 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
119 diag
"Test kernel streaming rotate-clear"
120 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
121 create_lttng_session_uri
$SESSION_NAME net
://localhost
122 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
123 start_lttng_tracing_ok
$SESSION_NAME
124 echo -n "1" > /proc
/lttng-test-filter-event
125 rotate_session_ok
$SESSION_NAME
126 echo -n "2" > /proc
/lttng-test-filter-event
127 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
128 echo -n "3" > /proc
/lttng-test-filter-event
130 stop_lttng_tracing_ok
$SESSION_NAME
132 if [[ $rotate_before -eq 1 ]]; then
137 validate_trace_count
$EVENT_NAME $local_path $expect_count
139 destroy_lttng_session_ok
$SESSION_NAME
142 function test_kernel_streaming_clear_rotate
()
144 local tracing_active
=$1
146 local rotate_before
=$3
147 local rotate_after
=$4
148 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
150 diag
"Test kernel streaming clear-rotate"
151 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
152 create_lttng_session_uri
$SESSION_NAME net
://localhost
153 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
154 start_lttng_tracing_ok
$SESSION_NAME
155 echo -n "1" > /proc
/lttng-test-filter-event
156 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
157 echo -n "2" > /proc
/lttng-test-filter-event
158 rotate_session_ok
$SESSION_NAME
159 echo -n "3" > /proc
/lttng-test-filter-event
161 stop_lttng_tracing_ok
$SESSION_NAME
163 if [[ $rotate_before -eq 1 ]]; then
168 validate_trace_count
$EVENT_NAME $local_path $expect_count
170 destroy_lttng_session_ok
$SESSION_NAME
173 function test_kernel_streaming_live
()
175 local tracing_active
=$1
177 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
179 diag
"Test kernel streaming live clear"
180 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice"
181 create_lttng_session_uri
$SESSION_NAME net
://localhost
"--live"
182 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
183 start_lttng_tracing_ok
$SESSION_NAME
184 # Generate 10 events that will sit in the buffers.
185 echo -n "10" > /proc
/lttng-test-filter-event
186 do_clear_session
$SESSION_NAME $tracing_active $clear_twice 0 0
187 stop_lttng_tracing_ok
$SESSION_NAME
189 validate_trace_empty
$local_path
191 destroy_lttng_session_ok
$SESSION_NAME
195 function test_kernel_basic_streaming_live_viewer
()
197 local tracing_active
=$1
200 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
201 local remote_trace_path
="${HOSTNAME}/${SESSION_NAME}"
202 local channel_name
="chan"
203 local bt_output_path
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_bt_output.XXXXXX")
204 local file_sync_before_exit
=$
(mktemp
--tmpdir -u -t "tmp.${FUNCNAME[0]}_sync_before_exit.XXXXXX")
206 diag
"Test kernel basic streaming live with viewer"
207 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice"
208 create_lttng_session_uri
$SESSION_NAME net
://localhost
"--live"
209 enable_kernel_lttng_channel_ok
$SESSION_NAME $channel_name
210 enable_kernel_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
211 start_lttng_tracing_ok
$SESSION_NAME
213 wait_live_trace_ready net
://localhost
215 # Connect a live viewer
216 $BABELTRACE_BIN -i lttng-live net
://localhost
/host
/$remote_trace_path > $bt_output_path &
219 wait_live_viewer_connect net
://localhost
221 echo -n "10" > /proc
/lttng-test-filter-event
223 diag
"Wait until viewer sees all 10 expected events"
225 while [ $evcount -ne 10 ]; do
226 evcount
=$
(cat $bt_output_path |
wc -l)
229 pass
"Live viewer read $evcount events, expect 10"
231 destroy_lttng_session_ok
$SESSION_NAME
232 touch $file_sync_before_exit
233 diag
"Wait for viewer to exit"
235 ok $?
"Babeltrace succeeds"
236 pass
"Wait for viewer to exit"
238 rm -f $bt_output_path
239 rm -f $file_sync_before_exit
242 function test_kernel_streaming_live_viewer
()
244 local tracing_active
=$1
247 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
248 local remote_trace_path
="${HOSTNAME}/${SESSION_NAME}"
249 local channel_name
="chan"
250 local bt_output_path
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_bt_output.XXXXXX")
252 diag
"Test kernel streaming live clear with viewer"
253 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice"
254 create_lttng_session_uri
$SESSION_NAME net
://localhost
"--live"
255 enable_kernel_lttng_channel_ok
$SESSION_NAME $channel_name
256 enable_kernel_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
257 start_lttng_tracing_ok
$SESSION_NAME
259 wait_live_trace_ready net
://localhost
261 # Connect a live viewer
262 $BABELTRACE_BIN -i lttng-live net
://localhost
/host
/$remote_trace_path > $bt_output_path &
265 wait_live_viewer_connect net
://localhost
267 echo -n "10" > /proc
/lttng-test-filter-event
268 do_clear_session
$SESSION_NAME $tracing_active $clear_twice 0 0
269 stop_lttng_tracing_ok
$SESSION_NAME
271 destroy_lttng_session_ok
$SESSION_NAME
272 diag
"Wait for viewer to exit"
274 ok $?
"Babeltrace succeeds"
275 pass
"Wait for viewer to exit"
277 clean_path
$bt_output_path
280 function test_kernel_local
()
282 local tracing_active
=$1
284 local rotate_before
=$3
285 local rotate_after
=$4
287 diag
"Test kernel local"
288 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
289 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
290 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
291 start_lttng_tracing_ok
$SESSION_NAME
292 # Generate 10 events that will sit in the buffers.
293 echo -n "10" > /proc
/lttng-test-filter-event
294 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
295 stop_lttng_tracing_ok
$SESSION_NAME
297 if [[ $rotate_before -eq 1 ]]; then
298 validate_trace_count
$EVENT_NAME $TRACE_PATH 10
300 validate_trace_empty
$TRACE_PATH
303 destroy_lttng_session_ok
$SESSION_NAME
306 function test_kernel_local_rotate_clear
()
308 local tracing_active
=$1
310 local rotate_before
=$3
311 local rotate_after
=$4
313 diag
"Test kernel local rotate-clear"
314 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
315 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
316 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
317 start_lttng_tracing_ok
$SESSION_NAME
318 echo -n "1" > /proc
/lttng-test-filter-event
319 rotate_session_ok
$SESSION_NAME
320 echo -n "2" > /proc
/lttng-test-filter-event
321 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
322 echo -n "3" > /proc
/lttng-test-filter-event
323 stop_lttng_tracing_ok
$SESSION_NAME
325 if [[ $rotate_before -eq 1 ]]; then
330 validate_trace_count
$EVENT_NAME $TRACE_PATH $expect_count
332 destroy_lttng_session_ok
$SESSION_NAME
335 function test_kernel_local_clear_rotate
()
337 local tracing_active
=$1
339 local rotate_before
=$3
340 local rotate_after
=$4
342 diag
"Test kernel local clear-rotate"
343 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
344 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
345 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
346 start_lttng_tracing_ok
$SESSION_NAME
347 echo -n "1" > /proc
/lttng-test-filter-event
348 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
349 echo -n "2" > /proc
/lttng-test-filter-event
350 rotate_session_ok
$SESSION_NAME
351 echo -n "3" > /proc
/lttng-test-filter-event
352 stop_lttng_tracing_ok
$SESSION_NAME
354 if [[ $rotate_before -eq 1 ]]; then
359 validate_trace_count
$EVENT_NAME $TRACE_PATH $expect_count
361 destroy_lttng_session_ok
$SESSION_NAME
364 function do_kernel_snapshot
()
366 local session_name
=$1
368 local tracing_active
=$3
370 local rotate_before
=$5
371 local rotate_after
=$6
373 lttng_enable_kernel_event
$session_name $EVENT_NAME
374 start_lttng_tracing_ok
$session_name
376 # Generate 10 events that will sit in the buffers.
377 echo -n "10" > /proc
/lttng-test-filter-event
379 # Take a first snapshot and validate that the events are present.
380 lttng_snapshot_record
$session_name
381 stop_lttng_tracing_ok
$session_name
382 validate_trace_count
$EVENT_NAME $trace_path 10
384 # Clean the output path
385 clean_path
$trace_path
386 start_lttng_tracing_ok
$session_name
388 do_clear_session
$SESSION_NAME $tracing_active $clear_twice 0 0
390 # Make sure the subsequent snapshot is empty and valid.
391 lttng_snapshot_record
$session_name
392 stop_lttng_tracing_ok
$session_name
393 validate_trace_empty
$trace_path
395 # Clean the output path
396 clean_path
$trace_path
397 start_lttng_tracing_ok
$session_name
399 # Make sure that everything still works, generate events and take a
401 echo -n "10" > /proc
/lttng-test-filter-event
402 lttng_snapshot_record
$session_name
403 stop_lttng_tracing_ok
$session_name
404 validate_trace_count
$EVENT_NAME $trace_path 10
407 function test_kernel_streaming_snapshot
()
409 local tracing_active
=$1
412 diag
"Test kernel streaming snapshot clear"
413 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice"
415 create_lttng_session_uri
$SESSION_NAME net
://localhost
"--snapshot"
416 do_kernel_snapshot
$SESSION_NAME $TRACE_PATH $tracing_active $clear_twice
417 destroy_lttng_session_ok
$SESSION_NAME
420 function test_kernel_local_snapshot
()
422 local tracing_active
=$1
425 diag
"Test kernel local snapshot clear"
426 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice"
428 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH "--snapshot"
429 do_kernel_snapshot
$SESSION_NAME $TRACE_PATH $tracing_active $clear_twice
430 destroy_lttng_session_ok
$SESSION_NAME
433 function test_kernel_streaming_tracefile_rotation
()
435 local tracing_active
=$1
437 local rotate_before
=$3
438 local rotate_after
=$4
439 local channel_name
="rotchan"
440 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
442 diag
"Test kernel streaming clear with tracefile rotation"
443 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
444 create_lttng_session_uri
$SESSION_NAME net
://localhost
445 enable_kernel_lttng_channel_ok
$SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \
446 --tracefile-size=$PAGE_SIZE --tracefile-count=2
447 enable_kernel_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
448 start_lttng_tracing_ok
$SESSION_NAME
449 echo -n "10" > /proc
/lttng-test-filter-event
450 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
451 stop_lttng_tracing_ok
$SESSION_NAME
453 if [[ $rotate_before -eq 1 ]]; then
454 validate_trace_count
$EVENT_NAME $local_path 10
456 validate_trace_empty
$local_path
459 start_lttng_tracing_ok
$SESSION_NAME
460 echo -n "20" > /proc
/lttng-test-filter-event
461 stop_lttng_tracing_ok
463 if [[ $rotate_before -eq 1 ]]; then
464 validate_trace_count
$EVENT_NAME $local_path 30
466 validate_trace_count
$EVENT_NAME $local_path 20
469 destroy_lttng_session_ok
$SESSION_NAME
472 # With 1 byte per event (as strict minimum), generating 200000 events
473 # guarantees filling up 2 files of 64k in size, which is the maximum
474 # page size known on Linux
475 function test_kernel_streaming_tracefile_rotation_overwrite_files
()
477 local tracing_active
=$1
479 local rotate_before
=$3
480 local rotate_after
=$4
481 local channel_name
="rotchan"
482 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
484 diag
"Test kernel streaming clear with tracefile rotation, overwrite files"
485 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
486 create_lttng_session_uri
$SESSION_NAME net
://localhost
487 enable_kernel_lttng_channel_ok
$SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \
488 --tracefile-size=$PAGE_SIZE --tracefile-count=2
489 enable_kernel_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
490 start_lttng_tracing_ok
$SESSION_NAME
491 taskset
-c 0 echo -n "200000" > /proc
/lttng-test-filter-event
492 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
493 stop_lttng_tracing_ok
$SESSION_NAME
495 if [[ $rotate_before -eq 1 ]]; then
496 validate_trace_count_range_incl_min_excl_max
$EVENT_NAME $local_path 1 200000
498 validate_trace_empty
$local_path
501 start_lttng_tracing_ok
$SESSION_NAME
502 taskset
-c 0 echo -n "400000" > /proc
/lttng-test-filter-event
503 stop_lttng_tracing_ok
505 if [[ $rotate_before -eq 1 ]]; then
506 validate_trace_count_range_incl_min_excl_max
$EVENT_NAME $local_path 1 600000
508 validate_trace_count_range_incl_min_excl_max
$EVENT_NAME $local_path 1 200000
511 destroy_lttng_session_ok
$SESSION_NAME
514 function test_kernel_disallow_clear
()
516 diag
"Test kernel disallow clear on relay daemon"
517 SESSION_NAME
=$
(randstring
16 0)
519 LTTNG_RELAYD_DISALLOW_CLEAR
=1 start_lttng_relayd
"-o $TRACE_PATH"
523 create_lttng_session_uri
$SESSION_NAME net
://localhost
524 enable_kernel_lttng_event_ok
$SESSION_NAME $EVENT_NAME
525 start_lttng_tracing_ok
$SESSION_NAME
526 lttng_clear_session_fail
$SESSION_NAME
527 destroy_lttng_session_ok
$SESSION_NAME
531 clean_path
$TRACE_PATH
534 plan_tests
$NUM_TESTS
536 print_test_banner
"$TEST_DESC"
538 bail_out_if_no_babeltrace
540 if [ "$(id -u)" == "0" ]; then
546 streaming_tests
=(test_kernel_streaming
547 test_kernel_streaming_rotate_clear
548 test_kernel_streaming_clear_rotate
549 test_kernel_streaming_tracefile_rotation
550 test_kernel_streaming_tracefile_rotation_overwrite_files
553 live_tests
=(test_kernel_streaming_live
554 test_kernel_basic_streaming_live_viewer
555 test_kernel_streaming_live_viewer
558 local_tests
=(test_kernel_local
559 test_kernel_local_rotate_clear
560 test_kernel_local_clear_rotate
563 snapshot_tests
=(test_kernel_streaming_snapshot
564 test_kernel_local_snapshot
567 skip
$isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS ||
569 trap signal_cleanup SIGTERM SIGINT
571 validate_lttng_modules_present
573 start_lttng_relayd
"-o $TRACE_PATH"
577 # Clear with tracing active, clear once
578 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_tests[@]};
580 SESSION_NAME
=$
(randstring
16 0)
582 clean_path
$TRACE_PATH
585 # Clear with tracing active, clear twice
586 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_tests[@]};
588 SESSION_NAME
=$
(randstring
16 0)
590 clean_path
$TRACE_PATH
593 # Clear with tracing inactive, clear once
594 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_tests[@]};
596 SESSION_NAME
=$
(randstring
16 0)
598 clean_path
$TRACE_PATH
601 # Clear with tracing inactive, clear twice
602 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_tests[@]};
604 SESSION_NAME
=$
(randstring
16 0)
606 clean_path
$TRACE_PATH
609 # Clear with tracing inactive, rotate-clear once
610 for fct_test
in ${streaming_tests[@]} ${local_tests[@]};
612 SESSION_NAME
=$
(randstring
16 0)
614 clean_path
$TRACE_PATH
617 # Clear with tracing inactive, clear once-rotate(fail)
618 for fct_test
in ${streaming_tests[@]} ${local_tests[@]};
620 SESSION_NAME
=$
(randstring
16 0)
622 clean_path
$TRACE_PATH
625 modprobe
--remove lttng-test
629 test_kernel_disallow_clear
632 clean_path
$TRACE_PATH