1 # Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
3 # SPDX-License-Identifier: LGPL-2.1-only
6 SESSIOND_BIN
="lttng-sessiond"
7 SESSIOND_MATCH
=".*lttng-sess.*"
8 RUNAS_BIN
="lttng-runas"
9 RUNAS_MATCH
=".*lttng-runas.*"
10 CONSUMERD_BIN
="lttng-consumerd"
11 CONSUMERD_MATCH
=".*lttng-consumerd.*"
12 RELAYD_BIN
="lttng-relayd"
13 RELAYD_MATCH
=".*lttng-relayd.*"
15 BABELTRACE_BIN
="babeltrace2"
17 ERROR_OUTPUT_DEST
=/dev
/null
18 MI_XSD_MAJOR_VERSION
=4
19 MI_XSD_MINOR_VERSION
=1
20 MI_XSD_PATH
="$TESTDIR/../src/common/mi-lttng-${MI_XSD_MAJOR_VERSION}.${MI_XSD_MINOR_VERSION}.xsd"
21 MI_VALIDATE
="$TESTDIR/utils/xml-utils/validate_xml ${MI_XSD_PATH}"
23 XML_PRETTY
="$TESTDIR/utils/xml-utils/pretty_xml"
24 XML_EXTRACT
="$TESTDIR/utils/xml-utils/extract_xml"
25 XML_NODE_CHECK
="${XML_EXTRACT} -e"
27 # To match 20201127-175802
28 date_time_pattern
="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]"
29 # The size of a long on this system
30 system_long_bit_size
=$
(getconf LONG_BIT
)
32 # Minimal kernel version supported for session daemon tests
33 KERNEL_MAJOR_VERSION
=2
34 KERNEL_MINOR_VERSION
=6
35 KERNEL_PATCHLEVEL_VERSION
=27
37 # We set the default UST register timeout and network and app socket timeout to
38 # "wait forever", so that basic tests don't have to worry about hitting
39 # timeouts on busy systems. Specialized tests should test those corner-cases.
40 export LTTNG_UST_REGISTER_TIMEOUT
=-1
41 export LTTNG_NETWORK_SOCKET_TIMEOUT
=-1
42 export LTTNG_APP_SOCKET_TIMEOUT
=-1
44 # We set the default lttng-sessiond path to /bin/true to prevent the spawning
45 # of a daemonized sessiond. This is necessary since 'lttng create' will spawn
46 # its own sessiond if none is running. It also ensures that 'lttng create'
47 # fails when no sessiond is running.
48 export LTTNG_SESSIOND_PATH
="/bin/true"
50 source $TESTDIR/utils
/tap
/tap.sh
52 if [ -z ${LTTNG_TEST_TEARDOWN_TIMEOUT+x} ]; then
53 LTTNG_TEST_TEARDOWN_TIMEOUT
=60
56 # Enable job monitor mode.
57 # Here we are mostly interested in the following from the monitor mode:
58 # All processes run in a separate process group.
59 # This allows us to ensure that all subprocesses from all background tasks are
60 # cleaned up correctly using signal to process group id.
63 kill_background_jobs
()
68 if [ -z "$pids" ]; then
75 # Use negative number to send the signal to the process group.
76 # This ensure that any subprocesses receive the signal.
77 # /dev/null is used since there is an acceptable race between
78 # the moments the pids are listed and the moment we send a
80 kill -SIGTERM -- "-$pid" 2>/dev
/null
86 # Try to kill daemons gracefully
87 stop_lttng_relayd_cleanup SIGTERM
$LTTNG_TEST_TEARDOWN_TIMEOUT
88 stop_lttng_sessiond_cleanup SIGTERM
$LTTNG_TEST_TEARDOWN_TIMEOUT
90 # If daemons are still present, forcibly kill them
91 stop_lttng_relayd_cleanup SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
92 stop_lttng_sessiond_cleanup SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
93 stop_lttng_consumerd_cleanup SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
98 function full_cleanup
()
104 function LTTNG_BAIL_OUT
()
110 function null_pipes
()
117 trap full_cleanup SIGINT SIGTERM
119 # perl prove closes its child pipes before giving it a chance to run its
120 # signal trap handlers. Redirect pipes to /dev/null if SIGPIPE is caught
121 # to allow those trap handlers to proceed.
123 trap null_pipes SIGPIPE
125 # Check pgrep from env, default to pgrep if none
126 if [ -z "$PGREP" ]; then
130 # Due to the renaming of threads we need to use the full command (pgrep -f) to
131 # identify the pids for multiple lttng related processes. The problem with "pgrep
132 # -f" is that it ends up also looking at the arguments. We use a two stage
133 # lookup. The first one is using "pgrep -f" yielding potential candidate.
134 # The second on perform grep on the basename of the first field of the
135 # /proc/pid/cmdline of the previously identified pids. The first field
136 # correspond to the actual command.
137 function lttng_pgrep
()
141 local full_command_no_argument
142 local command_basename
144 possible_pids
=$
($PGREP -f "$pattern")
145 if [ -z "$possible_pids" ]; then
149 while IFS
= read -r pid
; do
150 # /proc/pid/cmdline is null separated.
151 if full_command_no_argument
=$
( (tr '\0' '\n' < /proc
/"$pid"/cmdline
) 2>/dev
/null |
head -n1); then
152 command_basename
=$
(basename "$full_command_no_argument")
153 if grep -q "$pattern" <<< "$command_basename"; then
157 done <<< "$possible_pids"
163 # Check if we are a terminal
165 echo -e "\e[1;32mOK\e[0m"
171 function print_fail
()
173 # Check if we are a terminal
175 echo -e "\e[1;31mFAIL\e[0m"
181 function print_test_banner
()
187 function validate_kernel_version
()
189 local kern_version
=($
(uname
-r |
awk -F.
'{ printf("%d.%d.%d\n",$1,$2,$3); }' |
tr '.' '\n'))
190 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
193 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
196 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
202 # Generate a random string
203 # $1 = number of characters; defaults to 16
204 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
205 function randstring
()
209 [ "$2" == "0" ] && CHAR
="[:alnum:]" || CHAR
="[:graph:]"
210 # /dev/urandom isn't guaranteed to generate valid multi-byte characters.
211 # Specifying the C locale eliminates the "Illegal byte sequence" error
212 # that 'tr' outputs in such cases.
213 LC_CTYPE
=C
tr -cd "$CHAR" < /dev
/urandom
2>/dev
/null |
head -c "$len" 2>/dev
/null
217 # Helpers for get_possible_cpus.
218 function get_possible_cpus_count_from_sysfs_possible_mask
()
220 local max_possible_cpu_id
222 # The Awk script extracts the highest CPU id from the possible CPU
223 # mask. Assuming a numerical order, a field separator '-' and a record
224 # separator ','. The last value parsed is the highest id.
225 if [ -f /sys
/devices
/system
/cpu
/possible
]; then
226 max_possible_cpu_id
=$
(awk -F '-' 'BEGIN { RS = ","} { last = $NF } END { printf("%d\n", last) }' \
227 /sys
/devices
/system
/cpu
/possible
)
228 echo "$((max_possible_cpu_id+1))"
234 # This is a fallback if the possible CPU mask is not available. This will not
235 # take into account unplugged CPUs.
236 function get_max_cpus_count_from_sysfs_cpu_directories
()
238 local max_possible_cpu_id
=0
241 for i
in /sys
/devices
/system
/cpu
/cpu
[0-9]*; do
242 current_cpu_id
="${i#/sys/devices/system/cpu/cpu}"
243 if [ "$current_cpu_id" -gt "$max_possible_cpu_id" ]; then
244 max_possible_cpu_id
="$current_cpu_id"
248 echo "$((max_possible_cpu_id+1))"
251 # Return the number of possible CPUs.
252 function get_possible_cpus_count
()
254 local possible_cpus_count
255 possible_cpus_count
=$
(get_possible_cpus_count_from_sysfs_possible_mask
)
257 if [ "$possible_cpus_count" -eq "0" ]; then
258 local configured_cpus_count
259 configured_cpus_count
=$
(getconf _NPROCESSORS_CONF
)
260 possible_cpus_count
=$
(get_max_cpus_count_from_sysfs_cpu_directories
)
261 possible_cpus_count
=$
((configured_cpus_count
> possible_cpus_count \
262 ? configured_cpus_count \
263 : possible_cpus_count
))
266 echo "$possible_cpus_count"
269 # Return the list of exposed CPU.
271 # NOTE! Use it like so:
273 # IFS=" " read -r -a VARIABLE <<< "$(get_exposed_cpus_list)"
274 function get_exposed_cpus_list
()
278 for i
in /sys
/devices
/system
/cpu
/cpu
[0-9]*; do
279 list
+=("${i#/sys/devices/system/cpu/cpu}")
285 # Return any available CPU found. Do not make assumption about the returned
286 # value, e.g. that it could be 0.
287 function get_any_available_cpu
()
289 for cpu
in /sys
/devices
/system
/cpu
/cpu
[0-9]*; do
290 echo "${cpu#/sys/devices/system/cpu/cpu}"
295 # Return the number of _configured_ CPUs.
296 function conf_proc_count
()
298 getconf _NPROCESSORS_CONF
299 if [ $?
-ne 0 ]; then
300 diag
"Failed to get the number of configured CPUs"
305 # Check if base lttng-modules are present.
306 # Bail out on failure
307 function validate_lttng_modules_present
()
309 # Check for loadable modules.
310 modprobe
-n lttng-tracer
2>/dev
/null
311 if [ $?
-eq 0 ]; then
315 # Check for builtin modules.
316 ls /proc
/lttng
> /dev
/null
2>&1
317 if [ $?
-eq 0 ]; then
321 LTTNG_BAIL_OUT
"LTTng modules not detected."
324 # Run the lttng binary.
326 # The first two arguments are stdout and stderr redirect paths, respectively.
327 # The rest of the arguments are forwarded to the lttng binary
328 function _run_lttng_cmd
330 local stdout_dest
="$1"
331 local stderr_dest
="$2"
334 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN $*"
335 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN "$@" 1> "$stdout_dest" 2> "$stderr_dest"
338 function enable_kernel_lttng_event
341 local expected_to_fail
="$2"
343 local event_name
="$4"
344 local channel_name
="$5"
346 if [ -z "$event_name" ]; then
347 # Enable all event if no event name specified
351 if [ -z "$channel_name" ]; then
352 # default channel if none specified
355 chan
="-c $channel_name"
358 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
359 enable-event
"$event_name" $chan -s $sess_name -k
361 if [[ $expected_to_fail -eq "1" ]]; then
364 if [ $withtap -eq "1" ]; then
365 ok
$ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
368 if [ $withtap -eq "1" ]; then
369 ok
$ret "Enable kernel event $event_name for session $sess_name"
374 function enable_kernel_lttng_event_ok
()
376 enable_kernel_lttng_event
1 0 "$@"
379 function enable_kernel_lttng_event_fail
()
381 enable_kernel_lttng_event
1 1 "$@"
384 function enable_kernel_lttng_event_notap
()
386 enable_kernel_lttng_event
0 0 "$@"
390 function lttng_enable_kernel_event
392 enable_kernel_lttng_event_ok
"$@"
395 function lttng_enable_kernel_syscall
()
397 local expected_to_fail
=$1
399 local syscall_name
=$3
400 local channel_name
=$4
402 if [ -z $syscall_name ]; then
403 # Enable all event if no syscall name specified
407 if [ -z $channel_name ]; then
408 # default channel if none specified
411 chan
="-c $channel_name"
414 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
415 enable-event
--syscall "$syscall_name" $chan -s $sess_name -k
417 if [[ $expected_to_fail -eq "1" ]]; then
419 ok $?
"Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
421 ok
$ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
425 function lttng_enable_kernel_syscall_ok
()
427 lttng_enable_kernel_syscall
0 "$@"
430 function lttng_enable_kernel_syscall_fail
()
432 lttng_enable_kernel_syscall
1 "$@"
435 function lttng_disable_kernel_syscall
()
437 local expected_to_fail
=$1
439 local syscall_name
=$3
440 local channel_name
=$4
442 if [ -z $syscall_name ]; then
443 # Enable all event if no syscall name specified
447 if [ -z $channel_name ]; then
448 # default channel if none specified
451 chan
="-c $channel_name"
454 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
455 disable-event
--syscall "$syscall_name" $chan -s $sess_name -k
458 if [[ $expected_to_fail -eq "1" ]]; then
460 ok $?
"Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
462 ok
$ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
466 function lttng_disable_kernel_syscall_ok
()
468 lttng_disable_kernel_syscall
0 "$@"
471 function lttng_disable_kernel_syscall_fail
()
473 lttng_disable_kernel_syscall
1 "$@"
476 function lttng_enable_kernel_function_event
()
478 local expected_to_fail
="$1"
481 local event_name
="$4"
483 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
--kernel --function="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
485 if [[ $expected_to_fail -eq "1" ]]; then
487 ok $?
"Enable kernel function event for session $sess_name failed as expected"
489 ok
$ret "Enable kernel function event for session $sess_name"
493 function lttng_enable_kernel_function_event_ok
()
495 lttng_enable_kernel_function_event
0 "$@"
498 function lttng_enable_kernel_userspace_probe_event
()
500 local expected_to_fail
="$1"
503 local event_name
="$4"
505 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
--kernel --userspace-probe="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
507 if [[ $expected_to_fail -eq "1" ]]; then
509 ok $?
"Enable kernel userspace probe event for session $sess_name failed as expected"
511 ok
$ret "Enable kernel userspace probe event for session $sess_name"
515 function lttng_enable_kernel_userspace_probe_event_fail
()
517 lttng_enable_kernel_userspace_probe_event
1 "$@"
520 function lttng_enable_kernel_userspace_probe_event_ok
()
522 lttng_enable_kernel_userspace_probe_event
0 "$@"
525 function disable_kernel_lttng_userspace_probe_event_ok
()
528 local event_name
="$2"
530 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" disable-event
--kernel "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
531 ok $?
"Disable kernel event $target for session $sess_name"
533 function lttng_enable_kernel_channel
()
536 local expected_to_fail
=$2
538 local channel_name
=$4
541 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
542 enable-channel
-k $channel_name -s $sess_name $opts
544 if [[ $expected_to_fail -eq "1" ]]; then
547 if [ $withtap -eq "1" ]; then
548 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
551 if [ $withtap -eq "1" ]; then
552 ok
$ret "Enable channel $channel_name for session $sess_name"
557 function lttng_enable_kernel_channel_ok
()
559 lttng_enable_kernel_channel
1 0 "$@"
562 function lttng_enable_kernel_channel_fail
()
564 lttng_enable_kernel_channel
1 1 "$@"
567 function lttng_enable_kernel_channel_notap
()
569 lttng_enable_kernel_channel
0 0 "$@"
572 function enable_kernel_lttng_channel_ok
()
574 lttng_enable_kernel_channel
1 0 "$@"
577 function lttng_disable_kernel_channel
()
579 local expected_to_fail
=$1
581 local channel_name
=$3
583 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
584 disable-channel
-k $channel_name -s $sess_name
586 if [[ $expected_to_fail -eq "1" ]]; then
588 ok $?
"Disable channel $channel_name for session $sess_name failed as expected"
590 ok
$ret "Disable channel $channel_name for session $sess_name"
594 function lttng_disable_kernel_channel_ok
()
596 lttng_disable_kernel_channel
0 "$@"
599 function lttng_disable_kernel_channel_fail
()
601 lttng_disable_kernel_channel
1 "$@"
604 function start_lttng_relayd_opt
()
607 local process_mode
=$2
610 DIR
=$
(readlink
-f "$TESTDIR")
612 if [ -z $
(lttng_pgrep
"$RELAYD_MATCH") ]; then
613 # shellcheck disable=SC2086
614 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
615 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
616 if [ $?
-eq 1 ]; then
617 if [ $withtap -eq "1" ]; then
618 fail
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
622 if [ $withtap -eq "1" ]; then
623 pass
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
627 pass
"Start lttng-relayd (opt: $opt)"
631 function start_lttng_relayd
()
633 start_lttng_relayd_opt
1 "-b" "$@"
636 function start_lttng_relayd_notap
()
638 start_lttng_relayd_opt
0 "-b" "$@"
641 function stop_lttng_relayd_opt
()
651 if [ -z "$signal" ]; then
656 # Multiply time by 2 to simplify integer arithmetic
657 if [ -n "$timeout_s" ]; then
658 dtimeleft_s
=$
((timeout_s
* 2))
662 pids
=$
(lttng_pgrep
"$RELAYD_MATCH")
663 if [ -z "$pids" ]; then
664 if [ "$is_cleanup" -eq 1 ]; then
666 elif [ "$withtap" -eq "1" ]; then
667 fail
"No relay daemon to kill"
669 LTTNG_BAIL_OUT
"No relay daemon to kill"
674 diag
"Killing (signal $signal) lttng-relayd (pid: $pids)"
676 # shellcheck disable=SC2086
677 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
679 if [ "$withtap" -eq "1" ]; then
680 fail
"Kill relay daemon"
684 while [ -n "$out" ]; do
685 out
=$
(lttng_pgrep
"$RELAYD_MATCH")
686 if [ -n "$dtimeleft_s" ]; then
687 if [ $dtimeleft_s -lt 0 ]; then
691 dtimeleft_s
=$
((dtimeleft_s
- 1))
695 if [ "$withtap" -eq "1" ]; then
696 if [ "$retval" -eq "0" ]; then
697 pass
"Wait after kill relay daemon"
699 fail
"Wait after kill relay daemon"
706 function stop_lttng_relayd
()
708 stop_lttng_relayd_opt
1 0 "$@"
711 function stop_lttng_relayd_notap
()
713 stop_lttng_relayd_opt
0 0 "$@"
716 function stop_lttng_relayd_cleanup
()
718 stop_lttng_relayd_opt
0 1 "$@"
721 #First arg: show tap output
722 #Second argument: load path for automatic loading
723 function start_lttng_sessiond_opt
()
728 # The rest of the arguments will be passed directly to lttng-sessiond.
734 local long_bit_value
=
735 long_bit_value
=$
(getconf LONG_BIT
)
737 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
738 # Env variable requested no session daemon
742 DIR
=$
(readlink
-f "$TESTDIR")
744 # Get long_bit value for 32/64 consumerd
745 case "$long_bit_value" in
747 consumerd
="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
750 consumerd
="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
757 # Check for env. variable. Allow the use of LD_PRELOAD etc.
758 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
759 env_vars
="${LTTNG_SESSIOND_ENV_VARS} "
761 env_vars
="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN"
763 if ! validate_kernel_version
; then
764 fail
"Start session daemon"
765 LTTNG_BAIL_OUT
"*** Kernel too old for session daemon tests ***"
768 diag
"export LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/"
769 : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/"}"
770 export LTTNG_SESSION_CONFIG_XSD_PATH
772 if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ]; then
774 if [ -n "$load_path" ]; then
775 diag
"env $env_vars --load $load_path --background $consumerd $@"
776 # shellcheck disable=SC2086
777 env
$env_vars --load "$load_path" --background "$consumerd" "$@"
779 diag
"env $env_vars --background $consumerd $@"
780 # shellcheck disable=SC2086
781 env
$env_vars --background "$consumerd" "$@"
783 #$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
785 if [ "$withtap" -eq "1" ]; then
786 ok
$status "Start session daemon"
791 function start_lttng_sessiond
()
793 start_lttng_sessiond_opt
1 "$@"
796 function start_lttng_sessiond_notap
()
798 start_lttng_sessiond_opt
0 "$@"
801 function stop_lttng_sessiond_opt
()
812 if [ -z "$signal" ]; then
816 # Multiply time by 2 to simplify integer arithmetic
817 if [ -n "$timeout_s" ]; then
818 dtimeleft_s
=$
((timeout_s
* 2))
821 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
822 # Env variable requested no session daemon
826 runas_pids
=$
(lttng_pgrep
"$RUNAS_MATCH")
827 pids
=$
(lttng_pgrep
"$SESSIOND_MATCH")
829 if [ -n "$runas_pids" ]; then
830 pids
="$pids $runas_pids"
833 if [ -z "$pids" ]; then
834 if [ "$is_cleanup" -eq 1 ]; then
836 elif [ "$withtap" -eq "1" ]; then
837 fail
"No session daemon to kill"
839 LTTNG_BAIL_OUT
"No session daemon to kill"
844 diag
"Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
846 # shellcheck disable=SC2086
847 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
849 if [ "$withtap" -eq "1" ]; then
850 fail
"Kill sessions daemon"
854 while [ -n "$out" ]; do
855 out
=$
(lttng_pgrep
"${SESSIOND_MATCH}")
856 if [ -n "$dtimeleft_s" ]; then
857 if [ $dtimeleft_s -lt 0 ]; then
861 dtimeleft_s
=$
((dtimeleft_s
- 1))
866 while [ -n "$out" ]; do
867 out
=$
(lttng_pgrep
"$CONSUMERD_MATCH")
868 if [ -n "$dtimeleft_s" ]; then
869 if [ $dtimeleft_s -lt 0 ]; then
873 dtimeleft_s
=$
((dtimeleft_s
- 1))
878 if [ "$withtap" -eq "1" ]; then
879 if [ "$retval" -eq "0" ]; then
880 pass
"Wait after kill session daemon"
882 fail
"Wait after kill session daemon"
886 if [ "$signal" = "SIGKILL" ]; then
887 if [ "$(id -u)" -eq "0" ]; then
889 modules
="$(lsmod | grep ^lttng | awk '{print $1}')"
891 if [ -n "$modules" ]; then
892 diag
"Unloading all LTTng modules"
893 modprobe
--remove "$modules"
901 function stop_lttng_sessiond
()
903 stop_lttng_sessiond_opt
1 0 "$@"
906 function stop_lttng_sessiond_notap
()
908 stop_lttng_sessiond_opt
0 0 "$@"
911 function stop_lttng_sessiond_cleanup
()
913 stop_lttng_sessiond_opt
0 1 "$@"
916 function sigstop_lttng_sessiond_opt
()
922 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
923 # Env variable requested no session daemon
927 pids
="$(lttng_pgrep "${SESSIOND_MATCH}") $(lttng_pgrep "$RUNAS_MATCH")"
929 if [ "$withtap" -eq "1" ]; then
930 diag
"Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
933 # shellcheck disable=SC2086
934 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
935 if [ "$withtap" -eq "1" ]; then
936 fail
"Sending SIGSTOP to session daemon"
940 while [ $out -ne 0 ]; do
941 pids
="$(lttng_pgrep "$SESSIOND_MATCH")"
943 # Wait until state becomes stopped for session
946 for sessiond_pid
in $pids; do
947 state
="$(ps -p "$sessiond_pid" -o state= )"
948 if [[ -n "$state" && "$state" != "T" ]]; then
954 if [ "$withtap" -eq "1" ]; then
955 pass
"Sending SIGSTOP to session daemon"
960 function sigstop_lttng_sessiond
()
962 sigstop_lttng_sessiond_opt
1 "$@"
965 function sigstop_lttng_sessiond_notap
()
967 sigstop_lttng_sessiond_opt
0 "$@"
970 function stop_lttng_consumerd_opt
()
980 if [ -z "$signal" ]; then
984 # Multiply time by 2 to simplify integer arithmetic
985 if [ -n "$timeout_s" ]; then
986 dtimeleft_s
=$
((timeout_s
* 2))
989 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
991 if [ -z "$pids" ]; then
992 if [ "$is_cleanup" -eq 1 ]; then
994 elif [ "$withtap" -eq "1" ]; then
995 fail
"No consumerd daemon to kill"
997 LTTNG_BAIL_OUT
"No consumerd daemon to kill"
1002 diag
"Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')"
1004 # shellcheck disable=SC2086
1005 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
1007 if [ "$withtap" -eq "1" ]; then
1008 fail
"Kill consumer daemon"
1012 while [ $out -ne 0 ]; do
1013 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
1015 # If consumerds are still present check their status.
1016 # A zombie status qualifies the consumerd as *killed*
1018 for consumer_pid
in $pids; do
1019 state
="$(ps -p "$consumer_pid" -o state= )"
1020 if [[ -n "$state" && "$state" != "Z" ]]; then
1024 if [ -n "$dtimeleft_s" ]; then
1025 if [ $dtimeleft_s -lt 0 ]; then
1029 dtimeleft_s
=$
((dtimeleft_s
- 1))
1033 if [ "$withtap" -eq "1" ]; then
1034 if [ "$retval" -eq "0" ]; then
1035 pass
"Wait after kill consumer daemon"
1037 fail
"Wait after kill consumer daemon"
1045 function stop_lttng_consumerd
()
1047 stop_lttng_consumerd_opt
1 0 "$@"
1050 function stop_lttng_consumerd_notap
()
1052 stop_lttng_consumerd_opt
0 0 "$@"
1055 function stop_lttng_consumerd_cleanup
()
1057 stop_lttng_consumerd_opt
0 1 "$@"
1060 function sigstop_lttng_consumerd_opt
()
1063 local signal
=SIGSTOP
1066 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
1068 diag
"Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')"
1070 # shellcheck disable=SC2086
1071 kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1074 if [ $retval -eq 1 ]; then
1075 if [ "$withtap" -eq "1" ]; then
1076 fail
"Sending SIGSTOP to consumer daemon"
1081 while [ $out -ne 0 ]; do
1082 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
1084 # Wait until state becomes stopped for all
1087 for consumer_pid
in $pids; do
1088 state
="$(ps -p "$consumer_pid" -o state= )"
1089 if [[ -n "$state" && "$state" != "T" ]]; then
1095 if [ "$withtap" -eq "1" ]; then
1096 pass
"Sending SIGSTOP to consumer daemon"
1102 function sigstop_lttng_consumerd
()
1104 sigstop_lttng_consumerd_opt
1 "$@"
1107 function sigstop_lttng_consumerd_notap
()
1109 sigstop_lttng_consumerd_opt
0 "$@"
1112 function list_lttng_with_opts
()
1118 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1121 if [ $withtap -eq "1" ]; then
1122 ok
$ret "Lttng-tool list command with option $opts"
1126 function list_lttng_ok
()
1128 list_lttng_with_opts
1 "$@"
1131 function list_lttng_notap
()
1133 list_lttng_with_opts
0 "$@"
1136 function create_lttng_session_no_output
()
1141 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1142 create
$sess_name --no-output $opts
1143 ok $?
"Create session $sess_name in no-output mode"
1146 function create_lttng_session_uri
() {
1151 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1152 create
$sess_name -U $uri $opts
1153 ok $?
"Create session $sess_name with uri:$uri and opts: $opts"
1156 function create_lttng_session
()
1159 local expected_to_fail
=$2
1164 if [ -z "$trace_path" ]; then
1165 # Use lttng-sessiond default output.
1168 trace_path
="-o $trace_path"
1171 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1172 create
"$sess_name" $trace_path $opt
1174 if [ $expected_to_fail -eq "1" ]; then
1177 if [ $withtap -eq "1" ]; then
1178 ok
$ret "Create session $sess_name in $trace_path failed as expected"
1181 if [ $withtap -eq "1" ]; then
1182 ok
$ret "Create session $sess_name in $trace_path"
1188 function create_lttng_session_ok
()
1190 create_lttng_session
1 0 "$@"
1193 function create_lttng_session_fail
()
1195 create_lttng_session
1 1 "$@"
1198 function create_lttng_session_notap
()
1200 create_lttng_session
0 0 "$@"
1204 function enable_ust_lttng_channel
()
1207 local expected_to_fail
=$2
1209 local channel_name
=$4
1212 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1213 enable-channel
-u $channel_name -s $sess_name $opts
1215 if [[ $expected_to_fail -eq "1" ]]; then
1218 if [ $withtap -eq "1" ]; then
1219 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
1222 if [ $withtap -eq "1" ]; then
1223 ok
$ret "Enable channel $channel_name for session $sess_name"
1229 function enable_ust_lttng_channel_ok
()
1231 enable_ust_lttng_channel
1 0 "$@"
1234 function enable_ust_lttng_channel_fail
()
1236 enable_ust_lttng_channel
1 1 "$@"
1239 function enable_ust_lttng_channel_notap
()
1241 enable_ust_lttng_channel
0 0 "$@"
1244 function disable_ust_lttng_channel
()
1247 local channel_name
=$2
1249 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1250 disable-channel
-u $channel_name -s $sess_name
1251 ok $?
"Disable channel $channel_name for session $sess_name"
1254 function enable_lttng_mmap_overwrite_kernel_channel
()
1257 local channel_name
=$2
1259 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1260 enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite
1261 ok $?
"Enable channel $channel_name for session $sess_name"
1264 function enable_lttng_mmap_discard_small_kernel_channel
()
1267 local channel_name
=$2
1269 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1270 enable-channel
-s $sess_name $channel_name -k --output mmap
--discard --subbuf-size=$
(getconf PAGE_SIZE
) --num-subbuf=2
1271 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1274 function enable_lttng_mmap_overwrite_small_kernel_channel
()
1277 local channel_name
=$2
1279 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1280 enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite --subbuf-size=$
(getconf PAGE_SIZE
) --num-subbuf=2
1281 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1284 function enable_lttng_mmap_overwrite_ust_channel
()
1287 local channel_name
=$2
1289 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1290 enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite
1291 ok $?
"Enable channel $channel_name for session $sess_name"
1294 function enable_ust_lttng_event
()
1297 local expected_to_fail
=$2
1299 local event_name
="$4"
1300 local channel_name
=$5
1302 if [ -z $channel_name ]; then
1303 # default channel if none specified
1306 chan
="-c $channel_name"
1309 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1310 enable-event
"$event_name" $chan -s "$sess_name" -u
1312 if [[ $expected_to_fail -eq "1" ]]; then
1315 if [[ $withtap -eq "1" ]]; then
1316 ok
$ret "Enable ust event $event_name for session $session_name failed as expected"
1319 if [[ $withtap -eq "1" ]]; then
1320 ok
$ret "Enable ust event $event_name for session $sess_name"
1326 function enable_ust_lttng_event_ok
()
1328 enable_ust_lttng_event
1 0 "$@"
1331 function enable_ust_lttng_event_fail
()
1333 enable_ust_lttng_event
1 1 "$@"
1336 function enable_ust_lttng_event_notap
()
1338 enable_ust_lttng_event
0 0 "$@"
1341 function enable_jul_lttng_event
()
1347 if [ -z $channel_name ]; then
1348 # default channel if none specified
1351 chan
="-c $channel_name"
1354 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1355 enable-event
"$event_name" $chan -s $sess_name -j
1356 ok $?
"Enable JUL event $event_name for session $sess_name"
1359 function enable_jul_lttng_event_loglevel
()
1362 local event_name
="$2"
1364 local channel_name
=$4
1366 if [ -z $channel_name ]; then
1367 # default channel if none specified
1370 chan
="-c $channel_name"
1373 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1374 enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j
1375 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
1378 function enable_log4j_lttng_event
()
1382 local channel_name
=$3
1386 # default channel if none specified
1387 if [ -n "$channel_name" ]; then
1388 chan_opt
=("-c" "$channel_name")
1391 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1392 enable-event
"$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j
1393 ok $?
"Enable LOG4J event '$event_name' for session '$sess_name'"
1396 function enable_log4j_lttng_event_filter
()
1402 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1403 enable-event
"$event_name" -s "$sess_name" --log4j --filter "$filter"
1404 ok $?
"Enable LOG4J event '$event_name' with filter '$filter' for session '$sess_name'"
1407 function enable_log4j_lttng_event_filter_loglevel_only
()
1414 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1415 enable-event
--loglevel-only "$loglevel" "$event_name" -s "$sess_name" -l --filter "$filter"
1416 ok $?
"Enable LOG4J event '$event_name' with filter '$filter' and loglevel-only '$loglevel' for session '$sess_name'"
1419 function enable_log4j_lttng_event_loglevel
()
1424 local channel_name
=$4
1427 # default channel if none specified
1428 if [ -n "$channel_name" ]; then
1429 chan_opt
=("-c" "$channel_name")
1432 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1433 enable-event
--loglevel "$loglevel" "$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j
1434 ok $?
"Enable LOG4J event '$event_name' for session '$sess_name' with loglevel '$loglevel'"
1437 function enable_log4j_lttng_event_loglevel_only
()
1442 local channel_name
=$4
1446 # default channel if none specified
1447 if [ -n "$channel_name" ]; then
1448 chan_opt
=("-c" "$channel_name")
1451 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1452 enable-event
--loglevel-only "$loglevel" "$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j
1453 ok $?
"Enable LOG4J event '$event_name' for session '$sess_name' with loglevel-only '$loglevel'"
1456 function enable_python_lttng_event
()
1462 if [ -z $channel_name ]; then
1463 # default channel if none specified
1466 chan
="-c $channel_name"
1469 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1470 enable-event
"$event_name" $chan -s $sess_name -p
1471 ok $?
"Enable Python event $event_name for session $sess_name"
1474 function enable_python_lttng_event_loglevel
()
1477 local event_name
="$2"
1479 local channel_name
=$4
1481 if [ -z $channel_name ]; then
1482 # default channel if none specified
1485 chan
="-c $channel_name"
1488 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1489 enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -p
1490 ok $?
"Enable Python event $event_name for session $sess_name with loglevel $loglevel"
1493 function enable_ust_lttng_event_filter
()
1495 local sess_name
="$1"
1496 local event_name
="$2"
1498 local channel_name
=$4
1500 if [ -z $channel_name ]; then
1501 # default channel if none specified
1504 chan
="-c $channel_name"
1507 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1508 enable-event
$chan "$event_name" -s $sess_name -u --filter "$filter"
1509 ok $?
"Enable event $event_name with filtering for session $sess_name"
1512 function enable_ust_lttng_event_loglevel
()
1514 local sess_name
="$1"
1515 local event_name
="$2"
1517 local channel_name
="$4"
1519 if [ -n "${channel_name}" ] ; then
1520 chan
=('-c' "${channel_name}")
1523 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1524 enable-event
"${chan[@]}" "$event_name" -s "${sess_name}" -u --loglevel="${loglevel}"
1525 ok $?
"Enable event $event_name with loglevel $loglevel"
1528 function enable_ust_lttng_event_loglevel_only
()
1530 local sess_name
="$1"
1531 local event_name
="$2"
1533 local channel_name
="$4"
1535 if [ -n "${channel_name}" ] ; then
1536 chan
=('-c' "${channel_name}")
1539 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1540 enable-event
"${chan[@]}" "$event_name" -s "${sess_name}" -u --loglevel-only "${loglevel}"
1541 ok $?
"Enable event $event_name with loglevel-only $loglevel"
1544 function disable_ust_lttng_event
()
1546 local sess_name
="$1"
1547 local event_name
="$2"
1548 local channel_name
="$3"
1550 if [ -z $channel_name ]; then
1551 # default channel if none specified
1554 chan
="-c $channel_name"
1557 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1558 disable-event
"$event_name" -s $sess_name $chan -u
1559 ok $?
"Disable event $event_name for session $sess_name"
1562 function disable_jul_lttng_event
()
1564 local sess_name
="$1"
1565 local event_name
="$2"
1567 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
1568 ok $?
"Disable JUL event $event_name for session $sess_name"
1571 function disable_log4j_lttng_event
()
1573 local sess_name
="$1"
1574 local event_name
="$2"
1576 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1577 disable-event
"$event_name" -s "$sess_name" --log4j
1578 ok $?
"Disable LOG4J event '$event_name' for session '$sess_name'"
1581 function disable_python_lttng_event
()
1583 local sess_name
="$1"
1584 local event_name
="$2"
1586 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1587 disable-event
"$event_name" -s $sess_name -p
1588 ok $?
"Disable Python event $event_name for session $sess_name"
1591 function start_lttng_tracing_opt
()
1594 local expected_to_fail
=$2
1597 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1600 if [[ $expected_to_fail -eq "1" ]]; then
1603 if [ $withtap -eq "1" ]; then
1604 ok $?
"Start tracing for session $sess_name failed as expected"
1607 if [ $withtap -eq "1" ]; then
1608 ok
$ret "Start tracing for session $sess_name"
1613 function start_lttng_tracing_ok
()
1615 start_lttng_tracing_opt
1 0 "$@"
1618 function start_lttng_tracing_fail
()
1620 start_lttng_tracing_opt
1 1 "$@"
1623 function start_lttng_tracing_notap
()
1625 start_lttng_tracing_opt
0 1 "$@"
1628 function stop_lttng_tracing_opt
()
1631 local expected_to_fail
=$2
1634 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1637 if [[ $expected_to_fail -eq "1" ]]; then
1640 if [ $withtap -eq "1" ]; then
1641 ok $?
"Stop lttng tracing for session $sess_name failed as expected"
1644 if [ $withtap -eq "1" ]; then
1645 ok
$ret "Stop lttng tracing for session $sess_name"
1650 function stop_lttng_tracing_ok
()
1652 stop_lttng_tracing_opt
1 0 "$@"
1655 function stop_lttng_tracing_fail
()
1657 stop_lttng_tracing_opt
1 1 "$@"
1660 function stop_lttng_tracing_notap
()
1662 stop_lttng_tracing_opt
0 0 "$@"
1665 function destroy_lttng_session
()
1668 local expected_to_fail
=$2
1671 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1674 if [[ $expected_to_fail -eq "1" ]]; then
1677 if [ $withtap -eq "1" ]; then
1678 ok
$ret "Destroy session $sess_name failed as expected"
1681 if [ $withtap -eq "1" ]; then
1682 ok
$ret "Destroy session $sess_name"
1687 function destroy_lttng_session_ok
()
1689 destroy_lttng_session
1 0 "$@"
1693 function destroy_lttng_session_fail
()
1695 destroy_lttng_session
1 1 "$@"
1698 function destroy_lttng_session_notap
()
1700 destroy_lttng_session
0 0 "$@"
1703 function destroy_lttng_sessions
()
1705 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1707 ok $?
"Destroy all lttng sessions"
1710 function lttng_snapshot_add_output
()
1712 local expected_to_fail
=$1
1717 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1718 snapshot add-output
-s $sess_name $trace_path $opts
1720 if [[ $expected_to_fail -eq 1 ]]; then
1722 ok $?
"Added snapshot output $trace_path failed as expected"
1724 ok
$ret "Added snapshot output $trace_path"
1728 function lttng_snapshot_add_output_ok
()
1730 lttng_snapshot_add_output
0 "$@"
1733 function lttng_snapshot_add_output_fail
()
1735 lttng_snapshot_add_output
1 "$@"
1738 function lttng_snapshot_del_output
()
1740 local expected_to_fail
=$1
1744 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1745 snapshot del-output
-s $sess_name $id
1747 if [[ $expected_to_fail -eq "1" ]]; then
1749 ok $?
"Deleted snapshot output id $id failed as expected"
1751 ok
$ret "Deleted snapshot output id $id"
1755 function lttng_snapshot_del_output_ok
()
1757 lttng_snapshot_del_output
0 "$@"
1760 function lttng_snapshot_del_output_fail
()
1762 lttng_snapshot_del_output
1 "$@"
1765 function lttng_snapshot_record
()
1770 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1771 snapshot record
-s "$sess_name" "$trace_path"
1772 ok $?
"Snapshot recorded"
1775 function lttng_snapshot_list
()
1778 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1779 snapshot list-output
-s $sess_name
1780 ok $?
"Snapshot list"
1783 function lttng_save
()
1788 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1789 save
$sess_name $opts
1790 ok $?
"Session saved"
1793 function lttng_load
()
1795 local expected_to_fail
=$1
1798 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1801 if [[ $expected_to_fail -eq "1" ]]; then
1803 ok $?
"Load command failed as expected with opts: $opts"
1805 ok
$ret "Load command with opts: $opts"
1809 function lttng_load_ok
()
1814 function lttng_load_fail
()
1819 function lttng_track
()
1821 local expected_to_fail
="$1"
1824 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN track
$opts >$OUTPUT_DEST
1826 if [[ $expected_to_fail -eq "1" ]]; then
1828 ok $?
"Track command failed as expected with opts: $opts"
1830 ok
$ret "Track command with opts: $opts"
1834 function lttng_track_ok
()
1839 function lttng_track_fail
()
1844 function lttng_untrack
()
1846 local expected_to_fail
="$1"
1849 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN untrack
$opts >$OUTPUT_DEST
1851 if [[ $expected_to_fail -eq "1" ]]; then
1853 ok $?
"Untrack command failed as expected with opts: $opts"
1855 ok
$ret "Untrack command with opts: $opts"
1859 function lttng_untrack_ok
()
1861 lttng_untrack
0 "$@"
1864 function lttng_untrack_fail
()
1866 lttng_untrack
1 "$@"
1869 function lttng_track_pid_ok
()
1872 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track
--kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1873 ok $?
"Lttng track pid on the kernel domain"
1876 function lttng_untrack_kernel_all_ok
()
1878 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack
--kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1879 ok $?
"Lttng untrack all pid on the kernel domain"
1882 function lttng_track_ust_ok
()
1884 lttng_track_ok
-u "$@"
1887 function lttng_track_ust_fail
()
1889 lttng_track_fail
-u "$@"
1892 function lttng_track_kernel_ok
()
1894 lttng_track_ok
-k "$@"
1897 function lttng_track_kernel_fail
()
1899 lttng_track_fail
-k "$@"
1902 function lttng_untrack_ust_ok
()
1904 lttng_untrack_ok
-u "$@"
1907 function lttng_untrack_ust_fail
()
1909 lttng_untrack_fail
-u "$@"
1912 function lttng_untrack_kernel_ok
()
1914 lttng_untrack_ok
-k "$@"
1917 function lttng_untrack_kernel_fail
()
1919 lttng_untrack_fail
-k "$@"
1922 function lttng_add_context_list
()
1924 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1927 ok
$ret "Context listing"
1930 function add_context_lttng
()
1932 local expected_to_fail
="$1"
1934 local session_name
="$3"
1935 local channel_name
="$4"
1938 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1939 add-context
-s $session_name -c $channel_name -t $type $domain
1941 if [[ $expected_to_fail -eq "1" ]]; then
1943 ok $?
"Add context command failed as expected for type: $type"
1945 ok
$ret "Add context command for type: $type"
1949 function add_context_ust_ok
()
1951 add_context_lttng
0 -u "$@"
1954 function add_context_ust_fail
()
1956 add_context_lttng
1 -u "$@"
1959 function add_context_kernel_ok
()
1961 add_context_lttng
0 -k "$@"
1964 function add_context_kernel_fail
()
1966 add_context_lttng
1 -k "$@"
1969 function wait_live_trace_ready
()
1972 local zero_client_match
=0
1974 diag
"Waiting for live trace at url: $url"
1975 while [ $zero_client_match -eq 0 ]; do
1976 zero_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "0 client(s) connected" |
wc -l)
1979 pass
"Waiting for live trace at url: $url"
1982 function wait_live_viewer_connect
()
1985 local one_client_match
=0
1987 diag
"Waiting for live viewers on url: $url"
1988 while [ $one_client_match -eq 0 ]; do
1989 one_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "1 client(s) connected" |
wc -l)
1992 pass
"Waiting for live viewers on url: $url"
1995 function bail_out_if_no_babeltrace
()
1997 which "$BABELTRACE_BIN" >/dev
/null
1998 if [ $?
-ne 0 ]; then
1999 LTTNG_BAIL_OUT
"\"$BABELTRACE_BIN\" binary not found. Skipping tests"
2003 # Check that the trace metadata contains '$expected' event ids matching '$event_name'.
2004 function validate_metadata_event
()
2014 metadata_file
=$
(find "$trace_path" -name "metadata")
2015 metadata_path
=$
(dirname "$metadata_file")
2017 bail_out_if_no_babeltrace
2019 count
=$
($BABELTRACE_BIN --output-format=ctf-metadata
"$metadata_path" |
grep -c "$event_name")
2021 test "$count" -eq "$expected"
2022 ok $?
"Found $count / $expected metadata event id matching '$event_name'"
2025 # Check that the trace contains '$expected' events matching '$event_name', other
2026 # events not matching '$event_name' can be present.
2027 function trace_matches
()
2036 bail_out_if_no_babeltrace
2038 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c "$event_name")
2039 total
=$
($BABELTRACE_BIN "$trace_path" |
wc -l)
2041 test "$count" -eq "$expected"
2043 ok $?
"Found $count / $expected events matching '$event_name' out of $total events"
2046 # Check that the trace contains '$expected' events matching '$event_name' and no
2048 function trace_match_only
()
2057 bail_out_if_no_babeltrace
2059 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c "$event_name")
2060 total
=$
($BABELTRACE_BIN "$trace_path" |
wc -l)
2062 test "$expected" -eq "$count" && test "$total" -eq "$expected"
2064 ok $?
"Found $count / $expected events matching '$event_name' amongst $total events"
2067 # Check that the trace contains at least 1 event matching each name in the
2068 # comma separated list '$event_names'.
2069 function validate_trace
()
2071 local event_names
=$1
2076 bail_out_if_no_babeltrace
2080 for event_name
in $event_names; do
2081 # trace_path is unquoted since callers make use of globbing
2082 count
=$
($BABELTRACE_BIN $trace_path |
grep -c "$event_name")
2084 ok $?
"Found $count events matching '$event_name'"
2089 # Check that the trace contains at least 1 event matching each name in the
2090 # comma separated list '$event_names' and a total of '$expected' events.
2091 function validate_trace_count
()
2093 local event_names
=$1
2100 bail_out_if_no_babeltrace
2104 for event_name
in $event_names; do
2105 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c "$event_name")
2107 ok $?
"Found '$count' events matching '$event_name'"
2108 total
=$
(( total
+ count
))
2111 test $total -eq "$expected"
2112 ok $?
"Found $total events, expected $expected events"
2115 # Check that the trace contains at least '$expected_min' event matching each
2116 # name in the comma separated list '$event_names' and a total at least
2117 # '$expected_min' and less than '$expected_max' events.
2118 function validate_trace_count_range_incl_min_excl_max
()
2120 local event_names
=$1
2122 local expected_min
=$3
2123 local expected_max
=$4
2128 bail_out_if_no_babeltrace
2132 for event_name
in $event_names; do
2133 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c "$event_name")
2134 test "$count" -ge "$expected_min"
2135 ok $?
"Found $count events matching '$event_name', expected at least $expected_min"
2136 total
=$
(( total
+ count
))
2139 test $total -ge "$expected_min" && test $total -lt "$expected_max"
2140 ok $?
"Found a total of $total events, expected at least $expected_min and less than $expected_max"
2143 function trace_first_line
()
2147 $BABELTRACE_BIN "$trace_path" |
head -n 1
2150 # Check that the trace contains at least 1 event matching the grep extended
2151 # regexp '$event_exp'.
2152 function validate_trace_exp
()
2159 bail_out_if_no_babeltrace
2161 # event_exp is unquoted since it contains multiple grep arguments
2162 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c --extended-regexp $event_exp)
2164 ok $?
"Found $count events matching expression '$event_exp'"
2167 # Check that the trace contains at least 1 event matching the grep extended
2168 # regexp '$event_exp' and zero event not matching it.
2169 function validate_trace_only_exp
()
2177 bail_out_if_no_babeltrace
2179 # event_exp is unquoted since it contains multiple grep arguments
2180 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c --extended-regexp $event_exp)
2181 total
=$
($BABELTRACE_BIN "$trace_path" |
wc -l)
2183 test "$count" -gt 0 && test "$total" -eq "$count"
2184 ok $?
"Found $count events matching expression '$event_exp' amongst $total events"
2187 # Check that the trace is valid and contains 0 event.
2188 function validate_trace_empty
()
2195 bail_out_if_no_babeltrace
2197 events
=$
($BABELTRACE_BIN "$trace_path")
2199 if [ $ret -ne 0 ]; then
2200 fail
"Failed to parse trace"
2204 count
=$
(echo -n "$events" |
wc -l)
2206 ok $?
"Validate trace is empty, found $count events"
2209 function validate_directory_empty
()
2211 local trace_path
="$1"
2217 # Do not double quote `$trace_path` below as we want wildcards to be
2219 files
="$(ls -A $trace_path)"
2221 if [ $ret -ne 0 ]; then
2222 fail
"Failed to list content of directory \"$trace_path\""
2226 nb_files
="$(echo -n "$files" | wc -l)"
2227 test "$nb_files" -eq 0
2228 ok $?
"Directory \"$trace_path\" is empty"
2231 function validate_trace_session_ust_empty
()
2233 validate_directory_empty
"$1"/ust
2236 function validate_trace_session_kernel_empty
()
2238 validate_trace_empty
"$1"/kernel
2241 function regenerate_metadata
()
2243 local expected_to_fail
=$1
2246 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2247 regenerate metadata
-s $sess_name
2249 if [[ $expected_to_fail -eq "1" ]]; then
2251 ok $?
"Expected fail on regenerate metadata $sess_name"
2253 ok
$ret "Metadata regenerate $sess_name"
2257 function regenerate_metadata_ok
()
2259 regenerate_metadata
0 "$@"
2262 function regenerate_metadata_fail
()
2264 regenerate_metadata
1 "$@"
2267 function regenerate_statedump
()
2269 local expected_to_fail
=$1
2272 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2273 regenerate statedump
-s $sess_name
2275 if [[ $expected_to_fail -eq "1" ]]; then
2277 ok $?
"Expected fail on regenerate statedump $sess_name"
2279 ok
$ret "Statedump regenerate $sess_name"
2283 function regenerate_statedump_ok
()
2285 regenerate_statedump
0 "$@"
2288 function regenerate_statedump_fail
()
2290 regenerate_statedump
1 "$@"
2293 function rotate_session
()
2295 local expected_to_fail
=$1
2298 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2301 if [[ $expected_to_fail -eq "1" ]]; then
2303 ok $?
"Expected fail on rotate session $sess_name"
2305 ok
$ret "Rotate session $sess_name"
2309 function rotate_session_ok
()
2311 rotate_session
0 "$@"
2314 function rotate_session_fail
()
2316 rotate_session
1 "$@"
2319 function destructive_tests_enabled
()
2321 if [ "$LTTNG_ENABLE_DESTRUCTIVE_TESTS" = "will-break-my-system" ]; then
2328 function lttng_enable_rotation_timer
()
2330 local expected_to_fail
=$1
2334 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2335 enable-rotation
-s $sess_name --timer $period
2337 if [[ $expected_to_fail -eq "1" ]]; then
2339 ok $?
"Expected fail when setting periodic rotation ($period) of session $sess_name"
2341 ok
$ret "Set periodic rotation ($period) of session $sess_name"
2345 function lttng_enable_rotation_timer_ok
()
2347 lttng_enable_rotation_timer
0 $@
2350 function lttng_enable_rotation_timer_fail
()
2352 lttng_enable_rotation_timer
1 $@
2355 function lttng_enable_rotation_size
()
2357 local expected_to_fail
=$1
2361 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2362 enable-rotation
-s $sess_name --size $size
2364 if [[ $expected_to_fail -eq "1" ]]; then
2366 ok $?
"Expected to fail to set a periodic rotation of session $sess_name" "every " $size " bytes"
2368 ok
$ret "Set a scheduled rotation of session $sess_name" "every " $size " bytes"
2372 function lttng_enable_rotation_size_ok
()
2374 lttng_enable_rotation_size
0 $@
2377 function lttng_enable_rotation_size_fail
()
2379 lttng_enable_rotation_size
1 $@
2382 function lttng_clear_session
()
2384 local expected_to_fail
=$1
2387 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2390 if [[ $expected_to_fail -eq "1" ]]; then
2392 ok $?
"Expected fail on clear session $sess_name"
2394 ok
$ret "Clear session $sess_name"
2398 function lttng_clear_session_ok
()
2400 lttng_clear_session
0 $@
2403 function lttng_clear_session_fail
()
2405 lttng_clear_session
1 $@
2408 function lttng_clear_all
()
2410 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2412 ok $?
"Clear all lttng sessions"
2415 function lttng_add_trigger
()
2417 local expected_to_fail
="$1"
2418 local trigger_name
="$2"
2422 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN add-trigger --name $trigger_name ${args[*]}"
2423 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-trigger
--name "$trigger_name" "${args[@]}" 1> /dev
/null
2> /dev
/null
2425 if [[ $expected_to_fail -eq "1" ]]; then
2427 ok $?
"Add trigger $trigger_name failed as expected"
2429 ok
$ret "Add trigger $trigger_name"
2433 function lttng_remove_trigger
()
2435 local expected_to_fail
="$1"
2436 local trigger_name
="$2"
2439 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN remove-trigger $trigger_name $*"
2440 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" remove-trigger
"$trigger_name" "$@" 1> /dev
/null
2> /dev
/null
2442 if [[ $expected_to_fail -eq "1" ]]; then
2444 ok $?
"Remove trigger $trigger_name failed as expected"
2446 ok
$ret "Remove trigger $trigger_name"
2450 function lttng_add_trigger_ok
()
2452 lttng_add_trigger
0 "$@"
2455 function lttng_add_trigger_fail
()
2457 lttng_add_trigger
1 "$@"
2460 function lttng_remove_trigger_ok
()
2462 lttng_remove_trigger
0 "$@"
2465 function list_triggers_matches_ok
()
2467 local tmp_stdout
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2468 local tmp_stderr
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_stderr.XXXXXX")
2470 local test_name
="$1"
2471 local expected_stdout_file
="$2"
2473 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN list-triggers"
2475 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" list-triggers
> "${tmp_stdout}" 2> "${tmp_stderr}"
2476 ok $?
"${test_name}: exit code is 0"
2478 diff -u "${expected_stdout_file}" "${tmp_stdout}"
2479 ok $?
"${test_name}: expected stdout"
2481 diff -u /dev
/null
"${tmp_stderr}"
2482 ok $?
"${test_name}: expected stderr"
2484 rm -f "${tmp_stdout}"
2485 rm -f "${tmp_stderr}"
2488 function list_triggers_matches_mi_ok
()
2491 local tmp_stdout_raw
2494 local test_name
="$1"
2495 local expected_stdout_file
="$2"
2497 tmp_stdout_raw
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2498 tmp_stdout
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2499 tmp_stderr
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_stderr.XXXXXX")
2501 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi xml list-triggers"
2503 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" --mi=xml list-triggers
> "${tmp_stdout_raw}" 2> "${tmp_stderr}"
2504 ok $?
"${test_name}: exit code is 0"
2506 # Pretty-fy xml before further test.
2507 $XML_PRETTY < "${tmp_stdout_raw}" > "${tmp_stdout}"
2509 $MI_VALIDATE "${tmp_stdout}"
2510 ok $?
"list-trigger mi is valid"
2512 diff -u "${expected_stdout_file}" "${tmp_stdout}"
2513 ok $?
"${test_name}: expected stdout"
2515 diff -u /dev
/null
"${tmp_stderr}"
2516 ok $?
"${test_name}: expected stderr"
2518 rm -f "${tmp_stdout}"
2519 rm -f "${tmp_stdout_raw}"
2520 rm -f "${tmp_stderr}"
2523 function validate_path_pattern
()
2527 # Base path is only used in error case and is used to list the content
2536 if [ "$ret" -ne "0" ]; then
2537 diag
"Path pattern expected: $pattern"
2538 # List the tracepath for more info. We use find as a recursive
2540 diag
"The base path content:"
2541 find "$base_path" -print
2545 function validate_trace_path_ust_uid
()
2548 local session_name
=$2
2550 local pattern
="$trace_path/$session_name-$date_time_pattern/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2552 validate_path_pattern
"UST per-uid trace path is valid" "$pattern" "$trace_path"
2555 function validate_trace_path_ust_uid_network
()
2558 local session_name
=$2
2561 local hostname
=$HOSTNAME
2565 # If the session was given a network base path (e.g
2566 # 127.0.0.1/my/custom/path on creation, there is no session name
2567 # component to the path on the relayd side. Caller can simply not pass a
2568 # session name for this scenario.
2569 if [ -n "$session_name" ]; then
2570 session_name
="$session_name-$date_time_pattern"
2571 if [ -n "$base_path" ]; then
2572 fail
"Session name and base path are mutually exclusive"
2577 pattern
="$trace_path/$hostname/$base_path/$session_name/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2579 validate_path_pattern
"UST per-uid network trace path is valid" "$pattern" "$trace_path"
2582 function validate_trace_path_ust_uid_snapshot_network
()
2585 local session_name
=$2
2586 local snapshot_name
=$3
2587 local snapshot_number
=$4
2589 local hostname
=$HOSTNAME
2594 # If the session/output was given a network base path (e.g
2595 # 127.0.0.1/my/custom/path on creation, there is no session name
2596 # component to the path on the relayd side. Caller can simply not pass a
2597 # session name for this scenario.
2598 if [ -n "$session_name" ]; then
2599 session_name
="$session_name-$date_time_pattern"
2600 if [ -n "$base_path" ]; then
2601 fail
"Session name and base path are mutually exclusive"
2606 pattern
="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2608 validate_path_pattern
"UST per-uid network snapshot trace path is valid" "$pattern" "$trace_path"
2611 function validate_trace_path_ust_uid_snapshot
()
2614 local session_name
=$2
2615 local snapshot_name
=$3
2616 local snapshot_number
=$4
2622 # If the session/output was given a network base path (e.g
2623 # 127.0.0.1/my/custom/path) on creation, there is no session name
2624 # component to the path on the relayd side. Caller can simply not pass a
2625 # session name for this scenario.
2626 if [ -n "$session_name" ]; then
2627 session_name
="$session_name-$date_time_pattern"
2628 if [ -n "$base_path" ]; then
2629 fail
"Session name and base path are mutually exclusive"
2634 pattern
="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2636 validate_path_pattern
"UST per-uid snapshot trace path is valid" "$pattern" "$trace_path"
2639 function validate_trace_path_ust_pid
()
2642 local session_name
=$2
2648 # If the session was given a trace path on creation, there is no session
2649 # name component to the path. Caller can simply not pass a session name
2650 # for this scenario.
2651 if [ -n "$session_name" ]; then
2652 session_name
="$session_name-$date_time_pattern"
2655 pattern
="$trace_path/$session_name/ust/pid/$pid/$app_string-*-$date_time_pattern/metadata"
2657 validate_path_pattern
"UST per-pid trace path is valid" "$pattern" "$trace_path"
2660 function validate_trace_path_kernel
()
2663 local session_name
=$2
2666 # If the session was given a trace path on creation, there is no session
2667 # name component to the path. Caller can simply not pass a session name
2668 # for this scenario.
2669 if [ -n "$session_name" ]; then
2670 session_name
="$session_name-$date_time_pattern"
2673 pattern
="$trace_path/$session_name/kernel/metadata"
2675 validate_path_pattern
"Kernel trace path is valid" "$pattern" "$trace_path"
2678 function validate_trace_path_kernel_network
()
2681 local session_name
=$2
2682 local hostname
=$HOSTNAME
2683 local pattern
="$trace_path/$hostname/$session_name-$date_time_pattern/kernel/metadata"
2685 validate_path_pattern
"Kernel network trace path is valid" "$pattern" "$trace_path"
2688 function validate_trace_path_kernel_snapshot
()
2691 local session_name
=$2
2692 local snapshot_name
=$3
2693 local snapshot_number
=$4
2698 # If the session/output was given a network base path (e.g
2699 # 127.0.0.1/my/custom/path on creation, there is no session name
2700 # component to the path on the relayd side. Caller can simply not pass a
2701 # session name for this scenario.
2702 if [ -n "$session_name" ]; then
2703 session_name
="$session_name-$date_time_pattern"
2704 if [ -n "$base_path" ]; then
2705 fail
"Session name and base path are mutually exclusive"
2710 pattern
="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata"
2712 validate_path_pattern
"Kernel snapshot trace path is valid" "$pattern" "$trace_path"
2715 function validate_trace_path_kernel_snapshot_network
()
2718 local session_name
=$2
2719 local snapshot_name
=$3
2720 local snapshot_number
=$4
2722 local hostname
=$HOSTNAME
2726 # If the session/output was given a network base path (e.g
2727 # 127.0.0.1/my/custom/path on creation, there is no session name
2728 # component to the path on the relayd side. Caller can simply not pass a
2729 # session name for this scenario.
2730 if [ -n "$session_name" ]; then
2731 session_name
="$session_name-$date_time_pattern"
2732 if [ -n "$base_path" ]; then
2733 fail
"Session name and base path are mutually exclusive"
2738 pattern
="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata"
2740 validate_path_pattern
"Kernel network snapshot trace path is valid" "$pattern" "$trace_path"