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
87 if [ -z $event_name ]; then
88 # Enable all event if no event name specified
92 if [ -z $channel_name ]; then
93 # default channel if none specified
96 chan
="-c $channel_name"
99 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -k >/dev
/null
2>&1
100 ok $?
"Enable kernel event $event_name for session $sess_name"
103 function start_lttng_relayd
107 DIR
=$
(readlink
-f $TESTDIR)
109 if [ -z $
(pidof lt-
$RELAYD_BIN) ]; then
110 $DIR/..
/src
/bin
/lttng-relayd
/$RELAYD_BIN $opt >/dev
/null
2>&1 &
111 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
112 if [ $?
-eq 1 ]; then
113 fail
"Start lttng-relayd (opt: $opt)"
116 pass
"Start lttng-relayd (opt: $opt)"
119 pass
"Start lttng-relayd (opt: $opt)"
123 function stop_lttng_relayd
125 PID_RELAYD
=`pidof lt-$RELAYD_BIN`
127 kill $PID_RELAYD >/dev
/null
2>&1
129 if [ $?
-eq 1 ]; then
130 fail
"Kill lttng-relayd (pid: $PID_RELAYD)"
134 while [ -n "$out" ]; do
135 out
=$
(pidof lt-
$RELAYD_BIN)
138 pass
"Kill lttng-relayd (pid: $PID_RELAYD)"
143 function start_lttng_sessiond
()
145 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
146 # Env variable requested no session daemon
150 validate_kernel_version
151 if [ $?
-ne 0 ]; then
152 fail
"Start session daemon"
153 BAIL_OUT
"*** Kernel too old for session daemon tests ***"
156 DIR
=$
(readlink
-f $TESTDIR)
158 if [ -z $
(pidof lt-
$SESSIOND_BIN) ]; then
159 $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"
160 #$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 &
162 # Wait for sessiond to bootstrap
164 ok
$status "Start session daemon"
168 function stop_lttng_sessiond
()
170 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
171 # Env variable requested no session daemon
175 PID_SESSIOND
=`pidof lt-$SESSIOND_BIN`
177 kill $PID_SESSIOND >/dev
/null
2>&1
179 if [ $?
-eq 1 ]; then
180 fail
"Kill sessions daemon"
184 while [ -n "$out" ]; do
185 out
=$
(pidof lt-
$SESSIOND_BIN)
188 pass
"Kill session daemon"
192 function create_lttng_session_no_output
()
196 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name --no-output >/dev
/null
2>&1
197 ok $?
"Create session $sess_name in no-output mode"
200 function create_lttng_session
()
205 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$sess_name -o $trace_path >/dev
/null
2>&1
206 ok $?
"Create session $sess_name in $trace_path"
209 function enable_ust_lttng_channel
()
214 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-u $channel_name -s $sess_name >/dev
/null
2>&1
215 ok $?
"Enable channel $channel_name for session $sess_name"
218 function disable_ust_lttng_channel
()
223 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-channel
-u $channel_name -s $sess_name >/dev
/null
2>&1
224 ok $?
"Disable channel $channel_name for session $sess_name"
227 function enable_lttng_mmap_overwrite_kernel_channel
()
232 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -k --output mmap
--overwrite >/dev
/null
2>&1
233 ok $?
"Enable channel $channel_name for session $sess_name"
236 function enable_lttng_mmap_overwrite_ust_channel
()
241 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name $channel_name -u --output mmap
--overwrite >/dev
/null
2>&1
242 ok $?
"Enable channel $channel_name for session $sess_name"
245 function enable_ust_lttng_event
()
251 if [ -z $channel_name ]; then
252 # default channel if none specified
255 chan
="-c $channel_name"
258 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" $chan -s $sess_name -u >/dev
/null
2>&1
259 ok $?
"Enable event $event_name for session $sess_name"
262 function enable_ust_lttng_event_filter
()
268 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --filter "$filter" >/dev
/null
2>&1
269 ok $?
"Enable event $event_name with filtering for session $sess_name"
272 function enable_ust_lttng_event_loglevel
()
278 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel $loglevel >/dev
/null
2>&1
279 ok $?
"Enable event $event_name with loglevel $loglevel"
282 function enable_ust_lttng_event_loglevel_only
()
288 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -u --loglevel-only $loglevel >/dev
/null
2>&1
289 ok $?
"Enable event $event_name with loglevel-only $loglevel"
292 function disable_ust_lttng_event
()
297 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN disable-event
"$event_name" -s $sess_name -u >/dev
/null
2>&1
298 ok $?
"Disable event $event_name for session $sess_name"
301 function start_lttng_tracing
()
305 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN start
$sess_name >/dev
/null
2>&1
306 ok $?
"Start tracing for session $sess_name"
309 function stop_lttng_tracing
()
313 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN stop
$sess_name >/dev
/null
2>&1
314 ok $?
"Stop lttng tracing for session $sess_name"
317 function destroy_lttng_session
()
322 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN destroy
$sess_name >/dev
/null
2>&1
323 ok $?
"Destroy lttng session $sess_name"
326 function lttng_snapshot_add_output
()
331 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name file://$trace_path >/dev
/null
2>&1
332 ok $?
"Added snapshot output file://$trace_path"
335 function lttng_snapshot_del_output
()
340 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output
-s $sess_name $id >/dev
/null
2>&1
341 ok $?
"Deleted snapshot output id $id"
344 function lttng_snapshot_record
()
349 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot record
-s $sess_name >/dev
/null
2>&1
350 ok $?
"Snapshot recorded"
353 function trace_matches
()
359 which $BABELTRACE_BIN >/dev
/null
360 skip $?
-ne 0 "Babeltrace binary not found. Skipping trace matches"
362 count
=$
($BABELTRACE_BIN $trace_path |
grep $event_name |
wc -l)
364 if [ "$count" -ne "$nr_iter" ]; then
366 diag
"$count events found in trace"
372 function validate_trace
377 which $BABELTRACE_BIN >/dev
/null
378 if [ $?
-ne 0 ]; then
379 skip
0 "Babeltrace binary not found. Skipping trace validation"
384 for i
in $event_name; do
385 traced
=$
($BABELTRACE_BIN $trace_path 2>/dev
/null |
grep $i |
wc -l)
386 if [ "$traced" -ne 0 ]; then
387 pass
"Validate trace for event $i, $traced events"
389 fail
"Validate trace for event $i"
390 diag
"Found $traced occurences of $i"