1 # Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
3 # This library is free software; you can redistribute it and/or modify it under
4 # the terms of the GNU Lesser General Public License as published by the Free
5 # Software Foundation; version 2.1 of the License.
7 # This library is distributed in the hope that it will be useful, but WITHOUT
8 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 # You should have received a copy of the GNU Lesser General Public License
13 # along with this library; if not, write to the Free Software Foundation, Inc.,
14 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 SESSIOND_BIN
="lttng-sessiond"
17 SESSIOND_MATCH
=".*lttng-sess.*"
18 RUNAS_BIN
="lttng-runas"
19 RUNAS_MATCH
=".*lttng-runas.*"
20 CONSUMERD_BIN
="lttng-consumerd"
21 CONSUMERD_MATCH
=".*lttng-consumerd.*"
22 RELAYD_BIN
="lttng-relayd"
23 RELAYD_MATCH
=".*lttng-relayd.*"
25 BABELTRACE_BIN
="babeltrace"
27 ERROR_OUTPUT_DEST
=/dev
/null
29 # Minimal kernel version supported for session daemon tests
30 KERNEL_MAJOR_VERSION
=2
31 KERNEL_MINOR_VERSION
=6
32 KERNEL_PATCHLEVEL_VERSION
=27
34 # We set the default UST register timeout and network and app socket timeout to
35 # "wait forever", so that basic tests don't have to worry about hitting
36 # timeouts on busy systems. Specialized tests should test those corner-cases.
37 export LTTNG_UST_REGISTER_TIMEOUT
=-1
38 export LTTNG_NETWORK_SOCKET_TIMEOUT
=-1
39 export LTTNG_APP_SOCKET_TIMEOUT
=-1
41 # We set the default lttng-sessiond path to /bin/true to prevent the spawning
42 # of a daemonized sessiond. This is necessary since 'lttng create' will spawn
43 # its own sessiond if none is running. It also ensures that 'lttng create'
44 # fails when no sessiond is running.
45 export LTTNG_SESSIOND_PATH
="/bin/true"
47 source $TESTDIR/utils
/tap
/tap.sh
49 if [ -z $LTTNG_TEST_TEARDOWN_TIMEOUT ]; then
50 LTTNG_TEST_TEARDOWN_TIMEOUT
=60
53 function full_cleanup
()
55 # Try to kill daemons gracefully
56 stop_lttng_relayd_notap SIGTERM
$LTTNG_TEST_TEARDOWN_TIMEOUT
57 stop_lttng_sessiond_notap SIGTERM
$LTTNG_TEST_TEARDOWN_TIMEOUT
59 # If daemons are still present, forcibly kill them
60 stop_lttng_relayd_notap SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
61 stop_lttng_sessiond_notap SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
62 stop_lttng_consumerd_notap SIGKILL
$LTTNG_TEST_TEARDOWN_TIMEOUT
64 # Disable trap for SIGTERM since the following kill to the
65 # pidgroup will be SIGTERM. Otherwise it loops.
66 # The '-' before the pid number ($$) indicates 'kill' to signal the
67 # whole process group.
68 trap - SIGTERM
&& kill -- -$$
72 function null_pipes
()
79 trap full_cleanup SIGINT SIGTERM
81 # perl prove closes its child pipes before giving it a chance to run its
82 # signal trap handlers. Redirect pipes to /dev/null if SIGPIPE is caught
83 # to allow those trap handlers to proceed.
85 trap null_pipes SIGPIPE
89 # Check if we are a terminal
91 echo -e "\e[1;32mOK\e[0m"
97 function print_fail
()
99 # Check if we are a terminal
101 echo -e "\e[1;31mFAIL\e[0m"
107 function print_test_banner
()
113 function validate_kernel_version
()
115 local kern_version
=($
(uname
-r |
awk -F.
'{ printf("%d.%d.%d\n",$1,$2,$3); }' |
tr '.' '\n'))
116 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
119 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
122 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
128 # Generate a random string
129 # $1 = number of characters; defaults to 16
130 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
131 function randstring
()
133 [ "$2" == "0" ] && CHAR
="[:alnum:]" || CHAR
="[:graph:]"
134 cat /dev
/urandom
2>/dev
/null |
tr -cd "$CHAR" 2>/dev
/null |
head -c ${1:-16} 2>/dev
/null
138 # Return the number of _configured_ CPUs.
139 function conf_proc_count
()
141 getconf _NPROCESSORS_CONF
142 if [ $?
-ne 0 ]; then
143 diag
"Failed to get the number of configured CPUs"
148 # Check if base lttng-modules are present.
149 # Bail out on failure
150 function validate_lttng_modules_present
()
152 modprobe
-n lttng-tracer
2>/dev
/null
153 if [ $?
-ne 0 ]; then
154 BAIL_OUT
"LTTng modules not detected."
158 function enable_kernel_lttng_event
161 local expected_to_fail
="$2"
163 local event_name
="$4"
164 local channel_name
="$5"
166 if [ -z "$event_name" ]; then
167 # Enable all event if no event name specified
171 if [ -z "$channel_name" ]; then
172 # default channel if none specified
175 chan
="-c $channel_name"
178 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
180 if [[ $expected_to_fail -eq "1" ]]; then
183 if [ $withtap -eq "1" ]; then
184 ok
$ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
187 if [ $withtap -eq "1" ]; then
188 ok
$ret "Enable kernel event $event_name for session $sess_name"
193 function enable_kernel_lttng_event_ok
()
195 enable_kernel_lttng_event
1 0 "$@"
198 function enable_kernel_lttng_event_fail
()
200 enable_kernel_lttng_event
1 1 "$@"
203 function enable_kernel_lttng_event_notap
()
205 enable_kernel_lttng_event
0 0 "$@"
209 function lttng_enable_kernel_event
211 enable_kernel_lttng_event_ok
"$@"
214 function lttng_enable_kernel_syscall
()
216 local expected_to_fail
=$1
218 local syscall_name
=$3
219 local channel_name
=$4
221 if [ -z $syscall_name ]; then
222 # Enable all event if no syscall name specified
226 if [ -z $channel_name ]; then
227 # default channel if none specified
230 chan
="-c $channel_name"
233 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
235 if [[ $expected_to_fail -eq "1" ]]; then
237 ok $?
"Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
239 ok
$ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
243 function lttng_enable_kernel_syscall_ok
()
245 lttng_enable_kernel_syscall
0 "$@"
248 function lttng_enable_kernel_syscall_fail
()
250 lttng_enable_kernel_syscall
1 "$@"
253 function lttng_disable_kernel_syscall
()
255 local expected_to_fail
=$1
257 local syscall_name
=$3
258 local channel_name
=$4
260 if [ -z $syscall_name ]; then
261 # Enable all event if no syscall name specified
265 if [ -z $channel_name ]; then
266 # default channel if none specified
269 chan
="-c $channel_name"
272 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
275 if [[ $expected_to_fail -eq "1" ]]; then
277 ok $?
"Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
279 ok
$ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
283 function lttng_disable_kernel_syscall_ok
()
285 lttng_disable_kernel_syscall
0 "$@"
288 function lttng_disable_kernel_syscall_fail
()
290 lttng_disable_kernel_syscall
1 "$@"
293 function lttng_enable_kernel_userspace_probe_event
()
295 local expected_to_fail
="$1"
298 local event_name
="$4"
300 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
--kernel --userspace-probe="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
302 if [[ $expected_to_fail -eq "1" ]]; then
304 ok $?
"Enable kernel userspace probe event for session $sess_name failed as expected"
306 ok
$ret "Enable kernel userspace probe event for session $sess_name"
310 function lttng_enable_kernel_userspace_probe_event_fail
()
312 lttng_enable_kernel_userspace_probe_event
1 "$@"
315 function lttng_enable_kernel_userspace_probe_event_ok
()
317 lttng_enable_kernel_userspace_probe_event
0 "$@"
320 function disable_kernel_lttng_userspace_probe_event_ok
()
323 local event_name
="$2"
325 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" disable-event
--kernel "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
326 ok $?
"Disable kernel event $target for session $sess_name"
328 function lttng_enable_kernel_channel
()
331 local expected_to_fail
=$2
333 local channel_name
=$4
336 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-k $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
338 if [[ $expected_to_fail -eq "1" ]]; then
341 if [ $withtap -eq "1" ]; then
342 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
345 if [ $withtap -eq "1" ]; then
346 ok
$ret "Enable channel $channel_name for session $sess_name"
351 function lttng_enable_kernel_channel_ok
()
353 lttng_enable_kernel_channel
1 0 "$@"
356 function lttng_enable_kernel_channel_fail
()
358 lttng_enable_kernel_channel
1 1 "$@"
361 function lttng_enable_kernel_channel_notap
()
363 lttng_enable_kernel_channel
0 0 "$@"
366 function enable_kernel_lttng_channel_ok
()
368 lttng_enable_kernel_channel
1 0 "$@"
371 function lttng_disable_kernel_channel
()
373 local expected_to_fail
=$1
375 local channel_name
=$3
377 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
379 if [[ $expected_to_fail -eq "1" ]]; then
381 ok $?
"Disable channel $channel_name for session $sess_name failed as expected"
383 ok
$ret "Disable channel $channel_name for session $sess_name"
387 function lttng_disable_kernel_channel_ok
()
389 lttng_disable_kernel_channel
0 "$@"
392 function lttng_disable_kernel_channel_fail
()
394 lttng_disable_kernel_channel
1 "$@"
397 function start_lttng_relayd_opt
()
400 local process_mode
=$2
403 DIR
=$
(readlink
-f "$TESTDIR")
405 if [ -z $
(pgrep
$RELAYD_MATCH) ]; then
406 # shellcheck disable=SC2086
407 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
408 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
409 if [ $?
-eq 1 ]; then
410 if [ $withtap -eq "1" ]; then
411 fail
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
415 if [ $withtap -eq "1" ]; then
416 pass
"Start lttng-relayd (process mode: $process_mode opt: $opt)"
420 pass
"Start lttng-relayd (opt: $opt)"
424 function start_lttng_relayd
()
426 start_lttng_relayd_opt
1 "-b" "$@"
429 function start_lttng_relayd_notap
()
431 start_lttng_relayd_opt
0 "-b" "$@"
434 function stop_lttng_relayd_opt
()
439 if [ -z "$signal" ]; then
446 # Multiply time by 2 to simplify integer arithmetic
447 if [ -n "$timeout_s" ]; then
448 dtimeleft_s
=$
((timeout_s
* 2))
454 pids
=$
(pgrep
"$RELAYD_MATCH")
455 if [ -z "$pids" ]; then
456 if [ "$withtap" -eq "1" ]; then
457 pass
"No relay daemon to kill"
462 diag
"Killing (signal $signal) lttng-relayd (pid: $pids)"
464 # shellcheck disable=SC2086
465 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
467 if [ "$withtap" -eq "1" ]; then
468 fail
"Kill relay daemon"
472 while [ -n "$out" ]; do
473 out
=$
(pgrep
"$RELAYD_MATCH")
474 if [ -n "$dtimeleft_s" ]; then
475 if [ $dtimeleft_s -lt 0 ]; then
479 dtimeleft_s
=$
((dtimeleft_s
- 1))
483 if [ "$withtap" -eq "1" ]; then
484 if [ "$retval" -eq "0" ]; then
485 pass
"Wait after kill relay daemon"
487 fail
"Wait after kill relay daemon"
494 function stop_lttng_relayd
()
496 stop_lttng_relayd_opt
1 "$@"
499 function stop_lttng_relayd_notap
()
501 stop_lttng_relayd_opt
0 "$@"
504 #First arg: show tap output
505 #Second argument: load path for automatic loading
506 function start_lttng_sessiond_opt
()
514 local long_bit_value
=
515 long_bit_value
=$
(getconf LONG_BIT
)
517 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
518 # Env variable requested no session daemon
522 DIR
=$
(readlink
-f "$TESTDIR")
524 # Get long_bit value for 32/64 consumerd
525 case "$long_bit_value" in
527 consumerd
="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
530 consumerd
="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
537 # Check for env. variable. Allow the use of LD_PRELOAD etc.
538 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
539 env_vars
="${LTTNG_SESSIOND_ENV_VARS} "
541 env_vars
="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN"
543 if ! validate_kernel_version
; then
544 fail
"Start session daemon"
545 BAIL_OUT
"*** Kernel too old for session daemon tests ***"
548 : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}"
549 export LTTNG_SESSION_CONFIG_XSD_PATH
551 if [ -z "$(pgrep "${SESSIOND_MATCH}")" ]; then
553 if [ -n "$load_path" ]; then
554 # shellcheck disable=SC2086
555 env
$env_vars --load "$load_path" --background "$consumerd"
557 # shellcheck disable=SC2086
558 env
$env_vars --background "$consumerd"
560 #$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
562 if [ "$withtap" -eq "1" ]; then
563 ok
$status "Start session daemon"
568 function start_lttng_sessiond
()
570 start_lttng_sessiond_opt
1 "$@"
573 function start_lttng_sessiond_notap
()
575 start_lttng_sessiond_opt
0 "$@"
578 function stop_lttng_sessiond_opt
()
583 if [ -z "$signal" ]; then
590 # Multiply time by 2 to simplify integer arithmetic
591 if [ -n "$timeout_s" ]; then
592 dtimeleft_s
=$
((timeout_s
* 2))
595 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
596 # Env variable requested no session daemon
603 runas_pids
=$
(pgrep
"$RUNAS_MATCH")
606 pids
=$
(pgrep
"$SESSIOND_MATCH")
608 if [ -n "$runas_pids" ]; then
609 pids
="$pids $runas_pids"
612 if [ -z "$pids" ]; then
613 if [ "$withtap" -eq "1" ]; then
614 pass
"No session daemon to kill"
619 diag
"Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
621 # shellcheck disable=SC2086
622 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
624 if [ "$withtap" -eq "1" ]; then
625 fail
"Kill sessions daemon"
629 while [ -n "$out" ]; do
630 out
=$
(pgrep
"${SESSIOND_MATCH}")
631 if [ -n "$dtimeleft_s" ]; then
632 if [ $dtimeleft_s -lt 0 ]; then
636 dtimeleft_s
=$
((dtimeleft_s
- 1))
641 while [ -n "$out" ]; do
642 out
=$
(pgrep
"$CONSUMERD_MATCH")
643 if [ -n "$dtimeleft_s" ]; then
644 if [ $dtimeleft_s -lt 0 ]; then
648 dtimeleft_s
=$
((dtimeleft_s
- 1))
653 if [ "$withtap" -eq "1" ]; then
654 if [ "$retval" -eq "0" ]; then
655 pass
"Wait after kill session daemon"
657 fail
"Wait after kill session daemon"
661 if [ "$signal" = "SIGKILL" ]; then
662 if [ "$(id -u)" -eq "0" ]; then
664 modules
="$(lsmod | grep ^lttng | awk '{print $1}')"
666 if [ -n "$modules" ]; then
667 diag
"Unloading all LTTng modules"
668 modprobe
-r "$modules"
676 function stop_lttng_sessiond
()
678 stop_lttng_sessiond_opt
1 "$@"
681 function stop_lttng_sessiond_notap
()
683 stop_lttng_sessiond_opt
0 "$@"
686 function sigstop_lttng_sessiond_opt
()
691 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
692 # Env variable requested no session daemon
696 PID_SESSIOND
="$(pgrep "${SESSIOND_MATCH}") $(pgrep "$RUNAS_MATCH")"
698 if [ "$withtap" -eq "1" ]; then
699 diag
"Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$PID_SESSIOND" | tr '\n' ' ')"
702 # shellcheck disable=SC2086
703 if ! kill -s $signal $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
704 if [ "$withtap" -eq "1" ]; then
705 fail
"Sending SIGSTOP to session daemon"
709 while [ $out -ne 0 ]; do
710 pid
="$(pgrep "$SESSIOND_MATCH")"
712 # Wait until state becomes stopped for session
715 for sessiond_pid
in $pid; do
716 state
="$(ps -p "$sessiond_pid" -o state= )"
717 if [[ -n "$state" && "$state" != "T" ]]; then
723 if [ "$withtap" -eq "1" ]; then
724 pass
"Sending SIGSTOP to session daemon"
729 function sigstop_lttng_sessiond
()
731 sigstop_lttng_sessiond_opt
1 "$@"
734 function sigstop_lttng_sessiond_notap
()
736 sigstop_lttng_sessiond_opt
0 "$@"
739 function stop_lttng_consumerd_opt
()
744 if [ -z "$signal" ]; then
751 # Multiply time by 2 to simplify integer arithmetic
752 if [ -n "$timeout_s" ]; then
753 dtimeleft_s
=$
((timeout_s
* 2))
758 PID_CONSUMERD
="$(pgrep "$CONSUMERD_MATCH")"
760 if [ -z "$PID_CONSUMERD" ]; then
761 if [ "$withtap" -eq "1" ]; then
762 pass
"No consumer daemon to kill"
767 diag
"Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')"
769 # shellcheck disable=SC2086
770 if ! kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
772 if [ "$withtap" -eq "1" ]; then
773 fail
"Kill consumer daemon"
777 while [ $out -ne 0 ]; do
778 pid
="$(pgrep "$CONSUMERD_MATCH")"
780 # If consumerds are still present check their status.
781 # A zombie status qualifies the consumerd as *killed*
783 for consumer_pid
in $pid; do
784 state
="$(ps -p "$consumer_pid" -o state= )"
785 if [[ -n "$state" && "$state" != "Z" ]]; then
789 if [ -n "$dtimeleft_s" ]; then
790 if [ $dtimeleft_s -lt 0 ]; then
794 dtimeleft_s
=$
((dtimeleft_s
- 1))
798 if [ "$withtap" -eq "1" ]; then
799 if [ "$retval" -eq "0" ]; then
800 pass
"Wait after kill consumer daemon"
802 fail
"Wait after kill consumer daemon"
810 function stop_lttng_consumerd
()
812 stop_lttng_consumerd_opt
1 "$@"
815 function stop_lttng_consumerd_notap
()
817 stop_lttng_consumerd_opt
0 "$@"
820 function sigstop_lttng_consumerd_opt
()
825 PID_CONSUMERD
="$(pgrep "$CONSUMERD_MATCH")"
827 diag
"Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')"
829 # shellcheck disable=SC2086
830 kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
833 if [ $retval -eq 1 ]; then
834 if [ "$withtap" -eq "1" ]; then
835 fail
"Sending SIGSTOP to consumer daemon"
840 while [ $out -ne 0 ]; do
841 pid
="$(pgrep "$CONSUMERD_MATCH")"
843 # Wait until state becomes stopped for all
846 for consumer_pid
in $pid; do
847 state
="$(ps -p "$consumer_pid" -o state= )"
848 if [[ -n "$state" && "$state" != "T" ]]; then
854 if [ "$withtap" -eq "1" ]; then
855 pass
"Sending SIGSTOP to consumer daemon"
861 function sigstop_lttng_consumerd
()
863 sigstop_lttng_consumerd_opt
1 "$@"
866 function sigstop_lttng_consumerd_notap
()
868 sigstop_lttng_consumerd_opt
0 "$@"
871 function list_lttng_with_opts
()
874 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN list
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
875 ok $?
"Lttng-tool list command with option $opts"
878 function create_lttng_session_no_output
()
883 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name --no-output $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
884 ok $?
"Create session $sess_name in no-output mode"
887 function create_lttng_session_uri
() {
892 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -U $uri $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
893 ok $?
"Create session $sess_name with uri:$uri and opts: $opts"
896 function create_lttng_session
()
899 local expected_to_fail
=$2
904 if [ -z "$trace_path" ]; then
905 # Use lttng-sessiond default output.
908 trace_path
="-o $trace_path"
911 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
"$sess_name" $trace_path $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
913 if [ $expected_to_fail -eq "1" ]; then
916 if [ $withtap -eq "1" ]; then
917 ok
$ret "Create session $sess_name in $trace_path failed as expected"
920 if [ $withtap -eq "1" ]; then
921 ok
$ret "Create session $sess_name in $trace_path"
927 function create_lttng_session_ok
()
929 create_lttng_session
1 0 "$@"
932 function create_lttng_session_fail
()
934 create_lttng_session
1 1 "$@"
937 function create_lttng_session_notap
()
939 create_lttng_session
0 0 "$@"
943 function enable_ust_lttng_channel
()
946 local expected_to_fail
=$2
948 local channel_name
=$4
951 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-u $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
953 if [[ $expected_to_fail -eq "1" ]]; then
956 if [ $withtap -eq "1" ]; then
957 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
960 if [ $withtap -eq "1" ]; then
961 ok
$ret "Enable channel $channel_name for session $sess_name"
967 function enable_ust_lttng_channel_ok
()
969 enable_ust_lttng_channel
1 0 "$@"
972 function enable_ust_lttng_channel_fail
()
974 enable_ust_lttng_channel
1 1 "$@"
977 function enable_ust_lttng_channel_notap
()
979 enable_ust_lttng_channel
0 0 "$@"
982 function disable_ust_lttng_channel
()
985 local channel_name
=$2
987 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
988 ok $?
"Disable channel $channel_name for session $sess_name"
991 function enable_lttng_mmap_overwrite_kernel_channel
()
994 local channel_name
=$2
996 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
997 ok $?
"Enable channel $channel_name for session $sess_name"
1000 function enable_lttng_mmap_discard_small_kernel_channel
()
1003 local channel_name
=$2
1005 $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
1006 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1009 function enable_lttng_mmap_overwrite_small_kernel_channel
()
1012 local channel_name
=$2
1014 $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
1015 ok $?
"Enable small discard channel $channel_name for session $sess_name"
1018 function enable_lttng_mmap_overwrite_ust_channel
()
1021 local channel_name
=$2
1023 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1024 ok $?
"Enable channel $channel_name for session $sess_name"
1027 function enable_ust_lttng_event
()
1030 local expected_to_fail
=$2
1032 local event_name
="$4"
1033 local channel_name
=$5
1035 if [ -z $channel_name ]; then
1036 # default channel if none specified
1039 chan
="-c $channel_name"
1042 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1044 if [[ $expected_to_fail -eq "1" ]]; then
1047 if [[ $withtap -eq "1" ]]; then
1048 ok
$ret "Enable ust event $event_name for session $session_name failed as expected"
1051 if [[ $withtap -eq "1" ]]; then
1052 ok
$ret "Enable ust event $event_name for session $sess_name"
1058 function enable_ust_lttng_event_ok
()
1060 enable_ust_lttng_event
1 0 "$@"
1063 function enable_ust_lttng_event_fail
()
1065 enable_ust_lttng_event
1 1 "$@"
1068 function enable_ust_lttng_event_notap
()
1070 enable_ust_lttng_event
0 0 "$@"
1073 function enable_jul_lttng_event
()
1079 if [ -z $channel_name ]; then
1080 # default channel if none specified
1083 chan
="-c $channel_name"
1086 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1087 ok $?
"Enable JUL event $event_name for session $sess_name"
1090 function enable_jul_lttng_event_loglevel
()
1093 local event_name
="$2"
1095 local channel_name
=$4
1097 if [ -z $channel_name ]; then
1098 # default channel if none specified
1101 chan
="-c $channel_name"
1104 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1105 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
1108 function enable_log4j_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 -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1122 ok $?
"Enable LOG4J event $event_name for session $sess_name"
1125 function enable_log4j_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 -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1140 ok $?
"Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
1143 function enable_python_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 -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1157 ok $?
"Enable Python event $event_name for session $sess_name"
1160 function enable_python_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 -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1175 ok $?
"Enable Python event $event_name for session $sess_name with loglevel $loglevel"
1178 function enable_ust_lttng_event_filter
()
1180 local sess_name
="$1"
1181 local event_name
="$2"
1184 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1185 ok $?
"Enable event $event_name with filtering for session $sess_name"
1188 function enable_ust_lttng_event_loglevel
()
1190 local sess_name
="$1"
1191 local event_name
="$2"
1194 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1195 ok $?
"Enable event $event_name with loglevel $loglevel"
1198 function enable_ust_lttng_event_loglevel_only
()
1200 local sess_name
="$1"
1201 local event_name
="$2"
1204 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1205 ok $?
"Enable event $event_name with loglevel-only $loglevel"
1208 function disable_ust_lttng_event
()
1210 local sess_name
="$1"
1211 local event_name
="$2"
1212 local channel_name
="$3"
1214 if [ -z $channel_name ]; then
1215 # default channel if none specified
1218 chan
="-c $channel_name"
1221 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1222 ok $?
"Disable event $event_name for session $sess_name"
1225 function disable_jul_lttng_event
()
1227 local sess_name
="$1"
1228 local event_name
="$2"
1230 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
1231 ok $?
"Disable JUL event $event_name for session $sess_name"
1234 function disable_log4j_lttng_event
()
1236 local sess_name
="$1"
1237 local event_name
="$2"
1239 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -l >/dev
/null
2>&1
1240 ok $?
"Disable LOG4J event $event_name for session $sess_name"
1243 function disable_python_lttng_event
()
1245 local sess_name
="$1"
1246 local event_name
="$2"
1248 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1249 ok $?
"Disable Python event $event_name for session $sess_name"
1252 function start_lttng_tracing_opt
()
1255 local expected_to_fail
=$2
1258 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1260 if [[ $expected_to_fail -eq "1" ]]; then
1263 if [ $withtap -eq "1" ]; then
1264 ok $?
"Start tracing for session $sess_name failed as expected"
1267 if [ $withtap -eq "1" ]; then
1268 ok
$ret "Start tracing for session $sess_name"
1273 function start_lttng_tracing_ok
()
1275 start_lttng_tracing_opt
1 0 "$@"
1278 function start_lttng_tracing_fail
()
1280 start_lttng_tracing_opt
1 1 "$@"
1283 function start_lttng_tracing_notap
()
1285 start_lttng_tracing_opt
0 1 "$@"
1288 function stop_lttng_tracing_opt
()
1291 local expected_to_fail
=$2
1294 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1296 if [[ $expected_to_fail -eq "1" ]]; then
1299 if [ $withtap -eq "1" ]; then
1300 ok $?
"Stop lttng tracing for session $sess_name failed as expected"
1303 if [ $withtap -eq "1" ]; then
1304 ok
$ret "Stop lttng tracing for session $sess_name"
1309 function stop_lttng_tracing_ok
()
1311 stop_lttng_tracing_opt
1 0 "$@"
1314 function stop_lttng_tracing_fail
()
1316 stop_lttng_tracing_opt
1 1 "$@"
1319 function stop_lttng_tracing_notap
()
1321 stop_lttng_tracing_opt
0 0 "$@"
1324 function destroy_lttng_session
()
1327 local expected_to_fail
=$2
1330 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1332 if [[ $expected_to_fail -eq "1" ]]; then
1335 if [ $withtap -eq "1" ]; then
1336 ok
$ret "Destroy session $sess_name failed as expected"
1339 if [ $withtap -eq "1" ]; then
1340 ok
$ret "Destroy session $sess_name"
1345 function destroy_lttng_session_ok
()
1347 destroy_lttng_session
1 0 "$@"
1351 function destroy_lttng_session_fail
()
1353 destroy_lttng_session
1 1 "$@"
1356 function destroy_lttng_session_notap
()
1358 destroy_lttng_session
0 0 "$@"
1361 function destroy_lttng_sessions
()
1363 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
--all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1364 ok $?
"Destroy all lttng sessions"
1367 function lttng_snapshot_add_output
()
1369 local expected_to_fail
=$1
1374 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name $trace_path $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1376 if [[ $expected_to_fail -eq 1 ]]; then
1378 ok $?
"Added snapshot output $trace_path failed as expected"
1380 ok
$ret "Added snapshot output $trace_path"
1384 function lttng_snapshot_add_output_ok
()
1386 lttng_snapshot_add_output
0 "$@"
1389 function lttng_snapshot_add_output_fail
()
1391 lttng_snapshot_add_output
1 "$@"
1394 function lttng_snapshot_del_output
()
1396 local expected_to_fail
=$1
1400 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output
-s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1402 if [[ $expected_to_fail -eq "1" ]]; then
1404 ok $?
"Deleted snapshot output id $id failed as expected"
1406 ok
$ret "Deleted snapshot output id $id"
1410 function lttng_snapshot_del_output_ok
()
1412 lttng_snapshot_del_output
0 "$@"
1415 function lttng_snapshot_del_output_fail
()
1417 lttng_snapshot_del_output
1 "$@"
1420 function lttng_snapshot_record
()
1424 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot record
-s $sess_name $trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1425 ok $?
"Snapshot recorded"
1428 function lttng_snapshot_list
()
1431 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1432 ok $?
"Snapshot list"
1435 function lttng_save
()
1440 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN save
$sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1441 ok $?
"Session saved"
1444 function lttng_load
()
1446 local expected_to_fail
=$1
1449 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN load
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1451 if [[ $expected_to_fail -eq "1" ]]; then
1453 ok $?
"Load command failed as expected with opts: $opts"
1455 ok
$ret "Load command with opts: $opts"
1459 function lttng_load_ok
()
1464 function lttng_load_fail
()
1469 function lttng_track
()
1471 local expected_to_fail
="$1"
1474 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN track
$opts >$OUTPUT_DEST
1476 if [[ $expected_to_fail -eq "1" ]]; then
1478 ok $?
"Track command failed as expected with opts: $opts"
1480 ok
$ret "Track command with opts: $opts"
1484 function lttng_track_ok
()
1489 function lttng_track_fail
()
1494 function lttng_untrack
()
1496 local expected_to_fail
="$1"
1499 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN untrack
$opts >$OUTPUT_DEST
1501 if [[ $expected_to_fail -eq "1" ]]; then
1503 ok $?
"Untrack command failed as expected with opts: $opts"
1505 ok
$ret "Untrack command with opts: $opts"
1509 function lttng_untrack_ok
()
1511 lttng_untrack
0 "$@"
1514 function lttng_untrack_fail
()
1516 lttng_untrack
1 "$@"
1519 function lttng_track_pid_ok
()
1522 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track
--kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1523 ok $?
"Lttng track pid on the kernel domain"
1526 function lttng_untrack_kernel_all_ok
()
1528 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack
--kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1529 ok $?
"Lttng untrack all pid on the kernel domain"
1532 function lttng_track_ust_ok
()
1534 lttng_track_ok
-u "$@"
1537 function lttng_track_ust_fail
()
1539 lttng_track_fail
-u "$@"
1542 function lttng_track_kernel_ok
()
1544 lttng_track_ok
-k "$@"
1547 function lttng_track_kernel_fail
()
1549 lttng_track_fail
-k "$@"
1552 function lttng_untrack_ust_ok
()
1554 lttng_untrack_ok
-u "$@"
1557 function lttng_untrack_ust_fail
()
1559 lttng_untrack_fail
-u "$@"
1562 function lttng_untrack_kernel_ok
()
1564 lttng_untrack_ok
-k "$@"
1567 function lttng_untrack_kernel_fail
()
1569 lttng_untrack_fail
-k "$@"
1572 function lttng_add_context_list
()
1574 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context
--list 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1576 ok
$ret "Context listing"
1579 function add_context_lttng
()
1581 local expected_to_fail
="$1"
1583 local session_name
="$3"
1584 local channel_name
="$4"
1587 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context
-s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1589 if [[ $expected_to_fail -eq "1" ]]; then
1591 ok $?
"Add context command failed as expected for type: $type"
1593 ok
$ret "Add context command for type: $type"
1597 function add_context_ust_ok
()
1599 add_context_lttng
0 -u "$@"
1602 function add_context_ust_fail
()
1604 add_context_lttng
1 -u "$@"
1607 function add_context_kernel_ok
()
1609 add_context_lttng
0 -k "$@"
1612 function add_context_kernel_fail
()
1614 add_context_lttng
1 -k "$@"
1617 function validate_directory_empty
()
1621 ls -A $local_path > /dev
/null
2>&1
1622 if [ $?
-eq 0 ]; then
1623 pass
"Directory empty"
1625 fail
"Directory empty"
1629 function wait_live_trace_ready
()
1632 local zero_client_match
=0
1634 diag
"Waiting for live trace at url: $url"
1635 while [ $zero_client_match -eq 0 ]; do
1636 zero_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "0 client(s) connected" |
wc -l)
1639 pass
"Waiting for live trace at url: $url"
1642 function wait_live_viewer_connect
()
1645 local one_client_match
=0
1647 diag
"Waiting for live viewers on url: $url"
1648 while [ $one_client_match -eq 0 ]; do
1649 one_client_match
=$
($BABELTRACE_BIN -i lttng-live
$url |
grep "1 client(s) connected" |
wc -l)
1652 pass
"Waiting for live viewers on url: $url"
1655 function validate_metadata_event
()
1658 local nr_event_id
=$2
1661 local metadata_file
=$
(find $trace_path |
grep metadata
)
1662 local metadata_path
=$
(dirname $metadata_file)
1664 which $BABELTRACE_BIN >/dev
/null
1665 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1667 local count
=$
($BABELTRACE_BIN --output-format=ctf-metadata
$metadata_path |
grep $event_name |
wc -l)
1669 if [ "$count" -ne "$nr_event_id" ]; then
1670 fail
"Metadata match with the metadata of $count event(s) named $event_name"
1671 diag
"$count matching event id found in metadata"
1673 pass
"Metadata match with the metadata of $count event(s) named $event_name"
1678 function trace_matches
()
1684 which $BABELTRACE_BIN >/dev
/null
1685 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1687 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1689 if [ "$count" -ne "$nr_iter" ]; then
1691 diag
"$count matching events found in trace"
1697 function trace_match_only
()
1703 which $BABELTRACE_BIN >/dev
/null
1704 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1706 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1707 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1709 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1710 pass
"Trace match with $total event $event_name"
1713 diag
"$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1717 function validate_trace
1722 which $BABELTRACE_BIN >/dev
/null
1723 if [ $?
-ne 0 ]; then
1724 skip
0 "Babeltrace binary not found. Skipping trace validation"
1729 for i
in $event_name; do
1730 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1731 if [ "$traced" -ne 0 ]; then
1732 pass
"Validate trace for event $i, $traced events"
1734 fail
"Validate trace for event $i"
1735 diag
"Found $traced occurences of $i"
1743 function validate_trace_count
1747 local expected_count
=$3
1749 which $BABELTRACE_BIN >/dev
/null
1750 if [ $?
-ne 0 ]; then
1751 skip
0 "Babeltrace binary not found. Skipping trace validation"
1757 for i
in $event_name; do
1758 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1759 if [ "$traced" -ne 0 ]; then
1760 pass
"Validate trace for event $i, $traced events"
1762 fail
"Validate trace for event $i"
1763 diag
"Found $traced occurences of $i"
1765 cnt
=$
(($cnt + $traced))
1768 test $cnt -eq $expected_count
1769 ok $?
"Read a total of $cnt events, expected $expected_count"
1772 function validate_trace_count_range_incl_min_excl_max
1776 local expected_min
=$3
1777 local expected_max
=$4
1779 which $BABELTRACE_BIN >/dev
/null
1780 if [ $?
-ne 0 ]; then
1781 skip
0 "Babeltrace binary not found. Skipping trace validation"
1787 for i
in $event_name; do
1788 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1789 if [ "$traced" -ge $expected_min ]; then
1790 pass
"Validate trace for event $i, $traced events"
1792 fail
"Validate trace for event $i"
1793 diag
"Found $traced occurences of $i"
1795 cnt
=$
(($cnt + $traced))
1798 test $cnt -lt $expected_max
1799 ok $?
"Read a total of $cnt events, expected between [$expected_min, $expected_max["
1802 function trace_first_line
1806 which $BABELTRACE_BIN >/dev
/null
1807 if [ $?
-ne 0 ]; then
1808 skip
0 "Babeltrace binary not found. Skipping trace validation"
1811 $BABELTRACE_BIN $trace_path 2>/dev
/null |
head -n 1
1814 function validate_trace_exp
()
1819 which $BABELTRACE_BIN >/dev
/null
1820 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace validation"
1822 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep --extended-regexp ${event_exp} |
wc -l)
1823 if [ "$traced" -ne 0 ]; then
1824 pass
"Validate trace for expression '${event_exp}', $traced events"
1826 fail
"Validate trace for expression '${event_exp}'"
1827 diag
"Found $traced occurences of '${event_exp}'"
1833 function validate_trace_only_exp
()
1838 which $BABELTRACE_BIN >/dev
/null
1839 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1841 local count
=$
($BABELTRACE_BIN $trace_path |
grep --extended-regexp ${event_exp} |
wc -l)
1842 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1844 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1845 pass
"Trace match with $total for expression '${event_exp}'"
1848 diag
"$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1854 function validate_trace_empty
()
1858 which $BABELTRACE_BIN >/dev
/null
1859 if [ $?
-ne 0 ]; then
1860 skip
0 "Babeltrace binary not found. Skipping trace validation"
1863 events
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null
)
1865 if [ $ret -ne 0 ]; then
1866 fail
"Failed to parse trace"
1870 traced
=$
(echo -n "$events" |
wc -l)
1871 if [ "$traced" -eq 0 ]; then
1872 pass
"Validate empty trace"
1874 fail
"Validate empty trace"
1875 diag
"Found $traced events in trace"
1881 function validate_folder_is_empty
()
1885 test -z "$(ls -A "$folder")"
1886 ok $?
"Folder ${folder} is empty"
1889 function validate_trace_session_ust_empty
()
1891 validate_folder_is_empty
"$1"/ust
1894 function validate_trace_session_kernel_empty
()
1896 validate_trace_empty
"$1"/kernel
1899 function regenerate_metadata
()
1901 local expected_to_fail
=$1
1904 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN regenerate metadata
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1906 if [[ $expected_to_fail -eq "1" ]]; then
1908 ok $?
"Expected fail on regenerate metadata $sess_name"
1910 ok
$ret "Metadata regenerate $sess_name"
1914 function regenerate_metadata_ok
()
1916 regenerate_metadata
0 "$@"
1919 function regenerate_metadata_fail
()
1921 regenerate_metadata
1 "$@"
1924 function regenerate_statedump
()
1926 local expected_to_fail
=$1
1929 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN regenerate statedump
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1931 if [[ $expected_to_fail -eq "1" ]]; then
1933 ok $?
"Expected fail on regenerate statedump $sess_name"
1935 ok
$ret "Statedump regenerate $sess_name"
1939 function regenerate_statedump_ok
()
1941 regenerate_statedump
0 "$@"
1944 function regenerate_statedump_fail
()
1946 regenerate_statedump
1 "$@"
1949 function rotate_session
()
1951 local expected_to_fail
=$1
1954 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN rotate
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1956 if [[ $expected_to_fail -eq "1" ]]; then
1958 ok $?
"Expected fail on rotate session $sess_name"
1960 ok
$ret "Rotate session $sess_name"
1964 function rotate_session_ok
()
1966 rotate_session
0 "$@"
1969 function rotate_session_fail
()
1971 rotate_session
1 "$@"
1974 function destructive_tests_enabled
()
1976 if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then
1983 function lttng_enable_rotation_timer
()
1985 local expected_to_fail
=$1
1989 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-rotation
-s $sess_name --timer $period 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1991 if [[ $expected_to_fail -eq "1" ]]; then
1993 ok $?
"Expected fail when setting periodic rotation ($period) of session $sess_name"
1995 ok
$ret "Set periodic rotation ($period) of session $sess_name"
1999 function lttng_enable_rotation_timer_ok
()
2001 lttng_enable_rotation_timer
0 $@
2004 function lttng_enable_rotation_timer_fail
()
2006 lttng_enable_rotation_timer
1 $@
2009 function lttng_enable_rotation_size
()
2011 local expected_to_fail
=$1
2015 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-rotation
-s $sess_name --size $size 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2017 if [[ $expected_to_fail -eq "1" ]]; then
2019 ok $?
"Expected fail on rotate session $sess_name"
2021 ok
$ret "Rotate session $sess_name"
2025 function lttng_enable_rotation_size_ok
()
2027 lttng_enable_rotation_size
0 $@
2030 function lttng_enable_rotation_size_fail
()
2032 lttng_enable_rotation_size
1 $@
2035 function lttng_clear_session
()
2037 local expected_to_fail
=$1
2040 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN clear $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2042 if [[ $expected_to_fail -eq "1" ]]; then
2044 ok $?
"Expected fail on clear session $sess_name"
2046 ok
$ret "Clear session $sess_name"
2050 function lttng_clear_session_ok
()
2052 lttng_clear_session
0 $@
2055 function lttng_clear_session_fail
()
2057 lttng_clear_session
1 $@
2060 function lttng_clear_all
()
2062 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN clear --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2063 ok $?
"Clear all lttng sessions"