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 # Minimal kernel version supported for session daemon tests
20 KERNEL_MAJOR_VERSION
=2
21 KERNEL_MINOR_VERSION
=6
22 KERNEL_PATCHLEVEL_VERSION
=27
24 # We set the default UST register timeout and network and app socket timeout to
25 # "wait forever", so that basic tests don't have to worry about hitting
26 # timeouts on busy systems. Specialized tests should test those corner-cases.
27 export LTTNG_UST_REGISTER_TIMEOUT
=-1
28 export LTTNG_NETWORK_SOCKET_TIMEOUT
=-1
29 export LTTNG_APP_SOCKET_TIMEOUT
=-1
31 # We set the default lttng-sessiond path to /bin/true to prevent the spawning
32 # of a daemonized sessiond. This is necessary since 'lttng create' will spawn
33 # its own sessiond if none is running. It also ensures that 'lttng create'
34 # fails when no sessiond is running.
35 export LTTNG_SESSIOND_PATH
="/bin/true"
37 source $TESTDIR/utils
/tap
/tap.sh
39 if [ -z ${LTTNG_TEST_TEARDOWN_TIMEOUT+x} ]; then
40 LTTNG_TEST_TEARDOWN_TIMEOUT
=60
43 # Enable job monitor mode.
44 # Here we are mostly interested in the following from the monitor mode:
45 # All processes run in a separate process group.
46 # This allows us to ensure that all subprocesses from all background tasks are
47 # cleaned up correctly using signal to process group id.
50 kill_background_jobs
()
55 if [ -z "$pids" ]; then
62 # Use negative number to send the signal to the process group.
63 # This ensure that any subprocesses receive the signal.
64 # /dev/null is used since there is an acceptable race between
65 # the moments the pids are listed and the moment we send a
67 kill -SIGTERM -- "-$pid" 2>/dev
/null
73 # Try to kill daemons gracefully
74 stop_lttng_relayd_cleanup SIGTERM
$LTTNG_TEST_TEARDOWN_TIMEOUT
75 stop_lttng_sessiond_cleanup SIGTERM
$LTTNG_TEST_TEARDOWN_TIMEOUT
77 # If daemons are still present, forcibly kill them
78 stop_lttng_relayd_cleanup SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
79 stop_lttng_sessiond_cleanup SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
80 stop_lttng_consumerd_cleanup SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
85 function full_cleanup
()
91 function LTTNG_BAIL_OUT
()
97 function null_pipes
()
104 trap full_cleanup SIGINT SIGTERM
106 # perl prove closes its child pipes before giving it a chance to run its
107 # signal trap handlers. Redirect pipes to /dev/null if SIGPIPE is caught
108 # to allow those trap handlers to proceed.
110 trap null_pipes SIGPIPE
112 # Check pgrep from env, default to pgrep if none
113 if [ -z "$PGREP" ]; then
117 # Due to the renaming of threads we need to use the full command (pgrep -f) to
118 # identify the pids for multiple lttng related processes. The problem with "pgrep
119 # -f" is that it ends up also looking at the arguments. We use a two stage
120 # lookup. The first one is using "pgrep -f" yielding potential candidate.
121 # The second on perform grep on the basename of the first field of the
122 # /proc/pid/cmdline of the previously identified pids. The first field
123 # correspond to the actual command.
124 function lttng_pgrep
()
128 local full_command_no_argument
129 local command_basename
131 possible_pids
=$
($PGREP -f "$pattern")
132 if [ -z "$possible_pids" ]; then
136 while IFS
= read -r pid
; do
137 # /proc/pid/cmdline is null separated.
138 if full_command_no_argument
=$
(cut
-d '' -f 1 2>/dev
/null
< /proc
/"$pid"/cmdline
); then
139 command_basename
=$
(basename "$full_command_no_argument")
140 if grep -q "$pattern" <<< "$command_basename"; then
144 done <<< "$possible_pids"
150 # Check if we are a terminal
152 echo -e "\e[1;32mOK\e[0m"
158 function print_fail
()
160 # Check if we are a terminal
162 echo -e "\e[1;31mFAIL\e[0m"
168 function print_test_banner
()
174 function validate_kernel_version
()
176 local kern_version
=($
(uname
-r |
awk -F.
'{ printf("%d.%d.%d\n",$1,$2,$3); }' |
tr '.' '\n'))
177 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
180 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
183 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
189 # Generate a random string
190 # $1 = number of characters; defaults to 16
191 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
192 function randstring
()
194 [ "$2" == "0" ] && CHAR
="[:alnum:]" || CHAR
="[:graph:]"
195 cat /dev
/urandom
2>/dev
/null |
tr -cd "$CHAR" 2>/dev
/null |
head -c ${1:-16} 2>/dev
/null
199 # Return the number of _configured_ CPUs.
200 function conf_proc_count
()
202 getconf _NPROCESSORS_CONF
203 if [ $?
-ne 0 ]; then
204 diag
"Failed to get the number of configured CPUs"
209 # Check if base lttng-modules are present.
210 # Bail out on failure
211 function validate_lttng_modules_present
()
213 # Check for loadable modules.
214 modprobe
-n lttng-tracer
2>/dev
/null
215 if [ $?
-eq 0 ]; then
219 # Check for builtin modules.
220 ls /proc
/lttng
> /dev
/null
2>&1
221 if [ $?
-eq 0 ]; then
225 LTTNG_BAIL_OUT
"LTTng modules not detected."
228 function enable_kernel_lttng_event
231 local expected_to_fail
="$2"
233 local event_name
="$4"
234 local channel_name
="$5"
236 if [ -z "$event_name" ]; then
237 # Enable all event if no event name specified
241 if [ -z "$channel_name" ]; then
242 # default channel if none specified
245 chan
="-c $channel_name"
248 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
250 if [[ $expected_to_fail -eq "1" ]]; then
253 if [ $withtap -eq "1" ]; then
254 ok
$ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
257 if [ $withtap -eq "1" ]; then
258 ok
$ret "Enable kernel event $event_name for session $sess_name"
263 function enable_kernel_lttng_event_ok
()
265 enable_kernel_lttng_event
1 0 "$@"
268 function enable_kernel_lttng_event_fail
()
270 enable_kernel_lttng_event
1 1 "$@"
273 function enable_kernel_lttng_event_notap
()
275 enable_kernel_lttng_event
0 0 "$@"
279 function lttng_enable_kernel_event
281 enable_kernel_lttng_event_ok
"$@"
284 function lttng_enable_kernel_syscall
()
286 local expected_to_fail
=$1
288 local syscall_name
=$3
289 local channel_name
=$4
291 if [ -z $syscall_name ]; then
292 # Enable all event if no syscall name specified
296 if [ -z $channel_name ]; then
297 # default channel if none specified
300 chan
="-c $channel_name"
303 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
305 if [[ $expected_to_fail -eq "1" ]]; then
307 ok $?
"Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
309 ok
$ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
313 function lttng_enable_kernel_syscall_ok
()
315 lttng_enable_kernel_syscall
0 "$@"
318 function lttng_enable_kernel_syscall_fail
()
320 lttng_enable_kernel_syscall
1 "$@"
323 function lttng_disable_kernel_syscall
()
325 local expected_to_fail
=$1
327 local syscall_name
=$3
328 local channel_name
=$4
330 if [ -z $syscall_name ]; then
331 # Enable all event if no syscall name specified
335 if [ -z $channel_name ]; then
336 # default channel if none specified
339 chan
="-c $channel_name"
342 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
345 if [[ $expected_to_fail -eq "1" ]]; then
347 ok $?
"Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
349 ok
$ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
353 function lttng_disable_kernel_syscall_ok
()
355 lttng_disable_kernel_syscall
0 "$@"
358 function lttng_disable_kernel_syscall_fail
()
360 lttng_disable_kernel_syscall
1 "$@"
363 function lttng_enable_kernel_function_event
()
365 local expected_to_fail
="$1"
368 local event_name
="$4"
370 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
--kernel --function="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
372 if [[ $expected_to_fail -eq "1" ]]; then
374 ok $?
"Enable kernel function event for session $sess_name failed as expected"
376 ok
$ret "Enable kernel function event for session $sess_name"
380 function lttng_enable_kernel_function_event_ok
()
382 lttng_enable_kernel_function_event
0 "$@"
385 function lttng_enable_kernel_userspace_probe_event
()
387 local expected_to_fail
="$1"
390 local event_name
="$4"
392 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
--kernel --userspace-probe="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
394 if [[ $expected_to_fail -eq "1" ]]; then
396 ok $?
"Enable kernel userspace probe event for session $sess_name failed as expected"
398 ok
$ret "Enable kernel userspace probe event for session $sess_name"
402 function lttng_enable_kernel_userspace_probe_event_fail
()
404 lttng_enable_kernel_userspace_probe_event
1 "$@"
407 function lttng_enable_kernel_userspace_probe_event_ok
()
409 lttng_enable_kernel_userspace_probe_event
0 "$@"
412 function disable_kernel_lttng_userspace_probe_event_ok
()
415 local event_name
="$2"
417 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" disable-event
--kernel "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
418 ok $?
"Disable kernel event $target for session $sess_name"
420 function lttng_enable_kernel_channel
()
423 local expected_to_fail
=$2
425 local channel_name
=$4
428 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-k $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
430 if [[ $expected_to_fail -eq "1" ]]; then
433 if [ $withtap -eq "1" ]; then
434 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
437 if [ $withtap -eq "1" ]; then
438 ok
$ret "Enable channel $channel_name for session $sess_name"
443 function lttng_enable_kernel_channel_ok
()
445 lttng_enable_kernel_channel
1 0 "$@"
448 function lttng_enable_kernel_channel_fail
()
450 lttng_enable_kernel_channel
1 1 "$@"
453 function lttng_enable_kernel_channel_notap
()
455 lttng_enable_kernel_channel
0 0 "$@"
458 function enable_kernel_lttng_channel_ok
()
460 lttng_enable_kernel_channel
1 0 "$@"
463 function lttng_disable_kernel_channel
()
465 local expected_to_fail
=$1
467 local channel_name
=$3
469 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
471 if [[ $expected_to_fail -eq "1" ]]; then
473 ok $?
"Disable channel $channel_name for session $sess_name failed as expected"
475 ok
$ret "Disable channel $channel_name for session $sess_name"
479 function lttng_disable_kernel_channel_ok
()
481 lttng_disable_kernel_channel
0 "$@"
484 function lttng_disable_kernel_channel_fail
()
486 lttng_disable_kernel_channel
1 "$@"
489 function start_lttng_relayd_opt
()
492 local process_mode
=$2
495 DIR
=$
(readlink
-f "$TESTDIR")
497 if [ -z $
(lttng_pgrep
"$RELAYD_MATCH") ]; then
498 # shellcheck disable=SC2086
499 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
500 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
501 if [ $?
-eq 1 ]; then
502 if [ $withtap -eq "1" ]; then
503 fail
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
507 if [ $withtap -eq "1" ]; then
508 pass
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
512 pass
"Start lttng-relayd (opt: $opt)"
516 function start_lttng_relayd
()
518 start_lttng_relayd_opt
1 "-b" "$@"
521 function start_lttng_relayd_notap
()
523 start_lttng_relayd_opt
0 "-b" "$@"
526 function stop_lttng_relayd_opt
()
536 if [ -z "$signal" ]; then
541 # Multiply time by 2 to simplify integer arithmetic
542 if [ -n "$timeout_s" ]; then
543 dtimeleft_s
=$
((timeout_s
* 2))
547 pids
=$
(lttng_pgrep
"$RELAYD_MATCH")
548 if [ -z "$pids" ]; then
549 if [ "$is_cleanup" -eq 1 ]; then
551 elif [ "$withtap" -eq "1" ]; then
552 fail
"No relay daemon to kill"
554 LTTNG_BAIL_OUT
"No relay daemon to kill"
559 diag
"Killing (signal $signal) lttng-relayd (pid: $pids)"
561 # shellcheck disable=SC2086
562 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
564 if [ "$withtap" -eq "1" ]; then
565 fail
"Kill relay daemon"
569 while [ -n "$out" ]; do
570 out
=$
(lttng_pgrep
"$RELAYD_MATCH")
571 if [ -n "$dtimeleft_s" ]; then
572 if [ $dtimeleft_s -lt 0 ]; then
576 dtimeleft_s
=$
((dtimeleft_s
- 1))
580 if [ "$withtap" -eq "1" ]; then
581 if [ "$retval" -eq "0" ]; then
582 pass
"Wait after kill relay daemon"
584 fail
"Wait after kill relay daemon"
591 function stop_lttng_relayd
()
593 stop_lttng_relayd_opt
1 0 "$@"
596 function stop_lttng_relayd_notap
()
598 stop_lttng_relayd_opt
0 0 "$@"
601 function stop_lttng_relayd_cleanup
()
603 stop_lttng_relayd_opt
0 1 "$@"
606 #First arg: show tap output
607 #Second argument: load path for automatic loading
608 function start_lttng_sessiond_opt
()
613 # The rest of the arguments will be passed directly to lttng-sessiond.
619 local long_bit_value
=
620 long_bit_value
=$
(getconf LONG_BIT
)
622 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
623 # Env variable requested no session daemon
627 DIR
=$
(readlink
-f "$TESTDIR")
629 # Get long_bit value for 32/64 consumerd
630 case "$long_bit_value" in
632 consumerd
="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
635 consumerd
="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
642 # Check for env. variable. Allow the use of LD_PRELOAD etc.
643 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
644 env_vars
="${LTTNG_SESSIOND_ENV_VARS} "
646 env_vars
="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN"
648 if ! validate_kernel_version
; then
649 fail
"Start session daemon"
650 LTTNG_BAIL_OUT
"*** Kernel too old for session daemon tests ***"
653 : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}"
654 export LTTNG_SESSION_CONFIG_XSD_PATH
656 if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ]; then
658 if [ -n "$load_path" ]; then
659 # shellcheck disable=SC2086
660 env
$env_vars --load "$load_path" --background "$consumerd" "$@"
662 # shellcheck disable=SC2086
663 env
$env_vars --background "$consumerd" "$@"
665 #$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
667 if [ "$withtap" -eq "1" ]; then
668 ok
$status "Start session daemon"
673 function start_lttng_sessiond
()
675 start_lttng_sessiond_opt
1 "$@"
678 function start_lttng_sessiond_notap
()
680 start_lttng_sessiond_opt
0 "$@"
683 function stop_lttng_sessiond_opt
()
694 if [ -z "$signal" ]; then
698 # Multiply time by 2 to simplify integer arithmetic
699 if [ -n "$timeout_s" ]; then
700 dtimeleft_s
=$
((timeout_s
* 2))
703 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
704 # Env variable requested no session daemon
708 runas_pids
=$
(lttng_pgrep
"$RUNAS_MATCH")
709 pids
=$
(lttng_pgrep
"$SESSIOND_MATCH")
711 if [ -n "$runas_pids" ]; then
712 pids
="$pids $runas_pids"
715 if [ -z "$pids" ]; then
716 if [ "$is_cleanup" -eq 1 ]; then
718 elif [ "$withtap" -eq "1" ]; then
719 fail
"No session daemon to kill"
721 LTTNG_BAIL_OUT
"No session daemon to kill"
726 diag
"Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
728 # shellcheck disable=SC2086
729 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
731 if [ "$withtap" -eq "1" ]; then
732 fail
"Kill sessions daemon"
736 while [ -n "$out" ]; do
737 out
=$
(lttng_pgrep
"${SESSIOND_MATCH}")
738 if [ -n "$dtimeleft_s" ]; then
739 if [ $dtimeleft_s -lt 0 ]; then
743 dtimeleft_s
=$
((dtimeleft_s
- 1))
748 while [ -n "$out" ]; do
749 out
=$
(lttng_pgrep
"$CONSUMERD_MATCH")
750 if [ -n "$dtimeleft_s" ]; then
751 if [ $dtimeleft_s -lt 0 ]; then
755 dtimeleft_s
=$
((dtimeleft_s
- 1))
760 if [ "$withtap" -eq "1" ]; then
761 if [ "$retval" -eq "0" ]; then
762 pass
"Wait after kill session daemon"
764 fail
"Wait after kill session daemon"
768 if [ "$signal" = "SIGKILL" ]; then
769 if [ "$(id -u)" -eq "0" ]; then
771 modules
="$(lsmod | grep ^lttng | awk '{print $1}')"
773 if [ -n "$modules" ]; then
774 diag
"Unloading all LTTng modules"
775 modprobe
--remove "$modules"
783 function stop_lttng_sessiond
()
785 stop_lttng_sessiond_opt
1 0 "$@"
788 function stop_lttng_sessiond_notap
()
790 stop_lttng_sessiond_opt
0 0 "$@"
793 function stop_lttng_sessiond_cleanup
()
795 stop_lttng_sessiond_opt
0 1 "$@"
798 function sigstop_lttng_sessiond_opt
()
804 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
805 # Env variable requested no session daemon
809 pids
="$(lttng_pgrep "${SESSIOND_MATCH}") $(lttng_pgrep "$RUNAS_MATCH")"
811 if [ "$withtap" -eq "1" ]; then
812 diag
"Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
815 # shellcheck disable=SC2086
816 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
817 if [ "$withtap" -eq "1" ]; then
818 fail
"Sending SIGSTOP to session daemon"
822 while [ $out -ne 0 ]; do
823 pids
="$(lttng_pgrep "$SESSIOND_MATCH")"
825 # Wait until state becomes stopped for session
828 for sessiond_pid
in $pids; do
829 state
="$(ps -p "$sessiond_pid" -o state= )"
830 if [[ -n "$state" && "$state" != "T" ]]; then
836 if [ "$withtap" -eq "1" ]; then
837 pass
"Sending SIGSTOP to session daemon"
842 function sigstop_lttng_sessiond
()
844 sigstop_lttng_sessiond_opt
1 "$@"
847 function sigstop_lttng_sessiond_notap
()
849 sigstop_lttng_sessiond_opt
0 "$@"
852 function stop_lttng_consumerd_opt
()
862 if [ -z "$signal" ]; then
866 # Multiply time by 2 to simplify integer arithmetic
867 if [ -n "$timeout_s" ]; then
868 dtimeleft_s
=$
((timeout_s
* 2))
871 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
873 if [ -z "$pids" ]; then
874 if [ "$is_cleanup" -eq 1 ]; then
876 elif [ "$withtap" -eq "1" ]; then
877 fail
"No consumerd daemon to kill"
879 LTTNG_BAIL_OUT
"No consumerd daemon to kill"
884 diag
"Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')"
886 # shellcheck disable=SC2086
887 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
889 if [ "$withtap" -eq "1" ]; then
890 fail
"Kill consumer daemon"
894 while [ $out -ne 0 ]; do
895 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
897 # If consumerds are still present check their status.
898 # A zombie status qualifies the consumerd as *killed*
900 for consumer_pid
in $pids; do
901 state
="$(ps -p "$consumer_pid" -o state= )"
902 if [[ -n "$state" && "$state" != "Z" ]]; then
906 if [ -n "$dtimeleft_s" ]; then
907 if [ $dtimeleft_s -lt 0 ]; then
911 dtimeleft_s
=$
((dtimeleft_s
- 1))
915 if [ "$withtap" -eq "1" ]; then
916 if [ "$retval" -eq "0" ]; then
917 pass
"Wait after kill consumer daemon"
919 fail
"Wait after kill consumer daemon"
927 function stop_lttng_consumerd
()
929 stop_lttng_consumerd_opt
1 0 "$@"
932 function stop_lttng_consumerd_notap
()
934 stop_lttng_consumerd_opt
0 0 "$@"
937 function stop_lttng_consumerd_cleanup
()
939 stop_lttng_consumerd_opt
0 1 "$@"
942 function sigstop_lttng_consumerd_opt
()
948 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
950 diag
"Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')"
952 # shellcheck disable=SC2086
953 kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
956 if [ $retval -eq 1 ]; then
957 if [ "$withtap" -eq "1" ]; then
958 fail
"Sending SIGSTOP to consumer daemon"
963 while [ $out -ne 0 ]; do
964 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
966 # Wait until state becomes stopped for all
969 for consumer_pid
in $pids; do
970 state
="$(ps -p "$consumer_pid" -o state= )"
971 if [[ -n "$state" && "$state" != "T" ]]; then
977 if [ "$withtap" -eq "1" ]; then
978 pass
"Sending SIGSTOP to consumer daemon"
984 function sigstop_lttng_consumerd
()
986 sigstop_lttng_consumerd_opt
1 "$@"
989 function sigstop_lttng_consumerd_notap
()
991 sigstop_lttng_consumerd_opt
0 "$@"
994 function list_lttng_with_opts
()
997 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN list
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
998 ok $?
"Lttng-tool list command with option $opts"
1001 function create_lttng_session_no_output
()
1006 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name --no-output $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1007 ok $?
"Create session $sess_name in no-output mode"
1010 function create_lttng_session_uri
() {
1015 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -U $uri $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1016 ok $?
"Create session $sess_name with uri:$uri and opts: $opts"
1019 function create_lttng_session
()
1022 local expected_to_fail
=$2
1027 if [ -z "$trace_path" ]; then
1028 # Use lttng-sessiond default output.
1031 trace_path
="-o $trace_path"
1034 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
"$sess_name" $trace_path $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1036 if [ $expected_to_fail -eq "1" ]; then
1039 if [ $withtap -eq "1" ]; then
1040 ok
$ret "Create session $sess_name in $trace_path failed as expected"
1043 if [ $withtap -eq "1" ]; then
1044 ok
$ret "Create session $sess_name in $trace_path"
1050 function create_lttng_session_ok
()
1052 create_lttng_session
1 0 "$@"
1055 function create_lttng_session_fail
()
1057 create_lttng_session
1 1 "$@"
1060 function create_lttng_session_notap
()
1062 create_lttng_session
0 0 "$@"
1066 function enable_ust_lttng_channel
()
1069 local expected_to_fail
=$2
1071 local channel_name
=$4
1074 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-u $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1076 if [[ $expected_to_fail -eq "1" ]]; then
1079 if [ $withtap -eq "1" ]; then
1080 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
1083 if [ $withtap -eq "1" ]; then
1084 ok
$ret "Enable channel $channel_name for session $sess_name"
1090 function enable_ust_lttng_channel_ok
()
1092 enable_ust_lttng_channel
1 0 "$@"
1095 function enable_ust_lttng_channel_fail
()
1097 enable_ust_lttng_channel
1 1 "$@"
1100 function enable_ust_lttng_channel_notap
()
1102 enable_ust_lttng_channel
0 0 "$@"
1105 function disable_ust_lttng_channel
()
1108 local channel_name
=$2
1110 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1111 ok $?
"Disable channel $channel_name for session $sess_name"
1114 function enable_lttng_mmap_overwrite_kernel_channel
()
1117 local channel_name
=$2
1119 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1120 ok $?
"Enable channel $channel_name for session $sess_name"
1123 function enable_lttng_mmap_discard_small_kernel_channel
()
1126 local channel_name
=$2
1128 $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
1129 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1132 function enable_lttng_mmap_overwrite_small_kernel_channel
()
1135 local channel_name
=$2
1137 $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
1138 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1141 function enable_lttng_mmap_overwrite_ust_channel
()
1144 local channel_name
=$2
1146 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1147 ok $?
"Enable channel $channel_name for session $sess_name"
1150 function enable_ust_lttng_event
()
1153 local expected_to_fail
=$2
1155 local event_name
="$4"
1156 local channel_name
=$5
1158 if [ -z $channel_name ]; then
1159 # default channel if none specified
1162 chan
="-c $channel_name"
1165 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1167 if [[ $expected_to_fail -eq "1" ]]; then
1170 if [[ $withtap -eq "1" ]]; then
1171 ok
$ret "Enable ust event $event_name for session $session_name failed as expected"
1174 if [[ $withtap -eq "1" ]]; then
1175 ok
$ret "Enable ust event $event_name for session $sess_name"
1181 function enable_ust_lttng_event_ok
()
1183 enable_ust_lttng_event
1 0 "$@"
1186 function enable_ust_lttng_event_fail
()
1188 enable_ust_lttng_event
1 1 "$@"
1191 function enable_ust_lttng_event_notap
()
1193 enable_ust_lttng_event
0 0 "$@"
1196 function enable_jul_lttng_event
()
1202 if [ -z $channel_name ]; then
1203 # default channel if none specified
1206 chan
="-c $channel_name"
1209 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1210 ok $?
"Enable JUL event $event_name for session $sess_name"
1213 function enable_jul_lttng_event_loglevel
()
1216 local event_name
="$2"
1218 local channel_name
=$4
1220 if [ -z $channel_name ]; then
1221 # default channel if none specified
1224 chan
="-c $channel_name"
1227 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1228 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
1231 function enable_log4j_lttng_event
()
1237 if [ -z $channel_name ]; then
1238 # default channel if none specified
1241 chan
="-c $channel_name"
1244 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1245 ok $?
"Enable LOG4J event $event_name for session $sess_name"
1248 function enable_log4j_lttng_event_loglevel
()
1251 local event_name
="$2"
1253 local channel_name
=$4
1255 if [ -z $channel_name ]; then
1256 # default channel if none specified
1259 chan
="-c $channel_name"
1262 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1263 ok $?
"Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
1266 function enable_python_lttng_event
()
1272 if [ -z $channel_name ]; then
1273 # default channel if none specified
1276 chan
="-c $channel_name"
1279 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1280 ok $?
"Enable Python event $event_name for session $sess_name"
1283 function enable_python_lttng_event_loglevel
()
1286 local event_name
="$2"
1288 local channel_name
=$4
1290 if [ -z $channel_name ]; then
1291 # default channel if none specified
1294 chan
="-c $channel_name"
1297 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1298 ok $?
"Enable Python event $event_name for session $sess_name with loglevel $loglevel"
1301 function enable_ust_lttng_event_filter
()
1303 local sess_name
="$1"
1304 local event_name
="$2"
1306 local channel_name
=$4
1308 if [ -z $channel_name ]; then
1309 # default channel if none specified
1312 chan
="-c $channel_name"
1315 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
$chan "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1316 ok $?
"Enable event $event_name with filtering for session $sess_name"
1319 function enable_ust_lttng_event_loglevel
()
1321 local sess_name
="$1"
1322 local event_name
="$2"
1325 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1326 ok $?
"Enable event $event_name with loglevel $loglevel"
1329 function enable_ust_lttng_event_loglevel_only
()
1331 local sess_name
="$1"
1332 local event_name
="$2"
1335 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1336 ok $?
"Enable event $event_name with loglevel-only $loglevel"
1339 function disable_ust_lttng_event
()
1341 local sess_name
="$1"
1342 local event_name
="$2"
1343 local channel_name
="$3"
1345 if [ -z $channel_name ]; then
1346 # default channel if none specified
1349 chan
="-c $channel_name"
1352 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1353 ok $?
"Disable event $event_name for session $sess_name"
1356 function disable_jul_lttng_event
()
1358 local sess_name
="$1"
1359 local event_name
="$2"
1361 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
1362 ok $?
"Disable JUL event $event_name for session $sess_name"
1365 function disable_log4j_lttng_event
()
1367 local sess_name
="$1"
1368 local event_name
="$2"
1370 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -l >/dev
/null
2>&1
1371 ok $?
"Disable LOG4J event $event_name for session $sess_name"
1374 function disable_python_lttng_event
()
1376 local sess_name
="$1"
1377 local event_name
="$2"
1379 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1380 ok $?
"Disable Python event $event_name for session $sess_name"
1383 function start_lttng_tracing_opt
()
1386 local expected_to_fail
=$2
1389 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1391 if [[ $expected_to_fail -eq "1" ]]; then
1394 if [ $withtap -eq "1" ]; then
1395 ok $?
"Start tracing for session $sess_name failed as expected"
1398 if [ $withtap -eq "1" ]; then
1399 ok
$ret "Start tracing for session $sess_name"
1404 function start_lttng_tracing_ok
()
1406 start_lttng_tracing_opt
1 0 "$@"
1409 function start_lttng_tracing_fail
()
1411 start_lttng_tracing_opt
1 1 "$@"
1414 function start_lttng_tracing_notap
()
1416 start_lttng_tracing_opt
0 1 "$@"
1419 function stop_lttng_tracing_opt
()
1422 local expected_to_fail
=$2
1425 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1427 if [[ $expected_to_fail -eq "1" ]]; then
1430 if [ $withtap -eq "1" ]; then
1431 ok $?
"Stop lttng tracing for session $sess_name failed as expected"
1434 if [ $withtap -eq "1" ]; then
1435 ok
$ret "Stop lttng tracing for session $sess_name"
1440 function stop_lttng_tracing_ok
()
1442 stop_lttng_tracing_opt
1 0 "$@"
1445 function stop_lttng_tracing_fail
()
1447 stop_lttng_tracing_opt
1 1 "$@"
1450 function stop_lttng_tracing_notap
()
1452 stop_lttng_tracing_opt
0 0 "$@"
1455 function destroy_lttng_session
()
1458 local expected_to_fail
=$2
1461 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1463 if [[ $expected_to_fail -eq "1" ]]; then
1466 if [ $withtap -eq "1" ]; then
1467 ok
$ret "Destroy session $sess_name failed as expected"
1470 if [ $withtap -eq "1" ]; then
1471 ok
$ret "Destroy session $sess_name"
1476 function destroy_lttng_session_ok
()
1478 destroy_lttng_session
1 0 "$@"
1482 function destroy_lttng_session_fail
()
1484 destroy_lttng_session
1 1 "$@"
1487 function destroy_lttng_session_notap
()
1489 destroy_lttng_session
0 0 "$@"
1492 function destroy_lttng_sessions
()
1494 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
--all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1495 ok $?
"Destroy all lttng sessions"
1498 function lttng_snapshot_add_output
()
1500 local expected_to_fail
=$1
1505 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name $trace_path $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1507 if [[ $expected_to_fail -eq 1 ]]; then
1509 ok $?
"Added snapshot output $trace_path failed as expected"
1511 ok
$ret "Added snapshot output $trace_path"
1515 function lttng_snapshot_add_output_ok
()
1517 lttng_snapshot_add_output
0 "$@"
1520 function lttng_snapshot_add_output_fail
()
1522 lttng_snapshot_add_output
1 "$@"
1525 function lttng_snapshot_del_output
()
1527 local expected_to_fail
=$1
1531 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output
-s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1533 if [[ $expected_to_fail -eq "1" ]]; then
1535 ok $?
"Deleted snapshot output id $id failed as expected"
1537 ok
$ret "Deleted snapshot output id $id"
1541 function lttng_snapshot_del_output_ok
()
1543 lttng_snapshot_del_output
0 "$@"
1546 function lttng_snapshot_del_output_fail
()
1548 lttng_snapshot_del_output
1 "$@"
1551 function lttng_snapshot_record
()
1556 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot record
-s "$sess_name" "$trace_path" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1557 ok $?
"Snapshot recorded"
1560 function lttng_snapshot_list
()
1563 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1564 ok $?
"Snapshot list"
1567 function lttng_save
()
1572 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN save
$sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1573 ok $?
"Session saved"
1576 function lttng_load
()
1578 local expected_to_fail
=$1
1581 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN load
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1583 if [[ $expected_to_fail -eq "1" ]]; then
1585 ok $?
"Load command failed as expected with opts: $opts"
1587 ok
$ret "Load command with opts: $opts"
1591 function lttng_load_ok
()
1596 function lttng_load_fail
()
1601 function lttng_track
()
1603 local expected_to_fail
="$1"
1606 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN track
$opts >$OUTPUT_DEST
1608 if [[ $expected_to_fail -eq "1" ]]; then
1610 ok $?
"Track command failed as expected with opts: $opts"
1612 ok
$ret "Track command with opts: $opts"
1616 function lttng_track_ok
()
1621 function lttng_track_fail
()
1626 function lttng_untrack
()
1628 local expected_to_fail
="$1"
1631 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN untrack
$opts >$OUTPUT_DEST
1633 if [[ $expected_to_fail -eq "1" ]]; then
1635 ok $?
"Untrack command failed as expected with opts: $opts"
1637 ok
$ret "Untrack command with opts: $opts"
1641 function lttng_untrack_ok
()
1643 lttng_untrack
0 "$@"
1646 function lttng_untrack_fail
()
1648 lttng_untrack
1 "$@"
1651 function lttng_track_pid_ok
()
1654 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track
--kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1655 ok $?
"Lttng track pid on the kernel domain"
1658 function lttng_untrack_kernel_all_ok
()
1660 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack
--kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1661 ok $?
"Lttng untrack all pid on the kernel domain"
1664 function lttng_track_ust_ok
()
1666 lttng_track_ok
-u "$@"
1669 function lttng_track_ust_fail
()
1671 lttng_track_fail
-u "$@"
1674 function lttng_track_kernel_ok
()
1676 lttng_track_ok
-k "$@"
1679 function lttng_track_kernel_fail
()
1681 lttng_track_fail
-k "$@"
1684 function lttng_untrack_ust_ok
()
1686 lttng_untrack_ok
-u "$@"
1689 function lttng_untrack_ust_fail
()
1691 lttng_untrack_fail
-u "$@"
1694 function lttng_untrack_kernel_ok
()
1696 lttng_untrack_ok
-k "$@"
1699 function lttng_untrack_kernel_fail
()
1701 lttng_untrack_fail
-k "$@"
1704 function lttng_add_context_list
()
1706 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context
--list 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1708 ok
$ret "Context listing"
1711 function add_context_lttng
()
1713 local expected_to_fail
="$1"
1715 local session_name
="$3"
1716 local channel_name
="$4"
1719 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context
-s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1721 if [[ $expected_to_fail -eq "1" ]]; then
1723 ok $?
"Add context command failed as expected for type: $type"
1725 ok
$ret "Add context command for type: $type"
1729 function add_context_ust_ok
()
1731 add_context_lttng
0 -u "$@"
1734 function add_context_ust_fail
()
1736 add_context_lttng
1 -u "$@"
1739 function add_context_kernel_ok
()
1741 add_context_lttng
0 -k "$@"
1744 function add_context_kernel_fail
()
1746 add_context_lttng
1 -k "$@"
1749 function wait_live_trace_ready
()
1752 local zero_client_match
=0
1754 diag
"Waiting for live trace at url: $url"
1755 while [ $zero_client_match -eq 0 ]; do
1756 zero_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "0 client(s) connected" |
wc -l)
1759 pass
"Waiting for live trace at url: $url"
1762 function wait_live_viewer_connect
()
1765 local one_client_match
=0
1767 diag
"Waiting for live viewers on url: $url"
1768 while [ $one_client_match -eq 0 ]; do
1769 one_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "1 client(s) connected" |
wc -l)
1772 pass
"Waiting for live viewers on url: $url"
1775 function validate_metadata_event
()
1778 local nr_event_id
=$2
1781 local metadata_file
=$
(find $trace_path |
grep metadata
)
1782 local metadata_path
=$
(dirname $metadata_file)
1784 which $BABELTRACE_BIN >/dev
/null
1785 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1787 local count
=$
($BABELTRACE_BIN --output-format=ctf-metadata
$metadata_path |
grep $event_name |
wc -l)
1789 if [ "$count" -ne "$nr_event_id" ]; then
1790 fail
"Metadata match with the metadata of $count event(s) named $event_name"
1791 diag
"$count matching event id found in metadata"
1793 pass
"Metadata match with the metadata of $count event(s) named $event_name"
1798 function trace_matches
()
1804 which $BABELTRACE_BIN >/dev
/null
1805 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1807 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1809 if [ "$count" -ne "$nr_iter" ]; then
1811 diag
"$count matching events found in trace"
1817 function trace_match_only
()
1823 which $BABELTRACE_BIN >/dev
/null
1824 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1826 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1827 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1829 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1830 pass
"Trace match with $total event $event_name"
1833 diag
"$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1837 function validate_trace
1842 which $BABELTRACE_BIN >/dev
/null
1843 if [ $?
-ne 0 ]; then
1844 skip
0 "Babeltrace binary not found. Skipping trace validation"
1849 for i
in $event_name; do
1850 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1851 if [ "$traced" -ne 0 ]; then
1852 pass
"Validate trace for event $i, $traced events"
1854 fail
"Validate trace for event $i"
1855 diag
"Found $traced occurences of $i"
1863 function validate_trace_count
1867 local expected_count
=$3
1869 which $BABELTRACE_BIN >/dev
/null
1870 if [ $?
-ne 0 ]; then
1871 skip
0 "Babeltrace binary not found. Skipping trace validation"
1877 for i
in $event_name; do
1878 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1879 if [ "$traced" -ne 0 ]; then
1880 pass
"Validate trace for event $i, $traced events"
1882 fail
"Validate trace for event $i"
1883 diag
"Found $traced occurences of $i"
1885 cnt
=$
(($cnt + $traced))
1888 test $cnt -eq $expected_count
1889 ok $?
"Read a total of $cnt events, expected $expected_count"
1892 function validate_trace_count_range_incl_min_excl_max
1896 local expected_min
=$3
1897 local expected_max
=$4
1899 which $BABELTRACE_BIN >/dev
/null
1900 if [ $?
-ne 0 ]; then
1901 skip
0 "Babeltrace binary not found. Skipping trace validation"
1907 for i
in $event_name; do
1908 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1909 if [ "$traced" -ge $expected_min ]; then
1910 pass
"Validate trace for event $i, $traced events"
1912 fail
"Validate trace for event $i"
1913 diag
"Found $traced occurences of $i"
1915 cnt
=$
(($cnt + $traced))
1918 test $cnt -lt $expected_max
1919 ok $?
"Read a total of $cnt events, expected between [$expected_min, $expected_max["
1922 function trace_first_line
1926 which $BABELTRACE_BIN >/dev
/null
1927 if [ $?
-ne 0 ]; then
1928 skip
0 "Babeltrace binary not found. Skipping trace validation"
1931 $BABELTRACE_BIN $trace_path 2>/dev
/null |
head -n 1
1934 function validate_trace_exp
()
1939 which $BABELTRACE_BIN >/dev
/null
1940 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace validation"
1942 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep --extended-regexp ${event_exp} |
wc -l)
1943 if [ "$traced" -ne 0 ]; then
1944 pass
"Validate trace for expression '${event_exp}', $traced events"
1946 fail
"Validate trace for expression '${event_exp}'"
1947 diag
"Found $traced occurences of '${event_exp}'"
1953 function validate_trace_only_exp
()
1958 which $BABELTRACE_BIN >/dev
/null
1959 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1961 local count
=$
($BABELTRACE_BIN $trace_path |
grep --extended-regexp ${event_exp} |
wc -l)
1962 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1964 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1965 pass
"Trace match with $total for expression '${event_exp}'"
1968 diag
"$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1974 function validate_trace_empty
()
1978 which $BABELTRACE_BIN >/dev
/null
1979 if [ $?
-ne 0 ]; then
1980 skip
0 "Babeltrace binary not found. Skipping trace validation"
1983 events
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null
)
1985 if [ $ret -ne 0 ]; then
1986 fail
"Failed to parse trace"
1990 traced
=$
(echo -n "$events" |
wc -l)
1991 if [ "$traced" -eq 0 ]; then
1992 pass
"Validate empty trace"
1994 fail
"Validate empty trace"
1995 diag
"Found $traced events in trace"
2001 function validate_directory_empty
()
2003 local trace_path
="$1"
2005 # Do not double quote `$trace_path` below as we want wildcards to be
2007 files
="$(ls -A $trace_path)"
2009 if [ $ret -ne 0 ]; then
2010 fail
"Failed to list content of directory \"$trace_path\""
2014 nb_files
="$(echo -n "$files" | wc -l)"
2015 ok
$nb_files "Directory \"$trace_path\" is empty"
2018 function validate_trace_session_ust_empty
()
2020 validate_directory_empty
"$1"/ust
2023 function validate_trace_session_kernel_empty
()
2025 validate_trace_empty
"$1"/kernel
2028 function regenerate_metadata
()
2030 local expected_to_fail
=$1
2033 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN regenerate metadata
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2035 if [[ $expected_to_fail -eq "1" ]]; then
2037 ok $?
"Expected fail on regenerate metadata $sess_name"
2039 ok
$ret "Metadata regenerate $sess_name"
2043 function regenerate_metadata_ok
()
2045 regenerate_metadata
0 "$@"
2048 function regenerate_metadata_fail
()
2050 regenerate_metadata
1 "$@"
2053 function regenerate_statedump
()
2055 local expected_to_fail
=$1
2058 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN regenerate statedump
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2060 if [[ $expected_to_fail -eq "1" ]]; then
2062 ok $?
"Expected fail on regenerate statedump $sess_name"
2064 ok
$ret "Statedump regenerate $sess_name"
2068 function regenerate_statedump_ok
()
2070 regenerate_statedump
0 "$@"
2073 function regenerate_statedump_fail
()
2075 regenerate_statedump
1 "$@"
2078 function rotate_session
()
2080 local expected_to_fail
=$1
2083 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN rotate
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2085 if [[ $expected_to_fail -eq "1" ]]; then
2087 ok $?
"Expected fail on rotate session $sess_name"
2089 ok
$ret "Rotate session $sess_name"
2093 function rotate_session_ok
()
2095 rotate_session
0 "$@"
2098 function rotate_session_fail
()
2100 rotate_session
1 "$@"
2103 function destructive_tests_enabled
()
2105 if [ "$LTTNG_ENABLE_DESTRUCTIVE_TESTS" = "will-break-my-system" ]; then
2112 function lttng_enable_rotation_timer
()
2114 local expected_to_fail
=$1
2118 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-rotation
-s $sess_name --timer $period 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2120 if [[ $expected_to_fail -eq "1" ]]; then
2122 ok $?
"Expected fail when setting periodic rotation ($period) of session $sess_name"
2124 ok
$ret "Set periodic rotation ($period) of session $sess_name"
2128 function lttng_enable_rotation_timer_ok
()
2130 lttng_enable_rotation_timer
0 $@
2133 function lttng_enable_rotation_timer_fail
()
2135 lttng_enable_rotation_timer
1 $@
2138 function lttng_enable_rotation_size
()
2140 local expected_to_fail
=$1
2144 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-rotation
-s $sess_name --size $size 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2146 if [[ $expected_to_fail -eq "1" ]]; then
2148 ok $?
"Expected fail on rotate session $sess_name"
2150 ok
$ret "Rotate session $sess_name"
2154 function lttng_enable_rotation_size_ok
()
2156 lttng_enable_rotation_size
0 $@
2159 function lttng_enable_rotation_size_fail
()
2161 lttng_enable_rotation_size
1 $@
2164 function lttng_clear_session
()
2166 local expected_to_fail
=$1
2169 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN clear $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2171 if [[ $expected_to_fail -eq "1" ]]; then
2173 ok $?
"Expected fail on clear session $sess_name"
2175 ok
$ret "Clear session $sess_name"
2179 function lttng_clear_session_ok
()
2181 lttng_clear_session
0 $@
2184 function lttng_clear_session_fail
()
2186 lttng_clear_session
1 $@
2189 function lttng_clear_all
()
2191 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN clear --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2192 ok $?
"Clear all lttng sessions"
2195 function lttng_add_trigger
()
2197 local expected_to_fail
="$1"
2198 local trigger_name
="$2"
2202 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN add-trigger --name $trigger_name ${args[*]}"
2203 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-trigger
--name "$trigger_name" "${args[@]}" 1> /dev
/null
2> /dev
/null
2205 if [[ $expected_to_fail -eq "1" ]]; then
2207 ok $?
"Add trigger $trigger_name failed as expected"
2209 ok
$ret "Add trigger $trigger_name"
2213 function lttng_remove_trigger
()
2215 local expected_to_fail
="$1"
2216 local trigger_name
="$2"
2219 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN remove-trigger $trigger_name $*"
2220 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" remove-trigger
"$trigger_name" "$@" 1> /dev
/null
2> /dev
/null
2222 if [[ $expected_to_fail -eq "1" ]]; then
2224 ok $?
"Remove trigger $trigger_name failed as expected"
2226 ok
$ret "Remove trigger $trigger_name"
2230 function lttng_add_trigger_ok
()
2232 lttng_add_trigger
0 "$@"
2235 function lttng_add_trigger_fail
()
2237 lttng_add_trigger
1 "$@"
2240 function lttng_remove_trigger_ok
()
2242 lttng_remove_trigger
0 "$@"