Commit | Line | Data |
---|---|---|
10a8a223 | 1 | #!/src/bin/bash |
d3e8f6bb DG |
2 | # |
3 | # Copyright (C) - 2012 David Goulet <dgoulet@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 | ||
18 | SESSIOND_BIN="lttng-sessiond" | |
f4e40ab6 | 19 | RELAYD_BIN="lttng-relayd" |
d3e8f6bb DG |
20 | LTTNG_BIN="lttng" |
21 | BABELTRACE_BIN="babeltrace" | |
22 | ||
fd4dfcec DG |
23 | # Minimal kernel version supported for session daemon tests |
24 | KERNEL_MAJOR_VERSION=2 | |
25 | KERNEL_MINOR_VERSION=6 | |
26 | KERNEL_PATCHLEVEL_VERSION=27 | |
27 | ||
fec81a7e CB |
28 | function print_ok () |
29 | { | |
30 | # Check if we are a terminal | |
31 | if [ -t 1 ]; then | |
32 | echo -e "\e[1;32mOK\e[0m" | |
33 | else | |
34 | echo -e "OK" | |
35 | fi | |
36 | } | |
37 | ||
38 | function print_fail () | |
39 | { | |
40 | # Check if we are a terminal | |
41 | if [ -t 1 ]; then | |
42 | echo -e "\e[1;31mFAIL\e[0m" | |
43 | else | |
44 | echo -e "FAIL" | |
45 | fi | |
46 | } | |
47 | ||
48 | function print_test_banner () | |
49 | { | |
50 | desc="$1" | |
51 | ||
52 | count=$((${#desc}+2)) | |
53 | str=$(printf "%${count}s"); | |
54 | echo -e "\n" | |
55 | echo -e ${str// /-} | |
56 | echo -e " $desc " | |
57 | echo -e ${str// /-} | |
58 | } | |
59 | ||
fd4dfcec DG |
60 | function validate_kernel_version () |
61 | { | |
62 | kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n')) | |
63 | if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then | |
64 | return 0 | |
65 | fi | |
66 | if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then | |
67 | return 0 | |
68 | fi | |
69 | if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then | |
70 | return 0 | |
71 | fi | |
72 | return 1 | |
73 | } | |
74 | ||
f4e40ab6 DG |
75 | # Generate a random string |
76 | # $1 = number of characters; defaults to 16 | |
77 | # $2 = include special characters; 1 = yes, 0 = no; defaults to yes | |
78 | function randstring() | |
79 | { | |
80 | [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]" | |
81 | cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-16} | |
82 | echo | |
83 | } | |
84 | ||
355f483d | 85 | function spawn_sessiond () |
d3e8f6bb | 86 | { |
317eef93 DG |
87 | echo "" |
88 | echo -n "Starting session daemon... " | |
fd4dfcec DG |
89 | validate_kernel_version |
90 | if [ $? -ne 0 ]; then | |
fbb28ea9 | 91 | echo -e "\n*** Kernel too old for session daemon tests ***\n" |
fd4dfcec DG |
92 | return 2 |
93 | fi | |
94 | ||
2e6a03f6 | 95 | DIR=$(readlink -f $TESTDIR) |
355f483d | 96 | |
317eef93 | 97 | if [ -z $(pidof lt-$SESSIOND_BIN) ]; then |
355f483d | 98 | $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --daemonize --quiet --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" |
25a818af | 99 | #$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --verbose-consumer >>/tmp/sessiond.log 2>&1 & |
d3e8f6bb | 100 | if [ $? -eq 1 ]; then |
c38b5107 | 101 | print_fail |
d3e8f6bb DG |
102 | return 1 |
103 | else | |
c38b5107 | 104 | print_ok |
d3e8f6bb DG |
105 | fi |
106 | fi | |
fd4dfcec DG |
107 | |
108 | return 0 | |
d3e8f6bb DG |
109 | } |
110 | ||
f4e40ab6 DG |
111 | function lttng_enable_kernel_event |
112 | { | |
113 | sess_name=$1 | |
114 | event_name=$2 | |
115 | ||
116 | if [ -z $event_name ]; then | |
117 | # Enable all event if no event name specified | |
118 | $event_name="-a" | |
119 | fi | |
120 | ||
121 | echo -n "Enabling kernel event $event_name for session $sess_name" | |
907b42de | 122 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -k >/dev/null 2>&1 |
f4e40ab6 | 123 | if [ $? -eq 1 ]; then |
c38b5107 | 124 | print_fail |
f4e40ab6 DG |
125 | return 1 |
126 | else | |
c38b5107 | 127 | print_ok |
f4e40ab6 DG |
128 | fi |
129 | } | |
130 | ||
fb3268e3 | 131 | function start_lttng_relayd |
f4e40ab6 | 132 | { |
198e7caf | 133 | local opt=$1 |
173af62f DG |
134 | |
135 | echo -e -n "Starting lttng-relayd (opt: $opt)... " | |
136 | ||
f4e40ab6 DG |
137 | DIR=$(readlink -f $TESTDIR) |
138 | ||
139 | if [ -z $(pidof lt-$RELAYD_BIN) ]; then | |
173af62f | 140 | $DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt >/dev/null 2>&1 & |
25a818af | 141 | #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 & |
f4e40ab6 | 142 | if [ $? -eq 1 ]; then |
c38b5107 | 143 | print_fail |
f4e40ab6 DG |
144 | return 1 |
145 | else | |
c38b5107 | 146 | print_ok |
f4e40ab6 DG |
147 | fi |
148 | else | |
c38b5107 | 149 | print_ok |
f4e40ab6 DG |
150 | fi |
151 | } | |
152 | ||
fb3268e3 | 153 | function stop_lttng_relayd |
f4e40ab6 DG |
154 | { |
155 | PID_RELAYD=`pidof lt-$RELAYD_BIN` | |
156 | ||
157 | echo -e -n "Killing lttng-relayd (pid: $PID_RELAYD)... " | |
158 | kill $PID_RELAYD >/dev/null 2>&1 | |
159 | if [ $? -eq 1 ]; then | |
c38b5107 | 160 | print_fail |
f4e40ab6 DG |
161 | return 1 |
162 | else | |
163 | out=1 | |
164 | while [ -n "$out" ]; do | |
165 | out=$(pidof lt-$RELAYD_BIN) | |
166 | sleep 0.5 | |
167 | done | |
c38b5107 | 168 | print_ok |
f4e40ab6 DG |
169 | return 0 |
170 | fi | |
171 | } | |
172 | ||
fb3268e3 | 173 | function start_lttng_sessiond() |
355f483d DG |
174 | { |
175 | if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then | |
176 | # Env variable requested no session daemon | |
177 | return | |
178 | fi | |
179 | ||
180 | spawn_sessiond | |
181 | out=$? | |
182 | if [ $out -eq 2 ]; then | |
183 | # Kernel version is not compatible. | |
184 | exit 0 | |
185 | elif [ $out -ne 0 ]; then | |
186 | echo "NOT bad $?" | |
187 | exit 1 | |
188 | fi | |
189 | ||
190 | # Simply wait for the session daemon bootstrap | |
191 | echo "Waiting for the session daemon to bootstrap (2 secs)" | |
192 | sleep 2 | |
193 | } | |
194 | ||
fb3268e3 | 195 | function stop_lttng_sessiond () |
d3e8f6bb | 196 | { |
355f483d DG |
197 | if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then |
198 | # Env variable requested no session daemon | |
199 | return | |
200 | fi | |
201 | ||
d3e8f6bb DG |
202 | PID_SESSIOND=`pidof lt-$SESSIOND_BIN` |
203 | ||
204 | echo -e -n "Killing session daemon... " | |
205 | kill $PID_SESSIOND >/dev/null 2>&1 | |
206 | if [ $? -eq 1 ]; then | |
c38b5107 | 207 | print_fail |
d3e8f6bb DG |
208 | return 1 |
209 | else | |
5fa32580 DG |
210 | out=1 |
211 | while [ -n "$out" ]; do | |
212 | out=$(pidof lt-$SESSIOND_BIN) | |
213 | sleep 0.5 | |
214 | done | |
c38b5107 | 215 | print_ok |
d3e8f6bb DG |
216 | fi |
217 | } | |
218 | ||
219 | function create_lttng_session () | |
220 | { | |
221 | sess_name=$1 | |
222 | trace_path=$2 | |
223 | ||
908ee7bd | 224 | echo -n "Creating lttng session $sess_name in $trace_path " |
10a8a223 | 225 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path >/dev/null 2>&1 |
d3e8f6bb | 226 | if [ $? -eq 1 ]; then |
c38b5107 | 227 | print_fail |
d3e8f6bb DG |
228 | return 1 |
229 | else | |
c38b5107 | 230 | print_ok |
d4018451 DG |
231 | fi |
232 | } | |
233 | ||
234 | function enable_lttng_channel() | |
235 | { | |
236 | sess_name=$1 | |
237 | channel_name=$2 | |
238 | ||
239 | echo -n "Enabling lttng channel $channel_name for session $sess_name" | |
240 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel $channel_name -s $sess_name >/dev/null 2>&1 | |
241 | if [ $? -eq 1 ]; then | |
c38b5107 | 242 | print_fail |
d4018451 DG |
243 | return 1 |
244 | else | |
c38b5107 | 245 | print_ok |
d4018451 DG |
246 | fi |
247 | } | |
248 | ||
249 | function disable_lttng_channel() | |
250 | { | |
251 | sess_name=$1 | |
252 | channel_name=$2 | |
253 | ||
254 | echo -n "Disabling lttng channel $channel_name for session $sess_name" | |
255 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel $channel_name -s $sess_name >/dev/null 2>&1 | |
256 | if [ $? -eq 1 ]; then | |
c38b5107 | 257 | print_fail |
d4018451 DG |
258 | return 1 |
259 | else | |
c38b5107 | 260 | print_ok |
d3e8f6bb DG |
261 | fi |
262 | } | |
263 | ||
264 | function enable_ust_lttng_event () | |
265 | { | |
266 | sess_name=$1 | |
26b53d3b | 267 | event_name="$2" |
d3e8f6bb DG |
268 | |
269 | echo -n "Enabling lttng event $event_name for session $sess_name " | |
26b53d3b DG |
270 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u >/dev/null 2>&1 |
271 | if [ $? -eq 1 ]; then | |
272 | print_fail | |
273 | return 1 | |
274 | else | |
275 | print_ok | |
276 | fi | |
277 | } | |
278 | ||
279 | function enable_ust_lttng_event_filter() | |
280 | { | |
281 | sess_name="$1" | |
282 | event_name="$2" | |
283 | filter="$3" | |
284 | echo -n "Enabling lttng event with filtering " | |
285 | ||
907b42de | 286 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 2>&1 >/dev/null |
26b53d3b DG |
287 | if [ $? -eq 0 ]; then |
288 | print_ok | |
289 | return 0 | |
290 | else | |
291 | print_fail | |
292 | return 1 | |
293 | fi | |
294 | } | |
295 | ||
296 | function enable_ust_lttng_event_loglevel() | |
297 | { | |
298 | sess_name="$1" | |
299 | event_name="$2" | |
300 | loglevel="$3" | |
301 | echo -n "Enabling lttng event $event_name with loglevel $loglevel" | |
302 | ||
907b42de | 303 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 2>&1 >/dev/null |
26b53d3b DG |
304 | if [ $? -eq 0 ]; then |
305 | print_ok | |
306 | return 0 | |
307 | else | |
308 | print_fail | |
309 | return 1 | |
310 | fi | |
311 | } | |
312 | ||
313 | function enable_ust_lttng_event_loglevel_only() | |
314 | { | |
315 | sess_name="$1" | |
316 | event_name="$2" | |
317 | loglevel="$3" | |
318 | echo -n "Enabling lttng event $event_name with loglevel-only $loglevel" | |
319 | ||
907b42de | 320 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 2>&1 >/dev/null |
26b53d3b DG |
321 | if [ $? -eq 0 ]; then |
322 | print_ok | |
323 | return 0 | |
324 | else | |
325 | print_fail | |
326 | return 1 | |
327 | fi | |
328 | } | |
329 | ||
330 | function disable_ust_lttng_event () | |
331 | { | |
907b42de DG |
332 | sess_name="$1" |
333 | event_name="$2" | |
26b53d3b DG |
334 | |
335 | echo -n "Disabling lttng event $event_name for session $sess_name " | |
907b42de | 336 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -u >/dev/null 2>&1 |
d3e8f6bb | 337 | if [ $? -eq 1 ]; then |
c38b5107 | 338 | print_fail |
d3e8f6bb DG |
339 | return 1 |
340 | else | |
c38b5107 | 341 | print_ok |
d3e8f6bb DG |
342 | fi |
343 | } | |
344 | ||
fb3268e3 | 345 | function start_lttng_tracing () |
d3e8f6bb DG |
346 | { |
347 | sess_name=$1 | |
348 | ||
349 | echo -n "Start lttng tracing for session $sess_name " | |
10a8a223 | 350 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name >/dev/null 2>&1 |
d3e8f6bb | 351 | if [ $? -eq 1 ]; then |
c38b5107 | 352 | print_fail |
d3e8f6bb DG |
353 | return 1 |
354 | else | |
c38b5107 | 355 | print_ok |
d3e8f6bb DG |
356 | fi |
357 | } | |
358 | ||
fb3268e3 | 359 | function stop_lttng_tracing () |
d3e8f6bb DG |
360 | { |
361 | sess_name=$1 | |
362 | ||
363 | echo -n "Stop lttng tracing for session $sess_name " | |
10a8a223 | 364 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name >/dev/null 2>&1 |
d3e8f6bb | 365 | if [ $? -eq 1 ]; then |
c38b5107 | 366 | print_fail |
d3e8f6bb DG |
367 | return 1 |
368 | else | |
c38b5107 | 369 | print_ok |
d3e8f6bb DG |
370 | fi |
371 | } | |
372 | ||
373 | function destroy_lttng_session () | |
374 | { | |
375 | sess_name=$1 | |
376 | ||
377 | echo -n "Destroy lttng session $sess_name " | |
10a8a223 | 378 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name >/dev/null 2>&1 |
d3e8f6bb | 379 | if [ $? -eq 1 ]; then |
c38b5107 | 380 | print_fail |
d3e8f6bb DG |
381 | return 1 |
382 | else | |
c38b5107 | 383 | print_ok |
d3e8f6bb DG |
384 | fi |
385 | } | |
386 | ||
387 | function trace_matches () | |
388 | { | |
389 | event_name=$1 | |
390 | nr_iter=$2 | |
391 | trace_path=$3 | |
392 | ||
317eef93 DG |
393 | which $BABELTRACE_BIN >/dev/null |
394 | if [ $? -eq 1 ]; then | |
395 | echo "Babeltrace binary not found. Skipping trace matches" | |
396 | return 0 | |
397 | fi | |
398 | ||
d3e8f6bb DG |
399 | echo -n "Looking for $nr_iter $event_name in $trace_path " |
400 | ||
401 | count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) | |
402 | if [ "$count" -ne "$nr_iter" ]; then | |
c38b5107 CB |
403 | echo -n "$count found in trace " |
404 | print_fail | |
d3e8f6bb DG |
405 | return 1 |
406 | else | |
c38b5107 CB |
407 | echo -n "Trace is coherent " |
408 | print_ok | |
d3e8f6bb DG |
409 | return 0 |
410 | fi | |
411 | } | |
f4e40ab6 DG |
412 | |
413 | function validate_trace | |
414 | { | |
415 | event_name=$1 | |
416 | trace_path=$2 | |
417 | ||
418 | which $BABELTRACE_BIN >/dev/null | |
419 | if [ $? -eq 1 ]; then | |
420 | echo "Babeltrace binary not found. Skipping trace matches" | |
421 | return 0 | |
422 | fi | |
423 | ||
424 | echo -n "Validating trace for event $event_name... " | |
425 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $event_name | wc -l) | |
426 | if [ $traced -eq 0 ]; then | |
c38b5107 | 427 | print_fail |
f4e40ab6 DG |
428 | return 1 |
429 | else | |
c38b5107 | 430 | print_ok |
f4e40ab6 DG |
431 | return 0 |
432 | fi | |
433 | } |