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 start_lttng_relayd
109 DIR
=$
(readlink
-f $TESTDIR)
111 if [ -z $
(pidof lt-
$RELAYD_BIN) ]; then
112 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN -b $opt >$OUTPUT_DEST
113 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
114 if [ $?
-eq 1 ]; then
115 fail
"Start lttng-relayd (opt: $opt)"
118 pass
"Start lttng-relayd (opt: $opt)"
121 pass
"Start lttng-relayd (opt: $opt)"
125 function stop_lttng_relayd_nocheck
127 PID_RELAYD
=`pidof lt-$RELAYD_BIN`
129 diag
"Killing lttng-relayd (pid: $PID_RELAYD)"
130 kill $PID_RELAYD >$OUTPUT_DEST
133 if [ $retval -eq 1 ]; then
135 while [ -n "$out" ]; do
136 out
=$
(pidof lt-
$RELAYD_BIN)
143 function stop_lttng_relayd
145 stop_lttng_relayd_nocheck
147 if [ $?
-eq 1 ]; then
148 fail
"Killed lttng-relayd (pid: $PID_RELAYD)"
151 pass
"Killed lttng-relayd (pid: $PID_RELAYD)"
156 #First argument: load path for automatic loading
157 function start_lttng_sessiond
()
161 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
162 # Env variable requested no session daemon
166 validate_kernel_version
167 if [ $?
-ne 0 ]; then
168 fail
"Start session daemon"
169 BAIL_OUT
"*** Kernel too old for session daemon tests ***"
172 DIR
=$
(readlink
-f $TESTDIR)
173 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
174 export LTTNG_SESSION_CONFIG_XSD_PATH
176 if [ -z $
(pidof lt-
$SESSIOND_BIN) ]; then
179 $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"
181 $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"
183 #$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 &
185 ok
$status "Start session daemon"
189 function stop_lttng_sessiond
()
191 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
192 # Env variable requested no session daemon
196 PID_SESSIOND
=`pidof lt-$SESSIOND_BIN`
198 kill $PID_SESSIOND >$OUTPUT_DEST
200 if [ $?
-eq 1 ]; then
201 fail
"Kill sessions daemon"
205 while [ -n "$out" ]; do
206 out
=$
(pidof lt-
$SESSIOND_BIN)
210 while [ -n "$out" ]; do
211 out
=$
(pidof
$CONSUMERD_BIN)
214 pass
"Kill session daemon"
218 function list_lttng_with_opts
()
221 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN list
$opts >$OUTPUT_DEST
222 ok $?
"Lttng-tool list command with option $opts"
225 function create_lttng_session_no_output
()
229 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name --no-output >$OUTPUT_DEST
230 ok $?
"Create session $sess_name in no-output mode"
233 function create_lttng_session
()
237 local expected_to_fail
=$3
239 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -o $trace_path > $OUTPUT_DEST
241 if [[ $expected_to_fail ]]; then
243 ok $?
"Expected fail on session creation $sess_name in $trace_path"
245 ok
$ret "Create session $sess_name in $trace_path"
249 function enable_ust_lttng_channel
()
252 local channel_name
=$2
255 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-u $channel_name -s $sess_name >$OUTPUT_DEST
257 if [[ $expect_fail ]]; then
259 ok $?
"Expected fail on ust channel creation $channel_name in $sess_name"
261 ok
$ret "Enable channel $channel_name for session $sess_name"
265 function disable_ust_lttng_channel
()
268 local channel_name
=$2
270 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-u $channel_name -s $sess_name >$OUTPUT_DEST
271 ok $?
"Disable channel $channel_name for session $sess_name"
274 function enable_lttng_mmap_overwrite_kernel_channel
()
277 local channel_name
=$2
279 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite >$OUTPUT_DEST
280 ok $?
"Enable channel $channel_name for session $sess_name"
283 function enable_lttng_mmap_overwrite_ust_channel
()
286 local channel_name
=$2
288 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite >$OUTPUT_DEST
289 ok $?
"Enable channel $channel_name for session $sess_name"
292 function enable_ust_lttng_event
()
295 local event_name
="$2"
296 local channel_name
=$3
297 local expected_to_fail
=$4
299 if [ -z $channel_name ]; then
300 # default channel if none specified
303 chan
="-c $channel_name"
306 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -u >$OUTPUT_DEST
308 if [[ $expected_to_fail ]]; then
310 ok $?
"Enable ust event $event_name for session $session_name on channel $channel_name failed as expected"
312 ok
$ret "Enable event $event_name for session $sess_name"
316 function enable_jul_lttng_event
()
322 if [ -z $channel_name ]; then
323 # default channel if none specified
326 chan
="-c $channel_name"
329 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -j >$OUTPUT_DEST
330 ok $?
"Enable JUL event $event_name for session $sess_name"
333 function enable_jul_lttng_event_loglevel
()
336 local event_name
="$2"
338 local channel_name
=$4
340 if [ -z $channel_name ]; then
341 # default channel if none specified
344 chan
="-c $channel_name"
347 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j >$OUTPUT_DEST
348 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
351 function enable_log4j_lttng_event
()
357 if [ -z $channel_name ]; then
358 # default channel if none specified
361 chan
="-c $channel_name"
364 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -l >$OUTPUT_DEST
365 ok $?
"Enable LOG4J event $event_name for session $sess_name"
368 function enable_log4j_lttng_event_loglevel
()
371 local event_name
="$2"
373 local channel_name
=$4
375 if [ -z $channel_name ]; then
376 # default channel if none specified
379 chan
="-c $channel_name"
382 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -l >$OUTPUT_DEST
383 ok $?
"Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
386 function enable_ust_lttng_event_filter
()
389 local event_name
="$2"
392 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --filter "$filter" >$OUTPUT_DEST
393 ok $?
"Enable event $event_name with filtering for session $sess_name"
396 function enable_ust_lttng_event_loglevel
()
399 local event_name
="$2"
402 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel >$OUTPUT_DEST
403 ok $?
"Enable event $event_name with loglevel $loglevel"
406 function enable_ust_lttng_event_loglevel_only
()
409 local event_name
="$2"
412 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel >$OUTPUT_DEST
413 ok $?
"Enable event $event_name with loglevel-only $loglevel"
416 function disable_ust_lttng_event
()
419 local event_name
="$2"
420 local channel_name
="$3"
422 if [ -z $channel_name ]; then
423 # default channel if none specified
426 chan
="-c $channel_name"
429 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name $chan -u >$OUTPUT_DEST
430 ok $?
"Disable event $event_name for session $sess_name"
433 function disable_jul_lttng_event
()
436 local event_name
="$2"
438 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
439 ok $?
"Disable JUL event $event_name for session $sess_name"
442 function disable_log4j_lttng_event
()
445 local event_name
="$2"
447 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -l >/dev
/null
2>&1
448 ok $?
"Disable LOG4J event $event_name for session $sess_name"
451 function start_lttng_tracing
()
454 local expected_to_fail
=$2
456 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name >$OUTPUT_DEST
458 if [[ $expected_to_fail ]]; then
460 ok $?
"Expected fail on start tracing for session: $sess_name"
462 ok
$ret "Start tracing for session $sess_name"
466 function stop_lttng_tracing
()
469 local expected_to_fail
=$2
471 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name >$OUTPUT_DEST
473 if [[ $expected_to_fail ]]; then
475 ok $?
"Expected fail on stop tracing for session: $sess_name"
477 ok
$ret "Stop lttng tracing for session $sess_name"
481 function destroy_lttng_session
()
484 local expected_to_fail
=$2
486 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name >$OUTPUT_DEST
488 if [[ $expected_to_fail ]]; then
490 ok $?
"Expected fail on session deletion $sess_name"
492 ok
$ret "Destroy session $sess_name"
496 function destroy_lttng_sessions
()
498 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
--all >$OUTPUT_DEST
499 ok $?
"Destroy all lttng sessions"
502 function lttng_snapshot_add_output
()
506 local expected_to_fail
=$3
508 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name file://$trace_path >$OUTPUT_DEST
510 if [[ $expected_to_fail ]]; then
512 ok $?
"Failed to add a snapshot output file://$trace_path as expected"
514 ok
$ret "Added snapshot output file://$trace_path"
518 function lttng_snapshot_del_output
()
522 local expected_to_fail
=$3
524 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output
-s $sess_name $id >$OUTPUT_DEST
526 if [[ $expected_to_fail ]]; then
528 ok $?
"Expect fail on deletion of snapshot output id $id"
530 ok
$ret "Deleted snapshot output id $id"
534 function lttng_snapshot_record
()
539 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot record
-s $sess_name >$OUTPUT_DEST
540 ok $?
"Snapshot recorded"
543 function lttng_snapshot_list
()
546 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output
-s $sess_name >$OUTPUT_DEST
547 ok $?
"Snapshot list"
550 function lttng_save
()
555 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN save
$sess_name $opts >$OUTPUT_DEST
556 ok $?
"Session successfully saved"
559 function lttng_load
()
563 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN load
$opts >$OUTPUT_DEST
564 ok $?
"Load command successful"
567 function trace_matches
()
573 which $BABELTRACE_BIN >/dev
/null
574 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
576 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
578 if [ "$count" -ne "$nr_iter" ]; then
580 diag
"$count events found in trace"
586 function trace_match_only
()
592 which $BABELTRACE_BIN >/dev
/null
593 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
595 local count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
596 local total
=$
($BABELTRACE_BIN $trace_path |
wc -l)
598 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
599 pass
"Trace match with $total event $event_name"
602 diag
"$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
606 function validate_trace
611 which $BABELTRACE_BIN >/dev
/null
612 if [ $?
-ne 0 ]; then
613 skip
0 "Babeltrace binary not found. Skipping trace validation"
618 for i
in $event_name; do
619 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
620 if [ "$traced" -ne 0 ]; then
621 pass
"Validate trace for event $i, $traced events"
623 fail
"Validate trace for event $i"
624 diag
"Found $traced occurences of $i"