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 SESSIOND_MATCH
=".*lttng-sess.*"
21 RUNAS_BIN
="lttng-runas"
22 RUNAS_MATCH
=".*lttng-runas.*"
23 CONSUMERD_BIN
="lttng-consumerd"
24 CONSUMERD_MATCH
=".*lttng-consumerd.*"
25 RELAYD_BIN
="lttng-relayd"
26 RELAYD_MATCH
=".*lttng-relayd.*"
29 BABELTRACE_BIN
="babeltrace"
31 ERROR_OUTPUT_DEST
=/dev
/null
33 # Minimal kernel version supported for session daemon tests
34 KERNEL_MAJOR_VERSION
=2
35 KERNEL_MINOR_VERSION
=6
36 KERNEL_PATCHLEVEL_VERSION
=27
38 # We set the default UST register timeout and network and app socket timeout to
39 # "wait forever", so that basic tests don't have to worry about hitting
40 # timeouts on busy systems. Specialized tests should test those corner-cases.
41 export LTTNG_UST_REGISTER_TIMEOUT
=-1
42 export LTTNG_NETWORK_SOCKET_TIMEOUT
=-1
43 export LTTNG_APP_SOCKET_TIMEOUT
=-1
45 # We set the default lttng-sessiond path to /bin/true to prevent the spawning
46 # of a daemonized sessiond. This is necessary since 'lttng create' will spawn
47 # its own sessiond if none is running. It also ensures that 'lttng create'
48 # fails when no sessiond is running.
49 export LTTNG_SESSIOND_PATH
="/bin/true"
51 source $TESTDIR/utils
/tap
/tap.sh
53 function full_cleanup
()
55 if [ -n "${SESSIOND_PIDS}" ] ||
[ -n "${RELAYD_PIDS}" ]; then
56 kill -9 ${SESSIOND_PIDS} ${RELAYD_PIDS} > /dev
/null
2>&1
59 # Disable trap for SIGTERM since the following kill to the
60 # pidgroup will be SIGTERM. Otherwise it loops.
61 # The '-' before the pid number ($$) indicates 'kill' to signal the
62 # whole process group.
63 trap - SIGTERM
&& kill -- -$$
67 trap full_cleanup SIGINT SIGTERM
71 # Check if we are a terminal
73 echo -e "\e[1;32mOK\e[0m"
79 function print_fail
()
81 # Check if we are a terminal
83 echo -e "\e[1;31mFAIL\e[0m"
89 function print_test_banner
()
95 function validate_kernel_version
()
97 local kern_version
=($
(uname
-r |
awk -F.
'{ printf("%d.%d.%d\n",$1,$2,$3); }' |
tr '.' '\n'))
98 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
101 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
104 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
110 # Generate a random string
111 # $1 = number of characters; defaults to 16
112 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
113 function randstring
()
115 [ "$2" == "0" ] && CHAR
="[:alnum:]" || CHAR
="[:graph:]"
116 cat /dev
/urandom
2>/dev
/null |
tr -cd "$CHAR" 2>/dev
/null |
head -c ${1:-16} 2>/dev
/null
120 # Return the number of _configured_ CPUs.
121 function conf_proc_count
()
123 getconf _NPROCESSORS_CONF
124 if [ $?
-ne 0 ]; then
125 diag
"Failed to get the number of configured CPUs"
130 function enable_kernel_lttng_event
132 local expected_to_fail
="$1"
134 local event_name
="$3"
135 local channel_name
="$4"
137 if [ -z "$event_name" ]; then
138 # Enable all event if no event name specified
142 if [ -z "$channel_name" ]; then
143 # default channel if none specified
146 chan
="-c $channel_name"
149 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
151 if [[ $expected_to_fail -eq "1" ]]; then
153 ok $?
"Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
155 ok
$ret "Enable kernel event $event_name for session $sess_name"
159 function enable_kernel_lttng_event_ok
()
161 enable_kernel_lttng_event
0 "$@"
164 function enable_kernel_lttng_event_fail
()
166 enable_kernel_lttng_event
1 "$@"
170 function lttng_enable_kernel_event
172 enable_kernel_lttng_event_ok
"$@"
175 function lttng_enable_kernel_syscall
()
177 local expected_to_fail
=$1
179 local syscall_name
=$3
180 local channel_name
=$4
182 if [ -z $syscall_name ]; then
183 # Enable all event if no syscall name specified
187 if [ -z $channel_name ]; then
188 # default channel if none specified
191 chan
="-c $channel_name"
194 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
196 if [[ $expected_to_fail -eq "1" ]]; then
198 ok $?
"Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
200 ok
$ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
204 function lttng_enable_kernel_syscall_ok
()
206 lttng_enable_kernel_syscall
0 "$@"
209 function lttng_enable_kernel_syscall_fail
()
211 lttng_enable_kernel_syscall
1 "$@"
214 function lttng_disable_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 disable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
236 if [[ $expected_to_fail -eq "1" ]]; then
238 ok $?
"Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
240 ok
$ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
244 function lttng_disable_kernel_syscall_ok
()
246 lttng_disable_kernel_syscall
0 "$@"
249 function lttng_disable_kernel_syscall_fail
()
251 lttng_disable_kernel_syscall
1 "$@"
254 function lttng_enable_kernel_channel
()
256 local expected_to_fail
=$1
258 local channel_name
=$3
260 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
262 if [[ $expected_to_fail -eq "1" ]]; then
264 ok $?
"Enable channel $channel_name for session $sess_name failed as expected"
266 ok
$ret "Enable channel $channel_name for session $sess_name"
270 function lttng_enable_kernel_channel_ok
()
272 lttng_enable_kernel_channel
0 "$@"
275 function lttng_enable_kernel_channel_fail
()
277 lttng_enable_kernel_channel
1 "$@"
280 function lttng_disable_kernel_channel
()
282 local expected_to_fail
=$1
284 local channel_name
=$3
286 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
288 if [[ $expected_to_fail -eq "1" ]]; then
290 ok $?
"Disable channel $channel_name for session $sess_name failed as expected"
292 ok
$ret "Disable channel $channel_name for session $sess_name"
296 function lttng_disable_kernel_channel_ok
()
298 lttng_disable_kernel_channel
0 "$@"
301 function lttng_disable_kernel_channel_fail
()
303 lttng_disable_kernel_channel
1 "$@"
306 function start_lttng_relayd_opt
()
311 DIR
=$
(readlink
-f $TESTDIR)
313 if [ -z $
(pgrep
$RELAYD_MATCH) ]; then
314 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
315 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
316 if [ $?
-eq 1 ]; then
317 if [ $withtap -eq "1" ]; then
318 fail
"Start lttng-relayd (opt: $opt)"
322 if [ $withtap -eq "1" ]; then
323 pass
"Start lttng-relayd (opt: $opt)"
327 pass
"Start lttng-relayd (opt: $opt)"
330 RELAYD_PIDS
=$
(pgrep
$RELAYD_MATCH)
333 function start_lttng_relayd
()
335 start_lttng_relayd_opt
1 "$@"
338 function start_lttng_relayd_notap
()
340 start_lttng_relayd_opt
0 "$@"
343 function stop_lttng_relayd_opt
()
347 if [ $withtap -eq "1" ]; then
348 diag
"Killing lttng-relayd (pid: $RELAYD_PIDS)"
350 kill $RELAYD_PIDS 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
353 if [ $?
-eq 1 ]; then
354 if [ $withtap -eq "1" ]; then
355 fail
"Kill relay daemon"
360 while [ -n "$out" ]; do
361 out
=$
(pgrep
$RELAYD_MATCH)
364 if [ $withtap -eq "1" ]; then
365 pass
"Kill relay daemon"
372 function stop_lttng_relayd
()
374 stop_lttng_relayd_opt
1 "$@"
377 function stop_lttng_relayd_notap
()
379 stop_lttng_relayd_opt
0 "$@"
382 #First arg: show tap output
383 #Second argument: load path for automatic loading
384 function start_lttng_sessiond_opt
()
389 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
390 # Env variable requested no session daemon
394 validate_kernel_version
395 if [ $?
-ne 0 ]; then
396 fail
"Start session daemon"
397 BAIL_OUT
"*** Kernel too old for session daemon tests ***"
400 DIR
=$
(readlink
-f $TESTDIR)
401 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
402 export LTTNG_SESSION_CONFIG_XSD_PATH
404 if [ -z $
(pgrep
${SESSIOND_MATCH}) ]; then
406 if [ -n "$load_path" ]; then
407 $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"
409 $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"
411 #$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
413 if [ $withtap -eq "1" ]; then
414 ok
$status "Start session daemon"
417 SESSIOND_PIDS
=$
(pgrep
$SESSIOND_MATCH)
420 function start_lttng_sessiond
()
422 start_lttng_sessiond_opt
1 "$@"
425 function start_lttng_sessiond_notap
()
427 start_lttng_sessiond_opt
0 "$@"
430 function stop_lttng_sessiond_opt
()
436 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
437 # Env variable requested no session daemon
441 local pids
="${SESSIOND_PIDS} $(pgrep $RUNAS_MATCH)"
444 kill_opt
="$kill_opt -s $signal"
446 if [ $withtap -eq "1" ]; then
447 diag
"Killing $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo $pids | tr '\n' ' ')"
449 kill $kill_opt $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
451 if [ $?
-eq 1 ]; then
452 if [ $withtap -eq "1" ]; then
453 fail
"Kill sessions daemon"
457 while [ -n "$out" ]; do
458 out
=$
(pgrep
${SESSIOND_MATCH})
462 while [ -n "$out" ]; do
463 out
=$
(pgrep
$CONSUMERD_MATCH)
468 if [ $withtap -eq "1" ]; then
469 pass
"Kill session daemon"
474 function stop_lttng_sessiond
()
476 stop_lttng_sessiond_opt
1 "$@"
479 function stop_lttng_sessiond_notap
()
481 stop_lttng_sessiond_opt
0 "$@"
484 function sigstop_lttng_sessiond_opt
()
490 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
491 # Env variable requested no session daemon
495 PID_SESSIOND
="$(pgrep ${SESSIOND_MATCH}) $(pgrep $RUNAS_MATCH)"
497 kill_opt
="$kill_opt -s $signal"
499 if [ $withtap -eq "1" ]; then
500 diag
"Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo $PID_SESSIOND | tr '\n' ' ')"
502 kill $kill_opt $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
504 if [ $?
-eq 1 ]; then
505 if [ $withtap -eq "1" ]; then
506 fail
"Sending SIGSTOP to session daemon"
510 while [ $out -ne 0 ]; do
511 pid
=$
(pgrep
$SESSIOND_MATCH)
513 # Wait until state becomes stopped for session
516 for sessiond_pid
in $pid; do
517 state
=$
(ps
-p $sessiond_pid -o state
= )
518 if [[ -n "$state" && "$state" != "T" ]]; then
524 if [ $withtap -eq "1" ]; then
525 pass
"Sending SIGSTOP to session daemon"
530 function sigstop_lttng_sessiond
()
532 sigstop_lttng_sessiond_opt
1 "$@"
535 function sigstop_lttng_sessiond_notap
()
537 sigstop_lttng_sessiond_opt
0 "$@"
540 function stop_lttng_consumerd_opt
()
546 PID_CONSUMERD
=$
(pgrep
$CONSUMERD_MATCH)
549 kill_opt
="$kill_opt -s $signal"
552 if [ $withtap -eq "1" ]; then
553 diag
"Killing $CONSUMERD_BIN pids: $(echo $PID_CONSUMERD | tr '\n' ' ')"
555 kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
559 if [ $?
-eq 1 ]; then
560 if [ $withtap -eq "1" ]; then
561 fail
"Kill consumer daemon"
566 while [ $out -ne 0 ]; do
567 pid
=$
(pgrep
$CONSUMERD_MATCH)
569 # If consumerds are still present check their status.
570 # A zombie status qualifies the consumerd as *killed*
572 for consumer_pid
in $pid; do
573 state
=$
(ps
-p $consumer_pid -o state
= )
574 if [[ -n "$state" && "$state" != "Z" ]]; then
580 if [ $withtap -eq "1" ]; then
581 pass
"Kill consumer daemon"
587 function stop_lttng_consumerd
()
589 stop_lttng_consumerd_opt
1 "$@"
592 function stop_lttng_consumerd_notap
()
594 stop_lttng_consumerd_opt
0 "$@"
597 function sigstop_lttng_consumerd_opt
()
603 PID_CONSUMERD
=$
(pgrep
$CONSUMERD_MATCH)
605 kill_opt
="$kill_opt -s $signal"
607 if [ $withtap -eq "1" ]; then
608 diag
"Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo $PID_CONSUMERD | tr '\n' ' ')"
610 kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
614 if [ $?
-eq 1 ]; then
615 if [ $withtap -eq "1" ]; then
616 fail
"Sending SIGSTOP to consumer daemon"
621 while [ $out -ne 0 ]; do
622 pid
=$
(pgrep
$CONSUMERD_MATCH)
624 # Wait until state becomes stopped for all
627 for consumer_pid
in $pid; do
628 state
=$
(ps
-p $consumer_pid -o state
= )
629 if [[ -n "$state" && "$state" != "T" ]]; then
635 if [ $withtap -eq "1" ]; then
636 pass
"Sending SIGSTOP to consumer daemon"
642 function sigstop_lttng_consumerd
()
644 sigstop_lttng_consumerd_opt
1 "$@"
647 function sigstop_lttng_consumerd_notap
()
649 sigstop_lttng_consumerd_opt
0 "$@"
652 function list_lttng_with_opts
()
655 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN list
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
656 ok $?
"Lttng-tool list command with option $opts"
659 function create_lttng_session_no_output
()
663 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name --no-output 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
664 ok $?
"Create session $sess_name in no-output mode"
667 function create_lttng_session
()
669 local expected_to_fail
=$1
674 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -o $trace_path $opt > $OUTPUT_DEST
676 if [[ $expected_to_fail -eq "1" ]]; then
678 ok $?
"Create session $sess_name in $trace_path failed as expected"
680 ok
$ret "Create session $sess_name in $trace_path"
684 function create_lttng_session_ok
()
686 create_lttng_session
0 "$@"
689 function create_lttng_session_fail
()
691 create_lttng_session
1 "$@"
695 function enable_ust_lttng_channel
()
697 local expected_to_fail
=$1
699 local channel_name
=$3
702 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-u $channel_name -s $sess_name $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
704 if [[ $expected_to_fail -eq "1" ]]; then
706 ok $?
"Enable channel $channel_name for session $sess_name failed as expected"
708 ok
$ret "Enable channel $channel_name for session $sess_name"
712 function enable_ust_lttng_channel_ok
()
714 enable_ust_lttng_channel
0 "$@"
717 function enable_ust_lttng_channel_fail
()
719 enable_ust_lttng_channel
1 "$@"
722 function disable_ust_lttng_channel
()
725 local channel_name
=$2
727 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
728 ok $?
"Disable channel $channel_name for session $sess_name"
731 function enable_lttng_mmap_overwrite_kernel_channel
()
734 local channel_name
=$2
736 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
737 ok $?
"Enable channel $channel_name for session $sess_name"
740 function enable_lttng_mmap_overwrite_ust_channel
()
743 local channel_name
=$2
745 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
746 ok $?
"Enable channel $channel_name for session $sess_name"
749 function enable_ust_lttng_event
()
751 local expected_to_fail
=$1
753 local event_name
="$3"
754 local channel_name
=$4
756 if [ -z $channel_name ]; then
757 # default channel if none specified
760 chan
="-c $channel_name"
763 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
765 if [[ $expected_to_fail -eq "1" ]]; then
767 ok $?
"Enable ust event $event_name for session $session_name failed as expected"
769 ok
$ret "Enable ust event $event_name for session $sess_name"
773 function enable_ust_lttng_event_ok
()
775 enable_ust_lttng_event
0 "$@"
778 function enable_ust_lttng_event_fail
()
780 enable_ust_lttng_event
1 "$@"
783 function enable_jul_lttng_event
()
789 if [ -z $channel_name ]; then
790 # default channel if none specified
793 chan
="-c $channel_name"
796 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
797 ok $?
"Enable JUL event $event_name for session $sess_name"
800 function enable_jul_lttng_event_loglevel
()
803 local event_name
="$2"
805 local channel_name
=$4
807 if [ -z $channel_name ]; then
808 # default channel if none specified
811 chan
="-c $channel_name"
814 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
815 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
818 function enable_log4j_lttng_event
()
824 if [ -z $channel_name ]; then
825 # default channel if none specified
828 chan
="-c $channel_name"
831 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
832 ok $?
"Enable LOG4J event $event_name for session $sess_name"
835 function enable_log4j_lttng_event_loglevel
()
838 local event_name
="$2"
840 local channel_name
=$4
842 if [ -z $channel_name ]; then
843 # default channel if none specified
846 chan
="-c $channel_name"
849 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
850 ok $?
"Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
853 function enable_python_lttng_event
()
859 if [ -z $channel_name ]; then
860 # default channel if none specified
863 chan
="-c $channel_name"
866 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
867 ok $?
"Enable Python event $event_name for session $sess_name"
870 function enable_python_lttng_event_loglevel
()
873 local event_name
="$2"
875 local channel_name
=$4
877 if [ -z $channel_name ]; then
878 # default channel if none specified
881 chan
="-c $channel_name"
884 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
885 ok $?
"Enable Python event $event_name for session $sess_name with loglevel $loglevel"
888 function enable_ust_lttng_event_filter
()
891 local event_name
="$2"
894 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
895 ok $?
"Enable event $event_name with filtering for session $sess_name"
898 function enable_ust_lttng_event_loglevel
()
901 local event_name
="$2"
904 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
905 ok $?
"Enable event $event_name with loglevel $loglevel"
908 function enable_ust_lttng_event_loglevel_only
()
911 local event_name
="$2"
914 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
915 ok $?
"Enable event $event_name with loglevel-only $loglevel"
918 function disable_ust_lttng_event
()
921 local event_name
="$2"
922 local channel_name
="$3"
924 if [ -z $channel_name ]; then
925 # default channel if none specified
928 chan
="-c $channel_name"
931 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
932 ok $?
"Disable event $event_name for session $sess_name"
935 function disable_jul_lttng_event
()
938 local event_name
="$2"
940 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
941 ok $?
"Disable JUL event $event_name for session $sess_name"
944 function disable_log4j_lttng_event
()
947 local event_name
="$2"
949 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -l >/dev
/null
2>&1
950 ok $?
"Disable LOG4J event $event_name for session $sess_name"
953 function disable_python_lttng_event
()
956 local event_name
="$2"
958 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
959 ok $?
"Disable Python event $event_name for session $sess_name"
962 function start_lttng_tracing
()
964 local expected_to_fail
=$1
967 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
969 if [[ $expected_to_fail -eq "1" ]]; then
971 ok $?
"Start tracing for session $sess_name failed as expected"
973 ok
$ret "Start tracing for session $sess_name"
977 function start_lttng_tracing_ok
()
979 start_lttng_tracing
0 "$@"
982 function start_lttng_tracing_fail
()
984 start_lttng_tracing
1 "$@"
987 function stop_lttng_tracing
()
989 local expected_to_fail
=$1
992 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
994 if [[ $expected_to_fail -eq "1" ]]; then
996 ok $?
"Stop lttng tracing for session $sess_name failed as expected"
998 ok
$ret "Stop lttng tracing for session $sess_name"
1002 function stop_lttng_tracing_ok
()
1004 stop_lttng_tracing
0 "$@"
1007 function stop_lttng_tracing_fail
()
1009 stop_lttng_tracing
1 "$@"
1012 function destroy_lttng_session
()
1014 local expected_to_fail
=$1
1017 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1019 if [[ $expected_to_fail -eq "1" ]]; then
1021 ok $?
"Destroy session $sess_name failed as expected"
1023 ok
$ret "Destroy session $sess_name"
1027 function destroy_lttng_session_ok
()
1029 destroy_lttng_session
0 "$@"
1033 function destroy_lttng_session_fail
()
1035 destroy_lttng_session
1 "$@"
1039 function destroy_lttng_sessions
()
1041 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
--all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1042 ok $?
"Destroy all lttng sessions"
1045 function lttng_snapshot_add_output
()
1047 local expected_to_fail
=$1
1051 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name file://$trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1053 if [[ $expected_to_fail -eq 1 ]]; then
1055 ok $?
"Added snapshot output file://$trace_path failed as expected"
1057 ok
$ret "Added snapshot output file://$trace_path"
1061 function lttng_snapshot_add_output_ok
()
1063 lttng_snapshot_add_output
0 "$@"
1066 function lttng_snapshot_add_output_fail
()
1068 lttng_snapshot_add_output
1 "$@"
1071 function lttng_snapshot_del_output
()
1073 local expected_to_fail
=$1
1077 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output
-s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1079 if [[ $expected_to_fail -eq "1" ]]; then
1081 ok $?
"Deleted snapshot output id $id failed as expected"
1083 ok
$ret "Deleted snapshot output id $id"
1087 function lttng_snapshot_del_output_ok
()
1089 lttng_snapshot_del_output
0 "$@"
1092 function lttng_snapshot_del_output_fail
()
1094 lttng_snapshot_del_output
1 "$@"
1097 function lttng_snapshot_record
()
1102 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot record
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1103 ok $?
"Snapshot recorded"
1106 function lttng_snapshot_list
()
1109 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1110 ok $?
"Snapshot list"
1113 function lttng_save
()
1118 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN save
$sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1119 ok $?
"Session saved"
1122 function lttng_load
()
1126 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN load
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1127 ok $?
"Load command with opts: $opts"
1130 function lttng_track
()
1132 local expected_to_fail
=$1
1134 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN track
$opts >$OUTPUT_DEST
1136 if [[ $expected_to_fail -eq "1" ]]; then
1138 ok $?
"Track command failed as expected with opts: $opts"
1140 ok
$ret "Track command with opts: $opts"
1144 function lttng_track_ok
()
1149 function lttng_track_fail
()
1154 function lttng_untrack
()
1156 local expected_to_fail
=$1
1158 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN untrack
$opts >$OUTPUT_DEST
1160 if [[ $expected_to_fail -eq "1" ]]; then
1162 ok $?
"Untrack command failed as expected with opts: $opts"
1164 ok
$ret "Untrack command with opts: $opts"
1168 function lttng_untrack_ok
()
1170 lttng_untrack
0 "$@"
1173 function lttng_untrack_fail
()
1175 lttng_untrack
1 "$@"
1178 function add_context_lttng
()
1180 local expected_to_fail
="$1"
1182 local session_name
="$3"
1183 local channel_name
="$4"
1186 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context
-s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1188 if [[ $expected_to_fail -eq "1" ]]; then
1190 ok $?
"Add context command failed as expected for type: $type"
1192 ok
$ret "Add context command for type: $type"
1196 function add_context_ust_ok
()
1198 add_context_lttng
0 -u "$@"
1201 function add_context_ust_fail
()
1203 add_context_lttng
1 -u "$@"
1206 function add_context_kernel_ok
()
1208 add_context_lttng
0 -k "$@"
1211 function add_context_kernel_fail
()
1213 add_context_lttng
1 -k "$@"
1216 function trace_matches
()
1222 which $BABELTRACE_BIN >/dev
/null
1223 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1225 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1227 if [ "$count" -ne "$nr_iter" ]; then
1229 diag
"$count matching events found in trace"
1235 function trace_match_only
()
1241 which $BABELTRACE_BIN >/dev
/null
1242 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1244 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1245 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1247 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1248 pass
"Trace match with $total event $event_name"
1251 diag
"$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1255 function validate_trace
1260 which $BABELTRACE_BIN >/dev
/null
1261 if [ $?
-ne 0 ]; then
1262 skip
0 "Babeltrace binary not found. Skipping trace validation"
1267 for i
in $event_name; do
1268 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1269 if [ "$traced" -ne 0 ]; then
1270 pass
"Validate trace for event $i, $traced events"
1272 fail
"Validate trace for event $i"
1273 diag
"Found $traced occurences of $i"
1281 function validate_trace_exp
()
1286 which $BABELTRACE_BIN >/dev
/null
1287 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace validation"
1289 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep ${event_exp} |
wc -l)
1290 if [ "$traced" -ne 0 ]; then
1291 pass
"Validate trace for expression '${event_exp}', $traced events"
1293 fail
"Validate trace for expression '${event_exp}'"
1294 diag
"Found $traced occurences of '${event_exp}'"
1300 function validate_trace_only_exp
()
1305 which $BABELTRACE_BIN >/dev
/null
1306 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1308 local count
=$
($BABELTRACE_BIN $trace_path |
grep ${event_exp} |
wc -l)
1309 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1311 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1312 pass
"Trace match with $total for expression '${event_exp}"
1315 diag
"$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1321 function validate_trace_empty
()
1325 which $BABELTRACE_BIN >/dev
/null
1326 if [ $?
-ne 0 ]; then
1327 skip
0 "Babeltrace binary not found. Skipping trace validation"
1330 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
wc -l)
1331 if [ "$traced" -eq 0 ]; then
1332 pass
"Validate empty trace"
1334 fail
"Validate empty trace"
1335 diag
"Found $traced events in trace"
1341 function metadata_regenerate
()
1343 local expected_to_fail
=$1
1346 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN metadata regenerate
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1348 if [[ $expected_to_fail -eq "1" ]]; then
1350 ok $?
"Expected fail on regenerate $sess_name"
1352 ok
$ret "Metadata regenerate $sess_name"
1356 function metadata_regenerate_ok
()
1358 metadata_regenerate
0 "$@"
1361 function metadata_regenerate_fail
()
1363 metadata_regenerate
1 "$@"
1366 function destructive_tests_enabled
()
1368 if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then