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"
23 CHANNEL_NAME
="snapchan"
25 TRACE_PATH
=$
(mktemp
-d)
29 source $TESTDIR/utils
/utils.sh
31 function test_kernel_local_snapshot
()
33 diag
"Test local kernel snapshots"
34 create_lttng_session_no_output
$SESSION_NAME
35 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
36 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
37 start_lttng_tracing_ok
$SESSION_NAME
38 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
39 lttng_snapshot_record
$SESSION_NAME
40 stop_lttng_tracing_ok
$SESSION_NAME
41 destroy_lttng_session_ok
$SESSION_NAME
44 validate_trace
$EVENT_NAME $TRACE_PATH/
46 # Only delete if successful
53 function test_kernel_local_snapshot_after_stop
()
55 diag
"Test local kernel snapshots after stop"
56 create_lttng_session_no_output
$SESSION_NAME
57 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
58 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
59 start_lttng_tracing_ok
$SESSION_NAME
60 stop_lttng_tracing_ok
$SESSION_NAME
61 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
62 lttng_snapshot_record
$SESSION_NAME
63 destroy_lttng_session_ok
$SESSION_NAME
66 validate_trace
$EVENT_NAME $TRACE_PATH/
68 # Only delete if successful
75 function test_kernel_local_snapshot_append_to_metadata
()
77 local EVENT1
=sched_switch
78 local EVENT2
=sched_process_exit
80 diag
"Test local kernel snapshots with one event $EVENT1"
81 create_lttng_session_no_output
$SESSION_NAME
82 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
83 lttng_enable_kernel_event
$SESSION_NAME $EVENT1 $CHANNEL_NAME
84 start_lttng_tracing_ok
$SESSION_NAME
85 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
87 # first snapshot with only 1 event
88 lttng_snapshot_record
$SESSION_NAME
89 validate_trace
$EVENT_NAME $TRACE_PATH/
91 # Only delete if successful
97 diag
"Adding event $EVENT2"
98 # second snapshot with 2 events
99 lttng_enable_kernel_event
$SESSION_NAME $EVENT2 $CHANNEL_NAME
100 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
101 lttng_snapshot_record
$SESSION_NAME
102 validate_trace
"${EVENT1},${EVENT2}" $TRACE_PATH/
103 if [ $?
-eq 0 ]; then
104 # Only delete if successful
110 stop_lttng_tracing_ok
$SESSION_NAME
111 destroy_lttng_session_ok
$SESSION_NAME
114 function true_loop_cpu0
()
116 # Generate many system call events (fill buffers) on CPU 0
117 for a
in $
(seq 1 $1); do
118 taskset
0x00000001 /bin
/true
;
122 function test_kernel_local_snapshot_discard
()
124 diag
"Test local kernel snapshots with small discard buffers"
125 create_lttng_session_no_output
$SESSION_NAME
126 enable_lttng_mmap_discard_small_kernel_channel
$SESSION_NAME \
128 lttng_enable_kernel_syscall_ok
$SESSION_NAME -a $CHANNEL_NAME
129 start_lttng_tracing_ok
$SESSION_NAME
130 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
134 # Take first snapshot, remember first line.
135 lttng_snapshot_record
$SESSION_NAME
136 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
137 diag
"First line (1st snapshot): $FIRST_LINE"
143 # Take 2nd snapshot, compare first line. In discard mode, they
144 # should still be the same.
145 lttng_snapshot_record
$SESSION_NAME
146 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
147 diag
"First line (2nd snapshot): $FIRST_LINE"
150 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
151 fail
"First snapshot event do not match."
153 pass
"First snapshot event match."
156 stop_lttng_tracing_ok
$SESSION_NAME
157 destroy_lttng_session_ok
$SESSION_NAME
160 function test_kernel_local_snapshot_overwrite_small_buffers
()
162 diag
"Test local kernel snapshot with small overwrite buffers"
163 create_lttng_session_no_output
$SESSION_NAME
164 enable_lttng_mmap_overwrite_small_kernel_channel
$SESSION_NAME \
166 lttng_enable_kernel_syscall_ok
$SESSION_NAME -a $CHANNEL_NAME
167 start_lttng_tracing_ok
$SESSION_NAME
168 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
172 # Take first snapshot, remember first line.
173 lttng_snapshot_record
$SESSION_NAME
174 FIRST_LINE
="$(trace_first_line $TRACE_PATH/)"
175 diag
"First line (1st snapshot): $FIRST_LINE"
181 # Take 2nd snapshot, compare first line. In overwrite mode, they
183 lttng_snapshot_record
$SESSION_NAME
184 FIRST_LINE_2
="$(trace_first_line $TRACE_PATH/)"
185 diag
"First line (2nd snapshot): $FIRST_LINE_2"
188 if [ x
"$FIRST_LINE" != x
"$FIRST_LINE_2" ]; then
189 pass
"First snapshot event do not match."
191 fail
"First snapshot event match."
194 stop_lttng_tracing_ok
$SESSION_NAME
195 destroy_lttng_session_ok
$SESSION_NAME
198 function test_kernel_1000_local_snapshots
()
202 diag
"Test local kernel snapshots"
203 create_lttng_session_no_output
$SESSION_NAME
204 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
205 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
206 start_lttng_tracing_ok
$SESSION_NAME
207 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
208 for i
in $
(seq 1 $NB_SNAP); do
209 diag
"Snapshot $i/$NB_SNAP"
210 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
211 lttng_snapshot_record
$SESSION_NAME
213 validate_trace
$EVENT_NAME $TRACE_PATH/
214 if [ $?
-eq 0 ]; then
215 # Only delete if successful
221 stop_lttng_tracing_ok
$SESSION_NAME
222 destroy_lttng_session_ok
$SESSION_NAME
225 plan_tests
$NUM_TESTS
227 print_test_banner
"$TEST_DESC"
229 if [ "$(id -u)" == "0" ]; then
235 skip
$isroot "Root access is needed. Skipping all kernel snapshot tests." $NUM_TESTS ||
238 validate_lttng_modules_present
242 #tests=( test_kernel_1000_local_snapshots )
243 tests
=( test_kernel_local_snapshot
244 test_kernel_local_snapshot_after_stop
245 test_kernel_local_snapshot_append_to_metadata
246 test_kernel_local_snapshot_discard
247 test_kernel_local_snapshot_overwrite_small_buffers
248 test_kernel_1000_local_snapshots
251 for fct_test
in ${tests[@]};
253 SESSION_NAME
=$
(randstring
16 0)