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