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
30 # Check if we are a terminal
32 echo -e "\e[1;32mOK\e[0m"
38 function print_fail
()
40 # Check if we are a terminal
42 echo -e "\e[1;31mFAIL\e[0m"
48 function print_test_banner
()
53 str
=$
(printf "%${count}s");
60 function validate_kernel_version
()
62 kern_version
=($
(uname
-r |
awk -F.
'{ printf("%d.%d.%d\n",$1,$2,$3); }' |
tr '.' '\n'))
63 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
66 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
69 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
75 # Generate a random string
76 # $1 = number of characters; defaults to 16
77 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
80 [ "$2" == "0" ] && CHAR
="[:alnum:]" || CHAR
="[:graph:]"
81 cat /dev
/urandom |
tr -cd "$CHAR" |
head -c ${1:-16}
85 function spawn_sessiond
()
88 echo -n "Starting session daemon... "
89 validate_kernel_version
91 echo -e "\n*** Kernel too old for session daemon tests ***\n"
95 DIR
=$
(readlink
-f $TESTDIR)
97 if [ -z $
(pidof lt-
$SESSIOND_BIN) ]; then
98 $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"
99 #$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 &
100 if [ $?
-eq 1 ]; then
111 function lttng_enable_kernel_event
116 if [ -z $event_name ]; then
117 # Enable all event if no event name specified
121 echo -n "Enabling kernel event $event_name for session $sess_name"
122 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -k >/dev
/null
2>&1
123 if [ $?
-eq 1 ]; then
131 function start_lttng_relayd
135 echo -e -n "Starting lttng-relayd (opt: $opt)... "
137 DIR
=$
(readlink
-f $TESTDIR)
139 if [ -z $
(pidof lt-
$RELAYD_BIN) ]; then
140 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN $opt >/dev
/null
2>&1 &
141 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
142 if [ $?
-eq 1 ]; then
153 function stop_lttng_relayd
155 PID_RELAYD
=`pidof lt-$RELAYD_BIN`
157 echo -e -n "Killing lttng-relayd (pid: $PID_RELAYD)... "
158 kill $PID_RELAYD >/dev
/null
2>&1
159 if [ $?
-eq 1 ]; then
164 while [ -n "$out" ]; do
165 out
=$
(pidof lt-
$RELAYD_BIN)
173 function start_lttng_sessiond
()
175 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
176 # Env variable requested no session daemon
182 if [ $out -eq 2 ]; then
183 # Kernel version is not compatible.
185 elif [ $out -ne 0 ]; then
190 # Simply wait for the session daemon bootstrap
191 echo "Waiting for the session daemon to bootstrap (2 secs)"
195 function stop_lttng_sessiond
()
197 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
198 # Env variable requested no session daemon
202 PID_SESSIOND
=`pidof lt-$SESSIOND_BIN`
204 echo -e -n "Killing session daemon... "
205 kill $PID_SESSIOND >/dev
/null
2>&1
206 if [ $?
-eq 1 ]; then
211 while [ -n "$out" ]; do
212 out
=$
(pidof lt-
$SESSIOND_BIN)
219 function create_lttng_session
()
224 echo -n "Creating lttng session $sess_name in $trace_path "
225 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -o $trace_path >/dev
/null
2>&1
226 if [ $?
-eq 1 ]; then
234 function enable_lttng_channel
()
239 echo -n "Enabling lttng channel $channel_name for session $sess_name"
240 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
$channel_name -s $sess_name >/dev
/null
2>&1
241 if [ $?
-eq 1 ]; then
249 function disable_lttng_channel
()
254 echo -n "Disabling lttng channel $channel_name for session $sess_name"
255 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
$channel_name -s $sess_name >/dev
/null
2>&1
256 if [ $?
-eq 1 ]; then
264 function enable_ust_lttng_event
()
269 echo -n "Enabling lttng event $event_name for session $sess_name "
270 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u >/dev
/null
2>&1
271 if [ $?
-eq 1 ]; then
279 function enable_ust_lttng_event_filter
()
284 echo -n "Enabling lttng event with filtering "
286 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --filter "$filter" 2>&1 >/dev
/null
287 if [ $?
-eq 0 ]; then
296 function enable_ust_lttng_event_loglevel
()
301 echo -n "Enabling lttng event $event_name with loglevel $loglevel"
303 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel 2>&1 >/dev
/null
304 if [ $?
-eq 0 ]; then
313 function enable_ust_lttng_event_loglevel_only
()
318 echo -n "Enabling lttng event $event_name with loglevel-only $loglevel"
320 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel 2>&1 >/dev
/null
321 if [ $?
-eq 0 ]; then
330 function disable_ust_lttng_event
()
335 echo -n "Disabling lttng event $event_name for session $sess_name "
336 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -u >/dev
/null
2>&1
337 if [ $?
-eq 1 ]; then
345 function start_lttng_tracing
()
349 echo -n "Start lttng tracing for session $sess_name "
350 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name >/dev
/null
2>&1
351 if [ $?
-eq 1 ]; then
359 function stop_lttng_tracing
()
363 echo -n "Stop lttng tracing for session $sess_name "
364 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name >/dev
/null
2>&1
365 if [ $?
-eq 1 ]; then
373 function destroy_lttng_session
()
377 echo -n "Destroy lttng session $sess_name "
378 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name >/dev
/null
2>&1
379 if [ $?
-eq 1 ]; then
387 function trace_matches
()
393 which $BABELTRACE_BIN >/dev
/null
394 if [ $?
-eq 1 ]; then
395 echo "Babeltrace binary not found. Skipping trace matches"
399 echo -n "Looking for $nr_iter $event_name in $trace_path "
401 count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
402 if [ "$count" -ne "$nr_iter" ]; then
403 echo -n "$count found in trace "
407 echo -n "Trace is coherent "
413 function validate_trace
418 which $BABELTRACE_BIN >/dev
/null
419 if [ $?
-eq 1 ]; then
420 echo "Babeltrace binary not found. Skipping trace matches"
424 echo -n "Validating trace for event $event_name... "
425 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $event_name |
wc -l)
426 if [ $traced -eq 0 ]; then