Tests: Switch test apps to use usleep_safe()
[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 failed 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 $? "Enable channel $channel_name for session $sess_name failed as expected"
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 $? "Disable channel $channel_name for session $sess_name failed as expected"
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 $(pgrep --full 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=`pgrep --full 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=$(pgrep --full 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 $(pgrep --full 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 local signal=$2
391 local kill_opt=""
392
393 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
394 # Env variable requested no session daemon
395 return
396 fi
397
398 PID_SESSIOND=`pgrep --full lt-$SESSIOND_BIN`
399
400 if [ -n "$2" ]; then
401 kill_opt="$kill_opt -s $signal"
402 fi
403
404 kill $kill_opt $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
405
406 if [ $? -eq 1 ]; then
407 if [ $withtap -eq "1" ]; then
408 fail "Kill sessions daemon"
409 fi
410 else
411 out=1
412 while [ -n "$out" ]; do
413 out=$(pgrep --full lt-$SESSIOND_BIN)
414 sleep 0.5
415 done
416 out=1
417 while [ -n "$out" ]; do
418 out=$(pgrep --full $CONSUMERD_BIN)
419 sleep 0.5
420 done
421 if [ $withtap -eq "1" ]; then
422 pass "Kill session daemon"
423 fi
424 fi
425 }
426
427 function stop_lttng_sessiond()
428 {
429 stop_lttng_sessiond_opt 1 "$@"
430 }
431
432 function stop_lttng_sessiond_notap()
433 {
434 stop_lttng_sessiond_opt 0 "$@"
435 }
436
437 function stop_lttng_consumerd_opt()
438 {
439 local withtap=$1
440 local signal=$2
441 local kill_opt=""
442
443 PID_CONSUMERD=`pgrep --full $CONSUMERD_BIN`
444
445 if [ -n "$2" ]; then
446 kill_opt="$kill_opt -s $signal"
447 fi
448
449 if [ $withtap -eq "1" ]; then
450 diag "Killing lttng-consumerd (pid: $PID_CONSUMERD)"
451 fi
452 kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
453 retval=$?
454 set +x
455
456 if [ $? -eq 1 ]; then
457 if [ $withtap -eq "1" ]; then
458 fail "Kill consumer daemon"
459 fi
460 return 1
461 else
462 out=1
463 while [ $out -ne 0 ]; do
464 pid=$(pgrep --full $CONSUMERD_BIN)
465
466 # If consumerds are still present check their status.
467 # A zombie status qualifies the consumerd as *killed*
468 out=0
469 for consumer_pid in $pid; do
470 state=$(ps -p $consumer_pid -o state= )
471 if [[ -n "$state" && "$state" != "Z" ]]; then
472 out=1
473 fi
474 done
475 sleep 0.5
476 done
477 if [ $withtap -eq "1" ]; then
478 pass "Kill consumer daemon"
479 fi
480 fi
481 return $retval
482 }
483
484 function stop_lttng_consumerd()
485 {
486 stop_lttng_consumerd_opt 1 "$@"
487 }
488
489 function stop_lttng_consumerd_notap()
490 {
491 stop_lttng_consumerd_opt 0 "$@"
492 }
493
494 function list_lttng_with_opts ()
495 {
496 local opts=$1
497 $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
498 ok $? "Lttng-tool list command with option $opts"
499 }
500
501 function create_lttng_session_no_output ()
502 {
503 local sess_name=$1
504
505 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
506 ok $? "Create session $sess_name in no-output mode"
507 }
508
509 function create_lttng_session ()
510 {
511 local expected_to_fail=$1
512 local sess_name=$2
513 local trace_path=$3
514 local opt=$4
515
516 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path $opt > $OUTPUT_DEST
517 ret=$?
518 if [[ $expected_to_fail -eq "1" ]]; then
519 test "$ret" -ne "0"
520 ok $? "Create session $sess_name in $trace_path failed as expected"
521 else
522 ok $ret "Create session $sess_name in $trace_path"
523 fi
524 }
525
526 function create_lttng_session_ok ()
527 {
528 create_lttng_session 0 "$@"
529 }
530
531 function create_lttng_session_fail ()
532 {
533 create_lttng_session 1 "$@"
534 }
535
536
537 function enable_ust_lttng_channel ()
538 {
539 local expected_to_fail=$1
540 local sess_name=$2
541 local channel_name=$3
542 local opt=$4
543
544 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
545 ret=$?
546 if [[ $expected_to_fail -eq "1" ]]; then
547 test "$ret" -ne "0"
548 ok $? "Enable channel $channel_name for session $sess_name failed as expected"
549 else
550 ok $ret "Enable channel $channel_name for session $sess_name"
551 fi
552 }
553
554 function enable_ust_lttng_channel_ok ()
555 {
556 enable_ust_lttng_channel 0 "$@"
557 }
558
559 function enable_ust_lttng_channel_fail ()
560 {
561 enable_ust_lttng_channel 1 "$@"
562 }
563
564 function disable_ust_lttng_channel()
565 {
566 local sess_name=$1
567 local channel_name=$2
568
569 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
570 ok $? "Disable channel $channel_name for session $sess_name"
571 }
572
573 function enable_lttng_mmap_overwrite_kernel_channel()
574 {
575 local sess_name=$1
576 local channel_name=$2
577
578 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
579 ok $? "Enable channel $channel_name for session $sess_name"
580 }
581
582 function enable_lttng_mmap_overwrite_ust_channel()
583 {
584 local sess_name=$1
585 local channel_name=$2
586
587 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
588 ok $? "Enable channel $channel_name for session $sess_name"
589 }
590
591 function enable_ust_lttng_event ()
592 {
593 local expected_to_fail=$1
594 local sess_name=$2
595 local event_name="$3"
596 local channel_name=$4
597
598 if [ -z $channel_name ]; then
599 # default channel if none specified
600 chan=""
601 else
602 chan="-c $channel_name"
603 fi
604
605 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
606 ret=$?
607 if [[ $expected_to_fail -eq "1" ]]; then
608 test $ret -ne "0"
609 ok $? "Enable ust event $event_name for session $session_name failed as expected"
610 else
611 ok $ret "Enable ust event $event_name for session $sess_name"
612 fi
613 }
614
615 function enable_ust_lttng_event_ok ()
616 {
617 enable_ust_lttng_event 0 "$@"
618 }
619
620 function enable_ust_lttng_event_fail ()
621 {
622 enable_ust_lttng_event 1 "$@"
623 }
624
625 function enable_jul_lttng_event()
626 {
627 sess_name=$1
628 event_name="$2"
629 channel_name=$3
630
631 if [ -z $channel_name ]; then
632 # default channel if none specified
633 chan=""
634 else
635 chan="-c $channel_name"
636 fi
637
638 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
639 ok $? "Enable JUL event $event_name for session $sess_name"
640 }
641
642 function enable_jul_lttng_event_loglevel()
643 {
644 local sess_name=$1
645 local event_name="$2"
646 local loglevel=$3
647 local channel_name=$4
648
649 if [ -z $channel_name ]; then
650 # default channel if none specified
651 chan=""
652 else
653 chan="-c $channel_name"
654 fi
655
656 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
657 ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
658 }
659
660 function enable_log4j_lttng_event()
661 {
662 sess_name=$1
663 event_name="$2"
664 channel_name=$3
665
666 if [ -z $channel_name ]; then
667 # default channel if none specified
668 chan=""
669 else
670 chan="-c $channel_name"
671 fi
672
673 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
674 ok $? "Enable LOG4J event $event_name for session $sess_name"
675 }
676
677 function enable_log4j_lttng_event_loglevel()
678 {
679 local sess_name=$1
680 local event_name="$2"
681 local loglevel=$3
682 local channel_name=$4
683
684 if [ -z $channel_name ]; then
685 # default channel if none specified
686 chan=""
687 else
688 chan="-c $channel_name"
689 fi
690
691 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
692 ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
693 }
694
695 function enable_python_lttng_event()
696 {
697 sess_name=$1
698 event_name="$2"
699 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 enable-event "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
709 ok $? "Enable Python event $event_name for session $sess_name"
710 }
711
712 function enable_python_lttng_event_loglevel()
713 {
714 local sess_name=$1
715 local event_name="$2"
716 local loglevel=$3
717 local channel_name=$4
718
719 if [ -z $channel_name ]; then
720 # default channel if none specified
721 chan=""
722 else
723 chan="-c $channel_name"
724 fi
725
726 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
727 ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel"
728 }
729
730 function enable_ust_lttng_event_filter()
731 {
732 local sess_name="$1"
733 local event_name="$2"
734 local filter="$3"
735
736 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
737 ok $? "Enable event $event_name with filtering for session $sess_name"
738 }
739
740 function enable_ust_lttng_event_loglevel()
741 {
742 local sess_name="$1"
743 local event_name="$2"
744 local loglevel="$3"
745
746 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
747 ok $? "Enable event $event_name with loglevel $loglevel"
748 }
749
750 function enable_ust_lttng_event_loglevel_only()
751 {
752 local sess_name="$1"
753 local event_name="$2"
754 local loglevel="$3"
755
756 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
757 ok $? "Enable event $event_name with loglevel-only $loglevel"
758 }
759
760 function disable_ust_lttng_event ()
761 {
762 local sess_name="$1"
763 local event_name="$2"
764 local channel_name="$3"
765
766 if [ -z $channel_name ]; then
767 # default channel if none specified
768 chan=""
769 else
770 chan="-c $channel_name"
771 fi
772
773 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
774 ok $? "Disable event $event_name for session $sess_name"
775 }
776
777 function disable_jul_lttng_event ()
778 {
779 local sess_name="$1"
780 local event_name="$2"
781
782 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1
783 ok $? "Disable JUL event $event_name for session $sess_name"
784 }
785
786 function disable_log4j_lttng_event ()
787 {
788 local sess_name="$1"
789 local event_name="$2"
790
791 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1
792 ok $? "Disable LOG4J event $event_name for session $sess_name"
793 }
794
795 function disable_python_lttng_event ()
796 {
797 local sess_name="$1"
798 local event_name="$2"
799
800 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
801 ok $? "Disable Python event $event_name for session $sess_name"
802 }
803
804 function start_lttng_tracing ()
805 {
806 local expected_to_fail=$1
807 local sess_name=$2
808
809 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
810 ret=$?
811 if [[ $expected_to_fail -eq "1" ]]; then
812 test "$ret" -ne "0"
813 ok $? "Start tracing for session $sess_name failed as expected"
814 else
815 ok $ret "Start tracing for session $sess_name"
816 fi
817 }
818
819 function start_lttng_tracing_ok ()
820 {
821 start_lttng_tracing 0 "$@"
822 }
823
824 function start_lttng_tracing_fail ()
825 {
826 start_lttng_tracing 1 "$@"
827 }
828
829 function stop_lttng_tracing ()
830 {
831 local expected_to_fail=$1
832 local sess_name=$2
833
834 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
835 ret=$?
836 if [[ $expected_to_fail -eq "1" ]]; then
837 test "$ret" -ne "0"
838 ok $? "Stop lttng tracing for session $sess_name failed as expected"
839 else
840 ok $ret "Stop lttng tracing for session $sess_name"
841 fi
842 }
843
844 function stop_lttng_tracing_ok ()
845 {
846 stop_lttng_tracing 0 "$@"
847 }
848
849 function stop_lttng_tracing_fail ()
850 {
851 stop_lttng_tracing 1 "$@"
852 }
853
854 function destroy_lttng_session ()
855 {
856 local expected_to_fail=$1
857 local sess_name=$2
858
859 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
860 ret=$?
861 if [[ $expected_to_fail -eq "1" ]]; then
862 test "$ret" -ne "0"
863 ok $? "Destroy session $sess_name failed as expected"
864 else
865 ok $ret "Destroy session $sess_name"
866 fi
867 }
868
869 function destroy_lttng_session_ok ()
870 {
871 destroy_lttng_session 0 "$@"
872
873 }
874
875 function destroy_lttng_session_fail ()
876 {
877 destroy_lttng_session 1 "$@"
878 }
879
880
881 function destroy_lttng_sessions ()
882 {
883 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
884 ok $? "Destroy all lttng sessions"
885 }
886
887 function lttng_snapshot_add_output ()
888 {
889 local expected_to_fail=$1
890 local sess_name=$2
891 local trace_path=$3
892
893 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name file://$trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
894 ret=$?
895 if [[ $expected_to_fail -eq 1 ]]; then
896 test "$ret" -ne "0"
897 ok $? "Added snapshot output file://$trace_path failed as expected"
898 else
899 ok $ret "Added snapshot output file://$trace_path"
900 fi
901 }
902
903 function lttng_snapshot_add_output_ok ()
904 {
905 lttng_snapshot_add_output 0 "$@"
906 }
907
908 function lttng_snapshot_add_output_fail ()
909 {
910 lttng_snapshot_add_output 1 "$@"
911 }
912
913 function lttng_snapshot_del_output ()
914 {
915 local expected_to_fail=$1
916 local sess_name=$2
917 local id=$3
918
919 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
920 ret=$?
921 if [[ $expected_to_fail -eq "1" ]]; then
922 test "$ret" -ne "0"
923 ok $? "Deleted snapshot output id $id failed as expected"
924 else
925 ok $ret "Deleted snapshot output id $id"
926 fi
927 }
928
929 function lttng_snapshot_del_output_ok ()
930 {
931 lttng_snapshot_del_output 0 "$@"
932 }
933
934 function lttng_snapshot_del_output_fail ()
935 {
936 lttng_snapshot_del_output 1 "$@"
937 }
938
939 function lttng_snapshot_record ()
940 {
941 local sess_name=$1
942 local trace_path=$2
943
944 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
945 ok $? "Snapshot recorded"
946 }
947
948 function lttng_snapshot_list ()
949 {
950 local sess_name=$1
951 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
952 ok $? "Snapshot list"
953 }
954
955 function lttng_save()
956 {
957 local sess_name=$1
958 local opts=$2
959
960 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
961 ok $? "Session saved"
962 }
963
964 function lttng_load()
965 {
966 local opts=$1
967
968 $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
969 ok $? "Load command with opts: $opts"
970 }
971
972 function lttng_track()
973 {
974 local expected_to_fail=$1
975 local opts=$2
976 $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST
977 ret=$?
978 if [[ $expected_to_fail -eq "1" ]]; then
979 test $ret -ne "0"
980 ok $? "Track command failed as expected with opts: $opts"
981 else
982 ok $ret "Track command with opts: $opts"
983 fi
984 }
985
986 function lttng_track_ok()
987 {
988 lttng_track 0 "$@"
989 }
990
991 function lttng_track_fail()
992 {
993 lttng_track 1 "$@"
994 }
995
996 function lttng_untrack()
997 {
998 local expected_to_fail=$1
999 local opts=$2
1000 $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST
1001 ret=$?
1002 if [[ $expected_to_fail -eq "1" ]]; then
1003 test $ret -ne "0"
1004 ok $? "Untrack command failed as expected with opts: $opts"
1005 else
1006 ok $ret "Untrack command with opts: $opts"
1007 fi
1008 }
1009
1010 function lttng_untrack_ok()
1011 {
1012 lttng_untrack 0 "$@"
1013 }
1014
1015 function lttng_untrack_fail()
1016 {
1017 lttng_untrack 1 "$@"
1018 }
1019
1020 function add_context_lttng()
1021 {
1022 local expected_to_fail="$1"
1023 local domain="$2"
1024 local session_name="$3"
1025 local channel_name="$4"
1026 local type="$5"
1027
1028 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context -s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1029 ret=$?
1030 if [[ $expected_to_fail -eq "1" ]]; then
1031 test $ret -ne "0"
1032 ok $? "Add context command failed as expected for type: $type"
1033 else
1034 ok $ret "Add context command for type: $type"
1035 fi
1036 }
1037
1038 function add_context_ust_ok()
1039 {
1040 add_context_lttng 0 -u "$@"
1041 }
1042
1043 function add_context_ust_fail()
1044 {
1045 add_context_lttng 1 -u "$@"
1046 }
1047
1048 function add_context_kernel_ok()
1049 {
1050 add_context_lttng 0 -k "$@"
1051 }
1052
1053 function add_context_kernel_fail()
1054 {
1055 add_context_lttng 1 -k "$@"
1056 }
1057
1058 function trace_matches ()
1059 {
1060 local event_name=$1
1061 local nr_iter=$2
1062 local trace_path=$3
1063
1064 which $BABELTRACE_BIN >/dev/null
1065 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1066
1067 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
1068
1069 if [ "$count" -ne "$nr_iter" ]; then
1070 fail "Trace match"
1071 diag "$count events found in trace"
1072 else
1073 pass "Trace match"
1074 fi
1075 }
1076
1077 function trace_match_only()
1078 {
1079 local event_name=$1
1080 local nr_iter=$2
1081 local trace_path=$3
1082
1083 which $BABELTRACE_BIN >/dev/null
1084 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1085
1086 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
1087 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1088
1089 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1090 pass "Trace match with $total event $event_name"
1091 else
1092 fail "Trace match"
1093 diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1094 fi
1095 }
1096
1097 function validate_trace
1098 {
1099 local event_name=$1
1100 local trace_path=$2
1101
1102 which $BABELTRACE_BIN >/dev/null
1103 if [ $? -ne 0 ]; then
1104 skip 0 "Babeltrace binary not found. Skipping trace validation"
1105 fi
1106
1107 OLDIFS=$IFS
1108 IFS=","
1109 for i in $event_name; do
1110 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1111 if [ "$traced" -ne 0 ]; then
1112 pass "Validate trace for event $i, $traced events"
1113 else
1114 fail "Validate trace for event $i"
1115 diag "Found $traced occurences of $i"
1116 fi
1117 done
1118 ret=$?
1119 IFS=$OLDIFS
1120 return $ret
1121 }
1122
1123 function validate_trace_exp()
1124 {
1125 local event_exp=$1
1126 local trace_path=$2
1127
1128 which $BABELTRACE_BIN >/dev/null
1129 skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
1130
1131 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep ${event_exp} | wc -l)
1132 if [ "$traced" -ne 0 ]; then
1133 pass "Validate trace for expression '${event_exp}', $traced events"
1134 else
1135 fail "Validate trace for expression '${event_exp}'"
1136 diag "Found $traced occurences of '${event_exp}'"
1137 fi
1138 ret=$?
1139 return $ret
1140 }
1141
1142 function validate_trace_only_exp()
1143 {
1144 local event_exp=$1
1145 local trace_path=$2
1146
1147 which $BABELTRACE_BIN >/dev/null
1148 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1149
1150 local count=$($BABELTRACE_BIN $trace_path | grep ${event_exp} | wc -l)
1151 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1152
1153 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1154 pass "Trace match with $total for expression '${event_exp}"
1155 else
1156 fail "Trace match"
1157 diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1158 fi
1159 ret=$?
1160 return $ret
1161 }
1162
1163 function validate_trace_empty()
1164 {
1165 local trace_path=$1
1166
1167 which $BABELTRACE_BIN >/dev/null
1168 if [ $? -ne 0 ]; then
1169 skip 0 "Babeltrace binary not found. Skipping trace validation"
1170 fi
1171
1172 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | wc -l)
1173 if [ "$traced" -eq 0 ]; then
1174 pass "Validate empty trace"
1175 else
1176 fail "Validate empty trace"
1177 diag "Found $traced events in trace"
1178 fi
1179 ret=$?
1180 return $ret
1181 }
This page took 0.053808 seconds and 4 git commands to generate.