Fix: include stdlib.h in compat/string.h
[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.*"
19356f3a 18RUNAS_BIN="lttng-runas"
725f658e 19RUNAS_MATCH=".*lttng-runas.*"
f7613992 20CONSUMERD_BIN="lttng-consumerd"
725f658e 21CONSUMERD_MATCH=".*lttng-consumerd.*"
f4e40ab6 22RELAYD_BIN="lttng-relayd"
725f658e 23RELAYD_MATCH=".*lttng-relayd.*"
d3e8f6bb
DG
24LTTNG_BIN="lttng"
25BABELTRACE_BIN="babeltrace"
2cf48300
JR
26OUTPUT_DEST=/dev/null
27ERROR_OUTPUT_DEST=/dev/null
d3e8f6bb 28
fd4dfcec
DG
29# Minimal kernel version supported for session daemon tests
30KERNEL_MAJOR_VERSION=2
31KERNEL_MINOR_VERSION=6
32KERNEL_PATCHLEVEL_VERSION=27
33
651b8bb3
JG
34# We set the default UST register timeout and network and app socket timeout to
35# "wait forever", so that basic tests don't have to worry about hitting
36# timeouts on busy systems. Specialized tests should test those corner-cases.
629b9335 37export LTTNG_UST_REGISTER_TIMEOUT=-1
651b8bb3
JG
38export LTTNG_NETWORK_SOCKET_TIMEOUT=-1
39export LTTNG_APP_SOCKET_TIMEOUT=-1
629b9335 40
fd7fe1a8
JR
41# We set the default lttng-sessiond path to /bin/true to prevent the spawning
42# of a daemonized sessiond. This is necessary since 'lttng create' will spawn
43# its own sessiond if none is running. It also ensures that 'lttng create'
44# fails when no sessiond is running.
45export LTTNG_SESSIOND_PATH="/bin/true"
46
29655db7
CB
47source $TESTDIR/utils/tap/tap.sh
48
529bb942
MD
49if [ -z $LTTNG_TEST_TEARDOWN_TIMEOUT ]; then
50 LTTNG_TEST_TEARDOWN_TIMEOUT=60
51fi
52
1c362dc7
JR
53function full_cleanup ()
54{
529bb942
MD
55 # Try to kill daemons gracefully
56 stop_lttng_relayd_notap SIGTERM $LTTNG_TEST_TEARDOWN_TIMEOUT
57 stop_lttng_sessiond_notap SIGTERM $LTTNG_TEST_TEARDOWN_TIMEOUT
58
59 # If daemons are still present, forcibly kill them
60 stop_lttng_relayd_notap SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT
61 stop_lttng_sessiond_notap SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT
62 stop_lttng_consumerd_notap SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT
1c362dc7
JR
63
64 # Disable trap for SIGTERM since the following kill to the
65 # pidgroup will be SIGTERM. Otherwise it loops.
66 # The '-' before the pid number ($$) indicates 'kill' to signal the
67 # whole process group.
68 trap - SIGTERM && kill -- -$$
4e8ea4fa 69 exit 1
1c362dc7
JR
70}
71
27b667f7
MD
72function null_pipes ()
73{
74 exec 0>/dev/null
75 exec 1>/dev/null
76 exec 2>/dev/null
77}
1c362dc7
JR
78
79trap full_cleanup SIGINT SIGTERM
80
27b667f7
MD
81# perl prove closes its child pipes before giving it a chance to run its
82# signal trap handlers. Redirect pipes to /dev/null if SIGPIPE is caught
83# to allow those trap handlers to proceed.
84
85trap null_pipes SIGPIPE
86
fec81a7e
CB
87function print_ok ()
88{
89 # Check if we are a terminal
90 if [ -t 1 ]; then
91 echo -e "\e[1;32mOK\e[0m"
92 else
93 echo -e "OK"
94 fi
95}
96
97function print_fail ()
98{
99 # Check if we are a terminal
100 if [ -t 1 ]; then
101 echo -e "\e[1;31mFAIL\e[0m"
102 else
103 echo -e "FAIL"
104 fi
105}
106
107function print_test_banner ()
108{
7d0ad314 109 local desc="$1"
29655db7 110 diag "$desc"
fec81a7e
CB
111}
112
fd4dfcec
DG
113function validate_kernel_version ()
114{
7d0ad314 115 local kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n'))
fd4dfcec
DG
116 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
117 return 0
118 fi
119 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
120 return 0
121 fi
122 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
123 return 0
124 fi
125 return 1
126}
127
9ac429ef 128# Generate a random string
f4e40ab6
DG
129# $1 = number of characters; defaults to 16
130# $2 = include special characters; 1 = yes, 0 = no; defaults to yes
9ac429ef 131function randstring()
f4e40ab6
DG
132{
133 [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
b89c3a68 134 cat /dev/urandom 2>/dev/null | tr -cd "$CHAR" 2>/dev/null | head -c ${1:-16} 2>/dev/null
f4e40ab6
DG
135 echo
136}
137
9e136324
JG
138# Return the number of _configured_ CPUs.
139function conf_proc_count()
140{
141 getconf _NPROCESSORS_CONF
142 if [ $? -ne 0 ]; then
143 diag "Failed to get the number of configured CPUs"
144 fi
145 echo
146}
147
9c8a3964
JR
148# Check if base lttng-modules are present.
149# Bail out on failure
150function validate_lttng_modules_present ()
151{
152 modprobe -n lttng-tracer 2>/dev/null
153 if [ $? -ne 0 ]; then
154 BAIL_OUT "LTTng modules not detected."
155 fi
156}
157
4a180d9f 158function enable_kernel_lttng_event
f4e40ab6 159{
854382b8
JR
160 local withtap="$1"
161 local expected_to_fail="$2"
162 local sess_name="$3"
163 local event_name="$4"
164 local channel_name="$5"
f4e40ab6 165
4a180d9f 166 if [ -z "$event_name" ]; then
f4e40ab6 167 # Enable all event if no event name specified
29655db7 168 event_name="-a"
f4e40ab6
DG
169 fi
170
4a180d9f 171 if [ -z "$channel_name" ]; then
07b86b52
JD
172 # default channel if none specified
173 chan=""
174 else
175 chan="-c $channel_name"
176 fi
177
2cf48300 178 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
4a180d9f
MD
179 ret=$?
180 if [[ $expected_to_fail -eq "1" ]]; then
181 test $ret -ne "0"
854382b8
JR
182 ret=$?
183 if [ $withtap -eq "1" ]; then
184 ok $ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
185 fi
4a180d9f 186 else
854382b8
JR
187 if [ $withtap -eq "1" ]; then
188 ok $ret "Enable kernel event $event_name for session $sess_name"
189 fi
4a180d9f
MD
190 fi
191}
192
193function enable_kernel_lttng_event_ok ()
194{
854382b8 195 enable_kernel_lttng_event 1 0 "$@"
4a180d9f
MD
196}
197
198function enable_kernel_lttng_event_fail ()
199{
854382b8
JR
200 enable_kernel_lttng_event 1 1 "$@"
201}
202
203function enable_kernel_lttng_event_notap ()
204{
205 enable_kernel_lttng_event 0 0 "$@"
4a180d9f
MD
206}
207
208# Old interface
209function lttng_enable_kernel_event
210{
211 enable_kernel_lttng_event_ok "$@"
f4e40ab6
DG
212}
213
8cfcd41c
MD
214function lttng_enable_kernel_syscall()
215{
216 local expected_to_fail=$1
217 local sess_name=$2
218 local syscall_name=$3
219 local channel_name=$4
220
221 if [ -z $syscall_name ]; then
222 # Enable all event if no syscall name specified
223 syscall_name="-a"
224 fi
225
226 if [ -z $channel_name ]; then
227 # default channel if none specified
228 chan=""
229 else
230 chan="-c $channel_name"
231 fi
232
2cf48300 233 $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
234 ret=$?
235 if [[ $expected_to_fail -eq "1" ]]; then
236 test $ret -ne "0"
237 ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
238 else
239 ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
240 fi
241}
242
243function lttng_enable_kernel_syscall_ok()
244{
421b83dc 245 lttng_enable_kernel_syscall 0 "$@"
8cfcd41c
MD
246}
247
248function lttng_enable_kernel_syscall_fail()
249{
421b83dc 250 lttng_enable_kernel_syscall 1 "$@"
8cfcd41c
MD
251}
252
253function lttng_disable_kernel_syscall()
254{
255 local expected_to_fail=$1
256 local sess_name=$2
257 local syscall_name=$3
258 local channel_name=$4
259
260 if [ -z $syscall_name ]; then
261 # Enable all event if no syscall name specified
262 syscall_name="-a"
263 fi
264
265 if [ -z $channel_name ]; then
266 # default channel if none specified
267 chan=""
268 else
269 chan="-c $channel_name"
270 fi
271
2cf48300 272 $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
273
274 ret=$?
275 if [[ $expected_to_fail -eq "1" ]]; then
276 test $ret -ne "0"
34ab15c5 277 ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
8cfcd41c
MD
278 else
279 ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
280 fi
281}
282
283function lttng_disable_kernel_syscall_ok()
284{
421b83dc 285 lttng_disable_kernel_syscall 0 "$@"
8cfcd41c
MD
286}
287
288function lttng_disable_kernel_syscall_fail()
289{
421b83dc 290 lttng_disable_kernel_syscall 1 "$@"
8cfcd41c
MD
291}
292
a9c2df2b
FD
293function lttng_enable_kernel_userspace_probe_event ()
294{
295 local expected_to_fail="$1"
296 local sess_name="$2"
297 local target="$3"
298 local event_name="$4"
299
300 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event --kernel --userspace-probe="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
301 ret=$?
302 if [[ $expected_to_fail -eq "1" ]]; then
303 test $ret -ne "0"
304 ok $? "Enable kernel userspace probe event for session $sess_name failed as expected"
305 else
306 ok $ret "Enable kernel userspace probe event for session $sess_name"
307 fi
308}
309
310function lttng_enable_kernel_userspace_probe_event_fail ()
311{
312 lttng_enable_kernel_userspace_probe_event 1 "$@"
313}
314
315function lttng_enable_kernel_userspace_probe_event_ok ()
316{
317 lttng_enable_kernel_userspace_probe_event 0 "$@"
318}
319
320function disable_kernel_lttng_userspace_probe_event_ok ()
321{
322 local sess_name="$1"
323 local event_name="$2"
324
325 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" disable-event --kernel "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
326 ok $? "Disable kernel event $target for session $sess_name"
327}
d96f6315
MD
328function lttng_enable_kernel_channel()
329{
854382b8
JR
330 local withtap=$1
331 local expected_to_fail=$2
332 local sess_name=$3
333 local channel_name=$4
c28fcefd 334 local opts="${@:5}"
d96f6315 335
c28fcefd 336 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
d96f6315
MD
337 ret=$?
338 if [[ $expected_to_fail -eq "1" ]]; then
339 test "$ret" -ne "0"
854382b8
JR
340 ret=$?
341 if [ $withtap -eq "1" ]; then
342 ok $ret "Enable channel $channel_name for session $sess_name failed as expected"
343 fi
d96f6315 344 else
854382b8
JR
345 if [ $withtap -eq "1" ]; then
346 ok $ret "Enable channel $channel_name for session $sess_name"
347 fi
d96f6315
MD
348 fi
349}
350
351function lttng_enable_kernel_channel_ok()
352{
854382b8 353 lttng_enable_kernel_channel 1 0 "$@"
d96f6315
MD
354}
355
356function lttng_enable_kernel_channel_fail()
357{
854382b8
JR
358 lttng_enable_kernel_channel 1 1 "$@"
359}
360
361function lttng_enable_kernel_channel_notap()
362{
363 lttng_enable_kernel_channel 0 0 "$@"
364}
365
366function enable_kernel_lttng_channel_ok()
367{
368 lttng_enable_kernel_channel 1 0 "$@"
d96f6315
MD
369}
370
371function lttng_disable_kernel_channel()
372{
373 local expected_to_fail=$1
374 local sess_name=$2
375 local channel_name=$3
376
2cf48300 377 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
d96f6315
MD
378 ret=$?
379 if [[ $expected_to_fail -eq "1" ]]; then
380 test "$ret" -ne "0"
34ab15c5 381 ok $? "Disable channel $channel_name for session $sess_name failed as expected"
d96f6315 382 else
34ab15c5 383 ok $ret "Disable channel $channel_name for session $sess_name"
d96f6315
MD
384 fi
385}
386
387function lttng_disable_kernel_channel_ok()
388{
421b83dc 389 lttng_disable_kernel_channel 0 "$@"
d96f6315
MD
390}
391
392function lttng_disable_kernel_channel_fail()
393{
421b83dc 394 lttng_disable_kernel_channel 1 "$@"
d96f6315
MD
395}
396
05aa48da 397function start_lttng_relayd_opt()
f4e40ab6 398{
05aa48da 399 local withtap=$1
f3630ec4
JR
400 local process_mode=$2
401 local opt=$3
173af62f 402
529bb942 403 DIR=$(readlink -f "$TESTDIR")
f4e40ab6 404
f3630ec4 405 if [ -z $(pgrep $RELAYD_MATCH) ]; then
529bb942 406 # shellcheck disable=SC2086
f3630ec4
JR
407 $DIR/../src/bin/lttng-relayd/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
408 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
f4e40ab6 409 if [ $? -eq 1 ]; then
f3630ec4
JR
410 if [ $withtap -eq "1" ]; then
411 fail "Start lttng-relayd (process mode: $process_mode opt: $opt)"
05aa48da 412 fi
f4e40ab6
DG
413 return 1
414 else
f3630ec4
JR
415 if [ $withtap -eq "1" ]; then
416 pass "Start lttng-relayd (process mode: $process_mode opt: $opt)"
05aa48da 417 fi
f4e40ab6
DG
418 fi
419 else
29655db7 420 pass "Start lttng-relayd (opt: $opt)"
f4e40ab6
DG
421 fi
422}
423
05aa48da 424function start_lttng_relayd()
f4e40ab6 425{
f3630ec4 426 start_lttng_relayd_opt 1 "-b" "$@"
05aa48da
MD
427}
428
429function start_lttng_relayd_notap()
430{
f3630ec4 431 start_lttng_relayd_opt 0 "-b" "$@"
05aa48da
MD
432}
433
434function stop_lttng_relayd_opt()
435{
436 local withtap=$1
529bb942 437 local signal=$2
05aa48da 438
529bb942
MD
439 if [ -z "$signal" ]; then
440 signal="SIGTERM"
05aa48da 441 fi
29655db7 442
529bb942
MD
443 local timeout_s=$3
444 local dtimeleft_s=
445
446 # Multiply time by 2 to simplify integer arithmetic
447 if [ -n "$timeout_s" ]; then
448 dtimeleft_s=$((timeout_s * 2))
449 fi
450
451 local retval=0
452 local pids=
453
454 pids=$(pgrep "$RELAYD_MATCH")
455 if [ -z "$pids" ]; then
456 if [ "$withtap" -eq "1" ]; then
457 pass "No relay daemon to kill"
458 fi
459 return 0
460 fi
461
462 diag "Killing (signal $signal) lttng-relayd (pid: $pids)"
463
464 # shellcheck disable=SC2086
465 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
466 retval=1
467 if [ "$withtap" -eq "1" ]; then
05aa48da
MD
468 fail "Kill relay daemon"
469 fi
05aa48da 470 else
f4e40ab6
DG
471 out=1
472 while [ -n "$out" ]; do
529bb942
MD
473 out=$(pgrep "$RELAYD_MATCH")
474 if [ -n "$dtimeleft_s" ]; then
475 if [ $dtimeleft_s -lt 0 ]; then
476 out=
477 retval=1
478 fi
479 dtimeleft_s=$((dtimeleft_s - 1))
480 fi
f4e40ab6
DG
481 sleep 0.5
482 done
529bb942
MD
483 if [ "$withtap" -eq "1" ]; then
484 if [ "$retval" -eq "0" ]; then
485 pass "Wait after kill relay daemon"
486 else
487 fail "Wait after kill relay daemon"
488 fi
05aa48da 489 fi
1fb23888
MD
490 fi
491 return $retval
492}
493
05aa48da 494function stop_lttng_relayd()
1fb23888 495{
05aa48da
MD
496 stop_lttng_relayd_opt 1 "$@"
497}
1fb23888 498
05aa48da
MD
499function stop_lttng_relayd_notap()
500{
501 stop_lttng_relayd_opt 0 "$@"
f4e40ab6
DG
502}
503
05aa48da
MD
504#First arg: show tap output
505#Second argument: load path for automatic loading
506function start_lttng_sessiond_opt()
355f483d 507{
05aa48da
MD
508 local withtap=$1
509 local load_path=$2
8d51ddbc 510
4b01971f 511 local env_vars=""
b916da6b 512 local consumerd=""
b916da6b 513
529bb942
MD
514 local long_bit_value=
515 long_bit_value=$(getconf LONG_BIT)
516
517 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
355f483d
DG
518 # Env variable requested no session daemon
519 return
520 fi
521
529bb942 522 DIR=$(readlink -f "$TESTDIR")
b916da6b
JR
523
524 # Get long_bit value for 32/64 consumerd
525 case "$long_bit_value" in
526 32)
527 consumerd="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
528 ;;
529 64)
530 consumerd="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
531 ;;
532 *)
533 return
534 ;;
535 esac
536
4b01971f
JR
537 # Check for env. variable. Allow the use of LD_PRELOAD etc.
538 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
529bb942 539 env_vars="${LTTNG_SESSIOND_ENV_VARS} "
4b01971f 540 fi
529bb942 541 env_vars="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN"
4b01971f 542
529bb942 543 if ! validate_kernel_version; then
29655db7
CB
544 fail "Start session daemon"
545 BAIL_OUT "*** Kernel too old for session daemon tests ***"
355f483d
DG
546 fi
547
529bb942 548 : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}"
d3d97763 549 export LTTNG_SESSION_CONFIG_XSD_PATH
29655db7 550
529bb942 551 if [ -z "$(pgrep "${SESSIOND_MATCH}")" ]; then
8d51ddbc 552 # Have a load path ?
05aa48da 553 if [ -n "$load_path" ]; then
529bb942
MD
554 # shellcheck disable=SC2086
555 env $env_vars --load "$load_path" --background "$consumerd"
8d51ddbc 556 else
529bb942
MD
557 # shellcheck disable=SC2086
558 env $env_vars --background "$consumerd"
8d51ddbc 559 fi
0fc2834c 560 #$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 561 status=$?
529bb942 562 if [ "$withtap" -eq "1" ]; then
05aa48da
MD
563 ok $status "Start session daemon"
564 fi
29655db7 565 fi
355f483d
DG
566}
567
05aa48da
MD
568function start_lttng_sessiond()
569{
570 start_lttng_sessiond_opt 1 "$@"
571}
572
573function start_lttng_sessiond_notap()
d3e8f6bb 574{
05aa48da
MD
575 start_lttng_sessiond_opt 0 "$@"
576}
577
578function stop_lttng_sessiond_opt()
579{
580 local withtap=$1
4c80129b 581 local signal=$2
05aa48da 582
529bb942
MD
583 if [ -z "$signal" ]; then
584 signal=SIGTERM
585 fi
586
587 local timeout_s=$3
588 local dtimeleft_s=
589
590 # Multiply time by 2 to simplify integer arithmetic
591 if [ -n "$timeout_s" ]; then
592 dtimeleft_s=$((timeout_s * 2))
593 fi
594
595 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
355f483d 596 # Env variable requested no session daemon
529bb942 597 return 0
355f483d
DG
598 fi
599
529bb942 600 local retval=0
d3e8f6bb 601
529bb942
MD
602 local runas_pids=
603 runas_pids=$(pgrep "$RUNAS_MATCH")
604
605 local pids=
606 pids=$(pgrep "$SESSIOND_MATCH")
607
608 if [ -n "$runas_pids" ]; then
609 pids="$pids $runas_pids"
4c80129b 610 fi
529bb942
MD
611
612 if [ -z "$pids" ]; then
613 if [ "$withtap" -eq "1" ]; then
614 pass "No session daemon to kill"
615 fi
616 return 0
8490897a 617 fi
29655db7 618
529bb942
MD
619 diag "Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
620
621 # shellcheck disable=SC2086
622 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
623 retval=1
624 if [ "$withtap" -eq "1" ]; then
05aa48da
MD
625 fail "Kill sessions daemon"
626 fi
d3e8f6bb 627 else
5fa32580
DG
628 out=1
629 while [ -n "$out" ]; do
529bb942
MD
630 out=$(pgrep "${SESSIOND_MATCH}")
631 if [ -n "$dtimeleft_s" ]; then
632 if [ $dtimeleft_s -lt 0 ]; then
633 out=
634 retval=1
635 fi
636 dtimeleft_s=$((dtimeleft_s - 1))
637 fi
5fa32580
DG
638 sleep 0.5
639 done
f7613992
MD
640 out=1
641 while [ -n "$out" ]; do
529bb942
MD
642 out=$(pgrep "$CONSUMERD_MATCH")
643 if [ -n "$dtimeleft_s" ]; then
644 if [ $dtimeleft_s -lt 0 ]; then
645 out=
646 retval=1
647 fi
648 dtimeleft_s=$((dtimeleft_s - 1))
649 fi
f7613992
MD
650 sleep 0.5
651 done
1c362dc7 652
529bb942
MD
653 if [ "$withtap" -eq "1" ]; then
654 if [ "$retval" -eq "0" ]; then
655 pass "Wait after kill session daemon"
656 else
657 fail "Wait after kill session daemon"
658 fi
05aa48da 659 fi
d3e8f6bb 660 fi
529bb942
MD
661 if [ "$signal" = "SIGKILL" ]; then
662 if [ "$(id -u)" -eq "0" ]; then
663 local modules=
664 modules="$(lsmod | grep ^lttng | awk '{print $1}')"
665
666 if [ -n "$modules" ]; then
667 diag "Unloading all LTTng modules"
668 modprobe -r "$modules"
669 fi
670 fi
671 fi
672
673 return $retval
d3e8f6bb
DG
674}
675
05aa48da
MD
676function stop_lttng_sessiond()
677{
678 stop_lttng_sessiond_opt 1 "$@"
679}
680
681function stop_lttng_sessiond_notap()
682{
683 stop_lttng_sessiond_opt 0 "$@"
684}
685
8490897a
MD
686function sigstop_lttng_sessiond_opt()
687{
688 local withtap=$1
689 local signal=SIGSTOP
8490897a 690
529bb942 691 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
8490897a
MD
692 # Env variable requested no session daemon
693 return
694 fi
695
529bb942 696 PID_SESSIOND="$(pgrep "${SESSIOND_MATCH}") $(pgrep "$RUNAS_MATCH")"
8490897a 697
529bb942
MD
698 if [ "$withtap" -eq "1" ]; then
699 diag "Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$PID_SESSIOND" | tr '\n' ' ')"
8490897a 700 fi
8490897a 701
529bb942
MD
702 # shellcheck disable=SC2086
703 if ! kill -s $signal $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
704 if [ "$withtap" -eq "1" ]; then
8490897a
MD
705 fail "Sending SIGSTOP to session daemon"
706 fi
707 else
708 out=1
709 while [ $out -ne 0 ]; do
529bb942 710 pid="$(pgrep "$SESSIOND_MATCH")"
8490897a
MD
711
712 # Wait until state becomes stopped for session
713 # daemon(s).
714 out=0
715 for sessiond_pid in $pid; do
529bb942 716 state="$(ps -p "$sessiond_pid" -o state= )"
8490897a
MD
717 if [[ -n "$state" && "$state" != "T" ]]; then
718 out=1
719 fi
720 done
721 sleep 0.5
722 done
529bb942 723 if [ "$withtap" -eq "1" ]; then
8490897a
MD
724 pass "Sending SIGSTOP to session daemon"
725 fi
726 fi
727}
728
729function sigstop_lttng_sessiond()
730{
731 sigstop_lttng_sessiond_opt 1 "$@"
732}
733
734function sigstop_lttng_sessiond_notap()
735{
736 sigstop_lttng_sessiond_opt 0 "$@"
737}
738
4c80129b
JR
739function stop_lttng_consumerd_opt()
740{
741 local withtap=$1
742 local signal=$2
4c80129b 743
529bb942
MD
744 if [ -z "$signal" ]; then
745 signal=SIGTERM
746 fi
747
748 local timeout_s=$3
749 local dtimeleft_s=
4c80129b 750
529bb942
MD
751 # Multiply time by 2 to simplify integer arithmetic
752 if [ -n "$timeout_s" ]; then
753 dtimeleft_s=$((timeout_s * 2))
4c80129b
JR
754 fi
755
529bb942
MD
756 local retval=0
757
758 PID_CONSUMERD="$(pgrep "$CONSUMERD_MATCH")"
759
760 if [ -z "$PID_CONSUMERD" ]; then
761 if [ "$withtap" -eq "1" ]; then
762 pass "No consumer daemon to kill"
763 fi
764 return 0
4c80129b 765 fi
3355fd4d 766
529bb942 767 diag "Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')"
4c80129b 768
529bb942
MD
769 # shellcheck disable=SC2086
770 if ! kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
771 retval=1
772 if [ "$withtap" -eq "1" ]; then
4c80129b
JR
773 fail "Kill consumer daemon"
774 fi
4c80129b
JR
775 else
776 out=1
777 while [ $out -ne 0 ]; do
529bb942 778 pid="$(pgrep "$CONSUMERD_MATCH")"
4c80129b
JR
779
780 # If consumerds are still present check their status.
781 # A zombie status qualifies the consumerd as *killed*
782 out=0
783 for consumer_pid in $pid; do
529bb942 784 state="$(ps -p "$consumer_pid" -o state= )"
4c80129b
JR
785 if [[ -n "$state" && "$state" != "Z" ]]; then
786 out=1
787 fi
788 done
529bb942
MD
789 if [ -n "$dtimeleft_s" ]; then
790 if [ $dtimeleft_s -lt 0 ]; then
791 out=0
792 retval=1
793 fi
794 dtimeleft_s=$((dtimeleft_s - 1))
795 fi
4c80129b
JR
796 sleep 0.5
797 done
529bb942
MD
798 if [ "$withtap" -eq "1" ]; then
799 if [ "$retval" -eq "0" ]; then
800 pass "Wait after kill consumer daemon"
801 else
802 fail "Wait after kill consumer daemon"
803 fi
4c80129b
JR
804 fi
805 fi
529bb942 806
4c80129b
JR
807 return $retval
808}
809
810function stop_lttng_consumerd()
811{
812 stop_lttng_consumerd_opt 1 "$@"
813}
814
815function stop_lttng_consumerd_notap()
816{
817 stop_lttng_consumerd_opt 0 "$@"
818}
819
8490897a
MD
820function sigstop_lttng_consumerd_opt()
821{
822 local withtap=$1
823 local signal=SIGSTOP
8490897a 824
529bb942 825 PID_CONSUMERD="$(pgrep "$CONSUMERD_MATCH")"
8490897a 826
529bb942 827 diag "Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')"
8490897a 828
529bb942
MD
829 # shellcheck disable=SC2086
830 kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
8490897a 831 retval=$?
8490897a 832
529bb942
MD
833 if [ $retval -eq 1 ]; then
834 if [ "$withtap" -eq "1" ]; then
8490897a
MD
835 fail "Sending SIGSTOP to consumer daemon"
836 fi
837 return 1
838 else
839 out=1
840 while [ $out -ne 0 ]; do
529bb942 841 pid="$(pgrep "$CONSUMERD_MATCH")"
8490897a
MD
842
843 # Wait until state becomes stopped for all
844 # consumers.
845 out=0
846 for consumer_pid in $pid; do
529bb942 847 state="$(ps -p "$consumer_pid" -o state= )"
8490897a
MD
848 if [[ -n "$state" && "$state" != "T" ]]; then
849 out=1
850 fi
851 done
852 sleep 0.5
853 done
529bb942 854 if [ "$withtap" -eq "1" ]; then
8490897a
MD
855 pass "Sending SIGSTOP to consumer daemon"
856 fi
857 fi
858 return $retval
859}
860
861function sigstop_lttng_consumerd()
862{
863 sigstop_lttng_consumerd_opt 1 "$@"
864}
865
866function sigstop_lttng_consumerd_notap()
867{
868 sigstop_lttng_consumerd_opt 0 "$@"
869}
870
873c2aae
JRJ
871function list_lttng_with_opts ()
872{
7d0ad314 873 local opts=$1
2cf48300 874 $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
873c2aae
JRJ
875 ok $? "Lttng-tool list command with option $opts"
876}
877
07b86b52
JD
878function create_lttng_session_no_output ()
879{
7d0ad314 880 local sess_name=$1
2a166864 881 local opts="${@:2}"
07b86b52 882
2a166864 883 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
07b86b52
JD
884 ok $? "Create session $sess_name in no-output mode"
885}
886
f0d43d3d
JR
887function create_lttng_session_uri () {
888 local sess_name=$1
889 local uri=$2
890 local opts="${@:3}"
891
892 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -U $uri $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
893 ok $? "Create session $sess_name with uri:$uri and opts: $opts"
894}
895
d3e8f6bb
DG
896function create_lttng_session ()
897{
434f8068
JR
898 local withtap=$1
899 local expected_to_fail=$2
900 local sess_name=$3
901 local trace_path=$4
902 local opt=$5
d3e8f6bb 903
01654d69
JR
904 if [ -z "$trace_path" ]; then
905 # Use lttng-sessiond default output.
906 trace_path=""
907 else
908 trace_path="-o $trace_path"
909 fi
910
911 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create "$sess_name" $trace_path $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
873c2aae 912 ret=$?
434f8068 913 if [ $expected_to_fail -eq "1" ]; then
01513c3e 914 test "$ret" -ne "0"
434f8068
JR
915 ret=$?
916 if [ $withtap -eq "1" ]; then
917 ok $ret "Create session $sess_name in $trace_path failed as expected"
918 fi
873c2aae 919 else
434f8068
JR
920 if [ $withtap -eq "1" ]; then
921 ok $ret "Create session $sess_name in $trace_path"
922 fi
873c2aae 923 fi
434f8068 924 return $ret
d4018451
DG
925}
926
bf6ae429
JR
927function create_lttng_session_ok ()
928{
434f8068 929 create_lttng_session 1 0 "$@"
bf6ae429
JR
930}
931
932function create_lttng_session_fail ()
933{
434f8068
JR
934 create_lttng_session 1 1 "$@"
935}
936
937function create_lttng_session_notap ()
938{
939 create_lttng_session 0 0 "$@"
bf6ae429
JR
940}
941
942
827caf52 943function enable_ust_lttng_channel ()
d4018451 944{
434f8068
JR
945 local withtap=$1
946 local expected_to_fail=$2
947 local sess_name=$3
948 local channel_name=$4
c28fcefd 949 local opts="${@:5}"
d4018451 950
c28fcefd 951 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
312dabc3 952 ret=$?
34ab15c5 953 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 954 test "$ret" -ne "0"
434f8068
JR
955 ret=$?
956 if [ $withtap -eq "1" ]; then
957 ok $ret "Enable channel $channel_name for session $sess_name failed as expected"
958 fi
312dabc3 959 else
434f8068
JR
960 if [ $withtap -eq "1" ]; then
961 ok $ret "Enable channel $channel_name for session $sess_name"
962 fi
312dabc3 963 fi
434f8068 964 return $ret
d4018451
DG
965}
966
827caf52
JR
967function enable_ust_lttng_channel_ok ()
968{
434f8068 969 enable_ust_lttng_channel 1 0 "$@"
827caf52
JR
970}
971
972function enable_ust_lttng_channel_fail ()
973{
434f8068
JR
974 enable_ust_lttng_channel 1 1 "$@"
975}
976
977function enable_ust_lttng_channel_notap ()
978{
979 enable_ust_lttng_channel 0 0 "$@"
827caf52
JR
980}
981
29655db7 982function disable_ust_lttng_channel()
d4018451 983{
7d0ad314
JRJ
984 local sess_name=$1
985 local channel_name=$2
d4018451 986
2cf48300 987 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 988 ok $? "Disable channel $channel_name for session $sess_name"
d3e8f6bb
DG
989}
990
07b86b52
JD
991function enable_lttng_mmap_overwrite_kernel_channel()
992{
7d0ad314
JRJ
993 local sess_name=$1
994 local channel_name=$2
07b86b52 995
2cf48300 996 $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
997 ok $? "Enable channel $channel_name for session $sess_name"
998}
999
086e6add
MD
1000function enable_lttng_mmap_discard_small_kernel_channel()
1001{
1002 local sess_name=$1
1003 local channel_name=$2
1004
1005 $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
1006 ok $? "Enable small discard channel $channel_name for session $sess_name"
1007}
1008
1009function enable_lttng_mmap_overwrite_small_kernel_channel()
1010{
1011 local sess_name=$1
1012 local channel_name=$2
1013
1014 $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
1015 ok $? "Enable small discard channel $channel_name for session $sess_name"
1016}
1017
ebaaaf5e
JD
1018function enable_lttng_mmap_overwrite_ust_channel()
1019{
7d0ad314
JRJ
1020 local sess_name=$1
1021 local channel_name=$2
ebaaaf5e 1022
2cf48300 1023 $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
1024 ok $? "Enable channel $channel_name for session $sess_name"
1025}
1026
d3e8f6bb
DG
1027function enable_ust_lttng_event ()
1028{
434f8068
JR
1029 local withtap=$1
1030 local expected_to_fail=$2
1031 local sess_name=$3
1032 local event_name="$4"
1033 local channel_name=$5
ebaaaf5e
JD
1034
1035 if [ -z $channel_name ]; then
1036 # default channel if none specified
1037 chan=""
1038 else
1039 chan="-c $channel_name"
1040 fi
d3e8f6bb 1041
2cf48300 1042 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1043 ret=$?
c4926bb5 1044 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1045 test $ret -ne "0"
434f8068
JR
1046 ret=$?
1047 if [[ $withtap -eq "1" ]]; then
1048 ok $ret "Enable ust event $event_name for session $session_name failed as expected"
1049 fi
01513c3e 1050 else
434f8068
JR
1051 if [[ $withtap -eq "1" ]]; then
1052 ok $ret "Enable ust event $event_name for session $sess_name"
1053 fi
01513c3e 1054 fi
434f8068 1055 return $ret
26b53d3b
DG
1056}
1057
c4926bb5
JR
1058function enable_ust_lttng_event_ok ()
1059{
434f8068 1060 enable_ust_lttng_event 1 0 "$@"
c4926bb5
JR
1061}
1062
1063function enable_ust_lttng_event_fail ()
1064{
434f8068
JR
1065 enable_ust_lttng_event 1 1 "$@"
1066}
1067
1068function enable_ust_lttng_event_notap ()
1069{
1070 enable_ust_lttng_event 0 0 "$@"
c4926bb5
JR
1071}
1072
37175ce4
DG
1073function enable_jul_lttng_event()
1074{
1075 sess_name=$1
1076 event_name="$2"
1077 channel_name=$3
1078
1079 if [ -z $channel_name ]; then
1080 # default channel if none specified
1081 chan=""
1082 else
1083 chan="-c $channel_name"
1084 fi
1085
2cf48300 1086 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
37175ce4
DG
1087 ok $? "Enable JUL event $event_name for session $sess_name"
1088}
1089
b2064f54
DG
1090function enable_jul_lttng_event_loglevel()
1091{
7d0ad314
JRJ
1092 local sess_name=$1
1093 local event_name="$2"
1094 local loglevel=$3
1095 local channel_name=$4
b2064f54
DG
1096
1097 if [ -z $channel_name ]; then
1098 # default channel if none specified
1099 chan=""
1100 else
1101 chan="-c $channel_name"
1102 fi
1103
2cf48300 1104 $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
1105 ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
1106}
1107
504d4ace
DG
1108function enable_log4j_lttng_event()
1109{
1110 sess_name=$1
1111 event_name="$2"
1112 channel_name=$3
1113
1114 if [ -z $channel_name ]; then
1115 # default channel if none specified
1116 chan=""
1117 else
1118 chan="-c $channel_name"
1119 fi
1120
2cf48300 1121 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
504d4ace
DG
1122 ok $? "Enable LOG4J event $event_name for session $sess_name"
1123}
1124
1125function enable_log4j_lttng_event_loglevel()
1126{
1127 local sess_name=$1
1128 local event_name="$2"
1129 local loglevel=$3
1130 local channel_name=$4
1131
1132 if [ -z $channel_name ]; then
1133 # default channel if none specified
1134 chan=""
1135 else
1136 chan="-c $channel_name"
1137 fi
1138
2cf48300 1139 $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
1140 ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
1141}
1142
0e115563
DG
1143function enable_python_lttng_event()
1144{
1145 sess_name=$1
1146 event_name="$2"
1147 channel_name=$3
1148
1149 if [ -z $channel_name ]; then
1150 # default channel if none specified
1151 chan=""
1152 else
1153 chan="-c $channel_name"
1154 fi
1155
2cf48300 1156 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
0e115563
DG
1157 ok $? "Enable Python event $event_name for session $sess_name"
1158}
1159
1160function enable_python_lttng_event_loglevel()
1161{
1162 local sess_name=$1
1163 local event_name="$2"
1164 local loglevel=$3
1165 local channel_name=$4
1166
1167 if [ -z $channel_name ]; then
1168 # default channel if none specified
1169 chan=""
1170 else
1171 chan="-c $channel_name"
1172 fi
1173
2cf48300 1174 $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
1175 ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel"
1176}
1177
26b53d3b
DG
1178function enable_ust_lttng_event_filter()
1179{
7d0ad314
JRJ
1180 local sess_name="$1"
1181 local event_name="$2"
1182 local filter="$3"
26b53d3b 1183
2cf48300 1184 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 1185 ok $? "Enable event $event_name with filtering for session $sess_name"
26b53d3b
DG
1186}
1187
1188function enable_ust_lttng_event_loglevel()
1189{
7d0ad314
JRJ
1190 local sess_name="$1"
1191 local event_name="$2"
1192 local loglevel="$3"
26b53d3b 1193
2cf48300 1194 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 1195 ok $? "Enable event $event_name with loglevel $loglevel"
26b53d3b
DG
1196}
1197
1198function enable_ust_lttng_event_loglevel_only()
1199{
7d0ad314
JRJ
1200 local sess_name="$1"
1201 local event_name="$2"
1202 local loglevel="$3"
26b53d3b 1203
2cf48300 1204 $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 1205 ok $? "Enable event $event_name with loglevel-only $loglevel"
26b53d3b
DG
1206}
1207
1208function disable_ust_lttng_event ()
1209{
7d0ad314
JRJ
1210 local sess_name="$1"
1211 local event_name="$2"
01513c3e 1212 local channel_name="$3"
26b53d3b 1213
01513c3e
JRJ
1214 if [ -z $channel_name ]; then
1215 # default channel if none specified
1216 chan=""
1217 else
1218 chan="-c $channel_name"
1219 fi
1220
2cf48300 1221 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 1222 ok $? "Disable event $event_name for session $sess_name"
d3e8f6bb
DG
1223}
1224
1d842d5a
DG
1225function disable_jul_lttng_event ()
1226{
1227 local sess_name="$1"
1228 local event_name="$2"
1229
1230 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1
1231 ok $? "Disable JUL event $event_name for session $sess_name"
1232}
1233
504d4ace
DG
1234function disable_log4j_lttng_event ()
1235{
1236 local sess_name="$1"
1237 local event_name="$2"
1238
1239 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1
1240 ok $? "Disable LOG4J event $event_name for session $sess_name"
1241}
1242
0e115563
DG
1243function disable_python_lttng_event ()
1244{
1245 local sess_name="$1"
1246 local event_name="$2"
1247
2cf48300 1248 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
0e115563
DG
1249 ok $? "Disable Python event $event_name for session $sess_name"
1250}
1251
7fe98a98 1252function start_lttng_tracing_opt ()
d3e8f6bb 1253{
7fe98a98
JG
1254 local withtap=$1
1255 local expected_to_fail=$2
1256 local sess_name=$3
d3e8f6bb 1257
2cf48300 1258 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1259 ret=$?
e563bbdb 1260 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1261 test "$ret" -ne "0"
7fe98a98
JG
1262 ret=$?
1263 if [ $withtap -eq "1" ]; then
1264 ok $? "Start tracing for session $sess_name failed as expected"
1265 fi
01513c3e 1266 else
7fe98a98
JG
1267 if [ $withtap -eq "1" ]; then
1268 ok $ret "Start tracing for session $sess_name"
1269 fi
01513c3e 1270 fi
d3e8f6bb
DG
1271}
1272
e563bbdb
JR
1273function start_lttng_tracing_ok ()
1274{
7fe98a98 1275 start_lttng_tracing_opt 1 0 "$@"
e563bbdb
JR
1276}
1277
1278function start_lttng_tracing_fail ()
1279{
7fe98a98 1280 start_lttng_tracing_opt 1 1 "$@"
e563bbdb
JR
1281}
1282
7fe98a98 1283function start_lttng_tracing_notap ()
d3e8f6bb 1284{
7fe98a98
JG
1285 start_lttng_tracing_opt 0 1 "$@"
1286}
1287
1288function stop_lttng_tracing_opt ()
1289{
1290 local withtap=$1
1291 local expected_to_fail=$2
1292 local sess_name=$3
d3e8f6bb 1293
2cf48300 1294 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1295 ret=$?
96340a01 1296 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1297 test "$ret" -ne "0"
7fe98a98
JG
1298 ret=$?
1299 if [ $withtap -eq "1" ]; then
1300 ok $? "Stop lttng tracing for session $sess_name failed as expected"
1301 fi
01513c3e 1302 else
7fe98a98
JG
1303 if [ $withtap -eq "1" ]; then
1304 ok $ret "Stop lttng tracing for session $sess_name"
1305 fi
01513c3e 1306 fi
d3e8f6bb
DG
1307}
1308
96340a01
JR
1309function stop_lttng_tracing_ok ()
1310{
7fe98a98 1311 stop_lttng_tracing_opt 1 0 "$@"
96340a01
JR
1312}
1313
1314function stop_lttng_tracing_fail ()
1315{
7fe98a98
JG
1316 stop_lttng_tracing_opt 1 1 "$@"
1317}
1318
1319function stop_lttng_tracing_notap ()
1320{
1321 stop_lttng_tracing_opt 0 0 "$@"
96340a01
JR
1322}
1323
d3e8f6bb
DG
1324function destroy_lttng_session ()
1325{
854382b8
JR
1326 local withtap=$1
1327 local expected_to_fail=$2
1328 local sess_name=$3
d3e8f6bb 1329
2cf48300 1330 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1331 ret=$?
96340a01 1332 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1333 test "$ret" -ne "0"
854382b8
JR
1334 ret=$?
1335 if [ $withtap -eq "1" ]; then
1336 ok $ret "Destroy session $sess_name failed as expected"
1337 fi
01513c3e 1338 else
854382b8
JR
1339 if [ $withtap -eq "1" ]; then
1340 ok $ret "Destroy session $sess_name"
1341 fi
01513c3e 1342 fi
d3e8f6bb
DG
1343}
1344
67b4c664
JR
1345function destroy_lttng_session_ok ()
1346{
854382b8 1347 destroy_lttng_session 1 0 "$@"
67b4c664
JR
1348
1349}
1350
1351function destroy_lttng_session_fail ()
1352{
854382b8 1353 destroy_lttng_session 1 1 "$@"
67b4c664
JR
1354}
1355
854382b8
JR
1356function destroy_lttng_session_notap ()
1357{
1358 destroy_lttng_session 0 0 "$@"
1359}
67b4c664 1360
873c2aae
JRJ
1361function destroy_lttng_sessions ()
1362{
2cf48300 1363 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
873c2aae
JRJ
1364 ok $? "Destroy all lttng sessions"
1365}
1366
07b86b52
JD
1367function lttng_snapshot_add_output ()
1368{
b5633831
JR
1369 local expected_to_fail=$1
1370 local sess_name=$2
1371 local trace_path=$3
9f0e230a 1372 local opts=$4
07b86b52 1373
9f0e230a 1374 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name $trace_path $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1375 ret=$?
b5633831 1376 if [[ $expected_to_fail -eq 1 ]]; then
01513c3e 1377 test "$ret" -ne "0"
9f0e230a 1378 ok $? "Added snapshot output $trace_path failed as expected"
01513c3e 1379 else
9f0e230a 1380 ok $ret "Added snapshot output $trace_path"
01513c3e 1381 fi
07b86b52
JD
1382}
1383
b5633831
JR
1384function lttng_snapshot_add_output_ok ()
1385{
1386 lttng_snapshot_add_output 0 "$@"
1387}
1388
1389function lttng_snapshot_add_output_fail ()
1390{
1391 lttng_snapshot_add_output 1 "$@"
1392}
1393
26402e0c
DG
1394function lttng_snapshot_del_output ()
1395{
31580dc7
JR
1396 local expected_to_fail=$1
1397 local sess_name=$2
1398 local id=$3
26402e0c 1399
2cf48300 1400 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1401 ret=$?
31580dc7 1402 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1403 test "$ret" -ne "0"
34ab15c5 1404 ok $? "Deleted snapshot output id $id failed as expected"
01513c3e
JRJ
1405 else
1406 ok $ret "Deleted snapshot output id $id"
1407 fi
26402e0c
DG
1408}
1409
31580dc7
JR
1410function lttng_snapshot_del_output_ok ()
1411{
1412 lttng_snapshot_del_output 0 "$@"
1413}
1414
1415function lttng_snapshot_del_output_fail ()
1416{
1417 lttng_snapshot_del_output 1 "$@"
1418}
1419
07b86b52
JD
1420function lttng_snapshot_record ()
1421{
7d0ad314 1422 local sess_name=$1
07b86b52 1423
2a166864 1424 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name $trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
07b86b52
JD
1425 ok $? "Snapshot recorded"
1426}
1427
01513c3e
JRJ
1428function lttng_snapshot_list ()
1429{
1430 local sess_name=$1
2cf48300 1431 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e
JRJ
1432 ok $? "Snapshot list"
1433}
1434
e02b109b
DG
1435function lttng_save()
1436{
1437 local sess_name=$1
1438 local opts=$2
1439
2cf48300 1440 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
34ab15c5 1441 ok $? "Session saved"
e02b109b
DG
1442}
1443
1444function lttng_load()
1445{
192ac418
JR
1446 local expected_to_fail=$1
1447 local opts=$2
e02b109b 1448
2cf48300 1449 $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
192ac418
JR
1450 ret=$?
1451 if [[ $expected_to_fail -eq "1" ]]; then
1452 test $ret -ne "0"
1453 ok $? "Load command failed as expected with opts: $opts"
1454 else
1455 ok $ret "Load command with opts: $opts"
1456 fi
1457}
1458
1459function lttng_load_ok()
1460{
1461 lttng_load 0 "$@"
1462}
1463
1464function lttng_load_fail()
1465{
1466 lttng_load 1 "$@"
e02b109b
DG
1467}
1468
e83a8bdb
JR
1469function lttng_track()
1470{
ba5e8d0a 1471 local expected_to_fail="$1"
c47a705b 1472 shift 1
ba5e8d0a 1473 local opts="$@"
e83a8bdb
JR
1474 $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST
1475 ret=$?
1476 if [[ $expected_to_fail -eq "1" ]]; then
1477 test $ret -ne "0"
1478 ok $? "Track command failed as expected with opts: $opts"
1479 else
34ab15c5 1480 ok $ret "Track command with opts: $opts"
e83a8bdb
JR
1481 fi
1482}
1483
1484function lttng_track_ok()
1485{
1486 lttng_track 0 "$@"
1487}
1488
1489function lttng_track_fail()
1490{
1491 lttng_track 1 "$@"
1492}
1493
1494function lttng_untrack()
1495{
ba5e8d0a 1496 local expected_to_fail="$1"
c47a705b 1497 shift 1
ba5e8d0a 1498 local opts="$@"
e83a8bdb
JR
1499 $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST
1500 ret=$?
1501 if [[ $expected_to_fail -eq "1" ]]; then
1502 test $ret -ne "0"
1503 ok $? "Untrack command failed as expected with opts: $opts"
1504 else
34ab15c5 1505 ok $ret "Untrack command with opts: $opts"
e83a8bdb
JR
1506 fi
1507}
1508
1509function lttng_untrack_ok()
1510{
1511 lttng_untrack 0 "$@"
1512}
1513
1514function lttng_untrack_fail()
1515{
1516 lttng_untrack 1 "$@"
1517}
1518
c8e51d15
FD
1519function lttng_track_pid_ok()
1520{
1521 PID=$1
1522 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track --kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1523 ok $? "Lttng track pid on the kernel domain"
1524}
1525
1526function lttng_untrack_kernel_all_ok()
1527{
1528 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack --kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1529 ok $? "Lttng untrack all pid on the kernel domain"
1530}
1531
ba5e8d0a
MD
1532function lttng_track_ust_ok()
1533{
1534 lttng_track_ok -u "$@"
1535}
1536
1537function lttng_track_ust_fail()
1538{
1539 lttng_track_fail -u "$@"
1540}
1541
1542function lttng_track_kernel_ok()
1543{
1544 lttng_track_ok -k "$@"
1545}
1546
1547function lttng_track_kernel_fail()
1548{
1549 lttng_track_fail -k "$@"
1550}
1551
1552function lttng_untrack_ust_ok()
1553{
1554 lttng_untrack_ok -u "$@"
1555}
1556
1557function lttng_untrack_ust_fail()
1558{
1559 lttng_untrack_fail -u "$@"
1560}
1561
1562function lttng_untrack_kernel_ok()
1563{
1564 lttng_untrack_ok -k "$@"
1565}
1566
1567function lttng_untrack_kernel_fail()
1568{
1569 lttng_untrack_fail -k "$@"
1570}
1571
59deec0c
JR
1572function lttng_add_context_list()
1573{
1574 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context --list 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1575 ret=$?
1576 ok $ret "Context listing"
1577}
1578
8dcef147
JR
1579function add_context_lttng()
1580{
1581 local expected_to_fail="$1"
1582 local domain="$2"
1583 local session_name="$3"
1584 local channel_name="$4"
1585 local type="$5"
1586
1587 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context -s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1588 ret=$?
1589 if [[ $expected_to_fail -eq "1" ]]; then
1590 test $ret -ne "0"
1591 ok $? "Add context command failed as expected for type: $type"
1592 else
1593 ok $ret "Add context command for type: $type"
1594 fi
1595}
1596
1597function add_context_ust_ok()
1598{
1599 add_context_lttng 0 -u "$@"
1600}
1601
1602function add_context_ust_fail()
1603{
1604 add_context_lttng 1 -u "$@"
1605}
1606
1607function add_context_kernel_ok()
1608{
1609 add_context_lttng 0 -k "$@"
1610}
1611
1612function add_context_kernel_fail()
1613{
1614 add_context_lttng 1 -k "$@"
1615}
1616
c28fcefd
JR
1617function validate_directory_empty ()
1618{
1619 local trace_path=$1
1620
1621 ls -A $local_path > /dev/null 2>&1
1622 if [ $? -eq 0 ]; then
1623 pass "Directory empty"
1624 else
1625 fail "Directory empty"
1626 fi
1627}
1628
1629function wait_live_trace_ready ()
1630{
1631 local url=$1
1632 local zero_client_match=0
1633
1634 diag "Waiting for live trace at url: $url"
1635 while [ $zero_client_match -eq 0 ]; do
1636 zero_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "0 client(s) connected" | wc -l)
1637 sleep 0.5
1638 done
1639 pass "Waiting for live trace at url: $url"
1640}
1641
1642function wait_live_viewer_connect ()
1643{
1644 local url=$1
1645 local one_client_match=0
1646
1647 diag "Waiting for live viewers on url: $url"
1648 while [ $one_client_match -eq 0 ]; do
1649 one_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "1 client(s) connected" | wc -l)
1650 sleep 0.5
1651 done
1652 pass "Waiting for live viewers on url: $url"
1653}
1654
c54b437e
FD
1655function validate_metadata_event ()
1656{
1657 local event_name=$1
1658 local nr_event_id=$2
1659 local trace_path=$3
1660
1661 local metadata_file=$(find $trace_path | grep metadata)
1662 local metadata_path=$(dirname $metadata_file)
1663
1664 which $BABELTRACE_BIN >/dev/null
1665 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1666
1667 local count=$($BABELTRACE_BIN --output-format=ctf-metadata $metadata_path | grep $event_name | wc -l)
1668
1669 if [ "$count" -ne "$nr_event_id" ]; then
1670 fail "Metadata match with the metadata of $count event(s) named $event_name"
1671 diag "$count matching event id found in metadata"
1672 else
1673 pass "Metadata match with the metadata of $count event(s) named $event_name"
1674 fi
1675
1676}
1677
d3e8f6bb
DG
1678function trace_matches ()
1679{
7d0ad314
JRJ
1680 local event_name=$1
1681 local nr_iter=$2
1682 local trace_path=$3
d3e8f6bb 1683
317eef93 1684 which $BABELTRACE_BIN >/dev/null
29655db7 1685 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
d3e8f6bb 1686
7d0ad314 1687 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
29655db7 1688
d3e8f6bb 1689 if [ "$count" -ne "$nr_iter" ]; then
29655db7 1690 fail "Trace match"
af91abc9 1691 diag "$count matching events found in trace"
d3e8f6bb 1692 else
29655db7 1693 pass "Trace match"
d3e8f6bb
DG
1694 fi
1695}
f4e40ab6 1696
d53addeb
DG
1697function trace_match_only()
1698{
1699 local event_name=$1
1700 local nr_iter=$2
1701 local trace_path=$3
1702
1703 which $BABELTRACE_BIN >/dev/null
1704 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1705
1706 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
1707 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1708
08f96a38
JG
1709 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1710 pass "Trace match with $total event $event_name"
1711 else
1712 fail "Trace match"
1713 diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1714 fi
d53addeb
DG
1715}
1716
f4e40ab6
DG
1717function validate_trace
1718{
7d0ad314
JRJ
1719 local event_name=$1
1720 local trace_path=$2
f4e40ab6
DG
1721
1722 which $BABELTRACE_BIN >/dev/null
29655db7
CB
1723 if [ $? -ne 0 ]; then
1724 skip 0 "Babeltrace binary not found. Skipping trace validation"
f4e40ab6
DG
1725 fi
1726
07b86b52
JD
1727 OLDIFS=$IFS
1728 IFS=","
1729 for i in $event_name; do
1730 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1731 if [ "$traced" -ne 0 ]; then
ebaaaf5e 1732 pass "Validate trace for event $i, $traced events"
07b86b52
JD
1733 else
1734 fail "Validate trace for event $i"
1735 diag "Found $traced occurences of $i"
1736 fi
1737 done
1738 ret=$?
1739 IFS=$OLDIFS
1740 return $ret
f4e40ab6 1741}
8cfcd41c 1742
54cd6107
JD
1743function validate_trace_count
1744{
1745 local event_name=$1
1746 local trace_path=$2
1747 local expected_count=$3
1748
1749 which $BABELTRACE_BIN >/dev/null
1750 if [ $? -ne 0 ]; then
1751 skip 0 "Babeltrace binary not found. Skipping trace validation"
1752 fi
1753
1754 cnt=0
1755 OLDIFS=$IFS
1756 IFS=","
1757 for i in $event_name; do
1758 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1759 if [ "$traced" -ne 0 ]; then
1760 pass "Validate trace for event $i, $traced events"
1761 else
1762 fail "Validate trace for event $i"
1763 diag "Found $traced occurences of $i"
1764 fi
1765 cnt=$(($cnt + $traced))
1766 done
1767 IFS=$OLDIFS
1768 test $cnt -eq $expected_count
1769 ok $? "Read a total of $cnt events, expected $expected_count"
1770}
1771
c28fcefd
JR
1772function validate_trace_count_range_incl_min_excl_max
1773{
1774 local event_name=$1
1775 local trace_path=$2
1776 local expected_min=$3
1777 local expected_max=$4
1778
1779 which $BABELTRACE_BIN >/dev/null
1780 if [ $? -ne 0 ]; then
1781 skip 0 "Babeltrace binary not found. Skipping trace validation"
1782 fi
1783
1784 cnt=0
1785 OLDIFS=$IFS
1786 IFS=","
1787 for i in $event_name; do
1788 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1789 if [ "$traced" -ge $expected_min ]; then
1790 pass "Validate trace for event $i, $traced events"
1791 else
1792 fail "Validate trace for event $i"
1793 diag "Found $traced occurences of $i"
1794 fi
1795 cnt=$(($cnt + $traced))
1796 done
1797 IFS=$OLDIFS
1798 test $cnt -lt $expected_max
1799 ok $? "Read a total of $cnt events, expected between [$expected_min, $expected_max["
1800}
1801
086e6add
MD
1802function trace_first_line
1803{
1804 local trace_path=$1
1805
1806 which $BABELTRACE_BIN >/dev/null
1807 if [ $? -ne 0 ]; then
1808 skip 0 "Babeltrace binary not found. Skipping trace validation"
1809 fi
1810
1811 $BABELTRACE_BIN $trace_path 2>/dev/null | head -n 1
1812}
1813
8cfcd41c
MD
1814function validate_trace_exp()
1815{
1816 local event_exp=$1
1817 local trace_path=$2
1818
1819 which $BABELTRACE_BIN >/dev/null
1820 skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
1821
49538c32 1822 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep --extended-regexp ${event_exp} | wc -l)
8cfcd41c
MD
1823 if [ "$traced" -ne 0 ]; then
1824 pass "Validate trace for expression '${event_exp}', $traced events"
1825 else
1826 fail "Validate trace for expression '${event_exp}'"
1827 diag "Found $traced occurences of '${event_exp}'"
1828 fi
1829 ret=$?
1830 return $ret
1831}
1832
1833function validate_trace_only_exp()
1834{
1835 local event_exp=$1
1836 local trace_path=$2
1837
1838 which $BABELTRACE_BIN >/dev/null
1839 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1840
49538c32 1841 local count=$($BABELTRACE_BIN $trace_path | grep --extended-regexp ${event_exp} | wc -l)
8cfcd41c
MD
1842 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1843
1844 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
ab95d85d 1845 pass "Trace match with $total for expression '${event_exp}'"
8cfcd41c
MD
1846 else
1847 fail "Trace match"
1848 diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1849 fi
1850 ret=$?
1851 return $ret
1852}
1853
1854function validate_trace_empty()
1855{
1856 local trace_path=$1
1857
1858 which $BABELTRACE_BIN >/dev/null
1859 if [ $? -ne 0 ]; then
1860 skip 0 "Babeltrace binary not found. Skipping trace validation"
1861 fi
1862
2462eee7
JD
1863 events=$($BABELTRACE_BIN $trace_path 2>/dev/null)
1864 ret=$?
1865 if [ $ret -ne 0 ]; then
1866 fail "Failed to parse trace"
1867 return $ret
1868 fi
1869
1870 traced=$(echo -n "$events" | wc -l)
8cfcd41c
MD
1871 if [ "$traced" -eq 0 ]; then
1872 pass "Validate empty trace"
1873 else
1874 fail "Validate empty trace"
1875 diag "Found $traced events in trace"
1876 fi
1877 ret=$?
1878 return $ret
1879}
801236b0 1880
ba5e8d0a
MD
1881function validate_folder_is_empty()
1882{
1883 local folder=$1
1884
1885 test -z "$(ls -A "$folder")"
1886 ok $? "Folder ${folder} is empty"
1887}
1888
1889function validate_trace_session_ust_empty()
1890{
1891 validate_folder_is_empty "$1"/ust
1892}
1893
1894function validate_trace_session_kernel_empty()
1895{
1896 validate_trace_empty "$1"/kernel
1897}
1898
eded6438 1899function regenerate_metadata ()
801236b0
JD
1900{
1901 local expected_to_fail=$1
1902 local sess_name=$2
1903
eded6438 1904 $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate metadata -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
801236b0
JD
1905 ret=$?
1906 if [[ $expected_to_fail -eq "1" ]]; then
1907 test "$ret" -ne "0"
eded6438 1908 ok $? "Expected fail on regenerate metadata $sess_name"
801236b0
JD
1909 else
1910 ok $ret "Metadata regenerate $sess_name"
1911 fi
1912}
1913
eded6438 1914function regenerate_metadata_ok ()
801236b0 1915{
eded6438 1916 regenerate_metadata 0 "$@"
801236b0
JD
1917}
1918
eded6438 1919function regenerate_metadata_fail ()
801236b0 1920{
eded6438 1921 regenerate_metadata 1 "$@"
801236b0 1922}
512eb148 1923
54cd6107
JD
1924function regenerate_statedump ()
1925{
1926 local expected_to_fail=$1
1927 local sess_name=$2
1928
1929 $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate statedump -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1930 ret=$?
1931 if [[ $expected_to_fail -eq "1" ]]; then
1932 test "$ret" -ne "0"
1933 ok $? "Expected fail on regenerate statedump $sess_name"
1934 else
5ebb1a9f 1935 ok $ret "Statedump regenerate $sess_name"
54cd6107
JD
1936 fi
1937}
1938
1939function regenerate_statedump_ok ()
1940{
1941 regenerate_statedump 0 "$@"
1942}
1943
1944function regenerate_statedump_fail ()
1945{
1946 regenerate_statedump 1 "$@"
1947}
1948
e7716c6a
JD
1949function rotate_session ()
1950{
1951 local expected_to_fail=$1
1952 local sess_name=$2
1953
1954 $TESTDIR/../src/bin/lttng/$LTTNG_BIN rotate $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1955 ret=$?
1956 if [[ $expected_to_fail -eq "1" ]]; then
1957 test "$ret" -ne "0"
1958 ok $? "Expected fail on rotate session $sess_name"
1959 else
1960 ok $ret "Rotate session $sess_name"
1961 fi
1962}
1963
1964function rotate_session_ok ()
1965{
1966 rotate_session 0 "$@"
1967}
1968
1969function rotate_session_fail ()
1970{
1971 rotate_session 1 "$@"
1972}
1973
512eb148
JD
1974function destructive_tests_enabled ()
1975{
1976 if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then
1977 return 0
1978 else
1979 return 1
1980 fi
1981}
e7716c6a
JD
1982
1983function lttng_enable_rotation_timer ()
1984{
1985 local expected_to_fail=$1
1986 local sess_name=$2
1987 local period=$3
1988
1989 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --timer $period 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1990 ret=$?
1991 if [[ $expected_to_fail -eq "1" ]]; then
1992 test "$ret" -ne "0"
9498e289 1993 ok $? "Expected fail when setting periodic rotation ($period) of session $sess_name"
e7716c6a 1994 else
795f9063 1995 ok $ret "Set periodic rotation ($period) of session $sess_name"
e7716c6a
JD
1996 fi
1997}
1998
1999function lttng_enable_rotation_timer_ok ()
2000{
2001 lttng_enable_rotation_timer 0 $@
2002}
2003
2004function lttng_enable_rotation_timer_fail ()
2005{
2006 lttng_enable_rotation_timer 1 $@
2007}
2008
2009function lttng_enable_rotation_size ()
2010{
2011 local expected_to_fail=$1
2012 local sess_name=$2
2013 local size=$3
2014
2015 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --size $size 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2016 ret=$?
2017 if [[ $expected_to_fail -eq "1" ]]; then
2018 test "$ret" -ne "0"
2019 ok $? "Expected fail on rotate session $sess_name"
2020 else
2021 ok $ret "Rotate session $sess_name"
2022 fi
2023}
2024
2025function lttng_enable_rotation_size_ok ()
2026{
2027 lttng_enable_rotation_size 0 $@
2028}
2029
2030function lttng_enable_rotation_size_fail ()
2031{
2032 lttng_enable_rotation_size 1 $@
2033}
c28fcefd
JR
2034
2035function lttng_clear_session ()
2036{
2037 local expected_to_fail=$1
2038 local sess_name=$2
2039
2040 $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2041 ret=$?
2042 if [[ $expected_to_fail -eq "1" ]]; then
2043 test "$ret" -ne "0"
2044 ok $? "Expected fail on clear session $sess_name"
2045 else
2046 ok $ret "Clear session $sess_name"
2047 fi
2048}
2049
2050function lttng_clear_session_ok ()
2051{
2052 lttng_clear_session 0 $@
2053}
2054
2055function lttng_clear_session_fail ()
2056{
2057 lttng_clear_session 1 $@
2058}
5ee26199
JR
2059
2060function lttng_clear_all ()
2061{
2062 $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2063 ok $? "Clear all lttng sessions"
2064}
This page took 0.175389 seconds and 5 git commands to generate.