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
-d -t 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
62 function test_kernel_local_snapshot_append_to_metadata
()
64 local EVENT1
=sched_switch
65 local EVENT2
=sched_process_exit
67 diag
"Test local kernel snapshots with one event $EVENT1"
68 create_lttng_session_no_output
$SESSION_NAME
69 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
70 lttng_enable_kernel_event
$SESSION_NAME $EVENT1 $CHANNEL_NAME
71 start_lttng_tracing_ok
$SESSION_NAME
72 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
74 # first snapshot with only 1 event
75 lttng_snapshot_record
$SESSION_NAME
76 validate_trace
$EVENT_NAME $TRACE_PATH/
78 # Only delete if successful
82 diag
"Adding event $EVENT2"
83 # second snapshot with 2 events
84 lttng_enable_kernel_event
$SESSION_NAME $EVENT2 $CHANNEL_NAME
85 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
86 lttng_snapshot_record
$SESSION_NAME
87 validate_trace
"${EVENT1},${EVENT2}" $TRACE_PATH/
89 # Only delete if successful
93 stop_lttng_tracing_ok
$SESSION_NAME
94 destroy_lttng_session_ok
$SESSION_NAME
97 function generate_filter_events_cpu0
()
99 # Generate many events (fill buffers) on a single CPU
100 taskset
--cpu-list "$(get_any_available_cpu)" /bin
/echo -n "$1" > /proc
/lttng-test-filter-event
2> /dev
/null
103 function test_kernel_local_snapshot_discard
()
105 diag
"Test local kernel snapshots with small discard buffers"
107 local event_name
="lttng_test_filter_event"
110 create_lttng_session_no_output
$SESSION_NAME
111 enable_lttng_mmap_discard_small_kernel_channel
$SESSION_NAME \
113 enable_kernel_lttng_event_ok
$SESSION_NAME $event_name $CHANNEL_NAME
114 start_lttng_tracing_ok
$SESSION_NAME
115 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
117 generate_filter_events_cpu0
10000
119 # Take first snapshot, remember first line.
120 lttng_snapshot_record
$SESSION_NAME
121 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
122 diag
"First line (1st snapshot): $FIRST_LINE"
126 # Fill CPU 0's buffer and overwrite previous contents
127 generate_filter_events_cpu0
10000
129 # Take 2nd snapshot, compare first line. In discard mode, they
130 # should still be the same.
131 lttng_snapshot_record
$SESSION_NAME
132 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
133 diag
"First line (2nd snapshot): $FIRST_LINE"
136 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
137 fail
"First snapshot event do not match"
139 pass
"First snapshot event match"
142 stop_lttng_tracing_ok
$SESSION_NAME
143 destroy_lttng_session_ok
$SESSION_NAME
144 modprobe
--remove lttng-test
147 function test_kernel_local_snapshot_overwrite_small_buffers
()
149 diag
"Test local kernel snapshot with small overwrite buffers"
151 local event_name
="lttng_test_filter_event"
154 create_lttng_session_no_output
$SESSION_NAME
155 enable_lttng_mmap_overwrite_small_kernel_channel
$SESSION_NAME \
157 enable_kernel_lttng_event_ok
$SESSION_NAME $event_name $CHANNEL_NAME
158 start_lttng_tracing_ok
$SESSION_NAME
159 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
161 generate_filter_events_cpu0
10000
163 # Take first snapshot, remember first line.
164 lttng_snapshot_record
$SESSION_NAME
165 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
166 diag
"First line (1st snapshot): $FIRST_LINE"
170 # Fill CPU 0's buffer and overwrite previous contents
171 generate_filter_events_cpu0
10000
173 # Take 2nd snapshot, compare first line. In overwrite mode, they
175 lttng_snapshot_record
$SESSION_NAME
176 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
177 diag
"First line (2nd snapshot): $FIRST_LINE_2"
180 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
181 pass
"First snapshot event do not match"
183 fail
"First snapshot event match"
186 stop_lttng_tracing_ok
$SESSION_NAME
187 destroy_lttng_session_ok
$SESSION_NAME
188 modprobe
--remove lttng-test
191 function test_kernel_1000_local_snapshots
()
195 diag
"Test local kernel snapshots"
196 create_lttng_session_no_output
$SESSION_NAME
197 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
198 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
199 start_lttng_tracing_ok
$SESSION_NAME
200 lttng_snapshot_add_output_ok
$SESSION_NAME file://$TRACE_PATH
201 for i
in $
(seq 1 $NB_SNAP); do
202 diag
"Snapshot $i/$NB_SNAP"
203 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
204 lttng_snapshot_record
$SESSION_NAME
206 validate_trace
$EVENT_NAME $TRACE_PATH/
207 if [ $?
-eq 0 ]; then
208 # Only delete if successful
214 stop_lttng_tracing_ok
$SESSION_NAME
215 destroy_lttng_session_ok
$SESSION_NAME
218 plan_tests
$NUM_TESTS
220 print_test_banner
"$TEST_DESC"
222 bail_out_if_no_babeltrace
224 check_skip_kernel_test
"$NUM_TESTS" "Skipping all tests." ||
227 validate_lttng_modules_present
231 #tests=( test_kernel_1000_local_snapshots )
232 tests
=( test_kernel_local_snapshot
233 test_kernel_local_snapshot_after_stop
234 test_kernel_local_snapshot_append_to_metadata
235 test_kernel_local_snapshot_discard
236 test_kernel_local_snapshot_overwrite_small_buffers
237 test_kernel_1000_local_snapshots
240 for fct_test
in ${tests[@]};
242 SESSION_NAME
=$
(randstring
16 0)