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