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