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