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