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