3 # Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
5 # This library is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation; version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this library; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 SESSIOND_BIN
="lttng-sessiond"
19 RUNAS_BIN
="lttng-runas"
20 CONSUMERD_BIN
="lttng-consumerd"
21 RELAYD_BIN
="lttng-relayd"
23 BABELTRACE_BIN
="babeltrace"
25 ERROR_OUTPUT_DEST
=/dev
/null
27 # Minimal kernel version supported for session daemon tests
28 KERNEL_MAJOR_VERSION
=2
29 KERNEL_MINOR_VERSION
=6
30 KERNEL_PATCHLEVEL_VERSION
=27
32 # We set the default UST register timeout to "wait forever", so that
33 # basic tests don't have to worry about hitting timeouts on busy
34 # systems. Specialized tests should test those corner-cases.
35 export LTTNG_UST_REGISTER_TIMEOUT
=-1
37 # We set the default lttng-sessiond path to /bin/true to prevent the spawning
38 # of a daemonized sessiond. This is necessary since 'lttng create' will spawn
39 # its own sessiond if none is running. It also ensures that 'lttng create'
40 # fails when no sessiond is running.
41 export LTTNG_SESSIOND_PATH
="/bin/true"
43 source $TESTDIR/utils
/tap
/tap.sh
47 # Check if we are a terminal
49 echo -e "\e[1;32mOK\e[0m"
55 function print_fail
()
57 # Check if we are a terminal
59 echo -e "\e[1;31mFAIL\e[0m"
65 function print_test_banner
()
71 function validate_kernel_version
()
73 local kern_version
=($
(uname
-r |
awk -F.
'{ printf("%d.%d.%d\n",$1,$2,$3); }' |
tr '.' '\n'))
74 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
77 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
80 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
86 # Generate a random string
87 # $1 = number of characters; defaults to 16
88 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
91 [ "$2" == "0" ] && CHAR
="[:alnum:]" || CHAR
="[:graph:]"
92 cat /dev
/urandom
2>/dev
/null |
tr -cd "$CHAR" 2>/dev
/null |
head -c ${1:-16} 2>/dev
/null
96 # Return the number of _configured_ CPUs.
97 function conf_proc_count
()
99 getconf _NPROCESSORS_CONF
100 if [ $?
-ne 0 ]; then
101 diag
"Failed to get the number of configured CPUs"
106 function enable_kernel_lttng_event
108 local expected_to_fail
="$1"
110 local event_name
="$3"
111 local channel_name
="$4"
113 if [ -z "$event_name" ]; then
114 # Enable all event if no event name specified
118 if [ -z "$channel_name" ]; then
119 # default channel if none specified
122 chan
="-c $channel_name"
125 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
127 if [[ $expected_to_fail -eq "1" ]]; then
129 ok $?
"Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
131 ok
$ret "Enable kernel event $event_name for session $sess_name"
135 function enable_kernel_lttng_event_ok
()
137 enable_kernel_lttng_event
0 "$@"
140 function enable_kernel_lttng_event_fail
()
142 enable_kernel_lttng_event
1 "$@"
146 function lttng_enable_kernel_event
148 enable_kernel_lttng_event_ok
"$@"
151 function lttng_enable_kernel_syscall
()
153 local expected_to_fail
=$1
155 local syscall_name
=$3
156 local channel_name
=$4
158 if [ -z $syscall_name ]; then
159 # Enable all event if no syscall name specified
163 if [ -z $channel_name ]; then
164 # default channel if none specified
167 chan
="-c $channel_name"
170 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
172 if [[ $expected_to_fail -eq "1" ]]; then
174 ok $?
"Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
176 ok
$ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
180 function lttng_enable_kernel_syscall_ok
()
182 lttng_enable_kernel_syscall
0 "$@"
185 function lttng_enable_kernel_syscall_fail
()
187 lttng_enable_kernel_syscall
1 "$@"
190 function lttng_disable_kernel_syscall
()
192 local expected_to_fail
=$1
194 local syscall_name
=$3
195 local channel_name
=$4
197 if [ -z $syscall_name ]; then
198 # Enable all event if no syscall name specified
202 if [ -z $channel_name ]; then
203 # default channel if none specified
206 chan
="-c $channel_name"
209 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
212 if [[ $expected_to_fail -eq "1" ]]; then
214 ok $?
"Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
216 ok
$ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
220 function lttng_disable_kernel_syscall_ok
()
222 lttng_disable_kernel_syscall
0 "$@"
225 function lttng_disable_kernel_syscall_fail
()
227 lttng_disable_kernel_syscall
1 "$@"
230 function lttng_enable_kernel_channel
()
232 local expected_to_fail
=$1
234 local channel_name
=$3
236 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
238 if [[ $expected_to_fail -eq "1" ]]; then
240 ok $?
"Enable channel $channel_name for session $sess_name failed as expected"
242 ok
$ret "Enable channel $channel_name for session $sess_name"
246 function lttng_enable_kernel_channel_ok
()
248 lttng_enable_kernel_channel
0 "$@"
251 function lttng_enable_kernel_channel_fail
()
253 lttng_enable_kernel_channel
1 "$@"
256 function lttng_disable_kernel_channel
()
258 local expected_to_fail
=$1
260 local channel_name
=$3
262 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
264 if [[ $expected_to_fail -eq "1" ]]; then
266 ok $?
"Disable channel $channel_name for session $sess_name failed as expected"
268 ok
$ret "Disable channel $channel_name for session $sess_name"
272 function lttng_disable_kernel_channel_ok
()
274 lttng_disable_kernel_channel
0 "$@"
277 function lttng_disable_kernel_channel_fail
()
279 lttng_disable_kernel_channel
1 "$@"
282 function start_lttng_relayd_opt
()
287 DIR
=$
(readlink
-f $TESTDIR)
289 if [ -z $
(pgrep
--full lt-
$RELAYD_BIN) ]; then
290 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
291 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
292 if [ $?
-eq 1 ]; then
293 if [ $withtap -eq "1" ]; then
294 fail
"Start lttng-relayd (opt: $opt)"
298 if [ $withtap -eq "1" ]; then
299 pass
"Start lttng-relayd (opt: $opt)"
303 pass
"Start lttng-relayd (opt: $opt)"
307 function start_lttng_relayd
()
309 start_lttng_relayd_opt
1 "$@"
312 function start_lttng_relayd_notap
()
314 start_lttng_relayd_opt
0 "$@"
317 function stop_lttng_relayd_opt
()
321 PID_RELAYD
=`pgrep --full lt-$RELAYD_BIN`
323 if [ $withtap -eq "1" ]; then
324 diag
"Killing lttng-relayd (pid: $PID_RELAYD)"
326 kill $PID_RELAYD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
329 if [ $?
-eq 1 ]; then
330 if [ $withtap -eq "1" ]; then
331 fail
"Kill relay daemon"
336 while [ -n "$out" ]; do
337 out
=$
(pgrep
--full lt-
$RELAYD_BIN)
340 if [ $withtap -eq "1" ]; then
341 pass
"Kill relay daemon"
347 function stop_lttng_relayd
()
349 stop_lttng_relayd_opt
1 "$@"
352 function stop_lttng_relayd_notap
()
354 stop_lttng_relayd_opt
0 "$@"
357 #First arg: show tap output
358 #Second argument: load path for automatic loading
359 function start_lttng_sessiond_opt
()
364 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
365 # Env variable requested no session daemon
369 validate_kernel_version
370 if [ $?
-ne 0 ]; then
371 fail
"Start session daemon"
372 BAIL_OUT
"*** Kernel too old for session daemon tests ***"
375 DIR
=$
(readlink
-f $TESTDIR)
376 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
377 export LTTNG_SESSION_CONFIG_XSD_PATH
379 if [ -z $
(pgrep
--full lt-
$SESSIOND_BIN) ]; then
381 if [ -n "$load_path" ]; then
382 $DIR/..
/src
/bin
/lttng-sessiond
/$SESSIOND_BIN --load "$load_path" --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
384 $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"
386 #$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
388 if [ $withtap -eq "1" ]; then
389 ok
$status "Start session daemon"
394 function start_lttng_sessiond
()
396 start_lttng_sessiond_opt
1 "$@"
399 function start_lttng_sessiond_notap
()
401 start_lttng_sessiond_opt
0 "$@"
404 function stop_lttng_sessiond_opt
()
410 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
411 # Env variable requested no session daemon
415 PID_SESSIOND
="$(pgrep --full lt-$SESSIOND_BIN) $(pgrep --full $RUNAS_BIN)"
418 kill_opt
="$kill_opt -s $signal"
420 if [ $withtap -eq "1" ]; then
421 diag
"Killing lt-$SESSIOND_BIN pids: $(echo $PID_SESSIOND | tr '\n' ' ')"
423 kill $kill_opt $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
425 if [ $?
-eq 1 ]; then
426 if [ $withtap -eq "1" ]; then
427 fail
"Kill sessions daemon"
431 while [ -n "$out" ]; do
432 out
=$
(pgrep
--full lt-
$SESSIOND_BIN)
436 while [ -n "$out" ]; do
437 out
=$
(pgrep
--full $CONSUMERD_BIN)
440 if [ $withtap -eq "1" ]; then
441 pass
"Kill session daemon"
446 function stop_lttng_sessiond
()
448 stop_lttng_sessiond_opt
1 "$@"
451 function stop_lttng_sessiond_notap
()
453 stop_lttng_sessiond_opt
0 "$@"
456 function sigstop_lttng_sessiond_opt
()
462 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
463 # Env variable requested no session daemon
467 PID_SESSIOND
="$(pgrep --full lt-$SESSIOND_BIN) $(pgrep --full $RUNAS_BIN)"
469 kill_opt
="$kill_opt -s $signal"
471 if [ $withtap -eq "1" ]; then
472 diag
"Sending SIGSTOP to lt-$SESSIOND_BIN pids: $(echo $PID_SESSIOND | tr '\n' ' ')"
474 kill $kill_opt $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
476 if [ $?
-eq 1 ]; then
477 if [ $withtap -eq "1" ]; then
478 fail
"Sending SIGSTOP to session daemon"
482 while [ $out -ne 0 ]; do
483 pid
=$
(pgrep
--full lt-
$SESSIOND_BIN)
485 # Wait until state becomes stopped for session
488 for sessiond_pid
in $pid; do
489 state
=$
(ps
-p $sessiond_pid -o state
= )
490 if [[ -n "$state" && "$state" != "T" ]]; then
496 if [ $withtap -eq "1" ]; then
497 pass
"Sending SIGSTOP to session daemon"
502 function sigstop_lttng_sessiond
()
504 sigstop_lttng_sessiond_opt
1 "$@"
507 function sigstop_lttng_sessiond_notap
()
509 sigstop_lttng_sessiond_opt
0 "$@"
512 function stop_lttng_consumerd_opt
()
518 PID_CONSUMERD
=`pgrep --full $CONSUMERD_BIN`
521 kill_opt
="$kill_opt -s $signal"
524 if [ $withtap -eq "1" ]; then
525 diag
"Killing $CONSUMERD_BIN pids: $(echo $PID_CONSUMERD | tr '\n' ' ')"
527 kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
531 if [ $?
-eq 1 ]; then
532 if [ $withtap -eq "1" ]; then
533 fail
"Kill consumer daemon"
538 while [ $out -ne 0 ]; do
539 pid
=$
(pgrep
--full $CONSUMERD_BIN)
541 # If consumerds are still present check their status.
542 # A zombie status qualifies the consumerd as *killed*
544 for consumer_pid
in $pid; do
545 state
=$
(ps
-p $consumer_pid -o state
= )
546 if [[ -n "$state" && "$state" != "Z" ]]; then
552 if [ $withtap -eq "1" ]; then
553 pass
"Kill consumer daemon"
559 function stop_lttng_consumerd
()
561 stop_lttng_consumerd_opt
1 "$@"
564 function stop_lttng_consumerd_notap
()
566 stop_lttng_consumerd_opt
0 "$@"
569 function sigstop_lttng_consumerd_opt
()
575 PID_CONSUMERD
=`pgrep --full $CONSUMERD_BIN`
577 kill_opt
="$kill_opt -s $signal"
579 if [ $withtap -eq "1" ]; then
580 diag
"Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo $PID_CONSUMERD | tr '\n' ' ')"
582 kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
586 if [ $?
-eq 1 ]; then
587 if [ $withtap -eq "1" ]; then
588 fail
"Sending SIGSTOP to consumer daemon"
593 while [ $out -ne 0 ]; do
594 pid
=$
(pgrep
--full $CONSUMERD_BIN)
596 # Wait until state becomes stopped for all
599 for consumer_pid
in $pid; do
600 state
=$
(ps
-p $consumer_pid -o state
= )
601 if [[ -n "$state" && "$state" != "T" ]]; then
607 if [ $withtap -eq "1" ]; then
608 pass
"Sending SIGSTOP to consumer daemon"
614 function sigstop_lttng_consumerd
()
616 sigstop_lttng_consumerd_opt
1 "$@"
619 function sigstop_lttng_consumerd_notap
()
621 sigstop_lttng_consumerd_opt
0 "$@"
624 function list_lttng_with_opts
()
627 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN list
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
628 ok $?
"Lttng-tool list command with option $opts"
631 function create_lttng_session_no_output
()
635 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name --no-output 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
636 ok $?
"Create session $sess_name in no-output mode"
639 function create_lttng_session
()
641 local expected_to_fail
=$1
646 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -o $trace_path $opt > $OUTPUT_DEST
648 if [[ $expected_to_fail -eq "1" ]]; then
650 ok $?
"Create session $sess_name in $trace_path failed as expected"
652 ok
$ret "Create session $sess_name in $trace_path"
656 function create_lttng_session_ok
()
658 create_lttng_session
0 "$@"
661 function create_lttng_session_fail
()
663 create_lttng_session
1 "$@"
667 function enable_ust_lttng_channel
()
669 local expected_to_fail
=$1
671 local channel_name
=$3
674 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-u $channel_name -s $sess_name $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
676 if [[ $expected_to_fail -eq "1" ]]; then
678 ok $?
"Enable channel $channel_name for session $sess_name failed as expected"
680 ok
$ret "Enable channel $channel_name for session $sess_name"
684 function enable_ust_lttng_channel_ok
()
686 enable_ust_lttng_channel
0 "$@"
689 function enable_ust_lttng_channel_fail
()
691 enable_ust_lttng_channel
1 "$@"
694 function disable_ust_lttng_channel
()
697 local channel_name
=$2
699 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
700 ok $?
"Disable channel $channel_name for session $sess_name"
703 function enable_lttng_mmap_overwrite_kernel_channel
()
706 local channel_name
=$2
708 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
709 ok $?
"Enable channel $channel_name for session $sess_name"
712 function enable_lttng_mmap_overwrite_ust_channel
()
715 local channel_name
=$2
717 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
718 ok $?
"Enable channel $channel_name for session $sess_name"
721 function enable_ust_lttng_event
()
723 local expected_to_fail
=$1
725 local event_name
="$3"
726 local channel_name
=$4
728 if [ -z $channel_name ]; then
729 # default channel if none specified
732 chan
="-c $channel_name"
735 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
737 if [[ $expected_to_fail -eq "1" ]]; then
739 ok $?
"Enable ust event $event_name for session $session_name failed as expected"
741 ok
$ret "Enable ust event $event_name for session $sess_name"
745 function enable_ust_lttng_event_ok
()
747 enable_ust_lttng_event
0 "$@"
750 function enable_ust_lttng_event_fail
()
752 enable_ust_lttng_event
1 "$@"
755 function enable_jul_lttng_event
()
761 if [ -z $channel_name ]; then
762 # default channel if none specified
765 chan
="-c $channel_name"
768 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
769 ok $?
"Enable JUL event $event_name for session $sess_name"
772 function enable_jul_lttng_event_loglevel
()
775 local event_name
="$2"
777 local channel_name
=$4
779 if [ -z $channel_name ]; then
780 # default channel if none specified
783 chan
="-c $channel_name"
786 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
787 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
790 function enable_log4j_lttng_event
()
796 if [ -z $channel_name ]; then
797 # default channel if none specified
800 chan
="-c $channel_name"
803 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
804 ok $?
"Enable LOG4J event $event_name for session $sess_name"
807 function enable_log4j_lttng_event_loglevel
()
810 local event_name
="$2"
812 local channel_name
=$4
814 if [ -z $channel_name ]; then
815 # default channel if none specified
818 chan
="-c $channel_name"
821 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
822 ok $?
"Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
825 function enable_python_lttng_event
()
831 if [ -z $channel_name ]; then
832 # default channel if none specified
835 chan
="-c $channel_name"
838 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
839 ok $?
"Enable Python event $event_name for session $sess_name"
842 function enable_python_lttng_event_loglevel
()
845 local event_name
="$2"
847 local channel_name
=$4
849 if [ -z $channel_name ]; then
850 # default channel if none specified
853 chan
="-c $channel_name"
856 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
857 ok $?
"Enable Python event $event_name for session $sess_name with loglevel $loglevel"
860 function enable_ust_lttng_event_filter
()
863 local event_name
="$2"
866 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
867 ok $?
"Enable event $event_name with filtering for session $sess_name"
870 function enable_ust_lttng_event_loglevel
()
873 local event_name
="$2"
876 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
877 ok $?
"Enable event $event_name with loglevel $loglevel"
880 function enable_ust_lttng_event_loglevel_only
()
883 local event_name
="$2"
886 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
887 ok $?
"Enable event $event_name with loglevel-only $loglevel"
890 function disable_ust_lttng_event
()
893 local event_name
="$2"
894 local channel_name
="$3"
896 if [ -z $channel_name ]; then
897 # default channel if none specified
900 chan
="-c $channel_name"
903 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
904 ok $?
"Disable event $event_name for session $sess_name"
907 function disable_jul_lttng_event
()
910 local event_name
="$2"
912 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
913 ok $?
"Disable JUL event $event_name for session $sess_name"
916 function disable_log4j_lttng_event
()
919 local event_name
="$2"
921 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -l >/dev
/null
2>&1
922 ok $?
"Disable LOG4J event $event_name for session $sess_name"
925 function disable_python_lttng_event
()
928 local event_name
="$2"
930 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
931 ok $?
"Disable Python event $event_name for session $sess_name"
934 function start_lttng_tracing
()
936 local expected_to_fail
=$1
939 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
941 if [[ $expected_to_fail -eq "1" ]]; then
943 ok $?
"Start tracing for session $sess_name failed as expected"
945 ok
$ret "Start tracing for session $sess_name"
949 function start_lttng_tracing_ok
()
951 start_lttng_tracing
0 "$@"
954 function start_lttng_tracing_fail
()
956 start_lttng_tracing
1 "$@"
959 function stop_lttng_tracing
()
961 local expected_to_fail
=$1
964 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
966 if [[ $expected_to_fail -eq "1" ]]; then
968 ok $?
"Stop lttng tracing for session $sess_name failed as expected"
970 ok
$ret "Stop lttng tracing for session $sess_name"
974 function stop_lttng_tracing_ok
()
976 stop_lttng_tracing
0 "$@"
979 function stop_lttng_tracing_fail
()
981 stop_lttng_tracing
1 "$@"
984 function destroy_lttng_session
()
986 local expected_to_fail
=$1
989 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
991 if [[ $expected_to_fail -eq "1" ]]; then
993 ok $?
"Destroy session $sess_name failed as expected"
995 ok
$ret "Destroy session $sess_name"
999 function destroy_lttng_session_ok
()
1001 destroy_lttng_session
0 "$@"
1005 function destroy_lttng_session_fail
()
1007 destroy_lttng_session
1 "$@"
1011 function destroy_lttng_sessions
()
1013 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
--all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1014 ok $?
"Destroy all lttng sessions"
1017 function lttng_snapshot_add_output
()
1019 local expected_to_fail
=$1
1023 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name file://$trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1025 if [[ $expected_to_fail -eq 1 ]]; then
1027 ok $?
"Added snapshot output file://$trace_path failed as expected"
1029 ok
$ret "Added snapshot output file://$trace_path"
1033 function lttng_snapshot_add_output_ok
()
1035 lttng_snapshot_add_output
0 "$@"
1038 function lttng_snapshot_add_output_fail
()
1040 lttng_snapshot_add_output
1 "$@"
1043 function lttng_snapshot_del_output
()
1045 local expected_to_fail
=$1
1049 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output
-s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1051 if [[ $expected_to_fail -eq "1" ]]; then
1053 ok $?
"Deleted snapshot output id $id failed as expected"
1055 ok
$ret "Deleted snapshot output id $id"
1059 function lttng_snapshot_del_output_ok
()
1061 lttng_snapshot_del_output
0 "$@"
1064 function lttng_snapshot_del_output_fail
()
1066 lttng_snapshot_del_output
1 "$@"
1069 function lttng_snapshot_record
()
1074 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot record
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1075 ok $?
"Snapshot recorded"
1078 function lttng_snapshot_list
()
1081 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1082 ok $?
"Snapshot list"
1085 function lttng_save
()
1090 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN save
$sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1091 ok $?
"Session saved"
1094 function lttng_load
()
1098 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN load
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1099 ok $?
"Load command with opts: $opts"
1102 function lttng_track
()
1104 local expected_to_fail
=$1
1106 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN track
$opts >$OUTPUT_DEST
1108 if [[ $expected_to_fail -eq "1" ]]; then
1110 ok $?
"Track command failed as expected with opts: $opts"
1112 ok
$ret "Track command with opts: $opts"
1116 function lttng_track_ok
()
1121 function lttng_track_fail
()
1126 function lttng_untrack
()
1128 local expected_to_fail
=$1
1130 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN untrack
$opts >$OUTPUT_DEST
1132 if [[ $expected_to_fail -eq "1" ]]; then
1134 ok $?
"Untrack command failed as expected with opts: $opts"
1136 ok
$ret "Untrack command with opts: $opts"
1140 function lttng_untrack_ok
()
1142 lttng_untrack
0 "$@"
1145 function lttng_untrack_fail
()
1147 lttng_untrack
1 "$@"
1150 function add_context_lttng
()
1152 local expected_to_fail
="$1"
1154 local session_name
="$3"
1155 local channel_name
="$4"
1158 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context
-s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1160 if [[ $expected_to_fail -eq "1" ]]; then
1162 ok $?
"Add context command failed as expected for type: $type"
1164 ok
$ret "Add context command for type: $type"
1168 function add_context_ust_ok
()
1170 add_context_lttng
0 -u "$@"
1173 function add_context_ust_fail
()
1175 add_context_lttng
1 -u "$@"
1178 function add_context_kernel_ok
()
1180 add_context_lttng
0 -k "$@"
1183 function add_context_kernel_fail
()
1185 add_context_lttng
1 -k "$@"
1188 function trace_matches
()
1194 which $BABELTRACE_BIN >/dev
/null
1195 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1197 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1199 if [ "$count" -ne "$nr_iter" ]; then
1201 diag
"$count events found in trace"
1207 function trace_match_only
()
1213 which $BABELTRACE_BIN >/dev
/null
1214 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1216 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1217 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1219 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1220 pass
"Trace match with $total event $event_name"
1223 diag
"$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1227 function validate_trace
1232 which $BABELTRACE_BIN >/dev
/null
1233 if [ $?
-ne 0 ]; then
1234 skip
0 "Babeltrace binary not found. Skipping trace validation"
1239 for i
in $event_name; do
1240 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1241 if [ "$traced" -ne 0 ]; then
1242 pass
"Validate trace for event $i, $traced events"
1244 fail
"Validate trace for event $i"
1245 diag
"Found $traced occurences of $i"
1253 function validate_trace_exp
()
1258 which $BABELTRACE_BIN >/dev
/null
1259 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace validation"
1261 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep ${event_exp} |
wc -l)
1262 if [ "$traced" -ne 0 ]; then
1263 pass
"Validate trace for expression '${event_exp}', $traced events"
1265 fail
"Validate trace for expression '${event_exp}'"
1266 diag
"Found $traced occurences of '${event_exp}'"
1272 function validate_trace_only_exp
()
1277 which $BABELTRACE_BIN >/dev
/null
1278 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1280 local count
=$
($BABELTRACE_BIN $trace_path |
grep ${event_exp} |
wc -l)
1281 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1283 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1284 pass
"Trace match with $total for expression '${event_exp}"
1287 diag
"$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1293 function validate_trace_empty
()
1297 which $BABELTRACE_BIN >/dev
/null
1298 if [ $?
-ne 0 ]; then
1299 skip
0 "Babeltrace binary not found. Skipping trace validation"
1302 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
wc -l)
1303 if [ "$traced" -eq 0 ]; then
1304 pass
"Validate empty trace"
1306 fail
"Validate empty trace"
1307 diag
"Found $traced events in trace"
1313 function metadata_regenerate
()
1315 local expected_to_fail
=$1
1318 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN metadata regenerate
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1320 if [[ $expected_to_fail -eq "1" ]]; then
1322 ok $?
"Expected fail on regenerate $sess_name"
1324 ok
$ret "Metadata regenerate $sess_name"
1328 function metadata_regenerate_ok
()
1330 metadata_regenerate
0 "$@"
1333 function metadata_regenerate_fail
()
1335 metadata_regenerate
1 "$@"
1338 function destructive_tests_enabled
()
1340 if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then