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 # LTTng kernel modules check
33 out
=`ls /lib/modules/$(uname -r)/extra | grep lttng`
34 if [ -z "$out" ]; then
35 BAIL_OUT
"LTTng modules not detected."
38 function test_kernel_local_snapshot
()
40 diag
"Test local kernel snapshots"
41 create_lttng_session_no_output
$SESSION_NAME
42 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
43 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
44 start_lttng_tracing_ok
$SESSION_NAME
45 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
46 lttng_snapshot_record
$SESSION_NAME
47 stop_lttng_tracing_ok
$SESSION_NAME
48 destroy_lttng_session_ok
$SESSION_NAME
51 validate_trace
$EVENT_NAME $TRACE_PATH/
53 # Only delete if successful
60 function test_kernel_local_snapshot_after_stop
()
62 diag
"Test local kernel snapshots after stop"
63 create_lttng_session_no_output
$SESSION_NAME
64 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
65 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
66 start_lttng_tracing_ok
$SESSION_NAME
67 stop_lttng_tracing_ok
$SESSION_NAME
68 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
69 lttng_snapshot_record
$SESSION_NAME
70 destroy_lttng_session_ok
$SESSION_NAME
73 validate_trace
$EVENT_NAME $TRACE_PATH/
75 # Only delete if successful
82 function test_kernel_local_snapshot_append_to_metadata
()
84 local EVENT1
=sched_switch
85 local EVENT2
=sched_process_exit
87 diag
"Test local kernel snapshots with one event $EVENT1"
88 create_lttng_session_no_output
$SESSION_NAME
89 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
90 lttng_enable_kernel_event
$SESSION_NAME $EVENT1 $CHANNEL_NAME
91 start_lttng_tracing_ok
$SESSION_NAME
92 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
94 # first snapshot with only 1 event
95 lttng_snapshot_record
$SESSION_NAME
96 validate_trace
$EVENT_NAME $TRACE_PATH/
98 # Only delete if successful
104 diag
"Adding event $EVENT2"
105 # second snapshot with 2 events
106 lttng_enable_kernel_event
$SESSION_NAME $EVENT2 $CHANNEL_NAME
107 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
108 lttng_snapshot_record
$SESSION_NAME
109 validate_trace
"${EVENT1},${EVENT2}" $TRACE_PATH/
110 if [ $?
-eq 0 ]; then
111 # Only delete if successful
117 stop_lttng_tracing_ok
$SESSION_NAME
118 destroy_lttng_session_ok
$SESSION_NAME
121 function true_loop_cpu0
()
123 # Generate many system call events (fill buffers) on CPU 0
124 for a
in $
(seq 1 $1); do
125 taskset
0x00000001 /bin
/true
;
129 function test_kernel_local_snapshot_discard
()
131 diag
"Test local kernel snapshots with small discard buffers"
132 create_lttng_session_no_output
$SESSION_NAME
133 enable_lttng_mmap_discard_small_kernel_channel
$SESSION_NAME \
135 lttng_enable_kernel_syscall_ok
$SESSION_NAME -a $CHANNEL_NAME
136 start_lttng_tracing_ok
$SESSION_NAME
137 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
141 # Take first snapshot, remember first line.
142 lttng_snapshot_record
$SESSION_NAME
143 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
144 diag
"First line (1st snapshot): $FIRST_LINE"
150 # Take 2nd snapshot, compare first line. In discard mode, they
151 # should still be the same.
152 lttng_snapshot_record
$SESSION_NAME
153 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
154 diag
"First line (2nd snapshot): $FIRST_LINE"
157 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
158 fail
"First snapshot event do not match."
160 pass
"First snapshot event match."
163 stop_lttng_tracing_ok
$SESSION_NAME
164 destroy_lttng_session_ok
$SESSION_NAME
167 function test_kernel_local_snapshot_overwrite_small_buffers
()
169 diag
"Test local kernel snapshot with small overwrite buffers"
170 create_lttng_session_no_output
$SESSION_NAME
171 enable_lttng_mmap_overwrite_small_kernel_channel
$SESSION_NAME \
173 lttng_enable_kernel_syscall_ok
$SESSION_NAME -a $CHANNEL_NAME
174 start_lttng_tracing_ok
$SESSION_NAME
175 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
179 # Take first snapshot, remember first line.
180 lttng_snapshot_record
$SESSION_NAME
181 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
182 diag
"First line (1st snapshot): $FIRST_LINE"
188 # Take 2nd snapshot, compare first line. In overwrite mode, they
190 lttng_snapshot_record
$SESSION_NAME
191 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
192 diag
"First line (2nd snapshot): $FIRST_LINE_2"
195 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
196 pass
"First snapshot event do not match."
198 fail
"First snapshot event match."
201 stop_lttng_tracing_ok
$SESSION_NAME
202 destroy_lttng_session_ok
$SESSION_NAME
205 function test_kernel_1000_local_snapshots
()
209 diag
"Test local kernel snapshots"
210 create_lttng_session_no_output
$SESSION_NAME
211 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
212 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
213 start_lttng_tracing_ok
$SESSION_NAME
214 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
215 for i
in $
(seq 1 $NB_SNAP); do
216 diag
"Snapshot $i/$NB_SNAP"
217 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
218 lttng_snapshot_record
$SESSION_NAME
220 validate_trace
$EVENT_NAME $TRACE_PATH/
221 if [ $?
-eq 0 ]; then
222 # Only delete if successful
228 stop_lttng_tracing_ok
$SESSION_NAME
229 destroy_lttng_session_ok
$SESSION_NAME
232 plan_tests
$NUM_TESTS
234 print_test_banner
"$TEST_DESC"
236 if [ "$(id -u)" == "0" ]; then
242 skip
$isroot "Root access is needed. Skipping all kernel snapshot tests." $NUM_TESTS ||
246 #tests=( test_kernel_1000_local_snapshots )
247 tests
=( test_kernel_local_snapshot
248 test_kernel_local_snapshot_after_stop
249 test_kernel_local_snapshot_append_to_metadata
250 test_kernel_local_snapshot_discard
251 test_kernel_local_snapshot_overwrite_small_buffers
252 test_kernel_1000_local_snapshots
255 for fct_test
in ${tests[@]};
257 SESSION_NAME
=$
(randstring
16 0)