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