Tests: kernel wildcards
[lttng-tools.git] / tests / utils / utils.sh
CommitLineData
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
18SESSIOND_BIN="lttng-sessiond"
f7613992 19CONSUMERD_BIN="lttng-consumerd"
f4e40ab6 20RELAYD_BIN="lttng-relayd"
d3e8f6bb
DG
21LTTNG_BIN="lttng"
22BABELTRACE_BIN="babeltrace"
2cf48300
JR
23OUTPUT_DEST=/dev/null
24ERROR_OUTPUT_DEST=/dev/null
d3e8f6bb 25
fd4dfcec
DG
26# Minimal kernel version supported for session daemon tests
27KERNEL_MAJOR_VERSION=2
28KERNEL_MINOR_VERSION=6
29KERNEL_PATCHLEVEL_VERSION=27
30
629b9335
MD
31# We set the default UST register timeout to "wait forever", so that
32# basic tests don't have to worry about hitting timeouts on busy
33# systems. Specialized tests should test those corner-cases.
34export LTTNG_UST_REGISTER_TIMEOUT=-1
35
29655db7
CB
36source $TESTDIR/utils/tap/tap.sh
37
fec81a7e
CB
38function print_ok ()
39{
40 # Check if we are a terminal
41 if [ -t 1 ]; then
42 echo -e "\e[1;32mOK\e[0m"
43 else
44 echo -e "OK"
45 fi
46}
47
48function print_fail ()
49{
50 # Check if we are a terminal
51 if [ -t 1 ]; then
52 echo -e "\e[1;31mFAIL\e[0m"
53 else
54 echo -e "FAIL"
55 fi
56}
57
58function print_test_banner ()
59{
7d0ad314 60 local desc="$1"
29655db7 61 diag "$desc"
fec81a7e
CB
62}
63
fd4dfcec
DG
64function validate_kernel_version ()
65{
7d0ad314 66 local kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n'))
fd4dfcec
DG
67 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
68 return 0
69 fi
70 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
71 return 0
72 fi
73 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
74 return 0
75 fi
76 return 1
77}
78
9ac429ef 79# Generate a random string
f4e40ab6
DG
80# $1 = number of characters; defaults to 16
81# $2 = include special characters; 1 = yes, 0 = no; defaults to yes
9ac429ef 82function randstring()
f4e40ab6
DG
83{
84 [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
85 cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-16}
86 echo
87}
88
4a180d9f 89function enable_kernel_lttng_event
f4e40ab6 90{
4a180d9f
MD
91 local expected_to_fail="$1"
92 local sess_name="$2"
93 local event_name="$3"
94 local channel_name="$4"
f4e40ab6 95
4a180d9f 96 if [ -z "$event_name" ]; then
f4e40ab6 97 # Enable all event if no event name specified
29655db7 98 event_name="-a"
f4e40ab6
DG
99 fi
100
4a180d9f 101 if [ -z "$channel_name" ]; then
07b86b52
JD
102 # default channel if none specified
103 chan=""
104 else
105 chan="-c $channel_name"
106 fi
107
2cf48300 108 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
4a180d9f
MD
109 ret=$?
110 if [[ $expected_to_fail -eq "1" ]]; then
111 test $ret -ne "0"
112 ok $? "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
113 else
114 ok $ret "Enable kernel event $event_name for session $sess_name"
115 fi
116}
117
118function enable_kernel_lttng_event_ok ()
119{
120 enable_kernel_lttng_event 0 "$@"
121}
122
123function enable_kernel_lttng_event_fail ()
124{
125 enable_kernel_lttng_event 1 "$@"
126}
127
128# Old interface
129function lttng_enable_kernel_event
130{
131 enable_kernel_lttng_event_ok "$@"
f4e40ab6
DG
132}
133
8cfcd41c
MD
134function lttng_enable_kernel_syscall()
135{
136 local expected_to_fail=$1
137 local sess_name=$2
138 local syscall_name=$3
139 local channel_name=$4
140
141 if [ -z $syscall_name ]; then
142 # Enable all event if no syscall name specified
143 syscall_name="-a"
144 fi
145
146 if [ -z $channel_name ]; then
147 # default channel if none specified
148 chan=""
149 else
150 chan="-c $channel_name"
151 fi
152
2cf48300 153 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
8cfcd41c
MD
154 ret=$?
155 if [[ $expected_to_fail -eq "1" ]]; then
156 test $ret -ne "0"
157 ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
158 else
159 ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
160 fi
161}
162
163function lttng_enable_kernel_syscall_ok()
164{
421b83dc 165 lttng_enable_kernel_syscall 0 "$@"
8cfcd41c
MD
166}
167
168function lttng_enable_kernel_syscall_fail()
169{
421b83dc 170 lttng_enable_kernel_syscall 1 "$@"
8cfcd41c
MD
171}
172
173function lttng_disable_kernel_syscall()
174{
175 local expected_to_fail=$1
176 local sess_name=$2
177 local syscall_name=$3
178 local channel_name=$4
179
180 if [ -z $syscall_name ]; then
181 # Enable all event if no syscall name specified
182 syscall_name="-a"
183 fi
184
185 if [ -z $channel_name ]; then
186 # default channel if none specified
187 chan=""
188 else
189 chan="-c $channel_name"
190 fi
191
2cf48300 192 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
8cfcd41c
MD
193
194 ret=$?
195 if [[ $expected_to_fail -eq "1" ]]; then
196 test $ret -ne "0"
197 ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
198 else
199 ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
200 fi
201}
202
203function lttng_disable_kernel_syscall_ok()
204{
421b83dc 205 lttng_disable_kernel_syscall 0 "$@"
8cfcd41c
MD
206}
207
208function lttng_disable_kernel_syscall_fail()
209{
421b83dc 210 lttng_disable_kernel_syscall 1 "$@"
8cfcd41c
MD
211}
212
d96f6315
MD
213function lttng_enable_kernel_channel()
214{
215 local expected_to_fail=$1
216 local sess_name=$2
217 local channel_name=$3
218
2cf48300 219 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
d96f6315
MD
220 ret=$?
221 if [[ $expected_to_fail -eq "1" ]]; then
222 test "$ret" -ne "0"
223 ok $? "Expected failure on kernel channel creation $channel_name in $sess_name"
224 else
225 ok $ret "Enable channel $channel_name for session $sess_name"
226 fi
227}
228
229function lttng_enable_kernel_channel_ok()
230{
421b83dc 231 lttng_enable_kernel_channel 0 "$@"
d96f6315
MD
232}
233
234function lttng_enable_kernel_channel_fail()
235{
421b83dc 236 lttng_enable_kernel_channel 1 "$@"
d96f6315
MD
237}
238
239function lttng_disable_kernel_channel()
240{
241 local expected_to_fail=$1
242 local sess_name=$2
243 local channel_name=$3
244
2cf48300 245 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
d96f6315
MD
246 ret=$?
247 if [[ $expected_to_fail -eq "1" ]]; then
248 test "$ret" -ne "0"
249 ok $? "Expected failure on kernel channel creation $channel_name in $sess_name"
250 else
251 ok $ret "disable channel $channel_name for session $sess_name"
252 fi
253}
254
255function lttng_disable_kernel_channel_ok()
256{
421b83dc 257 lttng_disable_kernel_channel 0 "$@"
d96f6315
MD
258}
259
260function lttng_disable_kernel_channel_fail()
261{
421b83dc 262 lttng_disable_kernel_channel 1 "$@"
d96f6315
MD
263}
264
05aa48da 265function start_lttng_relayd_opt()
f4e40ab6 266{
05aa48da
MD
267 local withtap=$1
268 local opt=$2
173af62f 269
f4e40ab6
DG
270 DIR=$(readlink -f $TESTDIR)
271
272 if [ -z $(pidof lt-$RELAYD_BIN) ]; then
2cf48300 273 $DIR/../src/bin/lttng-relayd/$RELAYD_BIN -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
25a818af 274 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
f4e40ab6 275 if [ $? -eq 1 ]; then
05aa48da
MD
276 if [ $withtap -eq "1" ]; then
277 fail "Start lttng-relayd (opt: $opt)"
278 fi
f4e40ab6
DG
279 return 1
280 else
05aa48da
MD
281 if [ $withtap -eq "1" ]; then
282 pass "Start lttng-relayd (opt: $opt)"
283 fi
f4e40ab6
DG
284 fi
285 else
29655db7 286 pass "Start lttng-relayd (opt: $opt)"
f4e40ab6
DG
287 fi
288}
289
05aa48da 290function start_lttng_relayd()
f4e40ab6 291{
05aa48da
MD
292 start_lttng_relayd_opt 1 "$@"
293}
294
295function start_lttng_relayd_notap()
296{
297 start_lttng_relayd_opt 0 "$@"
298}
299
300function stop_lttng_relayd_opt()
301{
302 local withtap=$1
303
f4e40ab6
DG
304 PID_RELAYD=`pidof lt-$RELAYD_BIN`
305
05aa48da
MD
306 if [ $withtap -eq "1" ]; then
307 diag "Killing lttng-relayd (pid: $PID_RELAYD)"
308 fi
2cf48300 309 kill $PID_RELAYD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1fb23888 310 retval=$?
29655db7 311
05aa48da
MD
312 if [ $? -eq 1 ]; then
313 if [ $withtap -eq "1" ]; then
314 fail "Kill relay daemon"
315 fi
316 return 1
317 else
f4e40ab6
DG
318 out=1
319 while [ -n "$out" ]; do
320 out=$(pidof lt-$RELAYD_BIN)
321 sleep 0.5
322 done
05aa48da
MD
323 if [ $withtap -eq "1" ]; then
324 pass "Kill relay daemon"
325 fi
1fb23888
MD
326 fi
327 return $retval
328}
329
05aa48da 330function stop_lttng_relayd()
1fb23888 331{
05aa48da
MD
332 stop_lttng_relayd_opt 1 "$@"
333}
1fb23888 334
05aa48da
MD
335function stop_lttng_relayd_notap()
336{
337 stop_lttng_relayd_opt 0 "$@"
f4e40ab6
DG
338}
339
05aa48da
MD
340#First arg: show tap output
341#Second argument: load path for automatic loading
342function start_lttng_sessiond_opt()
355f483d 343{
05aa48da
MD
344 local withtap=$1
345 local load_path=$2
8d51ddbc 346
355f483d
DG
347 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
348 # Env variable requested no session daemon
349 return
350 fi
351
29655db7
CB
352 validate_kernel_version
353 if [ $? -ne 0 ]; then
354 fail "Start session daemon"
355 BAIL_OUT "*** Kernel too old for session daemon tests ***"
355f483d
DG
356 fi
357
29655db7 358 DIR=$(readlink -f $TESTDIR)
d3d97763
JG
359 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
360 export LTTNG_SESSION_CONFIG_XSD_PATH
29655db7
CB
361
362 if [ -z $(pidof lt-$SESSIOND_BIN) ]; then
8d51ddbc 363 # Have a load path ?
05aa48da 364 if [ -n "$load_path" ]; then
8d51ddbc
JRJ
365 $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --load "$1" --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
366 else
367 $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"
368 fi
0fc2834c 369 #$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" --verbose-consumer >>/tmp/sessiond.log 2>&1
29655db7 370 status=$?
05aa48da
MD
371 if [ $withtap -eq "1" ]; then
372 ok $status "Start session daemon"
373 fi
29655db7 374 fi
355f483d
DG
375}
376
05aa48da
MD
377function start_lttng_sessiond()
378{
379 start_lttng_sessiond_opt 1 "$@"
380}
381
382function start_lttng_sessiond_notap()
d3e8f6bb 383{
05aa48da
MD
384 start_lttng_sessiond_opt 0 "$@"
385}
386
387function stop_lttng_sessiond_opt()
388{
389 local withtap=$1
390
355f483d
DG
391 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
392 # Env variable requested no session daemon
393 return
394 fi
395
d3e8f6bb
DG
396 PID_SESSIOND=`pidof lt-$SESSIOND_BIN`
397
2cf48300 398 kill $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 399
d3e8f6bb 400 if [ $? -eq 1 ]; then
05aa48da
MD
401 if [ $withtap -eq "1" ]; then
402 fail "Kill sessions daemon"
403 fi
d3e8f6bb 404 else
5fa32580
DG
405 out=1
406 while [ -n "$out" ]; do
407 out=$(pidof lt-$SESSIOND_BIN)
408 sleep 0.5
409 done
f7613992
MD
410 out=1
411 while [ -n "$out" ]; do
412 out=$(pidof $CONSUMERD_BIN)
413 sleep 0.5
414 done
05aa48da
MD
415 if [ $withtap -eq "1" ]; then
416 pass "Kill session daemon"
417 fi
d3e8f6bb
DG
418 fi
419}
420
05aa48da
MD
421function stop_lttng_sessiond()
422{
423 stop_lttng_sessiond_opt 1 "$@"
424}
425
426function stop_lttng_sessiond_notap()
427{
428 stop_lttng_sessiond_opt 0 "$@"
429}
430
873c2aae
JRJ
431function list_lttng_with_opts ()
432{
7d0ad314 433 local opts=$1
2cf48300 434 $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
873c2aae
JRJ
435 ok $? "Lttng-tool list command with option $opts"
436}
437
07b86b52
JD
438function create_lttng_session_no_output ()
439{
7d0ad314 440 local sess_name=$1
07b86b52 441
2cf48300 442 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
07b86b52
JD
443 ok $? "Create session $sess_name in no-output mode"
444}
445
d3e8f6bb
DG
446function create_lttng_session ()
447{
bf6ae429
JR
448 local expected_to_fail=$1
449 local sess_name=$2
450 local trace_path=$3
d3e8f6bb 451
873c2aae
JRJ
452 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path > $OUTPUT_DEST
453 ret=$?
bf6ae429 454 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e
JRJ
455 test "$ret" -ne "0"
456 ok $? "Expected fail on session creation $sess_name in $trace_path"
873c2aae
JRJ
457 else
458 ok $ret "Create session $sess_name in $trace_path"
459 fi
d4018451
DG
460}
461
bf6ae429
JR
462function create_lttng_session_ok ()
463{
464 create_lttng_session 0 "$@"
465}
466
467function create_lttng_session_fail ()
468{
469 create_lttng_session 1 "$@"
470}
471
472
827caf52 473function enable_ust_lttng_channel ()
d4018451 474{
827caf52
JR
475 local expect_fail=$1
476 local sess_name=$2
477 local channel_name=$3
d4018451 478
2cf48300 479 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
312dabc3 480 ret=$?
827caf52 481 if [[ $expect_fail -eq "1" ]]; then
01513c3e
JRJ
482 test "$ret" -ne "0"
483 ok $? "Expected fail on ust channel creation $channel_name in $sess_name"
312dabc3
JRJ
484 else
485 ok $ret "Enable channel $channel_name for session $sess_name"
486 fi
d4018451
DG
487}
488
827caf52
JR
489function enable_ust_lttng_channel_ok ()
490{
491 enable_ust_lttng_channel 0 "$@"
492}
493
494function enable_ust_lttng_channel_fail ()
495{
496 enable_ust_lttng_channel 1 "$@"
497}
498
29655db7 499function disable_ust_lttng_channel()
d4018451 500{
7d0ad314
JRJ
501 local sess_name=$1
502 local channel_name=$2
d4018451 503
2cf48300 504 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 505 ok $? "Disable channel $channel_name for session $sess_name"
d3e8f6bb
DG
506}
507
07b86b52
JD
508function enable_lttng_mmap_overwrite_kernel_channel()
509{
7d0ad314
JRJ
510 local sess_name=$1
511 local channel_name=$2
07b86b52 512
2cf48300 513 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
07b86b52
JD
514 ok $? "Enable channel $channel_name for session $sess_name"
515}
516
ebaaaf5e
JD
517function enable_lttng_mmap_overwrite_ust_channel()
518{
7d0ad314
JRJ
519 local sess_name=$1
520 local channel_name=$2
ebaaaf5e 521
2cf48300 522 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
ebaaaf5e
JD
523 ok $? "Enable channel $channel_name for session $sess_name"
524}
525
d3e8f6bb
DG
526function enable_ust_lttng_event ()
527{
c4926bb5
JR
528 local expected_to_fail=$1
529 local sess_name=$2
530 local event_name="$3"
531 local channel_name=$4
ebaaaf5e
JD
532
533 if [ -z $channel_name ]; then
534 # default channel if none specified
535 chan=""
536 else
537 chan="-c $channel_name"
538 fi
d3e8f6bb 539
2cf48300 540 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 541 ret=$?
c4926bb5 542 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e
JRJ
543 test $ret -ne "0"
544 ok $? "Enable ust event $event_name for session $session_name on channel $channel_name failed as expected"
545 else
546 ok $ret "Enable event $event_name for session $sess_name"
547 fi
26b53d3b
DG
548}
549
c4926bb5
JR
550function enable_ust_lttng_event_ok ()
551{
552 enable_ust_lttng_event 0 "$@"
553}
554
555function enable_ust_lttng_event_fail ()
556{
557 enable_ust_lttng_event 1 "$@"
558}
559
37175ce4
DG
560function enable_jul_lttng_event()
561{
562 sess_name=$1
563 event_name="$2"
564 channel_name=$3
565
566 if [ -z $channel_name ]; then
567 # default channel if none specified
568 chan=""
569 else
570 chan="-c $channel_name"
571 fi
572
2cf48300 573 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
37175ce4
DG
574 ok $? "Enable JUL event $event_name for session $sess_name"
575}
576
b2064f54
DG
577function enable_jul_lttng_event_loglevel()
578{
7d0ad314
JRJ
579 local sess_name=$1
580 local event_name="$2"
581 local loglevel=$3
582 local channel_name=$4
b2064f54
DG
583
584 if [ -z $channel_name ]; then
585 # default channel if none specified
586 chan=""
587 else
588 chan="-c $channel_name"
589 fi
590
2cf48300 591 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
b2064f54
DG
592 ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
593}
594
504d4ace
DG
595function enable_log4j_lttng_event()
596{
597 sess_name=$1
598 event_name="$2"
599 channel_name=$3
600
601 if [ -z $channel_name ]; then
602 # default channel if none specified
603 chan=""
604 else
605 chan="-c $channel_name"
606 fi
607
2cf48300 608 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
504d4ace
DG
609 ok $? "Enable LOG4J event $event_name for session $sess_name"
610}
611
612function enable_log4j_lttng_event_loglevel()
613{
614 local sess_name=$1
615 local event_name="$2"
616 local loglevel=$3
617 local channel_name=$4
618
619 if [ -z $channel_name ]; then
620 # default channel if none specified
621 chan=""
622 else
623 chan="-c $channel_name"
624 fi
625
2cf48300 626 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
504d4ace
DG
627 ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
628}
629
0e115563
DG
630function enable_python_lttng_event()
631{
632 sess_name=$1
633 event_name="$2"
634 channel_name=$3
635
636 if [ -z $channel_name ]; then
637 # default channel if none specified
638 chan=""
639 else
640 chan="-c $channel_name"
641 fi
642
2cf48300 643 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
0e115563
DG
644 ok $? "Enable Python event $event_name for session $sess_name"
645}
646
647function enable_python_lttng_event_loglevel()
648{
649 local sess_name=$1
650 local event_name="$2"
651 local loglevel=$3
652 local channel_name=$4
653
654 if [ -z $channel_name ]; then
655 # default channel if none specified
656 chan=""
657 else
658 chan="-c $channel_name"
659 fi
660
2cf48300 661 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
0e115563
DG
662 ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel"
663}
664
26b53d3b
DG
665function enable_ust_lttng_event_filter()
666{
7d0ad314
JRJ
667 local sess_name="$1"
668 local event_name="$2"
669 local filter="$3"
26b53d3b 670
2cf48300 671 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 672 ok $? "Enable event $event_name with filtering for session $sess_name"
26b53d3b
DG
673}
674
675function enable_ust_lttng_event_loglevel()
676{
7d0ad314
JRJ
677 local sess_name="$1"
678 local event_name="$2"
679 local loglevel="$3"
26b53d3b 680
2cf48300 681 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 682 ok $? "Enable event $event_name with loglevel $loglevel"
26b53d3b
DG
683}
684
685function enable_ust_lttng_event_loglevel_only()
686{
7d0ad314
JRJ
687 local sess_name="$1"
688 local event_name="$2"
689 local loglevel="$3"
26b53d3b 690
2cf48300 691 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 692 ok $? "Enable event $event_name with loglevel-only $loglevel"
26b53d3b
DG
693}
694
695function disable_ust_lttng_event ()
696{
7d0ad314
JRJ
697 local sess_name="$1"
698 local event_name="$2"
01513c3e 699 local channel_name="$3"
26b53d3b 700
01513c3e
JRJ
701 if [ -z $channel_name ]; then
702 # default channel if none specified
703 chan=""
704 else
705 chan="-c $channel_name"
706 fi
707
2cf48300 708 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 709 ok $? "Disable event $event_name for session $sess_name"
d3e8f6bb
DG
710}
711
1d842d5a
DG
712function disable_jul_lttng_event ()
713{
714 local sess_name="$1"
715 local event_name="$2"
716
717 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1
718 ok $? "Disable JUL event $event_name for session $sess_name"
719}
720
504d4ace
DG
721function disable_log4j_lttng_event ()
722{
723 local sess_name="$1"
724 local event_name="$2"
725
726 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1
727 ok $? "Disable LOG4J event $event_name for session $sess_name"
728}
729
0e115563
DG
730function disable_python_lttng_event ()
731{
732 local sess_name="$1"
733 local event_name="$2"
734
2cf48300 735 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
0e115563
DG
736 ok $? "Disable Python event $event_name for session $sess_name"
737}
738
fb3268e3 739function start_lttng_tracing ()
d3e8f6bb 740{
e563bbdb
JR
741 local expected_to_fail=$1
742 local sess_name=$2
d3e8f6bb 743
2cf48300 744 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 745 ret=$?
e563bbdb 746 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e
JRJ
747 test "$ret" -ne "0"
748 ok $? "Expected fail on start tracing for session: $sess_name"
749 else
750 ok $ret "Start tracing for session $sess_name"
751 fi
d3e8f6bb
DG
752}
753
e563bbdb
JR
754function start_lttng_tracing_ok ()
755{
756 start_lttng_tracing 0 "$@"
757}
758
759function start_lttng_tracing_fail ()
760{
761 start_lttng_tracing 1 "$@"
762}
763
fb3268e3 764function stop_lttng_tracing ()
d3e8f6bb 765{
96340a01
JR
766 local expected_to_fail=$1
767 local sess_name=$2
d3e8f6bb 768
2cf48300 769 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 770 ret=$?
96340a01 771 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e
JRJ
772 test "$ret" -ne "0"
773 ok $? "Expected fail on stop tracing for session: $sess_name"
774 else
775 ok $ret "Stop lttng tracing for session $sess_name"
776 fi
d3e8f6bb
DG
777}
778
96340a01
JR
779function stop_lttng_tracing_ok ()
780{
781 stop_lttng_tracing 0 "$@"
782}
783
784function stop_lttng_tracing_fail ()
785{
786 stop_lttng_tracing 1 "$@"
787}
788
d3e8f6bb
DG
789function destroy_lttng_session ()
790{
67b4c664
JR
791 local expected_to_fail=$1
792 local sess_name=$2
d3e8f6bb 793
2cf48300 794 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 795 ret=$?
96340a01 796 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e
JRJ
797 test "$ret" -ne "0"
798 ok $? "Expected fail on session deletion $sess_name"
799 else
800 ok $ret "Destroy session $sess_name"
801 fi
d3e8f6bb
DG
802}
803
67b4c664
JR
804function destroy_lttng_session_ok ()
805{
806 destroy_lttng_session 0 "$@"
807
808}
809
810function destroy_lttng_session_fail ()
811{
812 destroy_lttng_session 1 "$@"
813}
814
815
873c2aae
JRJ
816function destroy_lttng_sessions ()
817{
2cf48300 818 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
873c2aae
JRJ
819 ok $? "Destroy all lttng sessions"
820}
821
07b86b52
JD
822function lttng_snapshot_add_output ()
823{
b5633831
JR
824 local expected_to_fail=$1
825 local sess_name=$2
826 local trace_path=$3
07b86b52 827
2cf48300 828 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name file://$trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 829 ret=$?
b5633831 830 if [[ $expected_to_fail -eq 1 ]]; then
01513c3e
JRJ
831 test "$ret" -ne "0"
832 ok $? "Failed to add a snapshot output file://$trace_path as expected"
833 else
834 ok $ret "Added snapshot output file://$trace_path"
835 fi
07b86b52
JD
836}
837
b5633831
JR
838function lttng_snapshot_add_output_ok ()
839{
840 lttng_snapshot_add_output 0 "$@"
841}
842
843function lttng_snapshot_add_output_fail ()
844{
845 lttng_snapshot_add_output 1 "$@"
846}
847
26402e0c
DG
848function lttng_snapshot_del_output ()
849{
31580dc7
JR
850 local expected_to_fail=$1
851 local sess_name=$2
852 local id=$3
26402e0c 853
2cf48300 854 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 855 ret=$?
31580dc7 856 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e
JRJ
857 test "$ret" -ne "0"
858 ok $? "Expect fail on deletion of snapshot output id $id"
859 else
860 ok $ret "Deleted snapshot output id $id"
861 fi
26402e0c
DG
862}
863
31580dc7
JR
864function lttng_snapshot_del_output_ok ()
865{
866 lttng_snapshot_del_output 0 "$@"
867}
868
869function lttng_snapshot_del_output_fail ()
870{
871 lttng_snapshot_del_output 1 "$@"
872}
873
07b86b52
JD
874function lttng_snapshot_record ()
875{
7d0ad314
JRJ
876 local sess_name=$1
877 local trace_path=$2
07b86b52 878
2cf48300 879 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
07b86b52
JD
880 ok $? "Snapshot recorded"
881}
882
01513c3e
JRJ
883function lttng_snapshot_list ()
884{
885 local sess_name=$1
2cf48300 886 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e
JRJ
887 ok $? "Snapshot list"
888}
889
e02b109b
DG
890function lttng_save()
891{
892 local sess_name=$1
893 local opts=$2
894
2cf48300 895 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
e02b109b
DG
896 ok $? "Session successfully saved"
897}
898
899function lttng_load()
900{
901 local opts=$1
902
2cf48300 903 $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
e02b109b
DG
904 ok $? "Load command successful"
905}
906
e83a8bdb
JR
907function lttng_track()
908{
909 local expected_to_fail=$1
910 local opts=$2
911 $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST
912 ret=$?
913 if [[ $expected_to_fail -eq "1" ]]; then
914 test $ret -ne "0"
915 ok $? "Track command failed as expected with opts: $opts"
916 else
917 ok $ret "Track command success as expected with opts: $opts"
918 fi
919}
920
921function lttng_track_ok()
922{
923 lttng_track 0 "$@"
924}
925
926function lttng_track_fail()
927{
928 lttng_track 1 "$@"
929}
930
931function lttng_untrack()
932{
933 local expected_to_fail=$1
934 local opts=$2
935 $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST
936 ret=$?
937 if [[ $expected_to_fail -eq "1" ]]; then
938 test $ret -ne "0"
939 ok $? "Untrack command failed as expected with opts: $opts"
940 else
941 ok $ret "Untrack command success as expected with opts: $opts"
942 fi
943}
944
945function lttng_untrack_ok()
946{
947 lttng_untrack 0 "$@"
948}
949
950function lttng_untrack_fail()
951{
952 lttng_untrack 1 "$@"
953}
954
d3e8f6bb
DG
955function trace_matches ()
956{
7d0ad314
JRJ
957 local event_name=$1
958 local nr_iter=$2
959 local trace_path=$3
d3e8f6bb 960
317eef93 961 which $BABELTRACE_BIN >/dev/null
29655db7 962 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
d3e8f6bb 963
7d0ad314 964 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
29655db7 965
d3e8f6bb 966 if [ "$count" -ne "$nr_iter" ]; then
29655db7
CB
967 fail "Trace match"
968 diag "$count events found in trace"
d3e8f6bb 969 else
29655db7 970 pass "Trace match"
d3e8f6bb
DG
971 fi
972}
f4e40ab6 973
d53addeb
DG
974function trace_match_only()
975{
976 local event_name=$1
977 local nr_iter=$2
978 local trace_path=$3
979
980 which $BABELTRACE_BIN >/dev/null
981 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
982
983 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
984 local total=$($BABELTRACE_BIN $trace_path | wc -l)
985
986 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
987 pass "Trace match with $total event $event_name"
988 else
989 fail "Trace match"
990 diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
991 fi
992}
993
f4e40ab6
DG
994function validate_trace
995{
7d0ad314
JRJ
996 local event_name=$1
997 local trace_path=$2
f4e40ab6
DG
998
999 which $BABELTRACE_BIN >/dev/null
29655db7
CB
1000 if [ $? -ne 0 ]; then
1001 skip 0 "Babeltrace binary not found. Skipping trace validation"
f4e40ab6
DG
1002 fi
1003
07b86b52
JD
1004 OLDIFS=$IFS
1005 IFS=","
1006 for i in $event_name; do
1007 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1008 if [ "$traced" -ne 0 ]; then
ebaaaf5e 1009 pass "Validate trace for event $i, $traced events"
07b86b52
JD
1010 else
1011 fail "Validate trace for event $i"
1012 diag "Found $traced occurences of $i"
1013 fi
1014 done
1015 ret=$?
1016 IFS=$OLDIFS
1017 return $ret
f4e40ab6 1018}
8cfcd41c
MD
1019
1020function validate_trace_exp()
1021{
1022 local event_exp=$1
1023 local trace_path=$2
1024
1025 which $BABELTRACE_BIN >/dev/null
1026 skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
1027
1028 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep ${event_exp} | wc -l)
1029 if [ "$traced" -ne 0 ]; then
1030 pass "Validate trace for expression '${event_exp}', $traced events"
1031 else
1032 fail "Validate trace for expression '${event_exp}'"
1033 diag "Found $traced occurences of '${event_exp}'"
1034 fi
1035 ret=$?
1036 return $ret
1037}
1038
1039function validate_trace_only_exp()
1040{
1041 local event_exp=$1
1042 local trace_path=$2
1043
1044 which $BABELTRACE_BIN >/dev/null
1045 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1046
1047 local count=$($BABELTRACE_BIN $trace_path | grep ${event_exp} | wc -l)
1048 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1049
1050 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1051 pass "Trace match with $total for expression '${event_exp}"
1052 else
1053 fail "Trace match"
1054 diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1055 fi
1056 ret=$?
1057 return $ret
1058}
1059
1060function validate_trace_empty()
1061{
1062 local trace_path=$1
1063
1064 which $BABELTRACE_BIN >/dev/null
1065 if [ $? -ne 0 ]; then
1066 skip 0 "Babeltrace binary not found. Skipping trace validation"
1067 fi
1068
1069 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | wc -l)
1070 if [ "$traced" -eq 0 ]; then
1071 pass "Validate empty trace"
1072 else
1073 fail "Validate empty trace"
1074 diag "Found $traced events in trace"
1075 fi
1076 ret=$?
1077 return $ret
1078}
This page took 0.095144 seconds and 5 git commands to generate.