Build fix: Apps defining _LGPL_SOURCE must link to urcu-bp
[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"
f7613992 19CONSUMERD_BIN="lttng-consumerd"
f4e40ab6 20RELAYD_BIN="lttng-relayd"
d3e8f6bb
DG
21LTTNG_BIN="lttng"
22BABELTRACE_BIN="babeltrace"
873c2aae 23OUTPUT_DEST=/dev/null 2>&1
d3e8f6bb 24
fd4dfcec
DG
25# Minimal kernel version supported for session daemon tests
26KERNEL_MAJOR_VERSION=2
27KERNEL_MINOR_VERSION=6
28KERNEL_PATCHLEVEL_VERSION=27
29
29655db7
CB
30source $TESTDIR/utils/tap/tap.sh
31
fec81a7e
CB
32function print_ok ()
33{
34 # Check if we are a terminal
35 if [ -t 1 ]; then
36 echo -e "\e[1;32mOK\e[0m"
37 else
38 echo -e "OK"
39 fi
40}
41
42function print_fail ()
43{
44 # Check if we are a terminal
45 if [ -t 1 ]; then
46 echo -e "\e[1;31mFAIL\e[0m"
47 else
48 echo -e "FAIL"
49 fi
50}
51
52function print_test_banner ()
53{
7d0ad314 54 local desc="$1"
29655db7 55 diag "$desc"
fec81a7e
CB
56}
57
fd4dfcec
DG
58function validate_kernel_version ()
59{
7d0ad314 60 local kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n'))
fd4dfcec
DG
61 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
62 return 0
63 fi
64 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
65 return 0
66 fi
67 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
68 return 0
69 fi
70 return 1
71}
72
9ac429ef 73# Generate a random string
f4e40ab6
DG
74# $1 = number of characters; defaults to 16
75# $2 = include special characters; 1 = yes, 0 = no; defaults to yes
9ac429ef 76function randstring()
f4e40ab6
DG
77{
78 [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
79 cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-16}
80 echo
81}
82
f4e40ab6
DG
83function lttng_enable_kernel_event
84{
7d0ad314
JRJ
85 local sess_name=$1
86 local event_name=$2
87 local channel_name=$3
f4e40ab6
DG
88
89 if [ -z $event_name ]; then
90 # Enable all event if no event name specified
29655db7 91 event_name="-a"
f4e40ab6
DG
92 fi
93
07b86b52
JD
94 if [ -z $channel_name ]; then
95 # default channel if none specified
96 chan=""
97 else
98 chan="-c $channel_name"
99 fi
100
873c2aae 101 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k >$OUTPUT_DEST
29655db7 102 ok $? "Enable kernel event $event_name for session $sess_name"
f4e40ab6
DG
103}
104
8cfcd41c
MD
105function lttng_enable_kernel_syscall()
106{
107 local expected_to_fail=$1
108 local sess_name=$2
109 local syscall_name=$3
110 local channel_name=$4
111
112 if [ -z $syscall_name ]; then
113 # Enable all event if no syscall name specified
114 syscall_name="-a"
115 fi
116
117 if [ -z $channel_name ]; then
118 # default channel if none specified
119 chan=""
120 else
121 chan="-c $channel_name"
122 fi
123
124 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --syscall "$syscall_name" $chan -s $sess_name -k >$OUTPUT_DEST
125 ret=$?
126 if [[ $expected_to_fail -eq "1" ]]; then
127 test $ret -ne "0"
128 ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
129 else
130 ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
131 fi
132}
133
134function lttng_enable_kernel_syscall_ok()
135{
136 lttng_enable_kernel_syscall 0 ${*}
137}
138
139function lttng_enable_kernel_syscall_fail()
140{
141 lttng_enable_kernel_syscall 1 ${*}
142}
143
144function lttng_disable_kernel_syscall()
145{
146 local expected_to_fail=$1
147 local sess_name=$2
148 local syscall_name=$3
149 local channel_name=$4
150
151 if [ -z $syscall_name ]; then
152 # Enable all event if no syscall name specified
153 syscall_name="-a"
154 fi
155
156 if [ -z $channel_name ]; then
157 # default channel if none specified
158 chan=""
159 else
160 chan="-c $channel_name"
161 fi
162
163 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event --syscall "$syscall_name" $chan -s $sess_name -k >$OUTPUT_DEST
164
165 ret=$?
166 if [[ $expected_to_fail -eq "1" ]]; then
167 test $ret -ne "0"
168 ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
169 else
170 ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
171 fi
172}
173
174function lttng_disable_kernel_syscall_ok()
175{
176 lttng_disable_kernel_syscall 0 ${*}
177}
178
179function lttng_disable_kernel_syscall_fail()
180{
181 lttng_disable_kernel_syscall 1 ${*}
182}
183
d96f6315
MD
184function lttng_enable_kernel_channel()
185{
186 local expected_to_fail=$1
187 local sess_name=$2
188 local channel_name=$3
189
190 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name >$OUTPUT_DEST
191 ret=$?
192 if [[ $expected_to_fail -eq "1" ]]; then
193 test "$ret" -ne "0"
194 ok $? "Expected failure on kernel channel creation $channel_name in $sess_name"
195 else
196 ok $ret "Enable channel $channel_name for session $sess_name"
197 fi
198}
199
200function lttng_enable_kernel_channel_ok()
201{
202 lttng_enable_kernel_channel 0 ${*}
203}
204
205function lttng_enable_kernel_channel_fail()
206{
207 lttng_enable_kernel_channel 1 ${*}
208}
209
210function lttng_disable_kernel_channel()
211{
212 local expected_to_fail=$1
213 local sess_name=$2
214 local channel_name=$3
215
216 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -k $channel_name -s $sess_name >$OUTPUT_DEST
217 ret=$?
218 if [[ $expected_to_fail -eq "1" ]]; then
219 test "$ret" -ne "0"
220 ok $? "Expected failure on kernel channel creation $channel_name in $sess_name"
221 else
222 ok $ret "disable channel $channel_name for session $sess_name"
223 fi
224}
225
226function lttng_disable_kernel_channel_ok()
227{
228 lttng_disable_kernel_channel 0 ${*}
229}
230
231function lttng_disable_kernel_channel_fail()
232{
233 lttng_disable_kernel_channel 1 ${*}
234}
235
fb3268e3 236function start_lttng_relayd
f4e40ab6 237{
198e7caf 238 local opt=$1
173af62f 239
f4e40ab6
DG
240 DIR=$(readlink -f $TESTDIR)
241
242 if [ -z $(pidof lt-$RELAYD_BIN) ]; then
873c2aae 243 $DIR/../src/bin/lttng-relayd/$RELAYD_BIN -b $opt >$OUTPUT_DEST
25a818af 244 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
f4e40ab6 245 if [ $? -eq 1 ]; then
29655db7 246 fail "Start lttng-relayd (opt: $opt)"
f4e40ab6
DG
247 return 1
248 else
29655db7 249 pass "Start lttng-relayd (opt: $opt)"
f4e40ab6
DG
250 fi
251 else
29655db7 252 pass "Start lttng-relayd (opt: $opt)"
f4e40ab6
DG
253 fi
254}
255
1fb23888 256function stop_lttng_relayd_nocheck
f4e40ab6
DG
257{
258 PID_RELAYD=`pidof lt-$RELAYD_BIN`
259
1fb23888 260 diag "Killing lttng-relayd (pid: $PID_RELAYD)"
873c2aae 261 kill $PID_RELAYD >$OUTPUT_DEST
1fb23888 262 retval=$?
29655db7 263
1fb23888 264 if [ $retval -eq 1 ]; then
f4e40ab6
DG
265 out=1
266 while [ -n "$out" ]; do
267 out=$(pidof lt-$RELAYD_BIN)
268 sleep 0.5
269 done
1fb23888
MD
270 fi
271 return $retval
272}
273
274function stop_lttng_relayd
275{
276 stop_lttng_relayd_nocheck
277
278 if [ $? -eq 1 ]; then
279 fail "Killed lttng-relayd (pid: $PID_RELAYD)"
280 return 1
281 else
282 pass "Killed lttng-relayd (pid: $PID_RELAYD)"
f4e40ab6
DG
283 return 0
284 fi
285}
286
8d51ddbc 287#First argument: load path for automatic loading
fb3268e3 288function start_lttng_sessiond()
355f483d 289{
8d51ddbc
JRJ
290
291 local load_path="$1"
355f483d
DG
292 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
293 # Env variable requested no session daemon
294 return
295 fi
296
29655db7
CB
297 validate_kernel_version
298 if [ $? -ne 0 ]; then
299 fail "Start session daemon"
300 BAIL_OUT "*** Kernel too old for session daemon tests ***"
355f483d
DG
301 fi
302
29655db7 303 DIR=$(readlink -f $TESTDIR)
d3d97763
JG
304 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
305 export LTTNG_SESSION_CONFIG_XSD_PATH
29655db7
CB
306
307 if [ -z $(pidof lt-$SESSIOND_BIN) ]; then
8d51ddbc
JRJ
308 # Have a load path ?
309 if [ -n "$1" ]; then
310 $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --load "$1" --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
311 else
312 $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
313 fi
29655db7
CB
314 #$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 &
315 status=$?
29655db7
CB
316 ok $status "Start session daemon"
317 fi
355f483d
DG
318}
319
fb3268e3 320function stop_lttng_sessiond ()
d3e8f6bb 321{
355f483d
DG
322 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
323 # Env variable requested no session daemon
324 return
325 fi
326
d3e8f6bb
DG
327 PID_SESSIOND=`pidof lt-$SESSIOND_BIN`
328
873c2aae 329 kill $PID_SESSIOND >$OUTPUT_DEST
29655db7 330
d3e8f6bb 331 if [ $? -eq 1 ]; then
29655db7 332 fail "Kill sessions daemon"
d3e8f6bb
DG
333 return 1
334 else
5fa32580
DG
335 out=1
336 while [ -n "$out" ]; do
337 out=$(pidof lt-$SESSIOND_BIN)
338 sleep 0.5
339 done
f7613992
MD
340 out=1
341 while [ -n "$out" ]; do
342 out=$(pidof $CONSUMERD_BIN)
343 sleep 0.5
344 done
29655db7 345 pass "Kill session daemon"
d3e8f6bb
DG
346 fi
347}
348
873c2aae
JRJ
349function list_lttng_with_opts ()
350{
7d0ad314 351 local opts=$1
312dabc3 352 $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts >$OUTPUT_DEST
873c2aae
JRJ
353 ok $? "Lttng-tool list command with option $opts"
354}
355
07b86b52
JD
356function create_lttng_session_no_output ()
357{
7d0ad314 358 local sess_name=$1
07b86b52 359
873c2aae 360 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output >$OUTPUT_DEST
07b86b52
JD
361 ok $? "Create session $sess_name in no-output mode"
362}
363
d3e8f6bb
DG
364function create_lttng_session ()
365{
7d0ad314
JRJ
366 local sess_name=$1
367 local trace_path=$2
368 local expected_to_fail=$3
d3e8f6bb 369
873c2aae
JRJ
370 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path > $OUTPUT_DEST
371 ret=$?
312dabc3 372 if [[ $expected_to_fail ]]; then
01513c3e
JRJ
373 test "$ret" -ne "0"
374 ok $? "Expected fail on session creation $sess_name in $trace_path"
873c2aae
JRJ
375 else
376 ok $ret "Create session $sess_name in $trace_path"
377 fi
d4018451
DG
378}
379
29655db7 380function enable_ust_lttng_channel()
d4018451 381{
7d0ad314
JRJ
382 local sess_name=$1
383 local channel_name=$2
384 local expect_fail=$3
d4018451 385
873c2aae 386 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name >$OUTPUT_DEST
312dabc3
JRJ
387 ret=$?
388 if [[ $expect_fail ]]; then
01513c3e
JRJ
389 test "$ret" -ne "0"
390 ok $? "Expected fail on ust channel creation $channel_name in $sess_name"
312dabc3
JRJ
391 else
392 ok $ret "Enable channel $channel_name for session $sess_name"
393 fi
d4018451
DG
394}
395
29655db7 396function disable_ust_lttng_channel()
d4018451 397{
7d0ad314
JRJ
398 local sess_name=$1
399 local channel_name=$2
d4018451 400
873c2aae 401 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name >$OUTPUT_DEST
29655db7 402 ok $? "Disable channel $channel_name for session $sess_name"
d3e8f6bb
DG
403}
404
07b86b52
JD
405function enable_lttng_mmap_overwrite_kernel_channel()
406{
7d0ad314
JRJ
407 local sess_name=$1
408 local channel_name=$2
07b86b52 409
873c2aae 410 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite >$OUTPUT_DEST
07b86b52
JD
411 ok $? "Enable channel $channel_name for session $sess_name"
412}
413
ebaaaf5e
JD
414function enable_lttng_mmap_overwrite_ust_channel()
415{
7d0ad314
JRJ
416 local sess_name=$1
417 local channel_name=$2
ebaaaf5e 418
873c2aae 419 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite >$OUTPUT_DEST
ebaaaf5e
JD
420 ok $? "Enable channel $channel_name for session $sess_name"
421}
422
d3e8f6bb
DG
423function enable_ust_lttng_event ()
424{
7d0ad314
JRJ
425 local sess_name=$1
426 local event_name="$2"
427 local channel_name=$3
01513c3e 428 local expected_to_fail=$4
ebaaaf5e
JD
429
430 if [ -z $channel_name ]; then
431 # default channel if none specified
432 chan=""
433 else
434 chan="-c $channel_name"
435 fi
d3e8f6bb 436
873c2aae 437 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u >$OUTPUT_DEST
01513c3e
JRJ
438 ret=$?
439 if [[ $expected_to_fail ]]; then
440 test $ret -ne "0"
441 ok $? "Enable ust event $event_name for session $session_name on channel $channel_name failed as expected"
442 else
443 ok $ret "Enable event $event_name for session $sess_name"
444 fi
26b53d3b
DG
445}
446
37175ce4
DG
447function enable_jul_lttng_event()
448{
449 sess_name=$1
450 event_name="$2"
451 channel_name=$3
452
453 if [ -z $channel_name ]; then
454 # default channel if none specified
455 chan=""
456 else
457 chan="-c $channel_name"
458 fi
459
873c2aae 460 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j >$OUTPUT_DEST
37175ce4
DG
461 ok $? "Enable JUL event $event_name for session $sess_name"
462}
463
b2064f54
DG
464function enable_jul_lttng_event_loglevel()
465{
7d0ad314
JRJ
466 local sess_name=$1
467 local event_name="$2"
468 local loglevel=$3
469 local channel_name=$4
b2064f54
DG
470
471 if [ -z $channel_name ]; then
472 # default channel if none specified
473 chan=""
474 else
475 chan="-c $channel_name"
476 fi
477
873c2aae 478 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j >$OUTPUT_DEST
b2064f54
DG
479 ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
480}
481
504d4ace
DG
482function enable_log4j_lttng_event()
483{
484 sess_name=$1
485 event_name="$2"
486 channel_name=$3
487
488 if [ -z $channel_name ]; then
489 # default channel if none specified
490 chan=""
491 else
492 chan="-c $channel_name"
493 fi
494
495 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l >$OUTPUT_DEST
496 ok $? "Enable LOG4J event $event_name for session $sess_name"
497}
498
499function enable_log4j_lttng_event_loglevel()
500{
501 local sess_name=$1
502 local event_name="$2"
503 local loglevel=$3
504 local channel_name=$4
505
506 if [ -z $channel_name ]; then
507 # default channel if none specified
508 chan=""
509 else
510 chan="-c $channel_name"
511 fi
512
513 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l >$OUTPUT_DEST
514 ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
515}
516
0e115563
DG
517function enable_python_lttng_event()
518{
519 sess_name=$1
520 event_name="$2"
521 channel_name=$3
522
523 if [ -z $channel_name ]; then
524 # default channel if none specified
525 chan=""
526 else
527 chan="-c $channel_name"
528 fi
529
530 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p >$OUTPUT_DEST
531 ok $? "Enable Python event $event_name for session $sess_name"
532}
533
534function enable_python_lttng_event_loglevel()
535{
536 local sess_name=$1
537 local event_name="$2"
538 local loglevel=$3
539 local channel_name=$4
540
541 if [ -z $channel_name ]; then
542 # default channel if none specified
543 chan=""
544 else
545 chan="-c $channel_name"
546 fi
547
548 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -p >$OUTPUT_DEST
549 ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel"
550}
551
26b53d3b
DG
552function enable_ust_lttng_event_filter()
553{
7d0ad314
JRJ
554 local sess_name="$1"
555 local event_name="$2"
556 local filter="$3"
26b53d3b 557
873c2aae 558 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" >$OUTPUT_DEST
29655db7 559 ok $? "Enable event $event_name with filtering for session $sess_name"
26b53d3b
DG
560}
561
562function enable_ust_lttng_event_loglevel()
563{
7d0ad314
JRJ
564 local sess_name="$1"
565 local event_name="$2"
566 local loglevel="$3"
26b53d3b 567
873c2aae 568 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel >$OUTPUT_DEST
29655db7 569 ok $? "Enable event $event_name with loglevel $loglevel"
26b53d3b
DG
570}
571
572function enable_ust_lttng_event_loglevel_only()
573{
7d0ad314
JRJ
574 local sess_name="$1"
575 local event_name="$2"
576 local loglevel="$3"
26b53d3b 577
873c2aae 578 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel >$OUTPUT_DEST
29655db7 579 ok $? "Enable event $event_name with loglevel-only $loglevel"
26b53d3b
DG
580}
581
582function disable_ust_lttng_event ()
583{
7d0ad314
JRJ
584 local sess_name="$1"
585 local event_name="$2"
01513c3e 586 local channel_name="$3"
26b53d3b 587
01513c3e
JRJ
588 if [ -z $channel_name ]; then
589 # default channel if none specified
590 chan=""
591 else
592 chan="-c $channel_name"
593 fi
594
595 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u >$OUTPUT_DEST
29655db7 596 ok $? "Disable event $event_name for session $sess_name"
d3e8f6bb
DG
597}
598
1d842d5a
DG
599function disable_jul_lttng_event ()
600{
601 local sess_name="$1"
602 local event_name="$2"
603
604 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1
605 ok $? "Disable JUL event $event_name for session $sess_name"
606}
607
504d4ace
DG
608function disable_log4j_lttng_event ()
609{
610 local sess_name="$1"
611 local event_name="$2"
612
613 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1
614 ok $? "Disable LOG4J event $event_name for session $sess_name"
615}
616
0e115563
DG
617function disable_python_lttng_event ()
618{
619 local sess_name="$1"
620 local event_name="$2"
621
622 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p >$OUTPUT_DEST
623 ok $? "Disable Python event $event_name for session $sess_name"
624}
625
fb3268e3 626function start_lttng_tracing ()
d3e8f6bb 627{
7d0ad314 628 local sess_name=$1
01513c3e 629 local expected_to_fail=$2
d3e8f6bb 630
873c2aae 631 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name >$OUTPUT_DEST
01513c3e
JRJ
632 ret=$?
633 if [[ $expected_to_fail ]]; then
634 test "$ret" -ne "0"
635 ok $? "Expected fail on start tracing for session: $sess_name"
636 else
637 ok $ret "Start tracing for session $sess_name"
638 fi
d3e8f6bb
DG
639}
640
fb3268e3 641function stop_lttng_tracing ()
d3e8f6bb 642{
7d0ad314 643 local sess_name=$1
01513c3e 644 local expected_to_fail=$2
d3e8f6bb 645
873c2aae 646 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name >$OUTPUT_DEST
01513c3e
JRJ
647 ret=$?
648 if [[ $expected_to_fail ]]; then
649 test "$ret" -ne "0"
650 ok $? "Expected fail on stop tracing for session: $sess_name"
651 else
652 ok $ret "Stop lttng tracing for session $sess_name"
653 fi
d3e8f6bb
DG
654}
655
656function destroy_lttng_session ()
657{
7d0ad314 658 local sess_name=$1
01513c3e 659 local expected_to_fail=$2
d3e8f6bb 660
873c2aae 661 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name >$OUTPUT_DEST
01513c3e
JRJ
662 ret=$?
663 if [[ $expected_to_fail ]]; then
664 test "$ret" -ne "0"
665 ok $? "Expected fail on session deletion $sess_name"
666 else
667 ok $ret "Destroy session $sess_name"
668 fi
d3e8f6bb
DG
669}
670
873c2aae
JRJ
671function destroy_lttng_sessions ()
672{
673 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all >$OUTPUT_DEST
674 ok $? "Destroy all lttng sessions"
675}
676
07b86b52
JD
677function lttng_snapshot_add_output ()
678{
7d0ad314
JRJ
679 local sess_name=$1
680 local trace_path=$2
01513c3e 681 local expected_to_fail=$3
07b86b52 682
873c2aae 683 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name file://$trace_path >$OUTPUT_DEST
01513c3e
JRJ
684 ret=$?
685 if [[ $expected_to_fail ]]; then
686 test "$ret" -ne "0"
687 ok $? "Failed to add a snapshot output file://$trace_path as expected"
688 else
689 ok $ret "Added snapshot output file://$trace_path"
690 fi
07b86b52
JD
691}
692
26402e0c
DG
693function lttng_snapshot_del_output ()
694{
695 local sess_name=$1
696 local id=$2
01513c3e 697 local expected_to_fail=$3
26402e0c 698
873c2aae 699 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id >$OUTPUT_DEST
01513c3e
JRJ
700 ret=$?
701 if [[ $expected_to_fail ]]; then
702 test "$ret" -ne "0"
703 ok $? "Expect fail on deletion of snapshot output id $id"
704 else
705 ok $ret "Deleted snapshot output id $id"
706 fi
26402e0c
DG
707}
708
07b86b52
JD
709function lttng_snapshot_record ()
710{
7d0ad314
JRJ
711 local sess_name=$1
712 local trace_path=$2
07b86b52 713
873c2aae 714 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name >$OUTPUT_DEST
07b86b52
JD
715 ok $? "Snapshot recorded"
716}
717
01513c3e
JRJ
718function lttng_snapshot_list ()
719{
720 local sess_name=$1
721 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name >$OUTPUT_DEST
722 ok $? "Snapshot list"
723}
724
e02b109b
DG
725function lttng_save()
726{
727 local sess_name=$1
728 local opts=$2
729
873c2aae 730 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts >$OUTPUT_DEST
e02b109b
DG
731 ok $? "Session successfully saved"
732}
733
734function lttng_load()
735{
736 local opts=$1
737
873c2aae 738 $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts >$OUTPUT_DEST
e02b109b
DG
739 ok $? "Load command successful"
740}
741
d3e8f6bb
DG
742function trace_matches ()
743{
7d0ad314
JRJ
744 local event_name=$1
745 local nr_iter=$2
746 local trace_path=$3
d3e8f6bb 747
317eef93 748 which $BABELTRACE_BIN >/dev/null
29655db7 749 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
d3e8f6bb 750
7d0ad314 751 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
29655db7 752
d3e8f6bb 753 if [ "$count" -ne "$nr_iter" ]; then
29655db7
CB
754 fail "Trace match"
755 diag "$count events found in trace"
d3e8f6bb 756 else
29655db7 757 pass "Trace match"
d3e8f6bb
DG
758 fi
759}
f4e40ab6 760
d53addeb
DG
761function trace_match_only()
762{
763 local event_name=$1
764 local nr_iter=$2
765 local trace_path=$3
766
767 which $BABELTRACE_BIN >/dev/null
768 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
769
770 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
771 local total=$($BABELTRACE_BIN $trace_path | wc -l)
772
773 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
774 pass "Trace match with $total event $event_name"
775 else
776 fail "Trace match"
777 diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
778 fi
779}
780
f4e40ab6
DG
781function validate_trace
782{
7d0ad314
JRJ
783 local event_name=$1
784 local trace_path=$2
f4e40ab6
DG
785
786 which $BABELTRACE_BIN >/dev/null
29655db7
CB
787 if [ $? -ne 0 ]; then
788 skip 0 "Babeltrace binary not found. Skipping trace validation"
f4e40ab6
DG
789 fi
790
07b86b52
JD
791 OLDIFS=$IFS
792 IFS=","
793 for i in $event_name; do
794 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
795 if [ "$traced" -ne 0 ]; then
ebaaaf5e 796 pass "Validate trace for event $i, $traced events"
07b86b52
JD
797 else
798 fail "Validate trace for event $i"
799 diag "Found $traced occurences of $i"
800 fi
801 done
802 ret=$?
803 IFS=$OLDIFS
804 return $ret
f4e40ab6 805}
8cfcd41c
MD
806
807function validate_trace_exp()
808{
809 local event_exp=$1
810 local trace_path=$2
811
812 which $BABELTRACE_BIN >/dev/null
813 skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
814
815 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep ${event_exp} | wc -l)
816 if [ "$traced" -ne 0 ]; then
817 pass "Validate trace for expression '${event_exp}', $traced events"
818 else
819 fail "Validate trace for expression '${event_exp}'"
820 diag "Found $traced occurences of '${event_exp}'"
821 fi
822 ret=$?
823 return $ret
824}
825
826function validate_trace_only_exp()
827{
828 local event_exp=$1
829 local trace_path=$2
830
831 which $BABELTRACE_BIN >/dev/null
832 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
833
834 local count=$($BABELTRACE_BIN $trace_path | grep ${event_exp} | wc -l)
835 local total=$($BABELTRACE_BIN $trace_path | wc -l)
836
837 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
838 pass "Trace match with $total for expression '${event_exp}"
839 else
840 fail "Trace match"
841 diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
842 fi
843 ret=$?
844 return $ret
845}
846
847function validate_trace_empty()
848{
849 local trace_path=$1
850
851 which $BABELTRACE_BIN >/dev/null
852 if [ $? -ne 0 ]; then
853 skip 0 "Babeltrace binary not found. Skipping trace validation"
854 fi
855
856 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | wc -l)
857 if [ "$traced" -eq 0 ]; then
858 pass "Validate empty trace"
859 else
860 fail "Validate empty trace"
861 diag "Found $traced events in trace"
862 fi
863 ret=$?
864 return $ret
865}
This page took 0.092945 seconds and 4 git commands to generate.