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
="babeltrace2"
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 # Run the lttng binary.
243 # The first two arguments are stdout and stderr redirect paths, respectively.
244 # The rest of the arguments are forwarded to the lttng binary
245 function _run_lttng_cmd
247 local stdout_dest
="$1"
248 local stderr_dest
="$2"
251 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN $*"
252 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN "$@" 1> "$stdout_dest" 2> "$stderr_dest"
255 function enable_kernel_lttng_event
258 local expected_to_fail
="$2"
260 local event_name
="$4"
261 local channel_name
="$5"
263 if [ -z "$event_name" ]; then
264 # Enable all event if no event name specified
268 if [ -z "$channel_name" ]; then
269 # default channel if none specified
272 chan
="-c $channel_name"
275 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
276 enable-event
"$event_name" $chan -s $sess_name -k
278 if [[ $expected_to_fail -eq "1" ]]; then
281 if [ $withtap -eq "1" ]; then
282 ok
$ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
285 if [ $withtap -eq "1" ]; then
286 ok
$ret "Enable kernel event $event_name for session $sess_name"
291 function enable_kernel_lttng_event_ok
()
293 enable_kernel_lttng_event
1 0 "$@"
296 function enable_kernel_lttng_event_fail
()
298 enable_kernel_lttng_event
1 1 "$@"
301 function enable_kernel_lttng_event_notap
()
303 enable_kernel_lttng_event
0 0 "$@"
307 function lttng_enable_kernel_event
309 enable_kernel_lttng_event_ok
"$@"
312 function lttng_enable_kernel_syscall
()
314 local expected_to_fail
=$1
316 local syscall_name
=$3
317 local channel_name
=$4
319 if [ -z $syscall_name ]; then
320 # Enable all event if no syscall name specified
324 if [ -z $channel_name ]; then
325 # default channel if none specified
328 chan
="-c $channel_name"
331 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
332 enable-event
--syscall "$syscall_name" $chan -s $sess_name -k
334 if [[ $expected_to_fail -eq "1" ]]; then
336 ok $?
"Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
338 ok
$ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
342 function lttng_enable_kernel_syscall_ok
()
344 lttng_enable_kernel_syscall
0 "$@"
347 function lttng_enable_kernel_syscall_fail
()
349 lttng_enable_kernel_syscall
1 "$@"
352 function lttng_disable_kernel_syscall
()
354 local expected_to_fail
=$1
356 local syscall_name
=$3
357 local channel_name
=$4
359 if [ -z $syscall_name ]; then
360 # Enable all event if no syscall name specified
364 if [ -z $channel_name ]; then
365 # default channel if none specified
368 chan
="-c $channel_name"
371 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
372 disable-event
--syscall "$syscall_name" $chan -s $sess_name -k
375 if [[ $expected_to_fail -eq "1" ]]; then
377 ok $?
"Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
379 ok
$ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
383 function lttng_disable_kernel_syscall_ok
()
385 lttng_disable_kernel_syscall
0 "$@"
388 function lttng_disable_kernel_syscall_fail
()
390 lttng_disable_kernel_syscall
1 "$@"
393 function lttng_enable_kernel_function_event
()
395 local expected_to_fail
="$1"
398 local event_name
="$4"
400 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
--kernel --function="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
402 if [[ $expected_to_fail -eq "1" ]]; then
404 ok $?
"Enable kernel function event for session $sess_name failed as expected"
406 ok
$ret "Enable kernel function event for session $sess_name"
410 function lttng_enable_kernel_function_event_ok
()
412 lttng_enable_kernel_function_event
0 "$@"
415 function lttng_enable_kernel_userspace_probe_event
()
417 local expected_to_fail
="$1"
420 local event_name
="$4"
422 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
--kernel --userspace-probe="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
424 if [[ $expected_to_fail -eq "1" ]]; then
426 ok $?
"Enable kernel userspace probe event for session $sess_name failed as expected"
428 ok
$ret "Enable kernel userspace probe event for session $sess_name"
432 function lttng_enable_kernel_userspace_probe_event_fail
()
434 lttng_enable_kernel_userspace_probe_event
1 "$@"
437 function lttng_enable_kernel_userspace_probe_event_ok
()
439 lttng_enable_kernel_userspace_probe_event
0 "$@"
442 function disable_kernel_lttng_userspace_probe_event_ok
()
445 local event_name
="$2"
447 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" disable-event
--kernel "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
448 ok $?
"Disable kernel event $target for session $sess_name"
450 function lttng_enable_kernel_channel
()
453 local expected_to_fail
=$2
455 local channel_name
=$4
458 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
459 enable-channel
-k $channel_name -s $sess_name $opts
461 if [[ $expected_to_fail -eq "1" ]]; then
464 if [ $withtap -eq "1" ]; then
465 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
468 if [ $withtap -eq "1" ]; then
469 ok
$ret "Enable channel $channel_name for session $sess_name"
474 function lttng_enable_kernel_channel_ok
()
476 lttng_enable_kernel_channel
1 0 "$@"
479 function lttng_enable_kernel_channel_fail
()
481 lttng_enable_kernel_channel
1 1 "$@"
484 function lttng_enable_kernel_channel_notap
()
486 lttng_enable_kernel_channel
0 0 "$@"
489 function enable_kernel_lttng_channel_ok
()
491 lttng_enable_kernel_channel
1 0 "$@"
494 function lttng_disable_kernel_channel
()
496 local expected_to_fail
=$1
498 local channel_name
=$3
500 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
501 disable-channel
-k $channel_name -s $sess_name
503 if [[ $expected_to_fail -eq "1" ]]; then
505 ok $?
"Disable channel $channel_name for session $sess_name failed as expected"
507 ok
$ret "Disable channel $channel_name for session $sess_name"
511 function lttng_disable_kernel_channel_ok
()
513 lttng_disable_kernel_channel
0 "$@"
516 function lttng_disable_kernel_channel_fail
()
518 lttng_disable_kernel_channel
1 "$@"
521 function start_lttng_relayd_opt
()
524 local process_mode
=$2
527 DIR
=$
(readlink
-f "$TESTDIR")
529 if [ -z $
(lttng_pgrep
"$RELAYD_MATCH") ]; then
530 # shellcheck disable=SC2086
531 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
532 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
533 if [ $?
-eq 1 ]; then
534 if [ $withtap -eq "1" ]; then
535 fail
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
539 if [ $withtap -eq "1" ]; then
540 pass
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
544 pass
"Start lttng-relayd (opt: $opt)"
548 function start_lttng_relayd
()
550 start_lttng_relayd_opt
1 "-b" "$@"
553 function start_lttng_relayd_notap
()
555 start_lttng_relayd_opt
0 "-b" "$@"
558 function stop_lttng_relayd_opt
()
568 if [ -z "$signal" ]; then
573 # Multiply time by 2 to simplify integer arithmetic
574 if [ -n "$timeout_s" ]; then
575 dtimeleft_s
=$
((timeout_s
* 2))
579 pids
=$
(lttng_pgrep
"$RELAYD_MATCH")
580 if [ -z "$pids" ]; then
581 if [ "$is_cleanup" -eq 1 ]; then
583 elif [ "$withtap" -eq "1" ]; then
584 fail
"No relay daemon to kill"
586 LTTNG_BAIL_OUT
"No relay daemon to kill"
591 diag
"Killing (signal $signal) lttng-relayd (pid: $pids)"
593 # shellcheck disable=SC2086
594 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
596 if [ "$withtap" -eq "1" ]; then
597 fail
"Kill relay daemon"
601 while [ -n "$out" ]; do
602 out
=$
(lttng_pgrep
"$RELAYD_MATCH")
603 if [ -n "$dtimeleft_s" ]; then
604 if [ $dtimeleft_s -lt 0 ]; then
608 dtimeleft_s
=$
((dtimeleft_s
- 1))
612 if [ "$withtap" -eq "1" ]; then
613 if [ "$retval" -eq "0" ]; then
614 pass
"Wait after kill relay daemon"
616 fail
"Wait after kill relay daemon"
623 function stop_lttng_relayd
()
625 stop_lttng_relayd_opt
1 0 "$@"
628 function stop_lttng_relayd_notap
()
630 stop_lttng_relayd_opt
0 0 "$@"
633 function stop_lttng_relayd_cleanup
()
635 stop_lttng_relayd_opt
0 1 "$@"
638 #First arg: show tap output
639 #Second argument: load path for automatic loading
640 function start_lttng_sessiond_opt
()
645 # The rest of the arguments will be passed directly to lttng-sessiond.
651 local long_bit_value
=
652 long_bit_value
=$
(getconf LONG_BIT
)
654 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
655 # Env variable requested no session daemon
659 DIR
=$
(readlink
-f "$TESTDIR")
661 # Get long_bit value for 32/64 consumerd
662 case "$long_bit_value" in
664 consumerd
="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
667 consumerd
="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
674 # Check for env. variable. Allow the use of LD_PRELOAD etc.
675 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
676 env_vars
="${LTTNG_SESSIOND_ENV_VARS} "
678 env_vars
="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN"
680 if ! validate_kernel_version
; then
681 fail
"Start session daemon"
682 LTTNG_BAIL_OUT
"*** Kernel too old for session daemon tests ***"
685 diag
"export LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/"
686 : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/"}"
687 export LTTNG_SESSION_CONFIG_XSD_PATH
689 if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ]; then
691 if [ -n "$load_path" ]; then
692 diag
"env $env_vars --load $load_path --background $consumerd $@"
693 # shellcheck disable=SC2086
694 env
$env_vars --load "$load_path" --background "$consumerd" "$@"
696 diag
"env $env_vars --background $consumerd $@"
697 # shellcheck disable=SC2086
698 env
$env_vars --background "$consumerd" "$@"
700 #$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
702 if [ "$withtap" -eq "1" ]; then
703 ok
$status "Start session daemon"
708 function start_lttng_sessiond
()
710 start_lttng_sessiond_opt
1 "$@"
713 function start_lttng_sessiond_notap
()
715 start_lttng_sessiond_opt
0 "$@"
718 function stop_lttng_sessiond_opt
()
729 if [ -z "$signal" ]; then
733 # Multiply time by 2 to simplify integer arithmetic
734 if [ -n "$timeout_s" ]; then
735 dtimeleft_s
=$
((timeout_s
* 2))
738 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
739 # Env variable requested no session daemon
743 runas_pids
=$
(lttng_pgrep
"$RUNAS_MATCH")
744 pids
=$
(lttng_pgrep
"$SESSIOND_MATCH")
746 if [ -n "$runas_pids" ]; then
747 pids
="$pids $runas_pids"
750 if [ -z "$pids" ]; then
751 if [ "$is_cleanup" -eq 1 ]; then
753 elif [ "$withtap" -eq "1" ]; then
754 fail
"No session daemon to kill"
756 LTTNG_BAIL_OUT
"No session daemon to kill"
761 diag
"Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
763 # shellcheck disable=SC2086
764 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
766 if [ "$withtap" -eq "1" ]; then
767 fail
"Kill sessions daemon"
771 while [ -n "$out" ]; do
772 out
=$
(lttng_pgrep
"${SESSIOND_MATCH}")
773 if [ -n "$dtimeleft_s" ]; then
774 if [ $dtimeleft_s -lt 0 ]; then
778 dtimeleft_s
=$
((dtimeleft_s
- 1))
783 while [ -n "$out" ]; do
784 out
=$
(lttng_pgrep
"$CONSUMERD_MATCH")
785 if [ -n "$dtimeleft_s" ]; then
786 if [ $dtimeleft_s -lt 0 ]; then
790 dtimeleft_s
=$
((dtimeleft_s
- 1))
795 if [ "$withtap" -eq "1" ]; then
796 if [ "$retval" -eq "0" ]; then
797 pass
"Wait after kill session daemon"
799 fail
"Wait after kill session daemon"
803 if [ "$signal" = "SIGKILL" ]; then
804 if [ "$(id -u)" -eq "0" ]; then
806 modules
="$(lsmod | grep ^lttng | awk '{print $1}')"
808 if [ -n "$modules" ]; then
809 diag
"Unloading all LTTng modules"
810 modprobe
--remove "$modules"
818 function stop_lttng_sessiond
()
820 stop_lttng_sessiond_opt
1 0 "$@"
823 function stop_lttng_sessiond_notap
()
825 stop_lttng_sessiond_opt
0 0 "$@"
828 function stop_lttng_sessiond_cleanup
()
830 stop_lttng_sessiond_opt
0 1 "$@"
833 function sigstop_lttng_sessiond_opt
()
839 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
840 # Env variable requested no session daemon
844 pids
="$(lttng_pgrep "${SESSIOND_MATCH}") $(lttng_pgrep "$RUNAS_MATCH")"
846 if [ "$withtap" -eq "1" ]; then
847 diag
"Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
850 # shellcheck disable=SC2086
851 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
852 if [ "$withtap" -eq "1" ]; then
853 fail
"Sending SIGSTOP to session daemon"
857 while [ $out -ne 0 ]; do
858 pids
="$(lttng_pgrep "$SESSIOND_MATCH")"
860 # Wait until state becomes stopped for session
863 for sessiond_pid
in $pids; do
864 state
="$(ps -p "$sessiond_pid" -o state= )"
865 if [[ -n "$state" && "$state" != "T" ]]; then
871 if [ "$withtap" -eq "1" ]; then
872 pass
"Sending SIGSTOP to session daemon"
877 function sigstop_lttng_sessiond
()
879 sigstop_lttng_sessiond_opt
1 "$@"
882 function sigstop_lttng_sessiond_notap
()
884 sigstop_lttng_sessiond_opt
0 "$@"
887 function stop_lttng_consumerd_opt
()
897 if [ -z "$signal" ]; then
901 # Multiply time by 2 to simplify integer arithmetic
902 if [ -n "$timeout_s" ]; then
903 dtimeleft_s
=$
((timeout_s
* 2))
906 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
908 if [ -z "$pids" ]; then
909 if [ "$is_cleanup" -eq 1 ]; then
911 elif [ "$withtap" -eq "1" ]; then
912 fail
"No consumerd daemon to kill"
914 LTTNG_BAIL_OUT
"No consumerd daemon to kill"
919 diag
"Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')"
921 # shellcheck disable=SC2086
922 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
924 if [ "$withtap" -eq "1" ]; then
925 fail
"Kill consumer daemon"
929 while [ $out -ne 0 ]; do
930 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
932 # If consumerds are still present check their status.
933 # A zombie status qualifies the consumerd as *killed*
935 for consumer_pid
in $pids; do
936 state
="$(ps -p "$consumer_pid" -o state= )"
937 if [[ -n "$state" && "$state" != "Z" ]]; then
941 if [ -n "$dtimeleft_s" ]; then
942 if [ $dtimeleft_s -lt 0 ]; then
946 dtimeleft_s
=$
((dtimeleft_s
- 1))
950 if [ "$withtap" -eq "1" ]; then
951 if [ "$retval" -eq "0" ]; then
952 pass
"Wait after kill consumer daemon"
954 fail
"Wait after kill consumer daemon"
962 function stop_lttng_consumerd
()
964 stop_lttng_consumerd_opt
1 0 "$@"
967 function stop_lttng_consumerd_notap
()
969 stop_lttng_consumerd_opt
0 0 "$@"
972 function stop_lttng_consumerd_cleanup
()
974 stop_lttng_consumerd_opt
0 1 "$@"
977 function sigstop_lttng_consumerd_opt
()
983 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
985 diag
"Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')"
987 # shellcheck disable=SC2086
988 kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
991 if [ $retval -eq 1 ]; then
992 if [ "$withtap" -eq "1" ]; then
993 fail
"Sending SIGSTOP to consumer daemon"
998 while [ $out -ne 0 ]; do
999 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
1001 # Wait until state becomes stopped for all
1004 for consumer_pid
in $pids; do
1005 state
="$(ps -p "$consumer_pid" -o state= )"
1006 if [[ -n "$state" && "$state" != "T" ]]; then
1012 if [ "$withtap" -eq "1" ]; then
1013 pass
"Sending SIGSTOP to consumer daemon"
1019 function sigstop_lttng_consumerd
()
1021 sigstop_lttng_consumerd_opt
1 "$@"
1024 function sigstop_lttng_consumerd_notap
()
1026 sigstop_lttng_consumerd_opt
0 "$@"
1029 function list_lttng_with_opts
()
1035 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1038 if [ $withtap -eq "1" ]; then
1039 ok
$ret "Lttng-tool list command with option $opts"
1043 function list_lttng_ok
()
1045 list_lttng_with_opts
1 "$@"
1048 function list_lttng_notap
()
1050 list_lttng_with_opts
0 "$@"
1053 function create_lttng_session_no_output
()
1057 local trace_format
=("--trace-format" "ctf1")
1059 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1060 create
"${trace_format[@]}" $sess_name --no-output $opts
1061 ok $?
"Create session $sess_name in no-output mode"
1064 function create_lttng_session_uri
() {
1068 local trace_format
=("--trace-format" "ctf1")
1070 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1071 create
"${trace_format[@]}" $sess_name -U $uri $opts
1072 ok $?
"Create session $sess_name with uri:$uri and opts: $opts"
1075 function create_lttng_session
()
1078 local expected_to_fail
=$2
1082 local trace_format
=("--trace-format" "ctf1")
1084 if [ -z "$trace_path" ]; then
1085 # Use lttng-sessiond default output.
1088 trace_path
="-o $trace_path"
1091 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1092 create
"${trace_format[@]}" "$sess_name" $trace_path $opt
1094 if [ $expected_to_fail -eq "1" ]; then
1097 if [ $withtap -eq "1" ]; then
1098 ok
$ret "Create session $sess_name in $trace_path failed as expected"
1101 if [ $withtap -eq "1" ]; then
1102 ok
$ret "Create session $sess_name in $trace_path"
1108 function create_lttng_session_ok
()
1110 create_lttng_session
1 0 "$@"
1113 function create_lttng_session_fail
()
1115 create_lttng_session
1 1 "$@"
1118 function create_lttng_session_notap
()
1120 create_lttng_session
0 0 "$@"
1124 function enable_ust_lttng_channel
()
1127 local expected_to_fail
=$2
1129 local channel_name
=$4
1132 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1133 enable-channel
-u $channel_name -s $sess_name $opts
1135 if [[ $expected_to_fail -eq "1" ]]; then
1138 if [ $withtap -eq "1" ]; then
1139 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
1142 if [ $withtap -eq "1" ]; then
1143 ok
$ret "Enable channel $channel_name for session $sess_name"
1149 function enable_ust_lttng_channel_ok
()
1151 enable_ust_lttng_channel
1 0 "$@"
1154 function enable_ust_lttng_channel_fail
()
1156 enable_ust_lttng_channel
1 1 "$@"
1159 function enable_ust_lttng_channel_notap
()
1161 enable_ust_lttng_channel
0 0 "$@"
1164 function disable_ust_lttng_channel
()
1167 local channel_name
=$2
1169 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1170 disable-channel
-u $channel_name -s $sess_name
1171 ok $?
"Disable channel $channel_name for session $sess_name"
1174 function enable_lttng_mmap_overwrite_kernel_channel
()
1177 local channel_name
=$2
1179 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1180 enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite
1181 ok $?
"Enable channel $channel_name for session $sess_name"
1184 function enable_lttng_mmap_discard_small_kernel_channel
()
1187 local channel_name
=$2
1189 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1190 enable-channel
-s $sess_name $channel_name -k --output mmap
--discard --subbuf-size=$
(getconf PAGE_SIZE
) --num-subbuf=2
1191 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1194 function enable_lttng_mmap_overwrite_small_kernel_channel
()
1197 local channel_name
=$2
1199 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1200 enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite --subbuf-size=$
(getconf PAGE_SIZE
) --num-subbuf=2
1201 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1204 function enable_lttng_mmap_overwrite_ust_channel
()
1207 local channel_name
=$2
1209 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1210 enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite
1211 ok $?
"Enable channel $channel_name for session $sess_name"
1214 function enable_ust_lttng_event
()
1217 local expected_to_fail
=$2
1219 local event_name
="$4"
1220 local channel_name
=$5
1222 if [ -z $channel_name ]; then
1223 # default channel if none specified
1226 chan
="-c $channel_name"
1229 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1230 enable-event
"$event_name" $chan -s "$sess_name" -u
1232 if [[ $expected_to_fail -eq "1" ]]; then
1235 if [[ $withtap -eq "1" ]]; then
1236 ok
$ret "Enable ust event $event_name for session $session_name failed as expected"
1239 if [[ $withtap -eq "1" ]]; then
1240 ok
$ret "Enable ust event $event_name for session $sess_name"
1246 function enable_ust_lttng_event_ok
()
1248 enable_ust_lttng_event
1 0 "$@"
1251 function enable_ust_lttng_event_fail
()
1253 enable_ust_lttng_event
1 1 "$@"
1256 function enable_ust_lttng_event_notap
()
1258 enable_ust_lttng_event
0 0 "$@"
1261 function enable_jul_lttng_event
()
1267 if [ -z $channel_name ]; then
1268 # default channel if none specified
1271 chan
="-c $channel_name"
1274 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1275 enable-event
"$event_name" $chan -s $sess_name -j
1276 ok $?
"Enable JUL event $event_name for session $sess_name"
1279 function enable_jul_lttng_event_loglevel
()
1282 local event_name
="$2"
1284 local channel_name
=$4
1286 if [ -z $channel_name ]; then
1287 # default channel if none specified
1290 chan
="-c $channel_name"
1293 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1294 enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j
1295 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
1298 function enable_log4j_lttng_event
()
1302 local channel_name
=$3
1306 # default channel if none specified
1307 if [ -n "$channel_name" ]; then
1308 chan_opt
=("-c" "$channel_name")
1311 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1312 enable-event
"$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j
1313 ok $?
"Enable LOG4J event '$event_name' for session '$sess_name'"
1316 function enable_log4j_lttng_event_filter
()
1322 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1323 enable-event
"$event_name" -s "$sess_name" --log4j --filter "$filter"
1324 ok $?
"Enable LOG4J event '$event_name' with filter '$filter' for session '$sess_name'"
1327 function enable_log4j_lttng_event_filter_loglevel_only
()
1334 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1335 enable-event
--loglevel-only "$loglevel" "$event_name" -s "$sess_name" -l --filter "$filter"
1336 ok $?
"Enable LOG4J event '$event_name' with filter '$filter' and loglevel-only '$loglevel' for session '$sess_name'"
1339 function enable_log4j_lttng_event_loglevel
()
1344 local channel_name
=$4
1347 # default channel if none specified
1348 if [ -n "$channel_name" ]; then
1349 chan_opt
=("-c" "$channel_name")
1352 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1353 enable-event
--loglevel "$loglevel" "$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j
1354 ok $?
"Enable LOG4J event '$event_name' for session '$sess_name' with loglevel '$loglevel'"
1357 function enable_log4j_lttng_event_loglevel_only
()
1362 local channel_name
=$4
1366 # default channel if none specified
1367 if [ -n "$channel_name" ]; then
1368 chan_opt
=("-c" "$channel_name")
1371 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1372 enable-event
--loglevel-only "$loglevel" "$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j
1373 ok $?
"Enable LOG4J event '$event_name' for session '$sess_name' with loglevel-only '$loglevel'"
1376 function enable_python_lttng_event
()
1382 if [ -z $channel_name ]; then
1383 # default channel if none specified
1386 chan
="-c $channel_name"
1389 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1390 enable-event
"$event_name" $chan -s $sess_name -p
1391 ok $?
"Enable Python event $event_name for session $sess_name"
1394 function enable_python_lttng_event_loglevel
()
1397 local event_name
="$2"
1399 local channel_name
=$4
1401 if [ -z $channel_name ]; then
1402 # default channel if none specified
1405 chan
="-c $channel_name"
1408 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1409 enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -p
1410 ok $?
"Enable Python event $event_name for session $sess_name with loglevel $loglevel"
1413 function enable_ust_lttng_event_filter
()
1415 local sess_name
="$1"
1416 local event_name
="$2"
1418 local channel_name
=$4
1420 if [ -z $channel_name ]; then
1421 # default channel if none specified
1424 chan
="-c $channel_name"
1427 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1428 enable-event
$chan "$event_name" -s $sess_name -u --filter "$filter"
1429 ok $?
"Enable event $event_name with filtering for session $sess_name"
1432 function enable_ust_lttng_event_loglevel
()
1434 local sess_name
="$1"
1435 local event_name
="$2"
1438 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1439 enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel
1440 ok $?
"Enable event $event_name with loglevel $loglevel"
1443 function enable_ust_lttng_event_loglevel_only
()
1445 local sess_name
="$1"
1446 local event_name
="$2"
1449 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1450 enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel
1451 ok $?
"Enable event $event_name with loglevel-only $loglevel"
1454 function disable_ust_lttng_event
()
1456 local sess_name
="$1"
1457 local event_name
="$2"
1458 local channel_name
="$3"
1460 if [ -z $channel_name ]; then
1461 # default channel if none specified
1464 chan
="-c $channel_name"
1467 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1468 disable-event
"$event_name" -s $sess_name $chan -u
1469 ok $?
"Disable event $event_name for session $sess_name"
1472 function disable_jul_lttng_event
()
1474 local sess_name
="$1"
1475 local event_name
="$2"
1477 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
1478 ok $?
"Disable JUL event $event_name for session $sess_name"
1481 function disable_log4j_lttng_event
()
1483 local sess_name
="$1"
1484 local event_name
="$2"
1486 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1487 disable-event
"$event_name" -s "$sess_name" --log4j
1488 ok $?
"Disable LOG4J event '$event_name' for session '$sess_name'"
1491 function disable_python_lttng_event
()
1493 local sess_name
="$1"
1494 local event_name
="$2"
1496 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1497 disable-event
"$event_name" -s $sess_name -p
1498 ok $?
"Disable Python event $event_name for session $sess_name"
1501 function start_lttng_tracing_opt
()
1504 local expected_to_fail
=$2
1507 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1510 if [[ $expected_to_fail -eq "1" ]]; then
1513 if [ $withtap -eq "1" ]; then
1514 ok $?
"Start tracing for session $sess_name failed as expected"
1517 if [ $withtap -eq "1" ]; then
1518 ok
$ret "Start tracing for session $sess_name"
1523 function start_lttng_tracing_ok
()
1525 start_lttng_tracing_opt
1 0 "$@"
1528 function start_lttng_tracing_fail
()
1530 start_lttng_tracing_opt
1 1 "$@"
1533 function start_lttng_tracing_notap
()
1535 start_lttng_tracing_opt
0 1 "$@"
1538 function stop_lttng_tracing_opt
()
1541 local expected_to_fail
=$2
1544 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1547 if [[ $expected_to_fail -eq "1" ]]; then
1550 if [ $withtap -eq "1" ]; then
1551 ok $?
"Stop lttng tracing for session $sess_name failed as expected"
1554 if [ $withtap -eq "1" ]; then
1555 ok
$ret "Stop lttng tracing for session $sess_name"
1560 function stop_lttng_tracing_ok
()
1562 stop_lttng_tracing_opt
1 0 "$@"
1565 function stop_lttng_tracing_fail
()
1567 stop_lttng_tracing_opt
1 1 "$@"
1570 function stop_lttng_tracing_notap
()
1572 stop_lttng_tracing_opt
0 0 "$@"
1575 function destroy_lttng_session
()
1578 local expected_to_fail
=$2
1581 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1584 if [[ $expected_to_fail -eq "1" ]]; then
1587 if [ $withtap -eq "1" ]; then
1588 ok
$ret "Destroy session $sess_name failed as expected"
1591 if [ $withtap -eq "1" ]; then
1592 ok
$ret "Destroy session $sess_name"
1597 function destroy_lttng_session_ok
()
1599 destroy_lttng_session
1 0 "$@"
1603 function destroy_lttng_session_fail
()
1605 destroy_lttng_session
1 1 "$@"
1608 function destroy_lttng_session_notap
()
1610 destroy_lttng_session
0 0 "$@"
1613 function destroy_lttng_sessions
()
1615 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1617 ok $?
"Destroy all lttng sessions"
1620 function lttng_snapshot_add_output
()
1622 local expected_to_fail
=$1
1627 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1628 snapshot add-output
-s $sess_name $trace_path $opts
1630 if [[ $expected_to_fail -eq 1 ]]; then
1632 ok $?
"Added snapshot output $trace_path failed as expected"
1634 ok
$ret "Added snapshot output $trace_path"
1638 function lttng_snapshot_add_output_ok
()
1640 lttng_snapshot_add_output
0 "$@"
1643 function lttng_snapshot_add_output_fail
()
1645 lttng_snapshot_add_output
1 "$@"
1648 function lttng_snapshot_del_output
()
1650 local expected_to_fail
=$1
1654 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1655 snapshot del-output
-s $sess_name $id
1657 if [[ $expected_to_fail -eq "1" ]]; then
1659 ok $?
"Deleted snapshot output id $id failed as expected"
1661 ok
$ret "Deleted snapshot output id $id"
1665 function lttng_snapshot_del_output_ok
()
1667 lttng_snapshot_del_output
0 "$@"
1670 function lttng_snapshot_del_output_fail
()
1672 lttng_snapshot_del_output
1 "$@"
1675 function lttng_snapshot_record
()
1680 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1681 snapshot record
-s "$sess_name" "$trace_path"
1682 ok $?
"Snapshot recorded"
1685 function lttng_snapshot_list
()
1688 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1689 snapshot list-output
-s $sess_name
1690 ok $?
"Snapshot list"
1693 function lttng_save
()
1698 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1699 save
$sess_name $opts
1700 ok $?
"Session saved"
1703 function lttng_load
()
1705 local expected_to_fail
=$1
1708 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1711 if [[ $expected_to_fail -eq "1" ]]; then
1713 ok $?
"Load command failed as expected with opts: $opts"
1715 ok
$ret "Load command with opts: $opts"
1719 function lttng_load_ok
()
1724 function lttng_load_fail
()
1729 function lttng_track
()
1731 local expected_to_fail
="$1"
1734 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN track
$opts >$OUTPUT_DEST
1736 if [[ $expected_to_fail -eq "1" ]]; then
1738 ok $?
"Track command failed as expected with opts: $opts"
1740 ok
$ret "Track command with opts: $opts"
1744 function lttng_track_ok
()
1749 function lttng_track_fail
()
1754 function lttng_untrack
()
1756 local expected_to_fail
="$1"
1759 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN untrack
$opts >$OUTPUT_DEST
1761 if [[ $expected_to_fail -eq "1" ]]; then
1763 ok $?
"Untrack command failed as expected with opts: $opts"
1765 ok
$ret "Untrack command with opts: $opts"
1769 function lttng_untrack_ok
()
1771 lttng_untrack
0 "$@"
1774 function lttng_untrack_fail
()
1776 lttng_untrack
1 "$@"
1779 function lttng_track_pid_ok
()
1782 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track
--kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1783 ok $?
"Lttng track pid on the kernel domain"
1786 function lttng_untrack_kernel_all_ok
()
1788 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack
--kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1789 ok $?
"Lttng untrack all pid on the kernel domain"
1792 function lttng_track_ust_ok
()
1794 lttng_track_ok
-u "$@"
1797 function lttng_track_ust_fail
()
1799 lttng_track_fail
-u "$@"
1802 function lttng_track_kernel_ok
()
1804 lttng_track_ok
-k "$@"
1807 function lttng_track_kernel_fail
()
1809 lttng_track_fail
-k "$@"
1812 function lttng_untrack_ust_ok
()
1814 lttng_untrack_ok
-u "$@"
1817 function lttng_untrack_ust_fail
()
1819 lttng_untrack_fail
-u "$@"
1822 function lttng_untrack_kernel_ok
()
1824 lttng_untrack_ok
-k "$@"
1827 function lttng_untrack_kernel_fail
()
1829 lttng_untrack_fail
-k "$@"
1832 function lttng_add_context_list
()
1834 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1837 ok
$ret "Context listing"
1840 function add_context_lttng
()
1842 local expected_to_fail
="$1"
1844 local session_name
="$3"
1845 local channel_name
="$4"
1848 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1849 add-context
-s $session_name -c $channel_name -t $type $domain
1851 if [[ $expected_to_fail -eq "1" ]]; then
1853 ok $?
"Add context command failed as expected for type: $type"
1855 ok
$ret "Add context command for type: $type"
1859 function add_context_ust_ok
()
1861 add_context_lttng
0 -u "$@"
1864 function add_context_ust_fail
()
1866 add_context_lttng
1 -u "$@"
1869 function add_context_kernel_ok
()
1871 add_context_lttng
0 -k "$@"
1874 function add_context_kernel_fail
()
1876 add_context_lttng
1 -k "$@"
1879 function wait_live_trace_ready
()
1882 local zero_client_match
=0
1884 diag
"Waiting for live trace at url: $url"
1885 while [ $zero_client_match -eq 0 ]; do
1886 zero_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "0 client(s) connected" |
wc -l)
1889 pass
"Waiting for live trace at url: $url"
1892 function wait_live_viewer_connect
()
1895 local one_client_match
=0
1897 diag
"Waiting for live viewers on url: $url"
1898 while [ $one_client_match -eq 0 ]; do
1899 one_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "1 client(s) connected" |
wc -l)
1902 pass
"Waiting for live viewers on url: $url"
1905 function bail_out_if_no_babeltrace
()
1907 which "$BABELTRACE_BIN" >/dev
/null
1908 if [ $?
-ne 0 ]; then
1909 LTTNG_BAIL_OUT
"\"$BABELTRACE_BIN\" binary not found. Skipping tests"
1913 function validate_metadata_event
()
1916 local nr_event_id
=$2
1919 local metadata_file
=$
(find $trace_path -name "metadata")
1920 local metadata_path
=$
(dirname $metadata_file)
1922 bail_out_if_no_babeltrace
1924 local count
=$
($BABELTRACE_BIN --output-format=ctf-metadata
$metadata_path |
grep $event_name |
wc -l)
1926 if [ "$count" -ne "$nr_event_id" ]; then
1927 fail
"Metadata match with the metadata of $nr_event_id event(s) named $event_name"
1928 diag
"$count matching event names found in metadata"
1930 pass
"Metadata match with the metadata of $nr_event_id event(s) named $event_name"
1935 function trace_matches
()
1941 bail_out_if_no_babeltrace
1943 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1945 if [ "$count" -ne "$nr_iter" ]; then
1947 diag
"$count matching events found in trace"
1953 function trace_match_only
()
1959 bail_out_if_no_babeltrace
1960 #which "$BABELTRACE_BIN" >/dev/null
1961 #skip $? -ne 0 "\"$BABELTRACE_BIN\" binary not found. Skipping trace comparison"
1963 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1964 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1966 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1967 pass
"Trace match with $total event $event_name"
1970 diag
"$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1974 function validate_trace
1979 bail_out_if_no_babeltrace
1983 for i
in $event_name; do
1984 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1985 if [ "$traced" -ne 0 ]; then
1986 pass
"Validate trace for event $i, $traced events"
1988 fail
"Validate trace for event $i"
1989 diag
"Found $traced occurrences of $i"
1997 function validate_trace_count
2001 local expected_count
=$3
2003 bail_out_if_no_babeltrace
2008 for i
in $event_name; do
2009 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
2010 if [ "$traced" -ne 0 ]; then
2011 pass
"Validate trace for event $i, $traced events"
2013 fail
"Validate trace for event $i"
2014 diag
"Found $traced occurrences of $i"
2016 cnt
=$
(($cnt + $traced))
2019 test $cnt -eq $expected_count
2020 ok $?
"Read a total of $cnt events, expected $expected_count"
2023 function validate_trace_count_range_incl_min_excl_max
2027 local expected_min
=$3
2028 local expected_max
=$4
2030 bail_out_if_no_babeltrace
2035 for i
in $event_name; do
2036 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
2037 if [ "$traced" -ge $expected_min ]; then
2038 pass
"Validate trace for event $i, $traced events"
2040 fail
"Validate trace for event $i"
2041 diag
"Found $traced occurrences of $i"
2043 cnt
=$
(($cnt + $traced))
2046 test $cnt -lt $expected_max
2047 ok $?
"Read a total of $cnt events, expected between [$expected_min, $expected_max["
2050 function trace_first_line
2054 $BABELTRACE_BIN $trace_path 2>/dev
/null |
head -n 1
2057 function validate_trace_exp
()
2062 bail_out_if_no_babeltrace
2064 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep --extended-regexp ${event_exp} |
wc -l)
2065 if [ "$traced" -ne 0 ]; then
2066 pass
"Validate trace for expression '${event_exp}', $traced events"
2068 fail
"Validate trace for expression '${event_exp}'"
2069 diag
"Found $traced occurrences of '${event_exp}'"
2075 function validate_trace_only_exp
()
2080 bail_out_if_no_babeltrace
2082 local count
=$
($BABELTRACE_BIN $trace_path |
grep --extended-regexp ${event_exp} |
wc -l)
2083 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
2085 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
2086 pass
"Trace match with $total for expression '${event_exp}'"
2089 diag
"$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
2095 function validate_trace_empty
()
2099 bail_out_if_no_babeltrace
2101 events
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null
)
2103 if [ $ret -ne 0 ]; then
2104 fail
"Failed to parse trace"
2108 traced
=$
(echo -n "$events" |
wc -l)
2109 if [ "$traced" -eq 0 ]; then
2110 pass
"Validate empty trace"
2112 fail
"Validate empty trace"
2113 diag
"Found $traced events in trace"
2119 function validate_directory_empty
()
2121 local trace_path
="$1"
2123 # Do not double quote `$trace_path` below as we want wildcards to be
2125 files
="$(ls -A $trace_path)"
2127 if [ $ret -ne 0 ]; then
2128 fail
"Failed to list content of directory \"$trace_path\""
2132 nb_files
="$(echo -n "$files" | wc -l)"
2133 ok
$nb_files "Directory \"$trace_path\" is empty"
2136 function validate_trace_session_ust_empty
()
2138 validate_directory_empty
"$1"/ust
2141 function validate_trace_session_kernel_empty
()
2143 validate_trace_empty
"$1"/kernel
2146 function regenerate_metadata
()
2148 local expected_to_fail
=$1
2151 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2152 regenerate metadata
-s $sess_name
2154 if [[ $expected_to_fail -eq "1" ]]; then
2156 ok $?
"Expected fail on regenerate metadata $sess_name"
2158 ok
$ret "Metadata regenerate $sess_name"
2162 function regenerate_metadata_ok
()
2164 regenerate_metadata
0 "$@"
2167 function regenerate_metadata_fail
()
2169 regenerate_metadata
1 "$@"
2172 function regenerate_statedump
()
2174 local expected_to_fail
=$1
2177 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2178 regenerate statedump
-s $sess_name
2180 if [[ $expected_to_fail -eq "1" ]]; then
2182 ok $?
"Expected fail on regenerate statedump $sess_name"
2184 ok
$ret "Statedump regenerate $sess_name"
2188 function regenerate_statedump_ok
()
2190 regenerate_statedump
0 "$@"
2193 function regenerate_statedump_fail
()
2195 regenerate_statedump
1 "$@"
2198 function rotate_session
()
2200 local expected_to_fail
=$1
2203 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2206 if [[ $expected_to_fail -eq "1" ]]; then
2208 ok $?
"Expected fail on rotate session $sess_name"
2210 ok
$ret "Rotate session $sess_name"
2214 function rotate_session_ok
()
2216 rotate_session
0 "$@"
2219 function rotate_session_fail
()
2221 rotate_session
1 "$@"
2224 function destructive_tests_enabled
()
2226 if [ "$LTTNG_ENABLE_DESTRUCTIVE_TESTS" = "will-break-my-system" ]; then
2233 function lttng_enable_rotation_timer
()
2235 local expected_to_fail
=$1
2239 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2240 enable-rotation
-s $sess_name --timer $period
2242 if [[ $expected_to_fail -eq "1" ]]; then
2244 ok $?
"Expected fail when setting periodic rotation ($period) of session $sess_name"
2246 ok
$ret "Set periodic rotation ($period) of session $sess_name"
2250 function lttng_enable_rotation_timer_ok
()
2252 lttng_enable_rotation_timer
0 $@
2255 function lttng_enable_rotation_timer_fail
()
2257 lttng_enable_rotation_timer
1 $@
2260 function lttng_enable_rotation_size
()
2262 local expected_to_fail
=$1
2266 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2267 enable-rotation
-s $sess_name --size $size
2269 if [[ $expected_to_fail -eq "1" ]]; then
2271 ok $?
"Expected to fail to set a periodic rotation of session $sess_name" "every " $size " bytes"
2273 ok
$ret "Set a scheduled rotation of session $sess_name" "every " $size " bytes"
2277 function lttng_enable_rotation_size_ok
()
2279 lttng_enable_rotation_size
0 $@
2282 function lttng_enable_rotation_size_fail
()
2284 lttng_enable_rotation_size
1 $@
2287 function lttng_clear_session
()
2289 local expected_to_fail
=$1
2292 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2295 if [[ $expected_to_fail -eq "1" ]]; then
2297 ok $?
"Expected fail on clear session $sess_name"
2299 ok
$ret "Clear session $sess_name"
2303 function lttng_clear_session_ok
()
2305 lttng_clear_session
0 $@
2308 function lttng_clear_session_fail
()
2310 lttng_clear_session
1 $@
2313 function lttng_clear_all
()
2315 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2317 ok $?
"Clear all lttng sessions"
2320 function lttng_add_trigger
()
2322 local expected_to_fail
="$1"
2323 local trigger_name
="$2"
2327 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN add-trigger --name $trigger_name ${args[*]}"
2328 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-trigger
--name "$trigger_name" "${args[@]}" 1> /dev
/null
2> /dev
/null
2330 if [[ $expected_to_fail -eq "1" ]]; then
2332 ok $?
"Add trigger $trigger_name failed as expected"
2334 ok
$ret "Add trigger $trigger_name"
2338 function lttng_remove_trigger
()
2340 local expected_to_fail
="$1"
2341 local trigger_name
="$2"
2344 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN remove-trigger $trigger_name $*"
2345 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" remove-trigger
"$trigger_name" "$@" 1> /dev
/null
2> /dev
/null
2347 if [[ $expected_to_fail -eq "1" ]]; then
2349 ok $?
"Remove trigger $trigger_name failed as expected"
2351 ok
$ret "Remove trigger $trigger_name"
2355 function lttng_add_trigger_ok
()
2357 lttng_add_trigger
0 "$@"
2360 function lttng_add_trigger_fail
()
2362 lttng_add_trigger
1 "$@"
2365 function lttng_remove_trigger_ok
()
2367 lttng_remove_trigger
0 "$@"
2370 function list_triggers_matches_ok
()
2372 local tmp_stdout
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2373 local tmp_stderr
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stderr.XXXXXX")
2375 local test_name
="$1"
2376 local expected_stdout_file
="$2"
2378 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN list-triggers"
2380 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" list-triggers
> "${tmp_stdout}" 2> "${tmp_stderr}"
2381 ok $?
"${test_name}: exit code is 0"
2383 diff -u "${expected_stdout_file}" "${tmp_stdout}"
2384 ok $?
"${test_name}: expected stdout"
2386 diff -u /dev
/null
"${tmp_stderr}"
2387 ok $?
"${test_name}: expected stderr"
2389 rm -f "${tmp_stdout}"
2390 rm -f "${tmp_stderr}"
2393 function list_triggers_matches_mi_ok
()
2396 local tmp_stdout_raw
2399 local test_name
="$1"
2400 local expected_stdout_file
="$2"
2402 tmp_stdout_raw
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2403 tmp_stdout
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2404 tmp_stderr
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stderr.XXXXXX")
2406 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi xml list-triggers"
2408 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" --mi=xml list-triggers
> "${tmp_stdout_raw}" 2> "${tmp_stderr}"
2409 ok $?
"${test_name}: exit code is 0"
2411 # Pretty-fy xml before further test.
2412 $XML_PRETTY < "${tmp_stdout_raw}" > "${tmp_stdout}"
2414 $MI_VALIDATE "${tmp_stdout}"
2415 ok $?
"list-trigger mi is valid"
2417 diff -u "${expected_stdout_file}" "${tmp_stdout}"
2418 ok $?
"${test_name}: expected stdout"
2420 diff -u /dev
/null
"${tmp_stderr}"
2421 ok $?
"${test_name}: expected stderr"
2423 rm -f "${tmp_stdout}"
2424 rm -f "${tmp_stdout_raw}"
2425 rm -f "${tmp_stderr}"
2428 function validate_path_pattern
()
2432 # Base path is only used in error case and is used to list the content
2441 if [ "$ret" -ne "0" ]; then
2442 diag
"Path pattern expected: $pattern"
2443 # List the tracepath for more info. We use find as a recursive
2445 diag
"The base path content:"
2446 find "$base_path" -print
2450 function validate_trace_path_ust_uid
()
2453 local session_name
=$2
2455 local pattern
="$trace_path/$session_name-$date_time_pattern/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2457 validate_path_pattern
"UST per-uid trace path is valid" "$pattern" "$trace_path"
2460 function validate_trace_path_ust_uid_network
()
2463 local session_name
=$2
2466 local hostname
=$HOSTNAME
2470 # If the session was given a network base path (e.g
2471 # 127.0.0.1/my/custom/path on creation, there is no session name
2472 # component to the path on the relayd side. Caller can simply not pass a
2473 # session name for this scenario.
2474 if [ -n "$session_name" ]; then
2475 session_name
="$session_name-$date_time_pattern"
2476 if [ -n "$base_path" ]; then
2477 fail
"Session name and base path are mutually exclusive"
2482 pattern
="$trace_path/$hostname/$base_path/$session_name/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2484 validate_path_pattern
"UST per-uid network trace path is valid" "$pattern" "$trace_path"
2487 function validate_trace_path_ust_uid_snapshot_network
()
2490 local session_name
=$2
2491 local snapshot_name
=$3
2492 local snapshot_number
=$4
2494 local hostname
=$HOSTNAME
2499 # If the session/output was given a network base path (e.g
2500 # 127.0.0.1/my/custom/path on creation, there is no session name
2501 # component to the path on the relayd side. Caller can simply not pass a
2502 # session name for this scenario.
2503 if [ -n "$session_name" ]; then
2504 session_name
="$session_name-$date_time_pattern"
2505 if [ -n "$base_path" ]; then
2506 fail
"Session name and base path are mutually exclusive"
2511 pattern
="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2513 validate_path_pattern
"UST per-uid network snapshot trace path is valid" "$pattern" "$trace_path"
2516 function validate_trace_path_ust_uid_snapshot
()
2519 local session_name
=$2
2520 local snapshot_name
=$3
2521 local snapshot_number
=$4
2527 # If the session/output was given a network base path (e.g
2528 # 127.0.0.1/my/custom/path) on creation, there is no session name
2529 # component to the path on the relayd side. Caller can simply not pass a
2530 # session name for this scenario.
2531 if [ -n "$session_name" ]; then
2532 session_name
="$session_name-$date_time_pattern"
2533 if [ -n "$base_path" ]; then
2534 fail
"Session name and base path are mutually exclusive"
2539 pattern
="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2541 validate_path_pattern
"UST per-uid snapshot trace path is valid" "$pattern" "$trace_path"
2544 function validate_trace_path_ust_pid
()
2547 local session_name
=$2
2553 # If the session was given a trace path on creation, there is no session
2554 # name component to the path. Caller can simply not pass a session name
2555 # for this scenario.
2556 if [ -n "$session_name" ]; then
2557 session_name
="$session_name-$date_time_pattern"
2560 pattern
="$trace_path/$session_name/ust/pid/$pid/$app_string-*-$date_time_pattern/metadata"
2562 validate_path_pattern
"UST per-pid trace path is valid" "$pattern" "$trace_path"
2565 function validate_trace_path_kernel
()
2568 local session_name
=$2
2571 # If the session was given a trace path on creation, there is no session
2572 # name component to the path. Caller can simply not pass a session name
2573 # for this scenario.
2574 if [ -n "$session_name" ]; then
2575 session_name
="$session_name-$date_time_pattern"
2578 pattern
="$trace_path/$session_name/kernel/metadata"
2580 validate_path_pattern
"Kernel trace path is valid" "$pattern" "$trace_path"
2583 function validate_trace_path_kernel_network
()
2586 local session_name
=$2
2587 local hostname
=$HOSTNAME
2588 local pattern
="$trace_path/$hostname/$session_name-$date_time_pattern/kernel/metadata"
2590 validate_path_pattern
"Kernel network trace path is valid" "$pattern" "$trace_path"
2593 function validate_trace_path_kernel_snapshot
()
2596 local session_name
=$2
2597 local snapshot_name
=$3
2598 local snapshot_number
=$4
2603 # If the session/output was given a network base path (e.g
2604 # 127.0.0.1/my/custom/path on creation, there is no session name
2605 # component to the path on the relayd side. Caller can simply not pass a
2606 # session name for this scenario.
2607 if [ -n "$session_name" ]; then
2608 session_name
="$session_name-$date_time_pattern"
2609 if [ -n "$base_path" ]; then
2610 fail
"Session name and base path are mutually exclusive"
2615 pattern
="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata"
2617 validate_path_pattern
"Kernel snapshot trace path is valid" "$pattern" "$trace_path"
2620 function validate_trace_path_kernel_snapshot_network
()
2623 local session_name
=$2
2624 local snapshot_name
=$3
2625 local snapshot_number
=$4
2627 local hostname
=$HOSTNAME
2631 # If the session/output was given a network base path (e.g
2632 # 127.0.0.1/my/custom/path on creation, there is no session name
2633 # component to the path on the relayd side. Caller can simply not pass a
2634 # session name for this scenario.
2635 if [ -n "$session_name" ]; then
2636 session_name
="$session_name-$date_time_pattern"
2637 if [ -n "$base_path" ]; then
2638 fail
"Session name and base path are mutually exclusive"
2643 pattern
="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata"
2645 validate_path_pattern
"Kernel network snapshot trace path is valid" "$pattern" "$trace_path"