Add UST snapshot support
[lttng-tools.git] / tests / utils / utils.sh
CommitLineData
10a8a223 1#!/src/bin/bash
d3e8f6bb
DG
2#
3# Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
4#
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.
8#
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
12# details.
13#
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
17
18SESSIOND_BIN="lttng-sessiond"
f4e40ab6 19RELAYD_BIN="lttng-relayd"
d3e8f6bb
DG
20LTTNG_BIN="lttng"
21BABELTRACE_BIN="babeltrace"
22
fd4dfcec
DG
23# Minimal kernel version supported for session daemon tests
24KERNEL_MAJOR_VERSION=2
25KERNEL_MINOR_VERSION=6
26KERNEL_PATCHLEVEL_VERSION=27
27
29655db7
CB
28source $TESTDIR/utils/tap/tap.sh
29
fec81a7e
CB
30function print_ok ()
31{
32 # Check if we are a terminal
33 if [ -t 1 ]; then
34 echo -e "\e[1;32mOK\e[0m"
35 else
36 echo -e "OK"
37 fi
38}
39
40function print_fail ()
41{
42 # Check if we are a terminal
43 if [ -t 1 ]; then
44 echo -e "\e[1;31mFAIL\e[0m"
45 else
46 echo -e "FAIL"
47 fi
48}
49
50function print_test_banner ()
51{
52 desc="$1"
29655db7 53 diag "$desc"
fec81a7e
CB
54}
55
fd4dfcec
DG
56function validate_kernel_version ()
57{
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
60 return 0
61 fi
62 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
63 return 0
64 fi
65 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
66 return 0
67 fi
68 return 1
69}
70
9ac429ef 71# Generate a random string
f4e40ab6
DG
72# $1 = number of characters; defaults to 16
73# $2 = include special characters; 1 = yes, 0 = no; defaults to yes
9ac429ef 74function randstring()
f4e40ab6
DG
75{
76 [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
77 cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-16}
78 echo
79}
80
f4e40ab6
DG
81function lttng_enable_kernel_event
82{
83 sess_name=$1
84 event_name=$2
07b86b52 85 channel_name=$3
f4e40ab6
DG
86
87 if [ -z $event_name ]; then
88 # Enable all event if no event name specified
29655db7 89 event_name="-a"
f4e40ab6
DG
90 fi
91
07b86b52
JD
92 if [ -z $channel_name ]; then
93 # default channel if none specified
94 chan=""
95 else
96 chan="-c $channel_name"
97 fi
98
99 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k >/dev/null 2>&1
29655db7 100 ok $? "Enable kernel event $event_name for session $sess_name"
f4e40ab6
DG
101}
102
fb3268e3 103function start_lttng_relayd
f4e40ab6 104{
198e7caf 105 local opt=$1
173af62f 106
f4e40ab6
DG
107 DIR=$(readlink -f $TESTDIR)
108
109 if [ -z $(pidof lt-$RELAYD_BIN) ]; then
173af62f 110 $DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt >/dev/null 2>&1 &
25a818af 111 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
f4e40ab6 112 if [ $? -eq 1 ]; then
29655db7 113 fail "Start lttng-relayd (opt: $opt)"
f4e40ab6
DG
114 return 1
115 else
29655db7 116 pass "Start lttng-relayd (opt: $opt)"
f4e40ab6
DG
117 fi
118 else
29655db7 119 pass "Start lttng-relayd (opt: $opt)"
f4e40ab6
DG
120 fi
121}
122
fb3268e3 123function stop_lttng_relayd
f4e40ab6
DG
124{
125 PID_RELAYD=`pidof lt-$RELAYD_BIN`
126
f4e40ab6 127 kill $PID_RELAYD >/dev/null 2>&1
29655db7 128
f4e40ab6 129 if [ $? -eq 1 ]; then
29655db7 130 fail "Kill lttng-relayd (pid: $PID_RELAYD)"
f4e40ab6
DG
131 return 1
132 else
133 out=1
134 while [ -n "$out" ]; do
135 out=$(pidof lt-$RELAYD_BIN)
136 sleep 0.5
137 done
29655db7 138 pass "Kill lttng-relayd (pid: $PID_RELAYD)"
f4e40ab6
DG
139 return 0
140 fi
141}
142
fb3268e3 143function start_lttng_sessiond()
355f483d
DG
144{
145 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
146 # Env variable requested no session daemon
147 return
148 fi
149
29655db7
CB
150 validate_kernel_version
151 if [ $? -ne 0 ]; then
152 fail "Start session daemon"
153 BAIL_OUT "*** Kernel too old for session daemon tests ***"
355f483d
DG
154 fi
155
29655db7
CB
156 DIR=$(readlink -f $TESTDIR)
157
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 &
161 status=$?
162 # Wait for sessiond to bootstrap
163 sleep 2
164 ok $status "Start session daemon"
165 fi
355f483d
DG
166}
167
fb3268e3 168function stop_lttng_sessiond ()
d3e8f6bb 169{
355f483d
DG
170 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
171 # Env variable requested no session daemon
172 return
173 fi
174
d3e8f6bb
DG
175 PID_SESSIOND=`pidof lt-$SESSIOND_BIN`
176
d3e8f6bb 177 kill $PID_SESSIOND >/dev/null 2>&1
29655db7 178
d3e8f6bb 179 if [ $? -eq 1 ]; then
29655db7 180 fail "Kill sessions daemon"
d3e8f6bb
DG
181 return 1
182 else
5fa32580
DG
183 out=1
184 while [ -n "$out" ]; do
185 out=$(pidof lt-$SESSIOND_BIN)
186 sleep 0.5
187 done
29655db7 188 pass "Kill session daemon"
d3e8f6bb
DG
189 fi
190}
191
07b86b52
JD
192function create_lttng_session_no_output ()
193{
194 sess_name=$1
195
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"
198}
199
d3e8f6bb
DG
200function create_lttng_session ()
201{
202 sess_name=$1
203 trace_path=$2
204
10a8a223 205 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path >/dev/null 2>&1
29655db7 206 ok $? "Create session $sess_name in $trace_path"
d4018451
DG
207}
208
29655db7 209function enable_ust_lttng_channel()
d4018451
DG
210{
211 sess_name=$1
212 channel_name=$2
213
29655db7
CB
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"
d4018451
DG
216}
217
29655db7 218function disable_ust_lttng_channel()
d4018451
DG
219{
220 sess_name=$1
221 channel_name=$2
222
29655db7
CB
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"
d3e8f6bb
DG
225}
226
07b86b52
JD
227function enable_lttng_mmap_overwrite_kernel_channel()
228{
229 sess_name=$1
230 channel_name=$2
231
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"
234}
235
d3e8f6bb
DG
236function enable_ust_lttng_event ()
237{
238 sess_name=$1
26b53d3b 239 event_name="$2"
d3e8f6bb 240
26b53d3b 241 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u >/dev/null 2>&1
29655db7 242 ok $? "Enable event $event_name for session $sess_name"
26b53d3b
DG
243}
244
245function enable_ust_lttng_event_filter()
246{
247 sess_name="$1"
248 event_name="$2"
249 filter="$3"
26b53d3b 250
29655db7
CB
251 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" >/dev/null 2>&1
252 ok $? "Enable event $event_name with filtering for session $sess_name"
26b53d3b
DG
253}
254
255function enable_ust_lttng_event_loglevel()
256{
257 sess_name="$1"
258 event_name="$2"
259 loglevel="$3"
26b53d3b 260
29655db7
CB
261 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel >/dev/null 2>&1
262 ok $? "Enable event $event_name with loglevel $loglevel"
26b53d3b
DG
263}
264
265function enable_ust_lttng_event_loglevel_only()
266{
267 sess_name="$1"
268 event_name="$2"
269 loglevel="$3"
26b53d3b 270
29655db7
CB
271 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel >/dev/null 2>&1
272 ok $? "Enable event $event_name with loglevel-only $loglevel"
26b53d3b
DG
273}
274
275function disable_ust_lttng_event ()
276{
907b42de
DG
277 sess_name="$1"
278 event_name="$2"
26b53d3b 279
907b42de 280 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -u >/dev/null 2>&1
29655db7 281 ok $? "Disable event $event_name for session $sess_name"
d3e8f6bb
DG
282}
283
fb3268e3 284function start_lttng_tracing ()
d3e8f6bb
DG
285{
286 sess_name=$1
287
10a8a223 288 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name >/dev/null 2>&1
29655db7 289 ok $? "Start tracing for session $sess_name"
d3e8f6bb
DG
290}
291
fb3268e3 292function stop_lttng_tracing ()
d3e8f6bb
DG
293{
294 sess_name=$1
295
10a8a223 296 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name >/dev/null 2>&1
29655db7 297 ok $? "Stop lttng tracing for session $sess_name"
d3e8f6bb
DG
298}
299
300function destroy_lttng_session ()
301{
302 sess_name=$1
303
29655db7 304
10a8a223 305 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name >/dev/null 2>&1
29655db7 306 ok $? "Destroy lttng session $sess_name"
d3e8f6bb
DG
307}
308
07b86b52
JD
309function lttng_snapshot_add_output ()
310{
311 sess_name=$1
312 trace_path=$2
313
314 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name file://$trace_path >/dev/null 2>&1
315 ok $? "Added snapshot output file://$trace_path"
316}
317
26402e0c
DG
318function lttng_snapshot_del_output ()
319{
320 local sess_name=$1
321 local id=$2
322
323 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id >/dev/null 2>&1
324 ok $? "Deleted snapshot output id $id"
325}
326
07b86b52
JD
327function lttng_snapshot_record ()
328{
329 sess_name=$1
330 trace_path=$2
331
332 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name >/dev/null 2>&1
333 ok $? "Snapshot recorded"
334}
335
d3e8f6bb
DG
336function trace_matches ()
337{
338 event_name=$1
339 nr_iter=$2
340 trace_path=$3
341
317eef93 342 which $BABELTRACE_BIN >/dev/null
29655db7 343 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
d3e8f6bb
DG
344
345 count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
29655db7 346
d3e8f6bb 347 if [ "$count" -ne "$nr_iter" ]; then
29655db7
CB
348 fail "Trace match"
349 diag "$count events found in trace"
d3e8f6bb 350 else
29655db7 351 pass "Trace match"
d3e8f6bb
DG
352 fi
353}
f4e40ab6
DG
354
355function validate_trace
356{
357 event_name=$1
358 trace_path=$2
359
360 which $BABELTRACE_BIN >/dev/null
29655db7
CB
361 if [ $? -ne 0 ]; then
362 skip 0 "Babeltrace binary not found. Skipping trace validation"
f4e40ab6
DG
363 fi
364
07b86b52
JD
365 OLDIFS=$IFS
366 IFS=","
367 for i in $event_name; do
368 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
369 if [ "$traced" -ne 0 ]; then
370 pass "Validate trace for event $i"
371 else
372 fail "Validate trace for event $i"
373 diag "Found $traced occurences of $i"
374 fi
375 done
376 ret=$?
377 IFS=$OLDIFS
378 return $ret
f4e40ab6 379}
This page took 0.048714 seconds and 5 git commands to generate.