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.*"
19 RUNAS_BIN
="lttng-runas"
20 RUNAS_MATCH
=".*lttng-runas.*"
21 CONSUMERD_BIN
="lttng-consumerd"
22 CONSUMERD_MATCH
=".*lttng-consumerd.*"
23 RELAYD_BIN
="lttng-relayd"
24 RELAYD_MATCH
=".*lttng-relayd.*"
27 BABELTRACE_BIN
="babeltrace"
29 ERROR_OUTPUT_DEST
=/dev
/null
31 # Minimal kernel version supported for session daemon tests
32 KERNEL_MAJOR_VERSION
=2
33 KERNEL_MINOR_VERSION
=6
34 KERNEL_PATCHLEVEL_VERSION
=27
36 # We set the default UST register timeout and network and app socket timeout to
37 # "wait forever", so that basic tests don't have to worry about hitting
38 # timeouts on busy systems. Specialized tests should test those corner-cases.
39 export LTTNG_UST_REGISTER_TIMEOUT
=-1
40 export LTTNG_NETWORK_SOCKET_TIMEOUT
=-1
41 export LTTNG_APP_SOCKET_TIMEOUT
=-1
43 # We set the default lttng-sessiond path to /bin/true to prevent the spawning
44 # of a daemonized sessiond. This is necessary since 'lttng create' will spawn
45 # its own sessiond if none is running. It also ensures that 'lttng create'
46 # fails when no sessiond is running.
47 export LTTNG_SESSIOND_PATH
="/bin/true"
49 source $TESTDIR/utils
/tap
/tap.sh
51 function full_cleanup
()
53 if [ -n "${SESSIOND_PIDS}" ] ||
[ -n "${RELAYD_PIDS}" ]; then
54 kill -9 ${SESSIOND_PIDS} ${RELAYD_PIDS} > /dev
/null
2>&1
57 # Disable trap for SIGTERM since the following kill to the
58 # pidgroup will be SIGTERM. Otherwise it loops.
59 # The '-' before the pid number ($$) indicates 'kill' to signal the
60 # whole process group.
61 trap - SIGTERM
&& kill -- -$$
65 trap full_cleanup SIGINT SIGTERM
69 # Check if we are a terminal
71 echo -e "\e[1;32mOK\e[0m"
77 function print_fail
()
79 # Check if we are a terminal
81 echo -e "\e[1;31mFAIL\e[0m"
87 function print_test_banner
()
93 function validate_kernel_version
()
95 local kern_version
=($
(uname
-r |
awk -F.
'{ printf("%d.%d.%d\n",$1,$2,$3); }' |
tr '.' '\n'))
96 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
99 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
102 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
108 # Generate a random string
109 # $1 = number of characters; defaults to 16
110 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
111 function randstring
()
113 [ "$2" == "0" ] && CHAR
="[:alnum:]" || CHAR
="[:graph:]"
114 cat /dev
/urandom
2>/dev
/null |
tr -cd "$CHAR" 2>/dev
/null |
head -c ${1:-16} 2>/dev
/null
118 # Return the number of _configured_ CPUs.
119 function conf_proc_count
()
121 getconf _NPROCESSORS_CONF
122 if [ $?
-ne 0 ]; then
123 diag
"Failed to get the number of configured CPUs"
128 function enable_kernel_lttng_event
131 local expected_to_fail
="$2"
133 local event_name
="$4"
134 local channel_name
="$5"
136 if [ -z "$event_name" ]; then
137 # Enable all event if no event name specified
141 if [ -z "$channel_name" ]; then
142 # default channel if none specified
145 chan
="-c $channel_name"
148 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
150 if [[ $expected_to_fail -eq "1" ]]; then
153 if [ $withtap -eq "1" ]; then
154 ok
$ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
157 if [ $withtap -eq "1" ]; then
158 ok
$ret "Enable kernel event $event_name for session $sess_name"
163 function enable_kernel_lttng_event_ok
()
165 enable_kernel_lttng_event
1 0 "$@"
168 function enable_kernel_lttng_event_fail
()
170 enable_kernel_lttng_event
1 1 "$@"
173 function enable_kernel_lttng_event_notap
()
175 enable_kernel_lttng_event
0 0 "$@"
179 function lttng_enable_kernel_event
181 enable_kernel_lttng_event_ok
"$@"
184 function lttng_enable_kernel_syscall
()
186 local expected_to_fail
=$1
188 local syscall_name
=$3
189 local channel_name
=$4
191 if [ -z $syscall_name ]; then
192 # Enable all event if no syscall name specified
196 if [ -z $channel_name ]; then
197 # default channel if none specified
200 chan
="-c $channel_name"
203 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
205 if [[ $expected_to_fail -eq "1" ]]; then
207 ok $?
"Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
209 ok
$ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
213 function lttng_enable_kernel_syscall_ok
()
215 lttng_enable_kernel_syscall
0 "$@"
218 function lttng_enable_kernel_syscall_fail
()
220 lttng_enable_kernel_syscall
1 "$@"
223 function lttng_disable_kernel_syscall
()
225 local expected_to_fail
=$1
227 local syscall_name
=$3
228 local channel_name
=$4
230 if [ -z $syscall_name ]; then
231 # Enable all event if no syscall name specified
235 if [ -z $channel_name ]; then
236 # default channel if none specified
239 chan
="-c $channel_name"
242 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
245 if [[ $expected_to_fail -eq "1" ]]; then
247 ok $?
"Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
249 ok
$ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
253 function lttng_disable_kernel_syscall_ok
()
255 lttng_disable_kernel_syscall
0 "$@"
258 function lttng_disable_kernel_syscall_fail
()
260 lttng_disable_kernel_syscall
1 "$@"
263 function lttng_enable_kernel_channel
()
266 local expected_to_fail
=$2
268 local channel_name
=$4
271 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-k $channel_name -s $sess_name $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
273 if [[ $expected_to_fail -eq "1" ]]; then
276 if [ $withtap -eq "1" ]; then
277 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
280 if [ $withtap -eq "1" ]; then
281 ok
$ret "Enable channel $channel_name for session $sess_name"
286 function lttng_enable_kernel_channel_ok
()
288 lttng_enable_kernel_channel
1 0 "$@"
291 function lttng_enable_kernel_channel_fail
()
293 lttng_enable_kernel_channel
1 1 "$@"
296 function lttng_enable_kernel_channel_notap
()
298 lttng_enable_kernel_channel
0 0 "$@"
301 function enable_kernel_lttng_channel_ok
()
303 lttng_enable_kernel_channel
1 0 "$@"
306 function lttng_disable_kernel_channel
()
308 local expected_to_fail
=$1
310 local channel_name
=$3
312 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
314 if [[ $expected_to_fail -eq "1" ]]; then
316 ok $?
"Disable channel $channel_name for session $sess_name failed as expected"
318 ok
$ret "Disable channel $channel_name for session $sess_name"
322 function lttng_disable_kernel_channel_ok
()
324 lttng_disable_kernel_channel
0 "$@"
327 function lttng_disable_kernel_channel_fail
()
329 lttng_disable_kernel_channel
1 "$@"
332 function start_lttng_relayd_opt
()
337 DIR
=$
(readlink
-f $TESTDIR)
339 if [ -z $
(pgrep
$RELAYD_MATCH) ]; then
340 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
341 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
342 if [ $?
-eq 1 ]; then
343 if [ $withtap -eq "1" ]; then
344 fail
"Start lttng-relayd (opt: $opt)"
348 if [ $withtap -eq "1" ]; then
349 pass
"Start lttng-relayd (opt: $opt)"
353 pass
"Start lttng-relayd (opt: $opt)"
356 RELAYD_PIDS
=$
(pgrep
$RELAYD_MATCH)
359 function start_lttng_relayd
()
361 start_lttng_relayd_opt
1 "$@"
364 function start_lttng_relayd_notap
()
366 start_lttng_relayd_opt
0 "$@"
369 function stop_lttng_relayd_opt
()
373 if [ $withtap -eq "1" ]; then
374 diag
"Killing lttng-relayd (pid: $RELAYD_PIDS)"
376 kill $RELAYD_PIDS 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
379 if [ $?
-eq 1 ]; then
380 if [ $withtap -eq "1" ]; then
381 fail
"Kill relay daemon"
386 while [ -n "$out" ]; do
387 out
=$
(pgrep
$RELAYD_MATCH)
390 if [ $withtap -eq "1" ]; then
391 pass
"Kill relay daemon"
398 function stop_lttng_relayd
()
400 stop_lttng_relayd_opt
1 "$@"
403 function stop_lttng_relayd_notap
()
405 stop_lttng_relayd_opt
0 "$@"
408 #First arg: show tap output
409 #Second argument: load path for automatic loading
410 function start_lttng_sessiond_opt
()
417 local long_bit_value
=$
(getconf LONG_BIT
)
419 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
420 # Env variable requested no session daemon
424 DIR
=$
(readlink
-f $TESTDIR)
426 # Get long_bit value for 32/64 consumerd
427 case "$long_bit_value" in
429 consumerd
="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
432 consumerd
="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
439 # Check for env. variable. Allow the use of LD_PRELOAD etc.
440 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
441 env_vars
=${LTTNG_SESSIOND_ENV_VARS}
444 validate_kernel_version
445 if [ $?
-ne 0 ]; then
446 fail
"Start session daemon"
447 BAIL_OUT
"*** Kernel too old for session daemon tests ***"
450 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
451 export LTTNG_SESSION_CONFIG_XSD_PATH
453 if [ -z $
(pgrep
${SESSIOND_MATCH}) ]; then
455 if [ -n "$load_path" ]; then
456 env
$env_vars $DIR/..
/src
/bin
/lttng-sessiond
/$SESSIOND_BIN --load "$load_path" --background $consumerd
458 env
$env_vars $DIR/..
/src
/bin
/lttng-sessiond
/$SESSIOND_BIN --background $consumerd
460 #$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
462 if [ $withtap -eq "1" ]; then
463 ok
$status "Start session daemon"
466 SESSIOND_PIDS
=$
(pgrep
$SESSIOND_MATCH)
469 function start_lttng_sessiond
()
471 start_lttng_sessiond_opt
1 "$@"
474 function start_lttng_sessiond_notap
()
476 start_lttng_sessiond_opt
0 "$@"
479 function stop_lttng_sessiond_opt
()
485 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
486 # Env variable requested no session daemon
490 local pids
="${SESSIOND_PIDS} $(pgrep $RUNAS_MATCH)"
493 kill_opt
="$kill_opt -s $signal"
495 if [ $withtap -eq "1" ]; then
496 diag
"Killing $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo $pids | tr '\n' ' ')"
498 kill $kill_opt $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
500 if [ $?
-eq 1 ]; then
501 if [ $withtap -eq "1" ]; then
502 fail
"Kill sessions daemon"
506 while [ -n "$out" ]; do
507 out
=$
(pgrep
${SESSIOND_MATCH})
511 while [ -n "$out" ]; do
512 out
=$
(pgrep
$CONSUMERD_MATCH)
517 if [ $withtap -eq "1" ]; then
518 pass
"Kill session daemon"
523 function stop_lttng_sessiond
()
525 stop_lttng_sessiond_opt
1 "$@"
528 function stop_lttng_sessiond_notap
()
530 stop_lttng_sessiond_opt
0 "$@"
533 function sigstop_lttng_sessiond_opt
()
539 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
540 # Env variable requested no session daemon
544 PID_SESSIOND
="$(pgrep ${SESSIOND_MATCH}) $(pgrep $RUNAS_MATCH)"
546 kill_opt
="$kill_opt -s $signal"
548 if [ $withtap -eq "1" ]; then
549 diag
"Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo $PID_SESSIOND | tr '\n' ' ')"
551 kill $kill_opt $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
553 if [ $?
-eq 1 ]; then
554 if [ $withtap -eq "1" ]; then
555 fail
"Sending SIGSTOP to session daemon"
559 while [ $out -ne 0 ]; do
560 pid
=$
(pgrep
$SESSIOND_MATCH)
562 # Wait until state becomes stopped for session
565 for sessiond_pid
in $pid; do
566 state
=$
(ps
-p $sessiond_pid -o state
= )
567 if [[ -n "$state" && "$state" != "T" ]]; then
573 if [ $withtap -eq "1" ]; then
574 pass
"Sending SIGSTOP to session daemon"
579 function sigstop_lttng_sessiond
()
581 sigstop_lttng_sessiond_opt
1 "$@"
584 function sigstop_lttng_sessiond_notap
()
586 sigstop_lttng_sessiond_opt
0 "$@"
589 function stop_lttng_consumerd_opt
()
595 PID_CONSUMERD
=$
(pgrep
$CONSUMERD_MATCH)
598 kill_opt
="$kill_opt -s $signal"
601 if [ $withtap -eq "1" ]; then
602 diag
"Killing $CONSUMERD_BIN pids: $(echo $PID_CONSUMERD | tr '\n' ' ')"
604 kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
608 if [ $?
-eq 1 ]; then
609 if [ $withtap -eq "1" ]; then
610 fail
"Kill consumer daemon"
615 while [ $out -ne 0 ]; do
616 pid
=$
(pgrep
$CONSUMERD_MATCH)
618 # If consumerds are still present check their status.
619 # A zombie status qualifies the consumerd as *killed*
621 for consumer_pid
in $pid; do
622 state
=$
(ps
-p $consumer_pid -o state
= )
623 if [[ -n "$state" && "$state" != "Z" ]]; then
629 if [ $withtap -eq "1" ]; then
630 pass
"Kill consumer daemon"
636 function stop_lttng_consumerd
()
638 stop_lttng_consumerd_opt
1 "$@"
641 function stop_lttng_consumerd_notap
()
643 stop_lttng_consumerd_opt
0 "$@"
646 function sigstop_lttng_consumerd_opt
()
652 PID_CONSUMERD
=$
(pgrep
$CONSUMERD_MATCH)
654 kill_opt
="$kill_opt -s $signal"
656 if [ $withtap -eq "1" ]; then
657 diag
"Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo $PID_CONSUMERD | tr '\n' ' ')"
659 kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
663 if [ $?
-eq 1 ]; then
664 if [ $withtap -eq "1" ]; then
665 fail
"Sending SIGSTOP to consumer daemon"
670 while [ $out -ne 0 ]; do
671 pid
=$
(pgrep
$CONSUMERD_MATCH)
673 # Wait until state becomes stopped for all
676 for consumer_pid
in $pid; do
677 state
=$
(ps
-p $consumer_pid -o state
= )
678 if [[ -n "$state" && "$state" != "T" ]]; then
684 if [ $withtap -eq "1" ]; then
685 pass
"Sending SIGSTOP to consumer daemon"
691 function sigstop_lttng_consumerd
()
693 sigstop_lttng_consumerd_opt
1 "$@"
696 function sigstop_lttng_consumerd_notap
()
698 sigstop_lttng_consumerd_opt
0 "$@"
701 function list_lttng_with_opts
()
704 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN list
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
705 ok $?
"Lttng-tool list command with option $opts"
708 function create_lttng_session_no_output
()
712 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name --no-output 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
713 ok $?
"Create session $sess_name in no-output mode"
716 function create_lttng_session
()
719 local expected_to_fail
=$2
724 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -o $trace_path $opt > $OUTPUT_DEST
726 if [ $expected_to_fail -eq "1" ]; then
729 if [ $withtap -eq "1" ]; then
730 ok
$ret "Create session $sess_name in $trace_path failed as expected"
733 if [ $withtap -eq "1" ]; then
734 ok
$ret "Create session $sess_name in $trace_path"
740 function create_lttng_session_ok
()
742 create_lttng_session
1 0 "$@"
745 function create_lttng_session_fail
()
747 create_lttng_session
1 1 "$@"
750 function create_lttng_session_notap
()
752 create_lttng_session
0 0 "$@"
756 function enable_ust_lttng_channel
()
759 local expected_to_fail
=$2
761 local channel_name
=$4
764 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-u $channel_name -s $sess_name $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
766 if [[ $expected_to_fail -eq "1" ]]; then
769 if [ $withtap -eq "1" ]; then
770 ok
$ret "Enable channel $channel_name for session $sess_name failed as expected"
773 if [ $withtap -eq "1" ]; then
774 ok
$ret "Enable channel $channel_name for session $sess_name"
780 function enable_ust_lttng_channel_ok
()
782 enable_ust_lttng_channel
1 0 "$@"
785 function enable_ust_lttng_channel_fail
()
787 enable_ust_lttng_channel
1 1 "$@"
790 function enable_ust_lttng_channel_notap
()
792 enable_ust_lttng_channel
0 0 "$@"
795 function disable_ust_lttng_channel
()
798 local channel_name
=$2
800 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
801 ok $?
"Disable channel $channel_name for session $sess_name"
804 function enable_lttng_mmap_overwrite_kernel_channel
()
807 local channel_name
=$2
809 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
810 ok $?
"Enable channel $channel_name for session $sess_name"
813 function enable_lttng_mmap_discard_small_kernel_channel
()
816 local channel_name
=$2
818 $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
819 ok $?
"Enable small discard channel $channel_name for session $sess_name"
822 function enable_lttng_mmap_overwrite_small_kernel_channel
()
825 local channel_name
=$2
827 $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
828 ok $?
"Enable small discard channel $channel_name for session $sess_name"
831 function enable_lttng_mmap_overwrite_ust_channel
()
834 local channel_name
=$2
836 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
837 ok $?
"Enable channel $channel_name for session $sess_name"
840 function enable_ust_lttng_event
()
843 local expected_to_fail
=$2
845 local event_name
="$4"
846 local channel_name
=$5
848 if [ -z $channel_name ]; then
849 # default channel if none specified
852 chan
="-c $channel_name"
855 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
857 if [[ $expected_to_fail -eq "1" ]]; then
860 if [[ $withtap -eq "1" ]]; then
861 ok
$ret "Enable ust event $event_name for session $session_name failed as expected"
864 if [[ $withtap -eq "1" ]]; then
865 ok
$ret "Enable ust event $event_name for session $sess_name"
871 function enable_ust_lttng_event_ok
()
873 enable_ust_lttng_event
1 0 "$@"
876 function enable_ust_lttng_event_fail
()
878 enable_ust_lttng_event
1 1 "$@"
881 function enable_ust_lttng_event_notap
()
883 enable_ust_lttng_event
0 0 "$@"
886 function enable_jul_lttng_event
()
892 if [ -z $channel_name ]; then
893 # default channel if none specified
896 chan
="-c $channel_name"
899 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
900 ok $?
"Enable JUL event $event_name for session $sess_name"
903 function enable_jul_lttng_event_loglevel
()
906 local event_name
="$2"
908 local channel_name
=$4
910 if [ -z $channel_name ]; then
911 # default channel if none specified
914 chan
="-c $channel_name"
917 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
918 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
921 function enable_log4j_lttng_event
()
927 if [ -z $channel_name ]; then
928 # default channel if none specified
931 chan
="-c $channel_name"
934 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
935 ok $?
"Enable LOG4J event $event_name for session $sess_name"
938 function enable_log4j_lttng_event_loglevel
()
941 local event_name
="$2"
943 local channel_name
=$4
945 if [ -z $channel_name ]; then
946 # default channel if none specified
949 chan
="-c $channel_name"
952 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
953 ok $?
"Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
956 function enable_python_lttng_event
()
962 if [ -z $channel_name ]; then
963 # default channel if none specified
966 chan
="-c $channel_name"
969 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
970 ok $?
"Enable Python event $event_name for session $sess_name"
973 function enable_python_lttng_event_loglevel
()
976 local event_name
="$2"
978 local channel_name
=$4
980 if [ -z $channel_name ]; then
981 # default channel if none specified
984 chan
="-c $channel_name"
987 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
988 ok $?
"Enable Python event $event_name for session $sess_name with loglevel $loglevel"
991 function enable_ust_lttng_event_filter
()
994 local event_name
="$2"
997 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
998 ok $?
"Enable event $event_name with filtering for session $sess_name"
1001 function enable_ust_lttng_event_loglevel
()
1003 local sess_name
="$1"
1004 local event_name
="$2"
1007 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1008 ok $?
"Enable event $event_name with loglevel $loglevel"
1011 function enable_ust_lttng_event_loglevel_only
()
1013 local sess_name
="$1"
1014 local event_name
="$2"
1017 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1018 ok $?
"Enable event $event_name with loglevel-only $loglevel"
1021 function disable_ust_lttng_event
()
1023 local sess_name
="$1"
1024 local event_name
="$2"
1025 local channel_name
="$3"
1027 if [ -z $channel_name ]; then
1028 # default channel if none specified
1031 chan
="-c $channel_name"
1034 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1035 ok $?
"Disable event $event_name for session $sess_name"
1038 function disable_jul_lttng_event
()
1040 local sess_name
="$1"
1041 local event_name
="$2"
1043 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
1044 ok $?
"Disable JUL event $event_name for session $sess_name"
1047 function disable_log4j_lttng_event
()
1049 local sess_name
="$1"
1050 local event_name
="$2"
1052 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -l >/dev
/null
2>&1
1053 ok $?
"Disable LOG4J event $event_name for session $sess_name"
1056 function disable_python_lttng_event
()
1058 local sess_name
="$1"
1059 local event_name
="$2"
1061 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1062 ok $?
"Disable Python event $event_name for session $sess_name"
1065 function start_lttng_tracing
()
1067 local expected_to_fail
=$1
1070 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1072 if [[ $expected_to_fail -eq "1" ]]; then
1074 ok $?
"Start tracing for session $sess_name failed as expected"
1076 ok
$ret "Start tracing for session $sess_name"
1080 function start_lttng_tracing_ok
()
1082 start_lttng_tracing
0 "$@"
1085 function start_lttng_tracing_fail
()
1087 start_lttng_tracing
1 "$@"
1090 function stop_lttng_tracing
()
1092 local expected_to_fail
=$1
1095 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1097 if [[ $expected_to_fail -eq "1" ]]; then
1099 ok $?
"Stop lttng tracing for session $sess_name failed as expected"
1101 ok
$ret "Stop lttng tracing for session $sess_name"
1105 function stop_lttng_tracing_ok
()
1107 stop_lttng_tracing
0 "$@"
1110 function stop_lttng_tracing_fail
()
1112 stop_lttng_tracing
1 "$@"
1115 function destroy_lttng_session
()
1118 local expected_to_fail
=$2
1121 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1123 if [[ $expected_to_fail -eq "1" ]]; then
1126 if [ $withtap -eq "1" ]; then
1127 ok
$ret "Destroy session $sess_name failed as expected"
1130 if [ $withtap -eq "1" ]; then
1131 ok
$ret "Destroy session $sess_name"
1136 function destroy_lttng_session_ok
()
1138 destroy_lttng_session
1 0 "$@"
1142 function destroy_lttng_session_fail
()
1144 destroy_lttng_session
1 1 "$@"
1147 function destroy_lttng_session_notap
()
1149 destroy_lttng_session
0 0 "$@"
1152 function destroy_lttng_sessions
()
1154 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
--all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1155 ok $?
"Destroy all lttng sessions"
1158 function lttng_snapshot_add_output
()
1160 local expected_to_fail
=$1
1164 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name file://$trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1166 if [[ $expected_to_fail -eq 1 ]]; then
1168 ok $?
"Added snapshot output file://$trace_path failed as expected"
1170 ok
$ret "Added snapshot output file://$trace_path"
1174 function lttng_snapshot_add_output_ok
()
1176 lttng_snapshot_add_output
0 "$@"
1179 function lttng_snapshot_add_output_fail
()
1181 lttng_snapshot_add_output
1 "$@"
1184 function lttng_snapshot_del_output
()
1186 local expected_to_fail
=$1
1190 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output
-s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1192 if [[ $expected_to_fail -eq "1" ]]; then
1194 ok $?
"Deleted snapshot output id $id failed as expected"
1196 ok
$ret "Deleted snapshot output id $id"
1200 function lttng_snapshot_del_output_ok
()
1202 lttng_snapshot_del_output
0 "$@"
1205 function lttng_snapshot_del_output_fail
()
1207 lttng_snapshot_del_output
1 "$@"
1210 function lttng_snapshot_record
()
1215 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot record
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1216 ok $?
"Snapshot recorded"
1219 function lttng_snapshot_list
()
1222 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1223 ok $?
"Snapshot list"
1226 function lttng_save
()
1231 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN save
$sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1232 ok $?
"Session saved"
1235 function lttng_load
()
1237 local expected_to_fail
=$1
1240 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN load
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1242 if [[ $expected_to_fail -eq "1" ]]; then
1244 ok $?
"Load command failed as expected with opts: $opts"
1246 ok
$ret "Load command with opts: $opts"
1250 function lttng_load_ok
()
1255 function lttng_load_fail
()
1260 function lttng_track
()
1262 local expected_to_fail
=$1
1264 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN track
$opts >$OUTPUT_DEST
1266 if [[ $expected_to_fail -eq "1" ]]; then
1268 ok $?
"Track command failed as expected with opts: $opts"
1270 ok
$ret "Track command with opts: $opts"
1274 function lttng_track_ok
()
1279 function lttng_track_fail
()
1284 function lttng_untrack
()
1286 local expected_to_fail
=$1
1288 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN untrack
$opts >$OUTPUT_DEST
1290 if [[ $expected_to_fail -eq "1" ]]; then
1292 ok $?
"Untrack command failed as expected with opts: $opts"
1294 ok
$ret "Untrack command with opts: $opts"
1298 function lttng_untrack_ok
()
1300 lttng_untrack
0 "$@"
1303 function lttng_untrack_fail
()
1305 lttng_untrack
1 "$@"
1308 function lttng_track_pid_ok
()
1311 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track
--kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1312 ok $?
"Lttng track pid on the kernel domain"
1315 function lttng_untrack_kernel_all_ok
()
1317 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack
--kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1318 ok $?
"Lttng untrack all pid on the kernel domain"
1321 function add_context_lttng
()
1323 local expected_to_fail
="$1"
1325 local session_name
="$3"
1326 local channel_name
="$4"
1329 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context
-s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1331 if [[ $expected_to_fail -eq "1" ]]; then
1333 ok $?
"Add context command failed as expected for type: $type"
1335 ok
$ret "Add context command for type: $type"
1339 function add_context_ust_ok
()
1341 add_context_lttng
0 -u "$@"
1344 function add_context_ust_fail
()
1346 add_context_lttng
1 -u "$@"
1349 function add_context_kernel_ok
()
1351 add_context_lttng
0 -k "$@"
1354 function add_context_kernel_fail
()
1356 add_context_lttng
1 -k "$@"
1359 function trace_matches
()
1365 which $BABELTRACE_BIN >/dev
/null
1366 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1368 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1370 if [ "$count" -ne "$nr_iter" ]; then
1372 diag
"$count matching events found in trace"
1378 function trace_match_only
()
1384 which $BABELTRACE_BIN >/dev
/null
1385 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1387 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1388 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1390 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1391 pass
"Trace match with $total event $event_name"
1394 diag
"$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1398 function validate_trace
1403 which $BABELTRACE_BIN >/dev
/null
1404 if [ $?
-ne 0 ]; then
1405 skip
0 "Babeltrace binary not found. Skipping trace validation"
1410 for i
in $event_name; do
1411 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1412 if [ "$traced" -ne 0 ]; then
1413 pass
"Validate trace for event $i, $traced events"
1415 fail
"Validate trace for event $i"
1416 diag
"Found $traced occurences of $i"
1424 function validate_trace_count
1428 local expected_count
=$3
1430 which $BABELTRACE_BIN >/dev
/null
1431 if [ $?
-ne 0 ]; then
1432 skip
0 "Babeltrace binary not found. Skipping trace validation"
1438 for i
in $event_name; do
1439 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1440 if [ "$traced" -ne 0 ]; then
1441 pass
"Validate trace for event $i, $traced events"
1443 fail
"Validate trace for event $i"
1444 diag
"Found $traced occurences of $i"
1446 cnt
=$
(($cnt + $traced))
1449 test $cnt -eq $expected_count
1450 ok $?
"Read a total of $cnt events, expected $expected_count"
1453 function trace_first_line
1457 which $BABELTRACE_BIN >/dev
/null
1458 if [ $?
-ne 0 ]; then
1459 skip
0 "Babeltrace binary not found. Skipping trace validation"
1462 $BABELTRACE_BIN $trace_path 2>/dev
/null |
head -n 1
1465 function validate_trace_exp
()
1470 which $BABELTRACE_BIN >/dev
/null
1471 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace validation"
1473 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep ${event_exp} |
wc -l)
1474 if [ "$traced" -ne 0 ]; then
1475 pass
"Validate trace for expression '${event_exp}', $traced events"
1477 fail
"Validate trace for expression '${event_exp}'"
1478 diag
"Found $traced occurences of '${event_exp}'"
1484 function validate_trace_only_exp
()
1489 which $BABELTRACE_BIN >/dev
/null
1490 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1492 local count
=$
($BABELTRACE_BIN $trace_path |
grep ${event_exp} |
wc -l)
1493 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1495 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1496 pass
"Trace match with $total for expression '${event_exp}"
1499 diag
"$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1505 function validate_trace_empty
()
1509 which $BABELTRACE_BIN >/dev
/null
1510 if [ $?
-ne 0 ]; then
1511 skip
0 "Babeltrace binary not found. Skipping trace validation"
1514 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
wc -l)
1515 if [ "$traced" -eq 0 ]; then
1516 pass
"Validate empty trace"
1518 fail
"Validate empty trace"
1519 diag
"Found $traced events in trace"
1525 function regenerate_metadata
()
1527 local expected_to_fail
=$1
1530 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN regenerate metadata
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1532 if [[ $expected_to_fail -eq "1" ]]; then
1534 ok $?
"Expected fail on regenerate metadata $sess_name"
1536 ok
$ret "Metadata regenerate $sess_name"
1540 function regenerate_metadata_ok
()
1542 regenerate_metadata
0 "$@"
1545 function regenerate_metadata_fail
()
1547 regenerate_metadata
1 "$@"
1550 function regenerate_statedump
()
1552 local expected_to_fail
=$1
1555 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN regenerate statedump
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1557 if [[ $expected_to_fail -eq "1" ]]; then
1559 ok $?
"Expected fail on regenerate statedump $sess_name"
1561 ok
$ret "Metadata regenerate $sess_name"
1565 function regenerate_statedump_ok
()
1567 regenerate_statedump
0 "$@"
1570 function regenerate_statedump_fail
()
1572 regenerate_statedump
1 "$@"
1575 function destructive_tests_enabled
()
1577 if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then