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
100 echo -e -n "Starting lttng-relayd... "
101 DIR
=$
(readlink
-f $TESTDIR)
103 if [ -z $
(pidof lt-
$RELAYD_BIN) ]; then
104 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN >/dev
/null
2>&1 &
105 if [ $?
-eq 1 ]; then
106 echo -e "\e[1;31mFAILED\e[0m"
109 echo -e "\e[1;32mOK\e[0m"
112 echo -e "\e[1;32mOK\e[0m"
116 function lttng_stop_relayd
118 PID_RELAYD
=`pidof lt-$RELAYD_BIN`
120 echo -e -n "Killing lttng-relayd (pid: $PID_RELAYD)... "
121 kill $PID_RELAYD >/dev
/null
2>&1
122 if [ $?
-eq 1 ]; then
123 echo -e "\e[1;31mFAILED\e[0m"
127 while [ -n "$out" ]; do
128 out
=$
(pidof lt-
$RELAYD_BIN)
131 echo -e "\e[1;32mOK\e[0m"
136 function start_sessiond
()
138 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
139 # Env variable requested no session daemon
145 if [ $out -eq 2 ]; then
146 # Kernel version is not compatible.
148 elif [ $out -ne 0 ]; then
153 # Simply wait for the session daemon bootstrap
154 echo "Waiting for the session daemon to bootstrap (2 secs)"
158 function stop_sessiond
()
160 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
161 # Env variable requested no session daemon
165 PID_SESSIOND
=`pidof lt-$SESSIOND_BIN`
167 echo -e -n "Killing session daemon... "
168 kill $PID_SESSIOND >/dev
/null
2>&1
169 if [ $?
-eq 1 ]; then
170 echo -e "\e[1;31mFAILED\e[0m"
174 while [ -n "$out" ]; do
175 out
=$
(pidof lt-
$SESSIOND_BIN)
178 echo -e "\e[1;32mOK\e[0m"
182 function create_lttng_session
()
187 echo -n "Creating lttng session $sess_name in $trace_path "
188 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -o $trace_path >/dev
/null
2>&1
189 if [ $?
-eq 1 ]; then
190 echo -e "\e[1;31mFAILED\e[0m"
193 echo -e "\e[1;32mOK\e[0m"
197 function enable_lttng_channel
()
202 echo -n "Enabling lttng channel $channel_name for session $sess_name"
203 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
$channel_name -s $sess_name >/dev
/null
2>&1
204 if [ $?
-eq 1 ]; then
205 echo -e "\e[1;31mFAILED\e[0m"
208 echo -e "\e[1;32mOK\e[0m"
212 function disable_lttng_channel
()
217 echo -n "Disabling lttng channel $channel_name for session $sess_name"
218 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
$channel_name -s $sess_name >/dev
/null
2>&1
219 if [ $?
-eq 1 ]; then
220 echo -e "\e[1;31mFAILED\e[0m"
223 echo -e "\e[1;32mOK\e[0m"
227 function enable_ust_lttng_event
()
232 echo -n "Enabling lttng event $event_name for session $sess_name "
233 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
$event_name -s $sess_name -u >/dev
/null
2>&1
234 if [ $?
-eq 1 ]; then
235 echo -e '\e[1;31mFAILED\e[0m'
238 echo -e "\e[1;32mOK\e[0m"
242 function start_tracing
()
246 echo -n "Start lttng tracing for session $sess_name "
247 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name >/dev
/null
2>&1
248 if [ $?
-eq 1 ]; then
249 echo -e '\e[1;31mFAILED\e[0m'
252 echo -e "\e[1;32mOK\e[0m"
256 function stop_tracing
()
260 echo -n "Stop lttng tracing for session $sess_name "
261 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name >/dev
/null
2>&1
262 if [ $?
-eq 1 ]; then
263 echo -e '\e[1;31mFAILED\e[0m'
266 echo -e "\e[1;32mOK\e[0m"
270 function destroy_lttng_session
()
274 echo -n "Destroy lttng session $sess_name "
275 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name >/dev
/null
2>&1
276 if [ $?
-eq 1 ]; then
277 echo -e '\e[1;31mFAILED\e[0m'
280 echo -e "\e[1;32mOK\e[0m"
284 function trace_matches
()
290 which $BABELTRACE_BIN >/dev
/null
291 if [ $?
-eq 1 ]; then
292 echo "Babeltrace binary not found. Skipping trace matches"
296 echo -n "Looking for $nr_iter $event_name in $trace_path "
298 count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
299 if [ "$count" -ne "$nr_iter" ]; then
300 echo -e "$count found in trace \e[1;31mFAILED\e[0m"
303 echo -e "Trace is coherent \e[1;32mOK\e[0m"
308 function validate_trace
313 which $BABELTRACE_BIN >/dev
/null
314 if [ $?
-eq 1 ]; then
315 echo "Babeltrace binary not found. Skipping trace matches"
319 echo -n "Validating trace for event $event_name... "
320 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $event_name |
wc -l)
321 if [ $traced -eq 0 ]; then
322 echo -e "\e[1;31mFAILED\e[0m"
325 echo -e "\e[1;32mOK\e[0m"