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
-d -t tmp.test_clear_kernel_trace_path.XXXXXX
)
18 # shellcheck source=../utils/utils.sh
19 source "$TESTDIR/utils/utils.sh"
21 function signal_cleanup
()
24 modprobe
--remove lttng-test
28 function clean_path
()
36 function cond_start_tracing
()
39 local tracing_active
=$2
41 if [[ $tracing_active -ne 1 ]]; then
42 start_lttng_tracing_ok
$session_name
46 function cond_stop_tracing
()
49 local tracing_active
=$2
51 if [[ $tracing_active -ne 1 ]]; then
52 stop_lttng_tracing_ok
$session_name
56 function do_clear_session
()
59 local tracing_active
=$2
61 local rotate_before
=$4
64 cond_stop_tracing
$session_name $tracing_active
65 if [[ $rotate_before -eq 1 ]]; then
66 rotate_session_ok
$SESSION_NAME
68 lttng_clear_session_ok
$SESSION_NAME
69 if [[ $clear_twice -eq 1 ]]; then
70 lttng_clear_session_ok
$SESSION_NAME
72 if [[ $rotate_after -eq 1 ]]; then
73 if [[ $tracing_active -eq 1 ]]; then
74 rotate_session_ok
$SESSION_NAME
77 rotate_session_fail
$SESSION_NAME
80 cond_start_tracing
$session_name $tracing_active
83 function test_kernel_streaming
()
85 local tracing_active
=$1
87 local rotate_before
=$3
89 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
91 diag
"Test kernel streaming clear"
92 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
93 create_lttng_session_uri
$SESSION_NAME net
://localhost
94 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
95 start_lttng_tracing_ok
$SESSION_NAME
96 # Generate 10 events that will sit in the buffers.
97 echo -n "10" > /proc
/lttng-test-filter-event
99 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
101 stop_lttng_tracing_ok
$SESSION_NAME
103 if [[ $rotate_before -eq 1 ]]; then
104 validate_trace_count
$EVENT_NAME $local_path 10
106 validate_trace_empty
$local_path
109 destroy_lttng_session_ok
$SESSION_NAME
112 function test_kernel_streaming_rotate_clear
()
114 local tracing_active
=$1
116 local rotate_before
=$3
117 local rotate_after
=$4
118 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
120 diag
"Test kernel streaming rotate-clear"
121 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
122 create_lttng_session_uri
$SESSION_NAME net
://localhost
123 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
124 start_lttng_tracing_ok
$SESSION_NAME
125 echo -n "1" > /proc
/lttng-test-filter-event
126 rotate_session_ok
$SESSION_NAME
127 echo -n "2" > /proc
/lttng-test-filter-event
128 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
129 echo -n "3" > /proc
/lttng-test-filter-event
131 stop_lttng_tracing_ok
$SESSION_NAME
133 if [[ $rotate_before -eq 1 ]]; then
138 validate_trace_count
$EVENT_NAME $local_path $expect_count
140 destroy_lttng_session_ok
$SESSION_NAME
143 function test_kernel_streaming_clear_rotate
()
145 local tracing_active
=$1
147 local rotate_before
=$3
148 local rotate_after
=$4
149 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
151 diag
"Test kernel streaming clear-rotate"
152 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
153 create_lttng_session_uri
$SESSION_NAME net
://localhost
154 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
155 start_lttng_tracing_ok
$SESSION_NAME
156 echo -n "1" > /proc
/lttng-test-filter-event
157 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
158 echo -n "2" > /proc
/lttng-test-filter-event
159 rotate_session_ok
$SESSION_NAME
160 echo -n "3" > /proc
/lttng-test-filter-event
162 stop_lttng_tracing_ok
$SESSION_NAME
164 if [[ $rotate_before -eq 1 ]]; then
169 validate_trace_count
$EVENT_NAME $local_path $expect_count
171 destroy_lttng_session_ok
$SESSION_NAME
174 function test_kernel_streaming_live
()
176 local tracing_active
=$1
178 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
180 diag
"Test kernel streaming live clear"
181 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice"
182 create_lttng_session_uri
$SESSION_NAME net
://localhost
"--live"
183 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
184 start_lttng_tracing_ok
$SESSION_NAME
185 # Generate 10 events that will sit in the buffers.
186 echo -n "10" > /proc
/lttng-test-filter-event
187 do_clear_session
$SESSION_NAME $tracing_active $clear_twice 0 0
188 stop_lttng_tracing_ok
$SESSION_NAME
190 validate_trace_empty
$local_path
192 destroy_lttng_session_ok
$SESSION_NAME
196 function test_kernel_basic_streaming_live_viewer
()
198 local tracing_active
=$1
201 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
202 local remote_trace_path
="${HOSTNAME}/${SESSION_NAME}"
203 local channel_name
="chan"
204 local bt_output_path
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_bt_output.XXXXXX")
205 local file_sync_before_exit
=$
(mktemp
-u -t "tmp.${FUNCNAME[0]}_sync_before_exit.XXXXXX")
207 diag
"Test kernel basic streaming live with viewer"
208 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice"
209 create_lttng_session_uri
$SESSION_NAME net
://localhost
"--live"
210 enable_kernel_lttng_channel_ok
$SESSION_NAME $channel_name
211 enable_kernel_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
212 start_lttng_tracing_ok
$SESSION_NAME
214 wait_live_trace_ready net
://localhost
216 # Connect a live viewer
217 $BABELTRACE_BIN -i lttng-live net
://localhost
/host
/$remote_trace_path > $bt_output_path &
220 wait_live_viewer_connect net
://localhost
222 echo -n "10" > /proc
/lttng-test-filter-event
224 diag
"Wait until viewer sees all 10 expected events"
226 while [ $evcount -ne 10 ]; do
227 evcount
=$
(cat $bt_output_path |
wc -l)
230 pass
"Live viewer read $evcount events, expect 10"
232 destroy_lttng_session_ok
$SESSION_NAME
233 touch $file_sync_before_exit
234 diag
"Wait for viewer to exit"
236 ok $?
"Babeltrace succeeds"
237 pass
"Wait for viewer to exit"
239 rm -f $bt_output_path
240 rm -f $file_sync_before_exit
243 function test_kernel_streaming_live_viewer
()
245 local tracing_active
=$1
248 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
249 local remote_trace_path
="${HOSTNAME}/${SESSION_NAME}"
250 local channel_name
="chan"
251 local bt_output_path
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_bt_output.XXXXXX")
253 diag
"Test kernel streaming live clear with viewer"
254 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice"
255 create_lttng_session_uri
$SESSION_NAME net
://localhost
"--live"
256 enable_kernel_lttng_channel_ok
$SESSION_NAME $channel_name
257 enable_kernel_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 > $bt_output_path &
266 wait_live_viewer_connect net
://localhost
268 echo -n "10" > /proc
/lttng-test-filter-event
269 do_clear_session
$SESSION_NAME $tracing_active $clear_twice 0 0
270 stop_lttng_tracing_ok
$SESSION_NAME
272 destroy_lttng_session_ok
$SESSION_NAME
273 diag
"Wait for viewer to exit"
275 ok $?
"Babeltrace succeeds"
276 pass
"Wait for viewer to exit"
278 clean_path
$bt_output_path
281 function test_kernel_local
()
283 local tracing_active
=$1
285 local rotate_before
=$3
286 local rotate_after
=$4
288 diag
"Test kernel local"
289 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
290 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
291 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
292 start_lttng_tracing_ok
$SESSION_NAME
293 # Generate 10 events that will sit in the buffers.
294 echo -n "10" > /proc
/lttng-test-filter-event
295 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
296 stop_lttng_tracing_ok
$SESSION_NAME
298 if [[ $rotate_before -eq 1 ]]; then
299 validate_trace_count
$EVENT_NAME $TRACE_PATH 10
301 validate_trace_empty
$TRACE_PATH
304 destroy_lttng_session_ok
$SESSION_NAME
307 function test_kernel_local_rotate_clear
()
309 local tracing_active
=$1
311 local rotate_before
=$3
312 local rotate_after
=$4
314 diag
"Test kernel local rotate-clear"
315 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
316 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
317 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
318 start_lttng_tracing_ok
$SESSION_NAME
319 echo -n "1" > /proc
/lttng-test-filter-event
320 rotate_session_ok
$SESSION_NAME
321 echo -n "2" > /proc
/lttng-test-filter-event
322 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
323 echo -n "3" > /proc
/lttng-test-filter-event
324 stop_lttng_tracing_ok
$SESSION_NAME
326 if [[ $rotate_before -eq 1 ]]; then
331 validate_trace_count
$EVENT_NAME $TRACE_PATH $expect_count
333 destroy_lttng_session_ok
$SESSION_NAME
336 function test_kernel_local_clear_rotate
()
338 local tracing_active
=$1
340 local rotate_before
=$3
341 local rotate_after
=$4
343 diag
"Test kernel local clear-rotate"
344 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
345 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
346 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
347 start_lttng_tracing_ok
$SESSION_NAME
348 echo -n "1" > /proc
/lttng-test-filter-event
349 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
350 echo -n "2" > /proc
/lttng-test-filter-event
351 rotate_session_ok
$SESSION_NAME
352 echo -n "3" > /proc
/lttng-test-filter-event
353 stop_lttng_tracing_ok
$SESSION_NAME
355 if [[ $rotate_before -eq 1 ]]; then
360 validate_trace_count
$EVENT_NAME $TRACE_PATH $expect_count
362 destroy_lttng_session_ok
$SESSION_NAME
365 function do_kernel_snapshot
()
367 local session_name
=$1
369 local tracing_active
=$3
371 local rotate_before
=$5
372 local rotate_after
=$6
374 lttng_enable_kernel_event
$session_name $EVENT_NAME
375 start_lttng_tracing_ok
$session_name
377 # Generate 10 events that will sit in the buffers.
378 echo -n "10" > /proc
/lttng-test-filter-event
380 # Take a first snapshot and validate that the events are present.
381 lttng_snapshot_record
$session_name
382 stop_lttng_tracing_ok
$session_name
383 validate_trace_count
$EVENT_NAME $trace_path 10
385 # Clean the output path
386 clean_path
$trace_path
387 start_lttng_tracing_ok
$session_name
389 do_clear_session
$SESSION_NAME $tracing_active $clear_twice 0 0
391 # Make sure the subsequent snapshot is empty and valid.
392 lttng_snapshot_record
$session_name
393 stop_lttng_tracing_ok
$session_name
394 validate_trace_empty
$trace_path
396 # Clean the output path
397 clean_path
$trace_path
398 start_lttng_tracing_ok
$session_name
400 # Make sure that everything still works, generate events and take a
402 echo -n "10" > /proc
/lttng-test-filter-event
403 lttng_snapshot_record
$session_name
404 stop_lttng_tracing_ok
$session_name
405 validate_trace_count
$EVENT_NAME $trace_path 10
408 function test_kernel_streaming_snapshot
()
410 local tracing_active
=$1
413 diag
"Test kernel streaming snapshot clear"
414 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice"
416 create_lttng_session_uri
$SESSION_NAME net
://localhost
"--snapshot"
417 do_kernel_snapshot
$SESSION_NAME $TRACE_PATH $tracing_active $clear_twice
418 destroy_lttng_session_ok
$SESSION_NAME
421 function test_kernel_local_snapshot
()
423 local tracing_active
=$1
426 diag
"Test kernel local snapshot clear"
427 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice"
429 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH "--snapshot"
430 do_kernel_snapshot
$SESSION_NAME $TRACE_PATH $tracing_active $clear_twice
431 destroy_lttng_session_ok
$SESSION_NAME
434 function test_kernel_streaming_tracefile_rotation
()
436 local tracing_active
=$1
438 local rotate_before
=$3
439 local rotate_after
=$4
440 local channel_name
="rotchan"
441 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
443 diag
"Test kernel streaming clear with tracefile rotation"
444 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
445 create_lttng_session_uri
$SESSION_NAME net
://localhost
446 enable_kernel_lttng_channel_ok
$SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \
447 --tracefile-size=$PAGE_SIZE --tracefile-count=2
448 enable_kernel_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
449 start_lttng_tracing_ok
$SESSION_NAME
450 echo -n "10" > /proc
/lttng-test-filter-event
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 $local_path 10
457 validate_trace_empty
$local_path
460 start_lttng_tracing_ok
$SESSION_NAME
461 echo -n "20" > /proc
/lttng-test-filter-event
462 stop_lttng_tracing_ok
464 if [[ $rotate_before -eq 1 ]]; then
465 validate_trace_count
$EVENT_NAME $local_path 30
467 validate_trace_count
$EVENT_NAME $local_path 20
470 destroy_lttng_session_ok
$SESSION_NAME
473 # With 1 byte per event (as strict minimum), generating 200000 events
474 # guarantees filling up 2 files of 64k in size, which is the maximum
475 # page size known on Linux
476 function test_kernel_streaming_tracefile_rotation_overwrite_files
()
478 local tracing_active
=$1
480 local rotate_before
=$3
481 local rotate_after
=$4
482 local channel_name
="rotchan"
483 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
485 diag
"Test kernel streaming clear with tracefile rotation, overwrite files"
486 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
487 create_lttng_session_uri
$SESSION_NAME net
://localhost
488 enable_kernel_lttng_channel_ok
$SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \
489 --tracefile-size=$PAGE_SIZE --tracefile-count=2
490 enable_kernel_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
491 start_lttng_tracing_ok
$SESSION_NAME
492 taskset
-c "$(get_any_available_cpu)" echo -n "200000" > /proc
/lttng-test-filter-event
493 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
494 stop_lttng_tracing_ok
$SESSION_NAME
496 if [[ $rotate_before -eq 1 ]]; then
497 validate_trace_count_range_incl_min_excl_max
$EVENT_NAME $local_path 1 200000
499 validate_trace_empty
$local_path
502 start_lttng_tracing_ok
$SESSION_NAME
503 taskset
-c "$(get_any_available_cpu)" echo -n "400000" > /proc
/lttng-test-filter-event
504 stop_lttng_tracing_ok
506 if [[ $rotate_before -eq 1 ]]; then
507 validate_trace_count_range_incl_min_excl_max
$EVENT_NAME $local_path 1 600000
509 validate_trace_count_range_incl_min_excl_max
$EVENT_NAME $local_path 1 200000
512 destroy_lttng_session_ok
$SESSION_NAME
515 function test_kernel_disallow_clear
()
517 diag
"Test kernel disallow clear on relay daemon"
518 SESSION_NAME
=$
(randstring
16 0)
520 LTTNG_RELAYD_DISALLOW_CLEAR
=1 start_lttng_relayd
"-o $TRACE_PATH"
524 create_lttng_session_uri
$SESSION_NAME net
://localhost
525 enable_kernel_lttng_event_ok
$SESSION_NAME $EVENT_NAME
526 start_lttng_tracing_ok
$SESSION_NAME
527 lttng_clear_session_fail
$SESSION_NAME
528 destroy_lttng_session_ok
$SESSION_NAME
532 clean_path
$TRACE_PATH
535 plan_tests
$NUM_TESTS
537 print_test_banner
"$TEST_DESC"
539 bail_out_if_no_babeltrace
541 streaming_tests
=(test_kernel_streaming
542 test_kernel_streaming_rotate_clear
543 test_kernel_streaming_clear_rotate
544 test_kernel_streaming_tracefile_rotation
545 test_kernel_streaming_tracefile_rotation_overwrite_files
548 live_tests
=(test_kernel_streaming_live
549 test_kernel_basic_streaming_live_viewer
550 test_kernel_streaming_live_viewer
553 local_tests
=(test_kernel_local
554 test_kernel_local_rotate_clear
555 test_kernel_local_clear_rotate
558 snapshot_tests
=(test_kernel_streaming_snapshot
559 test_kernel_local_snapshot
562 check_skip_kernel_test
"$NUM_TESTS" "Skipping kernel streaming tests." ||
564 trap signal_cleanup SIGTERM SIGINT
566 validate_lttng_modules_present
568 start_lttng_relayd
"-o $TRACE_PATH"
572 # Clear with tracing active, clear once
573 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_tests[@]};
575 SESSION_NAME
=$
(randstring
16 0)
577 clean_path
$TRACE_PATH
580 # Clear with tracing active, clear twice
581 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_tests[@]};
583 SESSION_NAME
=$
(randstring
16 0)
585 clean_path
$TRACE_PATH
588 # Clear with tracing inactive, clear once
589 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_tests[@]};
591 SESSION_NAME
=$
(randstring
16 0)
593 clean_path
$TRACE_PATH
596 # Clear with tracing inactive, clear twice
597 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_tests[@]};
599 SESSION_NAME
=$
(randstring
16 0)
601 clean_path
$TRACE_PATH
604 # Clear with tracing inactive, rotate-clear once
605 for fct_test
in ${streaming_tests[@]} ${local_tests[@]};
607 SESSION_NAME
=$
(randstring
16 0)
609 clean_path
$TRACE_PATH
612 # Clear with tracing inactive, clear once-rotate(fail)
613 for fct_test
in ${streaming_tests[@]} ${local_tests[@]};
615 SESSION_NAME
=$
(randstring
16 0)
617 clean_path
$TRACE_PATH
620 modprobe
--remove lttng-test
624 test_kernel_disallow_clear
627 clean_path
$TRACE_PATH