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