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 RELAYD_BIN
="lttng-relayd"
21 BABELTRACE_BIN
="babeltrace"
23 # Minimal kernel version supported for session daemon tests
24 KERNEL_MAJOR_VERSION
=2
25 KERNEL_MINOR_VERSION
=6
26 KERNEL_PATCHLEVEL_VERSION
=27
28 source $TESTDIR/utils
/tap
/tap.sh
32 # Check if we are a terminal
34 echo -e "\e[1;32mOK\e[0m"
40 function print_fail
()
42 # Check if we are a terminal
44 echo -e "\e[1;31mFAIL\e[0m"
50 function print_test_banner
()
56 function validate_kernel_version
()
58 kern_version
=($
(uname
-r |
awk -F.
'{ printf("%d.%d.%d\n",$1,$2,$3); }' |
tr '.' '\n'))
59 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
62 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
65 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
71 # Generate a random string
72 # $1 = number of characters; defaults to 16
73 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
76 [ "$2" == "0" ] && CHAR
="[:alnum:]" || CHAR
="[:graph:]"
77 cat /dev
/urandom |
tr -cd "$CHAR" |
head -c ${1:-16}
81 function lttng_enable_kernel_event
86 if [ -z $event_name ]; then
87 # Enable all event if no event name specified
91 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -k >/dev
/null
2>&1
92 ok $?
"Enable kernel event $event_name for session $sess_name"
95 function start_lttng_relayd
99 DIR
=$
(readlink
-f $TESTDIR)
101 if [ -z $
(pidof lt-
$RELAYD_BIN) ]; then
102 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN $opt >/dev
/null
2>&1 &
103 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
104 if [ $?
-eq 1 ]; then
105 fail
"Start lttng-relayd (opt: $opt)"
108 pass
"Start lttng-relayd (opt: $opt)"
111 pass
"Start lttng-relayd (opt: $opt)"
115 function stop_lttng_relayd
117 PID_RELAYD
=`pidof lt-$RELAYD_BIN`
119 kill $PID_RELAYD >/dev
/null
2>&1
121 if [ $?
-eq 1 ]; then
122 fail
"Kill lttng-relayd (pid: $PID_RELAYD)"
126 while [ -n "$out" ]; do
127 out
=$
(pidof lt-
$RELAYD_BIN)
130 pass
"Kill lttng-relayd (pid: $PID_RELAYD)"
135 function start_lttng_sessiond
()
137 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
138 # Env variable requested no session daemon
142 validate_kernel_version
143 if [ $?
-ne 0 ]; then
144 fail
"Start session daemon"
145 BAIL_OUT
"*** Kernel too old for session daemon tests ***"
148 DIR
=$
(readlink
-f $TESTDIR)
150 if [ -z $
(pidof lt-
$SESSIOND_BIN) ]; then
151 $DIR/..
/src
/bin
/lttng-sessiond
/$SESSIOND_BIN --daemonize --quiet --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
152 #$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 &
154 # Wait for sessiond to bootstrap
156 ok
$status "Start session daemon"
160 function stop_lttng_sessiond
()
162 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
163 # Env variable requested no session daemon
167 PID_SESSIOND
=`pidof lt-$SESSIOND_BIN`
169 kill $PID_SESSIOND >/dev
/null
2>&1
171 if [ $?
-eq 1 ]; then
172 fail
"Kill sessions daemon"
176 while [ -n "$out" ]; do
177 out
=$
(pidof lt-
$SESSIOND_BIN)
180 pass
"Kill session daemon"
184 function create_lttng_session
()
189 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -o $trace_path >/dev
/null
2>&1
190 ok $?
"Create session $sess_name in $trace_path"
193 function enable_ust_lttng_channel
()
198 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-u $channel_name -s $sess_name >/dev
/null
2>&1
199 ok $?
"Enable channel $channel_name for session $sess_name"
202 function disable_ust_lttng_channel
()
207 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-u $channel_name -s $sess_name >/dev
/null
2>&1
208 ok $?
"Disable channel $channel_name for session $sess_name"
211 function enable_ust_lttng_event
()
216 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u >/dev
/null
2>&1
217 ok $?
"Enable event $event_name for session $sess_name"
220 function enable_ust_lttng_event_filter
()
226 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --filter "$filter" >/dev
/null
2>&1
227 ok $?
"Enable event $event_name with filtering for session $sess_name"
230 function enable_ust_lttng_event_loglevel
()
236 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel >/dev
/null
2>&1
237 ok $?
"Enable event $event_name with loglevel $loglevel"
240 function enable_ust_lttng_event_loglevel_only
()
246 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel >/dev
/null
2>&1
247 ok $?
"Enable event $event_name with loglevel-only $loglevel"
250 function disable_ust_lttng_event
()
255 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -u >/dev
/null
2>&1
256 ok $?
"Disable event $event_name for session $sess_name"
259 function start_lttng_tracing
()
263 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name >/dev
/null
2>&1
264 ok $?
"Start tracing for session $sess_name"
267 function stop_lttng_tracing
()
271 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name >/dev
/null
2>&1
272 ok $?
"Stop lttng tracing for session $sess_name"
275 function destroy_lttng_session
()
280 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name >/dev
/null
2>&1
281 ok $?
"Destroy lttng session $sess_name"
284 function trace_matches
()
290 which $BABELTRACE_BIN >/dev
/null
291 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
293 count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
295 if [ "$count" -ne "$nr_iter" ]; then
297 diag
"$count events found in trace"
303 function validate_trace
308 which $BABELTRACE_BIN >/dev
/null
309 if [ $?
-ne 0 ]; then
310 skip
0 "Babeltrace binary not found. Skipping trace validation"
313 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $event_name |
wc -l)
314 if [ "$traced" -ne 0 ]; then
315 pass
"Validate trace for event $event_name"
317 fail
"Validate trace for event $event_name"
318 diag
"Found $traced occurences of $event_name"