1 # Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
3 # SPDX-License-Identifier: LGPL-2.1-only
6 SESSIOND_BIN
="lttng-sessiond"
7 SESSIOND_MATCH
=".*lttng-sess.*"
8 RUNAS_BIN
="lttng-runas"
9 RUNAS_MATCH
=".*lttng-runas.*"
10 CONSUMERD_BIN
="lttng-consumerd"
11 CONSUMERD_MATCH
=".*lttng-consumerd.*"
12 RELAYD_BIN
="lttng-relayd"
13 RELAYD_MATCH
=".*lttng-relayd.*"
15 BABELTRACE_BIN
="babeltrace"
17 ERROR_OUTPUT_DEST
=/dev
/null
19 # Minimal kernel version supported for session daemon tests
20 KERNEL_MAJOR_VERSION
=2
21 KERNEL_MINOR_VERSION
=6
22 KERNEL_PATCHLEVEL_VERSION
=27
24 # We set the default UST register timeout and network and app socket timeout to
25 # "wait forever", so that basic tests don't have to worry about hitting
26 # timeouts on busy systems. Specialized tests should test those corner-cases.
27 export LTTNG_UST_REGISTER_TIMEOUT
=-1
28 export LTTNG_NETWORK_SOCKET_TIMEOUT
=-1
29 export LTTNG_APP_SOCKET_TIMEOUT
=-1
31 # We set the default lttng-sessiond path to /bin/true to prevent the spawning
32 # of a daemonized sessiond. This is necessary since 'lttng create' will spawn
33 # its own sessiond if none is running. It also ensures that 'lttng create'
34 # fails when no sessiond is running.
35 export LTTNG_SESSIOND_PATH
="/bin/true"
37 source $TESTDIR/utils
/tap
/tap.sh
39 if [ -z ${LTTNG_TEST_TEARDOWN_TIMEOUT+x} ]; then
40 LTTNG_TEST_TEARDOWN_TIMEOUT
=60
43 function full_cleanup
()
45 # Try to kill daemons gracefully
46 stop_lttng_relayd_notap SIGTERM
$LTTNG_TEST_TEARDOWN_TIMEOUT
47 stop_lttng_sessiond_notap SIGTERM
$LTTNG_TEST_TEARDOWN_TIMEOUT
49 # If daemons are still present, forcibly kill them
50 stop_lttng_relayd_notap SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
51 stop_lttng_sessiond_notap SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
52 stop_lttng_consumerd_notap SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
54 # Disable trap for SIGTERM since the following kill to the
55 # pidgroup will be SIGTERM. Otherwise it loops.
56 # The '-' before the pid number ($$) indicates 'kill' to signal the
57 # whole process group.
58 trap - SIGTERM
&& kill -- -$$
62 function null_pipes
()
69 trap full_cleanup SIGINT SIGTERM
71 # perl prove closes its child pipes before giving it a chance to run its
72 # signal trap handlers. Redirect pipes to /dev/null if SIGPIPE is caught
73 # to allow those trap handlers to proceed.
75 trap null_pipes SIGPIPE
77 # Check pgrep from env, default to pgrep if none
78 if [ -z "$PGREP" ]; then
82 # Due to the renaming of threads we need to use the full command (pgrep -f) to
83 # identify the pids for multiple lttng related processes. The problem with "pgrep
84 # -f" is that it ends up also looking at the arguments. We use a two stage
85 # lookup. The first one is using "pgrep -f" yielding potential candidate.
86 # The second on perform grep on the basename of the first field of the
87 # /proc/pid/cmdline of the previously identified pids. The first field
88 # correspond to the actual command.
89 function lttng_pgrep
()
93 local full_command_no_argument
94 local command_basename
96 possible_pids
=$
($PGREP -f "$pattern")
97 if [ -z "$possible_pids" ]; then
101 while IFS
= read -r pid
; do
102 # /proc/pid/cmdline is null separated.
103 if full_command_no_argument
=$
(cut
-d '' -f 1 < /proc
/"$pid"/cmdline
); then
104 command_basename
=$
(basename "$full_command_no_argument")
105 if grep -q "$pattern" <<< "$command_basename"; then
109 done <<< "$possible_pids"
115 # Check if we are a terminal
117 echo -e "\e[1;32mOK\e[0m"
123 function print_fail
()
125 # Check if we are a terminal
127 echo -e "\e[1;31mFAIL\e[0m"
133 function print_test_banner
()
139 function validate_kernel_version
()
141 local kern_version
=($
(uname
-r |
awk -F.
'{ printf("%d.%d.%d\n",$1,$2,$3); }' |
tr '.' '\n'))
142 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
145 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
148 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
154 # Generate a random string
155 # $1 = number of characters; defaults to 16
156 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
157 function randstring
()
159 [ "$2" == "0" ] && CHAR
="[:alnum:]" || CHAR
="[:graph:]"
160 cat /dev
/urandom
2>/dev
/null |
tr -cd "$CHAR" 2>/dev
/null |
head -c ${1:-16} 2>/dev
/null
164 # Return the number of _configured_ CPUs.
165 function conf_proc_count
()
167 getconf _NPROCESSORS_CONF
168 if [ $?
-ne 0 ]; then
169 diag
"Failed to get the number of configured CPUs"
174 # Check if base lttng-modules are present.
175 # Bail out on failure
176 function validate_lttng_modules_present
()
178 # Check for loadable modules.
179 modprobe
-n lttng-tracer
2>/dev
/null
180 if [ $?
-eq 0 ]; then
184 # Check for builtin modules.
185 ls /proc
/lttng
> /dev
/null
2>&1
186 if [ $?
-eq 0 ]; then
190 BAIL_OUT
"LTTng modules not detected."
193 function enable_kernel_lttng_event
196 local expected_to_fail
="$2"
198 local event_name
="$4"
199 local channel_name
="$5"
201 if [ -z "$event_name" ]; then
202 # Enable all event if no event name specified
206 if [ -z "$channel_name" ]; then
207 # default channel if none specified
210 chan
="-c $channel_name"
213 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
215 if [[ $expected_to_fail -eq "1" ]]; then
218 if [ $withtap -eq "1" ]; then
219 ok
$ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
222 if [ $withtap -eq "1" ]; then
223 ok
$ret "Enable kernel event $event_name for session $sess_name"
228 function enable_kernel_lttng_event_ok
()
230 enable_kernel_lttng_event
1 0 "$@"
233 function enable_kernel_lttng_event_fail
()
235 enable_kernel_lttng_event
1 1 "$@"
238 function enable_kernel_lttng_event_notap
()
240 enable_kernel_lttng_event
0 0 "$@"
244 function lttng_enable_kernel_event
246 enable_kernel_lttng_event_ok
"$@"
249 function lttng_enable_kernel_syscall
()
251 local expected_to_fail
=$1
253 local syscall_name
=$3
254 local channel_name
=$4
256 if [ -z $syscall_name ]; then
257 # Enable all event if no syscall name specified
261 if [ -z $channel_name ]; then
262 # default channel if none specified
265 chan
="-c $channel_name"
268 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
270 if [[ $expected_to_fail -eq "1" ]]; then
272 ok $?
"Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
274 ok
$ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
278 function lttng_enable_kernel_syscall_ok
()
280 lttng_enable_kernel_syscall
0 "$@"
283 function lttng_enable_kernel_syscall_fail
()
285 lttng_enable_kernel_syscall
1 "$@"
288 function lttng_disable_kernel_syscall
()
290 local expected_to_fail
=$1
292 local syscall_name
=$3
293 local channel_name
=$4
295 if [ -z $syscall_name ]; then
296 # Enable all event if no syscall name specified
300 if [ -z $channel_name ]; then
301 # default channel if none specified
304 chan
="-c $channel_name"
307 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
310 if [[ $expected_to_fail -eq "1" ]]; then
312 ok $?
"Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
314 ok
$ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
318 function lttng_disable_kernel_syscall_ok
()
320 lttng_disable_kernel_syscall
0 "$@"
323 function lttng_disable_kernel_syscall_fail
()
325 lttng_disable_kernel_syscall
1 "$@"
328 function lttng_enable_kernel_userspace_probe_event
()
330 local expected_to_fail
="$1"
333 local event_name
="$4"
335 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
--kernel --userspace-probe="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
337 if [[ $expected_to_fail -eq "1" ]]; then
339 ok $?
"Enable kernel userspace probe event for session $sess_name failed as expected"
341 ok
$ret "Enable kernel userspace probe event for session $sess_name"
345 function lttng_enable_kernel_userspace_probe_event_fail
()
347 lttng_enable_kernel_userspace_probe_event
1 "$@"
350 function lttng_enable_kernel_userspace_probe_event_ok
()
352 lttng_enable_kernel_userspace_probe_event
0 "$@"
355 function disable_kernel_lttng_userspace_probe_event_ok
()
358 local event_name
="$2"
360 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" disable-event
--kernel "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
361 ok $?
"Disable kernel event $target for session $sess_name"
363 function lttng_enable_kernel_channel
()
366 local expected_to_fail
=$2
368 local channel_name
=$4
371 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-k $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
373 if [[ $expected_to_fail -eq "1" ]]; then
376 if [ $withtap -eq "1" ]; then
377 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
380 if [ $withtap -eq "1" ]; then
381 ok
$ret "Enable channel $channel_name for session $sess_name"
386 function lttng_enable_kernel_channel_ok
()
388 lttng_enable_kernel_channel
1 0 "$@"
391 function lttng_enable_kernel_channel_fail
()
393 lttng_enable_kernel_channel
1 1 "$@"
396 function lttng_enable_kernel_channel_notap
()
398 lttng_enable_kernel_channel
0 0 "$@"
401 function enable_kernel_lttng_channel_ok
()
403 lttng_enable_kernel_channel
1 0 "$@"
406 function lttng_disable_kernel_channel
()
408 local expected_to_fail
=$1
410 local channel_name
=$3
412 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
414 if [[ $expected_to_fail -eq "1" ]]; then
416 ok $?
"Disable channel $channel_name for session $sess_name failed as expected"
418 ok
$ret "Disable channel $channel_name for session $sess_name"
422 function lttng_disable_kernel_channel_ok
()
424 lttng_disable_kernel_channel
0 "$@"
427 function lttng_disable_kernel_channel_fail
()
429 lttng_disable_kernel_channel
1 "$@"
432 function start_lttng_relayd_opt
()
435 local process_mode
=$2
438 DIR
=$
(readlink
-f "$TESTDIR")
440 if [ -z $
(lttng_pgrep
"$RELAYD_MATCH") ]; then
441 # shellcheck disable=SC2086
442 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
443 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
444 if [ $?
-eq 1 ]; then
445 if [ $withtap -eq "1" ]; then
446 fail
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
450 if [ $withtap -eq "1" ]; then
451 pass
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
455 pass
"Start lttng-relayd (opt: $opt)"
459 function start_lttng_relayd
()
461 start_lttng_relayd_opt
1 "-b" "$@"
464 function start_lttng_relayd_notap
()
466 start_lttng_relayd_opt
0 "-b" "$@"
469 function stop_lttng_relayd_opt
()
474 if [ -z "$signal" ]; then
481 # Multiply time by 2 to simplify integer arithmetic
482 if [ -n "$timeout_s" ]; then
483 dtimeleft_s
=$
((timeout_s
* 2))
489 pids
=$
(lttng_pgrep
"$RELAYD_MATCH")
490 if [ -z "$pids" ]; then
491 if [ "$withtap" -eq "1" ]; then
492 pass
"No relay daemon to kill"
497 diag
"Killing (signal $signal) lttng-relayd (pid: $pids)"
499 # shellcheck disable=SC2086
500 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
502 if [ "$withtap" -eq "1" ]; then
503 fail
"Kill relay daemon"
507 while [ -n "$out" ]; do
508 out
=$
(lttng_pgrep
"$RELAYD_MATCH")
509 if [ -n "$dtimeleft_s" ]; then
510 if [ $dtimeleft_s -lt 0 ]; then
514 dtimeleft_s
=$
((dtimeleft_s
- 1))
518 if [ "$withtap" -eq "1" ]; then
519 if [ "$retval" -eq "0" ]; then
520 pass
"Wait after kill relay daemon"
522 fail
"Wait after kill relay daemon"
529 function stop_lttng_relayd
()
531 stop_lttng_relayd_opt
1 "$@"
534 function stop_lttng_relayd_notap
()
536 stop_lttng_relayd_opt
0 "$@"
539 #First arg: show tap output
540 #Second argument: load path for automatic loading
541 function start_lttng_sessiond_opt
()
549 local long_bit_value
=
550 long_bit_value
=$
(getconf LONG_BIT
)
552 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
553 # Env variable requested no session daemon
557 DIR
=$
(readlink
-f "$TESTDIR")
559 # Get long_bit value for 32/64 consumerd
560 case "$long_bit_value" in
562 consumerd
="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
565 consumerd
="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
572 # Check for env. variable. Allow the use of LD_PRELOAD etc.
573 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
574 env_vars
="${LTTNG_SESSIOND_ENV_VARS} "
576 env_vars
="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN"
578 if ! validate_kernel_version
; then
579 fail
"Start session daemon"
580 BAIL_OUT
"*** Kernel too old for session daemon tests ***"
583 : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}"
584 export LTTNG_SESSION_CONFIG_XSD_PATH
586 if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ]; then
588 if [ -n "$load_path" ]; then
589 # shellcheck disable=SC2086
590 env
$env_vars --load "$load_path" --background "$consumerd"
592 # shellcheck disable=SC2086
593 env
$env_vars --background "$consumerd"
595 #$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
597 if [ "$withtap" -eq "1" ]; then
598 ok
$status "Start session daemon"
603 function start_lttng_sessiond
()
605 start_lttng_sessiond_opt
1 "$@"
608 function start_lttng_sessiond_notap
()
610 start_lttng_sessiond_opt
0 "$@"
613 function stop_lttng_sessiond_opt
()
618 if [ -z "$signal" ]; then
625 # Multiply time by 2 to simplify integer arithmetic
626 if [ -n "$timeout_s" ]; then
627 dtimeleft_s
=$
((timeout_s
* 2))
630 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
631 # Env variable requested no session daemon
638 runas_pids
=$
(lttng_pgrep
"$RUNAS_MATCH")
641 pids
=$
(lttng_pgrep
"$SESSIOND_MATCH")
643 if [ -n "$runas_pids" ]; then
644 pids
="$pids $runas_pids"
647 if [ -z "$pids" ]; then
648 if [ "$withtap" -eq "1" ]; then
649 pass
"No session daemon to kill"
654 diag
"Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
656 # shellcheck disable=SC2086
657 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
659 if [ "$withtap" -eq "1" ]; then
660 fail
"Kill sessions daemon"
664 while [ -n "$out" ]; do
665 out
=$
(lttng_pgrep
"${SESSIOND_MATCH}")
666 if [ -n "$dtimeleft_s" ]; then
667 if [ $dtimeleft_s -lt 0 ]; then
671 dtimeleft_s
=$
((dtimeleft_s
- 1))
676 while [ -n "$out" ]; do
677 out
=$
(lttng_pgrep
"$CONSUMERD_MATCH")
678 if [ -n "$dtimeleft_s" ]; then
679 if [ $dtimeleft_s -lt 0 ]; then
683 dtimeleft_s
=$
((dtimeleft_s
- 1))
688 if [ "$withtap" -eq "1" ]; then
689 if [ "$retval" -eq "0" ]; then
690 pass
"Wait after kill session daemon"
692 fail
"Wait after kill session daemon"
696 if [ "$signal" = "SIGKILL" ]; then
697 if [ "$(id -u)" -eq "0" ]; then
699 modules
="$(lsmod | grep ^lttng | awk '{print $1}')"
701 if [ -n "$modules" ]; then
702 diag
"Unloading all LTTng modules"
703 modprobe
-r "$modules"
711 function stop_lttng_sessiond
()
713 stop_lttng_sessiond_opt
1 "$@"
716 function stop_lttng_sessiond_notap
()
718 stop_lttng_sessiond_opt
0 "$@"
721 function sigstop_lttng_sessiond_opt
()
726 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
727 # Env variable requested no session daemon
731 PID_SESSIOND
="$(lttng_pgrep "${SESSIOND_MATCH}") $(lttng_pgrep "$RUNAS_MATCH")"
733 if [ "$withtap" -eq "1" ]; then
734 diag
"Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$PID_SESSIOND" | tr '\n' ' ')"
737 # shellcheck disable=SC2086
738 if ! kill -s $signal $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
739 if [ "$withtap" -eq "1" ]; then
740 fail
"Sending SIGSTOP to session daemon"
744 while [ $out -ne 0 ]; do
745 pid
="$(lttng_pgrep "$SESSIOND_MATCH")"
747 # Wait until state becomes stopped for session
750 for sessiond_pid
in $pid; do
751 state
="$(ps -p "$sessiond_pid" -o state= )"
752 if [[ -n "$state" && "$state" != "T" ]]; then
758 if [ "$withtap" -eq "1" ]; then
759 pass
"Sending SIGSTOP to session daemon"
764 function sigstop_lttng_sessiond
()
766 sigstop_lttng_sessiond_opt
1 "$@"
769 function sigstop_lttng_sessiond_notap
()
771 sigstop_lttng_sessiond_opt
0 "$@"
774 function stop_lttng_consumerd_opt
()
779 if [ -z "$signal" ]; then
786 # Multiply time by 2 to simplify integer arithmetic
787 if [ -n "$timeout_s" ]; then
788 dtimeleft_s
=$
((timeout_s
* 2))
793 PID_CONSUMERD
="$(lttng_pgrep "$CONSUMERD_MATCH")"
795 if [ -z "$PID_CONSUMERD" ]; then
796 if [ "$withtap" -eq "1" ]; then
797 pass
"No consumer daemon to kill"
802 diag
"Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')"
804 # shellcheck disable=SC2086
805 if ! kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
807 if [ "$withtap" -eq "1" ]; then
808 fail
"Kill consumer daemon"
812 while [ $out -ne 0 ]; do
813 pid
="$(lttng_pgrep "$CONSUMERD_MATCH")"
815 # If consumerds are still present check their status.
816 # A zombie status qualifies the consumerd as *killed*
818 for consumer_pid
in $pid; do
819 state
="$(ps -p "$consumer_pid" -o state= )"
820 if [[ -n "$state" && "$state" != "Z" ]]; then
824 if [ -n "$dtimeleft_s" ]; then
825 if [ $dtimeleft_s -lt 0 ]; then
829 dtimeleft_s
=$
((dtimeleft_s
- 1))
833 if [ "$withtap" -eq "1" ]; then
834 if [ "$retval" -eq "0" ]; then
835 pass
"Wait after kill consumer daemon"
837 fail
"Wait after kill consumer daemon"
845 function stop_lttng_consumerd
()
847 stop_lttng_consumerd_opt
1 "$@"
850 function stop_lttng_consumerd_notap
()
852 stop_lttng_consumerd_opt
0 "$@"
855 function sigstop_lttng_consumerd_opt
()
860 PID_CONSUMERD
="$(lttng_pgrep "$CONSUMERD_MATCH")"
862 diag
"Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')"
864 # shellcheck disable=SC2086
865 kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
868 if [ $retval -eq 1 ]; then
869 if [ "$withtap" -eq "1" ]; then
870 fail
"Sending SIGSTOP to consumer daemon"
875 while [ $out -ne 0 ]; do
876 pid
="$(lttng_pgrep "$CONSUMERD_MATCH")"
878 # Wait until state becomes stopped for all
881 for consumer_pid
in $pid; do
882 state
="$(ps -p "$consumer_pid" -o state= )"
883 if [[ -n "$state" && "$state" != "T" ]]; then
889 if [ "$withtap" -eq "1" ]; then
890 pass
"Sending SIGSTOP to consumer daemon"
896 function sigstop_lttng_consumerd
()
898 sigstop_lttng_consumerd_opt
1 "$@"
901 function sigstop_lttng_consumerd_notap
()
903 sigstop_lttng_consumerd_opt
0 "$@"
906 function list_lttng_with_opts
()
909 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN list
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
910 ok $?
"Lttng-tool list command with option $opts"
913 function create_lttng_session_no_output
()
918 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name --no-output $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
919 ok $?
"Create session $sess_name in no-output mode"
922 function create_lttng_session_uri
() {
927 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -U $uri $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
928 ok $?
"Create session $sess_name with uri:$uri and opts: $opts"
931 function create_lttng_session
()
934 local expected_to_fail
=$2
939 if [ -z "$trace_path" ]; then
940 # Use lttng-sessiond default output.
943 trace_path
="-o $trace_path"
946 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
"$sess_name" $trace_path $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
948 if [ $expected_to_fail -eq "1" ]; then
951 if [ $withtap -eq "1" ]; then
952 ok
$ret "Create session $sess_name in $trace_path failed as expected"
955 if [ $withtap -eq "1" ]; then
956 ok
$ret "Create session $sess_name in $trace_path"
962 function create_lttng_session_ok
()
964 create_lttng_session
1 0 "$@"
967 function create_lttng_session_fail
()
969 create_lttng_session
1 1 "$@"
972 function create_lttng_session_notap
()
974 create_lttng_session
0 0 "$@"
978 function enable_ust_lttng_channel
()
981 local expected_to_fail
=$2
983 local channel_name
=$4
986 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-u $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
988 if [[ $expected_to_fail -eq "1" ]]; then
991 if [ $withtap -eq "1" ]; then
992 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
995 if [ $withtap -eq "1" ]; then
996 ok
$ret "Enable channel $channel_name for session $sess_name"
1002 function enable_ust_lttng_channel_ok
()
1004 enable_ust_lttng_channel
1 0 "$@"
1007 function enable_ust_lttng_channel_fail
()
1009 enable_ust_lttng_channel
1 1 "$@"
1012 function enable_ust_lttng_channel_notap
()
1014 enable_ust_lttng_channel
0 0 "$@"
1017 function disable_ust_lttng_channel
()
1020 local channel_name
=$2
1022 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1023 ok $?
"Disable channel $channel_name for session $sess_name"
1026 function enable_lttng_mmap_overwrite_kernel_channel
()
1029 local channel_name
=$2
1031 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1032 ok $?
"Enable channel $channel_name for session $sess_name"
1035 function enable_lttng_mmap_discard_small_kernel_channel
()
1038 local channel_name
=$2
1040 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--discard --subbuf-size=$
(getconf PAGE_SIZE
) --num-subbuf=2 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1041 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1044 function enable_lttng_mmap_overwrite_small_kernel_channel
()
1047 local channel_name
=$2
1049 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite --subbuf-size=$
(getconf PAGE_SIZE
) --num-subbuf=2 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1050 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1053 function enable_lttng_mmap_overwrite_ust_channel
()
1056 local channel_name
=$2
1058 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1059 ok $?
"Enable channel $channel_name for session $sess_name"
1062 function enable_ust_lttng_event
()
1065 local expected_to_fail
=$2
1067 local event_name
="$4"
1068 local channel_name
=$5
1070 if [ -z $channel_name ]; then
1071 # default channel if none specified
1074 chan
="-c $channel_name"
1077 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1079 if [[ $expected_to_fail -eq "1" ]]; then
1082 if [[ $withtap -eq "1" ]]; then
1083 ok
$ret "Enable ust event $event_name for session $session_name failed as expected"
1086 if [[ $withtap -eq "1" ]]; then
1087 ok
$ret "Enable ust event $event_name for session $sess_name"
1093 function enable_ust_lttng_event_ok
()
1095 enable_ust_lttng_event
1 0 "$@"
1098 function enable_ust_lttng_event_fail
()
1100 enable_ust_lttng_event
1 1 "$@"
1103 function enable_ust_lttng_event_notap
()
1105 enable_ust_lttng_event
0 0 "$@"
1108 function enable_jul_lttng_event
()
1114 if [ -z $channel_name ]; then
1115 # default channel if none specified
1118 chan
="-c $channel_name"
1121 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1122 ok $?
"Enable JUL event $event_name for session $sess_name"
1125 function enable_jul_lttng_event_loglevel
()
1128 local event_name
="$2"
1130 local channel_name
=$4
1132 if [ -z $channel_name ]; then
1133 # default channel if none specified
1136 chan
="-c $channel_name"
1139 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1140 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
1143 function enable_log4j_lttng_event
()
1149 if [ -z $channel_name ]; then
1150 # default channel if none specified
1153 chan
="-c $channel_name"
1156 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1157 ok $?
"Enable LOG4J event $event_name for session $sess_name"
1160 function enable_log4j_lttng_event_loglevel
()
1163 local event_name
="$2"
1165 local channel_name
=$4
1167 if [ -z $channel_name ]; then
1168 # default channel if none specified
1171 chan
="-c $channel_name"
1174 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1175 ok $?
"Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
1178 function enable_python_lttng_event
()
1184 if [ -z $channel_name ]; then
1185 # default channel if none specified
1188 chan
="-c $channel_name"
1191 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1192 ok $?
"Enable Python event $event_name for session $sess_name"
1195 function enable_python_lttng_event_loglevel
()
1198 local event_name
="$2"
1200 local channel_name
=$4
1202 if [ -z $channel_name ]; then
1203 # default channel if none specified
1206 chan
="-c $channel_name"
1209 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1210 ok $?
"Enable Python event $event_name for session $sess_name with loglevel $loglevel"
1213 function enable_ust_lttng_event_filter
()
1215 local sess_name
="$1"
1216 local event_name
="$2"
1219 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1220 ok $?
"Enable event $event_name with filtering for session $sess_name"
1223 function enable_ust_lttng_event_loglevel
()
1225 local sess_name
="$1"
1226 local event_name
="$2"
1229 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1230 ok $?
"Enable event $event_name with loglevel $loglevel"
1233 function enable_ust_lttng_event_loglevel_only
()
1235 local sess_name
="$1"
1236 local event_name
="$2"
1239 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1240 ok $?
"Enable event $event_name with loglevel-only $loglevel"
1243 function disable_ust_lttng_event
()
1245 local sess_name
="$1"
1246 local event_name
="$2"
1247 local channel_name
="$3"
1249 if [ -z $channel_name ]; then
1250 # default channel if none specified
1253 chan
="-c $channel_name"
1256 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1257 ok $?
"Disable event $event_name for session $sess_name"
1260 function disable_jul_lttng_event
()
1262 local sess_name
="$1"
1263 local event_name
="$2"
1265 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
1266 ok $?
"Disable JUL event $event_name for session $sess_name"
1269 function disable_log4j_lttng_event
()
1271 local sess_name
="$1"
1272 local event_name
="$2"
1274 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -l >/dev
/null
2>&1
1275 ok $?
"Disable LOG4J event $event_name for session $sess_name"
1278 function disable_python_lttng_event
()
1280 local sess_name
="$1"
1281 local event_name
="$2"
1283 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1284 ok $?
"Disable Python event $event_name for session $sess_name"
1287 function start_lttng_tracing_opt
()
1290 local expected_to_fail
=$2
1293 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1295 if [[ $expected_to_fail -eq "1" ]]; then
1298 if [ $withtap -eq "1" ]; then
1299 ok $?
"Start tracing for session $sess_name failed as expected"
1302 if [ $withtap -eq "1" ]; then
1303 ok
$ret "Start tracing for session $sess_name"
1308 function start_lttng_tracing_ok
()
1310 start_lttng_tracing_opt
1 0 "$@"
1313 function start_lttng_tracing_fail
()
1315 start_lttng_tracing_opt
1 1 "$@"
1318 function start_lttng_tracing_notap
()
1320 start_lttng_tracing_opt
0 1 "$@"
1323 function stop_lttng_tracing_opt
()
1326 local expected_to_fail
=$2
1329 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1331 if [[ $expected_to_fail -eq "1" ]]; then
1334 if [ $withtap -eq "1" ]; then
1335 ok $?
"Stop lttng tracing for session $sess_name failed as expected"
1338 if [ $withtap -eq "1" ]; then
1339 ok
$ret "Stop lttng tracing for session $sess_name"
1344 function stop_lttng_tracing_ok
()
1346 stop_lttng_tracing_opt
1 0 "$@"
1349 function stop_lttng_tracing_fail
()
1351 stop_lttng_tracing_opt
1 1 "$@"
1354 function stop_lttng_tracing_notap
()
1356 stop_lttng_tracing_opt
0 0 "$@"
1359 function destroy_lttng_session
()
1362 local expected_to_fail
=$2
1365 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1367 if [[ $expected_to_fail -eq "1" ]]; then
1370 if [ $withtap -eq "1" ]; then
1371 ok
$ret "Destroy session $sess_name failed as expected"
1374 if [ $withtap -eq "1" ]; then
1375 ok
$ret "Destroy session $sess_name"
1380 function destroy_lttng_session_ok
()
1382 destroy_lttng_session
1 0 "$@"
1386 function destroy_lttng_session_fail
()
1388 destroy_lttng_session
1 1 "$@"
1391 function destroy_lttng_session_notap
()
1393 destroy_lttng_session
0 0 "$@"
1396 function destroy_lttng_sessions
()
1398 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
--all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1399 ok $?
"Destroy all lttng sessions"
1402 function lttng_snapshot_add_output
()
1404 local expected_to_fail
=$1
1409 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name $trace_path $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1411 if [[ $expected_to_fail -eq 1 ]]; then
1413 ok $?
"Added snapshot output $trace_path failed as expected"
1415 ok
$ret "Added snapshot output $trace_path"
1419 function lttng_snapshot_add_output_ok
()
1421 lttng_snapshot_add_output
0 "$@"
1424 function lttng_snapshot_add_output_fail
()
1426 lttng_snapshot_add_output
1 "$@"
1429 function lttng_snapshot_del_output
()
1431 local expected_to_fail
=$1
1435 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output
-s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1437 if [[ $expected_to_fail -eq "1" ]]; then
1439 ok $?
"Deleted snapshot output id $id failed as expected"
1441 ok
$ret "Deleted snapshot output id $id"
1445 function lttng_snapshot_del_output_ok
()
1447 lttng_snapshot_del_output
0 "$@"
1450 function lttng_snapshot_del_output_fail
()
1452 lttng_snapshot_del_output
1 "$@"
1455 function lttng_snapshot_record
()
1459 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot record
-s $sess_name $trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1460 ok $?
"Snapshot recorded"
1463 function lttng_snapshot_list
()
1466 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1467 ok $?
"Snapshot list"
1470 function lttng_save
()
1475 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN save
$sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1476 ok $?
"Session saved"
1479 function lttng_load
()
1481 local expected_to_fail
=$1
1484 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN load
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1486 if [[ $expected_to_fail -eq "1" ]]; then
1488 ok $?
"Load command failed as expected with opts: $opts"
1490 ok
$ret "Load command with opts: $opts"
1494 function lttng_load_ok
()
1499 function lttng_load_fail
()
1504 function lttng_track
()
1506 local expected_to_fail
="$1"
1509 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN track
$opts >$OUTPUT_DEST
1511 if [[ $expected_to_fail -eq "1" ]]; then
1513 ok $?
"Track command failed as expected with opts: $opts"
1515 ok
$ret "Track command with opts: $opts"
1519 function lttng_track_ok
()
1524 function lttng_track_fail
()
1529 function lttng_untrack
()
1531 local expected_to_fail
="$1"
1534 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN untrack
$opts >$OUTPUT_DEST
1536 if [[ $expected_to_fail -eq "1" ]]; then
1538 ok $?
"Untrack command failed as expected with opts: $opts"
1540 ok
$ret "Untrack command with opts: $opts"
1544 function lttng_untrack_ok
()
1546 lttng_untrack
0 "$@"
1549 function lttng_untrack_fail
()
1551 lttng_untrack
1 "$@"
1554 function lttng_track_pid_ok
()
1557 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track
--kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1558 ok $?
"Lttng track pid on the kernel domain"
1561 function lttng_untrack_kernel_all_ok
()
1563 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack
--kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1564 ok $?
"Lttng untrack all pid on the kernel domain"
1567 function lttng_track_ust_ok
()
1569 lttng_track_ok
-u "$@"
1572 function lttng_track_ust_fail
()
1574 lttng_track_fail
-u "$@"
1577 function lttng_track_kernel_ok
()
1579 lttng_track_ok
-k "$@"
1582 function lttng_track_kernel_fail
()
1584 lttng_track_fail
-k "$@"
1587 function lttng_untrack_ust_ok
()
1589 lttng_untrack_ok
-u "$@"
1592 function lttng_untrack_ust_fail
()
1594 lttng_untrack_fail
-u "$@"
1597 function lttng_untrack_kernel_ok
()
1599 lttng_untrack_ok
-k "$@"
1602 function lttng_untrack_kernel_fail
()
1604 lttng_untrack_fail
-k "$@"
1607 function lttng_add_context_list
()
1609 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context
--list 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1611 ok
$ret "Context listing"
1614 function add_context_lttng
()
1616 local expected_to_fail
="$1"
1618 local session_name
="$3"
1619 local channel_name
="$4"
1622 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context
-s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1624 if [[ $expected_to_fail -eq "1" ]]; then
1626 ok $?
"Add context command failed as expected for type: $type"
1628 ok
$ret "Add context command for type: $type"
1632 function add_context_ust_ok
()
1634 add_context_lttng
0 -u "$@"
1637 function add_context_ust_fail
()
1639 add_context_lttng
1 -u "$@"
1642 function add_context_kernel_ok
()
1644 add_context_lttng
0 -k "$@"
1647 function add_context_kernel_fail
()
1649 add_context_lttng
1 -k "$@"
1652 function wait_live_trace_ready
()
1655 local zero_client_match
=0
1657 diag
"Waiting for live trace at url: $url"
1658 while [ $zero_client_match -eq 0 ]; do
1659 zero_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "0 client(s) connected" |
wc -l)
1662 pass
"Waiting for live trace at url: $url"
1665 function wait_live_viewer_connect
()
1668 local one_client_match
=0
1670 diag
"Waiting for live viewers on url: $url"
1671 while [ $one_client_match -eq 0 ]; do
1672 one_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "1 client(s) connected" |
wc -l)
1675 pass
"Waiting for live viewers on url: $url"
1678 function validate_metadata_event
()
1681 local nr_event_id
=$2
1684 local metadata_file
=$
(find $trace_path |
grep metadata
)
1685 local metadata_path
=$
(dirname $metadata_file)
1687 which $BABELTRACE_BIN >/dev
/null
1688 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1690 local count
=$
($BABELTRACE_BIN --output-format=ctf-metadata
$metadata_path |
grep $event_name |
wc -l)
1692 if [ "$count" -ne "$nr_event_id" ]; then
1693 fail
"Metadata match with the metadata of $count event(s) named $event_name"
1694 diag
"$count matching event id found in metadata"
1696 pass
"Metadata match with the metadata of $count event(s) named $event_name"
1701 function trace_matches
()
1707 which $BABELTRACE_BIN >/dev
/null
1708 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1710 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1712 if [ "$count" -ne "$nr_iter" ]; then
1714 diag
"$count matching events found in trace"
1720 function trace_match_only
()
1726 which $BABELTRACE_BIN >/dev
/null
1727 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1729 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1730 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1732 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1733 pass
"Trace match with $total event $event_name"
1736 diag
"$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1740 function validate_trace
1745 which $BABELTRACE_BIN >/dev
/null
1746 if [ $?
-ne 0 ]; then
1747 skip
0 "Babeltrace binary not found. Skipping trace validation"
1752 for i
in $event_name; do
1753 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1754 if [ "$traced" -ne 0 ]; then
1755 pass
"Validate trace for event $i, $traced events"
1757 fail
"Validate trace for event $i"
1758 diag
"Found $traced occurences of $i"
1766 function validate_trace_count
1770 local expected_count
=$3
1772 which $BABELTRACE_BIN >/dev
/null
1773 if [ $?
-ne 0 ]; then
1774 skip
0 "Babeltrace binary not found. Skipping trace validation"
1780 for i
in $event_name; do
1781 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1782 if [ "$traced" -ne 0 ]; then
1783 pass
"Validate trace for event $i, $traced events"
1785 fail
"Validate trace for event $i"
1786 diag
"Found $traced occurences of $i"
1788 cnt
=$
(($cnt + $traced))
1791 test $cnt -eq $expected_count
1792 ok $?
"Read a total of $cnt events, expected $expected_count"
1795 function validate_trace_count_range_incl_min_excl_max
1799 local expected_min
=$3
1800 local expected_max
=$4
1802 which $BABELTRACE_BIN >/dev
/null
1803 if [ $?
-ne 0 ]; then
1804 skip
0 "Babeltrace binary not found. Skipping trace validation"
1810 for i
in $event_name; do
1811 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1812 if [ "$traced" -ge $expected_min ]; then
1813 pass
"Validate trace for event $i, $traced events"
1815 fail
"Validate trace for event $i"
1816 diag
"Found $traced occurences of $i"
1818 cnt
=$
(($cnt + $traced))
1821 test $cnt -lt $expected_max
1822 ok $?
"Read a total of $cnt events, expected between [$expected_min, $expected_max["
1825 function trace_first_line
1829 which $BABELTRACE_BIN >/dev
/null
1830 if [ $?
-ne 0 ]; then
1831 skip
0 "Babeltrace binary not found. Skipping trace validation"
1834 $BABELTRACE_BIN $trace_path 2>/dev
/null |
head -n 1
1837 function validate_trace_exp
()
1842 which $BABELTRACE_BIN >/dev
/null
1843 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace validation"
1845 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep --extended-regexp ${event_exp} |
wc -l)
1846 if [ "$traced" -ne 0 ]; then
1847 pass
"Validate trace for expression '${event_exp}', $traced events"
1849 fail
"Validate trace for expression '${event_exp}'"
1850 diag
"Found $traced occurences of '${event_exp}'"
1856 function validate_trace_only_exp
()
1861 which $BABELTRACE_BIN >/dev
/null
1862 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1864 local count
=$
($BABELTRACE_BIN $trace_path |
grep --extended-regexp ${event_exp} |
wc -l)
1865 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1867 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1868 pass
"Trace match with $total for expression '${event_exp}'"
1871 diag
"$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1877 function validate_trace_empty
()
1881 which $BABELTRACE_BIN >/dev
/null
1882 if [ $?
-ne 0 ]; then
1883 skip
0 "Babeltrace binary not found. Skipping trace validation"
1886 events
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null
)
1888 if [ $ret -ne 0 ]; then
1889 fail
"Failed to parse trace"
1893 traced
=$
(echo -n "$events" |
wc -l)
1894 if [ "$traced" -eq 0 ]; then
1895 pass
"Validate empty trace"
1897 fail
"Validate empty trace"
1898 diag
"Found $traced events in trace"
1904 function validate_directory_empty
()
1906 local trace_path
="$1"
1908 # Do not double quote `$trace_path` below as we want wildcards to be
1910 files
="$(ls -A $trace_path)"
1912 if [ $ret -ne 0 ]; then
1913 fail
"Failed to list content of directory \"$trace_path\""
1917 nb_files
="$(echo -n "$files" | wc -l)"
1918 ok
$nb_files "Directory \"$trace_path\" is empty"
1921 function validate_trace_session_ust_empty
()
1923 validate_directory_empty
"$1"/ust
1926 function validate_trace_session_kernel_empty
()
1928 validate_trace_empty
"$1"/kernel
1931 function regenerate_metadata
()
1933 local expected_to_fail
=$1
1936 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN regenerate metadata
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1938 if [[ $expected_to_fail -eq "1" ]]; then
1940 ok $?
"Expected fail on regenerate metadata $sess_name"
1942 ok
$ret "Metadata regenerate $sess_name"
1946 function regenerate_metadata_ok
()
1948 regenerate_metadata
0 "$@"
1951 function regenerate_metadata_fail
()
1953 regenerate_metadata
1 "$@"
1956 function regenerate_statedump
()
1958 local expected_to_fail
=$1
1961 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN regenerate statedump
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1963 if [[ $expected_to_fail -eq "1" ]]; then
1965 ok $?
"Expected fail on regenerate statedump $sess_name"
1967 ok
$ret "Statedump regenerate $sess_name"
1971 function regenerate_statedump_ok
()
1973 regenerate_statedump
0 "$@"
1976 function regenerate_statedump_fail
()
1978 regenerate_statedump
1 "$@"
1981 function rotate_session
()
1983 local expected_to_fail
=$1
1986 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN rotate
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1988 if [[ $expected_to_fail -eq "1" ]]; then
1990 ok $?
"Expected fail on rotate session $sess_name"
1992 ok
$ret "Rotate session $sess_name"
1996 function rotate_session_ok
()
1998 rotate_session
0 "$@"
2001 function rotate_session_fail
()
2003 rotate_session
1 "$@"
2006 function destructive_tests_enabled
()
2008 if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then
2015 function lttng_enable_rotation_timer
()
2017 local expected_to_fail
=$1
2021 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-rotation
-s $sess_name --timer $period 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2023 if [[ $expected_to_fail -eq "1" ]]; then
2025 ok $?
"Expected fail when setting periodic rotation ($period) of session $sess_name"
2027 ok
$ret "Set periodic rotation ($period) of session $sess_name"
2031 function lttng_enable_rotation_timer_ok
()
2033 lttng_enable_rotation_timer
0 $@
2036 function lttng_enable_rotation_timer_fail
()
2038 lttng_enable_rotation_timer
1 $@
2041 function lttng_enable_rotation_size
()
2043 local expected_to_fail
=$1
2047 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-rotation
-s $sess_name --size $size 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2049 if [[ $expected_to_fail -eq "1" ]]; then
2051 ok $?
"Expected fail on rotate session $sess_name"
2053 ok
$ret "Rotate session $sess_name"
2057 function lttng_enable_rotation_size_ok
()
2059 lttng_enable_rotation_size
0 $@
2062 function lttng_enable_rotation_size_fail
()
2064 lttng_enable_rotation_size
1 $@
2067 function lttng_clear_session
()
2069 local expected_to_fail
=$1
2072 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN clear $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2074 if [[ $expected_to_fail -eq "1" ]]; then
2076 ok $?
"Expected fail on clear session $sess_name"
2078 ok
$ret "Clear session $sess_name"
2082 function lttng_clear_session_ok
()
2084 lttng_clear_session
0 $@
2087 function lttng_clear_session_fail
()
2089 lttng_clear_session
1 $@
2092 function lttng_clear_all
()
2094 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN clear --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2095 ok $?
"Clear all lttng sessions"