3 # Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 TEST_DESC
="Snapshots - Kernel tracing"
10 TESTDIR
=$CURDIR/..
/..
/..
11 EVENT_NAME
="sched_switch"
13 CHANNEL_NAME
="snapchan"
15 TRACE_PATH
=$
(mktemp
--tmpdir -d tmp.test_snapshots_kernel_trace_path.XXXXXX
)
19 source $TESTDIR/utils
/utils.sh
21 function test_kernel_local_snapshot
()
23 diag
"Test local kernel snapshots"
24 create_lttng_session_no_output
$SESSION_NAME
25 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
26 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
27 start_lttng_tracing_ok
$SESSION_NAME
28 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
29 lttng_snapshot_record
$SESSION_NAME
30 stop_lttng_tracing_ok
$SESSION_NAME
31 destroy_lttng_session_ok
$SESSION_NAME
34 validate_trace_path_kernel_snapshot
"$TRACE_PATH" "" "snapshot-1" 0 ""
35 validate_trace
$EVENT_NAME $TRACE_PATH/
37 # Only delete if successful
42 function test_kernel_local_snapshot_after_stop
()
44 diag
"Test local kernel snapshots after stop"
45 create_lttng_session_no_output
$SESSION_NAME
46 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
47 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
48 start_lttng_tracing_ok
$SESSION_NAME
49 stop_lttng_tracing_ok
$SESSION_NAME
50 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
51 lttng_snapshot_record
$SESSION_NAME
52 destroy_lttng_session_ok
$SESSION_NAME
55 validate_trace
$EVENT_NAME $TRACE_PATH/
57 # Only delete if successful
64 function test_kernel_local_snapshot_append_to_metadata
()
66 local EVENT1
=sched_switch
67 local EVENT2
=sched_process_exit
69 diag
"Test local kernel snapshots with one event $EVENT1"
70 create_lttng_session_no_output
$SESSION_NAME
71 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
72 lttng_enable_kernel_event
$SESSION_NAME $EVENT1 $CHANNEL_NAME
73 start_lttng_tracing_ok
$SESSION_NAME
74 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
76 # first snapshot with only 1 event
77 lttng_snapshot_record
$SESSION_NAME
78 validate_trace
$EVENT_NAME $TRACE_PATH/
80 # Only delete if successful
86 diag
"Adding event $EVENT2"
87 # second snapshot with 2 events
88 lttng_enable_kernel_event
$SESSION_NAME $EVENT2 $CHANNEL_NAME
89 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
90 lttng_snapshot_record
$SESSION_NAME
91 validate_trace
"${EVENT1},${EVENT2}" $TRACE_PATH/
93 # Only delete if successful
99 stop_lttng_tracing_ok
$SESSION_NAME
100 destroy_lttng_session_ok
$SESSION_NAME
103 function true_loop_cpu0
()
105 # Generate many system call events (fill buffers) on CPU 0
106 for a
in $
(seq 1 $1); do
107 taskset
0x00000001 /bin
/true
;
111 function test_kernel_local_snapshot_discard
()
113 diag
"Test local kernel snapshots with small discard buffers"
114 create_lttng_session_no_output
$SESSION_NAME
115 enable_lttng_mmap_discard_small_kernel_channel
$SESSION_NAME \
117 lttng_enable_kernel_syscall_ok
$SESSION_NAME -a $CHANNEL_NAME
118 start_lttng_tracing_ok
$SESSION_NAME
119 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
123 # Take first snapshot, remember first line.
124 lttng_snapshot_record
$SESSION_NAME
125 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
126 diag
"First line (1st snapshot): $FIRST_LINE"
132 # Take 2nd snapshot, compare first line. In discard mode, they
133 # should still be the same.
134 lttng_snapshot_record
$SESSION_NAME
135 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
136 diag
"First line (2nd snapshot): $FIRST_LINE"
139 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
140 fail
"First snapshot event do not match"
142 pass
"First snapshot event match"
145 stop_lttng_tracing_ok
$SESSION_NAME
146 destroy_lttng_session_ok
$SESSION_NAME
149 function test_kernel_local_snapshot_overwrite_small_buffers
()
151 diag
"Test local kernel snapshot with small overwrite buffers"
152 create_lttng_session_no_output
$SESSION_NAME
153 enable_lttng_mmap_overwrite_small_kernel_channel
$SESSION_NAME \
155 lttng_enable_kernel_syscall_ok
$SESSION_NAME -a $CHANNEL_NAME
156 start_lttng_tracing_ok
$SESSION_NAME
157 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
161 # Take first snapshot, remember first line.
162 lttng_snapshot_record
$SESSION_NAME
163 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
164 diag
"First line (1st snapshot): $FIRST_LINE"
170 # Take 2nd snapshot, compare first line. In overwrite mode, they
172 lttng_snapshot_record
$SESSION_NAME
173 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
174 diag
"First line (2nd snapshot): $FIRST_LINE_2"
177 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
178 pass
"First snapshot event do not match"
180 fail
"First snapshot event match"
183 stop_lttng_tracing_ok
$SESSION_NAME
184 destroy_lttng_session_ok
$SESSION_NAME
187 function test_kernel_1000_local_snapshots
()
191 diag
"Test local kernel snapshots"
192 create_lttng_session_no_output
$SESSION_NAME
193 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
194 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
195 start_lttng_tracing_ok
$SESSION_NAME
196 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
197 for i
in $
(seq 1 $NB_SNAP); do
198 diag
"Snapshot $i/$NB_SNAP"
199 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
200 lttng_snapshot_record
$SESSION_NAME
202 validate_trace
$EVENT_NAME $TRACE_PATH/
203 if [ $?
-eq 0 ]; then
204 # Only delete if successful
210 stop_lttng_tracing_ok
$SESSION_NAME
211 destroy_lttng_session_ok
$SESSION_NAME
214 plan_tests
$NUM_TESTS
216 print_test_banner
"$TEST_DESC"
218 bail_out_if_no_babeltrace
221 if [ "$(id -u)" == "0" ]; then
227 skip
$isroot "Root access is needed. Skipping all kernel snapshot tests" $NUM_TESTS ||
230 validate_lttng_modules_present
234 #tests=( test_kernel_1000_local_snapshots )
235 tests
=( test_kernel_local_snapshot
236 test_kernel_local_snapshot_after_stop
237 test_kernel_local_snapshot_append_to_metadata
238 test_kernel_local_snapshot_discard
239 test_kernel_local_snapshot_overwrite_small_buffers
240 test_kernel_1000_local_snapshots
243 for fct_test
in ${tests[@]};
245 SESSION_NAME
=$
(randstring
16 0)