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