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 function validate_kernel_version
()
30 kern_version
=($
(uname
-r |
awk -F.
'{ printf("%d.%d.%d\n",$1,$2,$3); }' |
tr '.' '\n'))
31 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
34 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
37 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
43 # Generate a random string
44 # $1 = number of characters; defaults to 16
45 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
48 [ "$2" == "0" ] && CHAR
="[:alnum:]" || CHAR
="[:graph:]"
49 cat /dev
/urandom |
tr -cd "$CHAR" |
head -c ${1:-16}
53 function spawn_sessiond
()
56 echo -n "Starting session daemon... "
57 validate_kernel_version
59 echo -e "\n*** Kernel too old for session daemon tests ***\n"
63 DIR
=$
(readlink
-f $TESTDIR)
65 if [ -z $
(pidof lt-
$SESSIOND_BIN) ]; then
66 $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"
68 echo -e "\e[1;31mFAILED\e[0m"
71 echo -e "\e[1;32mOK\e[0m"
78 function lttng_enable_kernel_event
83 if [ -z $event_name ]; then
84 # Enable all event if no event name specified
88 echo -n "Enabling kernel event $event_name for session $sess_name"
89 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
$event_name -s $sess_name -k >/dev
/null
2>&1
91 echo -e '\e[1;31mFAILED\e[0m'
94 echo -e "\e[1;32mOK\e[0m"
98 function lttng_start_relayd
102 echo -e -n "Starting lttng-relayd (opt: $opt)... "
104 DIR
=$
(readlink
-f $TESTDIR)
106 if [ -z $
(pidof lt-
$RELAYD_BIN) ]; then
107 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN $opt >/dev
/null
2>&1 &
108 if [ $?
-eq 1 ]; then
109 echo -e "\e[1;31mFAILED\e[0m"
112 echo -e "\e[1;32mOK\e[0m"
115 echo -e "\e[1;32mOK\e[0m"
119 function lttng_stop_relayd
121 PID_RELAYD
=`pidof lt-$RELAYD_BIN`
123 echo -e -n "Killing lttng-relayd (pid: $PID_RELAYD)... "
124 kill $PID_RELAYD >/dev
/null
2>&1
125 if [ $?
-eq 1 ]; then
126 echo -e "\e[1;31mFAILED\e[0m"
130 while [ -n "$out" ]; do
131 out
=$
(pidof lt-
$RELAYD_BIN)
134 echo -e "\e[1;32mOK\e[0m"
139 function start_sessiond
()
141 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
142 # Env variable requested no session daemon
148 if [ $out -eq 2 ]; then
149 # Kernel version is not compatible.
151 elif [ $out -ne 0 ]; then
156 # Simply wait for the session daemon bootstrap
157 echo "Waiting for the session daemon to bootstrap (2 secs)"
161 function stop_sessiond
()
163 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
164 # Env variable requested no session daemon
168 PID_SESSIOND
=`pidof lt-$SESSIOND_BIN`
170 echo -e -n "Killing session daemon... "
171 kill $PID_SESSIOND >/dev
/null
2>&1
172 if [ $?
-eq 1 ]; then
173 echo -e "\e[1;31mFAILED\e[0m"
177 while [ -n "$out" ]; do
178 out
=$
(pidof lt-
$SESSIOND_BIN)
181 echo -e "\e[1;32mOK\e[0m"
185 function create_lttng_session
()
190 echo -n "Creating lttng session $sess_name in $trace_path "
191 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -o $trace_path >/dev
/null
2>&1
192 if [ $?
-eq 1 ]; then
193 echo -e "\e[1;31mFAILED\e[0m"
196 echo -e "\e[1;32mOK\e[0m"
200 function enable_lttng_channel
()
205 echo -n "Enabling lttng channel $channel_name for session $sess_name"
206 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
$channel_name -s $sess_name >/dev
/null
2>&1
207 if [ $?
-eq 1 ]; then
208 echo -e "\e[1;31mFAILED\e[0m"
211 echo -e "\e[1;32mOK\e[0m"
215 function disable_lttng_channel
()
220 echo -n "Disabling lttng channel $channel_name for session $sess_name"
221 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
$channel_name -s $sess_name >/dev
/null
2>&1
222 if [ $?
-eq 1 ]; then
223 echo -e "\e[1;31mFAILED\e[0m"
226 echo -e "\e[1;32mOK\e[0m"
230 function enable_ust_lttng_event
()
235 echo -n "Enabling lttng event $event_name for session $sess_name "
236 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
$event_name -s $sess_name -u >/dev
/null
2>&1
237 if [ $?
-eq 1 ]; then
238 echo -e '\e[1;31mFAILED\e[0m'
241 echo -e "\e[1;32mOK\e[0m"
245 function start_tracing
()
249 echo -n "Start lttng tracing for session $sess_name "
250 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name >/dev
/null
2>&1
251 if [ $?
-eq 1 ]; then
252 echo -e '\e[1;31mFAILED\e[0m'
255 echo -e "\e[1;32mOK\e[0m"
259 function stop_tracing
()
263 echo -n "Stop lttng tracing for session $sess_name "
264 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name >/dev
/null
2>&1
265 if [ $?
-eq 1 ]; then
266 echo -e '\e[1;31mFAILED\e[0m'
269 echo -e "\e[1;32mOK\e[0m"
273 function destroy_lttng_session
()
277 echo -n "Destroy lttng session $sess_name "
278 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name >/dev
/null
2>&1
279 if [ $?
-eq 1 ]; then
280 echo -e '\e[1;31mFAILED\e[0m'
283 echo -e "\e[1;32mOK\e[0m"
287 function trace_matches
()
293 which $BABELTRACE_BIN >/dev
/null
294 if [ $?
-eq 1 ]; then
295 echo "Babeltrace binary not found. Skipping trace matches"
299 echo -n "Looking for $nr_iter $event_name in $trace_path "
301 count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
302 if [ "$count" -ne "$nr_iter" ]; then
303 echo -e "$count found in trace \e[1;31mFAILED\e[0m"
306 echo -e "Trace is coherent \e[1;32mOK\e[0m"
311 function validate_trace
316 which $BABELTRACE_BIN >/dev
/null
317 if [ $?
-eq 1 ]; then
318 echo "Babeltrace binary not found. Skipping trace matches"
322 echo -n "Validating trace for event $event_name... "
323 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $event_name |
wc -l)
324 if [ $traced -eq 0 ]; then
325 echo -e "\e[1;31mFAILED\e[0m"
328 echo -e "\e[1;32mOK\e[0m"