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"
24 # Minimal kernel version supported for session daemon tests
25 KERNEL_MAJOR_VERSION
=2
26 KERNEL_MINOR_VERSION
=6
27 KERNEL_PATCHLEVEL_VERSION
=27
29 source $TESTDIR/utils
/tap
/tap.sh
33 # Check if we are a terminal
35 echo -e "\e[1;32mOK\e[0m"
41 function print_fail
()
43 # Check if we are a terminal
45 echo -e "\e[1;31mFAIL\e[0m"
51 function print_test_banner
()
57 function validate_kernel_version
()
59 kern_version
=($
(uname
-r |
awk -F.
'{ printf("%d.%d.%d\n",$1,$2,$3); }' |
tr '.' '\n'))
60 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
63 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
66 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
72 # Generate a random string
73 # $1 = number of characters; defaults to 16
74 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
77 [ "$2" == "0" ] && CHAR
="[:alnum:]" || CHAR
="[:graph:]"
78 cat /dev
/urandom |
tr -cd "$CHAR" |
head -c ${1:-16}
82 function lttng_enable_kernel_event
88 if [ -z $event_name ]; then
89 # Enable all event if no event name specified
93 if [ -z $channel_name ]; then
94 # default channel if none specified
97 chan
="-c $channel_name"
100 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -k >/dev
/null
2>&1
101 ok $?
"Enable kernel event $event_name for session $sess_name"
104 function start_lttng_relayd
108 DIR
=$
(readlink
-f $TESTDIR)
110 if [ -z $
(pidof lt-
$RELAYD_BIN) ]; then
111 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN -b $opt >/dev
/null
2>&1
112 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
113 if [ $?
-eq 1 ]; then
114 fail
"Start lttng-relayd (opt: $opt)"
117 pass
"Start lttng-relayd (opt: $opt)"
120 pass
"Start lttng-relayd (opt: $opt)"
124 function stop_lttng_relayd_nocheck
126 PID_RELAYD
=`pidof lt-$RELAYD_BIN`
128 diag
"Killing lttng-relayd (pid: $PID_RELAYD)"
129 kill $PID_RELAYD >/dev
/null
2>&1
132 if [ $retval -eq 1 ]; then
134 while [ -n "$out" ]; do
135 out
=$
(pidof lt-
$RELAYD_BIN)
142 function stop_lttng_relayd
144 stop_lttng_relayd_nocheck
146 if [ $?
-eq 1 ]; then
147 fail
"Killed lttng-relayd (pid: $PID_RELAYD)"
150 pass
"Killed lttng-relayd (pid: $PID_RELAYD)"
155 function start_lttng_sessiond
()
157 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
158 # Env variable requested no session daemon
162 validate_kernel_version
163 if [ $?
-ne 0 ]; then
164 fail
"Start session daemon"
165 BAIL_OUT
"*** Kernel too old for session daemon tests ***"
168 DIR
=$
(readlink
-f $TESTDIR)
169 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
170 export LTTNG_SESSION_CONFIG_XSD_PATH
172 if [ -z $
(pidof lt-
$SESSIOND_BIN) ]; then
173 $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"
174 #$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 &
176 ok
$status "Start session daemon"
180 function stop_lttng_sessiond
()
182 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
183 # Env variable requested no session daemon
187 PID_SESSIOND
=`pidof lt-$SESSIOND_BIN`
189 kill $PID_SESSIOND >/dev
/null
2>&1
191 if [ $?
-eq 1 ]; then
192 fail
"Kill sessions daemon"
196 while [ -n "$out" ]; do
197 out
=$
(pidof lt-
$SESSIOND_BIN)
201 while [ -n "$out" ]; do
202 out
=$
(pidof
$CONSUMERD_BIN)
205 pass
"Kill session daemon"
209 function create_lttng_session_no_output
()
213 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name --no-output >/dev
/null
2>&1
214 ok $?
"Create session $sess_name in no-output mode"
217 function create_lttng_session
()
222 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -o $trace_path >/dev
/null
2>&1
223 ok $?
"Create session $sess_name in $trace_path"
226 function enable_ust_lttng_channel
()
231 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-u $channel_name -s $sess_name >/dev
/null
2>&1
232 ok $?
"Enable channel $channel_name for session $sess_name"
235 function disable_ust_lttng_channel
()
240 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-u $channel_name -s $sess_name >/dev
/null
2>&1
241 ok $?
"Disable channel $channel_name for session $sess_name"
244 function enable_lttng_mmap_overwrite_kernel_channel
()
249 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite >/dev
/null
2>&1
250 ok $?
"Enable channel $channel_name for session $sess_name"
253 function enable_lttng_mmap_overwrite_ust_channel
()
258 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite >/dev
/null
2>&1
259 ok $?
"Enable channel $channel_name for session $sess_name"
262 function enable_ust_lttng_event
()
268 if [ -z $channel_name ]; then
269 # default channel if none specified
272 chan
="-c $channel_name"
275 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -u >/dev
/null
2>&1
276 ok $?
"Enable event $event_name for session $sess_name"
279 function enable_jul_lttng_event
()
285 if [ -z $channel_name ]; then
286 # default channel if none specified
289 chan
="-c $channel_name"
292 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -j >/dev
/null
2>&1
293 ok $?
"Enable JUL event $event_name for session $sess_name"
296 function enable_jul_lttng_event_loglevel
()
303 if [ -z $channel_name ]; then
304 # default channel if none specified
307 chan
="-c $channel_name"
310 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel $loglevel "$event_name" $chan -s $sess_name -j >/dev
/null
2>&1
311 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
314 function enable_ust_lttng_event_filter
()
320 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --filter "$filter" >/dev
/null
2>&1
321 ok $?
"Enable event $event_name with filtering for session $sess_name"
324 function enable_ust_lttng_event_loglevel
()
330 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel >/dev
/null
2>&1
331 ok $?
"Enable event $event_name with loglevel $loglevel"
334 function enable_ust_lttng_event_loglevel_only
()
340 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel >/dev
/null
2>&1
341 ok $?
"Enable event $event_name with loglevel-only $loglevel"
344 function disable_ust_lttng_event
()
349 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -u >/dev
/null
2>&1
350 ok $?
"Disable event $event_name for session $sess_name"
353 function start_lttng_tracing
()
357 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name >/dev
/null
2>&1
358 ok $?
"Start tracing for session $sess_name"
361 function stop_lttng_tracing
()
365 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name >/dev
/null
2>&1
366 ok $?
"Stop lttng tracing for session $sess_name"
369 function destroy_lttng_session
()
374 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name >/dev
/null
2>&1
375 ok $?
"Destroy lttng session $sess_name"
378 function lttng_snapshot_add_output
()
383 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name file://$trace_path >/dev
/null
2>&1
384 ok $?
"Added snapshot output file://$trace_path"
387 function lttng_snapshot_del_output
()
392 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output
-s $sess_name $id >/dev
/null
2>&1
393 ok $?
"Deleted snapshot output id $id"
396 function lttng_snapshot_record
()
401 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot record
-s $sess_name >/dev
/null
2>&1
402 ok $?
"Snapshot recorded"
405 function lttng_save
()
410 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN save
$sess_name $opts >/dev
/null
2>&1
411 ok $?
"Session successfully saved"
414 function lttng_load
()
418 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN load
$opts >/dev
/null
2>&1
419 ok $?
"Load command successful"
422 function trace_matches
()
428 which $BABELTRACE_BIN >/dev
/null
429 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
431 count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
433 if [ "$count" -ne "$nr_iter" ]; then
435 diag
"$count events found in trace"
441 function validate_trace
446 which $BABELTRACE_BIN >/dev
/null
447 if [ $?
-ne 0 ]; then
448 skip
0 "Babeltrace binary not found. Skipping trace validation"
453 for i
in $event_name; do
454 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
455 if [ "$traced" -ne 0 ]; then
456 pass
"Validate trace for event $i, $traced events"
458 fail
"Validate trace for event $i"
459 diag
"Found $traced occurences of $i"