1 # Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
3 # SPDX-License-Identifier: LGPL-2.1-only
6 SESSIOND_BIN
="lttng-sessiond"
7 SESSIOND_MATCH
=".*lttng-sess.*"
8 RUNAS_BIN
="lttng-runas"
9 RUNAS_MATCH
=".*lttng-runas.*"
10 CONSUMERD_BIN
="lttng-consumerd"
11 CONSUMERD_MATCH
=".*lttng-consumerd.*"
12 RELAYD_BIN
="lttng-relayd"
13 RELAYD_MATCH
=".*lttng-relayd.*"
15 BABELTRACE_BIN
="babeltrace"
17 ERROR_OUTPUT_DEST
=/dev
/null
19 # To match 20201127-175802
20 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]"
21 # The size of a long on this system
22 system_long_bit_size
=$
(getconf LONG_BIT
)
24 # Minimal kernel version supported for session daemon tests
25 KERNEL_MAJOR_VERSION
=2
26 KERNEL_MINOR_VERSION
=6
27 KERNEL_PATCHLEVEL_VERSION
=27
29 # We set the default UST register timeout and network and app socket timeout to
30 # "wait forever", so that basic tests don't have to worry about hitting
31 # timeouts on busy systems. Specialized tests should test those corner-cases.
32 export LTTNG_UST_REGISTER_TIMEOUT
=-1
33 export LTTNG_NETWORK_SOCKET_TIMEOUT
=-1
34 export LTTNG_APP_SOCKET_TIMEOUT
=-1
36 # We set the default lttng-sessiond path to /bin/true to prevent the spawning
37 # of a daemonized sessiond. This is necessary since 'lttng create' will spawn
38 # its own sessiond if none is running. It also ensures that 'lttng create'
39 # fails when no sessiond is running.
40 export LTTNG_SESSIOND_PATH
="/bin/true"
42 source $TESTDIR/utils
/tap
/tap.sh
44 if [ -z ${LTTNG_TEST_TEARDOWN_TIMEOUT+x} ]; then
45 LTTNG_TEST_TEARDOWN_TIMEOUT
=60
48 # Enable job monitor mode.
49 # Here we are mostly interested in the following from the monitor mode:
50 # All processes run in a separate process group.
51 # This allows us to ensure that all subprocesses from all background tasks are
52 # cleaned up correctly using signal to process group id.
55 kill_background_jobs
()
60 if [ -z "$pids" ]; then
67 # Use negative number to send the signal to the process group.
68 # This ensure that any subprocesses receive the signal.
69 # /dev/null is used since there is an acceptable race between
70 # the moments the pids are listed and the moment we send a
72 kill -SIGTERM -- "-$pid" 2>/dev
/null
78 # Try to kill daemons gracefully
79 stop_lttng_relayd_cleanup SIGTERM
$LTTNG_TEST_TEARDOWN_TIMEOUT
80 stop_lttng_sessiond_cleanup SIGTERM
$LTTNG_TEST_TEARDOWN_TIMEOUT
82 # If daemons are still present, forcibly kill them
83 stop_lttng_relayd_cleanup SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
84 stop_lttng_sessiond_cleanup SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
85 stop_lttng_consumerd_cleanup SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
90 function full_cleanup
()
96 function LTTNG_BAIL_OUT
()
102 function null_pipes
()
109 trap full_cleanup SIGINT SIGTERM
111 # perl prove closes its child pipes before giving it a chance to run its
112 # signal trap handlers. Redirect pipes to /dev/null if SIGPIPE is caught
113 # to allow those trap handlers to proceed.
115 trap null_pipes SIGPIPE
117 # Check pgrep from env, default to pgrep if none
118 if [ -z "$PGREP" ]; then
122 # Due to the renaming of threads we need to use the full command (pgrep -f) to
123 # identify the pids for multiple lttng related processes. The problem with "pgrep
124 # -f" is that it ends up also looking at the arguments. We use a two stage
125 # lookup. The first one is using "pgrep -f" yielding potential candidate.
126 # The second on perform grep on the basename of the first field of the
127 # /proc/pid/cmdline of the previously identified pids. The first field
128 # correspond to the actual command.
129 function lttng_pgrep
()
133 local full_command_no_argument
134 local command_basename
136 possible_pids
=$
($PGREP -f "$pattern")
137 if [ -z "$possible_pids" ]; then
141 while IFS
= read -r pid
; do
142 # /proc/pid/cmdline is null separated.
143 if full_command_no_argument
=$
(cut
-d '' -f 1 2>/dev
/null
< /proc
/"$pid"/cmdline
); then
144 command_basename
=$
(basename "$full_command_no_argument")
145 if grep -q "$pattern" <<< "$command_basename"; then
149 done <<< "$possible_pids"
155 # Check if we are a terminal
157 echo -e "\e[1;32mOK\e[0m"
163 function print_fail
()
165 # Check if we are a terminal
167 echo -e "\e[1;31mFAIL\e[0m"
173 function print_test_banner
()
179 function validate_kernel_version
()
181 local kern_version
=($
(uname
-r |
awk -F.
'{ printf("%d.%d.%d\n",$1,$2,$3); }' |
tr '.' '\n'))
182 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
185 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
188 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
194 # Generate a random string
195 # $1 = number of characters; defaults to 16
196 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
197 function randstring
()
199 [ "$2" == "0" ] && CHAR
="[:alnum:]" || CHAR
="[:graph:]"
200 cat /dev
/urandom
2>/dev
/null |
tr -cd "$CHAR" 2>/dev
/null |
head -c ${1:-16} 2>/dev
/null
204 # Return the number of _configured_ CPUs.
205 function conf_proc_count
()
207 getconf _NPROCESSORS_CONF
208 if [ $?
-ne 0 ]; then
209 diag
"Failed to get the number of configured CPUs"
214 # Check if base lttng-modules are present.
215 # Bail out on failure
216 function validate_lttng_modules_present
()
218 # Check for loadable modules.
219 modprobe
-n lttng-tracer
2>/dev
/null
220 if [ $?
-eq 0 ]; then
224 # Check for builtin modules.
225 ls /proc
/lttng
> /dev
/null
2>&1
226 if [ $?
-eq 0 ]; then
230 LTTNG_BAIL_OUT
"LTTng modules not detected."
233 function enable_kernel_lttng_event
236 local expected_to_fail
="$2"
238 local event_name
="$4"
239 local channel_name
="$5"
241 if [ -z "$event_name" ]; then
242 # Enable all event if no event name specified
246 if [ -z "$channel_name" ]; then
247 # default channel if none specified
250 chan
="-c $channel_name"
253 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
255 if [[ $expected_to_fail -eq "1" ]]; then
258 if [ $withtap -eq "1" ]; then
259 ok
$ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
262 if [ $withtap -eq "1" ]; then
263 ok
$ret "Enable kernel event $event_name for session $sess_name"
268 function enable_kernel_lttng_event_ok
()
270 enable_kernel_lttng_event
1 0 "$@"
273 function enable_kernel_lttng_event_fail
()
275 enable_kernel_lttng_event
1 1 "$@"
278 function enable_kernel_lttng_event_notap
()
280 enable_kernel_lttng_event
0 0 "$@"
284 function lttng_enable_kernel_event
286 enable_kernel_lttng_event_ok
"$@"
289 function lttng_enable_kernel_syscall
()
291 local expected_to_fail
=$1
293 local syscall_name
=$3
294 local channel_name
=$4
296 if [ -z $syscall_name ]; then
297 # Enable all event if no syscall name specified
301 if [ -z $channel_name ]; then
302 # default channel if none specified
305 chan
="-c $channel_name"
308 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
310 if [[ $expected_to_fail -eq "1" ]]; then
312 ok $?
"Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
314 ok
$ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
318 function lttng_enable_kernel_syscall_ok
()
320 lttng_enable_kernel_syscall
0 "$@"
323 function lttng_enable_kernel_syscall_fail
()
325 lttng_enable_kernel_syscall
1 "$@"
328 function lttng_disable_kernel_syscall
()
330 local expected_to_fail
=$1
332 local syscall_name
=$3
333 local channel_name
=$4
335 if [ -z $syscall_name ]; then
336 # Enable all event if no syscall name specified
340 if [ -z $channel_name ]; then
341 # default channel if none specified
344 chan
="-c $channel_name"
347 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
350 if [[ $expected_to_fail -eq "1" ]]; then
352 ok $?
"Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
354 ok
$ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
358 function lttng_disable_kernel_syscall_ok
()
360 lttng_disable_kernel_syscall
0 "$@"
363 function lttng_disable_kernel_syscall_fail
()
365 lttng_disable_kernel_syscall
1 "$@"
368 function lttng_enable_kernel_function_event
()
370 local expected_to_fail
="$1"
373 local event_name
="$4"
375 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
--kernel --function="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
377 if [[ $expected_to_fail -eq "1" ]]; then
379 ok $?
"Enable kernel function event for session $sess_name failed as expected"
381 ok
$ret "Enable kernel function event for session $sess_name"
385 function lttng_enable_kernel_function_event_ok
()
387 lttng_enable_kernel_function_event
0 "$@"
390 function lttng_enable_kernel_userspace_probe_event
()
392 local expected_to_fail
="$1"
395 local event_name
="$4"
397 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
--kernel --userspace-probe="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
399 if [[ $expected_to_fail -eq "1" ]]; then
401 ok $?
"Enable kernel userspace probe event for session $sess_name failed as expected"
403 ok
$ret "Enable kernel userspace probe event for session $sess_name"
407 function lttng_enable_kernel_userspace_probe_event_fail
()
409 lttng_enable_kernel_userspace_probe_event
1 "$@"
412 function lttng_enable_kernel_userspace_probe_event_ok
()
414 lttng_enable_kernel_userspace_probe_event
0 "$@"
417 function disable_kernel_lttng_userspace_probe_event_ok
()
420 local event_name
="$2"
422 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" disable-event
--kernel "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
423 ok $?
"Disable kernel event $target for session $sess_name"
425 function lttng_enable_kernel_channel
()
428 local expected_to_fail
=$2
430 local channel_name
=$4
433 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-k $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
435 if [[ $expected_to_fail -eq "1" ]]; then
438 if [ $withtap -eq "1" ]; then
439 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
442 if [ $withtap -eq "1" ]; then
443 ok
$ret "Enable channel $channel_name for session $sess_name"
448 function lttng_enable_kernel_channel_ok
()
450 lttng_enable_kernel_channel
1 0 "$@"
453 function lttng_enable_kernel_channel_fail
()
455 lttng_enable_kernel_channel
1 1 "$@"
458 function lttng_enable_kernel_channel_notap
()
460 lttng_enable_kernel_channel
0 0 "$@"
463 function enable_kernel_lttng_channel_ok
()
465 lttng_enable_kernel_channel
1 0 "$@"
468 function lttng_disable_kernel_channel
()
470 local expected_to_fail
=$1
472 local channel_name
=$3
474 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
476 if [[ $expected_to_fail -eq "1" ]]; then
478 ok $?
"Disable channel $channel_name for session $sess_name failed as expected"
480 ok
$ret "Disable channel $channel_name for session $sess_name"
484 function lttng_disable_kernel_channel_ok
()
486 lttng_disable_kernel_channel
0 "$@"
489 function lttng_disable_kernel_channel_fail
()
491 lttng_disable_kernel_channel
1 "$@"
494 function start_lttng_relayd_opt
()
497 local process_mode
=$2
500 DIR
=$
(readlink
-f "$TESTDIR")
502 if [ -z $
(lttng_pgrep
"$RELAYD_MATCH") ]; then
503 # shellcheck disable=SC2086
504 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
505 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
506 if [ $?
-eq 1 ]; then
507 if [ $withtap -eq "1" ]; then
508 fail
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
512 if [ $withtap -eq "1" ]; then
513 pass
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
517 pass
"Start lttng-relayd (opt: $opt)"
521 function start_lttng_relayd
()
523 start_lttng_relayd_opt
1 "-b" "$@"
526 function start_lttng_relayd_notap
()
528 start_lttng_relayd_opt
0 "-b" "$@"
531 function stop_lttng_relayd_opt
()
541 if [ -z "$signal" ]; then
546 # Multiply time by 2 to simplify integer arithmetic
547 if [ -n "$timeout_s" ]; then
548 dtimeleft_s
=$
((timeout_s
* 2))
552 pids
=$
(lttng_pgrep
"$RELAYD_MATCH")
553 if [ -z "$pids" ]; then
554 if [ "$is_cleanup" -eq 1 ]; then
556 elif [ "$withtap" -eq "1" ]; then
557 fail
"No relay daemon to kill"
559 LTTNG_BAIL_OUT
"No relay daemon to kill"
564 diag
"Killing (signal $signal) lttng-relayd (pid: $pids)"
566 # shellcheck disable=SC2086
567 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
569 if [ "$withtap" -eq "1" ]; then
570 fail
"Kill relay daemon"
574 while [ -n "$out" ]; do
575 out
=$
(lttng_pgrep
"$RELAYD_MATCH")
576 if [ -n "$dtimeleft_s" ]; then
577 if [ $dtimeleft_s -lt 0 ]; then
581 dtimeleft_s
=$
((dtimeleft_s
- 1))
585 if [ "$withtap" -eq "1" ]; then
586 if [ "$retval" -eq "0" ]; then
587 pass
"Wait after kill relay daemon"
589 fail
"Wait after kill relay daemon"
596 function stop_lttng_relayd
()
598 stop_lttng_relayd_opt
1 0 "$@"
601 function stop_lttng_relayd_notap
()
603 stop_lttng_relayd_opt
0 0 "$@"
606 function stop_lttng_relayd_cleanup
()
608 stop_lttng_relayd_opt
0 1 "$@"
611 #First arg: show tap output
612 #Second argument: load path for automatic loading
613 function start_lttng_sessiond_opt
()
618 # The rest of the arguments will be passed directly to lttng-sessiond.
624 local long_bit_value
=
625 long_bit_value
=$
(getconf LONG_BIT
)
627 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
628 # Env variable requested no session daemon
632 DIR
=$
(readlink
-f "$TESTDIR")
634 # Get long_bit value for 32/64 consumerd
635 case "$long_bit_value" in
637 consumerd
="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
640 consumerd
="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
647 # Check for env. variable. Allow the use of LD_PRELOAD etc.
648 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
649 env_vars
="${LTTNG_SESSIOND_ENV_VARS} "
651 env_vars
="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN"
653 if ! validate_kernel_version
; then
654 fail
"Start session daemon"
655 LTTNG_BAIL_OUT
"*** Kernel too old for session daemon tests ***"
658 : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}"
659 export LTTNG_SESSION_CONFIG_XSD_PATH
661 if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ]; then
663 if [ -n "$load_path" ]; then
664 # shellcheck disable=SC2086
665 env
$env_vars --load "$load_path" --background "$consumerd" "$@"
667 # shellcheck disable=SC2086
668 env
$env_vars --background "$consumerd" "$@"
670 #$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
672 if [ "$withtap" -eq "1" ]; then
673 ok
$status "Start session daemon"
678 function start_lttng_sessiond
()
680 start_lttng_sessiond_opt
1 "$@"
683 function start_lttng_sessiond_notap
()
685 start_lttng_sessiond_opt
0 "$@"
688 function stop_lttng_sessiond_opt
()
699 if [ -z "$signal" ]; then
703 # Multiply time by 2 to simplify integer arithmetic
704 if [ -n "$timeout_s" ]; then
705 dtimeleft_s
=$
((timeout_s
* 2))
708 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
709 # Env variable requested no session daemon
713 runas_pids
=$
(lttng_pgrep
"$RUNAS_MATCH")
714 pids
=$
(lttng_pgrep
"$SESSIOND_MATCH")
716 if [ -n "$runas_pids" ]; then
717 pids
="$pids $runas_pids"
720 if [ -z "$pids" ]; then
721 if [ "$is_cleanup" -eq 1 ]; then
723 elif [ "$withtap" -eq "1" ]; then
724 fail
"No session daemon to kill"
726 LTTNG_BAIL_OUT
"No session daemon to kill"
731 diag
"Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
733 # shellcheck disable=SC2086
734 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
736 if [ "$withtap" -eq "1" ]; then
737 fail
"Kill sessions daemon"
741 while [ -n "$out" ]; do
742 out
=$
(lttng_pgrep
"${SESSIOND_MATCH}")
743 if [ -n "$dtimeleft_s" ]; then
744 if [ $dtimeleft_s -lt 0 ]; then
748 dtimeleft_s
=$
((dtimeleft_s
- 1))
753 while [ -n "$out" ]; do
754 out
=$
(lttng_pgrep
"$CONSUMERD_MATCH")
755 if [ -n "$dtimeleft_s" ]; then
756 if [ $dtimeleft_s -lt 0 ]; then
760 dtimeleft_s
=$
((dtimeleft_s
- 1))
765 if [ "$withtap" -eq "1" ]; then
766 if [ "$retval" -eq "0" ]; then
767 pass
"Wait after kill session daemon"
769 fail
"Wait after kill session daemon"
773 if [ "$signal" = "SIGKILL" ]; then
774 if [ "$(id -u)" -eq "0" ]; then
776 modules
="$(lsmod | grep ^lttng | awk '{print $1}')"
778 if [ -n "$modules" ]; then
779 diag
"Unloading all LTTng modules"
780 modprobe
--remove "$modules"
788 function stop_lttng_sessiond
()
790 stop_lttng_sessiond_opt
1 0 "$@"
793 function stop_lttng_sessiond_notap
()
795 stop_lttng_sessiond_opt
0 0 "$@"
798 function stop_lttng_sessiond_cleanup
()
800 stop_lttng_sessiond_opt
0 1 "$@"
803 function sigstop_lttng_sessiond_opt
()
809 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
810 # Env variable requested no session daemon
814 pids
="$(lttng_pgrep "${SESSIOND_MATCH}") $(lttng_pgrep "$RUNAS_MATCH")"
816 if [ "$withtap" -eq "1" ]; then
817 diag
"Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
820 # shellcheck disable=SC2086
821 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
822 if [ "$withtap" -eq "1" ]; then
823 fail
"Sending SIGSTOP to session daemon"
827 while [ $out -ne 0 ]; do
828 pids
="$(lttng_pgrep "$SESSIOND_MATCH")"
830 # Wait until state becomes stopped for session
833 for sessiond_pid
in $pids; do
834 state
="$(ps -p "$sessiond_pid" -o state= )"
835 if [[ -n "$state" && "$state" != "T" ]]; then
841 if [ "$withtap" -eq "1" ]; then
842 pass
"Sending SIGSTOP to session daemon"
847 function sigstop_lttng_sessiond
()
849 sigstop_lttng_sessiond_opt
1 "$@"
852 function sigstop_lttng_sessiond_notap
()
854 sigstop_lttng_sessiond_opt
0 "$@"
857 function stop_lttng_consumerd_opt
()
867 if [ -z "$signal" ]; then
871 # Multiply time by 2 to simplify integer arithmetic
872 if [ -n "$timeout_s" ]; then
873 dtimeleft_s
=$
((timeout_s
* 2))
876 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
878 if [ -z "$pids" ]; then
879 if [ "$is_cleanup" -eq 1 ]; then
881 elif [ "$withtap" -eq "1" ]; then
882 fail
"No consumerd daemon to kill"
884 LTTNG_BAIL_OUT
"No consumerd daemon to kill"
889 diag
"Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')"
891 # shellcheck disable=SC2086
892 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
894 if [ "$withtap" -eq "1" ]; then
895 fail
"Kill consumer daemon"
899 while [ $out -ne 0 ]; do
900 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
902 # If consumerds are still present check their status.
903 # A zombie status qualifies the consumerd as *killed*
905 for consumer_pid
in $pids; do
906 state
="$(ps -p "$consumer_pid" -o state= )"
907 if [[ -n "$state" && "$state" != "Z" ]]; then
911 if [ -n "$dtimeleft_s" ]; then
912 if [ $dtimeleft_s -lt 0 ]; then
916 dtimeleft_s
=$
((dtimeleft_s
- 1))
920 if [ "$withtap" -eq "1" ]; then
921 if [ "$retval" -eq "0" ]; then
922 pass
"Wait after kill consumer daemon"
924 fail
"Wait after kill consumer daemon"
932 function stop_lttng_consumerd
()
934 stop_lttng_consumerd_opt
1 0 "$@"
937 function stop_lttng_consumerd_notap
()
939 stop_lttng_consumerd_opt
0 0 "$@"
942 function stop_lttng_consumerd_cleanup
()
944 stop_lttng_consumerd_opt
0 1 "$@"
947 function sigstop_lttng_consumerd_opt
()
953 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
955 diag
"Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')"
957 # shellcheck disable=SC2086
958 kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
961 if [ $retval -eq 1 ]; then
962 if [ "$withtap" -eq "1" ]; then
963 fail
"Sending SIGSTOP to consumer daemon"
968 while [ $out -ne 0 ]; do
969 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
971 # Wait until state becomes stopped for all
974 for consumer_pid
in $pids; do
975 state
="$(ps -p "$consumer_pid" -o state= )"
976 if [[ -n "$state" && "$state" != "T" ]]; then
982 if [ "$withtap" -eq "1" ]; then
983 pass
"Sending SIGSTOP to consumer daemon"
989 function sigstop_lttng_consumerd
()
991 sigstop_lttng_consumerd_opt
1 "$@"
994 function sigstop_lttng_consumerd_notap
()
996 sigstop_lttng_consumerd_opt
0 "$@"
999 function list_lttng_with_opts
()
1002 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN list
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1003 ok $?
"Lttng-tool list command with option $opts"
1006 function create_lttng_session_no_output
()
1011 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name --no-output $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1012 ok $?
"Create session $sess_name in no-output mode"
1015 function create_lttng_session_uri
() {
1020 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -U $uri $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1021 ok $?
"Create session $sess_name with uri:$uri and opts: $opts"
1024 function create_lttng_session
()
1027 local expected_to_fail
=$2
1032 if [ -z "$trace_path" ]; then
1033 # Use lttng-sessiond default output.
1036 trace_path
="-o $trace_path"
1039 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
"$sess_name" $trace_path $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1041 if [ $expected_to_fail -eq "1" ]; then
1044 if [ $withtap -eq "1" ]; then
1045 ok
$ret "Create session $sess_name in $trace_path failed as expected"
1048 if [ $withtap -eq "1" ]; then
1049 ok
$ret "Create session $sess_name in $trace_path"
1055 function create_lttng_session_ok
()
1057 create_lttng_session
1 0 "$@"
1060 function create_lttng_session_fail
()
1062 create_lttng_session
1 1 "$@"
1065 function create_lttng_session_notap
()
1067 create_lttng_session
0 0 "$@"
1071 function enable_ust_lttng_channel
()
1074 local expected_to_fail
=$2
1076 local channel_name
=$4
1079 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-u $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1081 if [[ $expected_to_fail -eq "1" ]]; then
1084 if [ $withtap -eq "1" ]; then
1085 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
1088 if [ $withtap -eq "1" ]; then
1089 ok
$ret "Enable channel $channel_name for session $sess_name"
1095 function enable_ust_lttng_channel_ok
()
1097 enable_ust_lttng_channel
1 0 "$@"
1100 function enable_ust_lttng_channel_fail
()
1102 enable_ust_lttng_channel
1 1 "$@"
1105 function enable_ust_lttng_channel_notap
()
1107 enable_ust_lttng_channel
0 0 "$@"
1110 function disable_ust_lttng_channel
()
1113 local channel_name
=$2
1115 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1116 ok $?
"Disable channel $channel_name for session $sess_name"
1119 function enable_lttng_mmap_overwrite_kernel_channel
()
1122 local channel_name
=$2
1124 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1125 ok $?
"Enable channel $channel_name for session $sess_name"
1128 function enable_lttng_mmap_discard_small_kernel_channel
()
1131 local channel_name
=$2
1133 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--discard --subbuf-size=$
(getconf PAGE_SIZE
) --num-subbuf=2 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1134 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1137 function enable_lttng_mmap_overwrite_small_kernel_channel
()
1140 local channel_name
=$2
1142 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite --subbuf-size=$
(getconf PAGE_SIZE
) --num-subbuf=2 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1143 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1146 function enable_lttng_mmap_overwrite_ust_channel
()
1149 local channel_name
=$2
1151 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1152 ok $?
"Enable channel $channel_name for session $sess_name"
1155 function enable_ust_lttng_event
()
1158 local expected_to_fail
=$2
1160 local event_name
="$4"
1161 local channel_name
=$5
1163 if [ -z $channel_name ]; then
1164 # default channel if none specified
1167 chan
="-c $channel_name"
1170 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1172 if [[ $expected_to_fail -eq "1" ]]; then
1175 if [[ $withtap -eq "1" ]]; then
1176 ok
$ret "Enable ust event $event_name for session $session_name failed as expected"
1179 if [[ $withtap -eq "1" ]]; then
1180 ok
$ret "Enable ust event $event_name for session $sess_name"
1186 function enable_ust_lttng_event_ok
()
1188 enable_ust_lttng_event
1 0 "$@"
1191 function enable_ust_lttng_event_fail
()
1193 enable_ust_lttng_event
1 1 "$@"
1196 function enable_ust_lttng_event_notap
()
1198 enable_ust_lttng_event
0 0 "$@"
1201 function enable_jul_lttng_event
()
1207 if [ -z $channel_name ]; then
1208 # default channel if none specified
1211 chan
="-c $channel_name"
1214 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1215 ok $?
"Enable JUL event $event_name for session $sess_name"
1218 function enable_jul_lttng_event_loglevel
()
1221 local event_name
="$2"
1223 local channel_name
=$4
1225 if [ -z $channel_name ]; then
1226 # default channel if none specified
1229 chan
="-c $channel_name"
1232 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1233 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
1236 function enable_log4j_lttng_event
()
1242 if [ -z $channel_name ]; then
1243 # default channel if none specified
1246 chan
="-c $channel_name"
1249 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1250 ok $?
"Enable LOG4J event $event_name for session $sess_name"
1253 function enable_log4j_lttng_event_loglevel
()
1256 local event_name
="$2"
1258 local channel_name
=$4
1260 if [ -z $channel_name ]; then
1261 # default channel if none specified
1264 chan
="-c $channel_name"
1267 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1268 ok $?
"Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
1271 function enable_python_lttng_event
()
1277 if [ -z $channel_name ]; then
1278 # default channel if none specified
1281 chan
="-c $channel_name"
1284 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1285 ok $?
"Enable Python event $event_name for session $sess_name"
1288 function enable_python_lttng_event_loglevel
()
1291 local event_name
="$2"
1293 local channel_name
=$4
1295 if [ -z $channel_name ]; then
1296 # default channel if none specified
1299 chan
="-c $channel_name"
1302 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1303 ok $?
"Enable Python event $event_name for session $sess_name with loglevel $loglevel"
1306 function enable_ust_lttng_event_filter
()
1308 local sess_name
="$1"
1309 local event_name
="$2"
1311 local channel_name
=$4
1313 if [ -z $channel_name ]; then
1314 # default channel if none specified
1317 chan
="-c $channel_name"
1320 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
$chan "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1321 ok $?
"Enable event $event_name with filtering for session $sess_name"
1324 function enable_ust_lttng_event_loglevel
()
1326 local sess_name
="$1"
1327 local event_name
="$2"
1330 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1331 ok $?
"Enable event $event_name with loglevel $loglevel"
1334 function enable_ust_lttng_event_loglevel_only
()
1336 local sess_name
="$1"
1337 local event_name
="$2"
1340 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1341 ok $?
"Enable event $event_name with loglevel-only $loglevel"
1344 function disable_ust_lttng_event
()
1346 local sess_name
="$1"
1347 local event_name
="$2"
1348 local channel_name
="$3"
1350 if [ -z $channel_name ]; then
1351 # default channel if none specified
1354 chan
="-c $channel_name"
1357 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1358 ok $?
"Disable event $event_name for session $sess_name"
1361 function disable_jul_lttng_event
()
1363 local sess_name
="$1"
1364 local event_name
="$2"
1366 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
1367 ok $?
"Disable JUL event $event_name for session $sess_name"
1370 function disable_log4j_lttng_event
()
1372 local sess_name
="$1"
1373 local event_name
="$2"
1375 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -l >/dev
/null
2>&1
1376 ok $?
"Disable LOG4J event $event_name for session $sess_name"
1379 function disable_python_lttng_event
()
1381 local sess_name
="$1"
1382 local event_name
="$2"
1384 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1385 ok $?
"Disable Python event $event_name for session $sess_name"
1388 function start_lttng_tracing_opt
()
1391 local expected_to_fail
=$2
1394 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1396 if [[ $expected_to_fail -eq "1" ]]; then
1399 if [ $withtap -eq "1" ]; then
1400 ok $?
"Start tracing for session $sess_name failed as expected"
1403 if [ $withtap -eq "1" ]; then
1404 ok
$ret "Start tracing for session $sess_name"
1409 function start_lttng_tracing_ok
()
1411 start_lttng_tracing_opt
1 0 "$@"
1414 function start_lttng_tracing_fail
()
1416 start_lttng_tracing_opt
1 1 "$@"
1419 function start_lttng_tracing_notap
()
1421 start_lttng_tracing_opt
0 1 "$@"
1424 function stop_lttng_tracing_opt
()
1427 local expected_to_fail
=$2
1430 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1432 if [[ $expected_to_fail -eq "1" ]]; then
1435 if [ $withtap -eq "1" ]; then
1436 ok $?
"Stop lttng tracing for session $sess_name failed as expected"
1439 if [ $withtap -eq "1" ]; then
1440 ok
$ret "Stop lttng tracing for session $sess_name"
1445 function stop_lttng_tracing_ok
()
1447 stop_lttng_tracing_opt
1 0 "$@"
1450 function stop_lttng_tracing_fail
()
1452 stop_lttng_tracing_opt
1 1 "$@"
1455 function stop_lttng_tracing_notap
()
1457 stop_lttng_tracing_opt
0 0 "$@"
1460 function destroy_lttng_session
()
1463 local expected_to_fail
=$2
1466 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1468 if [[ $expected_to_fail -eq "1" ]]; then
1471 if [ $withtap -eq "1" ]; then
1472 ok
$ret "Destroy session $sess_name failed as expected"
1475 if [ $withtap -eq "1" ]; then
1476 ok
$ret "Destroy session $sess_name"
1481 function destroy_lttng_session_ok
()
1483 destroy_lttng_session
1 0 "$@"
1487 function destroy_lttng_session_fail
()
1489 destroy_lttng_session
1 1 "$@"
1492 function destroy_lttng_session_notap
()
1494 destroy_lttng_session
0 0 "$@"
1497 function destroy_lttng_sessions
()
1499 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
--all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1500 ok $?
"Destroy all lttng sessions"
1503 function lttng_snapshot_add_output
()
1505 local expected_to_fail
=$1
1510 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name $trace_path $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1512 if [[ $expected_to_fail -eq 1 ]]; then
1514 ok $?
"Added snapshot output $trace_path failed as expected"
1516 ok
$ret "Added snapshot output $trace_path"
1520 function lttng_snapshot_add_output_ok
()
1522 lttng_snapshot_add_output
0 "$@"
1525 function lttng_snapshot_add_output_fail
()
1527 lttng_snapshot_add_output
1 "$@"
1530 function lttng_snapshot_del_output
()
1532 local expected_to_fail
=$1
1536 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output
-s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1538 if [[ $expected_to_fail -eq "1" ]]; then
1540 ok $?
"Deleted snapshot output id $id failed as expected"
1542 ok
$ret "Deleted snapshot output id $id"
1546 function lttng_snapshot_del_output_ok
()
1548 lttng_snapshot_del_output
0 "$@"
1551 function lttng_snapshot_del_output_fail
()
1553 lttng_snapshot_del_output
1 "$@"
1556 function lttng_snapshot_record
()
1561 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot record
-s "$sess_name" "$trace_path" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1562 ok $?
"Snapshot recorded"
1565 function lttng_snapshot_list
()
1568 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1569 ok $?
"Snapshot list"
1572 function lttng_save
()
1577 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN save
$sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1578 ok $?
"Session saved"
1581 function lttng_load
()
1583 local expected_to_fail
=$1
1586 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN load
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1588 if [[ $expected_to_fail -eq "1" ]]; then
1590 ok $?
"Load command failed as expected with opts: $opts"
1592 ok
$ret "Load command with opts: $opts"
1596 function lttng_load_ok
()
1601 function lttng_load_fail
()
1606 function lttng_track
()
1608 local expected_to_fail
="$1"
1611 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN track
$opts >$OUTPUT_DEST
1613 if [[ $expected_to_fail -eq "1" ]]; then
1615 ok $?
"Track command failed as expected with opts: $opts"
1617 ok
$ret "Track command with opts: $opts"
1621 function lttng_track_ok
()
1626 function lttng_track_fail
()
1631 function lttng_untrack
()
1633 local expected_to_fail
="$1"
1636 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN untrack
$opts >$OUTPUT_DEST
1638 if [[ $expected_to_fail -eq "1" ]]; then
1640 ok $?
"Untrack command failed as expected with opts: $opts"
1642 ok
$ret "Untrack command with opts: $opts"
1646 function lttng_untrack_ok
()
1648 lttng_untrack
0 "$@"
1651 function lttng_untrack_fail
()
1653 lttng_untrack
1 "$@"
1656 function lttng_track_pid_ok
()
1659 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track
--kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1660 ok $?
"Lttng track pid on the kernel domain"
1663 function lttng_untrack_kernel_all_ok
()
1665 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack
--kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1666 ok $?
"Lttng untrack all pid on the kernel domain"
1669 function lttng_track_ust_ok
()
1671 lttng_track_ok
-u "$@"
1674 function lttng_track_ust_fail
()
1676 lttng_track_fail
-u "$@"
1679 function lttng_track_kernel_ok
()
1681 lttng_track_ok
-k "$@"
1684 function lttng_track_kernel_fail
()
1686 lttng_track_fail
-k "$@"
1689 function lttng_untrack_ust_ok
()
1691 lttng_untrack_ok
-u "$@"
1694 function lttng_untrack_ust_fail
()
1696 lttng_untrack_fail
-u "$@"
1699 function lttng_untrack_kernel_ok
()
1701 lttng_untrack_ok
-k "$@"
1704 function lttng_untrack_kernel_fail
()
1706 lttng_untrack_fail
-k "$@"
1709 function lttng_add_context_list
()
1711 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context
--list 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1713 ok
$ret "Context listing"
1716 function add_context_lttng
()
1718 local expected_to_fail
="$1"
1720 local session_name
="$3"
1721 local channel_name
="$4"
1724 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context
-s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1726 if [[ $expected_to_fail -eq "1" ]]; then
1728 ok $?
"Add context command failed as expected for type: $type"
1730 ok
$ret "Add context command for type: $type"
1734 function add_context_ust_ok
()
1736 add_context_lttng
0 -u "$@"
1739 function add_context_ust_fail
()
1741 add_context_lttng
1 -u "$@"
1744 function add_context_kernel_ok
()
1746 add_context_lttng
0 -k "$@"
1749 function add_context_kernel_fail
()
1751 add_context_lttng
1 -k "$@"
1754 function wait_live_trace_ready
()
1757 local zero_client_match
=0
1759 diag
"Waiting for live trace at url: $url"
1760 while [ $zero_client_match -eq 0 ]; do
1761 zero_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "0 client(s) connected" |
wc -l)
1764 pass
"Waiting for live trace at url: $url"
1767 function wait_live_viewer_connect
()
1770 local one_client_match
=0
1772 diag
"Waiting for live viewers on url: $url"
1773 while [ $one_client_match -eq 0 ]; do
1774 one_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "1 client(s) connected" |
wc -l)
1777 pass
"Waiting for live viewers on url: $url"
1780 function validate_metadata_event
()
1783 local nr_event_id
=$2
1786 local metadata_file
=$
(find $trace_path -name "metadata")
1787 local metadata_path
=$
(dirname $metadata_file)
1789 which $BABELTRACE_BIN >/dev
/null
1790 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1792 local count
=$
($BABELTRACE_BIN --output-format=ctf-metadata
$metadata_path |
grep $event_name |
wc -l)
1794 if [ "$count" -ne "$nr_event_id" ]; then
1795 fail
"Metadata match with the metadata of $count event(s) named $event_name"
1796 diag
"$count matching event id found in metadata"
1798 pass
"Metadata match with the metadata of $count event(s) named $event_name"
1803 function trace_matches
()
1809 which $BABELTRACE_BIN >/dev
/null
1810 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1812 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1814 if [ "$count" -ne "$nr_iter" ]; then
1816 diag
"$count matching events found in trace"
1822 function trace_match_only
()
1828 which $BABELTRACE_BIN >/dev
/null
1829 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1831 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1832 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1834 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1835 pass
"Trace match with $total event $event_name"
1838 diag
"$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1842 function validate_trace
1847 which $BABELTRACE_BIN >/dev
/null
1848 if [ $?
-ne 0 ]; then
1849 skip
0 "Babeltrace binary not found. Skipping trace validation"
1854 for i
in $event_name; do
1855 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1856 if [ "$traced" -ne 0 ]; then
1857 pass
"Validate trace for event $i, $traced events"
1859 fail
"Validate trace for event $i"
1860 diag
"Found $traced occurences of $i"
1868 function validate_trace_count
1872 local expected_count
=$3
1874 which $BABELTRACE_BIN >/dev
/null
1875 if [ $?
-ne 0 ]; then
1876 skip
0 "Babeltrace binary not found. Skipping trace validation"
1882 for i
in $event_name; do
1883 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1884 if [ "$traced" -ne 0 ]; then
1885 pass
"Validate trace for event $i, $traced events"
1887 fail
"Validate trace for event $i"
1888 diag
"Found $traced occurences of $i"
1890 cnt
=$
(($cnt + $traced))
1893 test $cnt -eq $expected_count
1894 ok $?
"Read a total of $cnt events, expected $expected_count"
1897 function validate_trace_count_range_incl_min_excl_max
1901 local expected_min
=$3
1902 local expected_max
=$4
1904 which $BABELTRACE_BIN >/dev
/null
1905 if [ $?
-ne 0 ]; then
1906 skip
0 "Babeltrace binary not found. Skipping trace validation"
1912 for i
in $event_name; do
1913 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1914 if [ "$traced" -ge $expected_min ]; then
1915 pass
"Validate trace for event $i, $traced events"
1917 fail
"Validate trace for event $i"
1918 diag
"Found $traced occurences of $i"
1920 cnt
=$
(($cnt + $traced))
1923 test $cnt -lt $expected_max
1924 ok $?
"Read a total of $cnt events, expected between [$expected_min, $expected_max["
1927 function trace_first_line
1931 which $BABELTRACE_BIN >/dev
/null
1932 if [ $?
-ne 0 ]; then
1933 skip
0 "Babeltrace binary not found. Skipping trace validation"
1936 $BABELTRACE_BIN $trace_path 2>/dev
/null |
head -n 1
1939 function validate_trace_exp
()
1944 which $BABELTRACE_BIN >/dev
/null
1945 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace validation"
1947 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep --extended-regexp ${event_exp} |
wc -l)
1948 if [ "$traced" -ne 0 ]; then
1949 pass
"Validate trace for expression '${event_exp}', $traced events"
1951 fail
"Validate trace for expression '${event_exp}'"
1952 diag
"Found $traced occurences of '${event_exp}'"
1958 function validate_trace_only_exp
()
1963 which $BABELTRACE_BIN >/dev
/null
1964 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1966 local count
=$
($BABELTRACE_BIN $trace_path |
grep --extended-regexp ${event_exp} |
wc -l)
1967 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1969 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1970 pass
"Trace match with $total for expression '${event_exp}'"
1973 diag
"$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1979 function validate_trace_empty
()
1983 which $BABELTRACE_BIN >/dev
/null
1984 if [ $?
-ne 0 ]; then
1985 skip
0 "Babeltrace binary not found. Skipping trace validation"
1988 events
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null
)
1990 if [ $ret -ne 0 ]; then
1991 fail
"Failed to parse trace"
1995 traced
=$
(echo -n "$events" |
wc -l)
1996 if [ "$traced" -eq 0 ]; then
1997 pass
"Validate empty trace"
1999 fail
"Validate empty trace"
2000 diag
"Found $traced events in trace"
2006 function validate_directory_empty
()
2008 local trace_path
="$1"
2010 # Do not double quote `$trace_path` below as we want wildcards to be
2012 files
="$(ls -A $trace_path)"
2014 if [ $ret -ne 0 ]; then
2015 fail
"Failed to list content of directory \"$trace_path\""
2019 nb_files
="$(echo -n "$files" | wc -l)"
2020 ok
$nb_files "Directory \"$trace_path\" is empty"
2023 function validate_trace_session_ust_empty
()
2025 validate_directory_empty
"$1"/ust
2028 function validate_trace_session_kernel_empty
()
2030 validate_trace_empty
"$1"/kernel
2033 function regenerate_metadata
()
2035 local expected_to_fail
=$1
2038 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN regenerate metadata
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2040 if [[ $expected_to_fail -eq "1" ]]; then
2042 ok $?
"Expected fail on regenerate metadata $sess_name"
2044 ok
$ret "Metadata regenerate $sess_name"
2048 function regenerate_metadata_ok
()
2050 regenerate_metadata
0 "$@"
2053 function regenerate_metadata_fail
()
2055 regenerate_metadata
1 "$@"
2058 function regenerate_statedump
()
2060 local expected_to_fail
=$1
2063 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN regenerate statedump
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2065 if [[ $expected_to_fail -eq "1" ]]; then
2067 ok $?
"Expected fail on regenerate statedump $sess_name"
2069 ok
$ret "Statedump regenerate $sess_name"
2073 function regenerate_statedump_ok
()
2075 regenerate_statedump
0 "$@"
2078 function regenerate_statedump_fail
()
2080 regenerate_statedump
1 "$@"
2083 function rotate_session
()
2085 local expected_to_fail
=$1
2088 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN rotate
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2090 if [[ $expected_to_fail -eq "1" ]]; then
2092 ok $?
"Expected fail on rotate session $sess_name"
2094 ok
$ret "Rotate session $sess_name"
2098 function rotate_session_ok
()
2100 rotate_session
0 "$@"
2103 function rotate_session_fail
()
2105 rotate_session
1 "$@"
2108 function destructive_tests_enabled
()
2110 if [ "$LTTNG_ENABLE_DESTRUCTIVE_TESTS" = "will-break-my-system" ]; then
2117 function lttng_enable_rotation_timer
()
2119 local expected_to_fail
=$1
2123 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-rotation
-s $sess_name --timer $period 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2125 if [[ $expected_to_fail -eq "1" ]]; then
2127 ok $?
"Expected fail when setting periodic rotation ($period) of session $sess_name"
2129 ok
$ret "Set periodic rotation ($period) of session $sess_name"
2133 function lttng_enable_rotation_timer_ok
()
2135 lttng_enable_rotation_timer
0 $@
2138 function lttng_enable_rotation_timer_fail
()
2140 lttng_enable_rotation_timer
1 $@
2143 function lttng_enable_rotation_size
()
2145 local expected_to_fail
=$1
2149 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-rotation
-s $sess_name --size $size 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2151 if [[ $expected_to_fail -eq "1" ]]; then
2153 ok $?
"Expected fail on rotate session $sess_name"
2155 ok
$ret "Rotate session $sess_name"
2159 function lttng_enable_rotation_size_ok
()
2161 lttng_enable_rotation_size
0 $@
2164 function lttng_enable_rotation_size_fail
()
2166 lttng_enable_rotation_size
1 $@
2169 function lttng_clear_session
()
2171 local expected_to_fail
=$1
2174 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN clear $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2176 if [[ $expected_to_fail -eq "1" ]]; then
2178 ok $?
"Expected fail on clear session $sess_name"
2180 ok
$ret "Clear session $sess_name"
2184 function lttng_clear_session_ok
()
2186 lttng_clear_session
0 $@
2189 function lttng_clear_session_fail
()
2191 lttng_clear_session
1 $@
2194 function lttng_clear_all
()
2196 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN clear --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2197 ok $?
"Clear all lttng sessions"
2200 function lttng_add_trigger
()
2202 local expected_to_fail
="$1"
2203 local trigger_name
="$2"
2207 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN add-trigger --name $trigger_name ${args[*]}"
2208 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-trigger
--name "$trigger_name" "${args[@]}" 1> /dev
/null
2> /dev
/null
2210 if [[ $expected_to_fail -eq "1" ]]; then
2212 ok $?
"Add trigger $trigger_name failed as expected"
2214 ok
$ret "Add trigger $trigger_name"
2218 function lttng_remove_trigger
()
2220 local expected_to_fail
="$1"
2221 local trigger_name
="$2"
2224 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN remove-trigger $trigger_name $*"
2225 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" remove-trigger
"$trigger_name" "$@" 1> /dev
/null
2> /dev
/null
2227 if [[ $expected_to_fail -eq "1" ]]; then
2229 ok $?
"Remove trigger $trigger_name failed as expected"
2231 ok
$ret "Remove trigger $trigger_name"
2235 function lttng_add_trigger_ok
()
2237 lttng_add_trigger
0 "$@"
2240 function lttng_add_trigger_fail
()
2242 lttng_add_trigger
1 "$@"
2245 function lttng_remove_trigger_ok
()
2247 lttng_remove_trigger
0 "$@"
2250 function list_triggers_matches_ok
()
2252 local tmp_stdout
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2253 local tmp_stderr
=$
(mktemp
--tmpdir -t "tmp.${FUNCNAME[0]}_stderr.XXXXXX")
2255 local test_name
="$1"
2256 local expected_stdout_file
="$2"
2258 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN list-triggers"
2260 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" list-triggers
> "${tmp_stdout}" 2> "${tmp_stderr}"
2261 ok $?
"${test_name}: exit code is 0"
2263 diff -u "${expected_stdout_file}" "${tmp_stdout}"
2264 ok $?
"${test_name}: expected stdout"
2266 diff -u /dev
/null
"${tmp_stderr}"
2267 ok $?
"${test_name}: expected stderr"
2269 rm -f "${tmp_stdout}"
2270 rm -f "${tmp_stderr}"
2273 function validate_path_pattern
()
2277 # Base path is only used in error case and is used to list the content
2286 if [ "$ret" -ne "0" ]; then
2287 diag
"Path pattern expected: $pattern"
2288 # List the tracepath for more info. We use find as a recursive
2290 diag
"The base path content:"
2291 find "$base_path" -print
2295 function validate_trace_path_ust_uid
()
2298 local session_name
=$2
2300 local pattern
="$trace_path/$session_name-$date_time_pattern/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2302 validate_path_pattern
"UST per-uid trace path is valid" "$pattern" "$trace_path"
2305 function validate_trace_path_ust_uid_network
()
2308 local session_name
=$2
2311 local hostname
=$HOSTNAME
2315 # If the session was given a network base path (e.g
2316 # 127.0.0.1/my/custom/path on creation, there is no session name
2317 # component to the path on the relayd side. Caller can simply not pass a
2318 # session name for this scenario.
2319 if [ -n "$session_name" ]; then
2320 session_name
="$session_name-$date_time_pattern"
2321 if [ -n "$base_path" ]; then
2322 fail
"Session name and base path are mutually exclusive"
2327 pattern
="$trace_path/$hostname/$base_path/$session_name/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2329 validate_path_pattern
"UST per-uid network trace path is valid" "$pattern" "$trace_path"
2332 function validate_trace_path_ust_uid_snapshot_network
()
2335 local session_name
=$2
2336 local snapshot_name
=$3
2337 local snapshot_number
=$4
2339 local hostname
=$HOSTNAME
2344 # If the session/output was given a network base path (e.g
2345 # 127.0.0.1/my/custom/path on creation, there is no session name
2346 # component to the path on the relayd side. Caller can simply not pass a
2347 # session name for this scenario.
2348 if [ -n "$session_name" ]; then
2349 session_name
="$session_name-$date_time_pattern"
2350 if [ -n "$base_path" ]; then
2351 fail
"Session name and base path are mutually exclusive"
2356 pattern
="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2358 validate_path_pattern
"UST per-uid network snapshot trace path is valid" "$pattern" "$trace_path"
2361 function validate_trace_path_ust_uid_snapshot
()
2364 local session_name
=$2
2365 local snapshot_name
=$3
2366 local snapshot_number
=$4
2372 # If the session/output was given a network base path (e.g
2373 # 127.0.0.1/my/custom/path) on creation, there is no session name
2374 # component to the path on the relayd side. Caller can simply not pass a
2375 # session name for this scenario.
2376 if [ -n "$session_name" ]; then
2377 session_name
="$session_name-$date_time_pattern"
2378 if [ -n "$base_path" ]; then
2379 fail
"Session name and base path are mutually exclusive"
2384 pattern
="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2386 validate_path_pattern
"UST per-uid snapshot trace path is valid" "$pattern" "$trace_path"
2389 function validate_trace_path_ust_pid
()
2392 local session_name
=$2
2398 # If the session was given a trace path on creation, there is no session
2399 # name component to the path. Caller can simply not pass a session name
2400 # for this scenario.
2401 if [ -n "$session_name" ]; then
2402 session_name
="$session_name-$date_time_pattern"
2405 pattern
="$trace_path/$session_name/ust/pid/$pid/$app_string-*-$date_time_pattern/metadata"
2407 validate_path_pattern
"UST per-pid trace path is valid" "$pattern" "$trace_path"
2410 function validate_trace_path_kernel
()
2413 local session_name
=$2
2416 # If the session was given a trace path on creation, there is no session
2417 # name component to the path. Caller can simply not pass a session name
2418 # for this scenario.
2419 if [ -n "$session_name" ]; then
2420 session_name
="$session_name-$date_time_pattern"
2423 pattern
="$trace_path/$session_name/kernel/metadata"
2425 validate_path_pattern
"Kernel trace path is valid" "$pattern" "$trace_path"
2428 function validate_trace_path_kernel_network
()
2431 local session_name
=$2
2432 local hostname
=$HOSTNAME
2433 local pattern
="$trace_path/$hostname/$session_name-$date_time_pattern/kernel/metadata"
2435 validate_path_pattern
"Kernel network trace path is valid" "$pattern" "$trace_path"
2438 function validate_trace_path_kernel_snapshot
()
2441 local session_name
=$2
2442 local snapshot_name
=$3
2443 local snapshot_number
=$4
2448 # If the session/output was given a network base path (e.g
2449 # 127.0.0.1/my/custom/path on creation, there is no session name
2450 # component to the path on the relayd side. Caller can simply not pass a
2451 # session name for this scenario.
2452 if [ -n "$session_name" ]; then
2453 session_name
="$session_name-$date_time_pattern"
2454 if [ -n "$base_path" ]; then
2455 fail
"Session name and base path are mutually exclusive"
2460 pattern
="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata"
2462 validate_path_pattern
"Kernel snapshot trace path is valid" "$pattern" "$trace_path"
2465 function validate_trace_path_kernel_snapshot_network
()
2468 local session_name
=$2
2469 local snapshot_name
=$3
2470 local snapshot_number
=$4
2472 local hostname
=$HOSTNAME
2476 # If the session/output was given a network base path (e.g
2477 # 127.0.0.1/my/custom/path on creation, there is no session name
2478 # component to the path on the relayd side. Caller can simply not pass a
2479 # session name for this scenario.
2480 if [ -n "$session_name" ]; then
2481 session_name
="$session_name-$date_time_pattern"
2482 if [ -n "$base_path" ]; then
2483 fail
"Session name and base path are mutually exclusive"
2488 pattern
="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata"
2490 validate_path_pattern
"Kernel network snapshot trace path is valid" "$pattern" "$trace_path"