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