7e8100f005e8dc35757ab819c1f229e3267b78cc
[lttng-tools.git] / tests / utils / utils.sh
1 # Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
2 #
3 # SPDX-License-Identifier: LGPL-2.1-only
4 #
5
6 SESSIOND_BIN="lttng-sessiond"
7 SESSIOND_MATCH=".*lttng-sess.*"
8 RUNAS_BIN="lttng-runas"
9 RUNAS_MATCH=".*lttng-runas.*"
10 CONSUMERD_BIN="lttng-consumerd"
11 CONSUMERD_MATCH=".*lttng-consumerd.*"
12 RELAYD_BIN="lttng-relayd"
13 RELAYD_MATCH=".*lttng-relayd.*"
14 LTTNG_BIN="lttng"
15 BABELTRACE_BIN="babeltrace"
16 OUTPUT_DEST=/dev/null
17 ERROR_OUTPUT_DEST=/dev/null
18
19 # Minimal kernel version supported for session daemon tests
20 KERNEL_MAJOR_VERSION=2
21 KERNEL_MINOR_VERSION=6
22 KERNEL_PATCHLEVEL_VERSION=27
23
24 # We set the default UST register timeout and network and app socket timeout to
25 # "wait forever", so that basic tests don't have to worry about hitting
26 # timeouts on busy systems. Specialized tests should test those corner-cases.
27 export LTTNG_UST_REGISTER_TIMEOUT=-1
28 export LTTNG_NETWORK_SOCKET_TIMEOUT=-1
29 export LTTNG_APP_SOCKET_TIMEOUT=-1
30
31 # We set the default lttng-sessiond path to /bin/true to prevent the spawning
32 # of a daemonized sessiond. This is necessary since 'lttng create' will spawn
33 # its own sessiond if none is running. It also ensures that 'lttng create'
34 # fails when no sessiond is running.
35 export LTTNG_SESSIOND_PATH="/bin/true"
36
37 source $TESTDIR/utils/tap/tap.sh
38
39 if [ -z ${LTTNG_TEST_TEARDOWN_TIMEOUT+x} ]; then
40 LTTNG_TEST_TEARDOWN_TIMEOUT=60
41 fi
42
43 function full_cleanup ()
44 {
45 # Try to kill daemons gracefully
46 stop_lttng_relayd_notap SIGTERM $LTTNG_TEST_TEARDOWN_TIMEOUT
47 stop_lttng_sessiond_notap SIGTERM $LTTNG_TEST_TEARDOWN_TIMEOUT
48
49 # If daemons are still present, forcibly kill them
50 stop_lttng_relayd_notap SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT
51 stop_lttng_sessiond_notap SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT
52 stop_lttng_consumerd_notap SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT
53
54 # Disable trap for SIGTERM since the following kill to the
55 # pidgroup will be SIGTERM. Otherwise it loops.
56 # The '-' before the pid number ($$) indicates 'kill' to signal the
57 # whole process group.
58 trap - SIGTERM && kill -- -$$
59 exit 1
60 }
61
62 function null_pipes ()
63 {
64 exec 0>/dev/null
65 exec 1>/dev/null
66 exec 2>/dev/null
67 }
68
69 trap full_cleanup SIGINT SIGTERM
70
71 # perl prove closes its child pipes before giving it a chance to run its
72 # signal trap handlers. Redirect pipes to /dev/null if SIGPIPE is caught
73 # to allow those trap handlers to proceed.
74
75 trap null_pipes SIGPIPE
76
77 # Check pgrep from env, default to pgrep if none
78 if [ -z "$PGREP" ]; then
79 PGREP=pgrep
80 fi
81
82 # Due to the renaming of threads we need to use the full command (pgrep -f) to
83 # identify the pids for multiple lttng related processes. The problem with "pgrep
84 # -f" is that it ends up also looking at the arguments. We use a two stage
85 # lookup. The first one is using "pgrep -f" yielding potential candidate.
86 # The second on perform grep on the basename of the first field of the
87 # /proc/pid/cmdline of the previously identified pids. The first field
88 # correspond to the actual command.
89 function lttng_pgrep ()
90 {
91 local pattern=$1
92 local possible_pids
93 local full_command_no_argument
94 local command_basename
95
96 possible_pids=$($PGREP -f "$pattern")
97 if [ -z "$possible_pids" ]; then
98 return 0
99 fi
100
101 while IFS= read -r pid ; do
102 # /proc/pid/cmdline is null separated.
103 if full_command_no_argument=$(cut -d '' -f 1 2>/dev/null < /proc/"$pid"/cmdline); then
104 command_basename=$(basename "$full_command_no_argument")
105 if grep -q "$pattern" <<< "$command_basename"; then
106 echo "$pid"
107 fi
108 fi
109 done <<< "$possible_pids"
110 return 0
111 }
112
113 function print_ok ()
114 {
115 # Check if we are a terminal
116 if [ -t 1 ]; then
117 echo -e "\e[1;32mOK\e[0m"
118 else
119 echo -e "OK"
120 fi
121 }
122
123 function print_fail ()
124 {
125 # Check if we are a terminal
126 if [ -t 1 ]; then
127 echo -e "\e[1;31mFAIL\e[0m"
128 else
129 echo -e "FAIL"
130 fi
131 }
132
133 function print_test_banner ()
134 {
135 local desc="$1"
136 diag "$desc"
137 }
138
139 function validate_kernel_version ()
140 {
141 local kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n'))
142 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
143 return 0
144 fi
145 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
146 return 0
147 fi
148 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
149 return 0
150 fi
151 return 1
152 }
153
154 # Generate a random string
155 # $1 = number of characters; defaults to 16
156 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
157 function randstring()
158 {
159 [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
160 cat /dev/urandom 2>/dev/null | tr -cd "$CHAR" 2>/dev/null | head -c ${1:-16} 2>/dev/null
161 echo
162 }
163
164 # Return the number of _configured_ CPUs.
165 function conf_proc_count()
166 {
167 getconf _NPROCESSORS_CONF
168 if [ $? -ne 0 ]; then
169 diag "Failed to get the number of configured CPUs"
170 fi
171 echo
172 }
173
174 # Check if base lttng-modules are present.
175 # Bail out on failure
176 function validate_lttng_modules_present ()
177 {
178 # Check for loadable modules.
179 modprobe -n lttng-tracer 2>/dev/null
180 if [ $? -eq 0 ]; then
181 return 0
182 fi
183
184 # Check for builtin modules.
185 ls /proc/lttng > /dev/null 2>&1
186 if [ $? -eq 0 ]; then
187 return 0
188 fi
189
190 BAIL_OUT "LTTng modules not detected."
191 }
192
193 function enable_kernel_lttng_event
194 {
195 local withtap="$1"
196 local expected_to_fail="$2"
197 local sess_name="$3"
198 local event_name="$4"
199 local channel_name="$5"
200
201 if [ -z "$event_name" ]; then
202 # Enable all event if no event name specified
203 event_name="-a"
204 fi
205
206 if [ -z "$channel_name" ]; then
207 # default channel if none specified
208 chan=""
209 else
210 chan="-c $channel_name"
211 fi
212
213 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
214 ret=$?
215 if [[ $expected_to_fail -eq "1" ]]; then
216 test $ret -ne "0"
217 ret=$?
218 if [ $withtap -eq "1" ]; then
219 ok $ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
220 fi
221 else
222 if [ $withtap -eq "1" ]; then
223 ok $ret "Enable kernel event $event_name for session $sess_name"
224 fi
225 fi
226 }
227
228 function enable_kernel_lttng_event_ok ()
229 {
230 enable_kernel_lttng_event 1 0 "$@"
231 }
232
233 function enable_kernel_lttng_event_fail ()
234 {
235 enable_kernel_lttng_event 1 1 "$@"
236 }
237
238 function enable_kernel_lttng_event_notap ()
239 {
240 enable_kernel_lttng_event 0 0 "$@"
241 }
242
243 # Old interface
244 function lttng_enable_kernel_event
245 {
246 enable_kernel_lttng_event_ok "$@"
247 }
248
249 function lttng_enable_kernel_syscall()
250 {
251 local expected_to_fail=$1
252 local sess_name=$2
253 local syscall_name=$3
254 local channel_name=$4
255
256 if [ -z $syscall_name ]; then
257 # Enable all event if no syscall name specified
258 syscall_name="-a"
259 fi
260
261 if [ -z $channel_name ]; then
262 # default channel if none specified
263 chan=""
264 else
265 chan="-c $channel_name"
266 fi
267
268 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
269 ret=$?
270 if [[ $expected_to_fail -eq "1" ]]; then
271 test $ret -ne "0"
272 ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
273 else
274 ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
275 fi
276 }
277
278 function lttng_enable_kernel_syscall_ok()
279 {
280 lttng_enable_kernel_syscall 0 "$@"
281 }
282
283 function lttng_enable_kernel_syscall_fail()
284 {
285 lttng_enable_kernel_syscall 1 "$@"
286 }
287
288 function lttng_disable_kernel_syscall()
289 {
290 local expected_to_fail=$1
291 local sess_name=$2
292 local syscall_name=$3
293 local channel_name=$4
294
295 if [ -z $syscall_name ]; then
296 # Enable all event if no syscall name specified
297 syscall_name="-a"
298 fi
299
300 if [ -z $channel_name ]; then
301 # default channel if none specified
302 chan=""
303 else
304 chan="-c $channel_name"
305 fi
306
307 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
308
309 ret=$?
310 if [[ $expected_to_fail -eq "1" ]]; then
311 test $ret -ne "0"
312 ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
313 else
314 ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
315 fi
316 }
317
318 function lttng_disable_kernel_syscall_ok()
319 {
320 lttng_disable_kernel_syscall 0 "$@"
321 }
322
323 function lttng_disable_kernel_syscall_fail()
324 {
325 lttng_disable_kernel_syscall 1 "$@"
326 }
327
328 function lttng_enable_kernel_function_event ()
329 {
330 local expected_to_fail="$1"
331 local sess_name="$2"
332 local target="$3"
333 local event_name="$4"
334
335 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event --kernel --function="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
336 ret=$?
337 if [[ $expected_to_fail -eq "1" ]]; then
338 test $ret -ne "0"
339 ok $? "Enable kernel function event for session $sess_name failed as expected"
340 else
341 ok $ret "Enable kernel function event for session $sess_name"
342 fi
343 }
344
345 function lttng_enable_kernel_function_event_ok ()
346 {
347 lttng_enable_kernel_function_event 0 "$@"
348 }
349
350 function lttng_enable_kernel_userspace_probe_event ()
351 {
352 local expected_to_fail="$1"
353 local sess_name="$2"
354 local target="$3"
355 local event_name="$4"
356
357 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event --kernel --userspace-probe="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
358 ret=$?
359 if [[ $expected_to_fail -eq "1" ]]; then
360 test $ret -ne "0"
361 ok $? "Enable kernel userspace probe event for session $sess_name failed as expected"
362 else
363 ok $ret "Enable kernel userspace probe event for session $sess_name"
364 fi
365 }
366
367 function lttng_enable_kernel_userspace_probe_event_fail ()
368 {
369 lttng_enable_kernel_userspace_probe_event 1 "$@"
370 }
371
372 function lttng_enable_kernel_userspace_probe_event_ok ()
373 {
374 lttng_enable_kernel_userspace_probe_event 0 "$@"
375 }
376
377 function disable_kernel_lttng_userspace_probe_event_ok ()
378 {
379 local sess_name="$1"
380 local event_name="$2"
381
382 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" disable-event --kernel "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
383 ok $? "Disable kernel event $target for session $sess_name"
384 }
385 function lttng_enable_kernel_channel()
386 {
387 local withtap=$1
388 local expected_to_fail=$2
389 local sess_name=$3
390 local channel_name=$4
391 local opts="${@:5}"
392
393 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
394 ret=$?
395 if [[ $expected_to_fail -eq "1" ]]; then
396 test "$ret" -ne "0"
397 ret=$?
398 if [ $withtap -eq "1" ]; then
399 ok $ret "Enable channel $channel_name for session $sess_name failed as expected"
400 fi
401 else
402 if [ $withtap -eq "1" ]; then
403 ok $ret "Enable channel $channel_name for session $sess_name"
404 fi
405 fi
406 }
407
408 function lttng_enable_kernel_channel_ok()
409 {
410 lttng_enable_kernel_channel 1 0 "$@"
411 }
412
413 function lttng_enable_kernel_channel_fail()
414 {
415 lttng_enable_kernel_channel 1 1 "$@"
416 }
417
418 function lttng_enable_kernel_channel_notap()
419 {
420 lttng_enable_kernel_channel 0 0 "$@"
421 }
422
423 function enable_kernel_lttng_channel_ok()
424 {
425 lttng_enable_kernel_channel 1 0 "$@"
426 }
427
428 function lttng_disable_kernel_channel()
429 {
430 local expected_to_fail=$1
431 local sess_name=$2
432 local channel_name=$3
433
434 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
435 ret=$?
436 if [[ $expected_to_fail -eq "1" ]]; then
437 test "$ret" -ne "0"
438 ok $? "Disable channel $channel_name for session $sess_name failed as expected"
439 else
440 ok $ret "Disable channel $channel_name for session $sess_name"
441 fi
442 }
443
444 function lttng_disable_kernel_channel_ok()
445 {
446 lttng_disable_kernel_channel 0 "$@"
447 }
448
449 function lttng_disable_kernel_channel_fail()
450 {
451 lttng_disable_kernel_channel 1 "$@"
452 }
453
454 function start_lttng_relayd_opt()
455 {
456 local withtap=$1
457 local process_mode=$2
458 local opt=$3
459
460 DIR=$(readlink -f "$TESTDIR")
461
462 if [ -z $(lttng_pgrep "$RELAYD_MATCH") ]; then
463 # shellcheck disable=SC2086
464 $DIR/../src/bin/lttng-relayd/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
465 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
466 if [ $? -eq 1 ]; then
467 if [ $withtap -eq "1" ]; then
468 fail "Start lttng-relayd (process mode: $process_mode opt: $opt)"
469 fi
470 return 1
471 else
472 if [ $withtap -eq "1" ]; then
473 pass "Start lttng-relayd (process mode: $process_mode opt: $opt)"
474 fi
475 fi
476 else
477 pass "Start lttng-relayd (opt: $opt)"
478 fi
479 }
480
481 function start_lttng_relayd()
482 {
483 start_lttng_relayd_opt 1 "-b" "$@"
484 }
485
486 function start_lttng_relayd_notap()
487 {
488 start_lttng_relayd_opt 0 "-b" "$@"
489 }
490
491 function stop_lttng_relayd_opt()
492 {
493 local withtap=$1
494 local signal=$2
495
496 if [ -z "$signal" ]; then
497 signal="SIGTERM"
498 fi
499
500 local timeout_s=$3
501 local dtimeleft_s=
502
503 # Multiply time by 2 to simplify integer arithmetic
504 if [ -n "$timeout_s" ]; then
505 dtimeleft_s=$((timeout_s * 2))
506 fi
507
508 local retval=0
509 local pids=
510
511 pids=$(lttng_pgrep "$RELAYD_MATCH")
512 if [ -z "$pids" ]; then
513 if [ "$withtap" -eq "1" ]; then
514 pass "No relay daemon to kill"
515 fi
516 return 0
517 fi
518
519 diag "Killing (signal $signal) lttng-relayd (pid: $pids)"
520
521 # shellcheck disable=SC2086
522 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
523 retval=1
524 if [ "$withtap" -eq "1" ]; then
525 fail "Kill relay daemon"
526 fi
527 else
528 out=1
529 while [ -n "$out" ]; do
530 out=$(lttng_pgrep "$RELAYD_MATCH")
531 if [ -n "$dtimeleft_s" ]; then
532 if [ $dtimeleft_s -lt 0 ]; then
533 out=
534 retval=1
535 fi
536 dtimeleft_s=$((dtimeleft_s - 1))
537 fi
538 sleep 0.5
539 done
540 if [ "$withtap" -eq "1" ]; then
541 if [ "$retval" -eq "0" ]; then
542 pass "Wait after kill relay daemon"
543 else
544 fail "Wait after kill relay daemon"
545 fi
546 fi
547 fi
548 return $retval
549 }
550
551 function stop_lttng_relayd()
552 {
553 stop_lttng_relayd_opt 1 "$@"
554 }
555
556 function stop_lttng_relayd_notap()
557 {
558 stop_lttng_relayd_opt 0 "$@"
559 }
560
561 #First arg: show tap output
562 #Second argument: load path for automatic loading
563 function start_lttng_sessiond_opt()
564 {
565 local withtap=$1
566 local load_path=$2
567
568 local env_vars=""
569 local consumerd=""
570
571 local long_bit_value=
572 long_bit_value=$(getconf LONG_BIT)
573
574 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
575 # Env variable requested no session daemon
576 return
577 fi
578
579 DIR=$(readlink -f "$TESTDIR")
580
581 # Get long_bit value for 32/64 consumerd
582 case "$long_bit_value" in
583 32)
584 consumerd="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
585 ;;
586 64)
587 consumerd="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
588 ;;
589 *)
590 return
591 ;;
592 esac
593
594 # Check for env. variable. Allow the use of LD_PRELOAD etc.
595 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
596 env_vars="${LTTNG_SESSIOND_ENV_VARS} "
597 fi
598 env_vars="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN"
599
600 if ! validate_kernel_version; then
601 fail "Start session daemon"
602 BAIL_OUT "*** Kernel too old for session daemon tests ***"
603 fi
604
605 : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}"
606 export LTTNG_SESSION_CONFIG_XSD_PATH
607
608 if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ]; then
609 # Have a load path ?
610 if [ -n "$load_path" ]; then
611 # shellcheck disable=SC2086
612 env $env_vars --load "$load_path" --background "$consumerd"
613 else
614 # shellcheck disable=SC2086
615 env $env_vars --background "$consumerd"
616 fi
617 #$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
618 status=$?
619 if [ "$withtap" -eq "1" ]; then
620 ok $status "Start session daemon"
621 fi
622 fi
623 }
624
625 function start_lttng_sessiond()
626 {
627 start_lttng_sessiond_opt 1 "$@"
628 }
629
630 function start_lttng_sessiond_notap()
631 {
632 start_lttng_sessiond_opt 0 "$@"
633 }
634
635 function stop_lttng_sessiond_opt()
636 {
637 local withtap=$1
638 local signal=$2
639
640 if [ -z "$signal" ]; then
641 signal=SIGTERM
642 fi
643
644 local timeout_s=$3
645 local dtimeleft_s=
646
647 # Multiply time by 2 to simplify integer arithmetic
648 if [ -n "$timeout_s" ]; then
649 dtimeleft_s=$((timeout_s * 2))
650 fi
651
652 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
653 # Env variable requested no session daemon
654 return 0
655 fi
656
657 local retval=0
658
659 local runas_pids=
660 runas_pids=$(lttng_pgrep "$RUNAS_MATCH")
661
662 local pids=
663 pids=$(lttng_pgrep "$SESSIOND_MATCH")
664
665 if [ -n "$runas_pids" ]; then
666 pids="$pids $runas_pids"
667 fi
668
669 if [ -z "$pids" ]; then
670 if [ "$withtap" -eq "1" ]; then
671 fail "No session daemon to kill"
672 else
673 BAIL_OUT "No session daemon to kill"
674 fi
675 return 0
676 fi
677
678 diag "Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
679
680 # shellcheck disable=SC2086
681 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
682 retval=1
683 if [ "$withtap" -eq "1" ]; then
684 fail "Kill sessions daemon"
685 fi
686 else
687 out=1
688 while [ -n "$out" ]; do
689 out=$(lttng_pgrep "${SESSIOND_MATCH}")
690 if [ -n "$dtimeleft_s" ]; then
691 if [ $dtimeleft_s -lt 0 ]; then
692 out=
693 retval=1
694 fi
695 dtimeleft_s=$((dtimeleft_s - 1))
696 fi
697 sleep 0.5
698 done
699 out=1
700 while [ -n "$out" ]; do
701 out=$(lttng_pgrep "$CONSUMERD_MATCH")
702 if [ -n "$dtimeleft_s" ]; then
703 if [ $dtimeleft_s -lt 0 ]; then
704 out=
705 retval=1
706 fi
707 dtimeleft_s=$((dtimeleft_s - 1))
708 fi
709 sleep 0.5
710 done
711
712 if [ "$withtap" -eq "1" ]; then
713 if [ "$retval" -eq "0" ]; then
714 pass "Wait after kill session daemon"
715 else
716 fail "Wait after kill session daemon"
717 fi
718 fi
719 fi
720 if [ "$signal" = "SIGKILL" ]; then
721 if [ "$(id -u)" -eq "0" ]; then
722 local modules=
723 modules="$(lsmod | grep ^lttng | awk '{print $1}')"
724
725 if [ -n "$modules" ]; then
726 diag "Unloading all LTTng modules"
727 modprobe --remove "$modules"
728 fi
729 fi
730 fi
731
732 return $retval
733 }
734
735 function stop_lttng_sessiond()
736 {
737 stop_lttng_sessiond_opt 1 "$@"
738 }
739
740 function stop_lttng_sessiond_notap()
741 {
742 stop_lttng_sessiond_opt 0 "$@"
743 }
744
745 function sigstop_lttng_sessiond_opt()
746 {
747 local withtap=$1
748 local signal=SIGSTOP
749
750 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
751 # Env variable requested no session daemon
752 return
753 fi
754
755 PID_SESSIOND="$(lttng_pgrep "${SESSIOND_MATCH}") $(lttng_pgrep "$RUNAS_MATCH")"
756
757 if [ "$withtap" -eq "1" ]; then
758 diag "Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$PID_SESSIOND" | tr '\n' ' ')"
759 fi
760
761 # shellcheck disable=SC2086
762 if ! kill -s $signal $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
763 if [ "$withtap" -eq "1" ]; then
764 fail "Sending SIGSTOP to session daemon"
765 fi
766 else
767 out=1
768 while [ $out -ne 0 ]; do
769 pid="$(lttng_pgrep "$SESSIOND_MATCH")"
770
771 # Wait until state becomes stopped for session
772 # daemon(s).
773 out=0
774 for sessiond_pid in $pid; do
775 state="$(ps -p "$sessiond_pid" -o state= )"
776 if [[ -n "$state" && "$state" != "T" ]]; then
777 out=1
778 fi
779 done
780 sleep 0.5
781 done
782 if [ "$withtap" -eq "1" ]; then
783 pass "Sending SIGSTOP to session daemon"
784 fi
785 fi
786 }
787
788 function sigstop_lttng_sessiond()
789 {
790 sigstop_lttng_sessiond_opt 1 "$@"
791 }
792
793 function sigstop_lttng_sessiond_notap()
794 {
795 sigstop_lttng_sessiond_opt 0 "$@"
796 }
797
798 function stop_lttng_consumerd_opt()
799 {
800 local withtap=$1
801 local signal=$2
802
803 if [ -z "$signal" ]; then
804 signal=SIGTERM
805 fi
806
807 local timeout_s=$3
808 local dtimeleft_s=
809
810 # Multiply time by 2 to simplify integer arithmetic
811 if [ -n "$timeout_s" ]; then
812 dtimeleft_s=$((timeout_s * 2))
813 fi
814
815 local retval=0
816
817 PID_CONSUMERD="$(lttng_pgrep "$CONSUMERD_MATCH")"
818
819 if [ -z "$PID_CONSUMERD" ]; then
820 if [ "$withtap" -eq "1" ]; then
821 pass "No consumer daemon to kill"
822 fi
823 return 0
824 fi
825
826 diag "Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')"
827
828 # shellcheck disable=SC2086
829 if ! kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
830 retval=1
831 if [ "$withtap" -eq "1" ]; then
832 fail "Kill consumer daemon"
833 fi
834 else
835 out=1
836 while [ $out -ne 0 ]; do
837 pid="$(lttng_pgrep "$CONSUMERD_MATCH")"
838
839 # If consumerds are still present check their status.
840 # A zombie status qualifies the consumerd as *killed*
841 out=0
842 for consumer_pid in $pid; do
843 state="$(ps -p "$consumer_pid" -o state= )"
844 if [[ -n "$state" && "$state" != "Z" ]]; then
845 out=1
846 fi
847 done
848 if [ -n "$dtimeleft_s" ]; then
849 if [ $dtimeleft_s -lt 0 ]; then
850 out=0
851 retval=1
852 fi
853 dtimeleft_s=$((dtimeleft_s - 1))
854 fi
855 sleep 0.5
856 done
857 if [ "$withtap" -eq "1" ]; then
858 if [ "$retval" -eq "0" ]; then
859 pass "Wait after kill consumer daemon"
860 else
861 fail "Wait after kill consumer daemon"
862 fi
863 fi
864 fi
865
866 return $retval
867 }
868
869 function stop_lttng_consumerd()
870 {
871 stop_lttng_consumerd_opt 1 "$@"
872 }
873
874 function stop_lttng_consumerd_notap()
875 {
876 stop_lttng_consumerd_opt 0 "$@"
877 }
878
879 function sigstop_lttng_consumerd_opt()
880 {
881 local withtap=$1
882 local signal=SIGSTOP
883
884 PID_CONSUMERD="$(lttng_pgrep "$CONSUMERD_MATCH")"
885
886 diag "Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')"
887
888 # shellcheck disable=SC2086
889 kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
890 retval=$?
891
892 if [ $retval -eq 1 ]; then
893 if [ "$withtap" -eq "1" ]; then
894 fail "Sending SIGSTOP to consumer daemon"
895 fi
896 return 1
897 else
898 out=1
899 while [ $out -ne 0 ]; do
900 pid="$(lttng_pgrep "$CONSUMERD_MATCH")"
901
902 # Wait until state becomes stopped for all
903 # consumers.
904 out=0
905 for consumer_pid in $pid; do
906 state="$(ps -p "$consumer_pid" -o state= )"
907 if [[ -n "$state" && "$state" != "T" ]]; then
908 out=1
909 fi
910 done
911 sleep 0.5
912 done
913 if [ "$withtap" -eq "1" ]; then
914 pass "Sending SIGSTOP to consumer daemon"
915 fi
916 fi
917 return $retval
918 }
919
920 function sigstop_lttng_consumerd()
921 {
922 sigstop_lttng_consumerd_opt 1 "$@"
923 }
924
925 function sigstop_lttng_consumerd_notap()
926 {
927 sigstop_lttng_consumerd_opt 0 "$@"
928 }
929
930 function list_lttng_with_opts ()
931 {
932 local opts=$1
933 $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
934 ok $? "Lttng-tool list command with option $opts"
935 }
936
937 function create_lttng_session_no_output ()
938 {
939 local sess_name=$1
940 local opts="${@:2}"
941
942 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
943 ok $? "Create session $sess_name in no-output mode"
944 }
945
946 function create_lttng_session_uri () {
947 local sess_name=$1
948 local uri=$2
949 local opts="${@:3}"
950
951 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -U $uri $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
952 ok $? "Create session $sess_name with uri:$uri and opts: $opts"
953 }
954
955 function create_lttng_session ()
956 {
957 local withtap=$1
958 local expected_to_fail=$2
959 local sess_name=$3
960 local trace_path=$4
961 local opt=$5
962
963 if [ -z "$trace_path" ]; then
964 # Use lttng-sessiond default output.
965 trace_path=""
966 else
967 trace_path="-o $trace_path"
968 fi
969
970 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create "$sess_name" $trace_path $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
971 ret=$?
972 if [ $expected_to_fail -eq "1" ]; then
973 test "$ret" -ne "0"
974 ret=$?
975 if [ $withtap -eq "1" ]; then
976 ok $ret "Create session $sess_name in $trace_path failed as expected"
977 fi
978 else
979 if [ $withtap -eq "1" ]; then
980 ok $ret "Create session $sess_name in $trace_path"
981 fi
982 fi
983 return $ret
984 }
985
986 function create_lttng_session_ok ()
987 {
988 create_lttng_session 1 0 "$@"
989 }
990
991 function create_lttng_session_fail ()
992 {
993 create_lttng_session 1 1 "$@"
994 }
995
996 function create_lttng_session_notap ()
997 {
998 create_lttng_session 0 0 "$@"
999 }
1000
1001
1002 function enable_ust_lttng_channel ()
1003 {
1004 local withtap=$1
1005 local expected_to_fail=$2
1006 local sess_name=$3
1007 local channel_name=$4
1008 local opts="${@:5}"
1009
1010 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1011 ret=$?
1012 if [[ $expected_to_fail -eq "1" ]]; then
1013 test "$ret" -ne "0"
1014 ret=$?
1015 if [ $withtap -eq "1" ]; then
1016 ok $ret "Enable channel $channel_name for session $sess_name failed as expected"
1017 fi
1018 else
1019 if [ $withtap -eq "1" ]; then
1020 ok $ret "Enable channel $channel_name for session $sess_name"
1021 fi
1022 fi
1023 return $ret
1024 }
1025
1026 function enable_ust_lttng_channel_ok ()
1027 {
1028 enable_ust_lttng_channel 1 0 "$@"
1029 }
1030
1031 function enable_ust_lttng_channel_fail ()
1032 {
1033 enable_ust_lttng_channel 1 1 "$@"
1034 }
1035
1036 function enable_ust_lttng_channel_notap ()
1037 {
1038 enable_ust_lttng_channel 0 0 "$@"
1039 }
1040
1041 function disable_ust_lttng_channel()
1042 {
1043 local sess_name=$1
1044 local channel_name=$2
1045
1046 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1047 ok $? "Disable channel $channel_name for session $sess_name"
1048 }
1049
1050 function enable_lttng_mmap_overwrite_kernel_channel()
1051 {
1052 local sess_name=$1
1053 local channel_name=$2
1054
1055 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1056 ok $? "Enable channel $channel_name for session $sess_name"
1057 }
1058
1059 function enable_lttng_mmap_discard_small_kernel_channel()
1060 {
1061 local sess_name=$1
1062 local channel_name=$2
1063
1064 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --discard --subbuf-size=$(getconf PAGE_SIZE) --num-subbuf=2 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1065 ok $? "Enable small discard channel $channel_name for session $sess_name"
1066 }
1067
1068 function enable_lttng_mmap_overwrite_small_kernel_channel()
1069 {
1070 local sess_name=$1
1071 local channel_name=$2
1072
1073 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite --subbuf-size=$(getconf PAGE_SIZE) --num-subbuf=2 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1074 ok $? "Enable small discard channel $channel_name for session $sess_name"
1075 }
1076
1077 function enable_lttng_mmap_overwrite_ust_channel()
1078 {
1079 local sess_name=$1
1080 local channel_name=$2
1081
1082 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1083 ok $? "Enable channel $channel_name for session $sess_name"
1084 }
1085
1086 function enable_ust_lttng_event ()
1087 {
1088 local withtap=$1
1089 local expected_to_fail=$2
1090 local sess_name=$3
1091 local event_name="$4"
1092 local channel_name=$5
1093
1094 if [ -z $channel_name ]; then
1095 # default channel if none specified
1096 chan=""
1097 else
1098 chan="-c $channel_name"
1099 fi
1100
1101 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1102 ret=$?
1103 if [[ $expected_to_fail -eq "1" ]]; then
1104 test $ret -ne "0"
1105 ret=$?
1106 if [[ $withtap -eq "1" ]]; then
1107 ok $ret "Enable ust event $event_name for session $session_name failed as expected"
1108 fi
1109 else
1110 if [[ $withtap -eq "1" ]]; then
1111 ok $ret "Enable ust event $event_name for session $sess_name"
1112 fi
1113 fi
1114 return $ret
1115 }
1116
1117 function enable_ust_lttng_event_ok ()
1118 {
1119 enable_ust_lttng_event 1 0 "$@"
1120 }
1121
1122 function enable_ust_lttng_event_fail ()
1123 {
1124 enable_ust_lttng_event 1 1 "$@"
1125 }
1126
1127 function enable_ust_lttng_event_notap ()
1128 {
1129 enable_ust_lttng_event 0 0 "$@"
1130 }
1131
1132 function enable_jul_lttng_event()
1133 {
1134 sess_name=$1
1135 event_name="$2"
1136 channel_name=$3
1137
1138 if [ -z $channel_name ]; then
1139 # default channel if none specified
1140 chan=""
1141 else
1142 chan="-c $channel_name"
1143 fi
1144
1145 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1146 ok $? "Enable JUL event $event_name for session $sess_name"
1147 }
1148
1149 function enable_jul_lttng_event_loglevel()
1150 {
1151 local sess_name=$1
1152 local event_name="$2"
1153 local loglevel=$3
1154 local channel_name=$4
1155
1156 if [ -z $channel_name ]; then
1157 # default channel if none specified
1158 chan=""
1159 else
1160 chan="-c $channel_name"
1161 fi
1162
1163 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1164 ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
1165 }
1166
1167 function enable_log4j_lttng_event()
1168 {
1169 sess_name=$1
1170 event_name="$2"
1171 channel_name=$3
1172
1173 if [ -z $channel_name ]; then
1174 # default channel if none specified
1175 chan=""
1176 else
1177 chan="-c $channel_name"
1178 fi
1179
1180 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1181 ok $? "Enable LOG4J event $event_name for session $sess_name"
1182 }
1183
1184 function enable_log4j_lttng_event_loglevel()
1185 {
1186 local sess_name=$1
1187 local event_name="$2"
1188 local loglevel=$3
1189 local channel_name=$4
1190
1191 if [ -z $channel_name ]; then
1192 # default channel if none specified
1193 chan=""
1194 else
1195 chan="-c $channel_name"
1196 fi
1197
1198 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1199 ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
1200 }
1201
1202 function enable_python_lttng_event()
1203 {
1204 sess_name=$1
1205 event_name="$2"
1206 channel_name=$3
1207
1208 if [ -z $channel_name ]; then
1209 # default channel if none specified
1210 chan=""
1211 else
1212 chan="-c $channel_name"
1213 fi
1214
1215 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1216 ok $? "Enable Python event $event_name for session $sess_name"
1217 }
1218
1219 function enable_python_lttng_event_loglevel()
1220 {
1221 local sess_name=$1
1222 local event_name="$2"
1223 local loglevel=$3
1224 local channel_name=$4
1225
1226 if [ -z $channel_name ]; then
1227 # default channel if none specified
1228 chan=""
1229 else
1230 chan="-c $channel_name"
1231 fi
1232
1233 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1234 ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel"
1235 }
1236
1237 function enable_ust_lttng_event_filter()
1238 {
1239 local sess_name="$1"
1240 local event_name="$2"
1241 local filter="$3"
1242 local channel_name=$4
1243
1244 if [ -z $channel_name ]; then
1245 # default channel if none specified
1246 chan=""
1247 else
1248 chan="-c $channel_name"
1249 fi
1250
1251 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $chan "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1252 ok $? "Enable event $event_name with filtering for session $sess_name"
1253 }
1254
1255 function enable_ust_lttng_event_loglevel()
1256 {
1257 local sess_name="$1"
1258 local event_name="$2"
1259 local loglevel="$3"
1260
1261 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1262 ok $? "Enable event $event_name with loglevel $loglevel"
1263 }
1264
1265 function enable_ust_lttng_event_loglevel_only()
1266 {
1267 local sess_name="$1"
1268 local event_name="$2"
1269 local loglevel="$3"
1270
1271 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1272 ok $? "Enable event $event_name with loglevel-only $loglevel"
1273 }
1274
1275 function disable_ust_lttng_event ()
1276 {
1277 local sess_name="$1"
1278 local event_name="$2"
1279 local channel_name="$3"
1280
1281 if [ -z $channel_name ]; then
1282 # default channel if none specified
1283 chan=""
1284 else
1285 chan="-c $channel_name"
1286 fi
1287
1288 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1289 ok $? "Disable event $event_name for session $sess_name"
1290 }
1291
1292 function disable_jul_lttng_event ()
1293 {
1294 local sess_name="$1"
1295 local event_name="$2"
1296
1297 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1
1298 ok $? "Disable JUL event $event_name for session $sess_name"
1299 }
1300
1301 function disable_log4j_lttng_event ()
1302 {
1303 local sess_name="$1"
1304 local event_name="$2"
1305
1306 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1
1307 ok $? "Disable LOG4J event $event_name for session $sess_name"
1308 }
1309
1310 function disable_python_lttng_event ()
1311 {
1312 local sess_name="$1"
1313 local event_name="$2"
1314
1315 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1316 ok $? "Disable Python event $event_name for session $sess_name"
1317 }
1318
1319 function start_lttng_tracing_opt ()
1320 {
1321 local withtap=$1
1322 local expected_to_fail=$2
1323 local sess_name=$3
1324
1325 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1326 ret=$?
1327 if [[ $expected_to_fail -eq "1" ]]; then
1328 test "$ret" -ne "0"
1329 ret=$?
1330 if [ $withtap -eq "1" ]; then
1331 ok $? "Start tracing for session $sess_name failed as expected"
1332 fi
1333 else
1334 if [ $withtap -eq "1" ]; then
1335 ok $ret "Start tracing for session $sess_name"
1336 fi
1337 fi
1338 }
1339
1340 function start_lttng_tracing_ok ()
1341 {
1342 start_lttng_tracing_opt 1 0 "$@"
1343 }
1344
1345 function start_lttng_tracing_fail ()
1346 {
1347 start_lttng_tracing_opt 1 1 "$@"
1348 }
1349
1350 function start_lttng_tracing_notap ()
1351 {
1352 start_lttng_tracing_opt 0 1 "$@"
1353 }
1354
1355 function stop_lttng_tracing_opt ()
1356 {
1357 local withtap=$1
1358 local expected_to_fail=$2
1359 local sess_name=$3
1360
1361 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1362 ret=$?
1363 if [[ $expected_to_fail -eq "1" ]]; then
1364 test "$ret" -ne "0"
1365 ret=$?
1366 if [ $withtap -eq "1" ]; then
1367 ok $? "Stop lttng tracing for session $sess_name failed as expected"
1368 fi
1369 else
1370 if [ $withtap -eq "1" ]; then
1371 ok $ret "Stop lttng tracing for session $sess_name"
1372 fi
1373 fi
1374 }
1375
1376 function stop_lttng_tracing_ok ()
1377 {
1378 stop_lttng_tracing_opt 1 0 "$@"
1379 }
1380
1381 function stop_lttng_tracing_fail ()
1382 {
1383 stop_lttng_tracing_opt 1 1 "$@"
1384 }
1385
1386 function stop_lttng_tracing_notap ()
1387 {
1388 stop_lttng_tracing_opt 0 0 "$@"
1389 }
1390
1391 function destroy_lttng_session ()
1392 {
1393 local withtap=$1
1394 local expected_to_fail=$2
1395 local sess_name=$3
1396
1397 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1398 ret=$?
1399 if [[ $expected_to_fail -eq "1" ]]; then
1400 test "$ret" -ne "0"
1401 ret=$?
1402 if [ $withtap -eq "1" ]; then
1403 ok $ret "Destroy session $sess_name failed as expected"
1404 fi
1405 else
1406 if [ $withtap -eq "1" ]; then
1407 ok $ret "Destroy session $sess_name"
1408 fi
1409 fi
1410 }
1411
1412 function destroy_lttng_session_ok ()
1413 {
1414 destroy_lttng_session 1 0 "$@"
1415
1416 }
1417
1418 function destroy_lttng_session_fail ()
1419 {
1420 destroy_lttng_session 1 1 "$@"
1421 }
1422
1423 function destroy_lttng_session_notap ()
1424 {
1425 destroy_lttng_session 0 0 "$@"
1426 }
1427
1428 function destroy_lttng_sessions ()
1429 {
1430 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1431 ok $? "Destroy all lttng sessions"
1432 }
1433
1434 function lttng_snapshot_add_output ()
1435 {
1436 local expected_to_fail=$1
1437 local sess_name=$2
1438 local trace_path=$3
1439 local opts=$4
1440
1441 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name $trace_path $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1442 ret=$?
1443 if [[ $expected_to_fail -eq 1 ]]; then
1444 test "$ret" -ne "0"
1445 ok $? "Added snapshot output $trace_path failed as expected"
1446 else
1447 ok $ret "Added snapshot output $trace_path"
1448 fi
1449 }
1450
1451 function lttng_snapshot_add_output_ok ()
1452 {
1453 lttng_snapshot_add_output 0 "$@"
1454 }
1455
1456 function lttng_snapshot_add_output_fail ()
1457 {
1458 lttng_snapshot_add_output 1 "$@"
1459 }
1460
1461 function lttng_snapshot_del_output ()
1462 {
1463 local expected_to_fail=$1
1464 local sess_name=$2
1465 local id=$3
1466
1467 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1468 ret=$?
1469 if [[ $expected_to_fail -eq "1" ]]; then
1470 test "$ret" -ne "0"
1471 ok $? "Deleted snapshot output id $id failed as expected"
1472 else
1473 ok $ret "Deleted snapshot output id $id"
1474 fi
1475 }
1476
1477 function lttng_snapshot_del_output_ok ()
1478 {
1479 lttng_snapshot_del_output 0 "$@"
1480 }
1481
1482 function lttng_snapshot_del_output_fail ()
1483 {
1484 lttng_snapshot_del_output 1 "$@"
1485 }
1486
1487 function lttng_snapshot_record ()
1488 {
1489 local sess_name=$1
1490
1491 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name $trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1492 ok $? "Snapshot recorded"
1493 }
1494
1495 function lttng_snapshot_list ()
1496 {
1497 local sess_name=$1
1498 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1499 ok $? "Snapshot list"
1500 }
1501
1502 function lttng_save()
1503 {
1504 local sess_name=$1
1505 local opts=$2
1506
1507 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1508 ok $? "Session saved"
1509 }
1510
1511 function lttng_load()
1512 {
1513 local expected_to_fail=$1
1514 local opts=$2
1515
1516 $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1517 ret=$?
1518 if [[ $expected_to_fail -eq "1" ]]; then
1519 test $ret -ne "0"
1520 ok $? "Load command failed as expected with opts: $opts"
1521 else
1522 ok $ret "Load command with opts: $opts"
1523 fi
1524 }
1525
1526 function lttng_load_ok()
1527 {
1528 lttng_load 0 "$@"
1529 }
1530
1531 function lttng_load_fail()
1532 {
1533 lttng_load 1 "$@"
1534 }
1535
1536 function lttng_track()
1537 {
1538 local expected_to_fail="$1"
1539 shift 1
1540 local opts="$@"
1541 $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST
1542 ret=$?
1543 if [[ $expected_to_fail -eq "1" ]]; then
1544 test $ret -ne "0"
1545 ok $? "Track command failed as expected with opts: $opts"
1546 else
1547 ok $ret "Track command with opts: $opts"
1548 fi
1549 }
1550
1551 function lttng_track_ok()
1552 {
1553 lttng_track 0 "$@"
1554 }
1555
1556 function lttng_track_fail()
1557 {
1558 lttng_track 1 "$@"
1559 }
1560
1561 function lttng_untrack()
1562 {
1563 local expected_to_fail="$1"
1564 shift 1
1565 local opts="$@"
1566 $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST
1567 ret=$?
1568 if [[ $expected_to_fail -eq "1" ]]; then
1569 test $ret -ne "0"
1570 ok $? "Untrack command failed as expected with opts: $opts"
1571 else
1572 ok $ret "Untrack command with opts: $opts"
1573 fi
1574 }
1575
1576 function lttng_untrack_ok()
1577 {
1578 lttng_untrack 0 "$@"
1579 }
1580
1581 function lttng_untrack_fail()
1582 {
1583 lttng_untrack 1 "$@"
1584 }
1585
1586 function lttng_track_pid_ok()
1587 {
1588 PID=$1
1589 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track --kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1590 ok $? "Lttng track pid on the kernel domain"
1591 }
1592
1593 function lttng_untrack_kernel_all_ok()
1594 {
1595 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack --kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1596 ok $? "Lttng untrack all pid on the kernel domain"
1597 }
1598
1599 function lttng_track_ust_ok()
1600 {
1601 lttng_track_ok -u "$@"
1602 }
1603
1604 function lttng_track_ust_fail()
1605 {
1606 lttng_track_fail -u "$@"
1607 }
1608
1609 function lttng_track_kernel_ok()
1610 {
1611 lttng_track_ok -k "$@"
1612 }
1613
1614 function lttng_track_kernel_fail()
1615 {
1616 lttng_track_fail -k "$@"
1617 }
1618
1619 function lttng_untrack_ust_ok()
1620 {
1621 lttng_untrack_ok -u "$@"
1622 }
1623
1624 function lttng_untrack_ust_fail()
1625 {
1626 lttng_untrack_fail -u "$@"
1627 }
1628
1629 function lttng_untrack_kernel_ok()
1630 {
1631 lttng_untrack_ok -k "$@"
1632 }
1633
1634 function lttng_untrack_kernel_fail()
1635 {
1636 lttng_untrack_fail -k "$@"
1637 }
1638
1639 function lttng_add_context_list()
1640 {
1641 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context --list 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1642 ret=$?
1643 ok $ret "Context listing"
1644 }
1645
1646 function add_context_lttng()
1647 {
1648 local expected_to_fail="$1"
1649 local domain="$2"
1650 local session_name="$3"
1651 local channel_name="$4"
1652 local type="$5"
1653
1654 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context -s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1655 ret=$?
1656 if [[ $expected_to_fail -eq "1" ]]; then
1657 test $ret -ne "0"
1658 ok $? "Add context command failed as expected for type: $type"
1659 else
1660 ok $ret "Add context command for type: $type"
1661 fi
1662 }
1663
1664 function add_context_ust_ok()
1665 {
1666 add_context_lttng 0 -u "$@"
1667 }
1668
1669 function add_context_ust_fail()
1670 {
1671 add_context_lttng 1 -u "$@"
1672 }
1673
1674 function add_context_kernel_ok()
1675 {
1676 add_context_lttng 0 -k "$@"
1677 }
1678
1679 function add_context_kernel_fail()
1680 {
1681 add_context_lttng 1 -k "$@"
1682 }
1683
1684 function wait_live_trace_ready ()
1685 {
1686 local url=$1
1687 local zero_client_match=0
1688
1689 diag "Waiting for live trace at url: $url"
1690 while [ $zero_client_match -eq 0 ]; do
1691 zero_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "0 client(s) connected" | wc -l)
1692 sleep 0.5
1693 done
1694 pass "Waiting for live trace at url: $url"
1695 }
1696
1697 function wait_live_viewer_connect ()
1698 {
1699 local url=$1
1700 local one_client_match=0
1701
1702 diag "Waiting for live viewers on url: $url"
1703 while [ $one_client_match -eq 0 ]; do
1704 one_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "1 client(s) connected" | wc -l)
1705 sleep 0.5
1706 done
1707 pass "Waiting for live viewers on url: $url"
1708 }
1709
1710 function validate_metadata_event ()
1711 {
1712 local event_name=$1
1713 local nr_event_id=$2
1714 local trace_path=$3
1715
1716 local metadata_file=$(find $trace_path | grep metadata)
1717 local metadata_path=$(dirname $metadata_file)
1718
1719 which $BABELTRACE_BIN >/dev/null
1720 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1721
1722 local count=$($BABELTRACE_BIN --output-format=ctf-metadata $metadata_path | grep $event_name | wc -l)
1723
1724 if [ "$count" -ne "$nr_event_id" ]; then
1725 fail "Metadata match with the metadata of $count event(s) named $event_name"
1726 diag "$count matching event id found in metadata"
1727 else
1728 pass "Metadata match with the metadata of $count event(s) named $event_name"
1729 fi
1730
1731 }
1732
1733 function trace_matches ()
1734 {
1735 local event_name=$1
1736 local nr_iter=$2
1737 local trace_path=$3
1738
1739 which $BABELTRACE_BIN >/dev/null
1740 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1741
1742 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
1743
1744 if [ "$count" -ne "$nr_iter" ]; then
1745 fail "Trace match"
1746 diag "$count matching events found in trace"
1747 else
1748 pass "Trace match"
1749 fi
1750 }
1751
1752 function trace_match_only()
1753 {
1754 local event_name=$1
1755 local nr_iter=$2
1756 local trace_path=$3
1757
1758 which $BABELTRACE_BIN >/dev/null
1759 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1760
1761 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
1762 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1763
1764 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1765 pass "Trace match with $total event $event_name"
1766 else
1767 fail "Trace match"
1768 diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1769 fi
1770 }
1771
1772 function validate_trace
1773 {
1774 local event_name=$1
1775 local trace_path=$2
1776
1777 which $BABELTRACE_BIN >/dev/null
1778 if [ $? -ne 0 ]; then
1779 skip 0 "Babeltrace binary not found. Skipping trace validation"
1780 fi
1781
1782 OLDIFS=$IFS
1783 IFS=","
1784 for i in $event_name; do
1785 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1786 if [ "$traced" -ne 0 ]; then
1787 pass "Validate trace for event $i, $traced events"
1788 else
1789 fail "Validate trace for event $i"
1790 diag "Found $traced occurences of $i"
1791 fi
1792 done
1793 ret=$?
1794 IFS=$OLDIFS
1795 return $ret
1796 }
1797
1798 function validate_trace_count
1799 {
1800 local event_name=$1
1801 local trace_path=$2
1802 local expected_count=$3
1803
1804 which $BABELTRACE_BIN >/dev/null
1805 if [ $? -ne 0 ]; then
1806 skip 0 "Babeltrace binary not found. Skipping trace validation"
1807 fi
1808
1809 cnt=0
1810 OLDIFS=$IFS
1811 IFS=","
1812 for i in $event_name; do
1813 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1814 if [ "$traced" -ne 0 ]; then
1815 pass "Validate trace for event $i, $traced events"
1816 else
1817 fail "Validate trace for event $i"
1818 diag "Found $traced occurences of $i"
1819 fi
1820 cnt=$(($cnt + $traced))
1821 done
1822 IFS=$OLDIFS
1823 test $cnt -eq $expected_count
1824 ok $? "Read a total of $cnt events, expected $expected_count"
1825 }
1826
1827 function validate_trace_count_range_incl_min_excl_max
1828 {
1829 local event_name=$1
1830 local trace_path=$2
1831 local expected_min=$3
1832 local expected_max=$4
1833
1834 which $BABELTRACE_BIN >/dev/null
1835 if [ $? -ne 0 ]; then
1836 skip 0 "Babeltrace binary not found. Skipping trace validation"
1837 fi
1838
1839 cnt=0
1840 OLDIFS=$IFS
1841 IFS=","
1842 for i in $event_name; do
1843 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1844 if [ "$traced" -ge $expected_min ]; then
1845 pass "Validate trace for event $i, $traced events"
1846 else
1847 fail "Validate trace for event $i"
1848 diag "Found $traced occurences of $i"
1849 fi
1850 cnt=$(($cnt + $traced))
1851 done
1852 IFS=$OLDIFS
1853 test $cnt -lt $expected_max
1854 ok $? "Read a total of $cnt events, expected between [$expected_min, $expected_max["
1855 }
1856
1857 function trace_first_line
1858 {
1859 local trace_path=$1
1860
1861 which $BABELTRACE_BIN >/dev/null
1862 if [ $? -ne 0 ]; then
1863 skip 0 "Babeltrace binary not found. Skipping trace validation"
1864 fi
1865
1866 $BABELTRACE_BIN $trace_path 2>/dev/null | head -n 1
1867 }
1868
1869 function validate_trace_exp()
1870 {
1871 local event_exp=$1
1872 local trace_path=$2
1873
1874 which $BABELTRACE_BIN >/dev/null
1875 skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
1876
1877 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep --extended-regexp ${event_exp} | wc -l)
1878 if [ "$traced" -ne 0 ]; then
1879 pass "Validate trace for expression '${event_exp}', $traced events"
1880 else
1881 fail "Validate trace for expression '${event_exp}'"
1882 diag "Found $traced occurences of '${event_exp}'"
1883 fi
1884 ret=$?
1885 return $ret
1886 }
1887
1888 function validate_trace_only_exp()
1889 {
1890 local event_exp=$1
1891 local trace_path=$2
1892
1893 which $BABELTRACE_BIN >/dev/null
1894 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1895
1896 local count=$($BABELTRACE_BIN $trace_path | grep --extended-regexp ${event_exp} | wc -l)
1897 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1898
1899 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1900 pass "Trace match with $total for expression '${event_exp}'"
1901 else
1902 fail "Trace match"
1903 diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1904 fi
1905 ret=$?
1906 return $ret
1907 }
1908
1909 function validate_trace_empty()
1910 {
1911 local trace_path=$1
1912
1913 which $BABELTRACE_BIN >/dev/null
1914 if [ $? -ne 0 ]; then
1915 skip 0 "Babeltrace binary not found. Skipping trace validation"
1916 fi
1917
1918 events=$($BABELTRACE_BIN $trace_path 2>/dev/null)
1919 ret=$?
1920 if [ $ret -ne 0 ]; then
1921 fail "Failed to parse trace"
1922 return $ret
1923 fi
1924
1925 traced=$(echo -n "$events" | wc -l)
1926 if [ "$traced" -eq 0 ]; then
1927 pass "Validate empty trace"
1928 else
1929 fail "Validate empty trace"
1930 diag "Found $traced events in trace"
1931 fi
1932 ret=$?
1933 return $ret
1934 }
1935
1936 function validate_directory_empty ()
1937 {
1938 local trace_path="$1"
1939
1940 # Do not double quote `$trace_path` below as we want wildcards to be
1941 # expanded.
1942 files="$(ls -A $trace_path)"
1943 ret=$?
1944 if [ $ret -ne 0 ]; then
1945 fail "Failed to list content of directory \"$trace_path\""
1946 return $ret
1947 fi
1948
1949 nb_files="$(echo -n "$files" | wc -l)"
1950 ok $nb_files "Directory \"$trace_path\" is empty"
1951 }
1952
1953 function validate_trace_session_ust_empty()
1954 {
1955 validate_directory_empty "$1"/ust
1956 }
1957
1958 function validate_trace_session_kernel_empty()
1959 {
1960 validate_trace_empty "$1"/kernel
1961 }
1962
1963 function regenerate_metadata ()
1964 {
1965 local expected_to_fail=$1
1966 local sess_name=$2
1967
1968 $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate metadata -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1969 ret=$?
1970 if [[ $expected_to_fail -eq "1" ]]; then
1971 test "$ret" -ne "0"
1972 ok $? "Expected fail on regenerate metadata $sess_name"
1973 else
1974 ok $ret "Metadata regenerate $sess_name"
1975 fi
1976 }
1977
1978 function regenerate_metadata_ok ()
1979 {
1980 regenerate_metadata 0 "$@"
1981 }
1982
1983 function regenerate_metadata_fail ()
1984 {
1985 regenerate_metadata 1 "$@"
1986 }
1987
1988 function regenerate_statedump ()
1989 {
1990 local expected_to_fail=$1
1991 local sess_name=$2
1992
1993 $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate statedump -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1994 ret=$?
1995 if [[ $expected_to_fail -eq "1" ]]; then
1996 test "$ret" -ne "0"
1997 ok $? "Expected fail on regenerate statedump $sess_name"
1998 else
1999 ok $ret "Statedump regenerate $sess_name"
2000 fi
2001 }
2002
2003 function regenerate_statedump_ok ()
2004 {
2005 regenerate_statedump 0 "$@"
2006 }
2007
2008 function regenerate_statedump_fail ()
2009 {
2010 regenerate_statedump 1 "$@"
2011 }
2012
2013 function rotate_session ()
2014 {
2015 local expected_to_fail=$1
2016 local sess_name=$2
2017
2018 $TESTDIR/../src/bin/lttng/$LTTNG_BIN rotate $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2019 ret=$?
2020 if [[ $expected_to_fail -eq "1" ]]; then
2021 test "$ret" -ne "0"
2022 ok $? "Expected fail on rotate session $sess_name"
2023 else
2024 ok $ret "Rotate session $sess_name"
2025 fi
2026 }
2027
2028 function rotate_session_ok ()
2029 {
2030 rotate_session 0 "$@"
2031 }
2032
2033 function rotate_session_fail ()
2034 {
2035 rotate_session 1 "$@"
2036 }
2037
2038 function destructive_tests_enabled ()
2039 {
2040 if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then
2041 return 0
2042 else
2043 return 1
2044 fi
2045 }
2046
2047 function lttng_enable_rotation_timer ()
2048 {
2049 local expected_to_fail=$1
2050 local sess_name=$2
2051 local period=$3
2052
2053 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --timer $period 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2054 ret=$?
2055 if [[ $expected_to_fail -eq "1" ]]; then
2056 test "$ret" -ne "0"
2057 ok $? "Expected fail when setting periodic rotation ($period) of session $sess_name"
2058 else
2059 ok $ret "Set periodic rotation ($period) of session $sess_name"
2060 fi
2061 }
2062
2063 function lttng_enable_rotation_timer_ok ()
2064 {
2065 lttng_enable_rotation_timer 0 $@
2066 }
2067
2068 function lttng_enable_rotation_timer_fail ()
2069 {
2070 lttng_enable_rotation_timer 1 $@
2071 }
2072
2073 function lttng_enable_rotation_size ()
2074 {
2075 local expected_to_fail=$1
2076 local sess_name=$2
2077 local size=$3
2078
2079 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --size $size 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2080 ret=$?
2081 if [[ $expected_to_fail -eq "1" ]]; then
2082 test "$ret" -ne "0"
2083 ok $? "Expected fail on rotate session $sess_name"
2084 else
2085 ok $ret "Rotate session $sess_name"
2086 fi
2087 }
2088
2089 function lttng_enable_rotation_size_ok ()
2090 {
2091 lttng_enable_rotation_size 0 $@
2092 }
2093
2094 function lttng_enable_rotation_size_fail ()
2095 {
2096 lttng_enable_rotation_size 1 $@
2097 }
2098
2099 function lttng_clear_session ()
2100 {
2101 local expected_to_fail=$1
2102 local sess_name=$2
2103
2104 $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2105 ret=$?
2106 if [[ $expected_to_fail -eq "1" ]]; then
2107 test "$ret" -ne "0"
2108 ok $? "Expected fail on clear session $sess_name"
2109 else
2110 ok $ret "Clear session $sess_name"
2111 fi
2112 }
2113
2114 function lttng_clear_session_ok ()
2115 {
2116 lttng_clear_session 0 $@
2117 }
2118
2119 function lttng_clear_session_fail ()
2120 {
2121 lttng_clear_session 1 $@
2122 }
2123
2124 function lttng_clear_all ()
2125 {
2126 $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2127 ok $? "Clear all lttng sessions"
2128 }
2129
2130 function lttng_add_trigger()
2131 {
2132 local expected_to_fail="$1"
2133 local trigger_name="$2"
2134 shift 2
2135
2136 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-trigger --id "$trigger_name" "$@" 1> /dev/null 2> /dev/null
2137 ret=$?
2138 if [[ $expected_to_fail -eq "1" ]]; then
2139 test "$ret" -ne "0"
2140 ok $? "Add trigger $trigger_name failed as expected"
2141 else
2142 ok $ret "Add trigger $trigger_name"
2143 fi
2144 }
2145
2146 function lttng_remove_trigger()
2147 {
2148 local expected_to_fail="$1"
2149 local trigger_name="$2"
2150
2151 $TESTDIR/../src/bin/lttng/$LTTNG_BIN remove-trigger "$trigger_name" 1> /dev/null 2> /dev/null
2152 ret=$?
2153 if [[ $expected_to_fail -eq "1" ]]; then
2154 test "$ret" -ne "0"
2155 ok $? "Remove trigger $trigger_name failed as expected"
2156 else
2157 ok $ret "Remove trigger $trigger_name"
2158 fi
2159 }
2160
2161 function lttng_add_trigger_ok()
2162 {
2163 lttng_add_trigger 0 "$@"
2164 }
2165
2166 function lttng_remove_trigger_ok()
2167 {
2168 lttng_remove_trigger 0 "$@"
2169 }
This page took 0.124602 seconds and 3 git commands to generate.