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" | |
f7613992 | 19 | CONSUMERD_BIN="lttng-consumerd" |
f4e40ab6 | 20 | RELAYD_BIN="lttng-relayd" |
d3e8f6bb DG |
21 | LTTNG_BIN="lttng" |
22 | BABELTRACE_BIN="babeltrace" | |
23 | ||
fd4dfcec DG |
24 | # Minimal kernel version supported for session daemon tests |
25 | KERNEL_MAJOR_VERSION=2 | |
26 | KERNEL_MINOR_VERSION=6 | |
27 | KERNEL_PATCHLEVEL_VERSION=27 | |
28 | ||
29655db7 CB |
29 | source $TESTDIR/utils/tap/tap.sh |
30 | ||
fec81a7e CB |
31 | function print_ok () |
32 | { | |
33 | # Check if we are a terminal | |
34 | if [ -t 1 ]; then | |
35 | echo -e "\e[1;32mOK\e[0m" | |
36 | else | |
37 | echo -e "OK" | |
38 | fi | |
39 | } | |
40 | ||
41 | function print_fail () | |
42 | { | |
43 | # Check if we are a terminal | |
44 | if [ -t 1 ]; then | |
45 | echo -e "\e[1;31mFAIL\e[0m" | |
46 | else | |
47 | echo -e "FAIL" | |
48 | fi | |
49 | } | |
50 | ||
51 | function print_test_banner () | |
52 | { | |
53 | desc="$1" | |
29655db7 | 54 | diag "$desc" |
fec81a7e CB |
55 | } |
56 | ||
fd4dfcec DG |
57 | function validate_kernel_version () |
58 | { | |
59 | kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n')) | |
60 | if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then | |
61 | return 0 | |
62 | fi | |
63 | if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then | |
64 | return 0 | |
65 | fi | |
66 | if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then | |
67 | return 0 | |
68 | fi | |
69 | return 1 | |
70 | } | |
71 | ||
9ac429ef | 72 | # Generate a random string |
f4e40ab6 DG |
73 | # $1 = number of characters; defaults to 16 |
74 | # $2 = include special characters; 1 = yes, 0 = no; defaults to yes | |
9ac429ef | 75 | function randstring() |
f4e40ab6 DG |
76 | { |
77 | [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]" | |
78 | cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-16} | |
79 | echo | |
80 | } | |
81 | ||
f4e40ab6 DG |
82 | function lttng_enable_kernel_event |
83 | { | |
84 | sess_name=$1 | |
85 | event_name=$2 | |
07b86b52 | 86 | channel_name=$3 |
f4e40ab6 DG |
87 | |
88 | if [ -z $event_name ]; then | |
89 | # Enable all event if no event name specified | |
29655db7 | 90 | event_name="-a" |
f4e40ab6 DG |
91 | fi |
92 | ||
07b86b52 JD |
93 | if [ -z $channel_name ]; then |
94 | # default channel if none specified | |
95 | chan="" | |
96 | else | |
97 | chan="-c $channel_name" | |
98 | fi | |
99 | ||
100 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k >/dev/null 2>&1 | |
29655db7 | 101 | ok $? "Enable kernel event $event_name for session $sess_name" |
f4e40ab6 DG |
102 | } |
103 | ||
fb3268e3 | 104 | function start_lttng_relayd |
f4e40ab6 | 105 | { |
198e7caf | 106 | local opt=$1 |
173af62f | 107 | |
f4e40ab6 DG |
108 | DIR=$(readlink -f $TESTDIR) |
109 | ||
110 | if [ -z $(pidof lt-$RELAYD_BIN) ]; then | |
6f137cef | 111 | $DIR/../src/bin/lttng-relayd/$RELAYD_BIN -b $opt >/dev/null 2>&1 |
25a818af | 112 | #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 & |
f4e40ab6 | 113 | if [ $? -eq 1 ]; then |
29655db7 | 114 | fail "Start lttng-relayd (opt: $opt)" |
f4e40ab6 DG |
115 | return 1 |
116 | else | |
29655db7 | 117 | pass "Start lttng-relayd (opt: $opt)" |
f4e40ab6 DG |
118 | fi |
119 | else | |
29655db7 | 120 | pass "Start lttng-relayd (opt: $opt)" |
f4e40ab6 DG |
121 | fi |
122 | } | |
123 | ||
1fb23888 | 124 | function stop_lttng_relayd_nocheck |
f4e40ab6 DG |
125 | { |
126 | PID_RELAYD=`pidof lt-$RELAYD_BIN` | |
127 | ||
1fb23888 | 128 | diag "Killing lttng-relayd (pid: $PID_RELAYD)" |
f4e40ab6 | 129 | kill $PID_RELAYD >/dev/null 2>&1 |
1fb23888 | 130 | retval=$? |
29655db7 | 131 | |
1fb23888 | 132 | if [ $retval -eq 1 ]; then |
f4e40ab6 DG |
133 | out=1 |
134 | while [ -n "$out" ]; do | |
135 | out=$(pidof lt-$RELAYD_BIN) | |
136 | sleep 0.5 | |
137 | done | |
1fb23888 MD |
138 | fi |
139 | return $retval | |
140 | } | |
141 | ||
142 | function stop_lttng_relayd | |
143 | { | |
144 | stop_lttng_relayd_nocheck | |
145 | ||
146 | if [ $? -eq 1 ]; then | |
147 | fail "Killed lttng-relayd (pid: $PID_RELAYD)" | |
148 | return 1 | |
149 | else | |
150 | pass "Killed lttng-relayd (pid: $PID_RELAYD)" | |
f4e40ab6 DG |
151 | return 0 |
152 | fi | |
153 | } | |
154 | ||
fb3268e3 | 155 | function start_lttng_sessiond() |
355f483d DG |
156 | { |
157 | if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then | |
158 | # Env variable requested no session daemon | |
159 | return | |
160 | fi | |
161 | ||
29655db7 CB |
162 | validate_kernel_version |
163 | if [ $? -ne 0 ]; then | |
164 | fail "Start session daemon" | |
165 | BAIL_OUT "*** Kernel too old for session daemon tests ***" | |
355f483d DG |
166 | fi |
167 | ||
29655db7 | 168 | DIR=$(readlink -f $TESTDIR) |
d3d97763 JG |
169 | : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/} |
170 | export LTTNG_SESSION_CONFIG_XSD_PATH | |
29655db7 CB |
171 | |
172 | if [ -z $(pidof lt-$SESSIOND_BIN) ]; then | |
d7b63d8c | 173 | $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" |
29655db7 CB |
174 | #$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 & |
175 | status=$? | |
29655db7 CB |
176 | ok $status "Start session daemon" |
177 | fi | |
355f483d DG |
178 | } |
179 | ||
fb3268e3 | 180 | function stop_lttng_sessiond () |
d3e8f6bb | 181 | { |
355f483d DG |
182 | if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then |
183 | # Env variable requested no session daemon | |
184 | return | |
185 | fi | |
186 | ||
d3e8f6bb DG |
187 | PID_SESSIOND=`pidof lt-$SESSIOND_BIN` |
188 | ||
d3e8f6bb | 189 | kill $PID_SESSIOND >/dev/null 2>&1 |
29655db7 | 190 | |
d3e8f6bb | 191 | if [ $? -eq 1 ]; then |
29655db7 | 192 | fail "Kill sessions daemon" |
d3e8f6bb DG |
193 | return 1 |
194 | else | |
5fa32580 DG |
195 | out=1 |
196 | while [ -n "$out" ]; do | |
197 | out=$(pidof lt-$SESSIOND_BIN) | |
198 | sleep 0.5 | |
199 | done | |
f7613992 MD |
200 | out=1 |
201 | while [ -n "$out" ]; do | |
202 | out=$(pidof $CONSUMERD_BIN) | |
203 | sleep 0.5 | |
204 | done | |
29655db7 | 205 | pass "Kill session daemon" |
d3e8f6bb DG |
206 | fi |
207 | } | |
208 | ||
07b86b52 JD |
209 | function create_lttng_session_no_output () |
210 | { | |
211 | sess_name=$1 | |
212 | ||
213 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output >/dev/null 2>&1 | |
214 | ok $? "Create session $sess_name in no-output mode" | |
215 | } | |
216 | ||
d3e8f6bb DG |
217 | function create_lttng_session () |
218 | { | |
219 | sess_name=$1 | |
220 | trace_path=$2 | |
221 | ||
10a8a223 | 222 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path >/dev/null 2>&1 |
29655db7 | 223 | ok $? "Create session $sess_name in $trace_path" |
d4018451 DG |
224 | } |
225 | ||
29655db7 | 226 | function enable_ust_lttng_channel() |
d4018451 DG |
227 | { |
228 | sess_name=$1 | |
229 | channel_name=$2 | |
230 | ||
29655db7 CB |
231 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name >/dev/null 2>&1 |
232 | ok $? "Enable channel $channel_name for session $sess_name" | |
d4018451 DG |
233 | } |
234 | ||
29655db7 | 235 | function disable_ust_lttng_channel() |
d4018451 DG |
236 | { |
237 | sess_name=$1 | |
238 | channel_name=$2 | |
239 | ||
29655db7 CB |
240 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name >/dev/null 2>&1 |
241 | ok $? "Disable channel $channel_name for session $sess_name" | |
d3e8f6bb DG |
242 | } |
243 | ||
07b86b52 JD |
244 | function enable_lttng_mmap_overwrite_kernel_channel() |
245 | { | |
246 | sess_name=$1 | |
247 | channel_name=$2 | |
248 | ||
249 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite >/dev/null 2>&1 | |
250 | ok $? "Enable channel $channel_name for session $sess_name" | |
251 | } | |
252 | ||
ebaaaf5e JD |
253 | function enable_lttng_mmap_overwrite_ust_channel() |
254 | { | |
255 | sess_name=$1 | |
256 | channel_name=$2 | |
257 | ||
258 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite >/dev/null 2>&1 | |
259 | ok $? "Enable channel $channel_name for session $sess_name" | |
260 | } | |
261 | ||
d3e8f6bb DG |
262 | function enable_ust_lttng_event () |
263 | { | |
264 | sess_name=$1 | |
26b53d3b | 265 | event_name="$2" |
ebaaaf5e JD |
266 | channel_name=$3 |
267 | ||
268 | if [ -z $channel_name ]; then | |
269 | # default channel if none specified | |
270 | chan="" | |
271 | else | |
272 | chan="-c $channel_name" | |
273 | fi | |
d3e8f6bb | 274 | |
ebaaaf5e | 275 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u >/dev/null 2>&1 |
29655db7 | 276 | ok $? "Enable event $event_name for session $sess_name" |
26b53d3b DG |
277 | } |
278 | ||
37175ce4 DG |
279 | function enable_jul_lttng_event() |
280 | { | |
281 | sess_name=$1 | |
282 | event_name="$2" | |
283 | channel_name=$3 | |
284 | ||
285 | if [ -z $channel_name ]; then | |
286 | # default channel if none specified | |
287 | chan="" | |
288 | else | |
289 | chan="-c $channel_name" | |
290 | fi | |
291 | ||
292 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j >/dev/null 2>&1 | |
293 | ok $? "Enable JUL event $event_name for session $sess_name" | |
294 | } | |
295 | ||
b2064f54 DG |
296 | function enable_jul_lttng_event_loglevel() |
297 | { | |
298 | sess_name=$1 | |
299 | event_name="$2" | |
300 | loglevel=$3 | |
301 | channel_name=$4 | |
302 | ||
303 | if [ -z $channel_name ]; then | |
304 | # default channel if none specified | |
305 | chan="" | |
306 | else | |
307 | chan="-c $channel_name" | |
308 | fi | |
309 | ||
310 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j >/dev/null 2>&1 | |
311 | ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel" | |
312 | } | |
313 | ||
26b53d3b DG |
314 | function enable_ust_lttng_event_filter() |
315 | { | |
316 | sess_name="$1" | |
317 | event_name="$2" | |
318 | filter="$3" | |
26b53d3b | 319 | |
29655db7 CB |
320 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" >/dev/null 2>&1 |
321 | ok $? "Enable event $event_name with filtering for session $sess_name" | |
26b53d3b DG |
322 | } |
323 | ||
324 | function enable_ust_lttng_event_loglevel() | |
325 | { | |
326 | sess_name="$1" | |
327 | event_name="$2" | |
328 | loglevel="$3" | |
26b53d3b | 329 | |
29655db7 CB |
330 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel >/dev/null 2>&1 |
331 | ok $? "Enable event $event_name with loglevel $loglevel" | |
26b53d3b DG |
332 | } |
333 | ||
334 | function enable_ust_lttng_event_loglevel_only() | |
335 | { | |
336 | sess_name="$1" | |
337 | event_name="$2" | |
338 | loglevel="$3" | |
26b53d3b | 339 | |
29655db7 CB |
340 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel >/dev/null 2>&1 |
341 | ok $? "Enable event $event_name with loglevel-only $loglevel" | |
26b53d3b DG |
342 | } |
343 | ||
344 | function disable_ust_lttng_event () | |
345 | { | |
907b42de DG |
346 | sess_name="$1" |
347 | event_name="$2" | |
26b53d3b | 348 | |
907b42de | 349 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -u >/dev/null 2>&1 |
29655db7 | 350 | ok $? "Disable event $event_name for session $sess_name" |
d3e8f6bb DG |
351 | } |
352 | ||
5ddababf DG |
353 | function disable_jul_lttng_event () |
354 | { | |
355 | local sess_name="$1" | |
356 | local event_name="$2" | |
357 | ||
358 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1 | |
359 | ok $? "Disable JUL event $event_name for session $sess_name" | |
360 | } | |
361 | ||
fb3268e3 | 362 | function start_lttng_tracing () |
d3e8f6bb DG |
363 | { |
364 | sess_name=$1 | |
365 | ||
10a8a223 | 366 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name >/dev/null 2>&1 |
29655db7 | 367 | ok $? "Start tracing for session $sess_name" |
d3e8f6bb DG |
368 | } |
369 | ||
fb3268e3 | 370 | function stop_lttng_tracing () |
d3e8f6bb DG |
371 | { |
372 | sess_name=$1 | |
373 | ||
10a8a223 | 374 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name >/dev/null 2>&1 |
29655db7 | 375 | ok $? "Stop lttng tracing for session $sess_name" |
d3e8f6bb DG |
376 | } |
377 | ||
378 | function destroy_lttng_session () | |
379 | { | |
380 | sess_name=$1 | |
381 | ||
29655db7 | 382 | |
10a8a223 | 383 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name >/dev/null 2>&1 |
29655db7 | 384 | ok $? "Destroy lttng session $sess_name" |
d3e8f6bb DG |
385 | } |
386 | ||
07b86b52 JD |
387 | function lttng_snapshot_add_output () |
388 | { | |
389 | sess_name=$1 | |
390 | trace_path=$2 | |
391 | ||
392 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name file://$trace_path >/dev/null 2>&1 | |
393 | ok $? "Added snapshot output file://$trace_path" | |
394 | } | |
395 | ||
26402e0c DG |
396 | function lttng_snapshot_del_output () |
397 | { | |
398 | local sess_name=$1 | |
399 | local id=$2 | |
400 | ||
401 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id >/dev/null 2>&1 | |
402 | ok $? "Deleted snapshot output id $id" | |
403 | } | |
404 | ||
07b86b52 JD |
405 | function lttng_snapshot_record () |
406 | { | |
407 | sess_name=$1 | |
408 | trace_path=$2 | |
409 | ||
410 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name >/dev/null 2>&1 | |
411 | ok $? "Snapshot recorded" | |
412 | } | |
413 | ||
e02b109b DG |
414 | function lttng_save() |
415 | { | |
416 | local sess_name=$1 | |
417 | local opts=$2 | |
418 | ||
419 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts >/dev/null 2>&1 | |
420 | ok $? "Session successfully saved" | |
421 | } | |
422 | ||
423 | function lttng_load() | |
424 | { | |
425 | local opts=$1 | |
426 | ||
427 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts >/dev/null 2>&1 | |
428 | ok $? "Load command successful" | |
429 | } | |
430 | ||
d3e8f6bb DG |
431 | function trace_matches () |
432 | { | |
433 | event_name=$1 | |
434 | nr_iter=$2 | |
435 | trace_path=$3 | |
436 | ||
317eef93 | 437 | which $BABELTRACE_BIN >/dev/null |
29655db7 | 438 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" |
d3e8f6bb DG |
439 | |
440 | count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) | |
29655db7 | 441 | |
d3e8f6bb | 442 | if [ "$count" -ne "$nr_iter" ]; then |
29655db7 CB |
443 | fail "Trace match" |
444 | diag "$count events found in trace" | |
d3e8f6bb | 445 | else |
29655db7 | 446 | pass "Trace match" |
d3e8f6bb DG |
447 | fi |
448 | } | |
f4e40ab6 DG |
449 | |
450 | function validate_trace | |
451 | { | |
452 | event_name=$1 | |
453 | trace_path=$2 | |
454 | ||
455 | which $BABELTRACE_BIN >/dev/null | |
29655db7 CB |
456 | if [ $? -ne 0 ]; then |
457 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
f4e40ab6 DG |
458 | fi |
459 | ||
07b86b52 JD |
460 | OLDIFS=$IFS |
461 | IFS="," | |
462 | for i in $event_name; do | |
463 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l) | |
464 | if [ "$traced" -ne 0 ]; then | |
ebaaaf5e | 465 | pass "Validate trace for event $i, $traced events" |
07b86b52 JD |
466 | else |
467 | fail "Validate trace for event $i" | |
468 | diag "Found $traced occurences of $i" | |
469 | fi | |
470 | done | |
471 | ret=$? | |
472 | IFS=$OLDIFS | |
473 | return $ret | |
f4e40ab6 | 474 | } |