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 CONSUMERD_BIN
="lttng-consumerd"
20 RELAYD_BIN
="lttng-relayd"
22 BABELTRACE_BIN
="babeltrace"
23 OUTPUT_DEST
=/dev
/null
2>&1
25 # Minimal kernel version supported for session daemon tests
26 KERNEL_MAJOR_VERSION
=2
27 KERNEL_MINOR_VERSION
=6
28 KERNEL_PATCHLEVEL_VERSION
=27
30 source $TESTDIR/utils
/tap
/tap.sh
34 # Check if we are a terminal
36 echo -e "\e[1;32mOK\e[0m"
42 function print_fail
()
44 # Check if we are a terminal
46 echo -e "\e[1;31mFAIL\e[0m"
52 function print_test_banner
()
58 function validate_kernel_version
()
60 local kern_version
=($
(uname
-r |
awk -F.
'{ printf("%d.%d.%d\n",$1,$2,$3); }' |
tr '.' '\n'))
61 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
64 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
67 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
73 # Generate a random string
74 # $1 = number of characters; defaults to 16
75 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
78 [ "$2" == "0" ] && CHAR
="[:alnum:]" || CHAR
="[:graph:]"
79 cat /dev
/urandom |
tr -cd "$CHAR" |
head -c ${1:-16}
83 function lttng_enable_kernel_event
89 if [ -z $event_name ]; then
90 # Enable all event if no event name specified
94 if [ -z $channel_name ]; then
95 # default channel if none specified
98 chan
="-c $channel_name"
101 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -k >$OUTPUT_DEST
102 ok $?
"Enable kernel event $event_name for session $sess_name"
105 function lttng_enable_kernel_syscall
()
107 local expected_to_fail
=$1
109 local syscall_name
=$3
110 local channel_name
=$4
112 if [ -z $syscall_name ]; then
113 # Enable all event if no syscall name specified
117 if [ -z $channel_name ]; then
118 # default channel if none specified
121 chan
="-c $channel_name"
124 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--syscall "$syscall_name" $chan -s $sess_name -k >$OUTPUT_DEST
126 if [[ $expected_to_fail -eq "1" ]]; then
128 ok $?
"Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
130 ok
$ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
134 function lttng_enable_kernel_syscall_ok
()
136 lttng_enable_kernel_syscall
0 ${*}
139 function lttng_enable_kernel_syscall_fail
()
141 lttng_enable_kernel_syscall
1 ${*}
144 function lttng_disable_kernel_syscall
()
146 local expected_to_fail
=$1
148 local syscall_name
=$3
149 local channel_name
=$4
151 if [ -z $syscall_name ]; then
152 # Enable all event if no syscall name specified
156 if [ -z $channel_name ]; then
157 # default channel if none specified
160 chan
="-c $channel_name"
163 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
--syscall "$syscall_name" $chan -s $sess_name -k >$OUTPUT_DEST
166 if [[ $expected_to_fail -eq "1" ]]; then
168 ok $?
"Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
170 ok
$ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
174 function lttng_disable_kernel_syscall_ok
()
176 lttng_disable_kernel_syscall
0 ${*}
179 function lttng_disable_kernel_syscall_fail
()
181 lttng_disable_kernel_syscall
1 ${*}
184 function lttng_enable_kernel_channel
()
186 local expected_to_fail
=$1
188 local channel_name
=$3
190 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-k $channel_name -s $sess_name >$OUTPUT_DEST
192 if [[ $expected_to_fail -eq "1" ]]; then
194 ok $?
"Expected failure on kernel channel creation $channel_name in $sess_name"
196 ok
$ret "Enable channel $channel_name for session $sess_name"
200 function lttng_enable_kernel_channel_ok
()
202 lttng_enable_kernel_channel
0 ${*}
205 function lttng_enable_kernel_channel_fail
()
207 lttng_enable_kernel_channel
1 ${*}
210 function lttng_disable_kernel_channel
()
212 local expected_to_fail
=$1
214 local channel_name
=$3
216 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-k $channel_name -s $sess_name >$OUTPUT_DEST
218 if [[ $expected_to_fail -eq "1" ]]; then
220 ok $?
"Expected failure on kernel channel creation $channel_name in $sess_name"
222 ok
$ret "disable channel $channel_name for session $sess_name"
226 function lttng_disable_kernel_channel_ok
()
228 lttng_disable_kernel_channel
0 ${*}
231 function lttng_disable_kernel_channel_fail
()
233 lttng_disable_kernel_channel
1 ${*}
236 function start_lttng_relayd
240 DIR
=$
(readlink
-f $TESTDIR)
242 if [ -z $
(pidof lt-
$RELAYD_BIN) ]; then
243 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN -b $opt >$OUTPUT_DEST
244 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
245 if [ $?
-eq 1 ]; then
246 fail
"Start lttng-relayd (opt: $opt)"
249 pass
"Start lttng-relayd (opt: $opt)"
252 pass
"Start lttng-relayd (opt: $opt)"
256 function stop_lttng_relayd_nocheck
258 PID_RELAYD
=`pidof lt-$RELAYD_BIN`
260 diag
"Killing lttng-relayd (pid: $PID_RELAYD)"
261 kill $PID_RELAYD >$OUTPUT_DEST
264 if [ $retval -eq 1 ]; then
266 while [ -n "$out" ]; do
267 out
=$
(pidof lt-
$RELAYD_BIN)
274 function stop_lttng_relayd
276 stop_lttng_relayd_nocheck
278 if [ $?
-eq 1 ]; then
279 fail
"Killed lttng-relayd (pid: $PID_RELAYD)"
282 pass
"Killed lttng-relayd (pid: $PID_RELAYD)"
287 #First argument: load path for automatic loading
288 function start_lttng_sessiond
()
292 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
293 # Env variable requested no session daemon
297 validate_kernel_version
298 if [ $?
-ne 0 ]; then
299 fail
"Start session daemon"
300 BAIL_OUT
"*** Kernel too old for session daemon tests ***"
303 DIR
=$
(readlink
-f $TESTDIR)
304 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
305 export LTTNG_SESSION_CONFIG_XSD_PATH
307 if [ -z $
(pidof lt-
$SESSIOND_BIN) ]; then
310 $DIR/..
/src
/bin
/lttng-sessiond
/$SESSIOND_BIN --load "$1" --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
312 $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"
314 #$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --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 &
316 ok
$status "Start session daemon"
320 function stop_lttng_sessiond
()
322 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
323 # Env variable requested no session daemon
327 PID_SESSIOND
=`pidof lt-$SESSIOND_BIN`
329 kill $PID_SESSIOND >$OUTPUT_DEST
331 if [ $?
-eq 1 ]; then
332 fail
"Kill sessions daemon"
336 while [ -n "$out" ]; do
337 out
=$
(pidof lt-
$SESSIOND_BIN)
341 while [ -n "$out" ]; do
342 out
=$
(pidof
$CONSUMERD_BIN)
345 pass
"Kill session daemon"
349 function list_lttng_with_opts
()
352 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN list
$opts >$OUTPUT_DEST
353 ok $?
"Lttng-tool list command with option $opts"
356 function create_lttng_session_no_output
()
360 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name --no-output >$OUTPUT_DEST
361 ok $?
"Create session $sess_name in no-output mode"
364 function create_lttng_session
()
368 local expected_to_fail
=$3
370 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -o $trace_path > $OUTPUT_DEST
372 if [[ $expected_to_fail ]]; then
374 ok $?
"Expected fail on session creation $sess_name in $trace_path"
376 ok
$ret "Create session $sess_name in $trace_path"
380 function enable_ust_lttng_channel
()
383 local channel_name
=$2
386 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-u $channel_name -s $sess_name >$OUTPUT_DEST
388 if [[ $expect_fail ]]; then
390 ok $?
"Expected fail on ust channel creation $channel_name in $sess_name"
392 ok
$ret "Enable channel $channel_name for session $sess_name"
396 function disable_ust_lttng_channel
()
399 local channel_name
=$2
401 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-u $channel_name -s $sess_name >$OUTPUT_DEST
402 ok $?
"Disable channel $channel_name for session $sess_name"
405 function enable_lttng_mmap_overwrite_kernel_channel
()
408 local channel_name
=$2
410 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite >$OUTPUT_DEST
411 ok $?
"Enable channel $channel_name for session $sess_name"
414 function enable_lttng_mmap_overwrite_ust_channel
()
417 local channel_name
=$2
419 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite >$OUTPUT_DEST
420 ok $?
"Enable channel $channel_name for session $sess_name"
423 function enable_ust_lttng_event
()
426 local event_name
="$2"
427 local channel_name
=$3
428 local expected_to_fail
=$4
430 if [ -z $channel_name ]; then
431 # default channel if none specified
434 chan
="-c $channel_name"
437 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -u >$OUTPUT_DEST
439 if [[ $expected_to_fail ]]; then
441 ok $?
"Enable ust event $event_name for session $session_name on channel $channel_name failed as expected"
443 ok
$ret "Enable event $event_name for session $sess_name"
447 function enable_jul_lttng_event
()
453 if [ -z $channel_name ]; then
454 # default channel if none specified
457 chan
="-c $channel_name"
460 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -j >$OUTPUT_DEST
461 ok $?
"Enable JUL event $event_name for session $sess_name"
464 function enable_jul_lttng_event_loglevel
()
467 local event_name
="$2"
469 local channel_name
=$4
471 if [ -z $channel_name ]; then
472 # default channel if none specified
475 chan
="-c $channel_name"
478 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j >$OUTPUT_DEST
479 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
482 function enable_log4j_lttng_event
()
488 if [ -z $channel_name ]; then
489 # default channel if none specified
492 chan
="-c $channel_name"
495 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -l >$OUTPUT_DEST
496 ok $?
"Enable LOG4J event $event_name for session $sess_name"
499 function enable_log4j_lttng_event_loglevel
()
502 local event_name
="$2"
504 local channel_name
=$4
506 if [ -z $channel_name ]; then
507 # default channel if none specified
510 chan
="-c $channel_name"
513 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -l >$OUTPUT_DEST
514 ok $?
"Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
517 function enable_python_lttng_event
()
523 if [ -z $channel_name ]; then
524 # default channel if none specified
527 chan
="-c $channel_name"
530 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -p >$OUTPUT_DEST
531 ok $?
"Enable Python event $event_name for session $sess_name"
534 function enable_python_lttng_event_loglevel
()
537 local event_name
="$2"
539 local channel_name
=$4
541 if [ -z $channel_name ]; then
542 # default channel if none specified
545 chan
="-c $channel_name"
548 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -p >$OUTPUT_DEST
549 ok $?
"Enable Python event $event_name for session $sess_name with loglevel $loglevel"
552 function enable_ust_lttng_event_filter
()
555 local event_name
="$2"
558 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --filter "$filter" >$OUTPUT_DEST
559 ok $?
"Enable event $event_name with filtering for session $sess_name"
562 function enable_ust_lttng_event_loglevel
()
565 local event_name
="$2"
568 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel >$OUTPUT_DEST
569 ok $?
"Enable event $event_name with loglevel $loglevel"
572 function enable_ust_lttng_event_loglevel_only
()
575 local event_name
="$2"
578 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel >$OUTPUT_DEST
579 ok $?
"Enable event $event_name with loglevel-only $loglevel"
582 function disable_ust_lttng_event
()
585 local event_name
="$2"
586 local channel_name
="$3"
588 if [ -z $channel_name ]; then
589 # default channel if none specified
592 chan
="-c $channel_name"
595 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name $chan -u >$OUTPUT_DEST
596 ok $?
"Disable event $event_name for session $sess_name"
599 function disable_jul_lttng_event
()
602 local event_name
="$2"
604 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
605 ok $?
"Disable JUL event $event_name for session $sess_name"
608 function disable_log4j_lttng_event
()
611 local event_name
="$2"
613 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -l >/dev
/null
2>&1
614 ok $?
"Disable LOG4J event $event_name for session $sess_name"
617 function disable_python_lttng_event
()
620 local event_name
="$2"
622 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -p >$OUTPUT_DEST
623 ok $?
"Disable Python event $event_name for session $sess_name"
626 function start_lttng_tracing
()
629 local expected_to_fail
=$2
631 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name >$OUTPUT_DEST
633 if [[ $expected_to_fail ]]; then
635 ok $?
"Expected fail on start tracing for session: $sess_name"
637 ok
$ret "Start tracing for session $sess_name"
641 function stop_lttng_tracing
()
644 local expected_to_fail
=$2
646 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name >$OUTPUT_DEST
648 if [[ $expected_to_fail ]]; then
650 ok $?
"Expected fail on stop tracing for session: $sess_name"
652 ok
$ret "Stop lttng tracing for session $sess_name"
656 function destroy_lttng_session
()
659 local expected_to_fail
=$2
661 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name >$OUTPUT_DEST
663 if [[ $expected_to_fail ]]; then
665 ok $?
"Expected fail on session deletion $sess_name"
667 ok
$ret "Destroy session $sess_name"
671 function destroy_lttng_sessions
()
673 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
--all >$OUTPUT_DEST
674 ok $?
"Destroy all lttng sessions"
677 function lttng_snapshot_add_output
()
681 local expected_to_fail
=$3
683 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name file://$trace_path >$OUTPUT_DEST
685 if [[ $expected_to_fail ]]; then
687 ok $?
"Failed to add a snapshot output file://$trace_path as expected"
689 ok
$ret "Added snapshot output file://$trace_path"
693 function lttng_snapshot_del_output
()
697 local expected_to_fail
=$3
699 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output
-s $sess_name $id >$OUTPUT_DEST
701 if [[ $expected_to_fail ]]; then
703 ok $?
"Expect fail on deletion of snapshot output id $id"
705 ok
$ret "Deleted snapshot output id $id"
709 function lttng_snapshot_record
()
714 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot record
-s $sess_name >$OUTPUT_DEST
715 ok $?
"Snapshot recorded"
718 function lttng_snapshot_list
()
721 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output
-s $sess_name >$OUTPUT_DEST
722 ok $?
"Snapshot list"
725 function lttng_save
()
730 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN save
$sess_name $opts >$OUTPUT_DEST
731 ok $?
"Session successfully saved"
734 function lttng_load
()
738 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN load
$opts >$OUTPUT_DEST
739 ok $?
"Load command successful"
742 function trace_matches
()
748 which $BABELTRACE_BIN >/dev
/null
749 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
751 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
753 if [ "$count" -ne "$nr_iter" ]; then
755 diag
"$count events found in trace"
761 function trace_match_only
()
767 which $BABELTRACE_BIN >/dev
/null
768 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
770 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
771 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
773 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
774 pass
"Trace match with $total event $event_name"
777 diag
"$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
781 function validate_trace
786 which $BABELTRACE_BIN >/dev
/null
787 if [ $?
-ne 0 ]; then
788 skip
0 "Babeltrace binary not found. Skipping trace validation"
793 for i
in $event_name; do
794 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
795 if [ "$traced" -ne 0 ]; then
796 pass
"Validate trace for event $i, $traced events"
798 fail
"Validate trace for event $i"
799 diag
"Found $traced occurences of $i"
807 function validate_trace_exp
()
812 which $BABELTRACE_BIN >/dev
/null
813 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace validation"
815 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep ${event_exp} |
wc -l)
816 if [ "$traced" -ne 0 ]; then
817 pass
"Validate trace for expression '${event_exp}', $traced events"
819 fail
"Validate trace for expression '${event_exp}'"
820 diag
"Found $traced occurences of '${event_exp}'"
826 function validate_trace_only_exp
()
831 which $BABELTRACE_BIN >/dev
/null
832 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
834 local count
=$
($BABELTRACE_BIN $trace_path |
grep ${event_exp} |
wc -l)
835 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
837 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
838 pass
"Trace match with $total for expression '${event_exp}"
841 diag
"$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
847 function validate_trace_empty
()
851 which $BABELTRACE_BIN >/dev
/null
852 if [ $?
-ne 0 ]; then
853 skip
0 "Babeltrace binary not found. Skipping trace validation"
856 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
wc -l)
857 if [ "$traced" -eq 0 ]; then
858 pass
"Validate empty trace"
860 fail
"Validate empty trace"
861 diag
"Found $traced events in trace"