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 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 function start_lttng_sessiond
()
158 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
159 # Env variable requested no session daemon
163 validate_kernel_version
164 if [ $?
-ne 0 ]; then
165 fail
"Start session daemon"
166 BAIL_OUT
"*** Kernel too old for session daemon tests ***"
169 DIR
=$
(readlink
-f $TESTDIR)
170 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
171 export LTTNG_SESSION_CONFIG_XSD_PATH
173 if [ -z $
(pidof lt-
$SESSIOND_BIN) ]; then
174 $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"
175 #$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 &
177 ok
$status "Start session daemon"
181 function stop_lttng_sessiond
()
183 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
184 # Env variable requested no session daemon
188 PID_SESSIOND
=`pidof lt-$SESSIOND_BIN`
190 kill $PID_SESSIOND >$OUTPUT_DEST
192 if [ $?
-eq 1 ]; then
193 fail
"Kill sessions daemon"
197 while [ -n "$out" ]; do
198 out
=$
(pidof lt-
$SESSIOND_BIN)
202 while [ -n "$out" ]; do
203 out
=$
(pidof
$CONSUMERD_BIN)
206 pass
"Kill session daemon"
210 function list_lttng_with_opts
()
213 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN list
$opts >$OUTPUT_DEST
214 ok $?
"Lttng-tool list command with option $opts"
217 function create_lttng_session_no_output
()
221 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name --no-output >$OUTPUT_DEST
222 ok $?
"Create session $sess_name in no-output mode"
225 function create_lttng_session
()
231 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -o $trace_path > $OUTPUT_DEST
233 if [[ $expected_to_fail ]]; then
235 pass
"Expected fail on session creation $sess_name in $trace_path"
237 fail
"Session $sess_name creation in $trace_path was expected to fail"
240 ok
$ret "Create session $sess_name in $trace_path"
244 function enable_ust_lttng_channel
()
250 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-u $channel_name -s $sess_name >$OUTPUT_DEST
252 if [[ $expect_fail ]]; then
254 pass
"Enable channel $channel_name for session $sess_name expected fail"
256 fail
"Enable channel $channel_name for session $sess_name did not fail as expected"
259 ok
$ret "Enable channel $channel_name for session $sess_name"
263 function disable_ust_lttng_channel
()
268 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-u $channel_name -s $sess_name >$OUTPUT_DEST
269 ok $?
"Disable channel $channel_name for session $sess_name"
272 function enable_lttng_mmap_overwrite_kernel_channel
()
277 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite >$OUTPUT_DEST
278 ok $?
"Enable channel $channel_name for session $sess_name"
281 function enable_lttng_mmap_overwrite_ust_channel
()
286 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite >$OUTPUT_DEST
287 ok $?
"Enable channel $channel_name for session $sess_name"
290 function enable_ust_lttng_event
()
296 if [ -z $channel_name ]; then
297 # default channel if none specified
300 chan
="-c $channel_name"
303 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -u >$OUTPUT_DEST
304 ok $?
"Enable event $event_name for session $sess_name"
307 function enable_jul_lttng_event
()
313 if [ -z $channel_name ]; then
314 # default channel if none specified
317 chan
="-c $channel_name"
320 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -j >$OUTPUT_DEST
321 ok $?
"Enable JUL event $event_name for session $sess_name"
324 function enable_jul_lttng_event_loglevel
()
331 if [ -z $channel_name ]; then
332 # default channel if none specified
335 chan
="-c $channel_name"
338 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j >$OUTPUT_DEST
339 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
342 function enable_ust_lttng_event_filter
()
348 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --filter "$filter" >$OUTPUT_DEST
349 ok $?
"Enable event $event_name with filtering for session $sess_name"
352 function enable_ust_lttng_event_loglevel
()
358 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel >$OUTPUT_DEST
359 ok $?
"Enable event $event_name with loglevel $loglevel"
362 function enable_ust_lttng_event_loglevel_only
()
368 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel >$OUTPUT_DEST
369 ok $?
"Enable event $event_name with loglevel-only $loglevel"
372 function disable_ust_lttng_event
()
377 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -u >$OUTPUT_DEST
378 ok $?
"Disable event $event_name for session $sess_name"
381 function disable_jul_lttng_event
()
384 local event_name
="$2"
386 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -j >/dev
/null
2>&1
387 ok $?
"Disable JUL event $event_name for session $sess_name"
390 function start_lttng_tracing
()
394 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name >$OUTPUT_DEST
395 ok $?
"Start tracing for session $sess_name"
398 function stop_lttng_tracing
()
402 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name >$OUTPUT_DEST
403 ok $?
"Stop lttng tracing for session $sess_name"
406 function destroy_lttng_session
()
410 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name >$OUTPUT_DEST
411 ok $?
"Destroy lttng session $sess_name"
414 function destroy_lttng_sessions
()
416 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
--all >$OUTPUT_DEST
417 ok $?
"Destroy all lttng sessions"
420 function lttng_snapshot_add_output
()
425 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name file://$trace_path >$OUTPUT_DEST
426 ok $?
"Added snapshot output file://$trace_path"
429 function lttng_snapshot_del_output
()
434 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output
-s $sess_name $id >$OUTPUT_DEST
435 ok $?
"Deleted snapshot output id $id"
438 function lttng_snapshot_record
()
443 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot record
-s $sess_name >$OUTPUT_DEST
444 ok $?
"Snapshot recorded"
447 function lttng_save
()
452 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN save
$sess_name $opts >$OUTPUT_DEST
453 ok $?
"Session successfully saved"
456 function lttng_load
()
460 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN load
$opts >$OUTPUT_DEST
461 ok $?
"Load command successful"
464 function trace_matches
()
470 which $BABELTRACE_BIN >/dev
/null
471 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
473 count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
475 if [ "$count" -ne "$nr_iter" ]; then
477 diag
"$count events found in trace"
483 function validate_trace
488 which $BABELTRACE_BIN >/dev
/null
489 if [ $?
-ne 0 ]; then
490 skip
0 "Babeltrace binary not found. Skipping trace validation"
495 for i
in $event_name; do
496 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
497 if [ "$traced" -ne 0 ]; then
498 pass
"Validate trace for event $i, $traced events"
500 fail
"Validate trace for event $i"
501 diag
"Found $traced occurences of $i"