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 start_lttng_relayd
188 DIR
=$
(readlink
-f $TESTDIR)
190 if [ -z $
(pidof lt-
$RELAYD_BIN) ]; then
191 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN -b $opt >$OUTPUT_DEST
192 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
193 if [ $?
-eq 1 ]; then
194 fail
"Start lttng-relayd (opt: $opt)"
197 pass
"Start lttng-relayd (opt: $opt)"
200 pass
"Start lttng-relayd (opt: $opt)"
204 function stop_lttng_relayd_nocheck
206 PID_RELAYD
=`pidof lt-$RELAYD_BIN`
208 diag
"Killing lttng-relayd (pid: $PID_RELAYD)"
209 kill $PID_RELAYD >$OUTPUT_DEST
212 if [ $retval -eq 1 ]; then
214 while [ -n "$out" ]; do
215 out
=$
(pidof lt-
$RELAYD_BIN)
222 function stop_lttng_relayd
224 stop_lttng_relayd_nocheck
226 if [ $?
-eq 1 ]; then
227 fail
"Killed lttng-relayd (pid: $PID_RELAYD)"
230 pass
"Killed lttng-relayd (pid: $PID_RELAYD)"
235 #First argument: load path for automatic loading
236 function start_lttng_sessiond
()
240 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
241 # Env variable requested no session daemon
245 validate_kernel_version
246 if [ $?
-ne 0 ]; then
247 fail
"Start session daemon"
248 BAIL_OUT
"*** Kernel too old for session daemon tests ***"
251 DIR
=$
(readlink
-f $TESTDIR)
252 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
253 export LTTNG_SESSION_CONFIG_XSD_PATH
255 if [ -z $
(pidof lt-
$SESSIOND_BIN) ]; then
258 $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"
260 $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"
262 #$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 &
264 ok
$status "Start session daemon"
268 function stop_lttng_sessiond
()
270 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
271 # Env variable requested no session daemon
275 PID_SESSIOND
=`pidof lt-$SESSIOND_BIN`
277 kill $PID_SESSIOND >$OUTPUT_DEST
279 if [ $?
-eq 1 ]; then
280 fail
"Kill sessions daemon"
284 while [ -n "$out" ]; do
285 out
=$
(pidof lt-
$SESSIOND_BIN)
289 while [ -n "$out" ]; do
290 out
=$
(pidof
$CONSUMERD_BIN)
293 pass
"Kill session daemon"
297 function list_lttng_with_opts
()
300 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN list
$opts >$OUTPUT_DEST
301 ok $?
"Lttng-tool list command with option $opts"
304 function create_lttng_session_no_output
()
308 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name --no-output >$OUTPUT_DEST
309 ok $?
"Create session $sess_name in no-output mode"
312 function create_lttng_session
()
316 local expected_to_fail
=$3
318 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -o $trace_path > $OUTPUT_DEST
320 if [[ $expected_to_fail ]]; then
322 ok $?
"Expected fail on session creation $sess_name in $trace_path"
324 ok
$ret "Create session $sess_name in $trace_path"
328 function enable_ust_lttng_channel
()
331 local channel_name
=$2
334 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-u $channel_name -s $sess_name >$OUTPUT_DEST
336 if [[ $expect_fail ]]; then
338 ok $?
"Expected fail on ust channel creation $channel_name in $sess_name"
340 ok
$ret "Enable channel $channel_name for session $sess_name"
344 function disable_ust_lttng_channel
()
347 local channel_name
=$2
349 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-u $channel_name -s $sess_name >$OUTPUT_DEST
350 ok $?
"Disable channel $channel_name for session $sess_name"
353 function enable_lttng_mmap_overwrite_kernel_channel
()
356 local channel_name
=$2
358 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite >$OUTPUT_DEST
359 ok $?
"Enable channel $channel_name for session $sess_name"
362 function enable_lttng_mmap_overwrite_ust_channel
()
365 local channel_name
=$2
367 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite >$OUTPUT_DEST
368 ok $?
"Enable channel $channel_name for session $sess_name"
371 function enable_ust_lttng_event
()
374 local event_name
="$2"
375 local channel_name
=$3
376 local expected_to_fail
=$4
378 if [ -z $channel_name ]; then
379 # default channel if none specified
382 chan
="-c $channel_name"
385 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -u >$OUTPUT_DEST
387 if [[ $expected_to_fail ]]; then
389 ok $?
"Enable ust event $event_name for session $session_name on channel $channel_name failed as expected"
391 ok
$ret "Enable event $event_name for session $sess_name"
395 function enable_jul_lttng_event
()
401 if [ -z $channel_name ]; then
402 # default channel if none specified
405 chan
="-c $channel_name"
408 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -j >$OUTPUT_DEST
409 ok $?
"Enable JUL event $event_name for session $sess_name"
412 function enable_jul_lttng_event_loglevel
()
415 local event_name
="$2"
417 local channel_name
=$4
419 if [ -z $channel_name ]; then
420 # default channel if none specified
423 chan
="-c $channel_name"
426 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j >$OUTPUT_DEST
427 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
430 function enable_log4j_lttng_event
()
436 if [ -z $channel_name ]; then
437 # default channel if none specified
440 chan
="-c $channel_name"
443 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -l >$OUTPUT_DEST
444 ok $?
"Enable LOG4J event $event_name for session $sess_name"
447 function enable_log4j_lttng_event_loglevel
()
450 local event_name
="$2"
452 local channel_name
=$4
454 if [ -z $channel_name ]; then
455 # default channel if none specified
458 chan
="-c $channel_name"
461 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -l >$OUTPUT_DEST
462 ok $?
"Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
465 function enable_ust_lttng_event_filter
()
468 local event_name
="$2"
471 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --filter "$filter" >$OUTPUT_DEST
472 ok $?
"Enable event $event_name with filtering for session $sess_name"
475 function enable_ust_lttng_event_loglevel
()
478 local event_name
="$2"
481 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel >$OUTPUT_DEST
482 ok $?
"Enable event $event_name with loglevel $loglevel"
485 function enable_ust_lttng_event_loglevel_only
()
488 local event_name
="$2"
491 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel >$OUTPUT_DEST
492 ok $?
"Enable event $event_name with loglevel-only $loglevel"
495 function disable_ust_lttng_event
()
498 local event_name
="$2"
499 local channel_name
="$3"
501 if [ -z $channel_name ]; then
502 # default channel if none specified
505 chan
="-c $channel_name"
508 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name $chan -u >$OUTPUT_DEST
509 ok $?
"Disable event $event_name for session $sess_name"
512 function disable_jul_lttng_event
()
515 local event_name
="$2"
517 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
518 ok $?
"Disable JUL event $event_name for session $sess_name"
521 function disable_log4j_lttng_event
()
524 local event_name
="$2"
526 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -l >/dev
/null
2>&1
527 ok $?
"Disable LOG4J event $event_name for session $sess_name"
530 function start_lttng_tracing
()
533 local expected_to_fail
=$2
535 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name >$OUTPUT_DEST
537 if [[ $expected_to_fail ]]; then
539 ok $?
"Expected fail on start tracing for session: $sess_name"
541 ok
$ret "Start tracing for session $sess_name"
545 function stop_lttng_tracing
()
548 local expected_to_fail
=$2
550 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name >$OUTPUT_DEST
552 if [[ $expected_to_fail ]]; then
554 ok $?
"Expected fail on stop tracing for session: $sess_name"
556 ok
$ret "Stop lttng tracing for session $sess_name"
560 function destroy_lttng_session
()
563 local expected_to_fail
=$2
565 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name >$OUTPUT_DEST
567 if [[ $expected_to_fail ]]; then
569 ok $?
"Expected fail on session deletion $sess_name"
571 ok
$ret "Destroy session $sess_name"
575 function destroy_lttng_sessions
()
577 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
--all >$OUTPUT_DEST
578 ok $?
"Destroy all lttng sessions"
581 function lttng_snapshot_add_output
()
585 local expected_to_fail
=$3
587 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name file://$trace_path >$OUTPUT_DEST
589 if [[ $expected_to_fail ]]; then
591 ok $?
"Failed to add a snapshot output file://$trace_path as expected"
593 ok
$ret "Added snapshot output file://$trace_path"
597 function lttng_snapshot_del_output
()
601 local expected_to_fail
=$3
603 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output
-s $sess_name $id >$OUTPUT_DEST
605 if [[ $expected_to_fail ]]; then
607 ok $?
"Expect fail on deletion of snapshot output id $id"
609 ok
$ret "Deleted snapshot output id $id"
613 function lttng_snapshot_record
()
618 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot record
-s $sess_name >$OUTPUT_DEST
619 ok $?
"Snapshot recorded"
622 function lttng_snapshot_list
()
625 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output
-s $sess_name >$OUTPUT_DEST
626 ok $?
"Snapshot list"
629 function lttng_save
()
634 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN save
$sess_name $opts >$OUTPUT_DEST
635 ok $?
"Session successfully saved"
638 function lttng_load
()
642 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN load
$opts >$OUTPUT_DEST
643 ok $?
"Load command successful"
646 function trace_matches
()
652 which $BABELTRACE_BIN >/dev
/null
653 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
655 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
657 if [ "$count" -ne "$nr_iter" ]; then
659 diag
"$count events found in trace"
665 function trace_match_only
()
671 which $BABELTRACE_BIN >/dev
/null
672 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
674 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
675 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
677 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
678 pass
"Trace match with $total event $event_name"
681 diag
"$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
685 function validate_trace
690 which $BABELTRACE_BIN >/dev
/null
691 if [ $?
-ne 0 ]; then
692 skip
0 "Babeltrace binary not found. Skipping trace validation"
697 for i
in $event_name; do
698 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
699 if [ "$traced" -ne 0 ]; then
700 pass
"Validate trace for event $i, $traced events"
702 fail
"Validate trace for event $i"
703 diag
"Found $traced occurences of $i"
711 function validate_trace_exp
()
716 which $BABELTRACE_BIN >/dev
/null
717 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace validation"
719 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep ${event_exp} |
wc -l)
720 if [ "$traced" -ne 0 ]; then
721 pass
"Validate trace for expression '${event_exp}', $traced events"
723 fail
"Validate trace for expression '${event_exp}'"
724 diag
"Found $traced occurences of '${event_exp}'"
730 function validate_trace_only_exp
()
735 which $BABELTRACE_BIN >/dev
/null
736 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
738 local count
=$
($BABELTRACE_BIN $trace_path |
grep ${event_exp} |
wc -l)
739 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
741 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
742 pass
"Trace match with $total for expression '${event_exp}"
745 diag
"$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
751 function validate_trace_empty
()
755 which $BABELTRACE_BIN >/dev
/null
756 if [ $?
-ne 0 ]; then
757 skip
0 "Babeltrace binary not found. Skipping trace validation"
760 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
wc -l)
761 if [ "$traced" -eq 0 ]; then
762 pass
"Validate empty trace"
764 fail
"Validate empty trace"
765 diag
"Found $traced events in trace"