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