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 to "wait forever", so that
39 # basic tests don't have to worry about hitting timeouts on busy
40 # systems. Specialized tests should test those corner-cases.
41 export LTTNG_UST_REGISTER_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
130 local expected_to_fail
="$1"
132 local event_name
="$3"
133 local channel_name
="$4"
135 if [ -z "$event_name" ]; then
136 # Enable all event if no event name specified
140 if [ -z "$channel_name" ]; then
141 # default channel if none specified
144 chan
="-c $channel_name"
147 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
149 if [[ $expected_to_fail -eq "1" ]]; then
151 ok $?
"Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
153 ok
$ret "Enable kernel event $event_name for session $sess_name"
157 function enable_kernel_lttng_event_ok
()
159 enable_kernel_lttng_event
0 "$@"
162 function enable_kernel_lttng_event_fail
()
164 enable_kernel_lttng_event
1 "$@"
168 function lttng_enable_kernel_event
170 enable_kernel_lttng_event_ok
"$@"
173 function lttng_enable_kernel_syscall
()
175 local expected_to_fail
=$1
177 local syscall_name
=$3
178 local channel_name
=$4
180 if [ -z $syscall_name ]; then
181 # Enable all event if no syscall name specified
185 if [ -z $channel_name ]; then
186 # default channel if none specified
189 chan
="-c $channel_name"
192 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
194 if [[ $expected_to_fail -eq "1" ]]; then
196 ok $?
"Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
198 ok
$ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
202 function lttng_enable_kernel_syscall_ok
()
204 lttng_enable_kernel_syscall
0 "$@"
207 function lttng_enable_kernel_syscall_fail
()
209 lttng_enable_kernel_syscall
1 "$@"
212 function lttng_disable_kernel_syscall
()
214 local expected_to_fail
=$1
216 local syscall_name
=$3
217 local channel_name
=$4
219 if [ -z $syscall_name ]; then
220 # Enable all event if no syscall name specified
224 if [ -z $channel_name ]; then
225 # default channel if none specified
228 chan
="-c $channel_name"
231 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
--syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
234 if [[ $expected_to_fail -eq "1" ]]; then
236 ok $?
"Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
238 ok
$ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
242 function lttng_disable_kernel_syscall_ok
()
244 lttng_disable_kernel_syscall
0 "$@"
247 function lttng_disable_kernel_syscall_fail
()
249 lttng_disable_kernel_syscall
1 "$@"
252 function lttng_enable_kernel_channel
()
254 local expected_to_fail
=$1
256 local channel_name
=$3
258 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
260 if [[ $expected_to_fail -eq "1" ]]; then
262 ok $?
"Enable channel $channel_name for session $sess_name failed as expected"
264 ok
$ret "Enable channel $channel_name for session $sess_name"
268 function lttng_enable_kernel_channel_ok
()
270 lttng_enable_kernel_channel
0 "$@"
273 function lttng_enable_kernel_channel_fail
()
275 lttng_enable_kernel_channel
1 "$@"
278 function lttng_disable_kernel_channel
()
280 local expected_to_fail
=$1
282 local channel_name
=$3
284 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
286 if [[ $expected_to_fail -eq "1" ]]; then
288 ok $?
"Disable channel $channel_name for session $sess_name failed as expected"
290 ok
$ret "Disable channel $channel_name for session $sess_name"
294 function lttng_disable_kernel_channel_ok
()
296 lttng_disable_kernel_channel
0 "$@"
299 function lttng_disable_kernel_channel_fail
()
301 lttng_disable_kernel_channel
1 "$@"
304 function start_lttng_relayd_opt
()
309 DIR
=$
(readlink
-f $TESTDIR)
311 if [ -z $
(pgrep
$RELAYD_MATCH) ]; then
312 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
313 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
314 if [ $?
-eq 1 ]; then
315 if [ $withtap -eq "1" ]; then
316 fail
"Start lttng-relayd (opt: $opt)"
320 if [ $withtap -eq "1" ]; then
321 pass
"Start lttng-relayd (opt: $opt)"
325 pass
"Start lttng-relayd (opt: $opt)"
328 RELAYD_PIDS
=$
(pgrep
$RELAYD_MATCH)
331 function start_lttng_relayd
()
333 start_lttng_relayd_opt
1 "$@"
336 function start_lttng_relayd_notap
()
338 start_lttng_relayd_opt
0 "$@"
341 function stop_lttng_relayd_opt
()
345 if [ $withtap -eq "1" ]; then
346 diag
"Killing lttng-relayd (pid: $RELAYD_PIDS)"
348 kill $RELAYD_PIDS 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
351 if [ $?
-eq 1 ]; then
352 if [ $withtap -eq "1" ]; then
353 fail
"Kill relay daemon"
358 while [ -n "$out" ]; do
359 out
=$
(pgrep
$RELAYD_MATCH)
362 if [ $withtap -eq "1" ]; then
363 pass
"Kill relay daemon"
370 function stop_lttng_relayd
()
372 stop_lttng_relayd_opt
1 "$@"
375 function stop_lttng_relayd_notap
()
377 stop_lttng_relayd_opt
0 "$@"
380 #First arg: show tap output
381 #Second argument: load path for automatic loading
382 function start_lttng_sessiond_opt
()
387 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
388 # Env variable requested no session daemon
392 validate_kernel_version
393 if [ $?
-ne 0 ]; then
394 fail
"Start session daemon"
395 BAIL_OUT
"*** Kernel too old for session daemon tests ***"
398 DIR
=$
(readlink
-f $TESTDIR)
399 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
400 export LTTNG_SESSION_CONFIG_XSD_PATH
402 if [ -z $
(pgrep
${SESSIOND_MATCH}) ]; then
404 if [ -n "$load_path" ]; then
405 $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"
407 $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"
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" --verbose-consumer >>/tmp/sessiond.log 2>&1
411 if [ $withtap -eq "1" ]; then
412 ok
$status "Start session daemon"
415 SESSIOND_PIDS
=$
(pgrep
$SESSIOND_MATCH)
418 function start_lttng_sessiond
()
420 start_lttng_sessiond_opt
1 "$@"
423 function start_lttng_sessiond_notap
()
425 start_lttng_sessiond_opt
0 "$@"
428 function stop_lttng_sessiond_opt
()
434 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
435 # Env variable requested no session daemon
439 local pids
="${SESSIOND_PIDS} $(pgrep $RUNAS_MATCH)"
442 kill_opt
="$kill_opt -s $signal"
444 if [ $withtap -eq "1" ]; then
445 diag
"Killing $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo $pids | tr '\n' ' ')"
447 kill $kill_opt $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
449 if [ $?
-eq 1 ]; then
450 if [ $withtap -eq "1" ]; then
451 fail
"Kill sessions daemon"
455 while [ -n "$out" ]; do
456 out
=$
(pgrep
${SESSIOND_MATCH})
460 while [ -n "$out" ]; do
461 out
=$
(pgrep
$CONSUMERD_MATCH)
466 if [ $withtap -eq "1" ]; then
467 pass
"Kill session daemon"
472 function stop_lttng_sessiond
()
474 stop_lttng_sessiond_opt
1 "$@"
477 function stop_lttng_sessiond_notap
()
479 stop_lttng_sessiond_opt
0 "$@"
482 function sigstop_lttng_sessiond_opt
()
488 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
489 # Env variable requested no session daemon
493 PID_SESSIOND
="$(pgrep ${SESSIOND_MATCH}) $(pgrep $RUNAS_MATCH)"
495 kill_opt
="$kill_opt -s $signal"
497 if [ $withtap -eq "1" ]; then
498 diag
"Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo $PID_SESSIOND | tr '\n' ' ')"
500 kill $kill_opt $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
502 if [ $?
-eq 1 ]; then
503 if [ $withtap -eq "1" ]; then
504 fail
"Sending SIGSTOP to session daemon"
508 while [ $out -ne 0 ]; do
509 pid
=$
(pgrep
$SESSIOND_MATCH)
511 # Wait until state becomes stopped for session
514 for sessiond_pid
in $pid; do
515 state
=$
(ps
-p $sessiond_pid -o state
= )
516 if [[ -n "$state" && "$state" != "T" ]]; then
522 if [ $withtap -eq "1" ]; then
523 pass
"Sending SIGSTOP to session daemon"
528 function sigstop_lttng_sessiond
()
530 sigstop_lttng_sessiond_opt
1 "$@"
533 function sigstop_lttng_sessiond_notap
()
535 sigstop_lttng_sessiond_opt
0 "$@"
538 function stop_lttng_consumerd_opt
()
544 PID_CONSUMERD
=$
(pgrep
$CONSUMERD_MATCH)
547 kill_opt
="$kill_opt -s $signal"
550 if [ $withtap -eq "1" ]; then
551 diag
"Killing $CONSUMERD_BIN pids: $(echo $PID_CONSUMERD | tr '\n' ' ')"
553 kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
557 if [ $?
-eq 1 ]; then
558 if [ $withtap -eq "1" ]; then
559 fail
"Kill consumer daemon"
564 while [ $out -ne 0 ]; do
565 pid
=$
(pgrep
$CONSUMERD_MATCH)
567 # If consumerds are still present check their status.
568 # A zombie status qualifies the consumerd as *killed*
570 for consumer_pid
in $pid; do
571 state
=$
(ps
-p $consumer_pid -o state
= )
572 if [[ -n "$state" && "$state" != "Z" ]]; then
578 if [ $withtap -eq "1" ]; then
579 pass
"Kill consumer daemon"
585 function stop_lttng_consumerd
()
587 stop_lttng_consumerd_opt
1 "$@"
590 function stop_lttng_consumerd_notap
()
592 stop_lttng_consumerd_opt
0 "$@"
595 function sigstop_lttng_consumerd_opt
()
601 PID_CONSUMERD
=$
(pgrep
$CONSUMERD_MATCH)
603 kill_opt
="$kill_opt -s $signal"
605 if [ $withtap -eq "1" ]; then
606 diag
"Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo $PID_CONSUMERD | tr '\n' ' ')"
608 kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
612 if [ $?
-eq 1 ]; then
613 if [ $withtap -eq "1" ]; then
614 fail
"Sending SIGSTOP to consumer daemon"
619 while [ $out -ne 0 ]; do
620 pid
=$
(pgrep
$CONSUMERD_MATCH)
622 # Wait until state becomes stopped for all
625 for consumer_pid
in $pid; do
626 state
=$
(ps
-p $consumer_pid -o state
= )
627 if [[ -n "$state" && "$state" != "T" ]]; then
633 if [ $withtap -eq "1" ]; then
634 pass
"Sending SIGSTOP to consumer daemon"
640 function sigstop_lttng_consumerd
()
642 sigstop_lttng_consumerd_opt
1 "$@"
645 function sigstop_lttng_consumerd_notap
()
647 sigstop_lttng_consumerd_opt
0 "$@"
650 function list_lttng_with_opts
()
653 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN list
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
654 ok $?
"Lttng-tool list command with option $opts"
657 function create_lttng_session_no_output
()
661 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name --no-output 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
662 ok $?
"Create session $sess_name in no-output mode"
665 function create_lttng_session
()
667 local expected_to_fail
=$1
672 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -o $trace_path $opt > $OUTPUT_DEST
674 if [[ $expected_to_fail -eq "1" ]]; then
676 ok $?
"Create session $sess_name in $trace_path failed as expected"
678 ok
$ret "Create session $sess_name in $trace_path"
682 function create_lttng_session_ok
()
684 create_lttng_session
0 "$@"
687 function create_lttng_session_fail
()
689 create_lttng_session
1 "$@"
693 function enable_ust_lttng_channel
()
695 local expected_to_fail
=$1
697 local channel_name
=$3
700 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-u $channel_name -s $sess_name $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
702 if [[ $expected_to_fail -eq "1" ]]; then
704 ok $?
"Enable channel $channel_name for session $sess_name failed as expected"
706 ok
$ret "Enable channel $channel_name for session $sess_name"
710 function enable_ust_lttng_channel_ok
()
712 enable_ust_lttng_channel
0 "$@"
715 function enable_ust_lttng_channel_fail
()
717 enable_ust_lttng_channel
1 "$@"
720 function disable_ust_lttng_channel
()
723 local channel_name
=$2
725 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
726 ok $?
"Disable channel $channel_name for session $sess_name"
729 function enable_lttng_mmap_overwrite_kernel_channel
()
732 local channel_name
=$2
734 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
735 ok $?
"Enable channel $channel_name for session $sess_name"
738 function enable_lttng_mmap_discard_small_kernel_channel
()
741 local channel_name
=$2
743 $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
744 ok $?
"Enable small discard channel $channel_name for session $sess_name"
747 function enable_lttng_mmap_overwrite_small_kernel_channel
()
750 local channel_name
=$2
752 $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
753 ok $?
"Enable small discard channel $channel_name for session $sess_name"
756 function enable_lttng_mmap_overwrite_ust_channel
()
759 local channel_name
=$2
761 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
762 ok $?
"Enable channel $channel_name for session $sess_name"
765 function enable_ust_lttng_event
()
767 local expected_to_fail
=$1
769 local event_name
="$3"
770 local channel_name
=$4
772 if [ -z $channel_name ]; then
773 # default channel if none specified
776 chan
="-c $channel_name"
779 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
781 if [[ $expected_to_fail -eq "1" ]]; then
783 ok $?
"Enable ust event $event_name for session $session_name failed as expected"
785 ok
$ret "Enable ust event $event_name for session $sess_name"
789 function enable_ust_lttng_event_ok
()
791 enable_ust_lttng_event
0 "$@"
794 function enable_ust_lttng_event_fail
()
796 enable_ust_lttng_event
1 "$@"
799 function enable_jul_lttng_event
()
805 if [ -z $channel_name ]; then
806 # default channel if none specified
809 chan
="-c $channel_name"
812 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
813 ok $?
"Enable JUL event $event_name for session $sess_name"
816 function enable_jul_lttng_event_loglevel
()
819 local event_name
="$2"
821 local channel_name
=$4
823 if [ -z $channel_name ]; then
824 # default channel if none specified
827 chan
="-c $channel_name"
830 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
831 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
834 function enable_log4j_lttng_event
()
840 if [ -z $channel_name ]; then
841 # default channel if none specified
844 chan
="-c $channel_name"
847 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
848 ok $?
"Enable LOG4J event $event_name for session $sess_name"
851 function enable_log4j_lttng_event_loglevel
()
854 local event_name
="$2"
856 local channel_name
=$4
858 if [ -z $channel_name ]; then
859 # default channel if none specified
862 chan
="-c $channel_name"
865 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
866 ok $?
"Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
869 function enable_python_lttng_event
()
875 if [ -z $channel_name ]; then
876 # default channel if none specified
879 chan
="-c $channel_name"
882 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
883 ok $?
"Enable Python event $event_name for session $sess_name"
886 function enable_python_lttng_event_loglevel
()
889 local event_name
="$2"
891 local channel_name
=$4
893 if [ -z $channel_name ]; then
894 # default channel if none specified
897 chan
="-c $channel_name"
900 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
901 ok $?
"Enable Python event $event_name for session $sess_name with loglevel $loglevel"
904 function enable_ust_lttng_event_filter
()
907 local event_name
="$2"
910 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
911 ok $?
"Enable event $event_name with filtering for session $sess_name"
914 function enable_ust_lttng_event_loglevel
()
917 local event_name
="$2"
920 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
921 ok $?
"Enable event $event_name with loglevel $loglevel"
924 function enable_ust_lttng_event_loglevel_only
()
927 local event_name
="$2"
930 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
931 ok $?
"Enable event $event_name with loglevel-only $loglevel"
934 function disable_ust_lttng_event
()
937 local event_name
="$2"
938 local channel_name
="$3"
940 if [ -z $channel_name ]; then
941 # default channel if none specified
944 chan
="-c $channel_name"
947 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
948 ok $?
"Disable event $event_name for session $sess_name"
951 function disable_jul_lttng_event
()
954 local event_name
="$2"
956 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
957 ok $?
"Disable JUL event $event_name for session $sess_name"
960 function disable_log4j_lttng_event
()
963 local event_name
="$2"
965 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -l >/dev
/null
2>&1
966 ok $?
"Disable LOG4J event $event_name for session $sess_name"
969 function disable_python_lttng_event
()
972 local event_name
="$2"
974 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
975 ok $?
"Disable Python event $event_name for session $sess_name"
978 function start_lttng_tracing
()
980 local expected_to_fail
=$1
983 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
985 if [[ $expected_to_fail -eq "1" ]]; then
987 ok $?
"Start tracing for session $sess_name failed as expected"
989 ok
$ret "Start tracing for session $sess_name"
993 function start_lttng_tracing_ok
()
995 start_lttng_tracing
0 "$@"
998 function start_lttng_tracing_fail
()
1000 start_lttng_tracing
1 "$@"
1003 function stop_lttng_tracing
()
1005 local expected_to_fail
=$1
1008 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1010 if [[ $expected_to_fail -eq "1" ]]; then
1012 ok $?
"Stop lttng tracing for session $sess_name failed as expected"
1014 ok
$ret "Stop lttng tracing for session $sess_name"
1018 function stop_lttng_tracing_ok
()
1020 stop_lttng_tracing
0 "$@"
1023 function stop_lttng_tracing_fail
()
1025 stop_lttng_tracing
1 "$@"
1028 function destroy_lttng_session
()
1030 local expected_to_fail
=$1
1033 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1035 if [[ $expected_to_fail -eq "1" ]]; then
1037 ok $?
"Destroy session $sess_name failed as expected"
1039 ok
$ret "Destroy session $sess_name"
1043 function destroy_lttng_session_ok
()
1045 destroy_lttng_session
0 "$@"
1049 function destroy_lttng_session_fail
()
1051 destroy_lttng_session
1 "$@"
1055 function destroy_lttng_sessions
()
1057 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
--all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1058 ok $?
"Destroy all lttng sessions"
1061 function lttng_snapshot_add_output
()
1063 local expected_to_fail
=$1
1067 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name file://$trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1069 if [[ $expected_to_fail -eq 1 ]]; then
1071 ok $?
"Added snapshot output file://$trace_path failed as expected"
1073 ok
$ret "Added snapshot output file://$trace_path"
1077 function lttng_snapshot_add_output_ok
()
1079 lttng_snapshot_add_output
0 "$@"
1082 function lttng_snapshot_add_output_fail
()
1084 lttng_snapshot_add_output
1 "$@"
1087 function lttng_snapshot_del_output
()
1089 local expected_to_fail
=$1
1093 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output
-s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1095 if [[ $expected_to_fail -eq "1" ]]; then
1097 ok $?
"Deleted snapshot output id $id failed as expected"
1099 ok
$ret "Deleted snapshot output id $id"
1103 function lttng_snapshot_del_output_ok
()
1105 lttng_snapshot_del_output
0 "$@"
1108 function lttng_snapshot_del_output_fail
()
1110 lttng_snapshot_del_output
1 "$@"
1113 function lttng_snapshot_record
()
1118 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot record
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1119 ok $?
"Snapshot recorded"
1122 function lttng_snapshot_list
()
1125 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1126 ok $?
"Snapshot list"
1129 function lttng_save
()
1134 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN save
$sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1135 ok $?
"Session saved"
1138 function lttng_load
()
1142 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN load
$opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1143 ok $?
"Load command with opts: $opts"
1146 function lttng_track
()
1148 local expected_to_fail
=$1
1150 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN track
$opts >$OUTPUT_DEST
1152 if [[ $expected_to_fail -eq "1" ]]; then
1154 ok $?
"Track command failed as expected with opts: $opts"
1156 ok
$ret "Track command with opts: $opts"
1160 function lttng_track_ok
()
1165 function lttng_track_fail
()
1170 function lttng_untrack
()
1172 local expected_to_fail
=$1
1174 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN untrack
$opts >$OUTPUT_DEST
1176 if [[ $expected_to_fail -eq "1" ]]; then
1178 ok $?
"Untrack command failed as expected with opts: $opts"
1180 ok
$ret "Untrack command with opts: $opts"
1184 function lttng_untrack_ok
()
1186 lttng_untrack
0 "$@"
1189 function lttng_untrack_fail
()
1191 lttng_untrack
1 "$@"
1194 function add_context_lttng
()
1196 local expected_to_fail
="$1"
1198 local session_name
="$3"
1199 local channel_name
="$4"
1202 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context
-s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1204 if [[ $expected_to_fail -eq "1" ]]; then
1206 ok $?
"Add context command failed as expected for type: $type"
1208 ok
$ret "Add context command for type: $type"
1212 function add_context_ust_ok
()
1214 add_context_lttng
0 -u "$@"
1217 function add_context_ust_fail
()
1219 add_context_lttng
1 -u "$@"
1222 function add_context_kernel_ok
()
1224 add_context_lttng
0 -k "$@"
1227 function add_context_kernel_fail
()
1229 add_context_lttng
1 -k "$@"
1232 function trace_matches
()
1238 which $BABELTRACE_BIN >/dev
/null
1239 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1241 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
1243 if [ "$count" -ne "$nr_iter" ]; then
1245 diag
"$count matching events found in trace"
1251 function trace_match_only
()
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)
1261 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1263 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1264 pass
"Trace match with $total event $event_name"
1267 diag
"$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1271 function validate_trace
1276 which $BABELTRACE_BIN >/dev
/null
1277 if [ $?
-ne 0 ]; then
1278 skip
0 "Babeltrace binary not found. Skipping trace validation"
1283 for i
in $event_name; do
1284 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1285 if [ "$traced" -ne 0 ]; then
1286 pass
"Validate trace for event $i, $traced events"
1288 fail
"Validate trace for event $i"
1289 diag
"Found $traced occurences of $i"
1297 function validate_trace_count
1301 local expected_count
=$3
1303 which $BABELTRACE_BIN >/dev
/null
1304 if [ $?
-ne 0 ]; then
1305 skip
0 "Babeltrace binary not found. Skipping trace validation"
1311 for i
in $event_name; do
1312 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
1313 if [ "$traced" -ne 0 ]; then
1314 pass
"Validate trace for event $i, $traced events"
1316 fail
"Validate trace for event $i"
1317 diag
"Found $traced occurences of $i"
1319 cnt
=$
(($cnt + $traced))
1322 test $cnt -eq $expected_count
1323 ok $?
"Read a total of $cnt events, expected $expected_count"
1326 function trace_first_line
1330 which $BABELTRACE_BIN >/dev
/null
1331 if [ $?
-ne 0 ]; then
1332 skip
0 "Babeltrace binary not found. Skipping trace validation"
1335 $BABELTRACE_BIN $trace_path 2>/dev
/null |
head -n 1
1338 function validate_trace_exp
()
1343 which $BABELTRACE_BIN >/dev
/null
1344 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace validation"
1346 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep ${event_exp} |
wc -l)
1347 if [ "$traced" -ne 0 ]; then
1348 pass
"Validate trace for expression '${event_exp}', $traced events"
1350 fail
"Validate trace for expression '${event_exp}'"
1351 diag
"Found $traced occurences of '${event_exp}'"
1357 function validate_trace_only_exp
()
1362 which $BABELTRACE_BIN >/dev
/null
1363 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
1365 local count
=$
($BABELTRACE_BIN $trace_path |
grep ${event_exp} |
wc -l)
1366 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
1368 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1369 pass
"Trace match with $total for expression '${event_exp}"
1372 diag
"$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1378 function validate_trace_empty
()
1382 which $BABELTRACE_BIN >/dev
/null
1383 if [ $?
-ne 0 ]; then
1384 skip
0 "Babeltrace binary not found. Skipping trace validation"
1387 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
wc -l)
1388 if [ "$traced" -eq 0 ]; then
1389 pass
"Validate empty trace"
1391 fail
"Validate empty trace"
1392 diag
"Found $traced events in trace"
1398 function regenerate_metadata
()
1400 local expected_to_fail
=$1
1403 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN regenerate metadata
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1405 if [[ $expected_to_fail -eq "1" ]]; then
1407 ok $?
"Expected fail on regenerate metadata $sess_name"
1409 ok
$ret "Metadata regenerate $sess_name"
1413 function regenerate_metadata_ok
()
1415 regenerate_metadata
0 "$@"
1418 function regenerate_metadata_fail
()
1420 regenerate_metadata
1 "$@"
1423 function regenerate_statedump
()
1425 local expected_to_fail
=$1
1428 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN regenerate statedump
-s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1430 if [[ $expected_to_fail -eq "1" ]]; then
1432 ok $?
"Expected fail on regenerate statedump $sess_name"
1434 ok
$ret "Metadata regenerate $sess_name"
1438 function regenerate_statedump_ok
()
1440 regenerate_statedump
0 "$@"
1443 function regenerate_statedump_fail
()
1445 regenerate_statedump
1 "$@"
1448 function destructive_tests_enabled
()
1450 if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then