1 # Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
3 # SPDX-License-Identifier: LGPL-2.1-only
6 SESSIOND_BIN
="lttng-sessiond"
7 SESSIOND_MATCH
=".*lttng-sess.*"
8 RUNAS_BIN
="lttng-runas"
9 RUNAS_MATCH
=".*lttng-runas.*"
10 CONSUMERD_BIN
="lttng-consumerd"
11 CONSUMERD_MATCH
=".*lttng-consumerd.*"
12 RELAYD_BIN
="lttng-relayd"
13 RELAYD_MATCH
=".*lttng-relayd.*"
15 BABELTRACE_BIN
="babeltrace"
17 ERROR_OUTPUT_DEST
=/dev
/null
18 MI_XSD_MAJOR_VERSION
=4
19 MI_XSD_MINOR_VERSION
=1
20 MI_XSD_PATH
="$TESTDIR/../src/common/mi-lttng-${MI_XSD_MAJOR_VERSION}.${MI_XSD_MINOR_VERSION}.xsd"
21 MI_VALIDATE
="$TESTDIR/utils/xml-utils/validate_xml ${MI_XSD_PATH}"
23 XML_PRETTY
="$TESTDIR/utils/xml-utils/pretty_xml"
24 XML_EXTRACT
="$TESTDIR/utils/xml-utils/extract_xml"
25 XML_NODE_CHECK
="${XML_EXTRACT} -e"
27 # To match 20201127-175802
28 date_time_pattern
="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]"
29 # The size of a long on this system
30 system_long_bit_size
=$
(getconf LONG_BIT
)
32 # Minimal kernel version supported for session daemon tests
33 KERNEL_MAJOR_VERSION
=2
34 KERNEL_MINOR_VERSION
=6
35 KERNEL_PATCHLEVEL_VERSION
=27
37 # We set the default UST register timeout and network and app socket timeout to
38 # "wait forever", so that basic tests don't have to worry about hitting
39 # timeouts on busy systems. Specialized tests should test those corner-cases.
40 export LTTNG_UST_REGISTER_TIMEOUT
=-1
41 export LTTNG_NETWORK_SOCKET_TIMEOUT
=-1
42 export LTTNG_APP_SOCKET_TIMEOUT
=-1
44 # We set the default lttng-sessiond path to /bin/true to prevent the spawning
45 # of a daemonized sessiond. This is necessary since 'lttng create' will spawn
46 # its own sessiond if none is running. It also ensures that 'lttng create'
47 # fails when no sessiond is running.
48 export LTTNG_SESSIOND_PATH
="/bin/true"
50 source $TESTDIR/utils
/tap
/tap.sh
52 if [ -z ${LTTNG_TEST_TEARDOWN_TIMEOUT+x} ]; then
53 LTTNG_TEST_TEARDOWN_TIMEOUT
=60
56 # Enable job monitor mode.
57 # Here we are mostly interested in the following from the monitor mode:
58 # All processes run in a separate process group.
59 # This allows us to ensure that all subprocesses from all background tasks are
60 # cleaned up correctly using signal to process group id.
63 kill_background_jobs
()
68 if [ -z "$pids" ]; then
75 # Use negative number to send the signal to the process group.
76 # This ensure that any subprocesses receive the signal.
77 # /dev/null is used since there is an acceptable race between
78 # the moments the pids are listed and the moment we send a
80 kill -SIGTERM -- "-$pid" 2>/dev
/null
86 # Try to kill daemons gracefully
87 stop_lttng_relayd_cleanup SIGTERM
$LTTNG_TEST_TEARDOWN_TIMEOUT
88 stop_lttng_sessiond_cleanup SIGTERM
$LTTNG_TEST_TEARDOWN_TIMEOUT
90 # If daemons are still present, forcibly kill them
91 stop_lttng_relayd_cleanup SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
92 stop_lttng_sessiond_cleanup SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
93 stop_lttng_consumerd_cleanup SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
98 function full_cleanup
()
104 function LTTNG_BAIL_OUT
()
110 function null_pipes
()
117 trap full_cleanup SIGINT SIGTERM
119 # perl prove closes its child pipes before giving it a chance to run its
120 # signal trap handlers. Redirect pipes to /dev/null if SIGPIPE is caught
121 # to allow those trap handlers to proceed.
123 trap null_pipes SIGPIPE
125 # Check pgrep from env, default to pgrep if none
126 if [ -z "$PGREP" ]; then
130 # Due to the renaming of threads we need to use the full command (pgrep -f) to
131 # identify the pids for multiple lttng related processes. The problem with "pgrep
132 # -f" is that it ends up also looking at the arguments. We use a two stage
133 # lookup. The first one is using "pgrep -f" yielding potential candidate.
134 # The second on perform grep on the basename of the first field of the
135 # /proc/pid/cmdline of the previously identified pids. The first field
136 # correspond to the actual command.
137 function lttng_pgrep
()
141 local full_command_no_argument
142 local command_basename
144 possible_pids
=$
($PGREP -f "$pattern")
145 if [ -z "$possible_pids" ]; then
149 while IFS
= read -r pid
; do
150 # /proc/pid/cmdline is null separated.
151 if full_command_no_argument
=$
(cut
-d '' -f 1 2>/dev
/null
< /proc
/"$pid"/cmdline
); then
152 command_basename
=$
(basename "$full_command_no_argument")
153 if grep -q "$pattern" <<< "$command_basename"; then
157 done <<< "$possible_pids"
163 # Check if we are a terminal
165 echo -e "\e[1;32mOK\e[0m"
171 function print_fail
()
173 # Check if we are a terminal
175 echo -e "\e[1;31mFAIL\e[0m"
181 function print_test_banner
()
187 function validate_kernel_version
()
189 local kern_version
=($
(uname
-r |
awk -F.
'{ printf("%d.%d.%d\n",$1,$2,$3); }' |
tr '.' '\n'))
190 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
193 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
196 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
202 # Generate a random string
203 # $1 = number of characters; defaults to 16
204 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
205 function randstring
()
207 [ "$2" == "0" ] && CHAR
="[:alnum:]" || CHAR
="[:graph:]"
208 cat /dev
/urandom
2>/dev
/null |
tr -cd "$CHAR" 2>/dev
/null |
head -c ${1:-16} 2>/dev
/null
212 # Return the number of _configured_ CPUs.
213 function conf_proc_count
()
215 getconf _NPROCESSORS_CONF
216 if [ $?
-ne 0 ]; then
217 diag
"Failed to get the number of configured CPUs"
222 # Check if base lttng-modules are present.
223 # Bail out on failure
224 function validate_lttng_modules_present
()
226 # Check for loadable modules.
227 modprobe
-n lttng-tracer
2>/dev
/null
228 if [ $?
-eq 0 ]; then
232 # Check for builtin modules.
233 ls /proc
/lttng
> /dev
/null
2>&1
234 if [ $?
-eq 0 ]; then
238 LTTNG_BAIL_OUT
"LTTng modules not detected."
241 function enable_kernel_lttng_event
244 local expected_to_fail
="$2"
246 local event_name
="$4"
247 local channel_name
="$5"
249 if [ -z "$event_name" ]; then
250 # Enable all event if no event name specified
254 if [ -z "$channel_name" ]; then
255 # default channel if none specified
258 chan
="-c $channel_name"
261 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
263 if [[ $expected_to_fail -eq "1" ]]; then
266 if [ $withtap -eq "1" ]; then
267 ok
$ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
270 if [ $withtap -eq "1" ]; then
271 ok
$ret "Enable kernel event $event_name for session $sess_name"
276 function enable_kernel_lttng_event_ok
()
278 enable_kernel_lttng_event
1 0 "$@"
281 function enable_kernel_lttng_event_fail
()
283 enable_kernel_lttng_event
1 1 "$@"
286 function enable_kernel_lttng_event_notap
()
288 enable_kernel_lttng_event
0 0 "$@"
292 function lttng_enable_kernel_event
294 enable_kernel_lttng_event_ok
"$@"
297 function lttng_enable_kernel_syscall
()
299 local expected_to_fail
=$1
301 local syscall_name
=$3
302 local channel_name
=$4
304 if [ -z $syscall_name ]; then
305 # Enable all event if no syscall name specified
309 if [ -z $channel_name ]; then
310 # default channel if none specified
313 chan
="-c $channel_name"
316 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
318 if [[ $expected_to_fail -eq "1" ]]; then
320 ok $?
"Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
322 ok
$ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
326 function lttng_enable_kernel_syscall_ok
()
328 lttng_enable_kernel_syscall
0 "$@"
331 function lttng_enable_kernel_syscall_fail
()
333 lttng_enable_kernel_syscall
1 "$@"
336 function lttng_disable_kernel_syscall
()
338 local expected_to_fail
=$1
340 local syscall_name
=$3
341 local channel_name
=$4
343 if [ -z $syscall_name ]; then
344 # Enable all event if no syscall name specified
348 if [ -z $channel_name ]; then
349 # default channel if none specified
352 chan
="-c $channel_name"
355 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
358 if [[ $expected_to_fail -eq "1" ]]; then
360 ok $?
"Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
362 ok
$ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
366 function lttng_disable_kernel_syscall_ok
()
368 lttng_disable_kernel_syscall
0 "$@"
371 function lttng_disable_kernel_syscall_fail
()
373 lttng_disable_kernel_syscall
1 "$@"
376 function lttng_enable_kernel_function_event
()
378 local expected_to_fail
="$1"
381 local event_name
="$4"
383 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
--kernel --function="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
385 if [[ $expected_to_fail -eq "1" ]]; then
387 ok $?
"Enable kernel function event for session $sess_name failed as expected"
389 ok
$ret "Enable kernel function event for session $sess_name"
393 function lttng_enable_kernel_function_event_ok
()
395 lttng_enable_kernel_function_event
0 "$@"
398 function lttng_enable_kernel_userspace_probe_event
()
400 local expected_to_fail
="$1"
403 local event_name
="$4"
405 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
--kernel --userspace-probe="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
407 if [[ $expected_to_fail -eq "1" ]]; then
409 ok $?
"Enable kernel userspace probe event for session $sess_name failed as expected"
411 ok
$ret "Enable kernel userspace probe event for session $sess_name"
415 function lttng_enable_kernel_userspace_probe_event_fail
()
417 lttng_enable_kernel_userspace_probe_event
1 "$@"
420 function lttng_enable_kernel_userspace_probe_event_ok
()
422 lttng_enable_kernel_userspace_probe_event
0 "$@"
425 function disable_kernel_lttng_userspace_probe_event_ok
()
428 local event_name
="$2"
430 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" disable-event
--kernel "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
431 ok $?
"Disable kernel event $target for session $sess_name"
433 function lttng_enable_kernel_channel
()
436 local expected_to_fail
=$2
438 local channel_name
=$4
441 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-k $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
443 if [[ $expected_to_fail -eq "1" ]]; then
446 if [ $withtap -eq "1" ]; then
447 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
450 if [ $withtap -eq "1" ]; then
451 ok
$ret "Enable channel $channel_name for session $sess_name"
456 function lttng_enable_kernel_channel_ok
()
458 lttng_enable_kernel_channel
1 0 "$@"
461 function lttng_enable_kernel_channel_fail
()
463 lttng_enable_kernel_channel
1 1 "$@"
466 function lttng_enable_kernel_channel_notap
()
468 lttng_enable_kernel_channel
0 0 "$@"
471 function enable_kernel_lttng_channel_ok
()
473 lttng_enable_kernel_channel
1 0 "$@"
476 function lttng_disable_kernel_channel
()
478 local expected_to_fail
=$1
480 local channel_name
=$3
482 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
484 if [[ $expected_to_fail -eq "1" ]]; then
486 ok $?
"Disable channel $channel_name for session $sess_name failed as expected"
488 ok
$ret "Disable channel $channel_name for session $sess_name"
492 function lttng_disable_kernel_channel_ok
()
494 lttng_disable_kernel_channel
0 "$@"
497 function lttng_disable_kernel_channel_fail
()
499 lttng_disable_kernel_channel
1 "$@"
502 function start_lttng_relayd_opt
()
505 local process_mode
=$2
508 DIR
=$
(readlink
-f "$TESTDIR")
510 if [ -z $
(lttng_pgrep
"$RELAYD_MATCH") ]; then
511 # shellcheck disable=SC2086
512 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
513 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
514 if [ $?
-eq 1 ]; then
515 if [ $withtap -eq "1" ]; then
516 fail
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
520 if [ $withtap -eq "1" ]; then
521 pass
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
525 pass
"Start lttng-relayd (opt: $opt)"
529 function start_lttng_relayd
()
531 start_lttng_relayd_opt
1 "-b" "$@"
534 function start_lttng_relayd_notap
()
536 start_lttng_relayd_opt
0 "-b" "$@"
539 function stop_lttng_relayd_opt
()
549 if [ -z "$signal" ]; then
554 # Multiply time by 2 to simplify integer arithmetic
555 if [ -n "$timeout_s" ]; then
556 dtimeleft_s
=$
((timeout_s
* 2))
560 pids
=$
(lttng_pgrep
"$RELAYD_MATCH")
561 if [ -z "$pids" ]; then
562 if [ "$is_cleanup" -eq 1 ]; then
564 elif [ "$withtap" -eq "1" ]; then
565 fail
"No relay daemon to kill"
567 LTTNG_BAIL_OUT
"No relay daemon to kill"
572 diag
"Killing (signal $signal) lttng-relayd (pid: $pids)"
574 # shellcheck disable=SC2086
575 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
577 if [ "$withtap" -eq "1" ]; then
578 fail
"Kill relay daemon"
582 while [ -n "$out" ]; do
583 out
=$
(lttng_pgrep
"$RELAYD_MATCH")
584 if [ -n "$dtimeleft_s" ]; then
585 if [ $dtimeleft_s -lt 0 ]; then
589 dtimeleft_s
=$
((dtimeleft_s
- 1))
593 if [ "$withtap" -eq "1" ]; then
594 if [ "$retval" -eq "0" ]; then
595 pass
"Wait after kill relay daemon"
597 fail
"Wait after kill relay daemon"
604 function stop_lttng_relayd
()
606 stop_lttng_relayd_opt
1 0 "$@"
609 function stop_lttng_relayd_notap
()
611 stop_lttng_relayd_opt
0 0 "$@"
614 function stop_lttng_relayd_cleanup
()
616 stop_lttng_relayd_opt
0 1 "$@"
619 #First arg: show tap output
620 #Second argument: load path for automatic loading
621 function start_lttng_sessiond_opt
()
626 # The rest of the arguments will be passed directly to lttng-sessiond.
632 local long_bit_value
=
633 long_bit_value
=$
(getconf LONG_BIT
)
635 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
636 # Env variable requested no session daemon
640 DIR
=$
(readlink
-f "$TESTDIR")
642 # Get long_bit value for 32/64 consumerd
643 case "$long_bit_value" in
645 consumerd
="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
648 consumerd
="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
655 # Check for env. variable. Allow the use of LD_PRELOAD etc.
656 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
657 env_vars
="${LTTNG_SESSIOND_ENV_VARS} "
659 env_vars
="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN"
661 if ! validate_kernel_version
; then
662 fail
"Start session daemon"
663 LTTNG_BAIL_OUT
"*** Kernel too old for session daemon tests ***"
666 : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}"
667 export LTTNG_SESSION_CONFIG_XSD_PATH
669 if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ]; then
671 if [ -n "$load_path" ]; then
672 # shellcheck disable=SC2086
673 env
$env_vars --load "$load_path" --background "$consumerd" "$@"
675 # shellcheck disable=SC2086
676 env
$env_vars --background "$consumerd" "$@"
678 #$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
680 if [ "$withtap" -eq "1" ]; then
681 ok
$status "Start session daemon"
686 function start_lttng_sessiond
()
688 start_lttng_sessiond_opt
1 "$@"
691 function start_lttng_sessiond_notap
()
693 start_lttng_sessiond_opt
0 "$@"
696 function stop_lttng_sessiond_opt
()
707 if [ -z "$signal" ]; then
711 # Multiply time by 2 to simplify integer arithmetic
712 if [ -n "$timeout_s" ]; then
713 dtimeleft_s
=$
((timeout_s
* 2))
716 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
717 # Env variable requested no session daemon
721 runas_pids
=$
(lttng_pgrep
"$RUNAS_MATCH")
722 pids
=$
(lttng_pgrep
"$SESSIOND_MATCH")
724 if [ -n "$runas_pids" ]; then
725 pids
="$pids $runas_pids"
728 if [ -z "$pids" ]; then
729 if [ "$is_cleanup" -eq 1 ]; then
731 elif [ "$withtap" -eq "1" ]; then
732 fail
"No session daemon to kill"
734 LTTNG_BAIL_OUT
"No session daemon to kill"
739 diag
"Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
741 # shellcheck disable=SC2086
742 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
744 if [ "$withtap" -eq "1" ]; then
745 fail
"Kill sessions daemon"
749 while [ -n "$out" ]; do
750 out
=$
(lttng_pgrep
"${SESSIOND_MATCH}")
751 if [ -n "$dtimeleft_s" ]; then
752 if [ $dtimeleft_s -lt 0 ]; then
756 dtimeleft_s
=$
((dtimeleft_s
- 1))
761 while [ -n "$out" ]; do
762 out
=$
(lttng_pgrep
"$CONSUMERD_MATCH")
763 if [ -n "$dtimeleft_s" ]; then
764 if [ $dtimeleft_s -lt 0 ]; then
768 dtimeleft_s
=$
((dtimeleft_s
- 1))
773 if [ "$withtap" -eq "1" ]; then
774 if [ "$retval" -eq "0" ]; then
775 pass
"Wait after kill session daemon"
777 fail
"Wait after kill session daemon"
781 if [ "$signal" = "SIGKILL" ]; then
782 if [ "$(id -u)" -eq "0" ]; then
784 modules
="$(lsmod | grep ^lttng | awk '{print $1}')"
786 if [ -n "$modules" ]; then
787 diag
"Unloading all LTTng modules"
788 modprobe
--remove "$modules"
796 function stop_lttng_sessiond
()
798 stop_lttng_sessiond_opt
1 0 "$@"
801 function stop_lttng_sessiond_notap
()
803 stop_lttng_sessiond_opt
0 0 "$@"
806 function stop_lttng_sessiond_cleanup
()
808 stop_lttng_sessiond_opt
0 1 "$@"
811 function sigstop_lttng_sessiond_opt
()
817 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
818 # Env variable requested no session daemon
822 pids
="$(lttng_pgrep "${SESSIOND_MATCH}") $(lttng_pgrep "$RUNAS_MATCH")"
824 if [ "$withtap" -eq "1" ]; then
825 diag
"Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
828 # shellcheck disable=SC2086
829 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
830 if [ "$withtap" -eq "1" ]; then
831 fail
"Sending SIGSTOP to session daemon"
835 while [ $out -ne 0 ]; do
836 pids
="$(lttng_pgrep "$SESSIOND_MATCH")"
838 # Wait until state becomes stopped for session
841 for sessiond_pid
in $pids; do
842 state
="$(ps -p "$sessiond_pid" -o state= )"
843 if [[ -n "$state" && "$state" != "T" ]]; then
849 if [ "$withtap" -eq "1" ]; then
850 pass
"Sending SIGSTOP to session daemon"
855 function sigstop_lttng_sessiond
()
857 sigstop_lttng_sessiond_opt
1 "$@"
860 function sigstop_lttng_sessiond_notap
()
862 sigstop_lttng_sessiond_opt
0 "$@"
865 function stop_lttng_consumerd_opt
()
875 if [ -z "$signal" ]; then
879 # Multiply time by 2 to simplify integer arithmetic
880 if [ -n "$timeout_s" ]; then
881 dtimeleft_s
=$
((timeout_s
* 2))
884 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
886 if [ -z "$pids" ]; then
887 if [ "$is_cleanup" -eq 1 ]; then
889 elif [ "$withtap" -eq "1" ]; then
890 fail
"No consumerd daemon to kill"
892 LTTNG_BAIL_OUT
"No consumerd daemon to kill"
897 diag
"Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')"
899 # shellcheck disable=SC2086
900 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
902 if [ "$withtap" -eq "1" ]; then
903 fail
"Kill consumer daemon"
907 while [ $out -ne 0 ]; do
908 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
910 # If consumerds are still present check their status.
911 # A zombie status qualifies the consumerd as *killed*
913 for consumer_pid
in $pids; do
914 state
="$(ps -p "$consumer_pid" -o state= )"
915 if [[ -n "$state" && "$state" != "Z" ]]; then
919 if [ -n "$dtimeleft_s" ]; then
920 if [ $dtimeleft_s -lt 0 ]; then
924 dtimeleft_s
=$
((dtimeleft_s
- 1))
928 if [ "$withtap" -eq "1" ]; then
929 if [ "$retval" -eq "0" ]; then
930 pass
"Wait after kill consumer daemon"
932 fail
"Wait after kill consumer daemon"
940 function stop_lttng_consumerd
()
942 stop_lttng_consumerd_opt
1 0 "$@"
945 function stop_lttng_consumerd_notap
()
947 stop_lttng_consumerd_opt
0 0 "$@"
950 function stop_lttng_consumerd_cleanup
()
952 stop_lttng_consumerd_opt
0 1 "$@"
955 function sigstop_lttng_consumerd_opt
()
961 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
963 diag
"Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')"
965 # shellcheck disable=SC2086
966 kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
969 if [ $retval -eq 1 ]; then
970 if [ "$withtap" -eq "1" ]; then
971 fail
"Sending SIGSTOP to consumer daemon"
976 while [ $out -ne 0 ]; do
977 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
979 # Wait until state becomes stopped for all
982 for consumer_pid
in $pids; do
983 state
="$(ps -p "$consumer_pid" -o state= )"
984 if [[ -n "$state" && "$state" != "T" ]]; then
990 if [ "$withtap" -eq "1" ]; then
991 pass
"Sending SIGSTOP to consumer daemon"
997 function sigstop_lttng_consumerd
()
999 sigstop_lttng_consumerd_opt
1 "$@"
1002 function sigstop_lttng_consumerd_notap
()
1004 sigstop_lttng_consumerd_opt
0 "$@"
1007 function list_lttng_with_opts
()
1013 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN list
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1015 if [ $withtap -eq "1" ]; then
1016 ok
$ret "Lttng-tool list command with option $opts"
1020 function list_lttng_ok
()
1022 list_lttng_with_opts
1 "$@"
1025 function list_lttng_notap
()
1027 list_lttng_with_opts
0 "$@"
1030 function create_lttng_session_no_output
()
1035 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name --no-output $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1036 ok $?
"Create session $sess_name in no-output mode"
1039 function create_lttng_session_uri
() {
1044 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -U $uri $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1045 ok $?
"Create session $sess_name with uri:$uri and opts: $opts"
1048 function create_lttng_session
()
1051 local expected_to_fail
=$2
1056 if [ -z "$trace_path" ]; then
1057 # Use lttng-sessiond default output.
1060 trace_path
="-o $trace_path"
1063 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
"$sess_name" $trace_path $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1065 if [ $expected_to_fail -eq "1" ]; then
1068 if [ $withtap -eq "1" ]; then
1069 ok
$ret "Create session $sess_name in $trace_path failed as expected"
1072 if [ $withtap -eq "1" ]; then
1073 ok
$ret "Create session $sess_name in $trace_path"
1079 function create_lttng_session_ok
()
1081 create_lttng_session
1 0 "$@"
1084 function create_lttng_session_fail
()
1086 create_lttng_session
1 1 "$@"
1089 function create_lttng_session_notap
()
1091 create_lttng_session
0 0 "$@"
1095 function enable_ust_lttng_channel
()
1098 local expected_to_fail
=$2
1100 local channel_name
=$4
1103 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-u $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1105 if [[ $expected_to_fail -eq "1" ]]; then
1108 if [ $withtap -eq "1" ]; then
1109 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
1112 if [ $withtap -eq "1" ]; then
1113 ok
$ret "Enable channel $channel_name for session $sess_name"
1119 function enable_ust_lttng_channel_ok
()
1121 enable_ust_lttng_channel
1 0 "$@"
1124 function enable_ust_lttng_channel_fail
()
1126 enable_ust_lttng_channel
1 1 "$@"
1129 function enable_ust_lttng_channel_notap
()
1131 enable_ust_lttng_channel
0 0 "$@"
1134 function disable_ust_lttng_channel
()
1137 local channel_name
=$2
1139 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1140 ok $?
"Disable channel $channel_name for session $sess_name"
1143 function enable_lttng_mmap_overwrite_kernel_channel
()
1146 local channel_name
=$2
1148 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1149 ok $?
"Enable channel $channel_name for session $sess_name"
1152 function enable_lttng_mmap_discard_small_kernel_channel
()
1155 local channel_name
=$2
1157 $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
1158 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1161 function enable_lttng_mmap_overwrite_small_kernel_channel
()
1164 local channel_name
=$2
1166 $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
1167 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1170 function enable_lttng_mmap_overwrite_ust_channel
()
1173 local channel_name
=$2
1175 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1176 ok $?
"Enable channel $channel_name for session $sess_name"
1179 function enable_ust_lttng_event
()
1182 local expected_to_fail
=$2
1184 local event_name
="$4"
1185 local channel_name
=$5
1187 if [ -z $channel_name ]; then
1188 # default channel if none specified
1191 chan
="-c $channel_name"
1194 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1196 if [[ $expected_to_fail -eq "1" ]]; then
1199 if [[ $withtap -eq "1" ]]; then
1200 ok
$ret "Enable ust event $event_name for session $session_name failed as expected"
1203 if [[ $withtap -eq "1" ]]; then
1204 ok
$ret "Enable ust event $event_name for session $sess_name"
1210 function enable_ust_lttng_event_ok
()
1212 enable_ust_lttng_event
1 0 "$@"
1215 function enable_ust_lttng_event_fail
()
1217 enable_ust_lttng_event
1 1 "$@"
1220 function enable_ust_lttng_event_notap
()
1222 enable_ust_lttng_event
0 0 "$@"
1225 function enable_jul_lttng_event
()
1231 if [ -z $channel_name ]; then
1232 # default channel if none specified
1235 chan
="-c $channel_name"
1238 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1239 ok $?
"Enable JUL event $event_name for session $sess_name"
1242 function enable_jul_lttng_event_loglevel
()
1245 local event_name
="$2"
1247 local channel_name
=$4
1249 if [ -z $channel_name ]; then
1250 # default channel if none specified
1253 chan
="-c $channel_name"
1256 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1257 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
1260 function enable_log4j_lttng_event
()
1266 if [ -z $channel_name ]; then
1267 # default channel if none specified
1270 chan
="-c $channel_name"
1273 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1274 ok $?
"Enable LOG4J event $event_name for session $sess_name"
1277 function enable_log4j_lttng_event_loglevel
()
1280 local event_name
="$2"
1282 local channel_name
=$4
1284 if [ -z $channel_name ]; then
1285 # default channel if none specified
1288 chan
="-c $channel_name"
1291 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1292 ok $?
"Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
1295 function enable_python_lttng_event
()
1301 if [ -z $channel_name ]; then
1302 # default channel if none specified
1305 chan
="-c $channel_name"
1308 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1309 ok $?
"Enable Python event $event_name for session $sess_name"
1312 function enable_python_lttng_event_loglevel
()
1315 local event_name
="$2"
1317 local channel_name
=$4
1319 if [ -z $channel_name ]; then
1320 # default channel if none specified
1323 chan
="-c $channel_name"
1326 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1327 ok $?
"Enable Python event $event_name for session $sess_name with loglevel $loglevel"
1330 function enable_ust_lttng_event_filter
()
1332 local sess_name
="$1"
1333 local event_name
="$2"
1335 local channel_name
=$4
1337 if [ -z $channel_name ]; then
1338 # default channel if none specified
1341 chan
="-c $channel_name"
1344 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
$chan "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1345 ok $?
"Enable event $event_name with filtering for session $sess_name"
1348 function enable_ust_lttng_event_loglevel
()
1350 local sess_name
="$1"
1351 local event_name
="$2"
1354 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1355 ok $?
"Enable event $event_name with loglevel $loglevel"
1358 function enable_ust_lttng_event_loglevel_only
()
1360 local sess_name
="$1"
1361 local event_name
="$2"
1364 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1365 ok $?
"Enable event $event_name with loglevel-only $loglevel"
1368 function disable_ust_lttng_event
()
1370 local sess_name
="$1"
1371 local event_name
="$2"
1372 local channel_name
="$3"
1374 if [ -z $channel_name ]; then
1375 # default channel if none specified
1378 chan
="-c $channel_name"
1381 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1382 ok $?
"Disable event $event_name for session $sess_name"
1385 function disable_jul_lttng_event
()
1387 local sess_name
="$1"
1388 local event_name
="$2"
1390 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
1391 ok $?
"Disable JUL event $event_name for session $sess_name"
1394 function disable_log4j_lttng_event
()
1396 local sess_name
="$1"
1397 local event_name
="$2"
1399 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -l >/dev
/null
2>&1
1400 ok $?
"Disable LOG4J event $event_name for session $sess_name"
1403 function disable_python_lttng_event
()
1405 local sess_name
="$1"
1406 local event_name
="$2"
1408 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1409 ok $?
"Disable Python event $event_name for session $sess_name"
1412 function start_lttng_tracing_opt
()
1415 local expected_to_fail
=$2
1418 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1420 if [[ $expected_to_fail -eq "1" ]]; then
1423 if [ $withtap -eq "1" ]; then
1424 ok $?
"Start tracing for session $sess_name failed as expected"
1427 if [ $withtap -eq "1" ]; then
1428 ok
$ret "Start tracing for session $sess_name"
1433 function start_lttng_tracing_ok
()
1435 start_lttng_tracing_opt
1 0 "$@"
1438 function start_lttng_tracing_fail
()
1440 start_lttng_tracing_opt
1 1 "$@"
1443 function start_lttng_tracing_notap
()
1445 start_lttng_tracing_opt
0 1 "$@"
1448 function stop_lttng_tracing_opt
()
1451 local expected_to_fail
=$2
1454 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1456 if [[ $expected_to_fail -eq "1" ]]; then
1459 if [ $withtap -eq "1" ]; then
1460 ok $?
"Stop lttng tracing for session $sess_name failed as expected"
1463 if [ $withtap -eq "1" ]; then
1464 ok
$ret "Stop lttng tracing for session $sess_name"
1469 function stop_lttng_tracing_ok
()
1471 stop_lttng_tracing_opt
1 0 "$@"
1474 function stop_lttng_tracing_fail
()
1476 stop_lttng_tracing_opt
1 1 "$@"
1479 function stop_lttng_tracing_notap
()
1481 stop_lttng_tracing_opt
0 0 "$@"
1484 function destroy_lttng_session
()
1487 local expected_to_fail
=$2
1490 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1492 if [[ $expected_to_fail -eq "1" ]]; then
1495 if [ $withtap -eq "1" ]; then
1496 ok
$ret "Destroy session $sess_name failed as expected"
1499 if [ $withtap -eq "1" ]; then
1500 ok
$ret "Destroy session $sess_name"
1505 function destroy_lttng_session_ok
()
1507 destroy_lttng_session
1 0 "$@"
1511 function destroy_lttng_session_fail
()
1513 destroy_lttng_session
1 1 "$@"
1516 function destroy_lttng_session_notap
()
1518 destroy_lttng_session
0 0 "$@"
1521 function destroy_lttng_sessions
()
1523 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
--all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1524 ok $?
"Destroy all lttng sessions"
1527 function lttng_snapshot_add_output
()
1529 local expected_to_fail
=$1
1534 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name $trace_path $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1536 if [[ $expected_to_fail -eq 1 ]]; then
1538 ok $?
"Added snapshot output $trace_path failed as expected"
1540 ok
$ret "Added snapshot output $trace_path"
1544 function lttng_snapshot_add_output_ok
()
1546 lttng_snapshot_add_output
0 "$@"
1549 function lttng_snapshot_add_output_fail
()
1551 lttng_snapshot_add_output
1 "$@"
1554 function lttng_snapshot_del_output
()
1556 local expected_to_fail
=$1
1560 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output
-s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1562 if [[ $expected_to_fail -eq "1" ]]; then
1564 ok $?
"Deleted snapshot output id $id failed as expected"
1566 ok
$ret "Deleted snapshot output id $id"
1570 function lttng_snapshot_del_output_ok
()
1572 lttng_snapshot_del_output
0 "$@"
1575 function lttng_snapshot_del_output_fail
()
1577 lttng_snapshot_del_output
1 "$@"
1580 function lttng_snapshot_record
()
1585 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot record
-s "$sess_name" "$trace_path" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1586 ok $?
"Snapshot recorded"
1589 function lttng_snapshot_list
()
1592 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1593 ok $?
"Snapshot list"
1596 function lttng_save
()
1601 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN save
$sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1602 ok $?
"Session saved"
1605 function lttng_load
()
1607 local expected_to_fail
=$1
1610 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN load
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1612 if [[ $expected_to_fail -eq "1" ]]; then
1614 ok $?
"Load command failed as expected with opts: $opts"
1616 ok
$ret "Load command with opts: $opts"
1620 function lttng_load_ok
()
1625 function lttng_load_fail
()
1630 function lttng_track
()
1632 local expected_to_fail
="$1"
1635 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN track
$opts >$OUTPUT_DEST
1637 if [[ $expected_to_fail -eq "1" ]]; then
1639 ok $?
"Track command failed as expected with opts: $opts"
1641 ok
$ret "Track command with opts: $opts"
1645 function lttng_track_ok
()
1650 function lttng_track_fail
()
1655 function lttng_untrack
()
1657 local expected_to_fail
="$1"
1660 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN untrack
$opts >$OUTPUT_DEST
1662 if [[ $expected_to_fail -eq "1" ]]; then
1664 ok $?
"Untrack command failed as expected with opts: $opts"
1666 ok
$ret "Untrack command with opts: $opts"
1670 function lttng_untrack_ok
()
1672 lttng_untrack
0 "$@"
1675 function lttng_untrack_fail
()
1677 lttng_untrack
1 "$@"
1680 function lttng_track_pid_ok
()
1683 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track
--kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1684 ok $?
"Lttng track pid on the kernel domain"
1687 function lttng_untrack_kernel_all_ok
()
1689 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack
--kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1690 ok $?
"Lttng untrack all pid on the kernel domain"
1693 function lttng_track_ust_ok
()
1695 lttng_track_ok
-u "$@"
1698 function lttng_track_ust_fail
()
1700 lttng_track_fail
-u "$@"
1703 function lttng_track_kernel_ok
()
1705 lttng_track_ok
-k "$@"
1708 function lttng_track_kernel_fail
()
1710 lttng_track_fail
-k "$@"
1713 function lttng_untrack_ust_ok
()
1715 lttng_untrack_ok
-u "$@"
1718 function lttng_untrack_ust_fail
()
1720 lttng_untrack_fail
-u "$@"
1723 function lttng_untrack_kernel_ok
()
1725 lttng_untrack_ok
-k "$@"
1728 function lttng_untrack_kernel_fail
()
1730 lttng_untrack_fail
-k "$@"
1733 function lttng_add_context_list
()
1735 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context
--list 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1737 ok
$ret "Context listing"
1740 function add_context_lttng
()
1742 local expected_to_fail
="$1"
1744 local session_name
="$3"
1745 local channel_name
="$4"
1748 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context
-s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1750 if [[ $expected_to_fail -eq "1" ]]; then
1752 ok $?
"Add context command failed as expected for type: $type"
1754 ok
$ret "Add context command for type: $type"
1758 function add_context_ust_ok
()
1760 add_context_lttng
0 -u "$@"
1763 function add_context_ust_fail
()
1765 add_context_lttng
1 -u "$@"
1768 function add_context_kernel_ok
()
1770 add_context_lttng
0 -k "$@"
1773 function add_context_kernel_fail
()
1775 add_context_lttng
1 -k "$@"
1778 function wait_live_trace_ready
()
1781 local zero_client_match
=0
1783 diag
"Waiting for live trace at url: $url"
1784 while [ $zero_client_match -eq 0 ]; do
1785 zero_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "0 client(s) connected" |
wc -l)
1788 pass
"Waiting for live trace at url: $url"
1791 function wait_live_viewer_connect
()
1794 local one_client_match
=0
1796 diag
"Waiting for live viewers on url: $url"
1797 while [ $one_client_match -eq 0 ]; do
1798 one_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "1 client(s) connected" |
wc -l)
1801 pass
"Waiting for live viewers on url: $url"
1804 function validate_metadata_event
()
1807 local nr_event_id
=$2
1810 local metadata_file
=$
(find $trace_path -name "metadata")
1811 local metadata_path
=$
(dirname $metadata_file)
1813 which $BABELTRACE_BIN >/dev
/null
1814 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1816 local count
=$
($BABELTRACE_BIN --output-format=ctf-metadata
$metadata_path |
grep $event_name |
wc -l)
1818 if [ "$count" -ne "$nr_event_id" ]; then
1819 fail
"Metadata match with the metadata of $count event(s) named $event_name"
1820 diag
"$count matching event id found in metadata"
1822 pass
"Metadata match with the metadata of $count event(s) named $event_name"
1827 function trace_matches
()
1833 which $BABELTRACE_BIN >/dev
/null
1834 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1836 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1838 if [ "$count" -ne "$nr_iter" ]; then
1840 diag
"$count matching events found in trace"
1846 function trace_match_only
()
1852 which $BABELTRACE_BIN >/dev
/null
1853 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1855 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1856 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1858 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1859 pass
"Trace match with $total event $event_name"
1862 diag
"$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1866 function validate_trace
1871 which $BABELTRACE_BIN >/dev
/null
1872 if [ $?
-ne 0 ]; then
1873 skip
0 "Babeltrace binary not found. Skipping trace validation"
1878 for i
in $event_name; do
1879 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1880 if [ "$traced" -ne 0 ]; then
1881 pass
"Validate trace for event $i, $traced events"
1883 fail
"Validate trace for event $i"
1884 diag
"Found $traced occurrences of $i"
1892 function validate_trace_count
1896 local expected_count
=$3
1898 which $BABELTRACE_BIN >/dev
/null
1899 if [ $?
-ne 0 ]; then
1900 skip
0 "Babeltrace binary not found. Skipping trace validation"
1906 for i
in $event_name; do
1907 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1908 if [ "$traced" -ne 0 ]; then
1909 pass
"Validate trace for event $i, $traced events"
1911 fail
"Validate trace for event $i"
1912 diag
"Found $traced occurrences of $i"
1914 cnt
=$
(($cnt + $traced))
1917 test $cnt -eq $expected_count
1918 ok $?
"Read a total of $cnt events, expected $expected_count"
1921 function validate_trace_count_range_incl_min_excl_max
1925 local expected_min
=$3
1926 local expected_max
=$4
1928 which $BABELTRACE_BIN >/dev
/null
1929 if [ $?
-ne 0 ]; then
1930 skip
0 "Babeltrace binary not found. Skipping trace validation"
1936 for i
in $event_name; do
1937 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1938 if [ "$traced" -ge $expected_min ]; then
1939 pass
"Validate trace for event $i, $traced events"
1941 fail
"Validate trace for event $i"
1942 diag
"Found $traced occurrences of $i"
1944 cnt
=$
(($cnt + $traced))
1947 test $cnt -lt $expected_max
1948 ok $?
"Read a total of $cnt events, expected between [$expected_min, $expected_max["
1951 function trace_first_line
1955 which $BABELTRACE_BIN >/dev
/null
1956 if [ $?
-ne 0 ]; then
1957 skip
0 "Babeltrace binary not found. Skipping trace validation"
1960 $BABELTRACE_BIN $trace_path 2>/dev
/null |
head -n 1
1963 function validate_trace_exp
()
1968 which $BABELTRACE_BIN >/dev
/null
1969 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace validation"
1971 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep --extended-regexp ${event_exp} |
wc -l)
1972 if [ "$traced" -ne 0 ]; then
1973 pass
"Validate trace for expression '${event_exp}', $traced events"
1975 fail
"Validate trace for expression '${event_exp}'"
1976 diag
"Found $traced occurrences of '${event_exp}'"
1982 function validate_trace_only_exp
()
1987 which $BABELTRACE_BIN >/dev
/null
1988 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1990 local count
=$
($BABELTRACE_BIN $trace_path |
grep --extended-regexp ${event_exp} |
wc -l)
1991 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1993 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1994 pass
"Trace match with $total for expression '${event_exp}'"
1997 diag
"$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
2003 function validate_trace_empty
()
2007 which $BABELTRACE_BIN >/dev
/null
2008 if [ $?
-ne 0 ]; then
2009 skip
0 "Babeltrace binary not found. Skipping trace validation"
2012 events
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null
)
2014 if [ $ret -ne 0 ]; then
2015 fail
"Failed to parse trace"
2019 traced
=$
(echo -n "$events" |
wc -l)
2020 if [ "$traced" -eq 0 ]; then
2021 pass
"Validate empty trace"
2023 fail
"Validate empty trace"
2024 diag
"Found $traced events in trace"
2030 function validate_directory_empty
()
2032 local trace_path
="$1"
2034 # Do not double quote `$trace_path` below as we want wildcards to be
2036 files
="$(ls -A $trace_path)"
2038 if [ $ret -ne 0 ]; then
2039 fail
"Failed to list content of directory \"$trace_path\""
2043 nb_files
="$(echo -n "$files" | wc -l)"
2044 ok
$nb_files "Directory \"$trace_path\" is empty"
2047 function validate_trace_session_ust_empty
()
2049 validate_directory_empty
"$1"/ust
2052 function validate_trace_session_kernel_empty
()
2054 validate_trace_empty
"$1"/kernel
2057 function regenerate_metadata
()
2059 local expected_to_fail
=$1
2062 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN regenerate metadata
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2064 if [[ $expected_to_fail -eq "1" ]]; then
2066 ok $?
"Expected fail on regenerate metadata $sess_name"
2068 ok
$ret "Metadata regenerate $sess_name"
2072 function regenerate_metadata_ok
()
2074 regenerate_metadata
0 "$@"
2077 function regenerate_metadata_fail
()
2079 regenerate_metadata
1 "$@"
2082 function regenerate_statedump
()
2084 local expected_to_fail
=$1
2087 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN regenerate statedump
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2089 if [[ $expected_to_fail -eq "1" ]]; then
2091 ok $?
"Expected fail on regenerate statedump $sess_name"
2093 ok
$ret "Statedump regenerate $sess_name"
2097 function regenerate_statedump_ok
()
2099 regenerate_statedump
0 "$@"
2102 function regenerate_statedump_fail
()
2104 regenerate_statedump
1 "$@"
2107 function rotate_session
()
2109 local expected_to_fail
=$1
2112 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN rotate
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2114 if [[ $expected_to_fail -eq "1" ]]; then
2116 ok $?
"Expected fail on rotate session $sess_name"
2118 ok
$ret "Rotate session $sess_name"
2122 function rotate_session_ok
()
2124 rotate_session
0 "$@"
2127 function rotate_session_fail
()
2129 rotate_session
1 "$@"
2132 function destructive_tests_enabled
()
2134 if [ "$LTTNG_ENABLE_DESTRUCTIVE_TESTS" = "will-break-my-system" ]; then
2141 function lttng_enable_rotation_timer
()
2143 local expected_to_fail
=$1
2147 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-rotation
-s $sess_name --timer $period 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2149 if [[ $expected_to_fail -eq "1" ]]; then
2151 ok $?
"Expected fail when setting periodic rotation ($period) of session $sess_name"
2153 ok
$ret "Set periodic rotation ($period) of session $sess_name"
2157 function lttng_enable_rotation_timer_ok
()
2159 lttng_enable_rotation_timer
0 $@
2162 function lttng_enable_rotation_timer_fail
()
2164 lttng_enable_rotation_timer
1 $@
2167 function lttng_enable_rotation_size
()
2169 local expected_to_fail
=$1
2173 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-rotation
-s $sess_name --size $size 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2175 if [[ $expected_to_fail -eq "1" ]]; then
2177 ok $?
"Expected fail on rotate session $sess_name"
2179 ok
$ret "Rotate session $sess_name"
2183 function lttng_enable_rotation_size_ok
()
2185 lttng_enable_rotation_size
0 $@
2188 function lttng_enable_rotation_size_fail
()
2190 lttng_enable_rotation_size
1 $@
2193 function lttng_clear_session
()
2195 local expected_to_fail
=$1
2198 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN clear $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2200 if [[ $expected_to_fail -eq "1" ]]; then
2202 ok $?
"Expected fail on clear session $sess_name"
2204 ok
$ret "Clear session $sess_name"
2208 function lttng_clear_session_ok
()
2210 lttng_clear_session
0 $@
2213 function lttng_clear_session_fail
()
2215 lttng_clear_session
1 $@
2218 function lttng_clear_all
()
2220 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN clear --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2221 ok $?
"Clear all lttng sessions"
2224 function lttng_add_trigger
()
2226 local expected_to_fail
="$1"
2227 local trigger_name
="$2"
2231 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN add-trigger --name $trigger_name ${args[*]}"
2232 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-trigger
--name "$trigger_name" "${args[@]}" 1> /dev
/null
2> /dev
/null
2234 if [[ $expected_to_fail -eq "1" ]]; then
2236 ok $?
"Add trigger $trigger_name failed as expected"
2238 ok
$ret "Add trigger $trigger_name"
2242 function lttng_remove_trigger
()
2244 local expected_to_fail
="$1"
2245 local trigger_name
="$2"
2248 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN remove-trigger $trigger_name $*"
2249 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" remove-trigger
"$trigger_name" "$@" 1> /dev
/null
2> /dev
/null
2251 if [[ $expected_to_fail -eq "1" ]]; then
2253 ok $?
"Remove trigger $trigger_name failed as expected"
2255 ok
$ret "Remove trigger $trigger_name"
2259 function lttng_add_trigger_ok
()
2261 lttng_add_trigger
0 "$@"
2264 function lttng_add_trigger_fail
()
2266 lttng_add_trigger
1 "$@"
2269 function lttng_remove_trigger_ok
()
2271 lttng_remove_trigger
0 "$@"
2274 function list_triggers_matches_ok
()
2276 local tmp_stdout
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2277 local tmp_stderr
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stderr.XXXXXX")
2279 local test_name
="$1"
2280 local expected_stdout_file
="$2"
2282 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN list-triggers"
2284 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" list-triggers
> "${tmp_stdout}" 2> "${tmp_stderr}"
2285 ok $?
"${test_name}: exit code is 0"
2287 diff -u "${expected_stdout_file}" "${tmp_stdout}"
2288 ok $?
"${test_name}: expected stdout"
2290 diff -u /dev
/null
"${tmp_stderr}"
2291 ok $?
"${test_name}: expected stderr"
2293 rm -f "${tmp_stdout}"
2294 rm -f "${tmp_stderr}"
2297 function list_triggers_matches_mi_ok
()
2300 local tmp_stdout_raw
2303 local test_name
="$1"
2304 local expected_stdout_file
="$2"
2306 tmp_stdout_raw
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2307 tmp_stdout
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2308 tmp_stderr
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stderr.XXXXXX")
2310 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi xml list-triggers"
2312 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" --mi=xml list-triggers
> "${tmp_stdout_raw}" 2> "${tmp_stderr}"
2313 ok $?
"${test_name}: exit code is 0"
2315 # Pretty-fy xml before further test.
2316 $XML_PRETTY < "${tmp_stdout_raw}" > "${tmp_stdout}"
2318 $MI_VALIDATE "${tmp_stdout}"
2319 ok $?
"list-trigger mi is valid"
2321 diff -u "${expected_stdout_file}" "${tmp_stdout}"
2322 ok $?
"${test_name}: expected stdout"
2324 diff -u /dev
/null
"${tmp_stderr}"
2325 ok $?
"${test_name}: expected stderr"
2327 rm -f "${tmp_stdout}"
2328 rm -f "${tmp_stdout_raw}"
2329 rm -f "${tmp_stderr}"
2332 function validate_path_pattern
()
2336 # Base path is only used in error case and is used to list the content
2345 if [ "$ret" -ne "0" ]; then
2346 diag
"Path pattern expected: $pattern"
2347 # List the tracepath for more info. We use find as a recursive
2349 diag
"The base path content:"
2350 find "$base_path" -print
2354 function validate_trace_path_ust_uid
()
2357 local session_name
=$2
2359 local pattern
="$trace_path/$session_name-$date_time_pattern/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2361 validate_path_pattern
"UST per-uid trace path is valid" "$pattern" "$trace_path"
2364 function validate_trace_path_ust_uid_network
()
2367 local session_name
=$2
2370 local hostname
=$HOSTNAME
2374 # If the session was given a network base path (e.g
2375 # 127.0.0.1/my/custom/path on creation, there is no session name
2376 # component to the path on the relayd side. Caller can simply not pass a
2377 # session name for this scenario.
2378 if [ -n "$session_name" ]; then
2379 session_name
="$session_name-$date_time_pattern"
2380 if [ -n "$base_path" ]; then
2381 fail
"Session name and base path are mutually exclusive"
2386 pattern
="$trace_path/$hostname/$base_path/$session_name/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2388 validate_path_pattern
"UST per-uid network trace path is valid" "$pattern" "$trace_path"
2391 function validate_trace_path_ust_uid_snapshot_network
()
2394 local session_name
=$2
2395 local snapshot_name
=$3
2396 local snapshot_number
=$4
2398 local hostname
=$HOSTNAME
2403 # If the session/output was given a network base path (e.g
2404 # 127.0.0.1/my/custom/path on creation, there is no session name
2405 # component to the path on the relayd side. Caller can simply not pass a
2406 # session name for this scenario.
2407 if [ -n "$session_name" ]; then
2408 session_name
="$session_name-$date_time_pattern"
2409 if [ -n "$base_path" ]; then
2410 fail
"Session name and base path are mutually exclusive"
2415 pattern
="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2417 validate_path_pattern
"UST per-uid network snapshot trace path is valid" "$pattern" "$trace_path"
2420 function validate_trace_path_ust_uid_snapshot
()
2423 local session_name
=$2
2424 local snapshot_name
=$3
2425 local snapshot_number
=$4
2431 # If the session/output was given a network base path (e.g
2432 # 127.0.0.1/my/custom/path) on creation, there is no session name
2433 # component to the path on the relayd side. Caller can simply not pass a
2434 # session name for this scenario.
2435 if [ -n "$session_name" ]; then
2436 session_name
="$session_name-$date_time_pattern"
2437 if [ -n "$base_path" ]; then
2438 fail
"Session name and base path are mutually exclusive"
2443 pattern
="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2445 validate_path_pattern
"UST per-uid snapshot trace path is valid" "$pattern" "$trace_path"
2448 function validate_trace_path_ust_pid
()
2451 local session_name
=$2
2457 # If the session was given a trace path on creation, there is no session
2458 # name component to the path. Caller can simply not pass a session name
2459 # for this scenario.
2460 if [ -n "$session_name" ]; then
2461 session_name
="$session_name-$date_time_pattern"
2464 pattern
="$trace_path/$session_name/ust/pid/$pid/$app_string-*-$date_time_pattern/metadata"
2466 validate_path_pattern
"UST per-pid trace path is valid" "$pattern" "$trace_path"
2469 function validate_trace_path_kernel
()
2472 local session_name
=$2
2475 # If the session was given a trace path on creation, there is no session
2476 # name component to the path. Caller can simply not pass a session name
2477 # for this scenario.
2478 if [ -n "$session_name" ]; then
2479 session_name
="$session_name-$date_time_pattern"
2482 pattern
="$trace_path/$session_name/kernel/metadata"
2484 validate_path_pattern
"Kernel trace path is valid" "$pattern" "$trace_path"
2487 function validate_trace_path_kernel_network
()
2490 local session_name
=$2
2491 local hostname
=$HOSTNAME
2492 local pattern
="$trace_path/$hostname/$session_name-$date_time_pattern/kernel/metadata"
2494 validate_path_pattern
"Kernel network trace path is valid" "$pattern" "$trace_path"
2497 function validate_trace_path_kernel_snapshot
()
2500 local session_name
=$2
2501 local snapshot_name
=$3
2502 local snapshot_number
=$4
2507 # If the session/output was given a network base path (e.g
2508 # 127.0.0.1/my/custom/path on creation, there is no session name
2509 # component to the path on the relayd side. Caller can simply not pass a
2510 # session name for this scenario.
2511 if [ -n "$session_name" ]; then
2512 session_name
="$session_name-$date_time_pattern"
2513 if [ -n "$base_path" ]; then
2514 fail
"Session name and base path are mutually exclusive"
2519 pattern
="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata"
2521 validate_path_pattern
"Kernel snapshot trace path is valid" "$pattern" "$trace_path"
2524 function validate_trace_path_kernel_snapshot_network
()
2527 local session_name
=$2
2528 local snapshot_name
=$3
2529 local snapshot_number
=$4
2531 local hostname
=$HOSTNAME
2535 # If the session/output was given a network base path (e.g
2536 # 127.0.0.1/my/custom/path on creation, there is no session name
2537 # component to the path on the relayd side. Caller can simply not pass a
2538 # session name for this scenario.
2539 if [ -n "$session_name" ]; then
2540 session_name
="$session_name-$date_time_pattern"
2541 if [ -n "$base_path" ]; then
2542 fail
"Session name and base path are mutually exclusive"
2547 pattern
="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata"
2549 validate_path_pattern
"Kernel network snapshot trace path is valid" "$pattern" "$trace_path"