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
=$
(cut
-d '-' -f 2 < /sys
/devices
/system
/cpu
/possible
)
221 echo $
((max_possible_cpu_id
+1))
224 function get_max_cpus_count_from_sysfs_cpu_directories
()
226 local max_possible_cpu_id
= \
227 $
(find /sys
/devices
/system
/cpu
/ -mindepth 1 -maxdepth 1 -regex ".+cpu[0-9]+" | \
228 sed -e 's/cpu//g' | \
229 awk -F '/' '{ if ($NF > N) N = $NF } END { print N }')
230 echo $
((max_possible_cpu_id
+1))
233 # Return the number of possible CPUs.
234 function get_possible_cpus_count
()
236 local possible_cpus_count
=$
(get_possible_cpus_count_from_sysfs_possible_mask
)
238 if [ $?
-ne 0 ]; then
239 possible_cpus_count
=$
(get_max_cpus_count_from_sysfs_cpu_directories
)
240 local configured_cpus_count
=$
(getconf _NPROCESSORS_CONF
)
241 possible_cpus_count
=$
(($configured_cpus_count > $possible_cpus_count \
242 ?
$configured_cpus_count \
243 : $possible_cpus_count))
246 echo $possible_cpus_count
249 # Return the number of _configured_ CPUs.
250 function conf_proc_count
()
252 getconf _NPROCESSORS_CONF
253 if [ $?
-ne 0 ]; then
254 diag
"Failed to get the number of configured CPUs"
259 # Check if base lttng-modules are present.
260 # Bail out on failure
261 function validate_lttng_modules_present
()
263 # Check for loadable modules.
264 modprobe
-n lttng-tracer
2>/dev
/null
265 if [ $?
-eq 0 ]; then
269 # Check for builtin modules.
270 ls /proc
/lttng
> /dev
/null
2>&1
271 if [ $?
-eq 0 ]; then
275 LTTNG_BAIL_OUT
"LTTng modules not detected."
278 # Run the lttng binary.
280 # The first two arguments are stdout and stderr redirect paths, respectively.
281 # The rest of the arguments are forwarded to the lttng binary
282 function _run_lttng_cmd
284 local stdout_dest
="$1"
285 local stderr_dest
="$2"
288 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN $*"
289 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN "$@" 1> "$stdout_dest" 2> "$stderr_dest"
292 function enable_kernel_lttng_event
295 local expected_to_fail
="$2"
297 local event_name
="$4"
298 local channel_name
="$5"
300 if [ -z "$event_name" ]; then
301 # Enable all event if no event name specified
305 if [ -z "$channel_name" ]; then
306 # default channel if none specified
309 chan
="-c $channel_name"
312 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
313 enable-event
"$event_name" $chan -s $sess_name -k
315 if [[ $expected_to_fail -eq "1" ]]; then
318 if [ $withtap -eq "1" ]; then
319 ok
$ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
322 if [ $withtap -eq "1" ]; then
323 ok
$ret "Enable kernel event $event_name for session $sess_name"
328 function enable_kernel_lttng_event_ok
()
330 enable_kernel_lttng_event
1 0 "$@"
333 function enable_kernel_lttng_event_fail
()
335 enable_kernel_lttng_event
1 1 "$@"
338 function enable_kernel_lttng_event_notap
()
340 enable_kernel_lttng_event
0 0 "$@"
344 function lttng_enable_kernel_event
346 enable_kernel_lttng_event_ok
"$@"
349 function lttng_enable_kernel_syscall
()
351 local expected_to_fail
=$1
353 local syscall_name
=$3
354 local channel_name
=$4
356 if [ -z $syscall_name ]; then
357 # Enable all event if no syscall name specified
361 if [ -z $channel_name ]; then
362 # default channel if none specified
365 chan
="-c $channel_name"
368 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
369 enable-event
--syscall "$syscall_name" $chan -s $sess_name -k
371 if [[ $expected_to_fail -eq "1" ]]; then
373 ok $?
"Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
375 ok
$ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
379 function lttng_enable_kernel_syscall_ok
()
381 lttng_enable_kernel_syscall
0 "$@"
384 function lttng_enable_kernel_syscall_fail
()
386 lttng_enable_kernel_syscall
1 "$@"
389 function lttng_disable_kernel_syscall
()
391 local expected_to_fail
=$1
393 local syscall_name
=$3
394 local channel_name
=$4
396 if [ -z $syscall_name ]; then
397 # Enable all event if no syscall name specified
401 if [ -z $channel_name ]; then
402 # default channel if none specified
405 chan
="-c $channel_name"
408 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
409 disable-event
--syscall "$syscall_name" $chan -s $sess_name -k
412 if [[ $expected_to_fail -eq "1" ]]; then
414 ok $?
"Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
416 ok
$ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
420 function lttng_disable_kernel_syscall_ok
()
422 lttng_disable_kernel_syscall
0 "$@"
425 function lttng_disable_kernel_syscall_fail
()
427 lttng_disable_kernel_syscall
1 "$@"
430 function lttng_enable_kernel_function_event
()
432 local expected_to_fail
="$1"
435 local event_name
="$4"
437 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
--kernel --function="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
439 if [[ $expected_to_fail -eq "1" ]]; then
441 ok $?
"Enable kernel function event for session $sess_name failed as expected"
443 ok
$ret "Enable kernel function event for session $sess_name"
447 function lttng_enable_kernel_function_event_ok
()
449 lttng_enable_kernel_function_event
0 "$@"
452 function lttng_enable_kernel_userspace_probe_event
()
454 local expected_to_fail
="$1"
457 local event_name
="$4"
459 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
--kernel --userspace-probe="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
461 if [[ $expected_to_fail -eq "1" ]]; then
463 ok $?
"Enable kernel userspace probe event for session $sess_name failed as expected"
465 ok
$ret "Enable kernel userspace probe event for session $sess_name"
469 function lttng_enable_kernel_userspace_probe_event_fail
()
471 lttng_enable_kernel_userspace_probe_event
1 "$@"
474 function lttng_enable_kernel_userspace_probe_event_ok
()
476 lttng_enable_kernel_userspace_probe_event
0 "$@"
479 function disable_kernel_lttng_userspace_probe_event_ok
()
482 local event_name
="$2"
484 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" disable-event
--kernel "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
485 ok $?
"Disable kernel event $target for session $sess_name"
487 function lttng_enable_kernel_channel
()
490 local expected_to_fail
=$2
492 local channel_name
=$4
495 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
496 enable-channel
-k $channel_name -s $sess_name $opts
498 if [[ $expected_to_fail -eq "1" ]]; then
501 if [ $withtap -eq "1" ]; then
502 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
505 if [ $withtap -eq "1" ]; then
506 ok
$ret "Enable channel $channel_name for session $sess_name"
511 function lttng_enable_kernel_channel_ok
()
513 lttng_enable_kernel_channel
1 0 "$@"
516 function lttng_enable_kernel_channel_fail
()
518 lttng_enable_kernel_channel
1 1 "$@"
521 function lttng_enable_kernel_channel_notap
()
523 lttng_enable_kernel_channel
0 0 "$@"
526 function enable_kernel_lttng_channel_ok
()
528 lttng_enable_kernel_channel
1 0 "$@"
531 function lttng_disable_kernel_channel
()
533 local expected_to_fail
=$1
535 local channel_name
=$3
537 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
538 disable-channel
-k $channel_name -s $sess_name
540 if [[ $expected_to_fail -eq "1" ]]; then
542 ok $?
"Disable channel $channel_name for session $sess_name failed as expected"
544 ok
$ret "Disable channel $channel_name for session $sess_name"
548 function lttng_disable_kernel_channel_ok
()
550 lttng_disable_kernel_channel
0 "$@"
553 function lttng_disable_kernel_channel_fail
()
555 lttng_disable_kernel_channel
1 "$@"
558 function start_lttng_relayd_opt
()
561 local process_mode
=$2
564 DIR
=$
(readlink
-f "$TESTDIR")
566 if [ -z $
(lttng_pgrep
"$RELAYD_MATCH") ]; then
567 # shellcheck disable=SC2086
568 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
569 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
570 if [ $?
-eq 1 ]; then
571 if [ $withtap -eq "1" ]; then
572 fail
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
576 if [ $withtap -eq "1" ]; then
577 pass
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
581 pass
"Start lttng-relayd (opt: $opt)"
585 function start_lttng_relayd
()
587 start_lttng_relayd_opt
1 "-b" "$@"
590 function start_lttng_relayd_notap
()
592 start_lttng_relayd_opt
0 "-b" "$@"
595 function stop_lttng_relayd_opt
()
605 if [ -z "$signal" ]; then
610 # Multiply time by 2 to simplify integer arithmetic
611 if [ -n "$timeout_s" ]; then
612 dtimeleft_s
=$
((timeout_s
* 2))
616 pids
=$
(lttng_pgrep
"$RELAYD_MATCH")
617 if [ -z "$pids" ]; then
618 if [ "$is_cleanup" -eq 1 ]; then
620 elif [ "$withtap" -eq "1" ]; then
621 fail
"No relay daemon to kill"
623 LTTNG_BAIL_OUT
"No relay daemon to kill"
628 diag
"Killing (signal $signal) lttng-relayd (pid: $pids)"
630 # shellcheck disable=SC2086
631 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
633 if [ "$withtap" -eq "1" ]; then
634 fail
"Kill relay daemon"
638 while [ -n "$out" ]; do
639 out
=$
(lttng_pgrep
"$RELAYD_MATCH")
640 if [ -n "$dtimeleft_s" ]; then
641 if [ $dtimeleft_s -lt 0 ]; then
645 dtimeleft_s
=$
((dtimeleft_s
- 1))
649 if [ "$withtap" -eq "1" ]; then
650 if [ "$retval" -eq "0" ]; then
651 pass
"Wait after kill relay daemon"
653 fail
"Wait after kill relay daemon"
660 function stop_lttng_relayd
()
662 stop_lttng_relayd_opt
1 0 "$@"
665 function stop_lttng_relayd_notap
()
667 stop_lttng_relayd_opt
0 0 "$@"
670 function stop_lttng_relayd_cleanup
()
672 stop_lttng_relayd_opt
0 1 "$@"
675 #First arg: show tap output
676 #Second argument: load path for automatic loading
677 function start_lttng_sessiond_opt
()
682 # The rest of the arguments will be passed directly to lttng-sessiond.
688 local long_bit_value
=
689 long_bit_value
=$
(getconf LONG_BIT
)
691 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
692 # Env variable requested no session daemon
696 DIR
=$
(readlink
-f "$TESTDIR")
698 # Get long_bit value for 32/64 consumerd
699 case "$long_bit_value" in
701 consumerd
="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
704 consumerd
="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
711 # Check for env. variable. Allow the use of LD_PRELOAD etc.
712 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
713 env_vars
="${LTTNG_SESSIOND_ENV_VARS} "
715 env_vars
="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN"
717 if ! validate_kernel_version
; then
718 fail
"Start session daemon"
719 LTTNG_BAIL_OUT
"*** Kernel too old for session daemon tests ***"
722 diag
"export LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/"
723 : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/"}"
724 export LTTNG_SESSION_CONFIG_XSD_PATH
726 if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ]; then
728 if [ -n "$load_path" ]; then
729 diag
"env $env_vars --load $load_path --background $consumerd $@"
730 # shellcheck disable=SC2086
731 env
$env_vars --load "$load_path" --background "$consumerd" "$@"
733 diag
"env $env_vars --background $consumerd $@"
734 # shellcheck disable=SC2086
735 env
$env_vars --background "$consumerd" "$@"
737 #$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
739 if [ "$withtap" -eq "1" ]; then
740 ok
$status "Start session daemon"
745 function start_lttng_sessiond
()
747 start_lttng_sessiond_opt
1 "$@"
750 function start_lttng_sessiond_notap
()
752 start_lttng_sessiond_opt
0 "$@"
755 function stop_lttng_sessiond_opt
()
766 if [ -z "$signal" ]; then
770 # Multiply time by 2 to simplify integer arithmetic
771 if [ -n "$timeout_s" ]; then
772 dtimeleft_s
=$
((timeout_s
* 2))
775 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
776 # Env variable requested no session daemon
780 runas_pids
=$
(lttng_pgrep
"$RUNAS_MATCH")
781 pids
=$
(lttng_pgrep
"$SESSIOND_MATCH")
783 if [ -n "$runas_pids" ]; then
784 pids
="$pids $runas_pids"
787 if [ -z "$pids" ]; then
788 if [ "$is_cleanup" -eq 1 ]; then
790 elif [ "$withtap" -eq "1" ]; then
791 fail
"No session daemon to kill"
793 LTTNG_BAIL_OUT
"No session daemon to kill"
798 diag
"Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
800 # shellcheck disable=SC2086
801 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
803 if [ "$withtap" -eq "1" ]; then
804 fail
"Kill sessions daemon"
808 while [ -n "$out" ]; do
809 out
=$
(lttng_pgrep
"${SESSIOND_MATCH}")
810 if [ -n "$dtimeleft_s" ]; then
811 if [ $dtimeleft_s -lt 0 ]; then
815 dtimeleft_s
=$
((dtimeleft_s
- 1))
820 while [ -n "$out" ]; do
821 out
=$
(lttng_pgrep
"$CONSUMERD_MATCH")
822 if [ -n "$dtimeleft_s" ]; then
823 if [ $dtimeleft_s -lt 0 ]; then
827 dtimeleft_s
=$
((dtimeleft_s
- 1))
832 if [ "$withtap" -eq "1" ]; then
833 if [ "$retval" -eq "0" ]; then
834 pass
"Wait after kill session daemon"
836 fail
"Wait after kill session daemon"
840 if [ "$signal" = "SIGKILL" ]; then
841 if [ "$(id -u)" -eq "0" ]; then
843 modules
="$(lsmod | grep ^lttng | awk '{print $1}')"
845 if [ -n "$modules" ]; then
846 diag
"Unloading all LTTng modules"
847 modprobe
--remove "$modules"
855 function stop_lttng_sessiond
()
857 stop_lttng_sessiond_opt
1 0 "$@"
860 function stop_lttng_sessiond_notap
()
862 stop_lttng_sessiond_opt
0 0 "$@"
865 function stop_lttng_sessiond_cleanup
()
867 stop_lttng_sessiond_opt
0 1 "$@"
870 function sigstop_lttng_sessiond_opt
()
876 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
877 # Env variable requested no session daemon
881 pids
="$(lttng_pgrep "${SESSIOND_MATCH}") $(lttng_pgrep "$RUNAS_MATCH")"
883 if [ "$withtap" -eq "1" ]; then
884 diag
"Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
887 # shellcheck disable=SC2086
888 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
889 if [ "$withtap" -eq "1" ]; then
890 fail
"Sending SIGSTOP to session daemon"
894 while [ $out -ne 0 ]; do
895 pids
="$(lttng_pgrep "$SESSIOND_MATCH")"
897 # Wait until state becomes stopped for session
900 for sessiond_pid
in $pids; do
901 state
="$(ps -p "$sessiond_pid" -o state= )"
902 if [[ -n "$state" && "$state" != "T" ]]; then
908 if [ "$withtap" -eq "1" ]; then
909 pass
"Sending SIGSTOP to session daemon"
914 function sigstop_lttng_sessiond
()
916 sigstop_lttng_sessiond_opt
1 "$@"
919 function sigstop_lttng_sessiond_notap
()
921 sigstop_lttng_sessiond_opt
0 "$@"
924 function stop_lttng_consumerd_opt
()
934 if [ -z "$signal" ]; then
938 # Multiply time by 2 to simplify integer arithmetic
939 if [ -n "$timeout_s" ]; then
940 dtimeleft_s
=$
((timeout_s
* 2))
943 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
945 if [ -z "$pids" ]; then
946 if [ "$is_cleanup" -eq 1 ]; then
948 elif [ "$withtap" -eq "1" ]; then
949 fail
"No consumerd daemon to kill"
951 LTTNG_BAIL_OUT
"No consumerd daemon to kill"
956 diag
"Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')"
958 # shellcheck disable=SC2086
959 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
961 if [ "$withtap" -eq "1" ]; then
962 fail
"Kill consumer daemon"
966 while [ $out -ne 0 ]; do
967 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
969 # If consumerds are still present check their status.
970 # A zombie status qualifies the consumerd as *killed*
972 for consumer_pid
in $pids; do
973 state
="$(ps -p "$consumer_pid" -o state= )"
974 if [[ -n "$state" && "$state" != "Z" ]]; then
978 if [ -n "$dtimeleft_s" ]; then
979 if [ $dtimeleft_s -lt 0 ]; then
983 dtimeleft_s
=$
((dtimeleft_s
- 1))
987 if [ "$withtap" -eq "1" ]; then
988 if [ "$retval" -eq "0" ]; then
989 pass
"Wait after kill consumer daemon"
991 fail
"Wait after kill consumer daemon"
999 function stop_lttng_consumerd
()
1001 stop_lttng_consumerd_opt
1 0 "$@"
1004 function stop_lttng_consumerd_notap
()
1006 stop_lttng_consumerd_opt
0 0 "$@"
1009 function stop_lttng_consumerd_cleanup
()
1011 stop_lttng_consumerd_opt
0 1 "$@"
1014 function sigstop_lttng_consumerd_opt
()
1017 local signal
=SIGSTOP
1020 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
1022 diag
"Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')"
1024 # shellcheck disable=SC2086
1025 kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1028 if [ $retval -eq 1 ]; then
1029 if [ "$withtap" -eq "1" ]; then
1030 fail
"Sending SIGSTOP to consumer daemon"
1035 while [ $out -ne 0 ]; do
1036 pids
="$(lttng_pgrep "$CONSUMERD_MATCH")"
1038 # Wait until state becomes stopped for all
1041 for consumer_pid
in $pids; do
1042 state
="$(ps -p "$consumer_pid" -o state= )"
1043 if [[ -n "$state" && "$state" != "T" ]]; then
1049 if [ "$withtap" -eq "1" ]; then
1050 pass
"Sending SIGSTOP to consumer daemon"
1056 function sigstop_lttng_consumerd
()
1058 sigstop_lttng_consumerd_opt
1 "$@"
1061 function sigstop_lttng_consumerd_notap
()
1063 sigstop_lttng_consumerd_opt
0 "$@"
1066 function list_lttng_with_opts
()
1072 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1075 if [ $withtap -eq "1" ]; then
1076 ok
$ret "Lttng-tool list command with option $opts"
1080 function list_lttng_ok
()
1082 list_lttng_with_opts
1 "$@"
1085 function list_lttng_notap
()
1087 list_lttng_with_opts
0 "$@"
1090 function create_lttng_session_no_output
()
1095 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1096 create
$sess_name --no-output $opts
1097 ok $?
"Create session $sess_name in no-output mode"
1100 function create_lttng_session_uri
() {
1105 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1106 create
$sess_name -U $uri $opts
1107 ok $?
"Create session $sess_name with uri:$uri and opts: $opts"
1110 function create_lttng_session
()
1113 local expected_to_fail
=$2
1118 if [ -z "$trace_path" ]; then
1119 # Use lttng-sessiond default output.
1122 trace_path
="-o $trace_path"
1125 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1126 create
"$sess_name" $trace_path $opt
1128 if [ $expected_to_fail -eq "1" ]; then
1131 if [ $withtap -eq "1" ]; then
1132 ok
$ret "Create session $sess_name in $trace_path failed as expected"
1135 if [ $withtap -eq "1" ]; then
1136 ok
$ret "Create session $sess_name in $trace_path"
1142 function create_lttng_session_ok
()
1144 create_lttng_session
1 0 "$@"
1147 function create_lttng_session_fail
()
1149 create_lttng_session
1 1 "$@"
1152 function create_lttng_session_notap
()
1154 create_lttng_session
0 0 "$@"
1158 function enable_ust_lttng_channel
()
1161 local expected_to_fail
=$2
1163 local channel_name
=$4
1166 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1167 enable-channel
-u $channel_name -s $sess_name $opts
1169 if [[ $expected_to_fail -eq "1" ]]; then
1172 if [ $withtap -eq "1" ]; then
1173 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
1176 if [ $withtap -eq "1" ]; then
1177 ok
$ret "Enable channel $channel_name for session $sess_name"
1183 function enable_ust_lttng_channel_ok
()
1185 enable_ust_lttng_channel
1 0 "$@"
1188 function enable_ust_lttng_channel_fail
()
1190 enable_ust_lttng_channel
1 1 "$@"
1193 function enable_ust_lttng_channel_notap
()
1195 enable_ust_lttng_channel
0 0 "$@"
1198 function disable_ust_lttng_channel
()
1201 local channel_name
=$2
1203 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1204 disable-channel
-u $channel_name -s $sess_name
1205 ok $?
"Disable channel $channel_name for session $sess_name"
1208 function enable_lttng_mmap_overwrite_kernel_channel
()
1211 local channel_name
=$2
1213 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1214 enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite
1215 ok $?
"Enable channel $channel_name for session $sess_name"
1218 function enable_lttng_mmap_discard_small_kernel_channel
()
1221 local channel_name
=$2
1223 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1224 enable-channel
-s $sess_name $channel_name -k --output mmap
--discard --subbuf-size=$
(getconf PAGE_SIZE
) --num-subbuf=2
1225 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1228 function enable_lttng_mmap_overwrite_small_kernel_channel
()
1231 local channel_name
=$2
1233 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1234 enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite --subbuf-size=$
(getconf PAGE_SIZE
) --num-subbuf=2
1235 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1238 function enable_lttng_mmap_overwrite_ust_channel
()
1241 local channel_name
=$2
1243 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1244 enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite
1245 ok $?
"Enable channel $channel_name for session $sess_name"
1248 function enable_ust_lttng_event
()
1251 local expected_to_fail
=$2
1253 local event_name
="$4"
1254 local channel_name
=$5
1256 if [ -z $channel_name ]; then
1257 # default channel if none specified
1260 chan
="-c $channel_name"
1263 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1264 enable-event
"$event_name" $chan -s "$sess_name" -u
1266 if [[ $expected_to_fail -eq "1" ]]; then
1269 if [[ $withtap -eq "1" ]]; then
1270 ok
$ret "Enable ust event $event_name for session $session_name failed as expected"
1273 if [[ $withtap -eq "1" ]]; then
1274 ok
$ret "Enable ust event $event_name for session $sess_name"
1280 function enable_ust_lttng_event_ok
()
1282 enable_ust_lttng_event
1 0 "$@"
1285 function enable_ust_lttng_event_fail
()
1287 enable_ust_lttng_event
1 1 "$@"
1290 function enable_ust_lttng_event_notap
()
1292 enable_ust_lttng_event
0 0 "$@"
1295 function enable_jul_lttng_event
()
1301 if [ -z $channel_name ]; then
1302 # default channel if none specified
1305 chan
="-c $channel_name"
1308 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1309 enable-event
"$event_name" $chan -s $sess_name -j
1310 ok $?
"Enable JUL event $event_name for session $sess_name"
1313 function enable_jul_lttng_event_loglevel
()
1316 local event_name
="$2"
1318 local channel_name
=$4
1320 if [ -z $channel_name ]; then
1321 # default channel if none specified
1324 chan
="-c $channel_name"
1327 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1328 enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j
1329 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
1332 function enable_log4j_lttng_event
()
1336 local channel_name
=$3
1340 # default channel if none specified
1341 if [ -n "$channel_name" ]; then
1342 chan_opt
=("-c" "$channel_name")
1345 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1346 enable-event
"$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j
1347 ok $?
"Enable LOG4J event '$event_name' for session '$sess_name'"
1350 function enable_log4j_lttng_event_filter
()
1356 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1357 enable-event
"$event_name" -s "$sess_name" --log4j --filter "$filter"
1358 ok $?
"Enable LOG4J event '$event_name' with filter '$filter' for session '$sess_name'"
1361 function enable_log4j_lttng_event_filter_loglevel_only
()
1368 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1369 enable-event
--loglevel-only "$loglevel" "$event_name" -s "$sess_name" -l --filter "$filter"
1370 ok $?
"Enable LOG4J event '$event_name' with filter '$filter' and loglevel-only '$loglevel' for session '$sess_name'"
1373 function enable_log4j_lttng_event_loglevel
()
1378 local channel_name
=$4
1381 # default channel if none specified
1382 if [ -n "$channel_name" ]; then
1383 chan_opt
=("-c" "$channel_name")
1386 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1387 enable-event
--loglevel "$loglevel" "$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j
1388 ok $?
"Enable LOG4J event '$event_name' for session '$sess_name' with loglevel '$loglevel'"
1391 function enable_log4j_lttng_event_loglevel_only
()
1396 local channel_name
=$4
1400 # default channel if none specified
1401 if [ -n "$channel_name" ]; then
1402 chan_opt
=("-c" "$channel_name")
1405 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1406 enable-event
--loglevel-only "$loglevel" "$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j
1407 ok $?
"Enable LOG4J event '$event_name' for session '$sess_name' with loglevel-only '$loglevel'"
1410 function enable_python_lttng_event
()
1416 if [ -z $channel_name ]; then
1417 # default channel if none specified
1420 chan
="-c $channel_name"
1423 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1424 enable-event
"$event_name" $chan -s $sess_name -p
1425 ok $?
"Enable Python event $event_name for session $sess_name"
1428 function enable_python_lttng_event_loglevel
()
1431 local event_name
="$2"
1433 local channel_name
=$4
1435 if [ -z $channel_name ]; then
1436 # default channel if none specified
1439 chan
="-c $channel_name"
1442 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1443 enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -p
1444 ok $?
"Enable Python event $event_name for session $sess_name with loglevel $loglevel"
1447 function enable_ust_lttng_event_filter
()
1449 local sess_name
="$1"
1450 local event_name
="$2"
1452 local channel_name
=$4
1454 if [ -z $channel_name ]; then
1455 # default channel if none specified
1458 chan
="-c $channel_name"
1461 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1462 enable-event
$chan "$event_name" -s $sess_name -u --filter "$filter"
1463 ok $?
"Enable event $event_name with filtering for session $sess_name"
1466 function enable_ust_lttng_event_loglevel
()
1468 local sess_name
="$1"
1469 local event_name
="$2"
1472 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1473 enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel
1474 ok $?
"Enable event $event_name with loglevel $loglevel"
1477 function enable_ust_lttng_event_loglevel_only
()
1479 local sess_name
="$1"
1480 local event_name
="$2"
1483 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1484 enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel
1485 ok $?
"Enable event $event_name with loglevel-only $loglevel"
1488 function disable_ust_lttng_event
()
1490 local sess_name
="$1"
1491 local event_name
="$2"
1492 local channel_name
="$3"
1494 if [ -z $channel_name ]; then
1495 # default channel if none specified
1498 chan
="-c $channel_name"
1501 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1502 disable-event
"$event_name" -s $sess_name $chan -u
1503 ok $?
"Disable event $event_name for session $sess_name"
1506 function disable_jul_lttng_event
()
1508 local sess_name
="$1"
1509 local event_name
="$2"
1511 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
1512 ok $?
"Disable JUL event $event_name for session $sess_name"
1515 function disable_log4j_lttng_event
()
1517 local sess_name
="$1"
1518 local event_name
="$2"
1520 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1521 disable-event
"$event_name" -s "$sess_name" --log4j
1522 ok $?
"Disable LOG4J event '$event_name' for session '$sess_name'"
1525 function disable_python_lttng_event
()
1527 local sess_name
="$1"
1528 local event_name
="$2"
1530 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1531 disable-event
"$event_name" -s $sess_name -p
1532 ok $?
"Disable Python event $event_name for session $sess_name"
1535 function start_lttng_tracing_opt
()
1538 local expected_to_fail
=$2
1541 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1544 if [[ $expected_to_fail -eq "1" ]]; then
1547 if [ $withtap -eq "1" ]; then
1548 ok $?
"Start tracing for session $sess_name failed as expected"
1551 if [ $withtap -eq "1" ]; then
1552 ok
$ret "Start tracing for session $sess_name"
1557 function start_lttng_tracing_ok
()
1559 start_lttng_tracing_opt
1 0 "$@"
1562 function start_lttng_tracing_fail
()
1564 start_lttng_tracing_opt
1 1 "$@"
1567 function start_lttng_tracing_notap
()
1569 start_lttng_tracing_opt
0 1 "$@"
1572 function stop_lttng_tracing_opt
()
1575 local expected_to_fail
=$2
1578 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1581 if [[ $expected_to_fail -eq "1" ]]; then
1584 if [ $withtap -eq "1" ]; then
1585 ok $?
"Stop lttng tracing for session $sess_name failed as expected"
1588 if [ $withtap -eq "1" ]; then
1589 ok
$ret "Stop lttng tracing for session $sess_name"
1594 function stop_lttng_tracing_ok
()
1596 stop_lttng_tracing_opt
1 0 "$@"
1599 function stop_lttng_tracing_fail
()
1601 stop_lttng_tracing_opt
1 1 "$@"
1604 function stop_lttng_tracing_notap
()
1606 stop_lttng_tracing_opt
0 0 "$@"
1609 function destroy_lttng_session
()
1612 local expected_to_fail
=$2
1615 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1618 if [[ $expected_to_fail -eq "1" ]]; then
1621 if [ $withtap -eq "1" ]; then
1622 ok
$ret "Destroy session $sess_name failed as expected"
1625 if [ $withtap -eq "1" ]; then
1626 ok
$ret "Destroy session $sess_name"
1631 function destroy_lttng_session_ok
()
1633 destroy_lttng_session
1 0 "$@"
1637 function destroy_lttng_session_fail
()
1639 destroy_lttng_session
1 1 "$@"
1642 function destroy_lttng_session_notap
()
1644 destroy_lttng_session
0 0 "$@"
1647 function destroy_lttng_sessions
()
1649 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1651 ok $?
"Destroy all lttng sessions"
1654 function lttng_snapshot_add_output
()
1656 local expected_to_fail
=$1
1661 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1662 snapshot add-output
-s $sess_name $trace_path $opts
1664 if [[ $expected_to_fail -eq 1 ]]; then
1666 ok $?
"Added snapshot output $trace_path failed as expected"
1668 ok
$ret "Added snapshot output $trace_path"
1672 function lttng_snapshot_add_output_ok
()
1674 lttng_snapshot_add_output
0 "$@"
1677 function lttng_snapshot_add_output_fail
()
1679 lttng_snapshot_add_output
1 "$@"
1682 function lttng_snapshot_del_output
()
1684 local expected_to_fail
=$1
1688 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1689 snapshot del-output
-s $sess_name $id
1691 if [[ $expected_to_fail -eq "1" ]]; then
1693 ok $?
"Deleted snapshot output id $id failed as expected"
1695 ok
$ret "Deleted snapshot output id $id"
1699 function lttng_snapshot_del_output_ok
()
1701 lttng_snapshot_del_output
0 "$@"
1704 function lttng_snapshot_del_output_fail
()
1706 lttng_snapshot_del_output
1 "$@"
1709 function lttng_snapshot_record
()
1714 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1715 snapshot record
-s "$sess_name" "$trace_path"
1716 ok $?
"Snapshot recorded"
1719 function lttng_snapshot_list
()
1722 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1723 snapshot list-output
-s $sess_name
1724 ok $?
"Snapshot list"
1727 function lttng_save
()
1732 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1733 save
$sess_name $opts
1734 ok $?
"Session saved"
1737 function lttng_load
()
1739 local expected_to_fail
=$1
1742 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1745 if [[ $expected_to_fail -eq "1" ]]; then
1747 ok $?
"Load command failed as expected with opts: $opts"
1749 ok
$ret "Load command with opts: $opts"
1753 function lttng_load_ok
()
1758 function lttng_load_fail
()
1763 function lttng_track
()
1765 local expected_to_fail
="$1"
1768 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN track
$opts >$OUTPUT_DEST
1770 if [[ $expected_to_fail -eq "1" ]]; then
1772 ok $?
"Track command failed as expected with opts: $opts"
1774 ok
$ret "Track command with opts: $opts"
1778 function lttng_track_ok
()
1783 function lttng_track_fail
()
1788 function lttng_untrack
()
1790 local expected_to_fail
="$1"
1793 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN untrack
$opts >$OUTPUT_DEST
1795 if [[ $expected_to_fail -eq "1" ]]; then
1797 ok $?
"Untrack command failed as expected with opts: $opts"
1799 ok
$ret "Untrack command with opts: $opts"
1803 function lttng_untrack_ok
()
1805 lttng_untrack
0 "$@"
1808 function lttng_untrack_fail
()
1810 lttng_untrack
1 "$@"
1813 function lttng_track_pid_ok
()
1816 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track
--kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1817 ok $?
"Lttng track pid on the kernel domain"
1820 function lttng_untrack_kernel_all_ok
()
1822 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack
--kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1823 ok $?
"Lttng untrack all pid on the kernel domain"
1826 function lttng_track_ust_ok
()
1828 lttng_track_ok
-u "$@"
1831 function lttng_track_ust_fail
()
1833 lttng_track_fail
-u "$@"
1836 function lttng_track_kernel_ok
()
1838 lttng_track_ok
-k "$@"
1841 function lttng_track_kernel_fail
()
1843 lttng_track_fail
-k "$@"
1846 function lttng_untrack_ust_ok
()
1848 lttng_untrack_ok
-u "$@"
1851 function lttng_untrack_ust_fail
()
1853 lttng_untrack_fail
-u "$@"
1856 function lttng_untrack_kernel_ok
()
1858 lttng_untrack_ok
-k "$@"
1861 function lttng_untrack_kernel_fail
()
1863 lttng_untrack_fail
-k "$@"
1866 function lttng_add_context_list
()
1868 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1871 ok
$ret "Context listing"
1874 function add_context_lttng
()
1876 local expected_to_fail
="$1"
1878 local session_name
="$3"
1879 local channel_name
="$4"
1882 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
1883 add-context
-s $session_name -c $channel_name -t $type $domain
1885 if [[ $expected_to_fail -eq "1" ]]; then
1887 ok $?
"Add context command failed as expected for type: $type"
1889 ok
$ret "Add context command for type: $type"
1893 function add_context_ust_ok
()
1895 add_context_lttng
0 -u "$@"
1898 function add_context_ust_fail
()
1900 add_context_lttng
1 -u "$@"
1903 function add_context_kernel_ok
()
1905 add_context_lttng
0 -k "$@"
1908 function add_context_kernel_fail
()
1910 add_context_lttng
1 -k "$@"
1913 function wait_live_trace_ready
()
1916 local zero_client_match
=0
1918 diag
"Waiting for live trace at url: $url"
1919 while [ $zero_client_match -eq 0 ]; do
1920 zero_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "0 client(s) connected" |
wc -l)
1923 pass
"Waiting for live trace at url: $url"
1926 function wait_live_viewer_connect
()
1929 local one_client_match
=0
1931 diag
"Waiting for live viewers on url: $url"
1932 while [ $one_client_match -eq 0 ]; do
1933 one_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "1 client(s) connected" |
wc -l)
1936 pass
"Waiting for live viewers on url: $url"
1939 function bail_out_if_no_babeltrace
()
1941 which "$BABELTRACE_BIN" >/dev
/null
1942 if [ $?
-ne 0 ]; then
1943 LTTNG_BAIL_OUT
"\"$BABELTRACE_BIN\" binary not found. Skipping tests"
1947 # Check that the trace metadata contains '$expected' event ids matching '$event_name'.
1948 function validate_metadata_event
()
1958 metadata_file
=$
(find "$trace_path" -name "metadata")
1959 metadata_path
=$
(dirname "$metadata_file")
1961 bail_out_if_no_babeltrace
1963 count
=$
($BABELTRACE_BIN --output-format=ctf-metadata
"$metadata_path" |
grep -c "$event_name")
1965 test "$count" -eq "$expected"
1966 ok $?
"Found $count / $expected metadata event id matching '$event_name'"
1969 # Check that the trace contains '$expected' events matching '$event_name', other
1970 # events not matching '$event_name' can be present.
1971 function trace_matches
()
1980 bail_out_if_no_babeltrace
1982 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c "$event_name")
1983 total
=$
($BABELTRACE_BIN "$trace_path" |
wc -l)
1985 test "$count" -eq "$expected"
1987 ok $?
"Found $count / $expected events matching '$event_name' out of $total events"
1990 # Check that the trace contains '$expected' events matching '$event_name' and no
1992 function trace_match_only
()
2001 bail_out_if_no_babeltrace
2003 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c "$event_name")
2004 total
=$
($BABELTRACE_BIN "$trace_path" |
wc -l)
2006 test "$expected" -eq "$count" && test "$total" -eq "$expected"
2008 ok $?
"Found $count / $expected events matching '$event_name' amongst $total events"
2011 # Check that the trace contains at least 1 event matching each name in the
2012 # comma separated list '$event_names'.
2013 function validate_trace
()
2015 local event_names
=$1
2020 bail_out_if_no_babeltrace
2024 for event_name
in $event_names; do
2025 # trace_path is unquoted since callers make use of globbing
2026 count
=$
($BABELTRACE_BIN $trace_path |
grep -c "$event_name")
2028 ok $?
"Found $count events matching '$event_name'"
2033 # Check that the trace contains at least 1 event matching each name in the
2034 # comma separated list '$event_names' and a total of '$expected' events.
2035 function validate_trace_count
()
2037 local event_names
=$1
2044 bail_out_if_no_babeltrace
2048 for event_name
in $event_names; do
2049 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c "$event_name")
2051 ok $?
"Found '$count' events matching '$event_name'"
2052 total
=$
(( total
+ count
))
2055 test $total -eq "$expected"
2056 ok $?
"Found $total events, expected $expected events"
2059 # Check that the trace contains at least '$expected_min' event matching each
2060 # name in the comma separated list '$event_names' and a total at least
2061 # '$expected_min' and less than '$expected_max' events.
2062 function validate_trace_count_range_incl_min_excl_max
()
2064 local event_names
=$1
2066 local expected_min
=$3
2067 local expected_max
=$4
2072 bail_out_if_no_babeltrace
2076 for event_name
in $event_names; do
2077 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c "$event_name")
2078 test "$count" -ge "$expected_min"
2079 ok $?
"Found $count events matching '$event_name', expected at least $expected_min"
2080 total
=$
(( total
+ count
))
2083 test $total -ge "$expected_min" && test $total -lt "$expected_max"
2084 ok $?
"Found a total of $total events, expected at least $expected_min and less than $expected_max"
2087 function trace_first_line
()
2091 $BABELTRACE_BIN "$trace_path" |
head -n 1
2094 # Check that the trace contains at least 1 event matching the grep extended
2095 # regexp '$event_exp'.
2096 function validate_trace_exp
()
2103 bail_out_if_no_babeltrace
2105 # event_exp is unquoted since it contains multiple grep arguments
2106 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c --extended-regexp $event_exp)
2108 ok $?
"Found $count events matching expression '$event_exp'"
2111 # Check that the trace contains at least 1 event matching the grep extended
2112 # regexp '$event_exp' and zero event not matching it.
2113 function validate_trace_only_exp
()
2121 bail_out_if_no_babeltrace
2123 # event_exp is unquoted since it contains multiple grep arguments
2124 count
=$
($BABELTRACE_BIN "$trace_path" |
grep -c --extended-regexp $event_exp)
2125 total
=$
($BABELTRACE_BIN "$trace_path" |
wc -l)
2127 test "$count" -gt 0 && test "$total" -eq "$count"
2128 ok $?
"Found $count events matching expression '$event_exp' amongst $total events"
2131 # Check that the trace is valid and contains 0 event.
2132 function validate_trace_empty
()
2139 bail_out_if_no_babeltrace
2141 events
=$
($BABELTRACE_BIN "$trace_path")
2143 if [ $ret -ne 0 ]; then
2144 fail
"Failed to parse trace"
2148 count
=$
(echo -n "$events" |
wc -l)
2150 ok $?
"Validate trace is empty, found $count events"
2153 function validate_directory_empty
()
2155 local trace_path
="$1"
2161 # Do not double quote `$trace_path` below as we want wildcards to be
2163 files
="$(ls -A $trace_path)"
2165 if [ $ret -ne 0 ]; then
2166 fail
"Failed to list content of directory \"$trace_path\""
2170 nb_files
="$(echo -n "$files" | wc -l)"
2171 test "$nb_files" -eq 0
2172 ok $?
"Directory \"$trace_path\" is empty"
2175 function validate_trace_session_ust_empty
()
2177 validate_directory_empty
"$1"/ust
2180 function validate_trace_session_kernel_empty
()
2182 validate_trace_empty
"$1"/kernel
2185 function regenerate_metadata
()
2187 local expected_to_fail
=$1
2190 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2191 regenerate metadata
-s $sess_name
2193 if [[ $expected_to_fail -eq "1" ]]; then
2195 ok $?
"Expected fail on regenerate metadata $sess_name"
2197 ok
$ret "Metadata regenerate $sess_name"
2201 function regenerate_metadata_ok
()
2203 regenerate_metadata
0 "$@"
2206 function regenerate_metadata_fail
()
2208 regenerate_metadata
1 "$@"
2211 function regenerate_statedump
()
2213 local expected_to_fail
=$1
2216 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2217 regenerate statedump
-s $sess_name
2219 if [[ $expected_to_fail -eq "1" ]]; then
2221 ok $?
"Expected fail on regenerate statedump $sess_name"
2223 ok
$ret "Statedump regenerate $sess_name"
2227 function regenerate_statedump_ok
()
2229 regenerate_statedump
0 "$@"
2232 function regenerate_statedump_fail
()
2234 regenerate_statedump
1 "$@"
2237 function rotate_session
()
2239 local expected_to_fail
=$1
2242 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2245 if [[ $expected_to_fail -eq "1" ]]; then
2247 ok $?
"Expected fail on rotate session $sess_name"
2249 ok
$ret "Rotate session $sess_name"
2253 function rotate_session_ok
()
2255 rotate_session
0 "$@"
2258 function rotate_session_fail
()
2260 rotate_session
1 "$@"
2263 function destructive_tests_enabled
()
2265 if [ "$LTTNG_ENABLE_DESTRUCTIVE_TESTS" = "will-break-my-system" ]; then
2272 function lttng_enable_rotation_timer
()
2274 local expected_to_fail
=$1
2278 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2279 enable-rotation
-s $sess_name --timer $period
2281 if [[ $expected_to_fail -eq "1" ]]; then
2283 ok $?
"Expected fail when setting periodic rotation ($period) of session $sess_name"
2285 ok
$ret "Set periodic rotation ($period) of session $sess_name"
2289 function lttng_enable_rotation_timer_ok
()
2291 lttng_enable_rotation_timer
0 $@
2294 function lttng_enable_rotation_timer_fail
()
2296 lttng_enable_rotation_timer
1 $@
2299 function lttng_enable_rotation_size
()
2301 local expected_to_fail
=$1
2305 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2306 enable-rotation
-s $sess_name --size $size
2308 if [[ $expected_to_fail -eq "1" ]]; then
2310 ok $?
"Expected to fail to set a periodic rotation of session $sess_name" "every " $size " bytes"
2312 ok
$ret "Set a scheduled rotation of session $sess_name" "every " $size " bytes"
2316 function lttng_enable_rotation_size_ok
()
2318 lttng_enable_rotation_size
0 $@
2321 function lttng_enable_rotation_size_fail
()
2323 lttng_enable_rotation_size
1 $@
2326 function lttng_clear_session
()
2328 local expected_to_fail
=$1
2331 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2334 if [[ $expected_to_fail -eq "1" ]]; then
2336 ok $?
"Expected fail on clear session $sess_name"
2338 ok
$ret "Clear session $sess_name"
2342 function lttng_clear_session_ok
()
2344 lttng_clear_session
0 $@
2347 function lttng_clear_session_fail
()
2349 lttng_clear_session
1 $@
2352 function lttng_clear_all
()
2354 _run_lttng_cmd
"$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
2356 ok $?
"Clear all lttng sessions"
2359 function lttng_add_trigger
()
2361 local expected_to_fail
="$1"
2362 local trigger_name
="$2"
2366 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN add-trigger --name $trigger_name ${args[*]}"
2367 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-trigger
--name "$trigger_name" "${args[@]}" 1> /dev
/null
2> /dev
/null
2369 if [[ $expected_to_fail -eq "1" ]]; then
2371 ok $?
"Add trigger $trigger_name failed as expected"
2373 ok
$ret "Add trigger $trigger_name"
2377 function lttng_remove_trigger
()
2379 local expected_to_fail
="$1"
2380 local trigger_name
="$2"
2383 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN remove-trigger $trigger_name $*"
2384 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" remove-trigger
"$trigger_name" "$@" 1> /dev
/null
2> /dev
/null
2386 if [[ $expected_to_fail -eq "1" ]]; then
2388 ok $?
"Remove trigger $trigger_name failed as expected"
2390 ok
$ret "Remove trigger $trigger_name"
2394 function lttng_add_trigger_ok
()
2396 lttng_add_trigger
0 "$@"
2399 function lttng_add_trigger_fail
()
2401 lttng_add_trigger
1 "$@"
2404 function lttng_remove_trigger_ok
()
2406 lttng_remove_trigger
0 "$@"
2409 function list_triggers_matches_ok
()
2411 local tmp_stdout
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2412 local tmp_stderr
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_stderr.XXXXXX")
2414 local test_name
="$1"
2415 local expected_stdout_file
="$2"
2417 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN list-triggers"
2419 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" list-triggers
> "${tmp_stdout}" 2> "${tmp_stderr}"
2420 ok $?
"${test_name}: exit code is 0"
2422 diff -u "${expected_stdout_file}" "${tmp_stdout}"
2423 ok $?
"${test_name}: expected stdout"
2425 diff -u /dev
/null
"${tmp_stderr}"
2426 ok $?
"${test_name}: expected stderr"
2428 rm -f "${tmp_stdout}"
2429 rm -f "${tmp_stderr}"
2432 function list_triggers_matches_mi_ok
()
2435 local tmp_stdout_raw
2438 local test_name
="$1"
2439 local expected_stdout_file
="$2"
2441 tmp_stdout_raw
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2442 tmp_stdout
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
2443 tmp_stderr
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_stderr.XXXXXX")
2445 diag
"$TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi xml list-triggers"
2447 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" --mi=xml list-triggers
> "${tmp_stdout_raw}" 2> "${tmp_stderr}"
2448 ok $?
"${test_name}: exit code is 0"
2450 # Pretty-fy xml before further test.
2451 $XML_PRETTY < "${tmp_stdout_raw}" > "${tmp_stdout}"
2453 $MI_VALIDATE "${tmp_stdout}"
2454 ok $?
"list-trigger mi is valid"
2456 diff -u "${expected_stdout_file}" "${tmp_stdout}"
2457 ok $?
"${test_name}: expected stdout"
2459 diff -u /dev
/null
"${tmp_stderr}"
2460 ok $?
"${test_name}: expected stderr"
2462 rm -f "${tmp_stdout}"
2463 rm -f "${tmp_stdout_raw}"
2464 rm -f "${tmp_stderr}"
2467 function validate_path_pattern
()
2471 # Base path is only used in error case and is used to list the content
2480 if [ "$ret" -ne "0" ]; then
2481 diag
"Path pattern expected: $pattern"
2482 # List the tracepath for more info. We use find as a recursive
2484 diag
"The base path content:"
2485 find "$base_path" -print
2489 function validate_trace_path_ust_uid
()
2492 local session_name
=$2
2494 local pattern
="$trace_path/$session_name-$date_time_pattern/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2496 validate_path_pattern
"UST per-uid trace path is valid" "$pattern" "$trace_path"
2499 function validate_trace_path_ust_uid_network
()
2502 local session_name
=$2
2505 local hostname
=$HOSTNAME
2509 # If the session was given a network base path (e.g
2510 # 127.0.0.1/my/custom/path on creation, there is no session name
2511 # component to the path on the relayd side. Caller can simply not pass a
2512 # session name for this scenario.
2513 if [ -n "$session_name" ]; then
2514 session_name
="$session_name-$date_time_pattern"
2515 if [ -n "$base_path" ]; then
2516 fail
"Session name and base path are mutually exclusive"
2521 pattern
="$trace_path/$hostname/$base_path/$session_name/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2523 validate_path_pattern
"UST per-uid network trace path is valid" "$pattern" "$trace_path"
2526 function validate_trace_path_ust_uid_snapshot_network
()
2529 local session_name
=$2
2530 local snapshot_name
=$3
2531 local snapshot_number
=$4
2533 local hostname
=$HOSTNAME
2538 # If the session/output was given a network base path (e.g
2539 # 127.0.0.1/my/custom/path on creation, there is no session name
2540 # component to the path on the relayd side. Caller can simply not pass a
2541 # session name for this scenario.
2542 if [ -n "$session_name" ]; then
2543 session_name
="$session_name-$date_time_pattern"
2544 if [ -n "$base_path" ]; then
2545 fail
"Session name and base path are mutually exclusive"
2550 pattern
="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2552 validate_path_pattern
"UST per-uid network snapshot trace path is valid" "$pattern" "$trace_path"
2555 function validate_trace_path_ust_uid_snapshot
()
2558 local session_name
=$2
2559 local snapshot_name
=$3
2560 local snapshot_number
=$4
2566 # If the session/output was given a network base path (e.g
2567 # 127.0.0.1/my/custom/path) on creation, there is no session name
2568 # component to the path on the relayd side. Caller can simply not pass a
2569 # session name for this scenario.
2570 if [ -n "$session_name" ]; then
2571 session_name
="$session_name-$date_time_pattern"
2572 if [ -n "$base_path" ]; then
2573 fail
"Session name and base path are mutually exclusive"
2578 pattern
="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
2580 validate_path_pattern
"UST per-uid snapshot trace path is valid" "$pattern" "$trace_path"
2583 function validate_trace_path_ust_pid
()
2586 local session_name
=$2
2592 # If the session was given a trace path on creation, there is no session
2593 # name component to the path. Caller can simply not pass a session name
2594 # for this scenario.
2595 if [ -n "$session_name" ]; then
2596 session_name
="$session_name-$date_time_pattern"
2599 pattern
="$trace_path/$session_name/ust/pid/$pid/$app_string-*-$date_time_pattern/metadata"
2601 validate_path_pattern
"UST per-pid trace path is valid" "$pattern" "$trace_path"
2604 function validate_trace_path_kernel
()
2607 local session_name
=$2
2610 # If the session was given a trace path on creation, there is no session
2611 # name component to the path. Caller can simply not pass a session name
2612 # for this scenario.
2613 if [ -n "$session_name" ]; then
2614 session_name
="$session_name-$date_time_pattern"
2617 pattern
="$trace_path/$session_name/kernel/metadata"
2619 validate_path_pattern
"Kernel trace path is valid" "$pattern" "$trace_path"
2622 function validate_trace_path_kernel_network
()
2625 local session_name
=$2
2626 local hostname
=$HOSTNAME
2627 local pattern
="$trace_path/$hostname/$session_name-$date_time_pattern/kernel/metadata"
2629 validate_path_pattern
"Kernel network trace path is valid" "$pattern" "$trace_path"
2632 function validate_trace_path_kernel_snapshot
()
2635 local session_name
=$2
2636 local snapshot_name
=$3
2637 local snapshot_number
=$4
2642 # If the session/output was given a network base path (e.g
2643 # 127.0.0.1/my/custom/path on creation, there is no session name
2644 # component to the path on the relayd side. Caller can simply not pass a
2645 # session name for this scenario.
2646 if [ -n "$session_name" ]; then
2647 session_name
="$session_name-$date_time_pattern"
2648 if [ -n "$base_path" ]; then
2649 fail
"Session name and base path are mutually exclusive"
2654 pattern
="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata"
2656 validate_path_pattern
"Kernel snapshot trace path is valid" "$pattern" "$trace_path"
2659 function validate_trace_path_kernel_snapshot_network
()
2662 local session_name
=$2
2663 local snapshot_name
=$3
2664 local snapshot_number
=$4
2666 local hostname
=$HOSTNAME
2670 # If the session/output was given a network base path (e.g
2671 # 127.0.0.1/my/custom/path on creation, there is no session name
2672 # component to the path on the relayd side. Caller can simply not pass a
2673 # session name for this scenario.
2674 if [ -n "$session_name" ]; then
2675 session_name
="$session_name-$date_time_pattern"
2676 if [ -n "$base_path" ]; then
2677 fail
"Session name and base path are mutually exclusive"
2682 pattern
="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata"
2684 validate_path_pattern
"Kernel network snapshot trace path is valid" "$pattern" "$trace_path"