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 the number of _configured_ CPUs.
286 function conf_proc_count
()
288 getconf _NPROCESSORS_CONF
289 if [ $?
-ne 0 ]; then
290 diag
"Failed to get the number of configured CPUs"
295 # Check if base lttng-modules are present.
296 # Bail out on failure
297 function validate_lttng_modules_present
()
299 # Check for loadable modules.
300 modprobe
-n lttng-tracer
2>/dev
/null
301 if [ $?
-eq 0 ]; then
305 # Check for builtin modules.
306 ls /proc
/lttng
> /dev
/null
2>&1
307 if [ $?
-eq 0 ]; then
311 LTTNG_BAIL_OUT
"LTTng modules not detected."
314 # Run the lttng binary.
316 # The first two arguments are stdout and stderr redirect paths, respectively.
317 # The rest of the arguments are forwarded to the lttng binary
318 function _run_lttng_cmd
320 local stdout_dest
="$1"
321 local stderr_dest
="$2"
324 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN $*"
325 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN "$@" 1> "$stdout_dest" 2> "$stderr_dest"
328 function enable_kernel_lttng_event
331 local expected_to_fail
="$2"
333 local event_name
="$4"
334 local channel_name
="$5"
336 if [ -z "$event_name" ]; then
337 # Enable all event if no event name specified
341 if [ -z "$channel_name" ]; then
342 # default channel if none specified
345 chan
="-c $channel_name"
348 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
349 enable-event
"$event_name" $chan -s $sess_name -k
351 if [[ $expected_to_fail -eq "1" ]]; then
354 if [ $withtap -eq "1" ]; then
355 ok
$ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
358 if [ $withtap -eq "1" ]; then
359 ok
$ret "Enable kernel event $event_name for session $sess_name"
364 function enable_kernel_lttng_event_ok
()
366 enable_kernel_lttng_event
1 0 "$@"
369 function enable_kernel_lttng_event_fail
()
371 enable_kernel_lttng_event
1 1 "$@"
374 function enable_kernel_lttng_event_notap
()
376 enable_kernel_lttng_event
0 0 "$@"
380 function lttng_enable_kernel_event
382 enable_kernel_lttng_event_ok
"$@"
385 function lttng_enable_kernel_syscall
()
387 local expected_to_fail
=$1
389 local syscall_name
=$3
390 local channel_name
=$4
392 if [ -z $syscall_name ]; then
393 # Enable all event if no syscall name specified
397 if [ -z $channel_name ]; then
398 # default channel if none specified
401 chan
="-c $channel_name"
404 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
405 enable-event
--syscall "$syscall_name" $chan -s $sess_name -k
407 if [[ $expected_to_fail -eq "1" ]]; then
409 ok $?
"Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
411 ok
$ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
415 function lttng_enable_kernel_syscall_ok
()
417 lttng_enable_kernel_syscall
0 "$@"
420 function lttng_enable_kernel_syscall_fail
()
422 lttng_enable_kernel_syscall
1 "$@"
425 function lttng_disable_kernel_syscall
()
427 local expected_to_fail
=$1
429 local syscall_name
=$3
430 local channel_name
=$4
432 if [ -z $syscall_name ]; then
433 # Enable all event if no syscall name specified
437 if [ -z $channel_name ]; then
438 # default channel if none specified
441 chan
="-c $channel_name"
444 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
445 disable-event
--syscall "$syscall_name" $chan -s $sess_name -k
448 if [[ $expected_to_fail -eq "1" ]]; then
450 ok $?
"Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
452 ok
$ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
456 function lttng_disable_kernel_syscall_ok
()
458 lttng_disable_kernel_syscall
0 "$@"
461 function lttng_disable_kernel_syscall_fail
()
463 lttng_disable_kernel_syscall
1 "$@"
466 function lttng_enable_kernel_function_event
()
468 local expected_to_fail
="$1"
471 local event_name
="$4"
473 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
--kernel --function="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
475 if [[ $expected_to_fail -eq "1" ]]; then
477 ok $?
"Enable kernel function event for session $sess_name failed as expected"
479 ok
$ret "Enable kernel function event for session $sess_name"
483 function lttng_enable_kernel_function_event_ok
()
485 lttng_enable_kernel_function_event
0 "$@"
488 function lttng_enable_kernel_userspace_probe_event
()
490 local expected_to_fail
="$1"
493 local event_name
="$4"
495 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
--kernel --userspace-probe="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
497 if [[ $expected_to_fail -eq "1" ]]; then
499 ok $?
"Enable kernel userspace probe event for session $sess_name failed as expected"
501 ok
$ret "Enable kernel userspace probe event for session $sess_name"
505 function lttng_enable_kernel_userspace_probe_event_fail
()
507 lttng_enable_kernel_userspace_probe_event
1 "$@"
510 function lttng_enable_kernel_userspace_probe_event_ok
()
512 lttng_enable_kernel_userspace_probe_event
0 "$@"
515 function disable_kernel_lttng_userspace_probe_event_ok
()
518 local event_name
="$2"
520 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" disable-event
--kernel "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
521 ok $?
"Disable kernel event $target for session $sess_name"
523 function lttng_enable_kernel_channel
()
526 local expected_to_fail
=$2
528 local channel_name
=$4
531 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
532 enable-channel
-k $channel_name -s $sess_name $opts
534 if [[ $expected_to_fail -eq "1" ]]; then
537 if [ $withtap -eq "1" ]; then
538 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
541 if [ $withtap -eq "1" ]; then
542 ok
$ret "Enable channel $channel_name for session $sess_name"
547 function lttng_enable_kernel_channel_ok
()
549 lttng_enable_kernel_channel
1 0 "$@"
552 function lttng_enable_kernel_channel_fail
()
554 lttng_enable_kernel_channel
1 1 "$@"
557 function lttng_enable_kernel_channel_notap
()
559 lttng_enable_kernel_channel
0 0 "$@"
562 function enable_kernel_lttng_channel_ok
()
564 lttng_enable_kernel_channel
1 0 "$@"
567 function lttng_disable_kernel_channel
()
569 local expected_to_fail
=$1
571 local channel_name
=$3
573 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
574 disable-channel
-k $channel_name -s $sess_name
576 if [[ $expected_to_fail -eq "1" ]]; then
578 ok $?
"Disable channel $channel_name for session $sess_name failed as expected"
580 ok
$ret "Disable channel $channel_name for session $sess_name"
584 function lttng_disable_kernel_channel_ok
()
586 lttng_disable_kernel_channel
0 "$@"
589 function lttng_disable_kernel_channel_fail
()
591 lttng_disable_kernel_channel
1 "$@"
594 function start_lttng_relayd_opt
()
597 local process_mode
=$2
600 DIR
=$
(readlink
-f "$TESTDIR")
602 if [ -z $
(lttng_pgrep
"$RELAYD_MATCH") ]; then
603 # shellcheck disable=SC2086
604 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
605 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
606 if [ $?
-eq 1 ]; then
607 if [ $withtap -eq "1" ]; then
608 fail
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
612 if [ $withtap -eq "1" ]; then
613 pass
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
617 pass
"Start lttng-relayd (opt: $opt)"
621 function start_lttng_relayd
()
623 start_lttng_relayd_opt
1 "-b" "$@"
626 function start_lttng_relayd_notap
()
628 start_lttng_relayd_opt
0 "-b" "$@"
631 function stop_lttng_relayd_opt
()
641 if [ -z "$signal" ]; then
646 # Multiply time by 2 to simplify integer arithmetic
647 if [ -n "$timeout_s" ]; then
648 dtimeleft_s
=$
((timeout_s
* 2))
652 pids
=$
(lttng_pgrep
"$RELAYD_MATCH")
653 if [ -z "$pids" ]; then
654 if [ "$is_cleanup" -eq 1 ]; then
656 elif [ "$withtap" -eq "1" ]; then
657 fail
"No relay daemon to kill"
659 LTTNG_BAIL_OUT
"No relay daemon to kill"
664 diag
"Killing (signal $signal) lttng-relayd (pid: $pids)"
666 # shellcheck disable=SC2086
667 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
669 if [ "$withtap" -eq "1" ]; then
670 fail
"Kill relay daemon"
674 while [ -n "$out" ]; do
675 out
=$
(lttng_pgrep
"$RELAYD_MATCH")
676 if [ -n "$dtimeleft_s" ]; then
677 if [ $dtimeleft_s -lt 0 ]; then
681 dtimeleft_s
=$
((dtimeleft_s
- 1))
685 if [ "$withtap" -eq "1" ]; then
686 if [ "$retval" -eq "0" ]; then
687 pass
"Wait after kill relay daemon"
689 fail
"Wait after kill relay daemon"
696 function stop_lttng_relayd
()
698 stop_lttng_relayd_opt
1 0 "$@"
701 function stop_lttng_relayd_notap
()
703 stop_lttng_relayd_opt
0 0 "$@"
706 function stop_lttng_relayd_cleanup
()
708 stop_lttng_relayd_opt
0 1 "$@"
711 #First arg: show tap output
712 #Second argument: load path for automatic loading
713 function start_lttng_sessiond_opt
()
718 # The rest of the arguments will be passed directly to lttng-sessiond.
724 local long_bit_value
=
725 long_bit_value
=$
(getconf LONG_BIT
)
727 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
728 # Env variable requested no session daemon
732 DIR
=$
(readlink
-f "$TESTDIR")
734 # Get long_bit value for 32/64 consumerd
735 case "$long_bit_value" in
737 consumerd
="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
740 consumerd
="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
747 # Check for env. variable. Allow the use of LD_PRELOAD etc.
748 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
749 env_vars
="${LTTNG_SESSIOND_ENV_VARS} "
751 env_vars
="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN"
753 if ! validate_kernel_version
; then
754 fail
"Start session daemon"
755 LTTNG_BAIL_OUT
"*** Kernel too old for session daemon tests ***"
758 diag
"export LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/"
759 : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/"}"
760 export LTTNG_SESSION_CONFIG_XSD_PATH
762 if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ]; then
764 if [ -n "$load_path" ]; then
765 diag
"env $env_vars --load $load_path --background $consumerd $@"
766 # shellcheck disable=SC2086
767 env
$env_vars --load "$load_path" --background "$consumerd" "$@"
769 diag
"env $env_vars --background $consumerd $@"
770 # shellcheck disable=SC2086
771 env
$env_vars --background "$consumerd" "$@"
773 #$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
775 if [ "$withtap" -eq "1" ]; then
776 ok
$status "Start session daemon"
781 function start_lttng_sessiond
()
783 start_lttng_sessiond_opt
1 "$@"
786 function start_lttng_sessiond_notap
()
788 start_lttng_sessiond_opt
0 "$@"
791 function stop_lttng_sessiond_opt
()
802 if [ -z "$signal" ]; then
806 # Multiply time by 2 to simplify integer arithmetic
807 if [ -n "$timeout_s" ]; then
808 dtimeleft_s
=$
((timeout_s
* 2))
811 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
812 # Env variable requested no session daemon
816 runas_pids
=$
(lttng_pgrep
"$RUNAS_MATCH")
817 pids
=$
(lttng_pgrep
"$SESSIOND_MATCH")
819 if [ -n "$runas_pids" ]; then
820 pids
="$pids $runas_pids"
823 if [ -z "$pids" ]; then
824 if [ "$is_cleanup" -eq 1 ]; then
826 elif [ "$withtap" -eq "1" ]; then
827 fail
"No session daemon to kill"
829 LTTNG_BAIL_OUT
"No session daemon to kill"
834 diag
"Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
836 # shellcheck disable=SC2086
837 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
839 if [ "$withtap" -eq "1" ]; then
840 fail
"Kill sessions daemon"
844 while [ -n "$out" ]; do
845 out
=$
(lttng_pgrep
"${SESSIOND_MATCH}")
846 if [ -n "$dtimeleft_s" ]; then
847 if [ $dtimeleft_s -lt 0 ]; then
851 dtimeleft_s
=$
((dtimeleft_s
- 1))
856 while [ -n "$out" ]; do
857 out
=$
(lttng_pgrep
"$CONSUMERD_MATCH")
858 if [ -n "$dtimeleft_s" ]; then
859 if [ $dtimeleft_s -lt 0 ]; then
863 dtimeleft_s
=$
((dtimeleft_s
- 1))
868 if [ "$withtap" -eq "1" ]; then
869 if [ "$retval" -eq "0" ]; then
870 pass
"Wait after kill session daemon"
872 fail
"Wait after kill session daemon"
876 if [ "$signal" = "SIGKILL" ]; then
877 if [ "$(id -u)" -eq "0" ]; then
879 modules
="$(lsmod | grep ^lttng | awk '{print $1}')"
881 if [ -n "$modules" ]; then
882 diag
"Unloading all LTTng modules"
883 modprobe
--remove "$modules"
891 function stop_lttng_sessiond
()
893 stop_lttng_sessiond_opt
1 0 "$@"
896 function stop_lttng_sessiond_notap
()
898 stop_lttng_sessiond_opt
0 0 "$@"
901 function stop_lttng_sessiond_cleanup
()
903 stop_lttng_sessiond_opt
0 1 "$@"
906 function sigstop_lttng_sessiond_opt
()
912 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
913 # Env variable requested no session daemon
917 pids
="$(lttng_pgrep "${SESSIOND_MATCH}") $(lttng_pgrep "$RUNAS_MATCH")"
919 if [ "$withtap" -eq "1" ]; then
920 diag
"Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
923 # shellcheck disable=SC2086
924 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
925 if [ "$withtap" -eq "1" ]; then
926 fail
"Sending SIGSTOP to session daemon"
930 while [ $out -ne 0 ]; do
931 pids
="$(lttng_pgrep "$SESSIOND_MATCH")"
933 # Wait until state becomes stopped for session
936 for sessiond_pid
in $pids; do
937 state
="$(ps -p "$sessiond_pid" -o state= )"
938 if [[ -n "$state" && "$state" != "T" ]]; then
944 if [ "$withtap" -eq "1" ]; then
945 pass
"Sending SIGSTOP to session daemon"
950 function sigstop_lttng_sessiond
()
952 sigstop_lttng_sessiond_opt
1 "$@"
955 function sigstop_lttng_sessiond_notap
()
957 sigstop_lttng_sessiond_opt
0 "$@"
960 function stop_lttng_consumerd_opt
()
970 if [ -z "$signal" ]; then
974 # Multiply time by 2 to simplify integer arithmetic
975 if [ -n "$timeout_s" ]; then
976 dtimeleft_s
=$
((timeout_s
* 2))
979 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
981 if [ -z "$pids" ]; then
982 if [ "$is_cleanup" -eq 1 ]; then
984 elif [ "$withtap" -eq "1" ]; then
985 fail
"No consumerd daemon to kill"
987 LTTNG_BAIL_OUT
"No consumerd daemon to kill"
992 diag
"Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')"
994 # shellcheck disable=SC2086
995 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
997 if [ "$withtap" -eq "1" ]; then
998 fail
"Kill consumer daemon"
1002 while [ $out -ne 0 ]; do
1003 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
1005 # If consumerds are still present check their status.
1006 # A zombie status qualifies the consumerd as *killed*
1008 for consumer_pid
in $pids; do
1009 state
="$(ps -p "$consumer_pid" -o state= )"
1010 if [[ -n "$state" && "$state" != "Z" ]]; then
1014 if [ -n "$dtimeleft_s" ]; then
1015 if [ $dtimeleft_s -lt 0 ]; then
1019 dtimeleft_s
=$
((dtimeleft_s
- 1))
1023 if [ "$withtap" -eq "1" ]; then
1024 if [ "$retval" -eq "0" ]; then
1025 pass
"Wait after kill consumer daemon"
1027 fail
"Wait after kill consumer daemon"
1035 function stop_lttng_consumerd
()
1037 stop_lttng_consumerd_opt
1 0 "$@"
1040 function stop_lttng_consumerd_notap
()
1042 stop_lttng_consumerd_opt
0 0 "$@"
1045 function stop_lttng_consumerd_cleanup
()
1047 stop_lttng_consumerd_opt
0 1 "$@"
1050 function sigstop_lttng_consumerd_opt
()
1053 local signal
=SIGSTOP
1056 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
1058 diag
"Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')"
1060 # shellcheck disable=SC2086
1061 kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1064 if [ $retval -eq 1 ]; then
1065 if [ "$withtap" -eq "1" ]; then
1066 fail
"Sending SIGSTOP to consumer daemon"
1071 while [ $out -ne 0 ]; do
1072 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
1074 # Wait until state becomes stopped for all
1077 for consumer_pid
in $pids; do
1078 state
="$(ps -p "$consumer_pid" -o state= )"
1079 if [[ -n "$state" && "$state" != "T" ]]; then
1085 if [ "$withtap" -eq "1" ]; then
1086 pass
"Sending SIGSTOP to consumer daemon"
1092 function sigstop_lttng_consumerd
()
1094 sigstop_lttng_consumerd_opt
1 "$@"
1097 function sigstop_lttng_consumerd_notap
()
1099 sigstop_lttng_consumerd_opt
0 "$@"
1102 function list_lttng_with_opts
()
1108 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1111 if [ $withtap -eq "1" ]; then
1112 ok
$ret "Lttng-tool list command with option $opts"
1116 function list_lttng_ok
()
1118 list_lttng_with_opts
1 "$@"
1121 function list_lttng_notap
()
1123 list_lttng_with_opts
0 "$@"
1126 function create_lttng_session_no_output
()
1131 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1132 create
$sess_name --no-output $opts
1133 ok $?
"Create session $sess_name in no-output mode"
1136 function create_lttng_session_uri
() {
1141 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1142 create
$sess_name -U $uri $opts
1143 ok $?
"Create session $sess_name with uri:$uri and opts: $opts"
1146 function create_lttng_session
()
1149 local expected_to_fail
=$2
1154 if [ -z "$trace_path" ]; then
1155 # Use lttng-sessiond default output.
1158 trace_path
="-o $trace_path"
1161 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1162 create
"$sess_name" $trace_path $opt
1164 if [ $expected_to_fail -eq "1" ]; then
1167 if [ $withtap -eq "1" ]; then
1168 ok
$ret "Create session $sess_name in $trace_path failed as expected"
1171 if [ $withtap -eq "1" ]; then
1172 ok
$ret "Create session $sess_name in $trace_path"
1178 function create_lttng_session_ok
()
1180 create_lttng_session
1 0 "$@"
1183 function create_lttng_session_fail
()
1185 create_lttng_session
1 1 "$@"
1188 function create_lttng_session_notap
()
1190 create_lttng_session
0 0 "$@"
1194 function enable_ust_lttng_channel
()
1197 local expected_to_fail
=$2
1199 local channel_name
=$4
1202 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1203 enable-channel
-u $channel_name -s $sess_name $opts
1205 if [[ $expected_to_fail -eq "1" ]]; then
1208 if [ $withtap -eq "1" ]; then
1209 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
1212 if [ $withtap -eq "1" ]; then
1213 ok
$ret "Enable channel $channel_name for session $sess_name"
1219 function enable_ust_lttng_channel_ok
()
1221 enable_ust_lttng_channel
1 0 "$@"
1224 function enable_ust_lttng_channel_fail
()
1226 enable_ust_lttng_channel
1 1 "$@"
1229 function enable_ust_lttng_channel_notap
()
1231 enable_ust_lttng_channel
0 0 "$@"
1234 function disable_ust_lttng_channel
()
1237 local channel_name
=$2
1239 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1240 disable-channel
-u $channel_name -s $sess_name
1241 ok $?
"Disable channel $channel_name for session $sess_name"
1244 function enable_lttng_mmap_overwrite_kernel_channel
()
1247 local channel_name
=$2
1249 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1250 enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite
1251 ok $?
"Enable channel $channel_name for session $sess_name"
1254 function enable_lttng_mmap_discard_small_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
--discard --subbuf-size=$
(getconf PAGE_SIZE
) --num-subbuf=2
1261 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1264 function enable_lttng_mmap_overwrite_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
--overwrite --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_ust_channel
()
1277 local channel_name
=$2
1279 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1280 enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite
1281 ok $?
"Enable channel $channel_name for session $sess_name"
1284 function enable_ust_lttng_event
()
1287 local expected_to_fail
=$2
1289 local event_name
="$4"
1290 local channel_name
=$5
1292 if [ -z $channel_name ]; then
1293 # default channel if none specified
1296 chan
="-c $channel_name"
1299 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1300 enable-event
"$event_name" $chan -s "$sess_name" -u
1302 if [[ $expected_to_fail -eq "1" ]]; then
1305 if [[ $withtap -eq "1" ]]; then
1306 ok
$ret "Enable ust event $event_name for session $session_name failed as expected"
1309 if [[ $withtap -eq "1" ]]; then
1310 ok
$ret "Enable ust event $event_name for session $sess_name"
1316 function enable_ust_lttng_event_ok
()
1318 enable_ust_lttng_event
1 0 "$@"
1321 function enable_ust_lttng_event_fail
()
1323 enable_ust_lttng_event
1 1 "$@"
1326 function enable_ust_lttng_event_notap
()
1328 enable_ust_lttng_event
0 0 "$@"
1331 function enable_jul_lttng_event
()
1337 if [ -z $channel_name ]; then
1338 # default channel if none specified
1341 chan
="-c $channel_name"
1344 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1345 enable-event
"$event_name" $chan -s $sess_name -j
1346 ok $?
"Enable JUL event $event_name for session $sess_name"
1349 function enable_jul_lttng_event_loglevel
()
1352 local event_name
="$2"
1354 local channel_name
=$4
1356 if [ -z $channel_name ]; then
1357 # default channel if none specified
1360 chan
="-c $channel_name"
1363 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1364 enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j
1365 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
1368 function enable_log4j_lttng_event
()
1372 local channel_name
=$3
1376 # default channel if none specified
1377 if [ -n "$channel_name" ]; then
1378 chan_opt
=("-c" "$channel_name")
1381 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1382 enable-event
"$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j
1383 ok $?
"Enable LOG4J event '$event_name' for session '$sess_name'"
1386 function enable_log4j_lttng_event_filter
()
1392 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1393 enable-event
"$event_name" -s "$sess_name" --log4j --filter "$filter"
1394 ok $?
"Enable LOG4J event '$event_name' with filter '$filter' for session '$sess_name'"
1397 function enable_log4j_lttng_event_filter_loglevel_only
()
1404 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1405 enable-event
--loglevel-only "$loglevel" "$event_name" -s "$sess_name" -l --filter "$filter"
1406 ok $?
"Enable LOG4J event '$event_name' with filter '$filter' and loglevel-only '$loglevel' for session '$sess_name'"
1409 function enable_log4j_lttng_event_loglevel
()
1414 local channel_name
=$4
1417 # default channel if none specified
1418 if [ -n "$channel_name" ]; then
1419 chan_opt
=("-c" "$channel_name")
1422 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1423 enable-event
--loglevel "$loglevel" "$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j
1424 ok $?
"Enable LOG4J event '$event_name' for session '$sess_name' with loglevel '$loglevel'"
1427 function enable_log4j_lttng_event_loglevel_only
()
1432 local channel_name
=$4
1436 # default channel if none specified
1437 if [ -n "$channel_name" ]; then
1438 chan_opt
=("-c" "$channel_name")
1441 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1442 enable-event
--loglevel-only "$loglevel" "$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j
1443 ok $?
"Enable LOG4J event '$event_name' for session '$sess_name' with loglevel-only '$loglevel'"
1446 function enable_python_lttng_event
()
1452 if [ -z $channel_name ]; then
1453 # default channel if none specified
1456 chan
="-c $channel_name"
1459 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1460 enable-event
"$event_name" $chan -s $sess_name -p
1461 ok $?
"Enable Python event $event_name for session $sess_name"
1464 function enable_python_lttng_event_loglevel
()
1467 local event_name
="$2"
1469 local channel_name
=$4
1471 if [ -z $channel_name ]; then
1472 # default channel if none specified
1475 chan
="-c $channel_name"
1478 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1479 enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -p
1480 ok $?
"Enable Python event $event_name for session $sess_name with loglevel $loglevel"
1483 function enable_ust_lttng_event_filter
()
1485 local sess_name
="$1"
1486 local event_name
="$2"
1488 local channel_name
=$4
1490 if [ -z $channel_name ]; then
1491 # default channel if none specified
1494 chan
="-c $channel_name"
1497 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1498 enable-event
$chan "$event_name" -s $sess_name -u --filter "$filter"
1499 ok $?
"Enable event $event_name with filtering for session $sess_name"
1502 function enable_ust_lttng_event_loglevel
()
1504 local sess_name
="$1"
1505 local event_name
="$2"
1508 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1509 enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel
1510 ok $?
"Enable event $event_name with loglevel $loglevel"
1513 function enable_ust_lttng_event_loglevel_only
()
1515 local sess_name
="$1"
1516 local event_name
="$2"
1519 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1520 enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel
1521 ok $?
"Enable event $event_name with loglevel-only $loglevel"
1524 function disable_ust_lttng_event
()
1526 local sess_name
="$1"
1527 local event_name
="$2"
1528 local channel_name
="$3"
1530 if [ -z $channel_name ]; then
1531 # default channel if none specified
1534 chan
="-c $channel_name"
1537 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1538 disable-event
"$event_name" -s $sess_name $chan -u
1539 ok $?
"Disable event $event_name for session $sess_name"
1542 function disable_jul_lttng_event
()
1544 local sess_name
="$1"
1545 local event_name
="$2"
1547 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
1548 ok $?
"Disable JUL event $event_name for session $sess_name"
1551 function disable_log4j_lttng_event
()
1553 local sess_name
="$1"
1554 local event_name
="$2"
1556 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1557 disable-event
"$event_name" -s "$sess_name" --log4j
1558 ok $?
"Disable LOG4J event '$event_name' for session '$sess_name'"
1561 function disable_python_lttng_event
()
1563 local sess_name
="$1"
1564 local event_name
="$2"
1566 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1567 disable-event
"$event_name" -s $sess_name -p
1568 ok $?
"Disable Python event $event_name for session $sess_name"
1571 function start_lttng_tracing_opt
()
1574 local expected_to_fail
=$2
1577 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1580 if [[ $expected_to_fail -eq "1" ]]; then
1583 if [ $withtap -eq "1" ]; then
1584 ok $?
"Start tracing for session $sess_name failed as expected"
1587 if [ $withtap -eq "1" ]; then
1588 ok
$ret "Start tracing for session $sess_name"
1593 function start_lttng_tracing_ok
()
1595 start_lttng_tracing_opt
1 0 "$@"
1598 function start_lttng_tracing_fail
()
1600 start_lttng_tracing_opt
1 1 "$@"
1603 function start_lttng_tracing_notap
()
1605 start_lttng_tracing_opt
0 1 "$@"
1608 function stop_lttng_tracing_opt
()
1611 local expected_to_fail
=$2
1614 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1617 if [[ $expected_to_fail -eq "1" ]]; then
1620 if [ $withtap -eq "1" ]; then
1621 ok $?
"Stop lttng tracing for session $sess_name failed as expected"
1624 if [ $withtap -eq "1" ]; then
1625 ok
$ret "Stop lttng tracing for session $sess_name"
1630 function stop_lttng_tracing_ok
()
1632 stop_lttng_tracing_opt
1 0 "$@"
1635 function stop_lttng_tracing_fail
()
1637 stop_lttng_tracing_opt
1 1 "$@"
1640 function stop_lttng_tracing_notap
()
1642 stop_lttng_tracing_opt
0 0 "$@"
1645 function destroy_lttng_session
()
1648 local expected_to_fail
=$2
1651 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1654 if [[ $expected_to_fail -eq "1" ]]; then
1657 if [ $withtap -eq "1" ]; then
1658 ok
$ret "Destroy session $sess_name failed as expected"
1661 if [ $withtap -eq "1" ]; then
1662 ok
$ret "Destroy session $sess_name"
1667 function destroy_lttng_session_ok
()
1669 destroy_lttng_session
1 0 "$@"
1673 function destroy_lttng_session_fail
()
1675 destroy_lttng_session
1 1 "$@"
1678 function destroy_lttng_session_notap
()
1680 destroy_lttng_session
0 0 "$@"
1683 function destroy_lttng_sessions
()
1685 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1687 ok $?
"Destroy all lttng sessions"
1690 function lttng_snapshot_add_output
()
1692 local expected_to_fail
=$1
1697 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1698 snapshot add-output
-s $sess_name $trace_path $opts
1700 if [[ $expected_to_fail -eq 1 ]]; then
1702 ok $?
"Added snapshot output $trace_path failed as expected"
1704 ok
$ret "Added snapshot output $trace_path"
1708 function lttng_snapshot_add_output_ok
()
1710 lttng_snapshot_add_output
0 "$@"
1713 function lttng_snapshot_add_output_fail
()
1715 lttng_snapshot_add_output
1 "$@"
1718 function lttng_snapshot_del_output
()
1720 local expected_to_fail
=$1
1724 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1725 snapshot del-output
-s $sess_name $id
1727 if [[ $expected_to_fail -eq "1" ]]; then
1729 ok $?
"Deleted snapshot output id $id failed as expected"
1731 ok
$ret "Deleted snapshot output id $id"
1735 function lttng_snapshot_del_output_ok
()
1737 lttng_snapshot_del_output
0 "$@"
1740 function lttng_snapshot_del_output_fail
()
1742 lttng_snapshot_del_output
1 "$@"
1745 function lttng_snapshot_record
()
1750 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1751 snapshot record
-s "$sess_name" "$trace_path"
1752 ok $?
"Snapshot recorded"
1755 function lttng_snapshot_list
()
1758 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1759 snapshot list-output
-s $sess_name
1760 ok $?
"Snapshot list"
1763 function lttng_save
()
1768 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1769 save
$sess_name $opts
1770 ok $?
"Session saved"
1773 function lttng_load
()
1775 local expected_to_fail
=$1
1778 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1781 if [[ $expected_to_fail -eq "1" ]]; then
1783 ok $?
"Load command failed as expected with opts: $opts"
1785 ok
$ret "Load command with opts: $opts"
1789 function lttng_load_ok
()
1794 function lttng_load_fail
()
1799 function lttng_track
()
1801 local expected_to_fail
="$1"
1804 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN track
$opts >$OUTPUT_DEST
1806 if [[ $expected_to_fail -eq "1" ]]; then
1808 ok $?
"Track command failed as expected with opts: $opts"
1810 ok
$ret "Track command with opts: $opts"
1814 function lttng_track_ok
()
1819 function lttng_track_fail
()
1824 function lttng_untrack
()
1826 local expected_to_fail
="$1"
1829 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN untrack
$opts >$OUTPUT_DEST
1831 if [[ $expected_to_fail -eq "1" ]]; then
1833 ok $?
"Untrack command failed as expected with opts: $opts"
1835 ok
$ret "Untrack command with opts: $opts"
1839 function lttng_untrack_ok
()
1841 lttng_untrack
0 "$@"
1844 function lttng_untrack_fail
()
1846 lttng_untrack
1 "$@"
1849 function lttng_track_pid_ok
()
1852 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track
--kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1853 ok $?
"Lttng track pid on the kernel domain"
1856 function lttng_untrack_kernel_all_ok
()
1858 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack
--kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1859 ok $?
"Lttng untrack all pid on the kernel domain"
1862 function lttng_track_ust_ok
()
1864 lttng_track_ok
-u "$@"
1867 function lttng_track_ust_fail
()
1869 lttng_track_fail
-u "$@"
1872 function lttng_track_kernel_ok
()
1874 lttng_track_ok
-k "$@"
1877 function lttng_track_kernel_fail
()
1879 lttng_track_fail
-k "$@"
1882 function lttng_untrack_ust_ok
()
1884 lttng_untrack_ok
-u "$@"
1887 function lttng_untrack_ust_fail
()
1889 lttng_untrack_fail
-u "$@"
1892 function lttng_untrack_kernel_ok
()
1894 lttng_untrack_ok
-k "$@"
1897 function lttng_untrack_kernel_fail
()
1899 lttng_untrack_fail
-k "$@"
1902 function lttng_add_context_list
()
1904 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1907 ok
$ret "Context listing"
1910 function add_context_lttng
()
1912 local expected_to_fail
="$1"
1914 local session_name
="$3"
1915 local channel_name
="$4"
1918 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1919 add-context
-s $session_name -c $channel_name -t $type $domain
1921 if [[ $expected_to_fail -eq "1" ]]; then
1923 ok $?
"Add context command failed as expected for type: $type"
1925 ok
$ret "Add context command for type: $type"
1929 function add_context_ust_ok
()
1931 add_context_lttng
0 -u "$@"
1934 function add_context_ust_fail
()
1936 add_context_lttng
1 -u "$@"
1939 function add_context_kernel_ok
()
1941 add_context_lttng
0 -k "$@"
1944 function add_context_kernel_fail
()
1946 add_context_lttng
1 -k "$@"
1949 function wait_live_trace_ready
()
1952 local zero_client_match
=0
1954 diag
"Waiting for live trace at url: $url"
1955 while [ $zero_client_match -eq 0 ]; do
1956 zero_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "0 client(s) connected" |
wc -l)
1959 pass
"Waiting for live trace at url: $url"
1962 function wait_live_viewer_connect
()
1965 local one_client_match
=0
1967 diag
"Waiting for live viewers on url: $url"
1968 while [ $one_client_match -eq 0 ]; do
1969 one_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "1 client(s) connected" |
wc -l)
1972 pass
"Waiting for live viewers on url: $url"
1975 function bail_out_if_no_babeltrace
()
1977 which "$BABELTRACE_BIN" >/dev
/null
1978 if [ $?
-ne 0 ]; then
1979 LTTNG_BAIL_OUT
"\"$BABELTRACE_BIN\" binary not found. Skipping tests"
1983 # Check that the trace metadata contains '$expected' event ids matching '$event_name'.
1984 function validate_metadata_event
()
1994 metadata_file
=$
(find "$trace_path" -name "metadata")
1995 metadata_path
=$
(dirname "$metadata_file")
1997 bail_out_if_no_babeltrace
1999 count
=$
($BABELTRACE_BIN --output-format=ctf-metadata
"$metadata_path" |
grep -c "$event_name")
2001 test "$count" -eq "$expected"
2002 ok $?
"Found $count / $expected metadata event id matching '$event_name'"
2005 # Check that the trace contains '$expected' events matching '$event_name', other
2006 # events not matching '$event_name' can be present.
2007 function trace_matches
()
2016 bail_out_if_no_babeltrace
2018 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c "$event_name")
2019 total
=$
($BABELTRACE_BIN "$trace_path" |
wc -l)
2021 test "$count" -eq "$expected"
2023 ok $?
"Found $count / $expected events matching '$event_name' out of $total events"
2026 # Check that the trace contains '$expected' events matching '$event_name' and no
2028 function trace_match_only
()
2037 bail_out_if_no_babeltrace
2039 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c "$event_name")
2040 total
=$
($BABELTRACE_BIN "$trace_path" |
wc -l)
2042 test "$expected" -eq "$count" && test "$total" -eq "$expected"
2044 ok $?
"Found $count / $expected events matching '$event_name' amongst $total events"
2047 # Check that the trace contains at least 1 event matching each name in the
2048 # comma separated list '$event_names'.
2049 function validate_trace
()
2051 local event_names
=$1
2056 bail_out_if_no_babeltrace
2060 for event_name
in $event_names; do
2061 # trace_path is unquoted since callers make use of globbing
2062 count
=$
($BABELTRACE_BIN $trace_path |
grep -c "$event_name")
2064 ok $?
"Found $count events matching '$event_name'"
2069 # Check that the trace contains at least 1 event matching each name in the
2070 # comma separated list '$event_names' and a total of '$expected' events.
2071 function validate_trace_count
()
2073 local event_names
=$1
2080 bail_out_if_no_babeltrace
2084 for event_name
in $event_names; do
2085 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c "$event_name")
2087 ok $?
"Found '$count' events matching '$event_name'"
2088 total
=$
(( total
+ count
))
2091 test $total -eq "$expected"
2092 ok $?
"Found $total events, expected $expected events"
2095 # Check that the trace contains at least '$expected_min' event matching each
2096 # name in the comma separated list '$event_names' and a total at least
2097 # '$expected_min' and less than '$expected_max' events.
2098 function validate_trace_count_range_incl_min_excl_max
()
2100 local event_names
=$1
2102 local expected_min
=$3
2103 local expected_max
=$4
2108 bail_out_if_no_babeltrace
2112 for event_name
in $event_names; do
2113 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c "$event_name")
2114 test "$count" -ge "$expected_min"
2115 ok $?
"Found $count events matching '$event_name', expected at least $expected_min"
2116 total
=$
(( total
+ count
))
2119 test $total -ge "$expected_min" && test $total -lt "$expected_max"
2120 ok $?
"Found a total of $total events, expected at least $expected_min and less than $expected_max"
2123 function trace_first_line
()
2127 $BABELTRACE_BIN "$trace_path" |
head -n 1
2130 # Check that the trace contains at least 1 event matching the grep extended
2131 # regexp '$event_exp'.
2132 function validate_trace_exp
()
2139 bail_out_if_no_babeltrace
2141 # event_exp is unquoted since it contains multiple grep arguments
2142 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c --extended-regexp $event_exp)
2144 ok $?
"Found $count events matching expression '$event_exp'"
2147 # Check that the trace contains at least 1 event matching the grep extended
2148 # regexp '$event_exp' and zero event not matching it.
2149 function validate_trace_only_exp
()
2157 bail_out_if_no_babeltrace
2159 # event_exp is unquoted since it contains multiple grep arguments
2160 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c --extended-regexp $event_exp)
2161 total
=$
($BABELTRACE_BIN "$trace_path" |
wc -l)
2163 test "$count" -gt 0 && test "$total" -eq "$count"
2164 ok $?
"Found $count events matching expression '$event_exp' amongst $total events"
2167 # Check that the trace is valid and contains 0 event.
2168 function validate_trace_empty
()
2175 bail_out_if_no_babeltrace
2177 events
=$
($BABELTRACE_BIN "$trace_path")
2179 if [ $ret -ne 0 ]; then
2180 fail
"Failed to parse trace"
2184 count
=$
(echo -n "$events" |
wc -l)
2186 ok $?
"Validate trace is empty, found $count events"
2189 function validate_directory_empty
()
2191 local trace_path
="$1"
2197 # Do not double quote `$trace_path` below as we want wildcards to be
2199 files
="$(ls -A $trace_path)"
2201 if [ $ret -ne 0 ]; then
2202 fail
"Failed to list content of directory \"$trace_path\""
2206 nb_files
="$(echo -n "$files" | wc -l)"
2207 test "$nb_files" -eq 0
2208 ok $?
"Directory \"$trace_path\" is empty"
2211 function validate_trace_session_ust_empty
()
2213 validate_directory_empty
"$1"/ust
2216 function validate_trace_session_kernel_empty
()
2218 validate_trace_empty
"$1"/kernel
2221 function regenerate_metadata
()
2223 local expected_to_fail
=$1
2226 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2227 regenerate metadata
-s $sess_name
2229 if [[ $expected_to_fail -eq "1" ]]; then
2231 ok $?
"Expected fail on regenerate metadata $sess_name"
2233 ok
$ret "Metadata regenerate $sess_name"
2237 function regenerate_metadata_ok
()
2239 regenerate_metadata
0 "$@"
2242 function regenerate_metadata_fail
()
2244 regenerate_metadata
1 "$@"
2247 function regenerate_statedump
()
2249 local expected_to_fail
=$1
2252 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2253 regenerate statedump
-s $sess_name
2255 if [[ $expected_to_fail -eq "1" ]]; then
2257 ok $?
"Expected fail on regenerate statedump $sess_name"
2259 ok
$ret "Statedump regenerate $sess_name"
2263 function regenerate_statedump_ok
()
2265 regenerate_statedump
0 "$@"
2268 function regenerate_statedump_fail
()
2270 regenerate_statedump
1 "$@"
2273 function rotate_session
()
2275 local expected_to_fail
=$1
2278 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2281 if [[ $expected_to_fail -eq "1" ]]; then
2283 ok $?
"Expected fail on rotate session $sess_name"
2285 ok
$ret "Rotate session $sess_name"
2289 function rotate_session_ok
()
2291 rotate_session
0 "$@"
2294 function rotate_session_fail
()
2296 rotate_session
1 "$@"
2299 function destructive_tests_enabled
()
2301 if [ "$LTTNG_ENABLE_DESTRUCTIVE_TESTS" = "will-break-my-system" ]; then
2308 function lttng_enable_rotation_timer
()
2310 local expected_to_fail
=$1
2314 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2315 enable-rotation
-s $sess_name --timer $period
2317 if [[ $expected_to_fail -eq "1" ]]; then
2319 ok $?
"Expected fail when setting periodic rotation ($period) of session $sess_name"
2321 ok
$ret "Set periodic rotation ($period) of session $sess_name"
2325 function lttng_enable_rotation_timer_ok
()
2327 lttng_enable_rotation_timer
0 $@
2330 function lttng_enable_rotation_timer_fail
()
2332 lttng_enable_rotation_timer
1 $@
2335 function lttng_enable_rotation_size
()
2337 local expected_to_fail
=$1
2341 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2342 enable-rotation
-s $sess_name --size $size
2344 if [[ $expected_to_fail -eq "1" ]]; then
2346 ok $?
"Expected to fail to set a periodic rotation of session $sess_name" "every " $size " bytes"
2348 ok
$ret "Set a scheduled rotation of session $sess_name" "every " $size " bytes"
2352 function lttng_enable_rotation_size_ok
()
2354 lttng_enable_rotation_size
0 $@
2357 function lttng_enable_rotation_size_fail
()
2359 lttng_enable_rotation_size
1 $@
2362 function lttng_clear_session
()
2364 local expected_to_fail
=$1
2367 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2370 if [[ $expected_to_fail -eq "1" ]]; then
2372 ok $?
"Expected fail on clear session $sess_name"
2374 ok
$ret "Clear session $sess_name"
2378 function lttng_clear_session_ok
()
2380 lttng_clear_session
0 $@
2383 function lttng_clear_session_fail
()
2385 lttng_clear_session
1 $@
2388 function lttng_clear_all
()
2390 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2392 ok $?
"Clear all lttng sessions"
2395 function lttng_add_trigger
()
2397 local expected_to_fail
="$1"
2398 local trigger_name
="$2"
2402 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN add-trigger --name $trigger_name ${args[*]}"
2403 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-trigger
--name "$trigger_name" "${args[@]}" 1> /dev
/null
2> /dev
/null
2405 if [[ $expected_to_fail -eq "1" ]]; then
2407 ok $?
"Add trigger $trigger_name failed as expected"
2409 ok
$ret "Add trigger $trigger_name"
2413 function lttng_remove_trigger
()
2415 local expected_to_fail
="$1"
2416 local trigger_name
="$2"
2419 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN remove-trigger $trigger_name $*"
2420 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" remove-trigger
"$trigger_name" "$@" 1> /dev
/null
2> /dev
/null
2422 if [[ $expected_to_fail -eq "1" ]]; then
2424 ok $?
"Remove trigger $trigger_name failed as expected"
2426 ok
$ret "Remove trigger $trigger_name"
2430 function lttng_add_trigger_ok
()
2432 lttng_add_trigger
0 "$@"
2435 function lttng_add_trigger_fail
()
2437 lttng_add_trigger
1 "$@"
2440 function lttng_remove_trigger_ok
()
2442 lttng_remove_trigger
0 "$@"
2445 function list_triggers_matches_ok
()
2447 local tmp_stdout
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2448 local tmp_stderr
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_stderr.XXXXXX")
2450 local test_name
="$1"
2451 local expected_stdout_file
="$2"
2453 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN list-triggers"
2455 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" list-triggers
> "${tmp_stdout}" 2> "${tmp_stderr}"
2456 ok $?
"${test_name}: exit code is 0"
2458 diff -u "${expected_stdout_file}" "${tmp_stdout}"
2459 ok $?
"${test_name}: expected stdout"
2461 diff -u /dev
/null
"${tmp_stderr}"
2462 ok $?
"${test_name}: expected stderr"
2464 rm -f "${tmp_stdout}"
2465 rm -f "${tmp_stderr}"
2468 function list_triggers_matches_mi_ok
()
2471 local tmp_stdout_raw
2474 local test_name
="$1"
2475 local expected_stdout_file
="$2"
2477 tmp_stdout_raw
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2478 tmp_stdout
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2479 tmp_stderr
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_stderr.XXXXXX")
2481 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi xml list-triggers"
2483 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" --mi=xml list-triggers
> "${tmp_stdout_raw}" 2> "${tmp_stderr}"
2484 ok $?
"${test_name}: exit code is 0"
2486 # Pretty-fy xml before further test.
2487 $XML_PRETTY < "${tmp_stdout_raw}" > "${tmp_stdout}"
2489 $MI_VALIDATE "${tmp_stdout}"
2490 ok $?
"list-trigger mi is valid"
2492 diff -u "${expected_stdout_file}" "${tmp_stdout}"
2493 ok $?
"${test_name}: expected stdout"
2495 diff -u /dev
/null
"${tmp_stderr}"
2496 ok $?
"${test_name}: expected stderr"
2498 rm -f "${tmp_stdout}"
2499 rm -f "${tmp_stdout_raw}"
2500 rm -f "${tmp_stderr}"
2503 function validate_path_pattern
()
2507 # Base path is only used in error case and is used to list the content
2516 if [ "$ret" -ne "0" ]; then
2517 diag
"Path pattern expected: $pattern"
2518 # List the tracepath for more info. We use find as a recursive
2520 diag
"The base path content:"
2521 find "$base_path" -print
2525 function validate_trace_path_ust_uid
()
2528 local session_name
=$2
2530 local pattern
="$trace_path/$session_name-$date_time_pattern/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2532 validate_path_pattern
"UST per-uid trace path is valid" "$pattern" "$trace_path"
2535 function validate_trace_path_ust_uid_network
()
2538 local session_name
=$2
2541 local hostname
=$HOSTNAME
2545 # If the session was given a network base path (e.g
2546 # 127.0.0.1/my/custom/path on creation, there is no session name
2547 # component to the path on the relayd side. Caller can simply not pass a
2548 # session name for this scenario.
2549 if [ -n "$session_name" ]; then
2550 session_name
="$session_name-$date_time_pattern"
2551 if [ -n "$base_path" ]; then
2552 fail
"Session name and base path are mutually exclusive"
2557 pattern
="$trace_path/$hostname/$base_path/$session_name/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2559 validate_path_pattern
"UST per-uid network trace path is valid" "$pattern" "$trace_path"
2562 function validate_trace_path_ust_uid_snapshot_network
()
2565 local session_name
=$2
2566 local snapshot_name
=$3
2567 local snapshot_number
=$4
2569 local hostname
=$HOSTNAME
2574 # If the session/output was given a network base path (e.g
2575 # 127.0.0.1/my/custom/path on creation, there is no session name
2576 # component to the path on the relayd side. Caller can simply not pass a
2577 # session name for this scenario.
2578 if [ -n "$session_name" ]; then
2579 session_name
="$session_name-$date_time_pattern"
2580 if [ -n "$base_path" ]; then
2581 fail
"Session name and base path are mutually exclusive"
2586 pattern
="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2588 validate_path_pattern
"UST per-uid network snapshot trace path is valid" "$pattern" "$trace_path"
2591 function validate_trace_path_ust_uid_snapshot
()
2594 local session_name
=$2
2595 local snapshot_name
=$3
2596 local snapshot_number
=$4
2602 # If the session/output was given a network base path (e.g
2603 # 127.0.0.1/my/custom/path) on creation, there is no session name
2604 # component to the path on the relayd side. Caller can simply not pass a
2605 # session name for this scenario.
2606 if [ -n "$session_name" ]; then
2607 session_name
="$session_name-$date_time_pattern"
2608 if [ -n "$base_path" ]; then
2609 fail
"Session name and base path are mutually exclusive"
2614 pattern
="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2616 validate_path_pattern
"UST per-uid snapshot trace path is valid" "$pattern" "$trace_path"
2619 function validate_trace_path_ust_pid
()
2622 local session_name
=$2
2628 # If the session was given a trace path on creation, there is no session
2629 # name component to the path. Caller can simply not pass a session name
2630 # for this scenario.
2631 if [ -n "$session_name" ]; then
2632 session_name
="$session_name-$date_time_pattern"
2635 pattern
="$trace_path/$session_name/ust/pid/$pid/$app_string-*-$date_time_pattern/metadata"
2637 validate_path_pattern
"UST per-pid trace path is valid" "$pattern" "$trace_path"
2640 function validate_trace_path_kernel
()
2643 local session_name
=$2
2646 # If the session was given a trace path on creation, there is no session
2647 # name component to the path. Caller can simply not pass a session name
2648 # for this scenario.
2649 if [ -n "$session_name" ]; then
2650 session_name
="$session_name-$date_time_pattern"
2653 pattern
="$trace_path/$session_name/kernel/metadata"
2655 validate_path_pattern
"Kernel trace path is valid" "$pattern" "$trace_path"
2658 function validate_trace_path_kernel_network
()
2661 local session_name
=$2
2662 local hostname
=$HOSTNAME
2663 local pattern
="$trace_path/$hostname/$session_name-$date_time_pattern/kernel/metadata"
2665 validate_path_pattern
"Kernel network trace path is valid" "$pattern" "$trace_path"
2668 function validate_trace_path_kernel_snapshot
()
2671 local session_name
=$2
2672 local snapshot_name
=$3
2673 local snapshot_number
=$4
2678 # If the session/output was given a network base path (e.g
2679 # 127.0.0.1/my/custom/path on creation, there is no session name
2680 # component to the path on the relayd side. Caller can simply not pass a
2681 # session name for this scenario.
2682 if [ -n "$session_name" ]; then
2683 session_name
="$session_name-$date_time_pattern"
2684 if [ -n "$base_path" ]; then
2685 fail
"Session name and base path are mutually exclusive"
2690 pattern
="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata"
2692 validate_path_pattern
"Kernel snapshot trace path is valid" "$pattern" "$trace_path"
2695 function validate_trace_path_kernel_snapshot_network
()
2698 local session_name
=$2
2699 local snapshot_name
=$3
2700 local snapshot_number
=$4
2702 local hostname
=$HOSTNAME
2706 # If the session/output was given a network base path (e.g
2707 # 127.0.0.1/my/custom/path on creation, there is no session name
2708 # component to the path on the relayd side. Caller can simply not pass a
2709 # session name for this scenario.
2710 if [ -n "$session_name" ]; then
2711 session_name
="$session_name-$date_time_pattern"
2712 if [ -n "$base_path" ]; then
2713 fail
"Session name and base path are mutually exclusive"
2718 pattern
="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata"
2720 validate_path_pattern
"Kernel network snapshot trace path is valid" "$pattern" "$trace_path"