3 # Copyright (C) - 2013 Julien Desfossez <jdesfossez@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
17 TEST_DESC
="Snapshots - Kernel tracing"
20 TESTDIR
=$CURDIR/..
/..
/..
21 EVENT_NAME
="sched_switch"
24 CHANNEL_NAME
="snapchan"
26 TRACE_PATH
=$
(mktemp
-d)
30 source $TESTDIR/utils
/utils.sh
32 function test_kernel_local_snapshot
()
34 diag
"Test local kernel snapshots"
35 create_lttng_session_no_output
$SESSION_NAME
36 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
37 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
38 start_lttng_tracing_ok
$SESSION_NAME
39 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
40 lttng_snapshot_record
$SESSION_NAME
41 stop_lttng_tracing_ok
$SESSION_NAME
42 destroy_lttng_session_ok
$SESSION_NAME
45 validate_trace
$EVENT_NAME $TRACE_PATH/
47 # Only delete if successful
54 function test_kernel_local_snapshot_after_stop
()
56 diag
"Test local kernel snapshots after stop"
57 create_lttng_session_no_output
$SESSION_NAME
58 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
59 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
60 start_lttng_tracing_ok
$SESSION_NAME
61 stop_lttng_tracing_ok
$SESSION_NAME
62 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
63 lttng_snapshot_record
$SESSION_NAME
64 destroy_lttng_session_ok
$SESSION_NAME
67 validate_trace
$EVENT_NAME $TRACE_PATH/
69 # Only delete if successful
76 function test_kernel_local_snapshot_append_to_metadata
()
78 local EVENT1
=sched_switch
79 local EVENT2
=sched_process_exit
81 diag
"Test local kernel snapshots with one event $EVENT1"
82 create_lttng_session_no_output
$SESSION_NAME
83 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
84 lttng_enable_kernel_event
$SESSION_NAME $EVENT1 $CHANNEL_NAME
85 start_lttng_tracing_ok
$SESSION_NAME
86 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
88 # first snapshot with only 1 event
89 lttng_snapshot_record
$SESSION_NAME
90 validate_trace
$EVENT_NAME $TRACE_PATH/
92 # Only delete if successful
98 diag
"Adding event $EVENT2"
99 # second snapshot with 2 events
100 lttng_enable_kernel_event
$SESSION_NAME $EVENT2 $CHANNEL_NAME
101 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
102 lttng_snapshot_record
$SESSION_NAME
103 validate_trace
"${EVENT1},${EVENT2}" $TRACE_PATH/
104 if [ $?
-eq 0 ]; then
105 # Only delete if successful
111 stop_lttng_tracing_ok
$SESSION_NAME
112 destroy_lttng_session_ok
$SESSION_NAME
115 function true_loop_cpu0
()
117 # Generate many system call events (fill buffers) on CPU 0
118 for a
in $
(seq 1 $1); do
119 taskset
0x00000001 /bin
/true
;
123 function test_kernel_local_snapshot_discard
()
125 diag
"Test local kernel snapshots with small discard buffers"
126 create_lttng_session_no_output
$SESSION_NAME
127 enable_lttng_mmap_discard_small_kernel_channel
$SESSION_NAME \
129 lttng_enable_kernel_syscall_ok
$SESSION_NAME -a $CHANNEL_NAME
130 start_lttng_tracing_ok
$SESSION_NAME
131 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
135 # Take first snapshot, remember first line.
136 lttng_snapshot_record
$SESSION_NAME
137 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
138 diag
"First line (1st snapshot): $FIRST_LINE"
144 # Take 2nd snapshot, compare first line. In discard mode, they
145 # should still be the same.
146 lttng_snapshot_record
$SESSION_NAME
147 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
148 diag
"First line (2nd snapshot): $FIRST_LINE"
151 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
152 fail
"First snapshot event do not match."
154 pass
"First snapshot event match."
157 stop_lttng_tracing_ok
$SESSION_NAME
158 destroy_lttng_session_ok
$SESSION_NAME
161 function test_kernel_local_snapshot_overwrite_small_buffers
()
163 diag
"Test local kernel snapshot with small overwrite buffers"
164 create_lttng_session_no_output
$SESSION_NAME
165 enable_lttng_mmap_overwrite_small_kernel_channel
$SESSION_NAME \
167 lttng_enable_kernel_syscall_ok
$SESSION_NAME -a $CHANNEL_NAME
168 start_lttng_tracing_ok
$SESSION_NAME
169 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
173 # Take first snapshot, remember first line.
174 lttng_snapshot_record
$SESSION_NAME
175 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
176 diag
"First line (1st snapshot): $FIRST_LINE"
182 # Take 2nd snapshot, compare first line. In overwrite mode, they
184 lttng_snapshot_record
$SESSION_NAME
185 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
186 diag
"First line (2nd snapshot): $FIRST_LINE_2"
189 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
190 pass
"First snapshot event do not match."
192 fail
"First snapshot event match."
195 stop_lttng_tracing_ok
$SESSION_NAME
196 destroy_lttng_session_ok
$SESSION_NAME
199 function test_kernel_1000_local_snapshots
()
203 diag
"Test local kernel snapshots"
204 create_lttng_session_no_output
$SESSION_NAME
205 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
206 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
207 start_lttng_tracing_ok
$SESSION_NAME
208 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
209 for i
in $
(seq 1 $NB_SNAP); do
210 diag
"Snapshot $i/$NB_SNAP"
211 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
212 lttng_snapshot_record
$SESSION_NAME
214 validate_trace
$EVENT_NAME $TRACE_PATH/
215 if [ $?
-eq 0 ]; then
216 # Only delete if successful
222 stop_lttng_tracing_ok
$SESSION_NAME
223 destroy_lttng_session_ok
$SESSION_NAME
226 plan_tests
$NUM_TESTS
228 print_test_banner
"$TEST_DESC"
230 if [ "$(id -u)" == "0" ]; then
236 skip
$isroot "Root access is needed. Skipping all kernel snapshot tests." $NUM_TESTS ||
239 validate_lttng_modules_present
243 #tests=( test_kernel_1000_local_snapshots )
244 tests
=( test_kernel_local_snapshot
245 test_kernel_local_snapshot_after_stop
246 test_kernel_local_snapshot_append_to_metadata
247 test_kernel_local_snapshot_discard
248 test_kernel_local_snapshot_overwrite_small_buffers
249 test_kernel_1000_local_snapshots
252 for fct_test
in ${tests[@]};
254 SESSION_NAME
=$
(randstring
16 0)