Test fix: ignore stderr at every step of randstring
[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 # We set the default lttng-sessiond path to /bin/true to prevent the spawning
37 # of a daemonized sessiond. This is necessary since 'lttng create' will spawn
38 # its own sessiond if none is running. It also ensures that 'lttng create'
39 # fails when no sessiond is running.
40 export LTTNG_SESSIOND_PATH="/bin/true"
41
42 source $TESTDIR/utils/tap/tap.sh
43
44 function print_ok ()
45 {
46 # Check if we are a terminal
47 if [ -t 1 ]; then
48 echo -e "\e[1;32mOK\e[0m"
49 else
50 echo -e "OK"
51 fi
52 }
53
54 function print_fail ()
55 {
56 # Check if we are a terminal
57 if [ -t 1 ]; then
58 echo -e "\e[1;31mFAIL\e[0m"
59 else
60 echo -e "FAIL"
61 fi
62 }
63
64 function print_test_banner ()
65 {
66 local desc="$1"
67 diag "$desc"
68 }
69
70 function validate_kernel_version ()
71 {
72 local kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n'))
73 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
74 return 0
75 fi
76 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
77 return 0
78 fi
79 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
80 return 0
81 fi
82 return 1
83 }
84
85 # Generate a random string
86 # $1 = number of characters; defaults to 16
87 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
88 function randstring()
89 {
90 [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
91 cat /dev/urandom 2>/dev/null | tr -cd "$CHAR" 2>/dev/null | head -c ${1:-16} 2>/dev/null
92 echo
93 }
94
95 # Return the number of _configured_ CPUs.
96 function conf_proc_count()
97 {
98 getconf _NPROCESSORS_CONF
99 if [ $? -ne 0 ]; then
100 diag "Failed to get the number of configured CPUs"
101 fi
102 echo
103 }
104
105 function enable_kernel_lttng_event
106 {
107 local expected_to_fail="$1"
108 local sess_name="$2"
109 local event_name="$3"
110 local channel_name="$4"
111
112 if [ -z "$event_name" ]; then
113 # Enable all event if no event name specified
114 event_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 "$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
125 ret=$?
126 if [[ $expected_to_fail -eq "1" ]]; then
127 test $ret -ne "0"
128 ok $? "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
129 else
130 ok $ret "Enable kernel event $event_name for session $sess_name"
131 fi
132 }
133
134 function enable_kernel_lttng_event_ok ()
135 {
136 enable_kernel_lttng_event 0 "$@"
137 }
138
139 function enable_kernel_lttng_event_fail ()
140 {
141 enable_kernel_lttng_event 1 "$@"
142 }
143
144 # Old interface
145 function lttng_enable_kernel_event
146 {
147 enable_kernel_lttng_event_ok "$@"
148 }
149
150 function lttng_enable_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 enable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
170 ret=$?
171 if [[ $expected_to_fail -eq "1" ]]; then
172 test $ret -ne "0"
173 ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
174 else
175 ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
176 fi
177 }
178
179 function lttng_enable_kernel_syscall_ok()
180 {
181 lttng_enable_kernel_syscall 0 "$@"
182 }
183
184 function lttng_enable_kernel_syscall_fail()
185 {
186 lttng_enable_kernel_syscall 1 "$@"
187 }
188
189 function lttng_disable_kernel_syscall()
190 {
191 local expected_to_fail=$1
192 local sess_name=$2
193 local syscall_name=$3
194 local channel_name=$4
195
196 if [ -z $syscall_name ]; then
197 # Enable all event if no syscall name specified
198 syscall_name="-a"
199 fi
200
201 if [ -z $channel_name ]; then
202 # default channel if none specified
203 chan=""
204 else
205 chan="-c $channel_name"
206 fi
207
208 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
209
210 ret=$?
211 if [[ $expected_to_fail -eq "1" ]]; then
212 test $ret -ne "0"
213 ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
214 else
215 ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
216 fi
217 }
218
219 function lttng_disable_kernel_syscall_ok()
220 {
221 lttng_disable_kernel_syscall 0 "$@"
222 }
223
224 function lttng_disable_kernel_syscall_fail()
225 {
226 lttng_disable_kernel_syscall 1 "$@"
227 }
228
229 function lttng_enable_kernel_channel()
230 {
231 local expected_to_fail=$1
232 local sess_name=$2
233 local channel_name=$3
234
235 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
236 ret=$?
237 if [[ $expected_to_fail -eq "1" ]]; then
238 test "$ret" -ne "0"
239 ok $? "Enable channel $channel_name for session $sess_name failed as expected"
240 else
241 ok $ret "Enable channel $channel_name for session $sess_name"
242 fi
243 }
244
245 function lttng_enable_kernel_channel_ok()
246 {
247 lttng_enable_kernel_channel 0 "$@"
248 }
249
250 function lttng_enable_kernel_channel_fail()
251 {
252 lttng_enable_kernel_channel 1 "$@"
253 }
254
255 function lttng_disable_kernel_channel()
256 {
257 local expected_to_fail=$1
258 local sess_name=$2
259 local channel_name=$3
260
261 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
262 ret=$?
263 if [[ $expected_to_fail -eq "1" ]]; then
264 test "$ret" -ne "0"
265 ok $? "Disable channel $channel_name for session $sess_name failed as expected"
266 else
267 ok $ret "Disable channel $channel_name for session $sess_name"
268 fi
269 }
270
271 function lttng_disable_kernel_channel_ok()
272 {
273 lttng_disable_kernel_channel 0 "$@"
274 }
275
276 function lttng_disable_kernel_channel_fail()
277 {
278 lttng_disable_kernel_channel 1 "$@"
279 }
280
281 function start_lttng_relayd_opt()
282 {
283 local withtap=$1
284 local opt=$2
285
286 DIR=$(readlink -f $TESTDIR)
287
288 if [ -z $(pgrep --full lt-$RELAYD_BIN) ]; then
289 $DIR/../src/bin/lttng-relayd/$RELAYD_BIN -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
290 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
291 if [ $? -eq 1 ]; then
292 if [ $withtap -eq "1" ]; then
293 fail "Start lttng-relayd (opt: $opt)"
294 fi
295 return 1
296 else
297 if [ $withtap -eq "1" ]; then
298 pass "Start lttng-relayd (opt: $opt)"
299 fi
300 fi
301 else
302 pass "Start lttng-relayd (opt: $opt)"
303 fi
304 }
305
306 function start_lttng_relayd()
307 {
308 start_lttng_relayd_opt 1 "$@"
309 }
310
311 function start_lttng_relayd_notap()
312 {
313 start_lttng_relayd_opt 0 "$@"
314 }
315
316 function stop_lttng_relayd_opt()
317 {
318 local withtap=$1
319
320 PID_RELAYD=`pgrep --full lt-$RELAYD_BIN`
321
322 if [ $withtap -eq "1" ]; then
323 diag "Killing lttng-relayd (pid: $PID_RELAYD)"
324 fi
325 kill $PID_RELAYD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
326 retval=$?
327
328 if [ $? -eq 1 ]; then
329 if [ $withtap -eq "1" ]; then
330 fail "Kill relay daemon"
331 fi
332 return 1
333 else
334 out=1
335 while [ -n "$out" ]; do
336 out=$(pgrep --full lt-$RELAYD_BIN)
337 sleep 0.5
338 done
339 if [ $withtap -eq "1" ]; then
340 pass "Kill relay daemon"
341 fi
342 fi
343 return $retval
344 }
345
346 function stop_lttng_relayd()
347 {
348 stop_lttng_relayd_opt 1 "$@"
349 }
350
351 function stop_lttng_relayd_notap()
352 {
353 stop_lttng_relayd_opt 0 "$@"
354 }
355
356 #First arg: show tap output
357 #Second argument: load path for automatic loading
358 function start_lttng_sessiond_opt()
359 {
360 local withtap=$1
361 local load_path=$2
362
363 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
364 # Env variable requested no session daemon
365 return
366 fi
367
368 validate_kernel_version
369 if [ $? -ne 0 ]; then
370 fail "Start session daemon"
371 BAIL_OUT "*** Kernel too old for session daemon tests ***"
372 fi
373
374 DIR=$(readlink -f $TESTDIR)
375 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
376 export LTTNG_SESSION_CONFIG_XSD_PATH
377
378 if [ -z $(pgrep --full lt-$SESSIOND_BIN) ]; then
379 # Have a load path ?
380 if [ -n "$load_path" ]; then
381 $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --load "$load_path" --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
382 else
383 $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"
384 fi
385 #$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
386 status=$?
387 if [ $withtap -eq "1" ]; then
388 ok $status "Start session daemon"
389 fi
390 fi
391 }
392
393 function start_lttng_sessiond()
394 {
395 start_lttng_sessiond_opt 1 "$@"
396 }
397
398 function start_lttng_sessiond_notap()
399 {
400 start_lttng_sessiond_opt 0 "$@"
401 }
402
403 function stop_lttng_sessiond_opt()
404 {
405 local withtap=$1
406 local signal=$2
407 local kill_opt=""
408
409 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
410 # Env variable requested no session daemon
411 return
412 fi
413
414 PID_SESSIOND=`pgrep --full lt-$SESSIOND_BIN`
415
416 if [ -n "$2" ]; then
417 kill_opt="$kill_opt -s $signal"
418 fi
419
420 kill $kill_opt $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
421
422 if [ $? -eq 1 ]; then
423 if [ $withtap -eq "1" ]; then
424 fail "Kill sessions daemon"
425 fi
426 else
427 out=1
428 while [ -n "$out" ]; do
429 out=$(pgrep --full lt-$SESSIOND_BIN)
430 sleep 0.5
431 done
432 out=1
433 while [ -n "$out" ]; do
434 out=$(pgrep --full $CONSUMERD_BIN)
435 sleep 0.5
436 done
437 if [ $withtap -eq "1" ]; then
438 pass "Kill session daemon"
439 fi
440 fi
441 }
442
443 function stop_lttng_sessiond()
444 {
445 stop_lttng_sessiond_opt 1 "$@"
446 }
447
448 function stop_lttng_sessiond_notap()
449 {
450 stop_lttng_sessiond_opt 0 "$@"
451 }
452
453 function stop_lttng_consumerd_opt()
454 {
455 local withtap=$1
456 local signal=$2
457 local kill_opt=""
458
459 PID_CONSUMERD=`pgrep --full $CONSUMERD_BIN`
460
461 if [ -n "$2" ]; then
462 kill_opt="$kill_opt -s $signal"
463 fi
464
465 if [ $withtap -eq "1" ]; then
466 diag "Killing lttng-consumerd (pid: $PID_CONSUMERD)"
467 fi
468 kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
469 retval=$?
470 set +x
471
472 if [ $? -eq 1 ]; then
473 if [ $withtap -eq "1" ]; then
474 fail "Kill consumer daemon"
475 fi
476 return 1
477 else
478 out=1
479 while [ $out -ne 0 ]; do
480 pid=$(pgrep --full $CONSUMERD_BIN)
481
482 # If consumerds are still present check their status.
483 # A zombie status qualifies the consumerd as *killed*
484 out=0
485 for consumer_pid in $pid; do
486 state=$(ps -p $consumer_pid -o state= )
487 if [[ -n "$state" && "$state" != "Z" ]]; then
488 out=1
489 fi
490 done
491 sleep 0.5
492 done
493 if [ $withtap -eq "1" ]; then
494 pass "Kill consumer daemon"
495 fi
496 fi
497 return $retval
498 }
499
500 function stop_lttng_consumerd()
501 {
502 stop_lttng_consumerd_opt 1 "$@"
503 }
504
505 function stop_lttng_consumerd_notap()
506 {
507 stop_lttng_consumerd_opt 0 "$@"
508 }
509
510 function list_lttng_with_opts ()
511 {
512 local opts=$1
513 $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
514 ok $? "Lttng-tool list command with option $opts"
515 }
516
517 function create_lttng_session_no_output ()
518 {
519 local sess_name=$1
520
521 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
522 ok $? "Create session $sess_name in no-output mode"
523 }
524
525 function create_lttng_session ()
526 {
527 local expected_to_fail=$1
528 local sess_name=$2
529 local trace_path=$3
530 local opt=$4
531
532 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path $opt > $OUTPUT_DEST
533 ret=$?
534 if [[ $expected_to_fail -eq "1" ]]; then
535 test "$ret" -ne "0"
536 ok $? "Create session $sess_name in $trace_path failed as expected"
537 else
538 ok $ret "Create session $sess_name in $trace_path"
539 fi
540 }
541
542 function create_lttng_session_ok ()
543 {
544 create_lttng_session 0 "$@"
545 }
546
547 function create_lttng_session_fail ()
548 {
549 create_lttng_session 1 "$@"
550 }
551
552
553 function enable_ust_lttng_channel ()
554 {
555 local expected_to_fail=$1
556 local sess_name=$2
557 local channel_name=$3
558 local opt=$4
559
560 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
561 ret=$?
562 if [[ $expected_to_fail -eq "1" ]]; then
563 test "$ret" -ne "0"
564 ok $? "Enable channel $channel_name for session $sess_name failed as expected"
565 else
566 ok $ret "Enable channel $channel_name for session $sess_name"
567 fi
568 }
569
570 function enable_ust_lttng_channel_ok ()
571 {
572 enable_ust_lttng_channel 0 "$@"
573 }
574
575 function enable_ust_lttng_channel_fail ()
576 {
577 enable_ust_lttng_channel 1 "$@"
578 }
579
580 function disable_ust_lttng_channel()
581 {
582 local sess_name=$1
583 local channel_name=$2
584
585 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
586 ok $? "Disable channel $channel_name for session $sess_name"
587 }
588
589 function enable_lttng_mmap_overwrite_kernel_channel()
590 {
591 local sess_name=$1
592 local channel_name=$2
593
594 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
595 ok $? "Enable channel $channel_name for session $sess_name"
596 }
597
598 function enable_lttng_mmap_overwrite_ust_channel()
599 {
600 local sess_name=$1
601 local channel_name=$2
602
603 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
604 ok $? "Enable channel $channel_name for session $sess_name"
605 }
606
607 function enable_ust_lttng_event ()
608 {
609 local expected_to_fail=$1
610 local sess_name=$2
611 local event_name="$3"
612 local channel_name=$4
613
614 if [ -z $channel_name ]; then
615 # default channel if none specified
616 chan=""
617 else
618 chan="-c $channel_name"
619 fi
620
621 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
622 ret=$?
623 if [[ $expected_to_fail -eq "1" ]]; then
624 test $ret -ne "0"
625 ok $? "Enable ust event $event_name for session $session_name failed as expected"
626 else
627 ok $ret "Enable ust event $event_name for session $sess_name"
628 fi
629 }
630
631 function enable_ust_lttng_event_ok ()
632 {
633 enable_ust_lttng_event 0 "$@"
634 }
635
636 function enable_ust_lttng_event_fail ()
637 {
638 enable_ust_lttng_event 1 "$@"
639 }
640
641 function enable_jul_lttng_event()
642 {
643 sess_name=$1
644 event_name="$2"
645 channel_name=$3
646
647 if [ -z $channel_name ]; then
648 # default channel if none specified
649 chan=""
650 else
651 chan="-c $channel_name"
652 fi
653
654 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
655 ok $? "Enable JUL event $event_name for session $sess_name"
656 }
657
658 function enable_jul_lttng_event_loglevel()
659 {
660 local sess_name=$1
661 local event_name="$2"
662 local loglevel=$3
663 local channel_name=$4
664
665 if [ -z $channel_name ]; then
666 # default channel if none specified
667 chan=""
668 else
669 chan="-c $channel_name"
670 fi
671
672 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
673 ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
674 }
675
676 function enable_log4j_lttng_event()
677 {
678 sess_name=$1
679 event_name="$2"
680 channel_name=$3
681
682 if [ -z $channel_name ]; then
683 # default channel if none specified
684 chan=""
685 else
686 chan="-c $channel_name"
687 fi
688
689 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
690 ok $? "Enable LOG4J event $event_name for session $sess_name"
691 }
692
693 function enable_log4j_lttng_event_loglevel()
694 {
695 local sess_name=$1
696 local event_name="$2"
697 local loglevel=$3
698 local channel_name=$4
699
700 if [ -z $channel_name ]; then
701 # default channel if none specified
702 chan=""
703 else
704 chan="-c $channel_name"
705 fi
706
707 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
708 ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
709 }
710
711 function enable_python_lttng_event()
712 {
713 sess_name=$1
714 event_name="$2"
715 channel_name=$3
716
717 if [ -z $channel_name ]; then
718 # default channel if none specified
719 chan=""
720 else
721 chan="-c $channel_name"
722 fi
723
724 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
725 ok $? "Enable Python event $event_name for session $sess_name"
726 }
727
728 function enable_python_lttng_event_loglevel()
729 {
730 local sess_name=$1
731 local event_name="$2"
732 local loglevel=$3
733 local channel_name=$4
734
735 if [ -z $channel_name ]; then
736 # default channel if none specified
737 chan=""
738 else
739 chan="-c $channel_name"
740 fi
741
742 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
743 ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel"
744 }
745
746 function enable_ust_lttng_event_filter()
747 {
748 local sess_name="$1"
749 local event_name="$2"
750 local filter="$3"
751
752 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
753 ok $? "Enable event $event_name with filtering for session $sess_name"
754 }
755
756 function enable_ust_lttng_event_loglevel()
757 {
758 local sess_name="$1"
759 local event_name="$2"
760 local loglevel="$3"
761
762 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
763 ok $? "Enable event $event_name with loglevel $loglevel"
764 }
765
766 function enable_ust_lttng_event_loglevel_only()
767 {
768 local sess_name="$1"
769 local event_name="$2"
770 local loglevel="$3"
771
772 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
773 ok $? "Enable event $event_name with loglevel-only $loglevel"
774 }
775
776 function disable_ust_lttng_event ()
777 {
778 local sess_name="$1"
779 local event_name="$2"
780 local channel_name="$3"
781
782 if [ -z $channel_name ]; then
783 # default channel if none specified
784 chan=""
785 else
786 chan="-c $channel_name"
787 fi
788
789 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
790 ok $? "Disable event $event_name for session $sess_name"
791 }
792
793 function disable_jul_lttng_event ()
794 {
795 local sess_name="$1"
796 local event_name="$2"
797
798 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1
799 ok $? "Disable JUL event $event_name for session $sess_name"
800 }
801
802 function disable_log4j_lttng_event ()
803 {
804 local sess_name="$1"
805 local event_name="$2"
806
807 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1
808 ok $? "Disable LOG4J event $event_name for session $sess_name"
809 }
810
811 function disable_python_lttng_event ()
812 {
813 local sess_name="$1"
814 local event_name="$2"
815
816 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
817 ok $? "Disable Python event $event_name for session $sess_name"
818 }
819
820 function start_lttng_tracing ()
821 {
822 local expected_to_fail=$1
823 local sess_name=$2
824
825 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
826 ret=$?
827 if [[ $expected_to_fail -eq "1" ]]; then
828 test "$ret" -ne "0"
829 ok $? "Start tracing for session $sess_name failed as expected"
830 else
831 ok $ret "Start tracing for session $sess_name"
832 fi
833 }
834
835 function start_lttng_tracing_ok ()
836 {
837 start_lttng_tracing 0 "$@"
838 }
839
840 function start_lttng_tracing_fail ()
841 {
842 start_lttng_tracing 1 "$@"
843 }
844
845 function stop_lttng_tracing ()
846 {
847 local expected_to_fail=$1
848 local sess_name=$2
849
850 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
851 ret=$?
852 if [[ $expected_to_fail -eq "1" ]]; then
853 test "$ret" -ne "0"
854 ok $? "Stop lttng tracing for session $sess_name failed as expected"
855 else
856 ok $ret "Stop lttng tracing for session $sess_name"
857 fi
858 }
859
860 function stop_lttng_tracing_ok ()
861 {
862 stop_lttng_tracing 0 "$@"
863 }
864
865 function stop_lttng_tracing_fail ()
866 {
867 stop_lttng_tracing 1 "$@"
868 }
869
870 function destroy_lttng_session ()
871 {
872 local expected_to_fail=$1
873 local sess_name=$2
874
875 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
876 ret=$?
877 if [[ $expected_to_fail -eq "1" ]]; then
878 test "$ret" -ne "0"
879 ok $? "Destroy session $sess_name failed as expected"
880 else
881 ok $ret "Destroy session $sess_name"
882 fi
883 }
884
885 function destroy_lttng_session_ok ()
886 {
887 destroy_lttng_session 0 "$@"
888
889 }
890
891 function destroy_lttng_session_fail ()
892 {
893 destroy_lttng_session 1 "$@"
894 }
895
896
897 function destroy_lttng_sessions ()
898 {
899 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
900 ok $? "Destroy all lttng sessions"
901 }
902
903 function lttng_snapshot_add_output ()
904 {
905 local expected_to_fail=$1
906 local sess_name=$2
907 local trace_path=$3
908
909 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name file://$trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
910 ret=$?
911 if [[ $expected_to_fail -eq 1 ]]; then
912 test "$ret" -ne "0"
913 ok $? "Added snapshot output file://$trace_path failed as expected"
914 else
915 ok $ret "Added snapshot output file://$trace_path"
916 fi
917 }
918
919 function lttng_snapshot_add_output_ok ()
920 {
921 lttng_snapshot_add_output 0 "$@"
922 }
923
924 function lttng_snapshot_add_output_fail ()
925 {
926 lttng_snapshot_add_output 1 "$@"
927 }
928
929 function lttng_snapshot_del_output ()
930 {
931 local expected_to_fail=$1
932 local sess_name=$2
933 local id=$3
934
935 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
936 ret=$?
937 if [[ $expected_to_fail -eq "1" ]]; then
938 test "$ret" -ne "0"
939 ok $? "Deleted snapshot output id $id failed as expected"
940 else
941 ok $ret "Deleted snapshot output id $id"
942 fi
943 }
944
945 function lttng_snapshot_del_output_ok ()
946 {
947 lttng_snapshot_del_output 0 "$@"
948 }
949
950 function lttng_snapshot_del_output_fail ()
951 {
952 lttng_snapshot_del_output 1 "$@"
953 }
954
955 function lttng_snapshot_record ()
956 {
957 local sess_name=$1
958 local trace_path=$2
959
960 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
961 ok $? "Snapshot recorded"
962 }
963
964 function lttng_snapshot_list ()
965 {
966 local sess_name=$1
967 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
968 ok $? "Snapshot list"
969 }
970
971 function lttng_save()
972 {
973 local sess_name=$1
974 local opts=$2
975
976 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
977 ok $? "Session saved"
978 }
979
980 function lttng_load()
981 {
982 local opts=$1
983
984 $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
985 ok $? "Load command with opts: $opts"
986 }
987
988 function lttng_track()
989 {
990 local expected_to_fail=$1
991 local opts=$2
992 $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST
993 ret=$?
994 if [[ $expected_to_fail -eq "1" ]]; then
995 test $ret -ne "0"
996 ok $? "Track command failed as expected with opts: $opts"
997 else
998 ok $ret "Track command with opts: $opts"
999 fi
1000 }
1001
1002 function lttng_track_ok()
1003 {
1004 lttng_track 0 "$@"
1005 }
1006
1007 function lttng_track_fail()
1008 {
1009 lttng_track 1 "$@"
1010 }
1011
1012 function lttng_untrack()
1013 {
1014 local expected_to_fail=$1
1015 local opts=$2
1016 $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST
1017 ret=$?
1018 if [[ $expected_to_fail -eq "1" ]]; then
1019 test $ret -ne "0"
1020 ok $? "Untrack command failed as expected with opts: $opts"
1021 else
1022 ok $ret "Untrack command with opts: $opts"
1023 fi
1024 }
1025
1026 function lttng_untrack_ok()
1027 {
1028 lttng_untrack 0 "$@"
1029 }
1030
1031 function lttng_untrack_fail()
1032 {
1033 lttng_untrack 1 "$@"
1034 }
1035
1036 function add_context_lttng()
1037 {
1038 local expected_to_fail="$1"
1039 local domain="$2"
1040 local session_name="$3"
1041 local channel_name="$4"
1042 local type="$5"
1043
1044 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context -s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1045 ret=$?
1046 if [[ $expected_to_fail -eq "1" ]]; then
1047 test $ret -ne "0"
1048 ok $? "Add context command failed as expected for type: $type"
1049 else
1050 ok $ret "Add context command for type: $type"
1051 fi
1052 }
1053
1054 function add_context_ust_ok()
1055 {
1056 add_context_lttng 0 -u "$@"
1057 }
1058
1059 function add_context_ust_fail()
1060 {
1061 add_context_lttng 1 -u "$@"
1062 }
1063
1064 function add_context_kernel_ok()
1065 {
1066 add_context_lttng 0 -k "$@"
1067 }
1068
1069 function add_context_kernel_fail()
1070 {
1071 add_context_lttng 1 -k "$@"
1072 }
1073
1074 function trace_matches ()
1075 {
1076 local event_name=$1
1077 local nr_iter=$2
1078 local trace_path=$3
1079
1080 which $BABELTRACE_BIN >/dev/null
1081 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1082
1083 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
1084
1085 if [ "$count" -ne "$nr_iter" ]; then
1086 fail "Trace match"
1087 diag "$count events found in trace"
1088 else
1089 pass "Trace match"
1090 fi
1091 }
1092
1093 function trace_match_only()
1094 {
1095 local event_name=$1
1096 local nr_iter=$2
1097 local trace_path=$3
1098
1099 which $BABELTRACE_BIN >/dev/null
1100 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1101
1102 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
1103 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1104
1105 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1106 pass "Trace match with $total event $event_name"
1107 else
1108 fail "Trace match"
1109 diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1110 fi
1111 }
1112
1113 function validate_trace
1114 {
1115 local event_name=$1
1116 local trace_path=$2
1117
1118 which $BABELTRACE_BIN >/dev/null
1119 if [ $? -ne 0 ]; then
1120 skip 0 "Babeltrace binary not found. Skipping trace validation"
1121 fi
1122
1123 OLDIFS=$IFS
1124 IFS=","
1125 for i in $event_name; do
1126 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1127 if [ "$traced" -ne 0 ]; then
1128 pass "Validate trace for event $i, $traced events"
1129 else
1130 fail "Validate trace for event $i"
1131 diag "Found $traced occurences of $i"
1132 fi
1133 done
1134 ret=$?
1135 IFS=$OLDIFS
1136 return $ret
1137 }
1138
1139 function validate_trace_exp()
1140 {
1141 local event_exp=$1
1142 local trace_path=$2
1143
1144 which $BABELTRACE_BIN >/dev/null
1145 skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
1146
1147 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep ${event_exp} | wc -l)
1148 if [ "$traced" -ne 0 ]; then
1149 pass "Validate trace for expression '${event_exp}', $traced events"
1150 else
1151 fail "Validate trace for expression '${event_exp}'"
1152 diag "Found $traced occurences of '${event_exp}'"
1153 fi
1154 ret=$?
1155 return $ret
1156 }
1157
1158 function validate_trace_only_exp()
1159 {
1160 local event_exp=$1
1161 local trace_path=$2
1162
1163 which $BABELTRACE_BIN >/dev/null
1164 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1165
1166 local count=$($BABELTRACE_BIN $trace_path | grep ${event_exp} | wc -l)
1167 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1168
1169 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1170 pass "Trace match with $total for expression '${event_exp}"
1171 else
1172 fail "Trace match"
1173 diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1174 fi
1175 ret=$?
1176 return $ret
1177 }
1178
1179 function validate_trace_empty()
1180 {
1181 local trace_path=$1
1182
1183 which $BABELTRACE_BIN >/dev/null
1184 if [ $? -ne 0 ]; then
1185 skip 0 "Babeltrace binary not found. Skipping trace validation"
1186 fi
1187
1188 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | wc -l)
1189 if [ "$traced" -eq 0 ]; then
1190 pass "Validate empty trace"
1191 else
1192 fail "Validate empty trace"
1193 diag "Found $traced events in trace"
1194 fi
1195 ret=$?
1196 return $ret
1197 }
This page took 0.057687 seconds and 5 git commands to generate.