3 # Copyright (C) - 2019 Jonathan Rajotte-Julien <jonathan.rajotte-julien@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
18 TEST_DESC
="Clear - Kernel tracing"
21 TESTDIR
=$CURDIR/..
/..
/..
22 EVENT_NAME
="lttng_test_filter_event"
24 PAGE_SIZE
=$
(getconf PAGE_SIZE
)
25 TRACE_PATH
=$
(mktemp
-d)
29 source $TESTDIR/utils
/utils.sh
31 function signal_cleanup
()
34 modprobe
-r lttng-test
38 function clean_path
()
46 function cond_start_tracing
()
49 local tracing_active
=$2
51 if [[ $tracing_active -ne 1 ]]; then
52 start_lttng_tracing_ok
$session_name
56 function cond_stop_tracing
()
59 local tracing_active
=$2
61 if [[ $tracing_active -ne 1 ]]; then
62 stop_lttng_tracing_ok
$session_name
66 function do_clear_session
()
69 local tracing_active
=$2
71 local rotate_before
=$4
74 cond_stop_tracing
$session_name $tracing_active
75 if [[ $rotate_before -eq 1 ]]; then
76 rotate_session_ok
$SESSION_NAME
78 lttng_clear_session_ok
$SESSION_NAME
79 if [[ $clear_twice -eq 1 ]]; then
80 lttng_clear_session_ok
$SESSION_NAME
82 if [[ $rotate_after -eq 1 ]]; then
83 if [[ $tracing_active -eq 1 ]]; then
84 rotate_session_ok
$SESSION_NAME
87 rotate_session_fail
$SESSION_NAME
90 cond_start_tracing
$session_name $tracing_active
93 function test_kernel_streaming
()
95 local tracing_active
=$1
97 local rotate_before
=$3
99 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
101 diag
"Test kernel streaming clear"
102 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
103 create_lttng_session_uri
$SESSION_NAME net
://localhost
104 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
105 start_lttng_tracing_ok
$SESSION_NAME
106 # Generate 10 events that will sit in the buffers.
107 echo -n "10" > /proc
/lttng-test-filter-event
109 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
111 stop_lttng_tracing_ok
$SESSION_NAME
113 if [[ $rotate_before -eq 1 ]]; then
114 validate_trace_count
$EVENT_NAME $local_path 10
116 validate_trace_empty
$local_path
119 destroy_lttng_session_ok
$SESSION_NAME
122 function test_kernel_streaming_rotate_clear
()
124 local tracing_active
=$1
126 local rotate_before
=$3
127 local rotate_after
=$4
128 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
130 diag
"Test kernel streaming rotate-clear"
131 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
132 create_lttng_session_uri
$SESSION_NAME net
://localhost
133 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
134 start_lttng_tracing_ok
$SESSION_NAME
135 echo -n "1" > /proc
/lttng-test-filter-event
136 rotate_session_ok
$SESSION_NAME
137 echo -n "2" > /proc
/lttng-test-filter-event
138 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
139 echo -n "3" > /proc
/lttng-test-filter-event
141 stop_lttng_tracing_ok
$SESSION_NAME
143 if [[ $rotate_before -eq 1 ]]; then
148 validate_trace_count
$EVENT_NAME $local_path $expect_count
150 destroy_lttng_session_ok
$SESSION_NAME
153 function test_kernel_streaming_clear_rotate
()
155 local tracing_active
=$1
157 local rotate_before
=$3
158 local rotate_after
=$4
159 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
161 diag
"Test kernel streaming clear-rotate"
162 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
163 create_lttng_session_uri
$SESSION_NAME net
://localhost
164 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
165 start_lttng_tracing_ok
$SESSION_NAME
166 echo -n "1" > /proc
/lttng-test-filter-event
167 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
168 echo -n "2" > /proc
/lttng-test-filter-event
169 rotate_session_ok
$SESSION_NAME
170 echo -n "3" > /proc
/lttng-test-filter-event
172 stop_lttng_tracing_ok
$SESSION_NAME
174 if [[ $rotate_before -eq 1 ]]; then
179 validate_trace_count
$EVENT_NAME $local_path $expect_count
181 destroy_lttng_session_ok
$SESSION_NAME
184 function test_kernel_streaming_live
()
186 local tracing_active
=$1
188 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
190 diag
"Test kernel streaming live clear"
191 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice"
192 create_lttng_session_uri
$SESSION_NAME net
://localhost
"--live"
193 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
194 start_lttng_tracing_ok
$SESSION_NAME
195 # Generate 10 events that will sit in the buffers.
196 echo -n "10" > /proc
/lttng-test-filter-event
197 do_clear_session
$SESSION_NAME $tracing_active $clear_twice 0 0
198 stop_lttng_tracing_ok
$SESSION_NAME
200 validate_trace_empty
$local_path
202 destroy_lttng_session_ok
$SESSION_NAME
206 function test_kernel_basic_streaming_live_viewer
()
208 local tracing_active
=$1
211 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
212 local remote_trace_path
="${HOSTNAME}/${SESSION_NAME}"
213 local channel_name
="chan"
214 local bt_output_path
=$
(mktemp
-u)
215 local file_sync_before_exit
=$
(mktemp
-u)
217 diag
"Test kernel basic streaming live with viewer"
218 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice"
219 create_lttng_session_uri
$SESSION_NAME net
://localhost
"--live"
220 enable_kernel_lttng_channel_ok
$SESSION_NAME $channel_name
221 enable_kernel_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
222 start_lttng_tracing_ok
$SESSION_NAME
224 wait_live_trace_ready net
://localhost
226 # Connect a live viewer
227 $BABELTRACE_BIN -i lttng-live net
://localhost
/host
/$remote_trace_path > $bt_output_path &
230 wait_live_viewer_connect net
://localhost
232 echo -n "10" > /proc
/lttng-test-filter-event
234 diag
"Wait until viewer sees all 10 expected events"
236 while [ $evcount -ne 10 ]; do
237 evcount
=$
(cat $bt_output_path |
wc -l)
240 pass
"Live viewer read $evcount events, expect 10"
242 destroy_lttng_session_ok
$SESSION_NAME
243 touch $file_sync_before_exit
244 diag
"Wait for viewer to exit"
246 ok $?
"Babeltrace succeeds"
247 pass
"Wait for viewer to exit"
249 rm -f $bt_output_path
250 rm -f $file_sync_before_exit
253 function test_kernel_streaming_live_viewer
()
255 local tracing_active
=$1
258 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
259 local remote_trace_path
="${HOSTNAME}/${SESSION_NAME}"
260 local channel_name
="chan"
261 local bt_output_path
=$
(mktemp
-d)/bt-output.txt
263 diag
"Test kernel streaming live clear with viewer"
264 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice"
265 create_lttng_session_uri
$SESSION_NAME net
://localhost
"--live"
266 enable_kernel_lttng_channel_ok
$SESSION_NAME $channel_name
267 enable_kernel_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
268 start_lttng_tracing_ok
$SESSION_NAME
270 wait_live_trace_ready net
://localhost
272 # Connect a live viewer
273 $BABELTRACE_BIN -i lttng-live net
://localhost
/host
/$remote_trace_path > $bt_output_path &
276 wait_live_viewer_connect net
://localhost
278 echo -n "10" > /proc
/lttng-test-filter-event
279 do_clear_session
$SESSION_NAME $tracing_active $clear_twice 0 0
280 stop_lttng_tracing_ok
$SESSION_NAME
282 destroy_lttng_session_ok
$SESSION_NAME
283 diag
"Wait for viewer to exit"
285 ok $?
"Babeltrace succeeds"
286 pass
"Wait for viewer to exit"
288 clean_path
$bt_output_path
291 function test_kernel_local
()
293 local tracing_active
=$1
295 local rotate_before
=$3
296 local rotate_after
=$4
298 diag
"Test kernel local"
299 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
300 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
301 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
302 start_lttng_tracing_ok
$SESSION_NAME
303 # Generate 10 events that will sit in the buffers.
304 echo -n "10" > /proc
/lttng-test-filter-event
305 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
306 stop_lttng_tracing_ok
$SESSION_NAME
308 if [[ $rotate_before -eq 1 ]]; then
309 validate_trace_count
$EVENT_NAME $TRACE_PATH 10
311 validate_trace_empty
$TRACE_PATH
314 destroy_lttng_session_ok
$SESSION_NAME
317 function test_kernel_local_rotate_clear
()
319 local tracing_active
=$1
321 local rotate_before
=$3
322 local rotate_after
=$4
324 diag
"Test kernel local rotate-clear"
325 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
326 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
327 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
328 start_lttng_tracing_ok
$SESSION_NAME
329 echo -n "1" > /proc
/lttng-test-filter-event
330 rotate_session_ok
$SESSION_NAME
331 echo -n "2" > /proc
/lttng-test-filter-event
332 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
333 echo -n "3" > /proc
/lttng-test-filter-event
334 stop_lttng_tracing_ok
$SESSION_NAME
336 if [[ $rotate_before -eq 1 ]]; then
341 validate_trace_count
$EVENT_NAME $TRACE_PATH $expect_count
343 destroy_lttng_session_ok
$SESSION_NAME
346 function test_kernel_local_clear_rotate
()
348 local tracing_active
=$1
350 local rotate_before
=$3
351 local rotate_after
=$4
353 diag
"Test kernel local clear-rotate"
354 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
355 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
356 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME
357 start_lttng_tracing_ok
$SESSION_NAME
358 echo -n "1" > /proc
/lttng-test-filter-event
359 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
360 echo -n "2" > /proc
/lttng-test-filter-event
361 rotate_session_ok
$SESSION_NAME
362 echo -n "3" > /proc
/lttng-test-filter-event
363 stop_lttng_tracing_ok
$SESSION_NAME
365 if [[ $rotate_before -eq 1 ]]; then
370 validate_trace_count
$EVENT_NAME $TRACE_PATH $expect_count
372 destroy_lttng_session_ok
$SESSION_NAME
375 function do_kernel_snapshot
()
377 local session_name
=$1
379 local tracing_active
=$3
381 local rotate_before
=$5
382 local rotate_after
=$6
384 lttng_enable_kernel_event
$session_name $EVENT_NAME
385 start_lttng_tracing_ok
$session_name
387 # Generate 10 events that will sit in the buffers.
388 echo -n "10" > /proc
/lttng-test-filter-event
390 # Take a first snapshot and validate that the events are present.
391 lttng_snapshot_record
$session_name
392 stop_lttng_tracing_ok
$session_name
393 validate_trace_count
$EVENT_NAME $trace_path 10
395 # Clean the output path
396 clean_path
$trace_path
397 start_lttng_tracing_ok
$session_name
399 do_clear_session
$SESSION_NAME $tracing_active $clear_twice 0 0
401 # Make sure the subsequent snapshot is empty and valid.
402 lttng_snapshot_record
$session_name
403 stop_lttng_tracing_ok
$session_name
404 validate_trace_empty
$trace_path
406 # Clean the output path
407 clean_path
$trace_path
408 start_lttng_tracing_ok
$session_name
410 # Make sure that everything still works, generate events and take a
412 echo -n "10" > /proc
/lttng-test-filter-event
413 lttng_snapshot_record
$session_name
414 stop_lttng_tracing_ok
$session_name
415 validate_trace_count
$EVENT_NAME $trace_path 10
418 function test_kernel_streaming_snapshot
()
420 local tracing_active
=$1
423 diag
"Test kernel streaming snapshot clear"
424 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice"
426 create_lttng_session_uri
$SESSION_NAME net
://localhost
"--snapshot"
427 do_kernel_snapshot
$SESSION_NAME $TRACE_PATH $tracing_active $clear_twice
428 destroy_lttng_session_ok
$SESSION_NAME
431 function test_kernel_local_snapshot
()
433 local tracing_active
=$1
436 diag
"Test kernel local snapshot clear"
437 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice"
439 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH "--snapshot"
440 do_kernel_snapshot
$SESSION_NAME $TRACE_PATH $tracing_active $clear_twice
441 destroy_lttng_session_ok
$SESSION_NAME
444 function test_kernel_streaming_tracefile_rotation
()
446 local tracing_active
=$1
448 local rotate_before
=$3
449 local rotate_after
=$4
450 local channel_name
="rotchan"
451 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
453 diag
"Test kernel streaming clear with tracefile rotation"
454 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
455 create_lttng_session_uri
$SESSION_NAME net
://localhost
456 enable_kernel_lttng_channel_ok
$SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \
457 --tracefile-size=$PAGE_SIZE --tracefile-count=2
458 enable_kernel_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
459 start_lttng_tracing_ok
$SESSION_NAME
460 echo -n "10" > /proc
/lttng-test-filter-event
461 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
462 stop_lttng_tracing_ok
$SESSION_NAME
464 if [[ $rotate_before -eq 1 ]]; then
465 validate_trace_count
$EVENT_NAME $local_path 10
467 validate_trace_empty
$local_path
470 start_lttng_tracing_ok
$SESSION_NAME
471 echo -n "20" > /proc
/lttng-test-filter-event
472 stop_lttng_tracing_ok
474 if [[ $rotate_before -eq 1 ]]; then
475 validate_trace_count
$EVENT_NAME $local_path 30
477 validate_trace_count
$EVENT_NAME $local_path 20
480 destroy_lttng_session_ok
$SESSION_NAME
483 # With 1 byte per event (as strict minimum), generating 200000 events
484 # guarantees filling up 2 files of 64k in size, which is the maximum
485 # page size known on Linux
486 function test_kernel_streaming_tracefile_rotation_overwrite_files
()
488 local tracing_active
=$1
490 local rotate_before
=$3
491 local rotate_after
=$4
492 local channel_name
="rotchan"
493 local local_path
="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
495 diag
"Test kernel streaming clear with tracefile rotation, overwrite files"
496 diag
"Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after"
497 create_lttng_session_uri
$SESSION_NAME net
://localhost
498 enable_kernel_lttng_channel_ok
$SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \
499 --tracefile-size=$PAGE_SIZE --tracefile-count=2
500 enable_kernel_lttng_event_ok
$SESSION_NAME $EVENT_NAME $channel_name
501 start_lttng_tracing_ok
$SESSION_NAME
502 taskset
-c 0 echo -n "200000" > /proc
/lttng-test-filter-event
503 do_clear_session
$SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
504 stop_lttng_tracing_ok
$SESSION_NAME
506 if [[ $rotate_before -eq 1 ]]; then
507 validate_trace_count_range_incl_min_excl_max
$EVENT_NAME $local_path 1 200000
509 validate_trace_empty
$local_path
512 start_lttng_tracing_ok
$SESSION_NAME
513 taskset
-c 0 echo -n "400000" > /proc
/lttng-test-filter-event
514 stop_lttng_tracing_ok
516 if [[ $rotate_before -eq 1 ]]; then
517 validate_trace_count_range_incl_min_excl_max
$EVENT_NAME $local_path 1 600000
519 validate_trace_count_range_incl_min_excl_max
$EVENT_NAME $local_path 1 200000
522 destroy_lttng_session_ok
$SESSION_NAME
525 function test_kernel_disallow_clear
()
527 diag
"Test kernel disallow clear on relay daemon"
528 SESSION_NAME
=$
(randstring
16 0)
530 LTTNG_RELAYD_DISALLOW_CLEAR
=1 start_lttng_relayd
"-o $TRACE_PATH"
534 create_lttng_session_uri
$SESSION_NAME net
://localhost
535 enable_kernel_lttng_event_ok
$SESSION_NAME $EVENT_NAME
536 start_lttng_tracing_ok
$SESSION_NAME
537 lttng_clear_session_fail
$SESSION_NAME
538 destroy_lttng_session_ok
$SESSION_NAME
542 clean_path
$TRACE_PATH
545 plan_tests
$NUM_TESTS
547 print_test_banner
"$TEST_DESC"
549 if [ "$(id -u)" == "0" ]; then
555 streaming_tests
=(test_kernel_streaming
556 test_kernel_streaming_rotate_clear
557 test_kernel_streaming_clear_rotate
558 test_kernel_streaming_tracefile_rotation
559 test_kernel_streaming_tracefile_rotation_overwrite_files
562 live_tests
=(test_kernel_streaming_live
563 test_kernel_basic_streaming_live_viewer
564 test_kernel_streaming_live_viewer
567 local_tests
=(test_kernel_local
568 test_kernel_local_rotate_clear
569 test_kernel_local_clear_rotate
572 snapshot_tests
=(test_kernel_streaming_snapshot
573 test_kernel_local_snapshot
576 skip
$isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS ||
578 trap signal_cleanup SIGTERM SIGINT
580 validate_lttng_modules_present
582 start_lttng_relayd
"-o $TRACE_PATH"
586 # Clear with tracing active, clear once
587 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_tests[@]};
589 SESSION_NAME
=$
(randstring
16 0)
591 clean_path
$TRACE_PATH
594 # Clear with tracing active, clear twice
595 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_tests[@]};
597 SESSION_NAME
=$
(randstring
16 0)
599 clean_path
$TRACE_PATH
602 # Clear with tracing inactive, clear once
603 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_tests[@]};
605 SESSION_NAME
=$
(randstring
16 0)
607 clean_path
$TRACE_PATH
610 # Clear with tracing inactive, clear twice
611 for fct_test
in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_tests[@]};
613 SESSION_NAME
=$
(randstring
16 0)
615 clean_path
$TRACE_PATH
618 # Clear with tracing inactive, rotate-clear once
619 for fct_test
in ${streaming_tests[@]} ${local_tests[@]};
621 SESSION_NAME
=$
(randstring
16 0)
623 clean_path
$TRACE_PATH
626 # Clear with tracing inactive, clear once-rotate(fail)
627 for fct_test
in ${streaming_tests[@]} ${local_tests[@]};
629 SESSION_NAME
=$
(randstring
16 0)
631 clean_path
$TRACE_PATH
638 test_kernel_disallow_clear
641 clean_path
$TRACE_PATH