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/config/"
686 : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}"
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
()
1032 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1034 ok $?
"Lttng-tool list command with option $opts"
1037 function create_lttng_session_no_output
()
1042 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1043 create
$sess_name --no-output $opts
1044 ok $?
"Create session $sess_name in no-output mode"
1047 function create_lttng_session_uri
() {
1052 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1053 create
$sess_name -U $uri $opts
1054 ok $?
"Create session $sess_name with uri:$uri and opts: $opts"
1057 function create_lttng_session
()
1060 local expected_to_fail
=$2
1065 if [ -z "$trace_path" ]; then
1066 # Use lttng-sessiond default output.
1069 trace_path
="-o $trace_path"
1072 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1073 create
"$sess_name" $trace_path $opt
1075 if [ $expected_to_fail -eq "1" ]; then
1078 if [ $withtap -eq "1" ]; then
1079 ok
$ret "Create session $sess_name in $trace_path failed as expected"
1082 if [ $withtap -eq "1" ]; then
1083 ok
$ret "Create session $sess_name in $trace_path"
1089 function create_lttng_session_ok
()
1091 create_lttng_session
1 0 "$@"
1094 function create_lttng_session_fail
()
1096 create_lttng_session
1 1 "$@"
1099 function create_lttng_session_notap
()
1101 create_lttng_session
0 0 "$@"
1105 function enable_ust_lttng_channel
()
1108 local expected_to_fail
=$2
1110 local channel_name
=$4
1113 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1114 enable-channel
-u $channel_name -s $sess_name $opts
1116 if [[ $expected_to_fail -eq "1" ]]; then
1119 if [ $withtap -eq "1" ]; then
1120 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
1123 if [ $withtap -eq "1" ]; then
1124 ok
$ret "Enable channel $channel_name for session $sess_name"
1130 function enable_ust_lttng_channel_ok
()
1132 enable_ust_lttng_channel
1 0 "$@"
1135 function enable_ust_lttng_channel_fail
()
1137 enable_ust_lttng_channel
1 1 "$@"
1140 function enable_ust_lttng_channel_notap
()
1142 enable_ust_lttng_channel
0 0 "$@"
1145 function disable_ust_lttng_channel
()
1148 local channel_name
=$2
1150 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1151 disable-channel
-u $channel_name -s $sess_name
1152 ok $?
"Disable channel $channel_name for session $sess_name"
1155 function enable_lttng_mmap_overwrite_kernel_channel
()
1158 local channel_name
=$2
1160 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1161 enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite
1162 ok $?
"Enable channel $channel_name for session $sess_name"
1165 function enable_lttng_mmap_discard_small_kernel_channel
()
1168 local channel_name
=$2
1170 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1171 enable-channel
-s $sess_name $channel_name -k --output mmap
--discard --subbuf-size=$
(getconf PAGE_SIZE
) --num-subbuf=2
1172 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1175 function enable_lttng_mmap_overwrite_small_kernel_channel
()
1178 local channel_name
=$2
1180 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1181 enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite --subbuf-size=$
(getconf PAGE_SIZE
) --num-subbuf=2
1182 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1185 function enable_lttng_mmap_overwrite_ust_channel
()
1188 local channel_name
=$2
1190 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1191 enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite
1192 ok $?
"Enable channel $channel_name for session $sess_name"
1195 function enable_ust_lttng_event
()
1198 local expected_to_fail
=$2
1200 local event_name
="$4"
1201 local channel_name
=$5
1203 if [ -z $channel_name ]; then
1204 # default channel if none specified
1207 chan
="-c $channel_name"
1210 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1211 enable-event
"$event_name" $chan -s "$sess_name" -u
1213 if [[ $expected_to_fail -eq "1" ]]; then
1216 if [[ $withtap -eq "1" ]]; then
1217 ok
$ret "Enable ust event $event_name for session $session_name failed as expected"
1220 if [[ $withtap -eq "1" ]]; then
1221 ok
$ret "Enable ust event $event_name for session $sess_name"
1227 function enable_ust_lttng_event_ok
()
1229 enable_ust_lttng_event
1 0 "$@"
1232 function enable_ust_lttng_event_fail
()
1234 enable_ust_lttng_event
1 1 "$@"
1237 function enable_ust_lttng_event_notap
()
1239 enable_ust_lttng_event
0 0 "$@"
1242 function enable_jul_lttng_event
()
1248 if [ -z $channel_name ]; then
1249 # default channel if none specified
1252 chan
="-c $channel_name"
1255 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1256 enable-event
"$event_name" $chan -s $sess_name -j
1257 ok $?
"Enable JUL event $event_name for session $sess_name"
1260 function enable_jul_lttng_event_loglevel
()
1263 local event_name
="$2"
1265 local channel_name
=$4
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
--loglevel $loglevel "$event_name" $chan -s $sess_name -j
1276 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
1279 function enable_log4j_lttng_event
()
1285 if [ -z $channel_name ]; then
1286 # default channel if none specified
1289 chan
="-c $channel_name"
1292 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1293 enable-event
"$event_name" $chan -s $sess_name -l
1294 ok $?
"Enable LOG4J event $event_name for session $sess_name"
1297 function enable_log4j_lttng_event_loglevel
()
1300 local event_name
="$2"
1302 local channel_name
=$4
1304 if [ -z $channel_name ]; then
1305 # default channel if none specified
1308 chan
="-c $channel_name"
1311 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1312 enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -l
1313 ok $?
"Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
1316 function enable_python_lttng_event
()
1322 if [ -z $channel_name ]; then
1323 # default channel if none specified
1326 chan
="-c $channel_name"
1329 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1330 enable-event
"$event_name" $chan -s $sess_name -p
1331 ok $?
"Enable Python event $event_name for session $sess_name"
1334 function enable_python_lttng_event_loglevel
()
1337 local event_name
="$2"
1339 local channel_name
=$4
1341 if [ -z $channel_name ]; then
1342 # default channel if none specified
1345 chan
="-c $channel_name"
1348 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1349 enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -p
1350 ok $?
"Enable Python event $event_name for session $sess_name with loglevel $loglevel"
1353 function enable_ust_lttng_event_filter
()
1355 local sess_name
="$1"
1356 local event_name
="$2"
1358 local channel_name
=$4
1360 if [ -z $channel_name ]; then
1361 # default channel if none specified
1364 chan
="-c $channel_name"
1367 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1368 enable-event
$chan "$event_name" -s $sess_name -u --filter "$filter"
1369 ok $?
"Enable event $event_name with filtering for session $sess_name"
1372 function enable_ust_lttng_event_loglevel
()
1374 local sess_name
="$1"
1375 local event_name
="$2"
1378 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1379 enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel
1380 ok $?
"Enable event $event_name with loglevel $loglevel"
1383 function enable_ust_lttng_event_loglevel_only
()
1385 local sess_name
="$1"
1386 local event_name
="$2"
1389 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1390 enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel
1391 ok $?
"Enable event $event_name with loglevel-only $loglevel"
1394 function disable_ust_lttng_event
()
1396 local sess_name
="$1"
1397 local event_name
="$2"
1398 local channel_name
="$3"
1400 if [ -z $channel_name ]; then
1401 # default channel if none specified
1404 chan
="-c $channel_name"
1407 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1408 disable-event
"$event_name" -s $sess_name $chan -u
1409 ok $?
"Disable event $event_name for session $sess_name"
1412 function disable_jul_lttng_event
()
1414 local sess_name
="$1"
1415 local event_name
="$2"
1417 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
1418 ok $?
"Disable JUL event $event_name for session $sess_name"
1421 function disable_log4j_lttng_event
()
1423 local sess_name
="$1"
1424 local event_name
="$2"
1426 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -l >/dev
/null
2>&1
1427 ok $?
"Disable LOG4J event $event_name for session $sess_name"
1430 function disable_python_lttng_event
()
1432 local sess_name
="$1"
1433 local event_name
="$2"
1435 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1436 disable-event
"$event_name" -s $sess_name -p
1437 ok $?
"Disable Python event $event_name for session $sess_name"
1440 function start_lttng_tracing_opt
()
1443 local expected_to_fail
=$2
1446 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1449 if [[ $expected_to_fail -eq "1" ]]; then
1452 if [ $withtap -eq "1" ]; then
1453 ok $?
"Start tracing for session $sess_name failed as expected"
1456 if [ $withtap -eq "1" ]; then
1457 ok
$ret "Start tracing for session $sess_name"
1462 function start_lttng_tracing_ok
()
1464 start_lttng_tracing_opt
1 0 "$@"
1467 function start_lttng_tracing_fail
()
1469 start_lttng_tracing_opt
1 1 "$@"
1472 function start_lttng_tracing_notap
()
1474 start_lttng_tracing_opt
0 1 "$@"
1477 function stop_lttng_tracing_opt
()
1480 local expected_to_fail
=$2
1483 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1486 if [[ $expected_to_fail -eq "1" ]]; then
1489 if [ $withtap -eq "1" ]; then
1490 ok $?
"Stop lttng tracing for session $sess_name failed as expected"
1493 if [ $withtap -eq "1" ]; then
1494 ok
$ret "Stop lttng tracing for session $sess_name"
1499 function stop_lttng_tracing_ok
()
1501 stop_lttng_tracing_opt
1 0 "$@"
1504 function stop_lttng_tracing_fail
()
1506 stop_lttng_tracing_opt
1 1 "$@"
1509 function stop_lttng_tracing_notap
()
1511 stop_lttng_tracing_opt
0 0 "$@"
1514 function destroy_lttng_session
()
1517 local expected_to_fail
=$2
1520 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1523 if [[ $expected_to_fail -eq "1" ]]; then
1526 if [ $withtap -eq "1" ]; then
1527 ok
$ret "Destroy session $sess_name failed as expected"
1530 if [ $withtap -eq "1" ]; then
1531 ok
$ret "Destroy session $sess_name"
1536 function destroy_lttng_session_ok
()
1538 destroy_lttng_session
1 0 "$@"
1542 function destroy_lttng_session_fail
()
1544 destroy_lttng_session
1 1 "$@"
1547 function destroy_lttng_session_notap
()
1549 destroy_lttng_session
0 0 "$@"
1552 function destroy_lttng_sessions
()
1554 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1556 ok $?
"Destroy all lttng sessions"
1559 function lttng_snapshot_add_output
()
1561 local expected_to_fail
=$1
1566 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1567 snapshot add-output
-s $sess_name $trace_path $opts
1569 if [[ $expected_to_fail -eq 1 ]]; then
1571 ok $?
"Added snapshot output $trace_path failed as expected"
1573 ok
$ret "Added snapshot output $trace_path"
1577 function lttng_snapshot_add_output_ok
()
1579 lttng_snapshot_add_output
0 "$@"
1582 function lttng_snapshot_add_output_fail
()
1584 lttng_snapshot_add_output
1 "$@"
1587 function lttng_snapshot_del_output
()
1589 local expected_to_fail
=$1
1593 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1594 snapshot del-output
-s $sess_name $id
1596 if [[ $expected_to_fail -eq "1" ]]; then
1598 ok $?
"Deleted snapshot output id $id failed as expected"
1600 ok
$ret "Deleted snapshot output id $id"
1604 function lttng_snapshot_del_output_ok
()
1606 lttng_snapshot_del_output
0 "$@"
1609 function lttng_snapshot_del_output_fail
()
1611 lttng_snapshot_del_output
1 "$@"
1614 function lttng_snapshot_record
()
1619 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1620 snapshot record
-s "$sess_name" "$trace_path"
1621 ok $?
"Snapshot recorded"
1624 function lttng_snapshot_list
()
1627 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1628 snapshot list-output
-s $sess_name
1629 ok $?
"Snapshot list"
1632 function lttng_save
()
1637 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1638 save
$sess_name $opts
1639 ok $?
"Session saved"
1642 function lttng_load
()
1644 local expected_to_fail
=$1
1647 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1650 if [[ $expected_to_fail -eq "1" ]]; then
1652 ok $?
"Load command failed as expected with opts: $opts"
1654 ok
$ret "Load command with opts: $opts"
1658 function lttng_load_ok
()
1663 function lttng_load_fail
()
1668 function lttng_track
()
1670 local expected_to_fail
="$1"
1673 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN track
$opts >$OUTPUT_DEST
1675 if [[ $expected_to_fail -eq "1" ]]; then
1677 ok $?
"Track command failed as expected with opts: $opts"
1679 ok
$ret "Track command with opts: $opts"
1683 function lttng_track_ok
()
1688 function lttng_track_fail
()
1693 function lttng_untrack
()
1695 local expected_to_fail
="$1"
1698 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN untrack
$opts >$OUTPUT_DEST
1700 if [[ $expected_to_fail -eq "1" ]]; then
1702 ok $?
"Untrack command failed as expected with opts: $opts"
1704 ok
$ret "Untrack command with opts: $opts"
1708 function lttng_untrack_ok
()
1710 lttng_untrack
0 "$@"
1713 function lttng_untrack_fail
()
1715 lttng_untrack
1 "$@"
1718 function lttng_track_pid_ok
()
1721 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track
--kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1722 ok $?
"Lttng track pid on the kernel domain"
1725 function lttng_untrack_kernel_all_ok
()
1727 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack
--kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1728 ok $?
"Lttng untrack all pid on the kernel domain"
1731 function lttng_track_ust_ok
()
1733 lttng_track_ok
-u "$@"
1736 function lttng_track_ust_fail
()
1738 lttng_track_fail
-u "$@"
1741 function lttng_track_kernel_ok
()
1743 lttng_track_ok
-k "$@"
1746 function lttng_track_kernel_fail
()
1748 lttng_track_fail
-k "$@"
1751 function lttng_untrack_ust_ok
()
1753 lttng_untrack_ok
-u "$@"
1756 function lttng_untrack_ust_fail
()
1758 lttng_untrack_fail
-u "$@"
1761 function lttng_untrack_kernel_ok
()
1763 lttng_untrack_ok
-k "$@"
1766 function lttng_untrack_kernel_fail
()
1768 lttng_untrack_fail
-k "$@"
1771 function lttng_add_context_list
()
1773 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1776 ok
$ret "Context listing"
1779 function add_context_lttng
()
1781 local expected_to_fail
="$1"
1783 local session_name
="$3"
1784 local channel_name
="$4"
1787 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1788 add-context
-s $session_name -c $channel_name -t $type $domain
1790 if [[ $expected_to_fail -eq "1" ]]; then
1792 ok $?
"Add context command failed as expected for type: $type"
1794 ok
$ret "Add context command for type: $type"
1798 function add_context_ust_ok
()
1800 add_context_lttng
0 -u "$@"
1803 function add_context_ust_fail
()
1805 add_context_lttng
1 -u "$@"
1808 function add_context_kernel_ok
()
1810 add_context_lttng
0 -k "$@"
1813 function add_context_kernel_fail
()
1815 add_context_lttng
1 -k "$@"
1818 function wait_live_trace_ready
()
1821 local zero_client_match
=0
1823 diag
"Waiting for live trace at url: $url"
1824 while [ $zero_client_match -eq 0 ]; do
1825 zero_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "0 client(s) connected" |
wc -l)
1828 pass
"Waiting for live trace at url: $url"
1831 function wait_live_viewer_connect
()
1834 local one_client_match
=0
1836 diag
"Waiting for live viewers on url: $url"
1837 while [ $one_client_match -eq 0 ]; do
1838 one_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "1 client(s) connected" |
wc -l)
1841 pass
"Waiting for live viewers on url: $url"
1844 function bail_out_if_no_babeltrace
()
1846 which "$BABELTRACE_BIN" >/dev
/null
1847 if [ $?
-ne 0 ]; then
1848 LTTNG_BAIL_OUT
"\"$BABELTRACE_BIN\" binary not found. Skipping tests"
1852 function validate_metadata_event
()
1855 local nr_event_id
=$2
1858 local metadata_file
=$
(find $trace_path -name "metadata")
1859 local metadata_path
=$
(dirname $metadata_file)
1861 bail_out_if_no_babeltrace
1863 local count
=$
($BABELTRACE_BIN --output-format=ctf-metadata
$metadata_path |
grep $event_name |
wc -l)
1865 if [ "$count" -ne "$nr_event_id" ]; then
1866 fail
"Metadata match with the metadata of $count event(s) named $event_name"
1867 diag
"$count matching event id found in metadata"
1869 pass
"Metadata match with the metadata of $count event(s) named $event_name"
1874 function trace_matches
()
1880 bail_out_if_no_babeltrace
1882 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1884 if [ "$count" -ne "$nr_iter" ]; then
1886 diag
"$count matching events found in trace"
1892 function trace_match_only
()
1898 bail_out_if_no_babeltrace
1899 #which "$BABELTRACE_BIN" >/dev/null
1900 #skip $? -ne 0 "\"$BABELTRACE_BIN\" binary not found. Skipping trace comparison"
1902 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1903 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1905 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1906 pass
"Trace match with $total event $event_name"
1909 diag
"$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1913 function validate_trace
1918 bail_out_if_no_babeltrace
1922 for i
in $event_name; do
1923 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1924 if [ "$traced" -ne 0 ]; then
1925 pass
"Validate trace for event $i, $traced events"
1927 fail
"Validate trace for event $i"
1928 diag
"Found $traced occurrences of $i"
1936 function validate_trace_count
1940 local expected_count
=$3
1942 bail_out_if_no_babeltrace
1947 for i
in $event_name; do
1948 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1949 if [ "$traced" -ne 0 ]; then
1950 pass
"Validate trace for event $i, $traced events"
1952 fail
"Validate trace for event $i"
1953 diag
"Found $traced occurrences of $i"
1955 cnt
=$
(($cnt + $traced))
1958 test $cnt -eq $expected_count
1959 ok $?
"Read a total of $cnt events, expected $expected_count"
1962 function validate_trace_count_range_incl_min_excl_max
1966 local expected_min
=$3
1967 local expected_max
=$4
1969 bail_out_if_no_babeltrace
1974 for i
in $event_name; do
1975 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1976 if [ "$traced" -ge $expected_min ]; then
1977 pass
"Validate trace for event $i, $traced events"
1979 fail
"Validate trace for event $i"
1980 diag
"Found $traced occurrences of $i"
1982 cnt
=$
(($cnt + $traced))
1985 test $cnt -lt $expected_max
1986 ok $?
"Read a total of $cnt events, expected between [$expected_min, $expected_max["
1989 function trace_first_line
1993 $BABELTRACE_BIN $trace_path 2>/dev
/null |
head -n 1
1996 function validate_trace_exp
()
2001 bail_out_if_no_babeltrace
2003 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep --extended-regexp ${event_exp} |
wc -l)
2004 if [ "$traced" -ne 0 ]; then
2005 pass
"Validate trace for expression '${event_exp}', $traced events"
2007 fail
"Validate trace for expression '${event_exp}'"
2008 diag
"Found $traced occurrences of '${event_exp}'"
2014 function validate_trace_only_exp
()
2019 bail_out_if_no_babeltrace
2021 local count
=$
($BABELTRACE_BIN $trace_path |
grep --extended-regexp ${event_exp} |
wc -l)
2022 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
2024 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
2025 pass
"Trace match with $total for expression '${event_exp}'"
2028 diag
"$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
2034 function validate_trace_empty
()
2038 bail_out_if_no_babeltrace
2040 events
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null
)
2042 if [ $ret -ne 0 ]; then
2043 fail
"Failed to parse trace"
2047 traced
=$
(echo -n "$events" |
wc -l)
2048 if [ "$traced" -eq 0 ]; then
2049 pass
"Validate empty trace"
2051 fail
"Validate empty trace"
2052 diag
"Found $traced events in trace"
2058 function validate_directory_empty
()
2060 local trace_path
="$1"
2062 # Do not double quote `$trace_path` below as we want wildcards to be
2064 files
="$(ls -A $trace_path)"
2066 if [ $ret -ne 0 ]; then
2067 fail
"Failed to list content of directory \"$trace_path\""
2071 nb_files
="$(echo -n "$files" | wc -l)"
2072 ok
$nb_files "Directory \"$trace_path\" is empty"
2075 function validate_trace_session_ust_empty
()
2077 validate_directory_empty
"$1"/ust
2080 function validate_trace_session_kernel_empty
()
2082 validate_trace_empty
"$1"/kernel
2085 function regenerate_metadata
()
2087 local expected_to_fail
=$1
2090 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2091 regenerate metadata
-s $sess_name
2093 if [[ $expected_to_fail -eq "1" ]]; then
2095 ok $?
"Expected fail on regenerate metadata $sess_name"
2097 ok
$ret "Metadata regenerate $sess_name"
2101 function regenerate_metadata_ok
()
2103 regenerate_metadata
0 "$@"
2106 function regenerate_metadata_fail
()
2108 regenerate_metadata
1 "$@"
2111 function regenerate_statedump
()
2113 local expected_to_fail
=$1
2116 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2117 regenerate statedump
-s $sess_name
2119 if [[ $expected_to_fail -eq "1" ]]; then
2121 ok $?
"Expected fail on regenerate statedump $sess_name"
2123 ok
$ret "Statedump regenerate $sess_name"
2127 function regenerate_statedump_ok
()
2129 regenerate_statedump
0 "$@"
2132 function regenerate_statedump_fail
()
2134 regenerate_statedump
1 "$@"
2137 function rotate_session
()
2139 local expected_to_fail
=$1
2142 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2145 if [[ $expected_to_fail -eq "1" ]]; then
2147 ok $?
"Expected fail on rotate session $sess_name"
2149 ok
$ret "Rotate session $sess_name"
2153 function rotate_session_ok
()
2155 rotate_session
0 "$@"
2158 function rotate_session_fail
()
2160 rotate_session
1 "$@"
2163 function destructive_tests_enabled
()
2165 if [ "$LTTNG_ENABLE_DESTRUCTIVE_TESTS" = "will-break-my-system" ]; then
2172 function lttng_enable_rotation_timer
()
2174 local expected_to_fail
=$1
2178 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2179 enable-rotation
-s $sess_name --timer $period
2181 if [[ $expected_to_fail -eq "1" ]]; then
2183 ok $?
"Expected fail when setting periodic rotation ($period) of session $sess_name"
2185 ok
$ret "Set periodic rotation ($period) of session $sess_name"
2189 function lttng_enable_rotation_timer_ok
()
2191 lttng_enable_rotation_timer
0 $@
2194 function lttng_enable_rotation_timer_fail
()
2196 lttng_enable_rotation_timer
1 $@
2199 function lttng_enable_rotation_size
()
2201 local expected_to_fail
=$1
2205 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2206 enable-rotation
-s $sess_name --size $size
2208 if [[ $expected_to_fail -eq "1" ]]; then
2210 ok $?
"Expected fail on rotate session $sess_name"
2212 ok
$ret "Rotate session $sess_name"
2216 function lttng_enable_rotation_size_ok
()
2218 lttng_enable_rotation_size
0 $@
2221 function lttng_enable_rotation_size_fail
()
2223 lttng_enable_rotation_size
1 $@
2226 function lttng_clear_session
()
2228 local expected_to_fail
=$1
2231 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2234 if [[ $expected_to_fail -eq "1" ]]; then
2236 ok $?
"Expected fail on clear session $sess_name"
2238 ok
$ret "Clear session $sess_name"
2242 function lttng_clear_session_ok
()
2244 lttng_clear_session
0 $@
2247 function lttng_clear_session_fail
()
2249 lttng_clear_session
1 $@
2252 function lttng_clear_all
()
2254 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2256 ok $?
"Clear all lttng sessions"
2259 function lttng_add_trigger
()
2261 local expected_to_fail
="$1"
2262 local trigger_name
="$2"
2266 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN add-trigger --name $trigger_name ${args[*]}"
2267 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-trigger
--name "$trigger_name" "${args[@]}" 1> /dev
/null
2> /dev
/null
2269 if [[ $expected_to_fail -eq "1" ]]; then
2271 ok $?
"Add trigger $trigger_name failed as expected"
2273 ok
$ret "Add trigger $trigger_name"
2277 function lttng_remove_trigger
()
2279 local expected_to_fail
="$1"
2280 local trigger_name
="$2"
2283 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN remove-trigger $trigger_name $*"
2284 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" remove-trigger
"$trigger_name" "$@" 1> /dev
/null
2> /dev
/null
2286 if [[ $expected_to_fail -eq "1" ]]; then
2288 ok $?
"Remove trigger $trigger_name failed as expected"
2290 ok
$ret "Remove trigger $trigger_name"
2294 function lttng_add_trigger_ok
()
2296 lttng_add_trigger
0 "$@"
2299 function lttng_add_trigger_fail
()
2301 lttng_add_trigger
1 "$@"
2304 function lttng_remove_trigger_ok
()
2306 lttng_remove_trigger
0 "$@"
2309 function list_triggers_matches_ok
()
2311 local tmp_stdout
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2312 local tmp_stderr
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stderr.XXXXXX")
2314 local test_name
="$1"
2315 local expected_stdout_file
="$2"
2317 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN list-triggers"
2319 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" list-triggers
> "${tmp_stdout}" 2> "${tmp_stderr}"
2320 ok $?
"${test_name}: exit code is 0"
2322 diff -u "${expected_stdout_file}" "${tmp_stdout}"
2323 ok $?
"${test_name}: expected stdout"
2325 diff -u /dev
/null
"${tmp_stderr}"
2326 ok $?
"${test_name}: expected stderr"
2328 rm -f "${tmp_stdout}"
2329 rm -f "${tmp_stderr}"
2332 function list_triggers_matches_mi_ok
()
2335 local tmp_stdout_raw
2338 local test_name
="$1"
2339 local expected_stdout_file
="$2"
2341 tmp_stdout_raw
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2342 tmp_stdout
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2343 tmp_stderr
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stderr.XXXXXX")
2345 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi xml list-triggers"
2347 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" --mi=xml list-triggers
> "${tmp_stdout_raw}" 2> "${tmp_stderr}"
2348 ok $?
"${test_name}: exit code is 0"
2350 # Pretty-fy xml before further test.
2351 $XML_PRETTY < "${tmp_stdout_raw}" > "${tmp_stdout}"
2353 $MI_VALIDATE "${tmp_stdout}"
2354 ok $?
"list-trigger mi is valid"
2356 diff -u "${expected_stdout_file}" "${tmp_stdout}"
2357 ok $?
"${test_name}: expected stdout"
2359 diff -u /dev
/null
"${tmp_stderr}"
2360 ok $?
"${test_name}: expected stderr"
2362 rm -f "${tmp_stdout}"
2363 rm -f "${tmp_stdout_raw}"
2364 rm -f "${tmp_stderr}"
2367 function validate_path_pattern
()
2371 # Base path is only used in error case and is used to list the content
2380 if [ "$ret" -ne "0" ]; then
2381 diag
"Path pattern expected: $pattern"
2382 # List the tracepath for more info. We use find as a recursive
2384 diag
"The base path content:"
2385 find "$base_path" -print
2389 function validate_trace_path_ust_uid
()
2392 local session_name
=$2
2394 local pattern
="$trace_path/$session_name-$date_time_pattern/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2396 validate_path_pattern
"UST per-uid trace path is valid" "$pattern" "$trace_path"
2399 function validate_trace_path_ust_uid_network
()
2402 local session_name
=$2
2405 local hostname
=$HOSTNAME
2409 # If the session was given a network base path (e.g
2410 # 127.0.0.1/my/custom/path on creation, there is no session name
2411 # component to the path on the relayd side. Caller can simply not pass a
2412 # session name for this scenario.
2413 if [ -n "$session_name" ]; then
2414 session_name
="$session_name-$date_time_pattern"
2415 if [ -n "$base_path" ]; then
2416 fail
"Session name and base path are mutually exclusive"
2421 pattern
="$trace_path/$hostname/$base_path/$session_name/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2423 validate_path_pattern
"UST per-uid network trace path is valid" "$pattern" "$trace_path"
2426 function validate_trace_path_ust_uid_snapshot_network
()
2429 local session_name
=$2
2430 local snapshot_name
=$3
2431 local snapshot_number
=$4
2433 local hostname
=$HOSTNAME
2438 # If the session/output was given a network base path (e.g
2439 # 127.0.0.1/my/custom/path on creation, there is no session name
2440 # component to the path on the relayd side. Caller can simply not pass a
2441 # session name for this scenario.
2442 if [ -n "$session_name" ]; then
2443 session_name
="$session_name-$date_time_pattern"
2444 if [ -n "$base_path" ]; then
2445 fail
"Session name and base path are mutually exclusive"
2450 pattern
="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2452 validate_path_pattern
"UST per-uid network snapshot trace path is valid" "$pattern" "$trace_path"
2455 function validate_trace_path_ust_uid_snapshot
()
2458 local session_name
=$2
2459 local snapshot_name
=$3
2460 local snapshot_number
=$4
2466 # If the session/output was given a network base path (e.g
2467 # 127.0.0.1/my/custom/path) on creation, there is no session name
2468 # component to the path on the relayd side. Caller can simply not pass a
2469 # session name for this scenario.
2470 if [ -n "$session_name" ]; then
2471 session_name
="$session_name-$date_time_pattern"
2472 if [ -n "$base_path" ]; then
2473 fail
"Session name and base path are mutually exclusive"
2478 pattern
="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2480 validate_path_pattern
"UST per-uid snapshot trace path is valid" "$pattern" "$trace_path"
2483 function validate_trace_path_ust_pid
()
2486 local session_name
=$2
2492 # If the session was given a trace path on creation, there is no session
2493 # name component to the path. Caller can simply not pass a session name
2494 # for this scenario.
2495 if [ -n "$session_name" ]; then
2496 session_name
="$session_name-$date_time_pattern"
2499 pattern
="$trace_path/$session_name/ust/pid/$pid/$app_string-*-$date_time_pattern/metadata"
2501 validate_path_pattern
"UST per-pid trace path is valid" "$pattern" "$trace_path"
2504 function validate_trace_path_kernel
()
2507 local session_name
=$2
2510 # If the session was given a trace path on creation, there is no session
2511 # name component to the path. Caller can simply not pass a session name
2512 # for this scenario.
2513 if [ -n "$session_name" ]; then
2514 session_name
="$session_name-$date_time_pattern"
2517 pattern
="$trace_path/$session_name/kernel/metadata"
2519 validate_path_pattern
"Kernel trace path is valid" "$pattern" "$trace_path"
2522 function validate_trace_path_kernel_network
()
2525 local session_name
=$2
2526 local hostname
=$HOSTNAME
2527 local pattern
="$trace_path/$hostname/$session_name-$date_time_pattern/kernel/metadata"
2529 validate_path_pattern
"Kernel network trace path is valid" "$pattern" "$trace_path"
2532 function validate_trace_path_kernel_snapshot
()
2535 local session_name
=$2
2536 local snapshot_name
=$3
2537 local snapshot_number
=$4
2542 # If the session/output was given a network base path (e.g
2543 # 127.0.0.1/my/custom/path on creation, there is no session name
2544 # component to the path on the relayd side. Caller can simply not pass a
2545 # session name for this scenario.
2546 if [ -n "$session_name" ]; then
2547 session_name
="$session_name-$date_time_pattern"
2548 if [ -n "$base_path" ]; then
2549 fail
"Session name and base path are mutually exclusive"
2554 pattern
="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata"
2556 validate_path_pattern
"Kernel snapshot trace path is valid" "$pattern" "$trace_path"
2559 function validate_trace_path_kernel_snapshot_network
()
2562 local session_name
=$2
2563 local snapshot_name
=$3
2564 local snapshot_number
=$4
2566 local hostname
=$HOSTNAME
2570 # If the session/output was given a network base path (e.g
2571 # 127.0.0.1/my/custom/path on creation, there is no session name
2572 # component to the path on the relayd side. Caller can simply not pass a
2573 # session name for this scenario.
2574 if [ -n "$session_name" ]; then
2575 session_name
="$session_name-$date_time_pattern"
2576 if [ -n "$base_path" ]; then
2577 fail
"Session name and base path are mutually exclusive"
2582 pattern
="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata"
2584 validate_path_pattern
"Kernel network snapshot trace path is valid" "$pattern" "$trace_path"