SoW-2020-0003: Trace Hit Counters
[lttng-tools.git] / tests / utils / utils.sh
... / ...
CommitLineData
1# Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
2#
3# SPDX-License-Identifier: LGPL-2.1-only
4#
5
6SESSIOND_BIN="lttng-sessiond"
7SESSIOND_MATCH=".*lttng-sess.*"
8RUNAS_BIN="lttng-runas"
9RUNAS_MATCH=".*lttng-runas.*"
10CONSUMERD_BIN="lttng-consumerd"
11CONSUMERD_MATCH=".*lttng-consumerd.*"
12RELAYD_BIN="lttng-relayd"
13RELAYD_MATCH=".*lttng-relayd.*"
14LTTNG_BIN="lttng"
15BABELTRACE_BIN="babeltrace"
16OUTPUT_DEST=/dev/null
17ERROR_OUTPUT_DEST=/dev/null
18
19# Minimal kernel version supported for session daemon tests
20KERNEL_MAJOR_VERSION=2
21KERNEL_MINOR_VERSION=6
22KERNEL_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.
27export LTTNG_UST_REGISTER_TIMEOUT=-1
28export LTTNG_NETWORK_SOCKET_TIMEOUT=-1
29export 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.
35export LTTNG_SESSIOND_PATH="/bin/true"
36
37source $TESTDIR/utils/tap/tap.sh
38
39if [ -z ${LTTNG_TEST_TEARDOWN_TIMEOUT+x} ]; then
40 LTTNG_TEST_TEARDOWN_TIMEOUT=60
41fi
42
43function 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
62function null_pipes ()
63{
64 exec 0>/dev/null
65 exec 1>/dev/null
66 exec 2>/dev/null
67}
68
69trap 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
75trap null_pipes SIGPIPE
76
77# Check pgrep from env, default to pgrep if none
78if [ -z "$PGREP" ]; then
79 PGREP=pgrep
80fi
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.
89function 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
113function 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
123function 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
133function print_test_banner ()
134{
135 local desc="$1"
136 diag "$desc"
137}
138
139function 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
157function 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.
165function 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
176function 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
193function 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
228function enable_kernel_lttng_event_ok ()
229{
230 enable_kernel_lttng_event 1 0 "$@"
231}
232
233function enable_kernel_lttng_event_fail ()
234{
235 enable_kernel_lttng_event 1 1 "$@"
236}
237
238function enable_kernel_lttng_event_notap ()
239{
240 enable_kernel_lttng_event 0 0 "$@"
241}
242
243# Old interface
244function lttng_enable_kernel_event
245{
246 enable_kernel_lttng_event_ok "$@"
247}
248
249function 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
278function lttng_enable_kernel_syscall_ok()
279{
280 lttng_enable_kernel_syscall 0 "$@"
281}
282
283function lttng_enable_kernel_syscall_fail()
284{
285 lttng_enable_kernel_syscall 1 "$@"
286}
287
288function 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
318function lttng_disable_kernel_syscall_ok()
319{
320 lttng_disable_kernel_syscall 0 "$@"
321}
322
323function lttng_disable_kernel_syscall_fail()
324{
325 lttng_disable_kernel_syscall 1 "$@"
326}
327
328function 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
345function lttng_enable_kernel_function_event_ok ()
346{
347 lttng_enable_kernel_function_event 0 "$@"
348}
349
350function 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
367function lttng_enable_kernel_userspace_probe_event_fail ()
368{
369 lttng_enable_kernel_userspace_probe_event 1 "$@"
370}
371
372function lttng_enable_kernel_userspace_probe_event_ok ()
373{
374 lttng_enable_kernel_userspace_probe_event 0 "$@"
375}
376
377function 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}
385function 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
408function lttng_enable_kernel_channel_ok()
409{
410 lttng_enable_kernel_channel 1 0 "$@"
411}
412
413function lttng_enable_kernel_channel_fail()
414{
415 lttng_enable_kernel_channel 1 1 "$@"
416}
417
418function lttng_enable_kernel_channel_notap()
419{
420 lttng_enable_kernel_channel 0 0 "$@"
421}
422
423function enable_kernel_lttng_channel_ok()
424{
425 lttng_enable_kernel_channel 1 0 "$@"
426}
427
428function 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
444function lttng_disable_kernel_channel_ok()
445{
446 lttng_disable_kernel_channel 0 "$@"
447}
448
449function lttng_disable_kernel_channel_fail()
450{
451 lttng_disable_kernel_channel 1 "$@"
452}
453
454function 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
481function start_lttng_relayd()
482{
483 start_lttng_relayd_opt 1 "-b" "$@"
484}
485
486function start_lttng_relayd_notap()
487{
488 start_lttng_relayd_opt 0 "-b" "$@"
489}
490
491function 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
551function stop_lttng_relayd()
552{
553 stop_lttng_relayd_opt 1 "$@"
554}
555
556function 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
563function start_lttng_sessiond_opt()
564{
565 local withtap=$1
566 local load_path=$2
567
568 # The rest of the arguments will be passed directly to lttng-sessiond.
569 shift
570 shift
571
572 local env_vars=""
573 local consumerd=""
574
575 local long_bit_value=
576 long_bit_value=$(getconf LONG_BIT)
577
578 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
579 # Env variable requested no session daemon
580 return
581 fi
582
583 DIR=$(readlink -f "$TESTDIR")
584
585 # Get long_bit value for 32/64 consumerd
586 case "$long_bit_value" in
587 32)
588 consumerd="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
589 ;;
590 64)
591 consumerd="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
592 ;;
593 *)
594 return
595 ;;
596 esac
597
598 # Check for env. variable. Allow the use of LD_PRELOAD etc.
599 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
600 env_vars="${LTTNG_SESSIOND_ENV_VARS} "
601 fi
602 env_vars="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN"
603
604 if ! validate_kernel_version; then
605 fail "Start session daemon"
606 BAIL_OUT "*** Kernel too old for session daemon tests ***"
607 fi
608
609 : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}"
610 export LTTNG_SESSION_CONFIG_XSD_PATH
611
612 if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ]; then
613 # Have a load path ?
614 if [ -n "$load_path" ]; then
615 # shellcheck disable=SC2086
616 env $env_vars --load "$load_path" --background "$consumerd" "$@"
617 else
618 # shellcheck disable=SC2086
619 env $env_vars --background "$consumerd" "$@"
620 fi
621 #$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
622 status=$?
623 if [ "$withtap" -eq "1" ]; then
624 ok $status "Start session daemon"
625 fi
626 fi
627}
628
629function start_lttng_sessiond()
630{
631 start_lttng_sessiond_opt 1 "$@"
632}
633
634function start_lttng_sessiond_notap()
635{
636 start_lttng_sessiond_opt 0 "$@"
637}
638
639function stop_lttng_sessiond_opt()
640{
641 local withtap=$1
642 local signal=$2
643
644 if [ -z "$signal" ]; then
645 signal=SIGTERM
646 fi
647
648 local timeout_s=$3
649 local dtimeleft_s=
650
651 # Multiply time by 2 to simplify integer arithmetic
652 if [ -n "$timeout_s" ]; then
653 dtimeleft_s=$((timeout_s * 2))
654 fi
655
656 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
657 # Env variable requested no session daemon
658 return 0
659 fi
660
661 local retval=0
662
663 local runas_pids=
664 runas_pids=$(lttng_pgrep "$RUNAS_MATCH")
665
666 local pids=
667 pids=$(lttng_pgrep "$SESSIOND_MATCH")
668
669 if [ -n "$runas_pids" ]; then
670 pids="$pids $runas_pids"
671 fi
672
673 if [ -z "$pids" ]; then
674 if [ "$withtap" -eq "1" ]; then
675 fail "No session daemon to kill"
676 else
677 BAIL_OUT "No session daemon to kill"
678 fi
679 return 0
680 fi
681
682 diag "Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
683
684 # shellcheck disable=SC2086
685 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
686 retval=1
687 if [ "$withtap" -eq "1" ]; then
688 fail "Kill sessions daemon"
689 fi
690 else
691 out=1
692 while [ -n "$out" ]; do
693 out=$(lttng_pgrep "${SESSIOND_MATCH}")
694 if [ -n "$dtimeleft_s" ]; then
695 if [ $dtimeleft_s -lt 0 ]; then
696 out=
697 retval=1
698 fi
699 dtimeleft_s=$((dtimeleft_s - 1))
700 fi
701 sleep 0.5
702 done
703 out=1
704 while [ -n "$out" ]; do
705 out=$(lttng_pgrep "$CONSUMERD_MATCH")
706 if [ -n "$dtimeleft_s" ]; then
707 if [ $dtimeleft_s -lt 0 ]; then
708 out=
709 retval=1
710 fi
711 dtimeleft_s=$((dtimeleft_s - 1))
712 fi
713 sleep 0.5
714 done
715
716 if [ "$withtap" -eq "1" ]; then
717 if [ "$retval" -eq "0" ]; then
718 pass "Wait after kill session daemon"
719 else
720 fail "Wait after kill session daemon"
721 fi
722 fi
723 fi
724 if [ "$signal" = "SIGKILL" ]; then
725 if [ "$(id -u)" -eq "0" ]; then
726 local modules=
727 modules="$(lsmod | grep ^lttng | awk '{print $1}')"
728
729 if [ -n "$modules" ]; then
730 diag "Unloading all LTTng modules"
731 modprobe --remove "$modules"
732 fi
733 fi
734 fi
735
736 return $retval
737}
738
739function stop_lttng_sessiond()
740{
741 stop_lttng_sessiond_opt 1 "$@"
742}
743
744function stop_lttng_sessiond_notap()
745{
746 stop_lttng_sessiond_opt 0 "$@"
747}
748
749function sigstop_lttng_sessiond_opt()
750{
751 local withtap=$1
752 local signal=SIGSTOP
753
754 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
755 # Env variable requested no session daemon
756 return
757 fi
758
759 PID_SESSIOND="$(lttng_pgrep "${SESSIOND_MATCH}") $(lttng_pgrep "$RUNAS_MATCH")"
760
761 if [ "$withtap" -eq "1" ]; then
762 diag "Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$PID_SESSIOND" | tr '\n' ' ')"
763 fi
764
765 # shellcheck disable=SC2086
766 if ! kill -s $signal $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
767 if [ "$withtap" -eq "1" ]; then
768 fail "Sending SIGSTOP to session daemon"
769 fi
770 else
771 out=1
772 while [ $out -ne 0 ]; do
773 pid="$(lttng_pgrep "$SESSIOND_MATCH")"
774
775 # Wait until state becomes stopped for session
776 # daemon(s).
777 out=0
778 for sessiond_pid in $pid; do
779 state="$(ps -p "$sessiond_pid" -o state= )"
780 if [[ -n "$state" && "$state" != "T" ]]; then
781 out=1
782 fi
783 done
784 sleep 0.5
785 done
786 if [ "$withtap" -eq "1" ]; then
787 pass "Sending SIGSTOP to session daemon"
788 fi
789 fi
790}
791
792function sigstop_lttng_sessiond()
793{
794 sigstop_lttng_sessiond_opt 1 "$@"
795}
796
797function sigstop_lttng_sessiond_notap()
798{
799 sigstop_lttng_sessiond_opt 0 "$@"
800}
801
802function stop_lttng_consumerd_opt()
803{
804 local withtap=$1
805 local signal=$2
806
807 if [ -z "$signal" ]; then
808 signal=SIGTERM
809 fi
810
811 local timeout_s=$3
812 local dtimeleft_s=
813
814 # Multiply time by 2 to simplify integer arithmetic
815 if [ -n "$timeout_s" ]; then
816 dtimeleft_s=$((timeout_s * 2))
817 fi
818
819 local retval=0
820
821 PID_CONSUMERD="$(lttng_pgrep "$CONSUMERD_MATCH")"
822
823 if [ -z "$PID_CONSUMERD" ]; then
824 if [ "$withtap" -eq "1" ]; then
825 pass "No consumer daemon to kill"
826 fi
827 return 0
828 fi
829
830 diag "Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')"
831
832 # shellcheck disable=SC2086
833 if ! kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
834 retval=1
835 if [ "$withtap" -eq "1" ]; then
836 fail "Kill consumer daemon"
837 fi
838 else
839 out=1
840 while [ $out -ne 0 ]; do
841 pid="$(lttng_pgrep "$CONSUMERD_MATCH")"
842
843 # If consumerds are still present check their status.
844 # A zombie status qualifies the consumerd as *killed*
845 out=0
846 for consumer_pid in $pid; do
847 state="$(ps -p "$consumer_pid" -o state= )"
848 if [[ -n "$state" && "$state" != "Z" ]]; then
849 out=1
850 fi
851 done
852 if [ -n "$dtimeleft_s" ]; then
853 if [ $dtimeleft_s -lt 0 ]; then
854 out=0
855 retval=1
856 fi
857 dtimeleft_s=$((dtimeleft_s - 1))
858 fi
859 sleep 0.5
860 done
861 if [ "$withtap" -eq "1" ]; then
862 if [ "$retval" -eq "0" ]; then
863 pass "Wait after kill consumer daemon"
864 else
865 fail "Wait after kill consumer daemon"
866 fi
867 fi
868 fi
869
870 return $retval
871}
872
873function stop_lttng_consumerd()
874{
875 stop_lttng_consumerd_opt 1 "$@"
876}
877
878function stop_lttng_consumerd_notap()
879{
880 stop_lttng_consumerd_opt 0 "$@"
881}
882
883function sigstop_lttng_consumerd_opt()
884{
885 local withtap=$1
886 local signal=SIGSTOP
887
888 PID_CONSUMERD="$(lttng_pgrep "$CONSUMERD_MATCH")"
889
890 diag "Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')"
891
892 # shellcheck disable=SC2086
893 kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
894 retval=$?
895
896 if [ $retval -eq 1 ]; then
897 if [ "$withtap" -eq "1" ]; then
898 fail "Sending SIGSTOP to consumer daemon"
899 fi
900 return 1
901 else
902 out=1
903 while [ $out -ne 0 ]; do
904 pid="$(lttng_pgrep "$CONSUMERD_MATCH")"
905
906 # Wait until state becomes stopped for all
907 # consumers.
908 out=0
909 for consumer_pid in $pid; do
910 state="$(ps -p "$consumer_pid" -o state= )"
911 if [[ -n "$state" && "$state" != "T" ]]; then
912 out=1
913 fi
914 done
915 sleep 0.5
916 done
917 if [ "$withtap" -eq "1" ]; then
918 pass "Sending SIGSTOP to consumer daemon"
919 fi
920 fi
921 return $retval
922}
923
924function sigstop_lttng_consumerd()
925{
926 sigstop_lttng_consumerd_opt 1 "$@"
927}
928
929function sigstop_lttng_consumerd_notap()
930{
931 sigstop_lttng_consumerd_opt 0 "$@"
932}
933
934function list_lttng_with_opts ()
935{
936 local opts=$1
937 $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
938 ok $? "Lttng-tool list command with option $opts"
939}
940
941function create_lttng_session_no_output ()
942{
943 local sess_name=$1
944 local opts="${@:2}"
945
946 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
947 ok $? "Create session $sess_name in no-output mode"
948}
949
950function create_lttng_session_uri () {
951 local sess_name=$1
952 local uri=$2
953 local opts="${@:3}"
954
955 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -U $uri $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
956 ok $? "Create session $sess_name with uri:$uri and opts: $opts"
957}
958
959function create_lttng_session ()
960{
961 local withtap=$1
962 local expected_to_fail=$2
963 local sess_name=$3
964 local trace_path=$4
965 local opt=$5
966
967 if [ -z "$trace_path" ]; then
968 # Use lttng-sessiond default output.
969 trace_path=""
970 else
971 trace_path="-o $trace_path"
972 fi
973
974 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create "$sess_name" $trace_path $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
975 ret=$?
976 if [ $expected_to_fail -eq "1" ]; then
977 test "$ret" -ne "0"
978 ret=$?
979 if [ $withtap -eq "1" ]; then
980 ok $ret "Create session $sess_name in $trace_path failed as expected"
981 fi
982 else
983 if [ $withtap -eq "1" ]; then
984 ok $ret "Create session $sess_name in $trace_path"
985 fi
986 fi
987 return $ret
988}
989
990function create_lttng_session_ok ()
991{
992 create_lttng_session 1 0 "$@"
993}
994
995function create_lttng_session_fail ()
996{
997 create_lttng_session 1 1 "$@"
998}
999
1000function create_lttng_session_notap ()
1001{
1002 create_lttng_session 0 0 "$@"
1003}
1004
1005
1006function enable_ust_lttng_channel ()
1007{
1008 local withtap=$1
1009 local expected_to_fail=$2
1010 local sess_name=$3
1011 local channel_name=$4
1012 local opts="${@:5}"
1013
1014 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1015 ret=$?
1016 if [[ $expected_to_fail -eq "1" ]]; then
1017 test "$ret" -ne "0"
1018 ret=$?
1019 if [ $withtap -eq "1" ]; then
1020 ok $ret "Enable channel $channel_name for session $sess_name failed as expected"
1021 fi
1022 else
1023 if [ $withtap -eq "1" ]; then
1024 ok $ret "Enable channel $channel_name for session $sess_name"
1025 fi
1026 fi
1027 return $ret
1028}
1029
1030function enable_ust_lttng_channel_ok ()
1031{
1032 enable_ust_lttng_channel 1 0 "$@"
1033}
1034
1035function enable_ust_lttng_channel_fail ()
1036{
1037 enable_ust_lttng_channel 1 1 "$@"
1038}
1039
1040function enable_ust_lttng_channel_notap ()
1041{
1042 enable_ust_lttng_channel 0 0 "$@"
1043}
1044
1045function disable_ust_lttng_channel()
1046{
1047 local sess_name=$1
1048 local channel_name=$2
1049
1050 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1051 ok $? "Disable channel $channel_name for session $sess_name"
1052}
1053
1054function enable_lttng_mmap_overwrite_kernel_channel()
1055{
1056 local sess_name=$1
1057 local channel_name=$2
1058
1059 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1060 ok $? "Enable channel $channel_name for session $sess_name"
1061}
1062
1063function enable_lttng_mmap_discard_small_kernel_channel()
1064{
1065 local sess_name=$1
1066 local channel_name=$2
1067
1068 $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
1069 ok $? "Enable small discard channel $channel_name for session $sess_name"
1070}
1071
1072function enable_lttng_mmap_overwrite_small_kernel_channel()
1073{
1074 local sess_name=$1
1075 local channel_name=$2
1076
1077 $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
1078 ok $? "Enable small discard channel $channel_name for session $sess_name"
1079}
1080
1081function enable_lttng_mmap_overwrite_ust_channel()
1082{
1083 local sess_name=$1
1084 local channel_name=$2
1085
1086 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1087 ok $? "Enable channel $channel_name for session $sess_name"
1088}
1089
1090function enable_ust_lttng_event ()
1091{
1092 local withtap=$1
1093 local expected_to_fail=$2
1094 local sess_name=$3
1095 local event_name="$4"
1096 local channel_name=$5
1097
1098 if [ -z $channel_name ]; then
1099 # default channel if none specified
1100 chan=""
1101 else
1102 chan="-c $channel_name"
1103 fi
1104
1105 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1106 ret=$?
1107 if [[ $expected_to_fail -eq "1" ]]; then
1108 test $ret -ne "0"
1109 ret=$?
1110 if [[ $withtap -eq "1" ]]; then
1111 ok $ret "Enable ust event $event_name for session $session_name failed as expected"
1112 fi
1113 else
1114 if [[ $withtap -eq "1" ]]; then
1115 ok $ret "Enable ust event $event_name for session $sess_name"
1116 fi
1117 fi
1118 return $ret
1119}
1120
1121function enable_ust_lttng_event_ok ()
1122{
1123 enable_ust_lttng_event 1 0 "$@"
1124}
1125
1126function enable_ust_lttng_event_fail ()
1127{
1128 enable_ust_lttng_event 1 1 "$@"
1129}
1130
1131function enable_ust_lttng_event_notap ()
1132{
1133 enable_ust_lttng_event 0 0 "$@"
1134}
1135
1136function enable_jul_lttng_event()
1137{
1138 sess_name=$1
1139 event_name="$2"
1140 channel_name=$3
1141
1142 if [ -z $channel_name ]; then
1143 # default channel if none specified
1144 chan=""
1145 else
1146 chan="-c $channel_name"
1147 fi
1148
1149 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1150 ok $? "Enable JUL event $event_name for session $sess_name"
1151}
1152
1153function enable_jul_lttng_event_loglevel()
1154{
1155 local sess_name=$1
1156 local event_name="$2"
1157 local loglevel=$3
1158 local channel_name=$4
1159
1160 if [ -z $channel_name ]; then
1161 # default channel if none specified
1162 chan=""
1163 else
1164 chan="-c $channel_name"
1165 fi
1166
1167 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1168 ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
1169}
1170
1171function enable_log4j_lttng_event()
1172{
1173 sess_name=$1
1174 event_name="$2"
1175 channel_name=$3
1176
1177 if [ -z $channel_name ]; then
1178 # default channel if none specified
1179 chan=""
1180 else
1181 chan="-c $channel_name"
1182 fi
1183
1184 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1185 ok $? "Enable LOG4J event $event_name for session $sess_name"
1186}
1187
1188function enable_log4j_lttng_event_loglevel()
1189{
1190 local sess_name=$1
1191 local event_name="$2"
1192 local loglevel=$3
1193 local channel_name=$4
1194
1195 if [ -z $channel_name ]; then
1196 # default channel if none specified
1197 chan=""
1198 else
1199 chan="-c $channel_name"
1200 fi
1201
1202 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1203 ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
1204}
1205
1206function enable_python_lttng_event()
1207{
1208 sess_name=$1
1209 event_name="$2"
1210 channel_name=$3
1211
1212 if [ -z $channel_name ]; then
1213 # default channel if none specified
1214 chan=""
1215 else
1216 chan="-c $channel_name"
1217 fi
1218
1219 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1220 ok $? "Enable Python event $event_name for session $sess_name"
1221}
1222
1223function enable_python_lttng_event_loglevel()
1224{
1225 local sess_name=$1
1226 local event_name="$2"
1227 local loglevel=$3
1228 local channel_name=$4
1229
1230 if [ -z $channel_name ]; then
1231 # default channel if none specified
1232 chan=""
1233 else
1234 chan="-c $channel_name"
1235 fi
1236
1237 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1238 ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel"
1239}
1240
1241function enable_ust_lttng_event_filter()
1242{
1243 local sess_name="$1"
1244 local event_name="$2"
1245 local filter="$3"
1246 local channel_name=$4
1247
1248 if [ -z $channel_name ]; then
1249 # default channel if none specified
1250 chan=""
1251 else
1252 chan="-c $channel_name"
1253 fi
1254
1255 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $chan "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1256 ok $? "Enable event $event_name with filtering for session $sess_name"
1257}
1258
1259function enable_ust_lttng_event_loglevel()
1260{
1261 local sess_name="$1"
1262 local event_name="$2"
1263 local loglevel="$3"
1264
1265 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1266 ok $? "Enable event $event_name with loglevel $loglevel"
1267}
1268
1269function enable_ust_lttng_event_loglevel_only()
1270{
1271 local sess_name="$1"
1272 local event_name="$2"
1273 local loglevel="$3"
1274
1275 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1276 ok $? "Enable event $event_name with loglevel-only $loglevel"
1277}
1278
1279function disable_ust_lttng_event ()
1280{
1281 local sess_name="$1"
1282 local event_name="$2"
1283 local channel_name="$3"
1284
1285 if [ -z $channel_name ]; then
1286 # default channel if none specified
1287 chan=""
1288 else
1289 chan="-c $channel_name"
1290 fi
1291
1292 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1293 ok $? "Disable event $event_name for session $sess_name"
1294}
1295
1296function disable_jul_lttng_event ()
1297{
1298 local sess_name="$1"
1299 local event_name="$2"
1300
1301 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1
1302 ok $? "Disable JUL event $event_name for session $sess_name"
1303}
1304
1305function disable_log4j_lttng_event ()
1306{
1307 local sess_name="$1"
1308 local event_name="$2"
1309
1310 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1
1311 ok $? "Disable LOG4J event $event_name for session $sess_name"
1312}
1313
1314function disable_python_lttng_event ()
1315{
1316 local sess_name="$1"
1317 local event_name="$2"
1318
1319 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1320 ok $? "Disable Python event $event_name for session $sess_name"
1321}
1322
1323function start_lttng_tracing_opt ()
1324{
1325 local withtap=$1
1326 local expected_to_fail=$2
1327 local sess_name=$3
1328
1329 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1330 ret=$?
1331 if [[ $expected_to_fail -eq "1" ]]; then
1332 test "$ret" -ne "0"
1333 ret=$?
1334 if [ $withtap -eq "1" ]; then
1335 ok $? "Start tracing for session $sess_name failed as expected"
1336 fi
1337 else
1338 if [ $withtap -eq "1" ]; then
1339 ok $ret "Start tracing for session $sess_name"
1340 fi
1341 fi
1342}
1343
1344function start_lttng_tracing_ok ()
1345{
1346 start_lttng_tracing_opt 1 0 "$@"
1347}
1348
1349function start_lttng_tracing_fail ()
1350{
1351 start_lttng_tracing_opt 1 1 "$@"
1352}
1353
1354function start_lttng_tracing_notap ()
1355{
1356 start_lttng_tracing_opt 0 1 "$@"
1357}
1358
1359function stop_lttng_tracing_opt ()
1360{
1361 local withtap=$1
1362 local expected_to_fail=$2
1363 local sess_name=$3
1364
1365 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1366 ret=$?
1367 if [[ $expected_to_fail -eq "1" ]]; then
1368 test "$ret" -ne "0"
1369 ret=$?
1370 if [ $withtap -eq "1" ]; then
1371 ok $? "Stop lttng tracing for session $sess_name failed as expected"
1372 fi
1373 else
1374 if [ $withtap -eq "1" ]; then
1375 ok $ret "Stop lttng tracing for session $sess_name"
1376 fi
1377 fi
1378}
1379
1380function stop_lttng_tracing_ok ()
1381{
1382 stop_lttng_tracing_opt 1 0 "$@"
1383}
1384
1385function stop_lttng_tracing_fail ()
1386{
1387 stop_lttng_tracing_opt 1 1 "$@"
1388}
1389
1390function stop_lttng_tracing_notap ()
1391{
1392 stop_lttng_tracing_opt 0 0 "$@"
1393}
1394
1395function destroy_lttng_session ()
1396{
1397 local withtap=$1
1398 local expected_to_fail=$2
1399 local sess_name=$3
1400
1401 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1402 ret=$?
1403 if [[ $expected_to_fail -eq "1" ]]; then
1404 test "$ret" -ne "0"
1405 ret=$?
1406 if [ $withtap -eq "1" ]; then
1407 ok $ret "Destroy session $sess_name failed as expected"
1408 fi
1409 else
1410 if [ $withtap -eq "1" ]; then
1411 ok $ret "Destroy session $sess_name"
1412 fi
1413 fi
1414}
1415
1416function destroy_lttng_session_ok ()
1417{
1418 destroy_lttng_session 1 0 "$@"
1419
1420}
1421
1422function destroy_lttng_session_fail ()
1423{
1424 destroy_lttng_session 1 1 "$@"
1425}
1426
1427function destroy_lttng_session_notap ()
1428{
1429 destroy_lttng_session 0 0 "$@"
1430}
1431
1432function destroy_lttng_sessions ()
1433{
1434 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1435 ok $? "Destroy all lttng sessions"
1436}
1437
1438function lttng_snapshot_add_output ()
1439{
1440 local expected_to_fail=$1
1441 local sess_name=$2
1442 local trace_path=$3
1443 local opts=$4
1444
1445 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name $trace_path $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1446 ret=$?
1447 if [[ $expected_to_fail -eq 1 ]]; then
1448 test "$ret" -ne "0"
1449 ok $? "Added snapshot output $trace_path failed as expected"
1450 else
1451 ok $ret "Added snapshot output $trace_path"
1452 fi
1453}
1454
1455function lttng_snapshot_add_output_ok ()
1456{
1457 lttng_snapshot_add_output 0 "$@"
1458}
1459
1460function lttng_snapshot_add_output_fail ()
1461{
1462 lttng_snapshot_add_output 1 "$@"
1463}
1464
1465function lttng_snapshot_del_output ()
1466{
1467 local expected_to_fail=$1
1468 local sess_name=$2
1469 local id=$3
1470
1471 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1472 ret=$?
1473 if [[ $expected_to_fail -eq "1" ]]; then
1474 test "$ret" -ne "0"
1475 ok $? "Deleted snapshot output id $id failed as expected"
1476 else
1477 ok $ret "Deleted snapshot output id $id"
1478 fi
1479}
1480
1481function lttng_snapshot_del_output_ok ()
1482{
1483 lttng_snapshot_del_output 0 "$@"
1484}
1485
1486function lttng_snapshot_del_output_fail ()
1487{
1488 lttng_snapshot_del_output 1 "$@"
1489}
1490
1491function lttng_snapshot_record ()
1492{
1493 local sess_name=$1
1494
1495 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name $trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1496 ok $? "Snapshot recorded"
1497}
1498
1499function lttng_snapshot_list ()
1500{
1501 local sess_name=$1
1502 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1503 ok $? "Snapshot list"
1504}
1505
1506function lttng_save()
1507{
1508 local sess_name=$1
1509 local opts=$2
1510
1511 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1512 ok $? "Session saved"
1513}
1514
1515function lttng_load()
1516{
1517 local expected_to_fail=$1
1518 local opts=$2
1519
1520 diag "$TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts"
1521 $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts
1522 ret=$?
1523 if [[ $expected_to_fail -eq "1" ]]; then
1524 test $ret -ne "0"
1525 ok $? "Load command failed as expected with opts: $opts"
1526 else
1527 ok $ret "Load command with opts: $opts"
1528 fi
1529}
1530
1531function lttng_load_ok()
1532{
1533 lttng_load 0 "$@"
1534}
1535
1536function lttng_load_fail()
1537{
1538 lttng_load 1 "$@"
1539}
1540
1541function lttng_track()
1542{
1543 local expected_to_fail="$1"
1544 shift 1
1545 local opts="$@"
1546 $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST
1547 ret=$?
1548 if [[ $expected_to_fail -eq "1" ]]; then
1549 test $ret -ne "0"
1550 ok $? "Track command failed as expected with opts: $opts"
1551 else
1552 ok $ret "Track command with opts: $opts"
1553 fi
1554}
1555
1556function lttng_track_ok()
1557{
1558 lttng_track 0 "$@"
1559}
1560
1561function lttng_track_fail()
1562{
1563 lttng_track 1 "$@"
1564}
1565
1566function lttng_untrack()
1567{
1568 local expected_to_fail="$1"
1569 shift 1
1570 local opts="$@"
1571 $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST
1572 ret=$?
1573 if [[ $expected_to_fail -eq "1" ]]; then
1574 test $ret -ne "0"
1575 ok $? "Untrack command failed as expected with opts: $opts"
1576 else
1577 ok $ret "Untrack command with opts: $opts"
1578 fi
1579}
1580
1581function lttng_untrack_ok()
1582{
1583 lttng_untrack 0 "$@"
1584}
1585
1586function lttng_untrack_fail()
1587{
1588 lttng_untrack 1 "$@"
1589}
1590
1591function lttng_track_pid_ok()
1592{
1593 PID=$1
1594 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track --kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1595 ok $? "Lttng track pid on the kernel domain"
1596}
1597
1598function lttng_untrack_kernel_all_ok()
1599{
1600 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack --kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1601 ok $? "Lttng untrack all pid on the kernel domain"
1602}
1603
1604function lttng_track_ust_ok()
1605{
1606 lttng_track_ok -u "$@"
1607}
1608
1609function lttng_track_ust_fail()
1610{
1611 lttng_track_fail -u "$@"
1612}
1613
1614function lttng_track_kernel_ok()
1615{
1616 lttng_track_ok -k "$@"
1617}
1618
1619function lttng_track_kernel_fail()
1620{
1621 lttng_track_fail -k "$@"
1622}
1623
1624function lttng_untrack_ust_ok()
1625{
1626 lttng_untrack_ok -u "$@"
1627}
1628
1629function lttng_untrack_ust_fail()
1630{
1631 lttng_untrack_fail -u "$@"
1632}
1633
1634function lttng_untrack_kernel_ok()
1635{
1636 lttng_untrack_ok -k "$@"
1637}
1638
1639function lttng_untrack_kernel_fail()
1640{
1641 lttng_untrack_fail -k "$@"
1642}
1643
1644function lttng_add_context_list()
1645{
1646 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context --list 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1647 ret=$?
1648 ok $ret "Context listing"
1649}
1650
1651function add_context_lttng()
1652{
1653 local expected_to_fail="$1"
1654 local domain="$2"
1655 local session_name="$3"
1656 local channel_name="$4"
1657 local type="$5"
1658
1659 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context -s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1660 ret=$?
1661 if [[ $expected_to_fail -eq "1" ]]; then
1662 test $ret -ne "0"
1663 ok $? "Add context command failed as expected for type: $type"
1664 else
1665 ok $ret "Add context command for type: $type"
1666 fi
1667}
1668
1669function add_context_ust_ok()
1670{
1671 add_context_lttng 0 -u "$@"
1672}
1673
1674function add_context_ust_fail()
1675{
1676 add_context_lttng 1 -u "$@"
1677}
1678
1679function add_context_kernel_ok()
1680{
1681 add_context_lttng 0 -k "$@"
1682}
1683
1684function add_context_kernel_fail()
1685{
1686 add_context_lttng 1 -k "$@"
1687}
1688
1689function wait_live_trace_ready ()
1690{
1691 local url=$1
1692 local zero_client_match=0
1693
1694 diag "Waiting for live trace at url: $url"
1695 while [ $zero_client_match -eq 0 ]; do
1696 zero_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "0 client(s) connected" | wc -l)
1697 sleep 0.5
1698 done
1699 pass "Waiting for live trace at url: $url"
1700}
1701
1702function wait_live_viewer_connect ()
1703{
1704 local url=$1
1705 local one_client_match=0
1706
1707 diag "Waiting for live viewers on url: $url"
1708 while [ $one_client_match -eq 0 ]; do
1709 one_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "1 client(s) connected" | wc -l)
1710 sleep 0.5
1711 done
1712 pass "Waiting for live viewers on url: $url"
1713}
1714
1715function validate_metadata_event ()
1716{
1717 local event_name=$1
1718 local nr_event_id=$2
1719 local trace_path=$3
1720
1721 local metadata_file=$(find $trace_path | grep metadata)
1722 local metadata_path=$(dirname $metadata_file)
1723
1724 which $BABELTRACE_BIN >/dev/null
1725 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1726
1727 local count=$($BABELTRACE_BIN --output-format=ctf-metadata $metadata_path | grep $event_name | wc -l)
1728
1729 if [ "$count" -ne "$nr_event_id" ]; then
1730 fail "Metadata match with the metadata of $count event(s) named $event_name"
1731 diag "$count matching event id found in metadata"
1732 else
1733 pass "Metadata match with the metadata of $count event(s) named $event_name"
1734 fi
1735
1736}
1737
1738function trace_matches ()
1739{
1740 local event_name=$1
1741 local nr_iter=$2
1742 local trace_path=$3
1743
1744 which $BABELTRACE_BIN >/dev/null
1745 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1746
1747 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
1748
1749 if [ "$count" -ne "$nr_iter" ]; then
1750 fail "Trace match"
1751 diag "$count matching events found in trace"
1752 else
1753 pass "Trace match"
1754 fi
1755}
1756
1757function trace_match_only()
1758{
1759 local event_name=$1
1760 local nr_iter=$2
1761 local trace_path=$3
1762
1763 which $BABELTRACE_BIN >/dev/null
1764 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1765
1766 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
1767 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1768
1769 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1770 pass "Trace match with $total event $event_name"
1771 else
1772 fail "Trace match"
1773 diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1774 fi
1775}
1776
1777function validate_trace
1778{
1779 local event_name=$1
1780 local trace_path=$2
1781
1782 which $BABELTRACE_BIN >/dev/null
1783 if [ $? -ne 0 ]; then
1784 skip 0 "Babeltrace binary not found. Skipping trace validation"
1785 fi
1786
1787 OLDIFS=$IFS
1788 IFS=","
1789 for i in $event_name; do
1790 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1791 if [ "$traced" -ne 0 ]; then
1792 pass "Validate trace for event $i, $traced events"
1793 else
1794 fail "Validate trace for event $i"
1795 diag "Found $traced occurences of $i"
1796 fi
1797 done
1798 ret=$?
1799 IFS=$OLDIFS
1800 return $ret
1801}
1802
1803function validate_trace_count
1804{
1805 local event_name=$1
1806 local trace_path=$2
1807 local expected_count=$3
1808
1809 which $BABELTRACE_BIN >/dev/null
1810 if [ $? -ne 0 ]; then
1811 skip 0 "Babeltrace binary not found. Skipping trace validation"
1812 fi
1813
1814 cnt=0
1815 OLDIFS=$IFS
1816 IFS=","
1817 for i in $event_name; do
1818 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1819 if [ "$traced" -ne 0 ]; then
1820 pass "Validate trace for event $i, $traced events"
1821 else
1822 fail "Validate trace for event $i"
1823 diag "Found $traced occurences of $i"
1824 fi
1825 cnt=$(($cnt + $traced))
1826 done
1827 IFS=$OLDIFS
1828 test $cnt -eq $expected_count
1829 ok $? "Read a total of $cnt events, expected $expected_count"
1830}
1831
1832function validate_trace_count_range_incl_min_excl_max
1833{
1834 local event_name=$1
1835 local trace_path=$2
1836 local expected_min=$3
1837 local expected_max=$4
1838
1839 which $BABELTRACE_BIN >/dev/null
1840 if [ $? -ne 0 ]; then
1841 skip 0 "Babeltrace binary not found. Skipping trace validation"
1842 fi
1843
1844 cnt=0
1845 OLDIFS=$IFS
1846 IFS=","
1847 for i in $event_name; do
1848 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1849 if [ "$traced" -ge $expected_min ]; then
1850 pass "Validate trace for event $i, $traced events"
1851 else
1852 fail "Validate trace for event $i"
1853 diag "Found $traced occurences of $i"
1854 fi
1855 cnt=$(($cnt + $traced))
1856 done
1857 IFS=$OLDIFS
1858 test $cnt -lt $expected_max
1859 ok $? "Read a total of $cnt events, expected between [$expected_min, $expected_max["
1860}
1861
1862function trace_first_line
1863{
1864 local trace_path=$1
1865
1866 which $BABELTRACE_BIN >/dev/null
1867 if [ $? -ne 0 ]; then
1868 skip 0 "Babeltrace binary not found. Skipping trace validation"
1869 fi
1870
1871 $BABELTRACE_BIN $trace_path 2>/dev/null | head -n 1
1872}
1873
1874function validate_trace_exp()
1875{
1876 local event_exp=$1
1877 local trace_path=$2
1878
1879 which $BABELTRACE_BIN >/dev/null
1880 skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
1881
1882 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep --extended-regexp ${event_exp} | wc -l)
1883 if [ "$traced" -ne 0 ]; then
1884 pass "Validate trace for expression '${event_exp}', $traced events"
1885 else
1886 fail "Validate trace for expression '${event_exp}'"
1887 diag "Found $traced occurences of '${event_exp}'"
1888 fi
1889 ret=$?
1890 return $ret
1891}
1892
1893function validate_trace_only_exp()
1894{
1895 local event_exp=$1
1896 local trace_path=$2
1897
1898 which $BABELTRACE_BIN >/dev/null
1899 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1900
1901 local count=$($BABELTRACE_BIN $trace_path | grep --extended-regexp ${event_exp} | wc -l)
1902 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1903
1904 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1905 pass "Trace match with $total for expression '${event_exp}'"
1906 else
1907 fail "Trace match"
1908 diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1909 fi
1910 ret=$?
1911 return $ret
1912}
1913
1914function validate_trace_empty()
1915{
1916 local trace_path=$1
1917
1918 which $BABELTRACE_BIN >/dev/null
1919 if [ $? -ne 0 ]; then
1920 skip 0 "Babeltrace binary not found. Skipping trace validation"
1921 fi
1922
1923 events=$($BABELTRACE_BIN $trace_path 2>/dev/null)
1924 ret=$?
1925 if [ $ret -ne 0 ]; then
1926 fail "Failed to parse trace"
1927 return $ret
1928 fi
1929
1930 traced=$(echo -n "$events" | wc -l)
1931 if [ "$traced" -eq 0 ]; then
1932 pass "Validate empty trace"
1933 else
1934 fail "Validate empty trace"
1935 diag "Found $traced events in trace"
1936 fi
1937 ret=$?
1938 return $ret
1939}
1940
1941function validate_directory_empty ()
1942{
1943 local trace_path="$1"
1944
1945 # Do not double quote `$trace_path` below as we want wildcards to be
1946 # expanded.
1947 files="$(ls -A $trace_path)"
1948 ret=$?
1949 if [ $ret -ne 0 ]; then
1950 fail "Failed to list content of directory \"$trace_path\""
1951 return $ret
1952 fi
1953
1954 nb_files="$(echo -n "$files" | wc -l)"
1955 ok $nb_files "Directory \"$trace_path\" is empty"
1956}
1957
1958function validate_trace_session_ust_empty()
1959{
1960 validate_directory_empty "$1"/ust
1961}
1962
1963function validate_trace_session_kernel_empty()
1964{
1965 validate_trace_empty "$1"/kernel
1966}
1967
1968function regenerate_metadata ()
1969{
1970 local expected_to_fail=$1
1971 local sess_name=$2
1972
1973 $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate metadata -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1974 ret=$?
1975 if [[ $expected_to_fail -eq "1" ]]; then
1976 test "$ret" -ne "0"
1977 ok $? "Expected fail on regenerate metadata $sess_name"
1978 else
1979 ok $ret "Metadata regenerate $sess_name"
1980 fi
1981}
1982
1983function regenerate_metadata_ok ()
1984{
1985 regenerate_metadata 0 "$@"
1986}
1987
1988function regenerate_metadata_fail ()
1989{
1990 regenerate_metadata 1 "$@"
1991}
1992
1993function regenerate_statedump ()
1994{
1995 local expected_to_fail=$1
1996 local sess_name=$2
1997
1998 $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate statedump -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1999 ret=$?
2000 if [[ $expected_to_fail -eq "1" ]]; then
2001 test "$ret" -ne "0"
2002 ok $? "Expected fail on regenerate statedump $sess_name"
2003 else
2004 ok $ret "Statedump regenerate $sess_name"
2005 fi
2006}
2007
2008function regenerate_statedump_ok ()
2009{
2010 regenerate_statedump 0 "$@"
2011}
2012
2013function regenerate_statedump_fail ()
2014{
2015 regenerate_statedump 1 "$@"
2016}
2017
2018function rotate_session ()
2019{
2020 local expected_to_fail=$1
2021 local sess_name=$2
2022
2023 $TESTDIR/../src/bin/lttng/$LTTNG_BIN rotate $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2024 ret=$?
2025 if [[ $expected_to_fail -eq "1" ]]; then
2026 test "$ret" -ne "0"
2027 ok $? "Expected fail on rotate session $sess_name"
2028 else
2029 ok $ret "Rotate session $sess_name"
2030 fi
2031}
2032
2033function rotate_session_ok ()
2034{
2035 rotate_session 0 "$@"
2036}
2037
2038function rotate_session_fail ()
2039{
2040 rotate_session 1 "$@"
2041}
2042
2043function destructive_tests_enabled ()
2044{
2045 if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then
2046 return 0
2047 else
2048 return 1
2049 fi
2050}
2051
2052function lttng_enable_rotation_timer ()
2053{
2054 local expected_to_fail=$1
2055 local sess_name=$2
2056 local period=$3
2057
2058 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --timer $period 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2059 ret=$?
2060 if [[ $expected_to_fail -eq "1" ]]; then
2061 test "$ret" -ne "0"
2062 ok $? "Expected fail when setting periodic rotation ($period) of session $sess_name"
2063 else
2064 ok $ret "Set periodic rotation ($period) of session $sess_name"
2065 fi
2066}
2067
2068function lttng_enable_rotation_timer_ok ()
2069{
2070 lttng_enable_rotation_timer 0 $@
2071}
2072
2073function lttng_enable_rotation_timer_fail ()
2074{
2075 lttng_enable_rotation_timer 1 $@
2076}
2077
2078function lttng_enable_rotation_size ()
2079{
2080 local expected_to_fail=$1
2081 local sess_name=$2
2082 local size=$3
2083
2084 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --size $size 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2085 ret=$?
2086 if [[ $expected_to_fail -eq "1" ]]; then
2087 test "$ret" -ne "0"
2088 ok $? "Expected fail on rotate session $sess_name"
2089 else
2090 ok $ret "Rotate session $sess_name"
2091 fi
2092}
2093
2094function lttng_enable_rotation_size_ok ()
2095{
2096 lttng_enable_rotation_size 0 $@
2097}
2098
2099function lttng_enable_rotation_size_fail ()
2100{
2101 lttng_enable_rotation_size 1 $@
2102}
2103
2104function lttng_clear_session ()
2105{
2106 local expected_to_fail=$1
2107 local sess_name=$2
2108
2109 $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2110 ret=$?
2111 if [[ $expected_to_fail -eq "1" ]]; then
2112 test "$ret" -ne "0"
2113 ok $? "Expected fail on clear session $sess_name"
2114 else
2115 ok $ret "Clear session $sess_name"
2116 fi
2117}
2118
2119function lttng_clear_session_ok ()
2120{
2121 lttng_clear_session 0 $@
2122}
2123
2124function lttng_clear_session_fail ()
2125{
2126 lttng_clear_session 1 $@
2127}
2128
2129function lttng_clear_all ()
2130{
2131 $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2132 ok $? "Clear all lttng sessions"
2133}
2134
2135function lttng_add_trigger()
2136{
2137 local expected_to_fail="$1"
2138 local trigger_name="$2"
2139 shift 2
2140
2141 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-trigger --id "$trigger_name" "$@" 1> /dev/null 2> /dev/null
2142 ret=$?
2143 if [[ $expected_to_fail -eq "1" ]]; then
2144 test "$ret" -ne "0"
2145 ok $? "Add trigger $trigger_name failed as expected"
2146 else
2147 ok $ret "Add trigger $trigger_name"
2148 fi
2149}
2150
2151function lttng_remove_trigger()
2152{
2153 local expected_to_fail="$1"
2154 local trigger_name="$2"
2155
2156 $TESTDIR/../src/bin/lttng/$LTTNG_BIN remove-trigger "$trigger_name" 1> /dev/null 2> /dev/null
2157 ret=$?
2158 if [[ $expected_to_fail -eq "1" ]]; then
2159 test "$ret" -ne "0"
2160 ok $? "Remove trigger $trigger_name failed as expected"
2161 else
2162 ok $ret "Remove trigger $trigger_name"
2163 fi
2164}
2165
2166function lttng_add_trigger_ok()
2167{
2168 lttng_add_trigger 0 "$@"
2169}
2170
2171function lttng_add_trigger_fail()
2172{
2173 lttng_add_trigger 1 "$@"
2174}
2175
2176function lttng_remove_trigger_ok()
2177{
2178 lttng_remove_trigger 0 "$@"
2179}
2180
2181function lttng_add_map()
2182{
2183 local expected_to_fail="$1"
2184 local map_name="$2"
2185 local session_name="$3"
2186 local domain="$4"
2187 local bitness="$5"
2188 local buf_option="$6"
2189 local coalesced="$7"
2190
2191 local args=("$domain" "--bitness=$bitness" "$buf_option" "--session=$session_name" "$map_name")
2192 if [ -n "$buf_option" ]
2193 then
2194 args+=("$buf_option")
2195 fi
2196
2197 if [ -n "$coalesced" ]
2198 then
2199 args+=("$coalesced")
2200 fi
2201
2202 "$FULL_LTTNG_BIN" add-map ${args[@]} > /dev/null
2203 ret=$?
2204 if [[ $expected_to_fail -eq "1" ]]; then
2205 test "$ret" -ne "0"
2206 ok $? "Map $domain --bitness $bitness creating failed as expected"
2207 else
2208 ok $ret "Map $domain --bitness $bitness created succesfully"
2209 fi
2210}
2211
2212function lttng_add_map_ok()
2213{
2214 lttng_add_map 0 "$@"
2215}
This page took 0.076997 seconds and 5 git commands to generate.