tests: test kernel snapshot with discard buffers
[lttng-tools.git] / tests / regression / tools / snapshots / test_kernel
1 #!/bin/bash
2 #
3 # Copyright (C) - 2013 Julien Desfossez <jdesfossez@efficios.com>
4 #
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.
8 #
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
12 # details.
13 #
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"
18
19 CURDIR=$(dirname $0)/
20 TESTDIR=$CURDIR/../../..
21 EVENT_NAME="sched_switch"
22 PID_RELAYD=0
23 SESSION_NAME=""
24 CHANNEL_NAME="snapchan"
25
26 TRACE_PATH=$(mktemp -d)
27
28 NUM_TESTS=2060
29
30 source $TESTDIR/utils/utils.sh
31
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."
36 fi
37
38 function test_kernel_local_snapshot ()
39 {
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
49
50 # Validate test
51 validate_trace $EVENT_NAME $TRACE_PATH/
52 if [ $? -eq 0 ]; then
53 # Only delete if successful
54 rm -rf $TRACE_PATH
55 else
56 break
57 fi
58 }
59
60 function test_kernel_local_snapshot_after_stop ()
61 {
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
71
72 # Validate test
73 validate_trace $EVENT_NAME $TRACE_PATH/
74 if [ $? -eq 0 ]; then
75 # Only delete if successful
76 rm -rf $TRACE_PATH
77 else
78 break
79 fi
80 }
81
82 function test_kernel_local_snapshot_append_to_metadata ()
83 {
84 local EVENT1=sched_switch
85 local EVENT2=sched_process_exit
86
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
93
94 # first snapshot with only 1 event
95 lttng_snapshot_record $SESSION_NAME
96 validate_trace $EVENT_NAME $TRACE_PATH/
97 if [ $? -eq 0 ]; then
98 # Only delete if successful
99 rm -rf $TRACE_PATH
100 else
101 break
102 fi
103
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
112 rm -rf $TRACE_PATH
113 else
114 break
115 fi
116
117 stop_lttng_tracing_ok $SESSION_NAME
118 destroy_lttng_session_ok $SESSION_NAME
119 }
120
121 function true_loop_cpu0()
122 {
123 # Generate many system call events (fill buffers) on CPU 0
124 for a in $(seq 1 $1); do
125 taskset 0x00000001 /bin/true;
126 done
127 }
128
129 function test_kernel_local_snapshot_discard ()
130 {
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 \
134 $CHANNEL_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
138
139 true_loop_cpu0 10000
140
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"
145
146 rm -rf $TRACE_PATH
147
148 true_loop_cpu0 10000
149
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"
155 rm -rf $TRACE_PATH
156
157 if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then
158 fail "First snapshot event do not match."
159 else
160 pass "First snapshot event match."
161 fi
162
163 stop_lttng_tracing_ok $SESSION_NAME
164 destroy_lttng_session_ok $SESSION_NAME
165 }
166
167 function test_kernel_local_snapshot_overwrite_small_buffers ()
168 {
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 \
172 $CHANNEL_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
176
177 true_loop_cpu0 10000
178
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"
183
184 rm -rf $TRACE_PATH
185
186 true_loop_cpu0 10000
187
188 # Take 2nd snapshot, compare first line. In overwrite mode, they
189 # WILL be different.
190 lttng_snapshot_record $SESSION_NAME
191 FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)"
192 diag "First line (2nd snapshot): $FIRST_LINE_2"
193 rm -rf $TRACE_PATH
194
195 if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then
196 pass "First snapshot event do not match."
197 else
198 fail "First snapshot event match."
199 fi
200
201 stop_lttng_tracing_ok $SESSION_NAME
202 destroy_lttng_session_ok $SESSION_NAME
203 }
204
205 function test_kernel_1000_local_snapshots ()
206 {
207 NB_SNAP=1000
208
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
219 # Validate test
220 validate_trace $EVENT_NAME $TRACE_PATH/
221 if [ $? -eq 0 ]; then
222 # Only delete if successful
223 rm -rf $TRACE_PATH
224 else
225 break
226 fi
227 done
228 stop_lttng_tracing_ok $SESSION_NAME
229 destroy_lttng_session_ok $SESSION_NAME
230 }
231
232 plan_tests $NUM_TESTS
233
234 print_test_banner "$TEST_DESC"
235
236 if [ "$(id -u)" == "0" ]; then
237 isroot=1
238 else
239 isroot=0
240 fi
241
242 skip $isroot "Root access is needed. Skipping all kernel snapshot tests." $NUM_TESTS ||
243 {
244 start_lttng_sessiond
245
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
253 )
254
255 for fct_test in ${tests[@]};
256 do
257 SESSION_NAME=$(randstring 16 0)
258 ${fct_test}
259
260 done
261
262 stop_lttng_sessiond
263 }
This page took 0.051209 seconds and 4 git commands to generate.