ff563100b2bf40c0796613298811fd9f2e780ebc
[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 function test_kernel_local_snapshot ()
33 {
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
43
44 # Validate test
45 validate_trace $EVENT_NAME $TRACE_PATH/
46 if [ $? -eq 0 ]; then
47 # Only delete if successful
48 rm -rf $TRACE_PATH
49 else
50 break
51 fi
52 }
53
54 function test_kernel_local_snapshot_after_stop ()
55 {
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
65
66 # Validate test
67 validate_trace $EVENT_NAME $TRACE_PATH/
68 if [ $? -eq 0 ]; then
69 # Only delete if successful
70 rm -rf $TRACE_PATH
71 else
72 break
73 fi
74 }
75
76 function test_kernel_local_snapshot_append_to_metadata ()
77 {
78 local EVENT1=sched_switch
79 local EVENT2=sched_process_exit
80
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
87
88 # first snapshot with only 1 event
89 lttng_snapshot_record $SESSION_NAME
90 validate_trace $EVENT_NAME $TRACE_PATH/
91 if [ $? -eq 0 ]; then
92 # Only delete if successful
93 rm -rf $TRACE_PATH
94 else
95 break
96 fi
97
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
106 rm -rf $TRACE_PATH
107 else
108 break
109 fi
110
111 stop_lttng_tracing_ok $SESSION_NAME
112 destroy_lttng_session_ok $SESSION_NAME
113 }
114
115 function true_loop_cpu0()
116 {
117 # Generate many system call events (fill buffers) on CPU 0
118 for a in $(seq 1 $1); do
119 taskset 0x00000001 /bin/true;
120 done
121 }
122
123 function test_kernel_local_snapshot_discard ()
124 {
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 \
128 $CHANNEL_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
132
133 true_loop_cpu0 10000
134
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"
139
140 rm -rf $TRACE_PATH
141
142 true_loop_cpu0 10000
143
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"
149 rm -rf $TRACE_PATH
150
151 if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then
152 fail "First snapshot event do not match."
153 else
154 pass "First snapshot event match."
155 fi
156
157 stop_lttng_tracing_ok $SESSION_NAME
158 destroy_lttng_session_ok $SESSION_NAME
159 }
160
161 function test_kernel_local_snapshot_overwrite_small_buffers ()
162 {
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 \
166 $CHANNEL_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
170
171 true_loop_cpu0 10000
172
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"
177
178 rm -rf $TRACE_PATH
179
180 true_loop_cpu0 10000
181
182 # Take 2nd snapshot, compare first line. In overwrite mode, they
183 # WILL be different.
184 lttng_snapshot_record $SESSION_NAME
185 FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)"
186 diag "First line (2nd snapshot): $FIRST_LINE_2"
187 rm -rf $TRACE_PATH
188
189 if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then
190 pass "First snapshot event do not match."
191 else
192 fail "First snapshot event match."
193 fi
194
195 stop_lttng_tracing_ok $SESSION_NAME
196 destroy_lttng_session_ok $SESSION_NAME
197 }
198
199 function test_kernel_1000_local_snapshots ()
200 {
201 NB_SNAP=1000
202
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
213 # Validate test
214 validate_trace $EVENT_NAME $TRACE_PATH/
215 if [ $? -eq 0 ]; then
216 # Only delete if successful
217 rm -rf $TRACE_PATH
218 else
219 break
220 fi
221 done
222 stop_lttng_tracing_ok $SESSION_NAME
223 destroy_lttng_session_ok $SESSION_NAME
224 }
225
226 plan_tests $NUM_TESTS
227
228 print_test_banner "$TEST_DESC"
229
230 if [ "$(id -u)" == "0" ]; then
231 isroot=1
232 else
233 isroot=0
234 fi
235
236 skip $isroot "Root access is needed. Skipping all kernel snapshot tests." $NUM_TESTS ||
237 {
238
239 validate_lttng_modules_present
240
241 start_lttng_sessiond
242
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
250 )
251
252 for fct_test in ${tests[@]};
253 do
254 SESSION_NAME=$(randstring 16 0)
255 ${fct_test}
256
257 done
258
259 stop_lttng_sessiond
260 }
This page took 0.034449 seconds and 3 git commands to generate.