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_discard_small_kernel_channel
()
743 local channel_name
=$2
745 $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
746 ok $?
"Enable small discard channel $channel_name for session $sess_name"
749 function enable_lttng_mmap_overwrite_small_kernel_channel
()
752 local channel_name
=$2
754 $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
755 ok $?
"Enable small discard channel $channel_name for session $sess_name"
758 function enable_lttng_mmap_overwrite_ust_channel
()
761 local channel_name
=$2
763 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
764 ok $?
"Enable channel $channel_name for session $sess_name"
767 function enable_ust_lttng_event
()
769 local expected_to_fail
=$1
771 local event_name
="$3"
772 local channel_name
=$4
774 if [ -z $channel_name ]; then
775 # default channel if none specified
778 chan
="-c $channel_name"
781 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
783 if [[ $expected_to_fail -eq "1" ]]; then
785 ok $?
"Enable ust event $event_name for session $session_name failed as expected"
787 ok
$ret "Enable ust event $event_name for session $sess_name"
791 function enable_ust_lttng_event_ok
()
793 enable_ust_lttng_event
0 "$@"
796 function enable_ust_lttng_event_fail
()
798 enable_ust_lttng_event
1 "$@"
801 function enable_jul_lttng_event
()
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
"$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"
818 function enable_jul_lttng_event_loglevel
()
821 local event_name
="$2"
823 local channel_name
=$4
825 if [ -z $channel_name ]; then
826 # default channel if none specified
829 chan
="-c $channel_name"
832 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
833 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
836 function enable_log4j_lttng_event
()
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
"$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"
853 function enable_log4j_lttng_event_loglevel
()
856 local event_name
="$2"
858 local channel_name
=$4
860 if [ -z $channel_name ]; then
861 # default channel if none specified
864 chan
="-c $channel_name"
867 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
868 ok $?
"Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
871 function enable_python_lttng_event
()
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
"$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"
888 function enable_python_lttng_event_loglevel
()
891 local event_name
="$2"
893 local channel_name
=$4
895 if [ -z $channel_name ]; then
896 # default channel if none specified
899 chan
="-c $channel_name"
902 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
903 ok $?
"Enable Python event $event_name for session $sess_name with loglevel $loglevel"
906 function enable_ust_lttng_event_filter
()
909 local event_name
="$2"
912 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
913 ok $?
"Enable event $event_name with filtering for session $sess_name"
916 function enable_ust_lttng_event_loglevel
()
919 local event_name
="$2"
922 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
923 ok $?
"Enable event $event_name with loglevel $loglevel"
926 function enable_ust_lttng_event_loglevel_only
()
929 local event_name
="$2"
932 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
933 ok $?
"Enable event $event_name with loglevel-only $loglevel"
936 function disable_ust_lttng_event
()
939 local event_name
="$2"
940 local channel_name
="$3"
942 if [ -z $channel_name ]; then
943 # default channel if none specified
946 chan
="-c $channel_name"
949 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
950 ok $?
"Disable event $event_name for session $sess_name"
953 function disable_jul_lttng_event
()
956 local event_name
="$2"
958 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
959 ok $?
"Disable JUL event $event_name for session $sess_name"
962 function disable_log4j_lttng_event
()
965 local event_name
="$2"
967 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -l >/dev
/null
2>&1
968 ok $?
"Disable LOG4J event $event_name for session $sess_name"
971 function disable_python_lttng_event
()
974 local event_name
="$2"
976 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
977 ok $?
"Disable Python event $event_name for session $sess_name"
980 function start_lttng_tracing
()
982 local expected_to_fail
=$1
985 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
987 if [[ $expected_to_fail -eq "1" ]]; then
989 ok $?
"Start tracing for session $sess_name failed as expected"
991 ok
$ret "Start tracing for session $sess_name"
995 function start_lttng_tracing_ok
()
997 start_lttng_tracing
0 "$@"
1000 function start_lttng_tracing_fail
()
1002 start_lttng_tracing
1 "$@"
1005 function stop_lttng_tracing
()
1007 local expected_to_fail
=$1
1010 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1012 if [[ $expected_to_fail -eq "1" ]]; then
1014 ok $?
"Stop lttng tracing for session $sess_name failed as expected"
1016 ok
$ret "Stop lttng tracing for session $sess_name"
1020 function stop_lttng_tracing_ok
()
1022 stop_lttng_tracing
0 "$@"
1025 function stop_lttng_tracing_fail
()
1027 stop_lttng_tracing
1 "$@"
1030 function destroy_lttng_session
()
1032 local expected_to_fail
=$1
1035 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1037 if [[ $expected_to_fail -eq "1" ]]; then
1039 ok $?
"Destroy session $sess_name failed as expected"
1041 ok
$ret "Destroy session $sess_name"
1045 function destroy_lttng_session_ok
()
1047 destroy_lttng_session
0 "$@"
1051 function destroy_lttng_session_fail
()
1053 destroy_lttng_session
1 "$@"
1057 function destroy_lttng_sessions
()
1059 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
--all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1060 ok $?
"Destroy all lttng sessions"
1063 function lttng_snapshot_add_output
()
1065 local expected_to_fail
=$1
1069 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name file://$trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1071 if [[ $expected_to_fail -eq 1 ]]; then
1073 ok $?
"Added snapshot output file://$trace_path failed as expected"
1075 ok
$ret "Added snapshot output file://$trace_path"
1079 function lttng_snapshot_add_output_ok
()
1081 lttng_snapshot_add_output
0 "$@"
1084 function lttng_snapshot_add_output_fail
()
1086 lttng_snapshot_add_output
1 "$@"
1089 function lttng_snapshot_del_output
()
1091 local expected_to_fail
=$1
1095 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output
-s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1097 if [[ $expected_to_fail -eq "1" ]]; then
1099 ok $?
"Deleted snapshot output id $id failed as expected"
1101 ok
$ret "Deleted snapshot output id $id"
1105 function lttng_snapshot_del_output_ok
()
1107 lttng_snapshot_del_output
0 "$@"
1110 function lttng_snapshot_del_output_fail
()
1112 lttng_snapshot_del_output
1 "$@"
1115 function lttng_snapshot_record
()
1120 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot record
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1121 ok $?
"Snapshot recorded"
1124 function lttng_snapshot_list
()
1127 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1128 ok $?
"Snapshot list"
1131 function lttng_save
()
1136 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN save
$sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1137 ok $?
"Session saved"
1140 function lttng_load
()
1142 local expected_to_fail
=$1
1145 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN load
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1147 if [[ $expected_to_fail -eq "1" ]]; then
1149 ok $?
"Load command failed as expected with opts: $opts"
1151 ok
$ret "Load command with opts: $opts"
1155 function lttng_load_ok
()
1160 function lttng_load_fail
()
1165 function lttng_track
()
1167 local expected_to_fail
=$1
1169 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN track
$opts >$OUTPUT_DEST
1171 if [[ $expected_to_fail -eq "1" ]]; then
1173 ok $?
"Track command failed as expected with opts: $opts"
1175 ok
$ret "Track command with opts: $opts"
1179 function lttng_track_ok
()
1184 function lttng_track_fail
()
1189 function lttng_untrack
()
1191 local expected_to_fail
=$1
1193 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN untrack
$opts >$OUTPUT_DEST
1195 if [[ $expected_to_fail -eq "1" ]]; then
1197 ok $?
"Untrack command failed as expected with opts: $opts"
1199 ok
$ret "Untrack command with opts: $opts"
1203 function lttng_untrack_ok
()
1205 lttng_untrack
0 "$@"
1208 function lttng_untrack_fail
()
1210 lttng_untrack
1 "$@"
1213 function add_context_lttng
()
1215 local expected_to_fail
="$1"
1217 local session_name
="$3"
1218 local channel_name
="$4"
1221 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context
-s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1223 if [[ $expected_to_fail -eq "1" ]]; then
1225 ok $?
"Add context command failed as expected for type: $type"
1227 ok
$ret "Add context command for type: $type"
1231 function add_context_ust_ok
()
1233 add_context_lttng
0 -u "$@"
1236 function add_context_ust_fail
()
1238 add_context_lttng
1 -u "$@"
1241 function add_context_kernel_ok
()
1243 add_context_lttng
0 -k "$@"
1246 function add_context_kernel_fail
()
1248 add_context_lttng
1 -k "$@"
1251 function trace_matches
()
1257 which $BABELTRACE_BIN >/dev
/null
1258 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1260 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1262 if [ "$count" -ne "$nr_iter" ]; then
1264 diag
"$count matching events found in trace"
1270 function trace_match_only
()
1276 which $BABELTRACE_BIN >/dev
/null
1277 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1279 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1280 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1282 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1283 pass
"Trace match with $total event $event_name"
1286 diag
"$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1290 function validate_trace
1295 which $BABELTRACE_BIN >/dev
/null
1296 if [ $?
-ne 0 ]; then
1297 skip
0 "Babeltrace binary not found. Skipping trace validation"
1302 for i
in $event_name; do
1303 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1304 if [ "$traced" -ne 0 ]; then
1305 pass
"Validate trace for event $i, $traced events"
1307 fail
"Validate trace for event $i"
1308 diag
"Found $traced occurences of $i"
1316 function validate_trace_count
1320 local expected_count
=$3
1322 which $BABELTRACE_BIN >/dev
/null
1323 if [ $?
-ne 0 ]; then
1324 skip
0 "Babeltrace binary not found. Skipping trace validation"
1330 for i
in $event_name; do
1331 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1332 if [ "$traced" -ne 0 ]; then
1333 pass
"Validate trace for event $i, $traced events"
1335 fail
"Validate trace for event $i"
1336 diag
"Found $traced occurences of $i"
1338 cnt
=$
(($cnt + $traced))
1341 test $cnt -eq $expected_count
1342 ok $?
"Read a total of $cnt events, expected $expected_count"
1345 function trace_first_line
1349 which $BABELTRACE_BIN >/dev
/null
1350 if [ $?
-ne 0 ]; then
1351 skip
0 "Babeltrace binary not found. Skipping trace validation"
1354 $BABELTRACE_BIN $trace_path 2>/dev
/null |
head -n 1
1357 function validate_trace_exp
()
1362 which $BABELTRACE_BIN >/dev
/null
1363 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace validation"
1365 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep ${event_exp} |
wc -l)
1366 if [ "$traced" -ne 0 ]; then
1367 pass
"Validate trace for expression '${event_exp}', $traced events"
1369 fail
"Validate trace for expression '${event_exp}'"
1370 diag
"Found $traced occurences of '${event_exp}'"
1376 function validate_trace_only_exp
()
1381 which $BABELTRACE_BIN >/dev
/null
1382 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1384 local count
=$
($BABELTRACE_BIN $trace_path |
grep ${event_exp} |
wc -l)
1385 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1387 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1388 pass
"Trace match with $total for expression '${event_exp}"
1391 diag
"$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1397 function validate_trace_empty
()
1401 which $BABELTRACE_BIN >/dev
/null
1402 if [ $?
-ne 0 ]; then
1403 skip
0 "Babeltrace binary not found. Skipping trace validation"
1406 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
wc -l)
1407 if [ "$traced" -eq 0 ]; then
1408 pass
"Validate empty trace"
1410 fail
"Validate empty trace"
1411 diag
"Found $traced events in trace"
1417 function regenerate_metadata
()
1419 local expected_to_fail
=$1
1422 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN regenerate metadata
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1424 if [[ $expected_to_fail -eq "1" ]]; then
1426 ok $?
"Expected fail on regenerate metadata $sess_name"
1428 ok
$ret "Metadata regenerate $sess_name"
1432 function regenerate_metadata_ok
()
1434 regenerate_metadata
0 "$@"
1437 function regenerate_metadata_fail
()
1439 regenerate_metadata
1 "$@"
1442 function regenerate_statedump
()
1444 local expected_to_fail
=$1
1447 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN regenerate statedump
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1449 if [[ $expected_to_fail -eq "1" ]]; then
1451 ok $?
"Expected fail on regenerate statedump $sess_name"
1453 ok
$ret "Metadata regenerate $sess_name"
1457 function regenerate_statedump_ok
()
1459 regenerate_statedump
0 "$@"
1462 function regenerate_statedump_fail
()
1464 regenerate_statedump
1 "$@"
1467 function destructive_tests_enabled
()
1469 if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then