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