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