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