Tests: regression testing for notification API
[lttng-tools.git] / tests / utils / utils.sh
CommitLineData
d3e8f6bb
DG
1# Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
2#
3# This library is free software; you can redistribute it and/or modify it under
4# the terms of the GNU Lesser General Public License as published by the Free
5# Software Foundation; version 2.1 of the License.
6#
7# This library is distributed in the hope that it will be useful, but WITHOUT
8# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
10# details.
11#
12# You should have received a copy of the GNU Lesser General Public License
13# along with this library; if not, write to the Free Software Foundation, Inc.,
14# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
16SESSIOND_BIN="lttng-sessiond"
725f658e 17SESSIOND_MATCH=".*lttng-sess.*"
1c362dc7 18SESSIOND_PIDS=""
19356f3a 19RUNAS_BIN="lttng-runas"
725f658e 20RUNAS_MATCH=".*lttng-runas.*"
f7613992 21CONSUMERD_BIN="lttng-consumerd"
725f658e 22CONSUMERD_MATCH=".*lttng-consumerd.*"
f4e40ab6 23RELAYD_BIN="lttng-relayd"
725f658e 24RELAYD_MATCH=".*lttng-relayd.*"
1c362dc7 25RELAYD_PIDS=""
d3e8f6bb
DG
26LTTNG_BIN="lttng"
27BABELTRACE_BIN="babeltrace"
2cf48300
JR
28OUTPUT_DEST=/dev/null
29ERROR_OUTPUT_DEST=/dev/null
d3e8f6bb 30
fd4dfcec
DG
31# Minimal kernel version supported for session daemon tests
32KERNEL_MAJOR_VERSION=2
33KERNEL_MINOR_VERSION=6
34KERNEL_PATCHLEVEL_VERSION=27
35
651b8bb3
JG
36# We set the default UST register timeout and network and app socket timeout to
37# "wait forever", so that basic tests don't have to worry about hitting
38# timeouts on busy systems. Specialized tests should test those corner-cases.
629b9335 39export LTTNG_UST_REGISTER_TIMEOUT=-1
651b8bb3
JG
40export LTTNG_NETWORK_SOCKET_TIMEOUT=-1
41export LTTNG_APP_SOCKET_TIMEOUT=-1
629b9335 42
fd7fe1a8
JR
43# We set the default lttng-sessiond path to /bin/true to prevent the spawning
44# of a daemonized sessiond. This is necessary since 'lttng create' will spawn
45# its own sessiond if none is running. It also ensures that 'lttng create'
46# fails when no sessiond is running.
47export LTTNG_SESSIOND_PATH="/bin/true"
48
29655db7
CB
49source $TESTDIR/utils/tap/tap.sh
50
1c362dc7
JR
51function full_cleanup ()
52{
53 if [ -n "${SESSIOND_PIDS}" ] || [ -n "${RELAYD_PIDS}" ]; then
54 kill -9 ${SESSIOND_PIDS} ${RELAYD_PIDS} > /dev/null 2>&1
55 fi
56
57 # Disable trap for SIGTERM since the following kill to the
58 # pidgroup will be SIGTERM. Otherwise it loops.
59 # The '-' before the pid number ($$) indicates 'kill' to signal the
60 # whole process group.
61 trap - SIGTERM && kill -- -$$
62}
63
64
65trap full_cleanup SIGINT SIGTERM
66
fec81a7e
CB
67function print_ok ()
68{
69 # Check if we are a terminal
70 if [ -t 1 ]; then
71 echo -e "\e[1;32mOK\e[0m"
72 else
73 echo -e "OK"
74 fi
75}
76
77function print_fail ()
78{
79 # Check if we are a terminal
80 if [ -t 1 ]; then
81 echo -e "\e[1;31mFAIL\e[0m"
82 else
83 echo -e "FAIL"
84 fi
85}
86
87function print_test_banner ()
88{
7d0ad314 89 local desc="$1"
29655db7 90 diag "$desc"
fec81a7e
CB
91}
92
fd4dfcec
DG
93function validate_kernel_version ()
94{
7d0ad314 95 local kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n'))
fd4dfcec
DG
96 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
97 return 0
98 fi
99 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
100 return 0
101 fi
102 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
103 return 0
104 fi
105 return 1
106}
107
9ac429ef 108# Generate a random string
f4e40ab6
DG
109# $1 = number of characters; defaults to 16
110# $2 = include special characters; 1 = yes, 0 = no; defaults to yes
9ac429ef 111function randstring()
f4e40ab6
DG
112{
113 [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
b89c3a68 114 cat /dev/urandom 2>/dev/null | tr -cd "$CHAR" 2>/dev/null | head -c ${1:-16} 2>/dev/null
f4e40ab6
DG
115 echo
116}
117
9e136324
JG
118# Return the number of _configured_ CPUs.
119function conf_proc_count()
120{
121 getconf _NPROCESSORS_CONF
122 if [ $? -ne 0 ]; then
123 diag "Failed to get the number of configured CPUs"
124 fi
125 echo
126}
127
4a180d9f 128function enable_kernel_lttng_event
f4e40ab6 129{
4a180d9f
MD
130 local expected_to_fail="$1"
131 local sess_name="$2"
132 local event_name="$3"
133 local channel_name="$4"
f4e40ab6 134
4a180d9f 135 if [ -z "$event_name" ]; then
f4e40ab6 136 # Enable all event if no event name specified
29655db7 137 event_name="-a"
f4e40ab6
DG
138 fi
139
4a180d9f 140 if [ -z "$channel_name" ]; then
07b86b52
JD
141 # default channel if none specified
142 chan=""
143 else
144 chan="-c $channel_name"
145 fi
146
2cf48300 147 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
4a180d9f
MD
148 ret=$?
149 if [[ $expected_to_fail -eq "1" ]]; then
150 test $ret -ne "0"
151 ok $? "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
152 else
153 ok $ret "Enable kernel event $event_name for session $sess_name"
154 fi
155}
156
157function enable_kernel_lttng_event_ok ()
158{
159 enable_kernel_lttng_event 0 "$@"
160}
161
162function enable_kernel_lttng_event_fail ()
163{
164 enable_kernel_lttng_event 1 "$@"
165}
166
167# Old interface
168function lttng_enable_kernel_event
169{
170 enable_kernel_lttng_event_ok "$@"
f4e40ab6
DG
171}
172
8cfcd41c
MD
173function lttng_enable_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 enable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
8cfcd41c
MD
193 ret=$?
194 if [[ $expected_to_fail -eq "1" ]]; then
195 test $ret -ne "0"
196 ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
197 else
198 ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
199 fi
200}
201
202function lttng_enable_kernel_syscall_ok()
203{
421b83dc 204 lttng_enable_kernel_syscall 0 "$@"
8cfcd41c
MD
205}
206
207function lttng_enable_kernel_syscall_fail()
208{
421b83dc 209 lttng_enable_kernel_syscall 1 "$@"
8cfcd41c
MD
210}
211
212function lttng_disable_kernel_syscall()
213{
214 local expected_to_fail=$1
215 local sess_name=$2
216 local syscall_name=$3
217 local channel_name=$4
218
219 if [ -z $syscall_name ]; then
220 # Enable all event if no syscall name specified
221 syscall_name="-a"
222 fi
223
224 if [ -z $channel_name ]; then
225 # default channel if none specified
226 chan=""
227 else
228 chan="-c $channel_name"
229 fi
230
2cf48300 231 $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
232
233 ret=$?
234 if [[ $expected_to_fail -eq "1" ]]; then
235 test $ret -ne "0"
34ab15c5 236 ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
8cfcd41c
MD
237 else
238 ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
239 fi
240}
241
242function lttng_disable_kernel_syscall_ok()
243{
421b83dc 244 lttng_disable_kernel_syscall 0 "$@"
8cfcd41c
MD
245}
246
247function lttng_disable_kernel_syscall_fail()
248{
421b83dc 249 lttng_disable_kernel_syscall 1 "$@"
8cfcd41c
MD
250}
251
d96f6315
MD
252function lttng_enable_kernel_channel()
253{
254 local expected_to_fail=$1
255 local sess_name=$2
256 local channel_name=$3
257
2cf48300 258 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
d96f6315
MD
259 ret=$?
260 if [[ $expected_to_fail -eq "1" ]]; then
261 test "$ret" -ne "0"
34ab15c5 262 ok $? "Enable channel $channel_name for session $sess_name failed as expected"
d96f6315
MD
263 else
264 ok $ret "Enable channel $channel_name for session $sess_name"
265 fi
266}
267
268function lttng_enable_kernel_channel_ok()
269{
421b83dc 270 lttng_enable_kernel_channel 0 "$@"
d96f6315
MD
271}
272
273function lttng_enable_kernel_channel_fail()
274{
421b83dc 275 lttng_enable_kernel_channel 1 "$@"
d96f6315
MD
276}
277
278function lttng_disable_kernel_channel()
279{
280 local expected_to_fail=$1
281 local sess_name=$2
282 local channel_name=$3
283
2cf48300 284 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
d96f6315
MD
285 ret=$?
286 if [[ $expected_to_fail -eq "1" ]]; then
287 test "$ret" -ne "0"
34ab15c5 288 ok $? "Disable channel $channel_name for session $sess_name failed as expected"
d96f6315 289 else
34ab15c5 290 ok $ret "Disable channel $channel_name for session $sess_name"
d96f6315
MD
291 fi
292}
293
294function lttng_disable_kernel_channel_ok()
295{
421b83dc 296 lttng_disable_kernel_channel 0 "$@"
d96f6315
MD
297}
298
299function lttng_disable_kernel_channel_fail()
300{
421b83dc 301 lttng_disable_kernel_channel 1 "$@"
d96f6315
MD
302}
303
05aa48da 304function start_lttng_relayd_opt()
f4e40ab6 305{
05aa48da
MD
306 local withtap=$1
307 local opt=$2
173af62f 308
f4e40ab6
DG
309 DIR=$(readlink -f $TESTDIR)
310
725f658e 311 if [ -z $(pgrep $RELAYD_MATCH) ]; then
2cf48300 312 $DIR/../src/bin/lttng-relayd/$RELAYD_BIN -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
25a818af 313 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
f4e40ab6 314 if [ $? -eq 1 ]; then
05aa48da
MD
315 if [ $withtap -eq "1" ]; then
316 fail "Start lttng-relayd (opt: $opt)"
317 fi
f4e40ab6
DG
318 return 1
319 else
05aa48da
MD
320 if [ $withtap -eq "1" ]; then
321 pass "Start lttng-relayd (opt: $opt)"
322 fi
f4e40ab6
DG
323 fi
324 else
29655db7 325 pass "Start lttng-relayd (opt: $opt)"
f4e40ab6 326 fi
1c362dc7 327
725f658e 328 RELAYD_PIDS=$(pgrep $RELAYD_MATCH)
f4e40ab6
DG
329}
330
05aa48da 331function start_lttng_relayd()
f4e40ab6 332{
05aa48da
MD
333 start_lttng_relayd_opt 1 "$@"
334}
335
336function start_lttng_relayd_notap()
337{
338 start_lttng_relayd_opt 0 "$@"
339}
340
341function stop_lttng_relayd_opt()
342{
343 local withtap=$1
344
05aa48da 345 if [ $withtap -eq "1" ]; then
1c362dc7 346 diag "Killing lttng-relayd (pid: $RELAYD_PIDS)"
05aa48da 347 fi
1c362dc7 348 kill $RELAYD_PIDS 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1fb23888 349 retval=$?
29655db7 350
05aa48da
MD
351 if [ $? -eq 1 ]; then
352 if [ $withtap -eq "1" ]; then
353 fail "Kill relay daemon"
354 fi
355 return 1
356 else
f4e40ab6
DG
357 out=1
358 while [ -n "$out" ]; do
725f658e 359 out=$(pgrep $RELAYD_MATCH)
f4e40ab6
DG
360 sleep 0.5
361 done
05aa48da
MD
362 if [ $withtap -eq "1" ]; then
363 pass "Kill relay daemon"
364 fi
1fb23888 365 fi
1c362dc7 366 RELAYD_PIDS=""
1fb23888
MD
367 return $retval
368}
369
05aa48da 370function stop_lttng_relayd()
1fb23888 371{
05aa48da
MD
372 stop_lttng_relayd_opt 1 "$@"
373}
1fb23888 374
05aa48da
MD
375function stop_lttng_relayd_notap()
376{
377 stop_lttng_relayd_opt 0 "$@"
f4e40ab6
DG
378}
379
05aa48da
MD
380#First arg: show tap output
381#Second argument: load path for automatic loading
382function start_lttng_sessiond_opt()
355f483d 383{
05aa48da
MD
384 local withtap=$1
385 local load_path=$2
8d51ddbc 386
4b01971f 387 local env_vars=""
b916da6b
JR
388 local consumerd=""
389 local long_bit_value=$(getconf LONG_BIT)
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
b916da6b
JR
396 DIR=$(readlink -f $TESTDIR)
397
398 # Get long_bit value for 32/64 consumerd
399 case "$long_bit_value" in
400 32)
401 consumerd="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
402 ;;
403 64)
404 consumerd="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
405 ;;
406 *)
407 return
408 ;;
409 esac
410
4b01971f
JR
411 # Check for env. variable. Allow the use of LD_PRELOAD etc.
412 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
413 env_vars=${LTTNG_SESSIOND_ENV_VARS}
414 fi
415
29655db7
CB
416 validate_kernel_version
417 if [ $? -ne 0 ]; then
418 fail "Start session daemon"
419 BAIL_OUT "*** Kernel too old for session daemon tests ***"
355f483d
DG
420 fi
421
d3d97763
JG
422 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
423 export LTTNG_SESSION_CONFIG_XSD_PATH
29655db7 424
725f658e 425 if [ -z $(pgrep ${SESSIOND_MATCH}) ]; then
8d51ddbc 426 # Have a load path ?
05aa48da 427 if [ -n "$load_path" ]; then
4b01971f 428 env $env_vars $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --load "$load_path" --background $consumerd
8d51ddbc 429 else
4b01971f 430 env $env_vars $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --background $consumerd
8d51ddbc 431 fi
0fc2834c 432 #$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 433 status=$?
05aa48da
MD
434 if [ $withtap -eq "1" ]; then
435 ok $status "Start session daemon"
436 fi
29655db7 437 fi
725f658e 438 SESSIOND_PIDS=$(pgrep $SESSIOND_MATCH)
355f483d
DG
439}
440
05aa48da
MD
441function start_lttng_sessiond()
442{
443 start_lttng_sessiond_opt 1 "$@"
444}
445
446function start_lttng_sessiond_notap()
d3e8f6bb 447{
05aa48da
MD
448 start_lttng_sessiond_opt 0 "$@"
449}
450
451function stop_lttng_sessiond_opt()
452{
453 local withtap=$1
4c80129b
JR
454 local signal=$2
455 local kill_opt=""
05aa48da 456
355f483d
DG
457 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
458 # Env variable requested no session daemon
459 return
460 fi
461
725f658e 462 local pids="${SESSIOND_PIDS} $(pgrep $RUNAS_MATCH)"
d3e8f6bb 463
4c80129b
JR
464 if [ -n "$2" ]; then
465 kill_opt="$kill_opt -s $signal"
466 fi
8490897a 467 if [ $withtap -eq "1" ]; then
725f658e 468 diag "Killing $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo $pids | tr '\n' ' ')"
8490897a 469 fi
1c362dc7 470 kill $kill_opt $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 471
d3e8f6bb 472 if [ $? -eq 1 ]; then
05aa48da
MD
473 if [ $withtap -eq "1" ]; then
474 fail "Kill sessions daemon"
475 fi
d3e8f6bb 476 else
5fa32580
DG
477 out=1
478 while [ -n "$out" ]; do
725f658e 479 out=$(pgrep ${SESSIOND_MATCH})
5fa32580
DG
480 sleep 0.5
481 done
f7613992
MD
482 out=1
483 while [ -n "$out" ]; do
725f658e 484 out=$(pgrep $CONSUMERD_MATCH)
f7613992
MD
485 sleep 0.5
486 done
1c362dc7
JR
487
488 SESSIOND_PIDS=""
05aa48da
MD
489 if [ $withtap -eq "1" ]; then
490 pass "Kill session daemon"
491 fi
d3e8f6bb
DG
492 fi
493}
494
05aa48da
MD
495function stop_lttng_sessiond()
496{
497 stop_lttng_sessiond_opt 1 "$@"
498}
499
500function stop_lttng_sessiond_notap()
501{
502 stop_lttng_sessiond_opt 0 "$@"
503}
504
8490897a
MD
505function sigstop_lttng_sessiond_opt()
506{
507 local withtap=$1
508 local signal=SIGSTOP
509 local kill_opt=""
510
511 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
512 # Env variable requested no session daemon
513 return
514 fi
515
725f658e 516 PID_SESSIOND="$(pgrep ${SESSIOND_MATCH}) $(pgrep $RUNAS_MATCH)"
8490897a
MD
517
518 kill_opt="$kill_opt -s $signal"
519
520 if [ $withtap -eq "1" ]; then
725f658e 521 diag "Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo $PID_SESSIOND | tr '\n' ' ')"
8490897a
MD
522 fi
523 kill $kill_opt $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
524
525 if [ $? -eq 1 ]; then
526 if [ $withtap -eq "1" ]; then
527 fail "Sending SIGSTOP to session daemon"
528 fi
529 else
530 out=1
531 while [ $out -ne 0 ]; do
725f658e 532 pid=$(pgrep $SESSIOND_MATCH)
8490897a
MD
533
534 # Wait until state becomes stopped for session
535 # daemon(s).
536 out=0
537 for sessiond_pid in $pid; do
538 state=$(ps -p $sessiond_pid -o state= )
539 if [[ -n "$state" && "$state" != "T" ]]; then
540 out=1
541 fi
542 done
543 sleep 0.5
544 done
545 if [ $withtap -eq "1" ]; then
546 pass "Sending SIGSTOP to session daemon"
547 fi
548 fi
549}
550
551function sigstop_lttng_sessiond()
552{
553 sigstop_lttng_sessiond_opt 1 "$@"
554}
555
556function sigstop_lttng_sessiond_notap()
557{
558 sigstop_lttng_sessiond_opt 0 "$@"
559}
560
4c80129b
JR
561function stop_lttng_consumerd_opt()
562{
563 local withtap=$1
564 local signal=$2
565 local kill_opt=""
566
725f658e 567 PID_CONSUMERD=$(pgrep $CONSUMERD_MATCH)
4c80129b
JR
568
569 if [ -n "$2" ]; then
570 kill_opt="$kill_opt -s $signal"
571 fi
572
573 if [ $withtap -eq "1" ]; then
8490897a 574 diag "Killing $CONSUMERD_BIN pids: $(echo $PID_CONSUMERD | tr '\n' ' ')"
4c80129b
JR
575 fi
576 kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
577 retval=$?
578 set +x
579
580 if [ $? -eq 1 ]; then
581 if [ $withtap -eq "1" ]; then
582 fail "Kill consumer daemon"
583 fi
584 return 1
585 else
586 out=1
587 while [ $out -ne 0 ]; do
725f658e 588 pid=$(pgrep $CONSUMERD_MATCH)
4c80129b
JR
589
590 # If consumerds are still present check their status.
591 # A zombie status qualifies the consumerd as *killed*
592 out=0
593 for consumer_pid in $pid; do
594 state=$(ps -p $consumer_pid -o state= )
595 if [[ -n "$state" && "$state" != "Z" ]]; then
596 out=1
597 fi
598 done
599 sleep 0.5
600 done
601 if [ $withtap -eq "1" ]; then
602 pass "Kill consumer daemon"
603 fi
604 fi
605 return $retval
606}
607
608function stop_lttng_consumerd()
609{
610 stop_lttng_consumerd_opt 1 "$@"
611}
612
613function stop_lttng_consumerd_notap()
614{
615 stop_lttng_consumerd_opt 0 "$@"
616}
617
8490897a
MD
618function sigstop_lttng_consumerd_opt()
619{
620 local withtap=$1
621 local signal=SIGSTOP
622 local kill_opt=""
623
725f658e 624 PID_CONSUMERD=$(pgrep $CONSUMERD_MATCH)
8490897a
MD
625
626 kill_opt="$kill_opt -s $signal"
627
628 if [ $withtap -eq "1" ]; then
629 diag "Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo $PID_CONSUMERD | tr '\n' ' ')"
630 fi
631 kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
632 retval=$?
633 set +x
634
635 if [ $? -eq 1 ]; then
636 if [ $withtap -eq "1" ]; then
637 fail "Sending SIGSTOP to consumer daemon"
638 fi
639 return 1
640 else
641 out=1
642 while [ $out -ne 0 ]; do
725f658e 643 pid=$(pgrep $CONSUMERD_MATCH)
8490897a
MD
644
645 # Wait until state becomes stopped for all
646 # consumers.
647 out=0
648 for consumer_pid in $pid; do
649 state=$(ps -p $consumer_pid -o state= )
650 if [[ -n "$state" && "$state" != "T" ]]; then
651 out=1
652 fi
653 done
654 sleep 0.5
655 done
656 if [ $withtap -eq "1" ]; then
657 pass "Sending SIGSTOP to consumer daemon"
658 fi
659 fi
660 return $retval
661}
662
663function sigstop_lttng_consumerd()
664{
665 sigstop_lttng_consumerd_opt 1 "$@"
666}
667
668function sigstop_lttng_consumerd_notap()
669{
670 sigstop_lttng_consumerd_opt 0 "$@"
671}
672
873c2aae
JRJ
673function list_lttng_with_opts ()
674{
7d0ad314 675 local opts=$1
2cf48300 676 $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
873c2aae
JRJ
677 ok $? "Lttng-tool list command with option $opts"
678}
679
07b86b52
JD
680function create_lttng_session_no_output ()
681{
7d0ad314 682 local sess_name=$1
07b86b52 683
2cf48300 684 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
07b86b52
JD
685 ok $? "Create session $sess_name in no-output mode"
686}
687
d3e8f6bb
DG
688function create_lttng_session ()
689{
434f8068
JR
690 local withtap=$1
691 local expected_to_fail=$2
692 local sess_name=$3
693 local trace_path=$4
694 local opt=$5
d3e8f6bb 695
4c80129b 696 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path $opt > $OUTPUT_DEST
873c2aae 697 ret=$?
434f8068 698 if [ $expected_to_fail -eq "1" ]; then
01513c3e 699 test "$ret" -ne "0"
434f8068
JR
700 ret=$?
701 if [ $withtap -eq "1" ]; then
702 ok $ret "Create session $sess_name in $trace_path failed as expected"
703 fi
873c2aae 704 else
434f8068
JR
705 if [ $withtap -eq "1" ]; then
706 ok $ret "Create session $sess_name in $trace_path"
707 fi
873c2aae 708 fi
434f8068 709 return $ret
d4018451
DG
710}
711
bf6ae429
JR
712function create_lttng_session_ok ()
713{
434f8068 714 create_lttng_session 1 0 "$@"
bf6ae429
JR
715}
716
717function create_lttng_session_fail ()
718{
434f8068
JR
719 create_lttng_session 1 1 "$@"
720}
721
722function create_lttng_session_notap ()
723{
724 create_lttng_session 0 0 "$@"
bf6ae429
JR
725}
726
727
827caf52 728function enable_ust_lttng_channel ()
d4018451 729{
434f8068
JR
730 local withtap=$1
731 local expected_to_fail=$2
732 local sess_name=$3
733 local channel_name=$4
734 local opt=$5
d4018451 735
4c80129b 736 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
312dabc3 737 ret=$?
34ab15c5 738 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 739 test "$ret" -ne "0"
434f8068
JR
740 ret=$?
741 if [ $withtap -eq "1" ]; then
742 ok $ret "Enable channel $channel_name for session $sess_name failed as expected"
743 fi
312dabc3 744 else
434f8068
JR
745 if [ $withtap -eq "1" ]; then
746 ok $ret "Enable channel $channel_name for session $sess_name"
747 fi
312dabc3 748 fi
434f8068 749 return $ret
d4018451
DG
750}
751
827caf52
JR
752function enable_ust_lttng_channel_ok ()
753{
434f8068 754 enable_ust_lttng_channel 1 0 "$@"
827caf52
JR
755}
756
757function enable_ust_lttng_channel_fail ()
758{
434f8068
JR
759 enable_ust_lttng_channel 1 1 "$@"
760}
761
762function enable_ust_lttng_channel_notap ()
763{
764 enable_ust_lttng_channel 0 0 "$@"
827caf52
JR
765}
766
29655db7 767function disable_ust_lttng_channel()
d4018451 768{
7d0ad314
JRJ
769 local sess_name=$1
770 local channel_name=$2
d4018451 771
2cf48300 772 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 773 ok $? "Disable channel $channel_name for session $sess_name"
d3e8f6bb
DG
774}
775
07b86b52
JD
776function enable_lttng_mmap_overwrite_kernel_channel()
777{
7d0ad314
JRJ
778 local sess_name=$1
779 local channel_name=$2
07b86b52 780
2cf48300 781 $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
782 ok $? "Enable channel $channel_name for session $sess_name"
783}
784
086e6add
MD
785function enable_lttng_mmap_discard_small_kernel_channel()
786{
787 local sess_name=$1
788 local channel_name=$2
789
790 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --discard --subbuf-size=$(getconf PAGE_SIZE) --num-subbuf=2 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
791 ok $? "Enable small discard channel $channel_name for session $sess_name"
792}
793
794function enable_lttng_mmap_overwrite_small_kernel_channel()
795{
796 local sess_name=$1
797 local channel_name=$2
798
799 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite --subbuf-size=$(getconf PAGE_SIZE) --num-subbuf=2 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
800 ok $? "Enable small discard channel $channel_name for session $sess_name"
801}
802
ebaaaf5e
JD
803function enable_lttng_mmap_overwrite_ust_channel()
804{
7d0ad314
JRJ
805 local sess_name=$1
806 local channel_name=$2
ebaaaf5e 807
2cf48300 808 $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
809 ok $? "Enable channel $channel_name for session $sess_name"
810}
811
d3e8f6bb
DG
812function enable_ust_lttng_event ()
813{
434f8068
JR
814 local withtap=$1
815 local expected_to_fail=$2
816 local sess_name=$3
817 local event_name="$4"
818 local channel_name=$5
ebaaaf5e
JD
819
820 if [ -z $channel_name ]; then
821 # default channel if none specified
822 chan=""
823 else
824 chan="-c $channel_name"
825 fi
d3e8f6bb 826
2cf48300 827 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 828 ret=$?
c4926bb5 829 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 830 test $ret -ne "0"
434f8068
JR
831 ret=$?
832 if [[ $withtap -eq "1" ]]; then
833 ok $ret "Enable ust event $event_name for session $session_name failed as expected"
834 fi
01513c3e 835 else
434f8068
JR
836 if [[ $withtap -eq "1" ]]; then
837 ok $ret "Enable ust event $event_name for session $sess_name"
838 fi
01513c3e 839 fi
434f8068 840 return $ret
26b53d3b
DG
841}
842
c4926bb5
JR
843function enable_ust_lttng_event_ok ()
844{
434f8068 845 enable_ust_lttng_event 1 0 "$@"
c4926bb5
JR
846}
847
848function enable_ust_lttng_event_fail ()
849{
434f8068
JR
850 enable_ust_lttng_event 1 1 "$@"
851}
852
853function enable_ust_lttng_event_notap ()
854{
855 enable_ust_lttng_event 0 0 "$@"
c4926bb5
JR
856}
857
37175ce4
DG
858function enable_jul_lttng_event()
859{
860 sess_name=$1
861 event_name="$2"
862 channel_name=$3
863
864 if [ -z $channel_name ]; then
865 # default channel if none specified
866 chan=""
867 else
868 chan="-c $channel_name"
869 fi
870
2cf48300 871 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
37175ce4
DG
872 ok $? "Enable JUL event $event_name for session $sess_name"
873}
874
b2064f54
DG
875function enable_jul_lttng_event_loglevel()
876{
7d0ad314
JRJ
877 local sess_name=$1
878 local event_name="$2"
879 local loglevel=$3
880 local channel_name=$4
b2064f54
DG
881
882 if [ -z $channel_name ]; then
883 # default channel if none specified
884 chan=""
885 else
886 chan="-c $channel_name"
887 fi
888
2cf48300 889 $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
890 ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
891}
892
504d4ace
DG
893function enable_log4j_lttng_event()
894{
895 sess_name=$1
896 event_name="$2"
897 channel_name=$3
898
899 if [ -z $channel_name ]; then
900 # default channel if none specified
901 chan=""
902 else
903 chan="-c $channel_name"
904 fi
905
2cf48300 906 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
504d4ace
DG
907 ok $? "Enable LOG4J event $event_name for session $sess_name"
908}
909
910function enable_log4j_lttng_event_loglevel()
911{
912 local sess_name=$1
913 local event_name="$2"
914 local loglevel=$3
915 local channel_name=$4
916
917 if [ -z $channel_name ]; then
918 # default channel if none specified
919 chan=""
920 else
921 chan="-c $channel_name"
922 fi
923
2cf48300 924 $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
925 ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
926}
927
0e115563
DG
928function enable_python_lttng_event()
929{
930 sess_name=$1
931 event_name="$2"
932 channel_name=$3
933
934 if [ -z $channel_name ]; then
935 # default channel if none specified
936 chan=""
937 else
938 chan="-c $channel_name"
939 fi
940
2cf48300 941 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
0e115563
DG
942 ok $? "Enable Python event $event_name for session $sess_name"
943}
944
945function enable_python_lttng_event_loglevel()
946{
947 local sess_name=$1
948 local event_name="$2"
949 local loglevel=$3
950 local channel_name=$4
951
952 if [ -z $channel_name ]; then
953 # default channel if none specified
954 chan=""
955 else
956 chan="-c $channel_name"
957 fi
958
2cf48300 959 $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
960 ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel"
961}
962
26b53d3b
DG
963function enable_ust_lttng_event_filter()
964{
7d0ad314
JRJ
965 local sess_name="$1"
966 local event_name="$2"
967 local filter="$3"
26b53d3b 968
2cf48300 969 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 970 ok $? "Enable event $event_name with filtering for session $sess_name"
26b53d3b
DG
971}
972
973function enable_ust_lttng_event_loglevel()
974{
7d0ad314
JRJ
975 local sess_name="$1"
976 local event_name="$2"
977 local loglevel="$3"
26b53d3b 978
2cf48300 979 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 980 ok $? "Enable event $event_name with loglevel $loglevel"
26b53d3b
DG
981}
982
983function enable_ust_lttng_event_loglevel_only()
984{
7d0ad314
JRJ
985 local sess_name="$1"
986 local event_name="$2"
987 local loglevel="$3"
26b53d3b 988
2cf48300 989 $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 990 ok $? "Enable event $event_name with loglevel-only $loglevel"
26b53d3b
DG
991}
992
993function disable_ust_lttng_event ()
994{
7d0ad314
JRJ
995 local sess_name="$1"
996 local event_name="$2"
01513c3e 997 local channel_name="$3"
26b53d3b 998
01513c3e
JRJ
999 if [ -z $channel_name ]; then
1000 # default channel if none specified
1001 chan=""
1002 else
1003 chan="-c $channel_name"
1004 fi
1005
2cf48300 1006 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 1007 ok $? "Disable event $event_name for session $sess_name"
d3e8f6bb
DG
1008}
1009
1d842d5a
DG
1010function disable_jul_lttng_event ()
1011{
1012 local sess_name="$1"
1013 local event_name="$2"
1014
1015 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1
1016 ok $? "Disable JUL event $event_name for session $sess_name"
1017}
1018
504d4ace
DG
1019function disable_log4j_lttng_event ()
1020{
1021 local sess_name="$1"
1022 local event_name="$2"
1023
1024 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1
1025 ok $? "Disable LOG4J event $event_name for session $sess_name"
1026}
1027
0e115563
DG
1028function disable_python_lttng_event ()
1029{
1030 local sess_name="$1"
1031 local event_name="$2"
1032
2cf48300 1033 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
0e115563
DG
1034 ok $? "Disable Python event $event_name for session $sess_name"
1035}
1036
fb3268e3 1037function start_lttng_tracing ()
d3e8f6bb 1038{
e563bbdb
JR
1039 local expected_to_fail=$1
1040 local sess_name=$2
d3e8f6bb 1041
2cf48300 1042 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1043 ret=$?
e563bbdb 1044 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1045 test "$ret" -ne "0"
34ab15c5 1046 ok $? "Start tracing for session $sess_name failed as expected"
01513c3e
JRJ
1047 else
1048 ok $ret "Start tracing for session $sess_name"
1049 fi
d3e8f6bb
DG
1050}
1051
e563bbdb
JR
1052function start_lttng_tracing_ok ()
1053{
1054 start_lttng_tracing 0 "$@"
1055}
1056
1057function start_lttng_tracing_fail ()
1058{
1059 start_lttng_tracing 1 "$@"
1060}
1061
fb3268e3 1062function stop_lttng_tracing ()
d3e8f6bb 1063{
96340a01
JR
1064 local expected_to_fail=$1
1065 local sess_name=$2
d3e8f6bb 1066
2cf48300 1067 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1068 ret=$?
96340a01 1069 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1070 test "$ret" -ne "0"
34ab15c5 1071 ok $? "Stop lttng tracing for session $sess_name failed as expected"
01513c3e
JRJ
1072 else
1073 ok $ret "Stop lttng tracing for session $sess_name"
1074 fi
d3e8f6bb
DG
1075}
1076
96340a01
JR
1077function stop_lttng_tracing_ok ()
1078{
1079 stop_lttng_tracing 0 "$@"
1080}
1081
1082function stop_lttng_tracing_fail ()
1083{
1084 stop_lttng_tracing 1 "$@"
1085}
1086
d3e8f6bb
DG
1087function destroy_lttng_session ()
1088{
67b4c664
JR
1089 local expected_to_fail=$1
1090 local sess_name=$2
d3e8f6bb 1091
2cf48300 1092 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1093 ret=$?
96340a01 1094 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1095 test "$ret" -ne "0"
34ab15c5 1096 ok $? "Destroy session $sess_name failed as expected"
01513c3e
JRJ
1097 else
1098 ok $ret "Destroy session $sess_name"
1099 fi
d3e8f6bb
DG
1100}
1101
67b4c664
JR
1102function destroy_lttng_session_ok ()
1103{
1104 destroy_lttng_session 0 "$@"
1105
1106}
1107
1108function destroy_lttng_session_fail ()
1109{
1110 destroy_lttng_session 1 "$@"
1111}
1112
1113
873c2aae
JRJ
1114function destroy_lttng_sessions ()
1115{
2cf48300 1116 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
873c2aae
JRJ
1117 ok $? "Destroy all lttng sessions"
1118}
1119
07b86b52
JD
1120function lttng_snapshot_add_output ()
1121{
b5633831
JR
1122 local expected_to_fail=$1
1123 local sess_name=$2
1124 local trace_path=$3
07b86b52 1125
2cf48300 1126 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name file://$trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1127 ret=$?
b5633831 1128 if [[ $expected_to_fail -eq 1 ]]; then
01513c3e 1129 test "$ret" -ne "0"
34ab15c5 1130 ok $? "Added snapshot output file://$trace_path failed as expected"
01513c3e
JRJ
1131 else
1132 ok $ret "Added snapshot output file://$trace_path"
1133 fi
07b86b52
JD
1134}
1135
b5633831
JR
1136function lttng_snapshot_add_output_ok ()
1137{
1138 lttng_snapshot_add_output 0 "$@"
1139}
1140
1141function lttng_snapshot_add_output_fail ()
1142{
1143 lttng_snapshot_add_output 1 "$@"
1144}
1145
26402e0c
DG
1146function lttng_snapshot_del_output ()
1147{
31580dc7
JR
1148 local expected_to_fail=$1
1149 local sess_name=$2
1150 local id=$3
26402e0c 1151
2cf48300 1152 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1153 ret=$?
31580dc7 1154 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1155 test "$ret" -ne "0"
34ab15c5 1156 ok $? "Deleted snapshot output id $id failed as expected"
01513c3e
JRJ
1157 else
1158 ok $ret "Deleted snapshot output id $id"
1159 fi
26402e0c
DG
1160}
1161
31580dc7
JR
1162function lttng_snapshot_del_output_ok ()
1163{
1164 lttng_snapshot_del_output 0 "$@"
1165}
1166
1167function lttng_snapshot_del_output_fail ()
1168{
1169 lttng_snapshot_del_output 1 "$@"
1170}
1171
07b86b52
JD
1172function lttng_snapshot_record ()
1173{
7d0ad314
JRJ
1174 local sess_name=$1
1175 local trace_path=$2
07b86b52 1176
2cf48300 1177 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
07b86b52
JD
1178 ok $? "Snapshot recorded"
1179}
1180
01513c3e
JRJ
1181function lttng_snapshot_list ()
1182{
1183 local sess_name=$1
2cf48300 1184 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e
JRJ
1185 ok $? "Snapshot list"
1186}
1187
e02b109b
DG
1188function lttng_save()
1189{
1190 local sess_name=$1
1191 local opts=$2
1192
2cf48300 1193 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
34ab15c5 1194 ok $? "Session saved"
e02b109b
DG
1195}
1196
1197function lttng_load()
1198{
192ac418
JR
1199 local expected_to_fail=$1
1200 local opts=$2
e02b109b 1201
2cf48300 1202 $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
192ac418
JR
1203 ret=$?
1204 if [[ $expected_to_fail -eq "1" ]]; then
1205 test $ret -ne "0"
1206 ok $? "Load command failed as expected with opts: $opts"
1207 else
1208 ok $ret "Load command with opts: $opts"
1209 fi
1210}
1211
1212function lttng_load_ok()
1213{
1214 lttng_load 0 "$@"
1215}
1216
1217function lttng_load_fail()
1218{
1219 lttng_load 1 "$@"
e02b109b
DG
1220}
1221
e83a8bdb
JR
1222function lttng_track()
1223{
1224 local expected_to_fail=$1
1225 local opts=$2
1226 $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST
1227 ret=$?
1228 if [[ $expected_to_fail -eq "1" ]]; then
1229 test $ret -ne "0"
1230 ok $? "Track command failed as expected with opts: $opts"
1231 else
34ab15c5 1232 ok $ret "Track command with opts: $opts"
e83a8bdb
JR
1233 fi
1234}
1235
1236function lttng_track_ok()
1237{
1238 lttng_track 0 "$@"
1239}
1240
1241function lttng_track_fail()
1242{
1243 lttng_track 1 "$@"
1244}
1245
1246function lttng_untrack()
1247{
1248 local expected_to_fail=$1
1249 local opts=$2
1250 $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST
1251 ret=$?
1252 if [[ $expected_to_fail -eq "1" ]]; then
1253 test $ret -ne "0"
1254 ok $? "Untrack command failed as expected with opts: $opts"
1255 else
34ab15c5 1256 ok $ret "Untrack command with opts: $opts"
e83a8bdb
JR
1257 fi
1258}
1259
1260function lttng_untrack_ok()
1261{
1262 lttng_untrack 0 "$@"
1263}
1264
1265function lttng_untrack_fail()
1266{
1267 lttng_untrack 1 "$@"
1268}
1269
8dcef147
JR
1270function add_context_lttng()
1271{
1272 local expected_to_fail="$1"
1273 local domain="$2"
1274 local session_name="$3"
1275 local channel_name="$4"
1276 local type="$5"
1277
1278 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context -s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1279 ret=$?
1280 if [[ $expected_to_fail -eq "1" ]]; then
1281 test $ret -ne "0"
1282 ok $? "Add context command failed as expected for type: $type"
1283 else
1284 ok $ret "Add context command for type: $type"
1285 fi
1286}
1287
1288function add_context_ust_ok()
1289{
1290 add_context_lttng 0 -u "$@"
1291}
1292
1293function add_context_ust_fail()
1294{
1295 add_context_lttng 1 -u "$@"
1296}
1297
1298function add_context_kernel_ok()
1299{
1300 add_context_lttng 0 -k "$@"
1301}
1302
1303function add_context_kernel_fail()
1304{
1305 add_context_lttng 1 -k "$@"
1306}
1307
d3e8f6bb
DG
1308function trace_matches ()
1309{
7d0ad314
JRJ
1310 local event_name=$1
1311 local nr_iter=$2
1312 local trace_path=$3
d3e8f6bb 1313
317eef93 1314 which $BABELTRACE_BIN >/dev/null
29655db7 1315 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
d3e8f6bb 1316
7d0ad314 1317 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
29655db7 1318
d3e8f6bb 1319 if [ "$count" -ne "$nr_iter" ]; then
29655db7 1320 fail "Trace match"
af91abc9 1321 diag "$count matching events found in trace"
d3e8f6bb 1322 else
29655db7 1323 pass "Trace match"
d3e8f6bb
DG
1324 fi
1325}
f4e40ab6 1326
d53addeb
DG
1327function trace_match_only()
1328{
1329 local event_name=$1
1330 local nr_iter=$2
1331 local trace_path=$3
1332
1333 which $BABELTRACE_BIN >/dev/null
1334 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1335
1336 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
1337 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1338
1339 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1340 pass "Trace match with $total event $event_name"
1341 else
1342 fail "Trace match"
1343 diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1344 fi
1345}
1346
f4e40ab6
DG
1347function validate_trace
1348{
7d0ad314
JRJ
1349 local event_name=$1
1350 local trace_path=$2
f4e40ab6
DG
1351
1352 which $BABELTRACE_BIN >/dev/null
29655db7
CB
1353 if [ $? -ne 0 ]; then
1354 skip 0 "Babeltrace binary not found. Skipping trace validation"
f4e40ab6
DG
1355 fi
1356
07b86b52
JD
1357 OLDIFS=$IFS
1358 IFS=","
1359 for i in $event_name; do
1360 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1361 if [ "$traced" -ne 0 ]; then
ebaaaf5e 1362 pass "Validate trace for event $i, $traced events"
07b86b52
JD
1363 else
1364 fail "Validate trace for event $i"
1365 diag "Found $traced occurences of $i"
1366 fi
1367 done
1368 ret=$?
1369 IFS=$OLDIFS
1370 return $ret
f4e40ab6 1371}
8cfcd41c 1372
54cd6107
JD
1373function validate_trace_count
1374{
1375 local event_name=$1
1376 local trace_path=$2
1377 local expected_count=$3
1378
1379 which $BABELTRACE_BIN >/dev/null
1380 if [ $? -ne 0 ]; then
1381 skip 0 "Babeltrace binary not found. Skipping trace validation"
1382 fi
1383
1384 cnt=0
1385 OLDIFS=$IFS
1386 IFS=","
1387 for i in $event_name; do
1388 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1389 if [ "$traced" -ne 0 ]; then
1390 pass "Validate trace for event $i, $traced events"
1391 else
1392 fail "Validate trace for event $i"
1393 diag "Found $traced occurences of $i"
1394 fi
1395 cnt=$(($cnt + $traced))
1396 done
1397 IFS=$OLDIFS
1398 test $cnt -eq $expected_count
1399 ok $? "Read a total of $cnt events, expected $expected_count"
1400}
1401
086e6add
MD
1402function trace_first_line
1403{
1404 local trace_path=$1
1405
1406 which $BABELTRACE_BIN >/dev/null
1407 if [ $? -ne 0 ]; then
1408 skip 0 "Babeltrace binary not found. Skipping trace validation"
1409 fi
1410
1411 $BABELTRACE_BIN $trace_path 2>/dev/null | head -n 1
1412}
1413
8cfcd41c
MD
1414function validate_trace_exp()
1415{
1416 local event_exp=$1
1417 local trace_path=$2
1418
1419 which $BABELTRACE_BIN >/dev/null
1420 skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
1421
1422 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep ${event_exp} | wc -l)
1423 if [ "$traced" -ne 0 ]; then
1424 pass "Validate trace for expression '${event_exp}', $traced events"
1425 else
1426 fail "Validate trace for expression '${event_exp}'"
1427 diag "Found $traced occurences of '${event_exp}'"
1428 fi
1429 ret=$?
1430 return $ret
1431}
1432
1433function validate_trace_only_exp()
1434{
1435 local event_exp=$1
1436 local trace_path=$2
1437
1438 which $BABELTRACE_BIN >/dev/null
1439 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1440
1441 local count=$($BABELTRACE_BIN $trace_path | grep ${event_exp} | wc -l)
1442 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1443
1444 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1445 pass "Trace match with $total for expression '${event_exp}"
1446 else
1447 fail "Trace match"
1448 diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1449 fi
1450 ret=$?
1451 return $ret
1452}
1453
1454function validate_trace_empty()
1455{
1456 local trace_path=$1
1457
1458 which $BABELTRACE_BIN >/dev/null
1459 if [ $? -ne 0 ]; then
1460 skip 0 "Babeltrace binary not found. Skipping trace validation"
1461 fi
1462
1463 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | wc -l)
1464 if [ "$traced" -eq 0 ]; then
1465 pass "Validate empty trace"
1466 else
1467 fail "Validate empty trace"
1468 diag "Found $traced events in trace"
1469 fi
1470 ret=$?
1471 return $ret
1472}
801236b0 1473
eded6438 1474function regenerate_metadata ()
801236b0
JD
1475{
1476 local expected_to_fail=$1
1477 local sess_name=$2
1478
eded6438 1479 $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate metadata -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
801236b0
JD
1480 ret=$?
1481 if [[ $expected_to_fail -eq "1" ]]; then
1482 test "$ret" -ne "0"
eded6438 1483 ok $? "Expected fail on regenerate metadata $sess_name"
801236b0
JD
1484 else
1485 ok $ret "Metadata regenerate $sess_name"
1486 fi
1487}
1488
eded6438 1489function regenerate_metadata_ok ()
801236b0 1490{
eded6438 1491 regenerate_metadata 0 "$@"
801236b0
JD
1492}
1493
eded6438 1494function regenerate_metadata_fail ()
801236b0 1495{
eded6438 1496 regenerate_metadata 1 "$@"
801236b0 1497}
512eb148 1498
54cd6107
JD
1499function regenerate_statedump ()
1500{
1501 local expected_to_fail=$1
1502 local sess_name=$2
1503
1504 $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate statedump -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1505 ret=$?
1506 if [[ $expected_to_fail -eq "1" ]]; then
1507 test "$ret" -ne "0"
1508 ok $? "Expected fail on regenerate statedump $sess_name"
1509 else
1510 ok $ret "Metadata regenerate $sess_name"
1511 fi
1512}
1513
1514function regenerate_statedump_ok ()
1515{
1516 regenerate_statedump 0 "$@"
1517}
1518
1519function regenerate_statedump_fail ()
1520{
1521 regenerate_statedump 1 "$@"
1522}
1523
512eb148
JD
1524function destructive_tests_enabled ()
1525{
1526 if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then
1527 return 0
1528 else
1529 return 1
1530 fi
1531}
This page took 0.201082 seconds and 5 git commands to generate.