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