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