Tests: event notifier error counters
[lttng-tools.git] / tests / utils / utils.sh
CommitLineData
9d16b343 1# Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
d3e8f6bb 2#
9d16b343 3# SPDX-License-Identifier: LGPL-2.1-only
d3e8f6bb 4#
d3e8f6bb
DG
5
6SESSIOND_BIN="lttng-sessiond"
725f658e 7SESSIOND_MATCH=".*lttng-sess.*"
19356f3a 8RUNAS_BIN="lttng-runas"
725f658e 9RUNAS_MATCH=".*lttng-runas.*"
f7613992 10CONSUMERD_BIN="lttng-consumerd"
725f658e 11CONSUMERD_MATCH=".*lttng-consumerd.*"
f4e40ab6 12RELAYD_BIN="lttng-relayd"
725f658e 13RELAYD_MATCH=".*lttng-relayd.*"
d3e8f6bb
DG
14LTTNG_BIN="lttng"
15BABELTRACE_BIN="babeltrace"
2cf48300
JR
16OUTPUT_DEST=/dev/null
17ERROR_OUTPUT_DEST=/dev/null
d3e8f6bb 18
fd4dfcec
DG
19# Minimal kernel version supported for session daemon tests
20KERNEL_MAJOR_VERSION=2
21KERNEL_MINOR_VERSION=6
22KERNEL_PATCHLEVEL_VERSION=27
23
651b8bb3
JG
24# We set the default UST register timeout and network and app socket timeout to
25# "wait forever", so that basic tests don't have to worry about hitting
26# timeouts on busy systems. Specialized tests should test those corner-cases.
629b9335 27export LTTNG_UST_REGISTER_TIMEOUT=-1
651b8bb3
JG
28export LTTNG_NETWORK_SOCKET_TIMEOUT=-1
29export LTTNG_APP_SOCKET_TIMEOUT=-1
629b9335 30
fd7fe1a8
JR
31# We set the default lttng-sessiond path to /bin/true to prevent the spawning
32# of a daemonized sessiond. This is necessary since 'lttng create' will spawn
33# its own sessiond if none is running. It also ensures that 'lttng create'
34# fails when no sessiond is running.
35export LTTNG_SESSIOND_PATH="/bin/true"
36
29655db7
CB
37source $TESTDIR/utils/tap/tap.sh
38
65e663fa 39if [ -z ${LTTNG_TEST_TEARDOWN_TIMEOUT+x} ]; then
529bb942
MD
40 LTTNG_TEST_TEARDOWN_TIMEOUT=60
41fi
42
1c362dc7
JR
43function full_cleanup ()
44{
529bb942
MD
45 # Try to kill daemons gracefully
46 stop_lttng_relayd_notap SIGTERM $LTTNG_TEST_TEARDOWN_TIMEOUT
47 stop_lttng_sessiond_notap SIGTERM $LTTNG_TEST_TEARDOWN_TIMEOUT
48
49 # If daemons are still present, forcibly kill them
50 stop_lttng_relayd_notap SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT
51 stop_lttng_sessiond_notap SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT
52 stop_lttng_consumerd_notap SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT
1c362dc7
JR
53
54 # Disable trap for SIGTERM since the following kill to the
55 # pidgroup will be SIGTERM. Otherwise it loops.
56 # The '-' before the pid number ($$) indicates 'kill' to signal the
57 # whole process group.
58 trap - SIGTERM && kill -- -$$
4e8ea4fa 59 exit 1
1c362dc7
JR
60}
61
27b667f7
MD
62function null_pipes ()
63{
64 exec 0>/dev/null
65 exec 1>/dev/null
66 exec 2>/dev/null
67}
1c362dc7
JR
68
69trap full_cleanup SIGINT SIGTERM
70
27b667f7
MD
71# perl prove closes its child pipes before giving it a chance to run its
72# signal trap handlers. Redirect pipes to /dev/null if SIGPIPE is caught
73# to allow those trap handlers to proceed.
74
75trap null_pipes SIGPIPE
76
7cb78e2f
JR
77# Check pgrep from env, default to pgrep if none
78if [ -z "$PGREP" ]; then
79 PGREP=pgrep
80fi
81
82# Due to the renaming of threads we need to use the full command (pgrep -f) to
83# identify the pids for multiple lttng related processes. The problem with "pgrep
84# -f" is that it ends up also looking at the arguments. We use a two stage
85# lookup. The first one is using "pgrep -f" yielding potential candidate.
86# The second on perform grep on the basename of the first field of the
87# /proc/pid/cmdline of the previously identified pids. The first field
88# correspond to the actual command.
89function lttng_pgrep ()
90{
91 local pattern=$1
92 local possible_pids
93 local full_command_no_argument
94 local command_basename
95
96 possible_pids=$($PGREP -f "$pattern")
97 if [ -z "$possible_pids" ]; then
98 return 0
99 fi
100
101 while IFS= read -r pid ; do
102 # /proc/pid/cmdline is null separated.
00d1ff64 103 if full_command_no_argument=$(cut -d '' -f 1 2>/dev/null < /proc/"$pid"/cmdline); then
7cb78e2f
JR
104 command_basename=$(basename "$full_command_no_argument")
105 if grep -q "$pattern" <<< "$command_basename"; then
106 echo "$pid"
107 fi
108 fi
109 done <<< "$possible_pids"
110 return 0
111}
112
fec81a7e
CB
113function print_ok ()
114{
115 # Check if we are a terminal
116 if [ -t 1 ]; then
117 echo -e "\e[1;32mOK\e[0m"
118 else
119 echo -e "OK"
120 fi
121}
122
123function print_fail ()
124{
125 # Check if we are a terminal
126 if [ -t 1 ]; then
127 echo -e "\e[1;31mFAIL\e[0m"
128 else
129 echo -e "FAIL"
130 fi
131}
132
133function print_test_banner ()
134{
7d0ad314 135 local desc="$1"
29655db7 136 diag "$desc"
fec81a7e
CB
137}
138
fd4dfcec
DG
139function validate_kernel_version ()
140{
7d0ad314 141 local kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n'))
fd4dfcec
DG
142 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
143 return 0
144 fi
145 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
146 return 0
147 fi
148 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
149 return 0
150 fi
151 return 1
152}
153
9ac429ef 154# Generate a random string
f4e40ab6
DG
155# $1 = number of characters; defaults to 16
156# $2 = include special characters; 1 = yes, 0 = no; defaults to yes
9ac429ef 157function randstring()
f4e40ab6
DG
158{
159 [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
b89c3a68 160 cat /dev/urandom 2>/dev/null | tr -cd "$CHAR" 2>/dev/null | head -c ${1:-16} 2>/dev/null
f4e40ab6
DG
161 echo
162}
163
9e136324
JG
164# Return the number of _configured_ CPUs.
165function conf_proc_count()
166{
167 getconf _NPROCESSORS_CONF
168 if [ $? -ne 0 ]; then
169 diag "Failed to get the number of configured CPUs"
170 fi
171 echo
172}
173
9c8a3964
JR
174# Check if base lttng-modules are present.
175# Bail out on failure
176function validate_lttng_modules_present ()
177{
03f11686 178 # Check for loadable modules.
9c8a3964 179 modprobe -n lttng-tracer 2>/dev/null
03f11686
FD
180 if [ $? -eq 0 ]; then
181 return 0
9c8a3964 182 fi
03f11686
FD
183
184 # Check for builtin modules.
185 ls /proc/lttng > /dev/null 2>&1
186 if [ $? -eq 0 ]; then
187 return 0
188 fi
189
190 BAIL_OUT "LTTng modules not detected."
9c8a3964
JR
191}
192
4a180d9f 193function enable_kernel_lttng_event
f4e40ab6 194{
854382b8
JR
195 local withtap="$1"
196 local expected_to_fail="$2"
197 local sess_name="$3"
198 local event_name="$4"
199 local channel_name="$5"
f4e40ab6 200
4a180d9f 201 if [ -z "$event_name" ]; then
f4e40ab6 202 # Enable all event if no event name specified
29655db7 203 event_name="-a"
f4e40ab6
DG
204 fi
205
4a180d9f 206 if [ -z "$channel_name" ]; then
07b86b52
JD
207 # default channel if none specified
208 chan=""
209 else
210 chan="-c $channel_name"
211 fi
212
2cf48300 213 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
4a180d9f
MD
214 ret=$?
215 if [[ $expected_to_fail -eq "1" ]]; then
216 test $ret -ne "0"
854382b8
JR
217 ret=$?
218 if [ $withtap -eq "1" ]; then
219 ok $ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
220 fi
4a180d9f 221 else
854382b8
JR
222 if [ $withtap -eq "1" ]; then
223 ok $ret "Enable kernel event $event_name for session $sess_name"
224 fi
4a180d9f
MD
225 fi
226}
227
228function enable_kernel_lttng_event_ok ()
229{
854382b8 230 enable_kernel_lttng_event 1 0 "$@"
4a180d9f
MD
231}
232
233function enable_kernel_lttng_event_fail ()
234{
854382b8
JR
235 enable_kernel_lttng_event 1 1 "$@"
236}
237
238function enable_kernel_lttng_event_notap ()
239{
240 enable_kernel_lttng_event 0 0 "$@"
4a180d9f
MD
241}
242
243# Old interface
244function lttng_enable_kernel_event
245{
246 enable_kernel_lttng_event_ok "$@"
f4e40ab6
DG
247}
248
8cfcd41c
MD
249function lttng_enable_kernel_syscall()
250{
251 local expected_to_fail=$1
252 local sess_name=$2
253 local syscall_name=$3
254 local channel_name=$4
255
256 if [ -z $syscall_name ]; then
257 # Enable all event if no syscall name specified
258 syscall_name="-a"
259 fi
260
261 if [ -z $channel_name ]; then
262 # default channel if none specified
263 chan=""
264 else
265 chan="-c $channel_name"
266 fi
267
2cf48300 268 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
8cfcd41c
MD
269 ret=$?
270 if [[ $expected_to_fail -eq "1" ]]; then
271 test $ret -ne "0"
272 ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
273 else
274 ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
275 fi
276}
277
278function lttng_enable_kernel_syscall_ok()
279{
421b83dc 280 lttng_enable_kernel_syscall 0 "$@"
8cfcd41c
MD
281}
282
283function lttng_enable_kernel_syscall_fail()
284{
421b83dc 285 lttng_enable_kernel_syscall 1 "$@"
8cfcd41c
MD
286}
287
288function lttng_disable_kernel_syscall()
289{
290 local expected_to_fail=$1
291 local sess_name=$2
292 local syscall_name=$3
293 local channel_name=$4
294
295 if [ -z $syscall_name ]; then
296 # Enable all event if no syscall name specified
297 syscall_name="-a"
298 fi
299
300 if [ -z $channel_name ]; then
301 # default channel if none specified
302 chan=""
303 else
304 chan="-c $channel_name"
305 fi
306
2cf48300 307 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
8cfcd41c
MD
308
309 ret=$?
310 if [[ $expected_to_fail -eq "1" ]]; then
311 test $ret -ne "0"
34ab15c5 312 ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
8cfcd41c
MD
313 else
314 ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
315 fi
316}
317
318function lttng_disable_kernel_syscall_ok()
319{
421b83dc 320 lttng_disable_kernel_syscall 0 "$@"
8cfcd41c
MD
321}
322
323function lttng_disable_kernel_syscall_fail()
324{
421b83dc 325 lttng_disable_kernel_syscall 1 "$@"
8cfcd41c
MD
326}
327
b6d14cf3
FD
328function lttng_enable_kernel_function_event ()
329{
330 local expected_to_fail="$1"
331 local sess_name="$2"
332 local target="$3"
333 local event_name="$4"
334
335 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event --kernel --function="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
336 ret=$?
337 if [[ $expected_to_fail -eq "1" ]]; then
338 test $ret -ne "0"
339 ok $? "Enable kernel function event for session $sess_name failed as expected"
340 else
341 ok $ret "Enable kernel function event for session $sess_name"
342 fi
343}
344
345function lttng_enable_kernel_function_event_ok ()
346{
347 lttng_enable_kernel_function_event 0 "$@"
348}
349
a9c2df2b
FD
350function lttng_enable_kernel_userspace_probe_event ()
351{
352 local expected_to_fail="$1"
353 local sess_name="$2"
354 local target="$3"
355 local event_name="$4"
356
357 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event --kernel --userspace-probe="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
358 ret=$?
359 if [[ $expected_to_fail -eq "1" ]]; then
360 test $ret -ne "0"
361 ok $? "Enable kernel userspace probe event for session $sess_name failed as expected"
362 else
363 ok $ret "Enable kernel userspace probe event for session $sess_name"
364 fi
365}
366
367function lttng_enable_kernel_userspace_probe_event_fail ()
368{
369 lttng_enable_kernel_userspace_probe_event 1 "$@"
370}
371
372function lttng_enable_kernel_userspace_probe_event_ok ()
373{
374 lttng_enable_kernel_userspace_probe_event 0 "$@"
375}
376
377function disable_kernel_lttng_userspace_probe_event_ok ()
378{
379 local sess_name="$1"
380 local event_name="$2"
381
382 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" disable-event --kernel "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
383 ok $? "Disable kernel event $target for session $sess_name"
384}
d96f6315
MD
385function lttng_enable_kernel_channel()
386{
854382b8
JR
387 local withtap=$1
388 local expected_to_fail=$2
389 local sess_name=$3
390 local channel_name=$4
c28fcefd 391 local opts="${@:5}"
d96f6315 392
c28fcefd 393 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
d96f6315
MD
394 ret=$?
395 if [[ $expected_to_fail -eq "1" ]]; then
396 test "$ret" -ne "0"
854382b8
JR
397 ret=$?
398 if [ $withtap -eq "1" ]; then
399 ok $ret "Enable channel $channel_name for session $sess_name failed as expected"
400 fi
d96f6315 401 else
854382b8
JR
402 if [ $withtap -eq "1" ]; then
403 ok $ret "Enable channel $channel_name for session $sess_name"
404 fi
d96f6315
MD
405 fi
406}
407
408function lttng_enable_kernel_channel_ok()
409{
854382b8 410 lttng_enable_kernel_channel 1 0 "$@"
d96f6315
MD
411}
412
413function lttng_enable_kernel_channel_fail()
414{
854382b8
JR
415 lttng_enable_kernel_channel 1 1 "$@"
416}
417
418function lttng_enable_kernel_channel_notap()
419{
420 lttng_enable_kernel_channel 0 0 "$@"
421}
422
423function enable_kernel_lttng_channel_ok()
424{
425 lttng_enable_kernel_channel 1 0 "$@"
d96f6315
MD
426}
427
428function lttng_disable_kernel_channel()
429{
430 local expected_to_fail=$1
431 local sess_name=$2
432 local channel_name=$3
433
2cf48300 434 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
d96f6315
MD
435 ret=$?
436 if [[ $expected_to_fail -eq "1" ]]; then
437 test "$ret" -ne "0"
34ab15c5 438 ok $? "Disable channel $channel_name for session $sess_name failed as expected"
d96f6315 439 else
34ab15c5 440 ok $ret "Disable channel $channel_name for session $sess_name"
d96f6315
MD
441 fi
442}
443
444function lttng_disable_kernel_channel_ok()
445{
421b83dc 446 lttng_disable_kernel_channel 0 "$@"
d96f6315
MD
447}
448
449function lttng_disable_kernel_channel_fail()
450{
421b83dc 451 lttng_disable_kernel_channel 1 "$@"
d96f6315
MD
452}
453
05aa48da 454function start_lttng_relayd_opt()
f4e40ab6 455{
05aa48da 456 local withtap=$1
f3630ec4
JR
457 local process_mode=$2
458 local opt=$3
173af62f 459
529bb942 460 DIR=$(readlink -f "$TESTDIR")
f4e40ab6 461
7cb78e2f 462 if [ -z $(lttng_pgrep "$RELAYD_MATCH") ]; then
529bb942 463 # shellcheck disable=SC2086
f3630ec4
JR
464 $DIR/../src/bin/lttng-relayd/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
465 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
f4e40ab6 466 if [ $? -eq 1 ]; then
f3630ec4
JR
467 if [ $withtap -eq "1" ]; then
468 fail "Start lttng-relayd (process mode: $process_mode opt: $opt)"
05aa48da 469 fi
f4e40ab6
DG
470 return 1
471 else
f3630ec4
JR
472 if [ $withtap -eq "1" ]; then
473 pass "Start lttng-relayd (process mode: $process_mode opt: $opt)"
05aa48da 474 fi
f4e40ab6
DG
475 fi
476 else
29655db7 477 pass "Start lttng-relayd (opt: $opt)"
f4e40ab6
DG
478 fi
479}
480
05aa48da 481function start_lttng_relayd()
f4e40ab6 482{
f3630ec4 483 start_lttng_relayd_opt 1 "-b" "$@"
05aa48da
MD
484}
485
486function start_lttng_relayd_notap()
487{
f3630ec4 488 start_lttng_relayd_opt 0 "-b" "$@"
05aa48da
MD
489}
490
491function stop_lttng_relayd_opt()
492{
493 local withtap=$1
529bb942 494 local signal=$2
05aa48da 495
529bb942
MD
496 if [ -z "$signal" ]; then
497 signal="SIGTERM"
05aa48da 498 fi
29655db7 499
529bb942
MD
500 local timeout_s=$3
501 local dtimeleft_s=
502
503 # Multiply time by 2 to simplify integer arithmetic
504 if [ -n "$timeout_s" ]; then
505 dtimeleft_s=$((timeout_s * 2))
506 fi
507
508 local retval=0
509 local pids=
510
7cb78e2f 511 pids=$(lttng_pgrep "$RELAYD_MATCH")
529bb942
MD
512 if [ -z "$pids" ]; then
513 if [ "$withtap" -eq "1" ]; then
514 pass "No relay daemon to kill"
515 fi
516 return 0
517 fi
518
519 diag "Killing (signal $signal) lttng-relayd (pid: $pids)"
520
521 # shellcheck disable=SC2086
522 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
523 retval=1
524 if [ "$withtap" -eq "1" ]; then
05aa48da
MD
525 fail "Kill relay daemon"
526 fi
05aa48da 527 else
f4e40ab6
DG
528 out=1
529 while [ -n "$out" ]; do
7cb78e2f 530 out=$(lttng_pgrep "$RELAYD_MATCH")
529bb942
MD
531 if [ -n "$dtimeleft_s" ]; then
532 if [ $dtimeleft_s -lt 0 ]; then
533 out=
534 retval=1
535 fi
536 dtimeleft_s=$((dtimeleft_s - 1))
537 fi
f4e40ab6
DG
538 sleep 0.5
539 done
529bb942
MD
540 if [ "$withtap" -eq "1" ]; then
541 if [ "$retval" -eq "0" ]; then
542 pass "Wait after kill relay daemon"
543 else
544 fail "Wait after kill relay daemon"
545 fi
05aa48da 546 fi
1fb23888
MD
547 fi
548 return $retval
549}
550
05aa48da 551function stop_lttng_relayd()
1fb23888 552{
05aa48da
MD
553 stop_lttng_relayd_opt 1 "$@"
554}
1fb23888 555
05aa48da
MD
556function stop_lttng_relayd_notap()
557{
558 stop_lttng_relayd_opt 0 "$@"
f4e40ab6
DG
559}
560
05aa48da
MD
561#First arg: show tap output
562#Second argument: load path for automatic loading
563function start_lttng_sessiond_opt()
355f483d 564{
05aa48da
MD
565 local withtap=$1
566 local load_path=$2
8d51ddbc 567
1d302e3d
JR
568 # The rest of the arguments will be passed directly to lttng-sessiond.
569 shift 2
570
4b01971f 571 local env_vars=""
b916da6b 572 local consumerd=""
b916da6b 573
529bb942
MD
574 local long_bit_value=
575 long_bit_value=$(getconf LONG_BIT)
576
577 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
355f483d
DG
578 # Env variable requested no session daemon
579 return
580 fi
581
529bb942 582 DIR=$(readlink -f "$TESTDIR")
b916da6b
JR
583
584 # Get long_bit value for 32/64 consumerd
585 case "$long_bit_value" in
586 32)
587 consumerd="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
588 ;;
589 64)
590 consumerd="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
591 ;;
592 *)
593 return
594 ;;
595 esac
596
4b01971f
JR
597 # Check for env. variable. Allow the use of LD_PRELOAD etc.
598 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
529bb942 599 env_vars="${LTTNG_SESSIOND_ENV_VARS} "
4b01971f 600 fi
529bb942 601 env_vars="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN"
4b01971f 602
529bb942 603 if ! validate_kernel_version; then
29655db7
CB
604 fail "Start session daemon"
605 BAIL_OUT "*** Kernel too old for session daemon tests ***"
355f483d
DG
606 fi
607
529bb942 608 : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}"
d3d97763 609 export LTTNG_SESSION_CONFIG_XSD_PATH
29655db7 610
7cb78e2f 611 if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ]; then
8d51ddbc 612 # Have a load path ?
05aa48da 613 if [ -n "$load_path" ]; then
529bb942 614 # shellcheck disable=SC2086
1d302e3d 615 env $env_vars --load "$load_path" --background "$consumerd" "$@"
8d51ddbc 616 else
529bb942 617 # shellcheck disable=SC2086
1d302e3d 618 env $env_vars --background "$consumerd" "$@"
8d51ddbc 619 fi
0fc2834c 620 #$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 621 status=$?
529bb942 622 if [ "$withtap" -eq "1" ]; then
05aa48da
MD
623 ok $status "Start session daemon"
624 fi
29655db7 625 fi
355f483d
DG
626}
627
05aa48da
MD
628function start_lttng_sessiond()
629{
630 start_lttng_sessiond_opt 1 "$@"
631}
632
633function start_lttng_sessiond_notap()
d3e8f6bb 634{
05aa48da
MD
635 start_lttng_sessiond_opt 0 "$@"
636}
637
638function stop_lttng_sessiond_opt()
639{
640 local withtap=$1
4c80129b 641 local signal=$2
05aa48da 642
529bb942
MD
643 if [ -z "$signal" ]; then
644 signal=SIGTERM
645 fi
646
647 local timeout_s=$3
648 local dtimeleft_s=
649
650 # Multiply time by 2 to simplify integer arithmetic
651 if [ -n "$timeout_s" ]; then
652 dtimeleft_s=$((timeout_s * 2))
653 fi
654
655 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
355f483d 656 # Env variable requested no session daemon
529bb942 657 return 0
355f483d
DG
658 fi
659
529bb942 660 local retval=0
d3e8f6bb 661
529bb942 662 local runas_pids=
7cb78e2f 663 runas_pids=$(lttng_pgrep "$RUNAS_MATCH")
529bb942
MD
664
665 local pids=
7cb78e2f 666 pids=$(lttng_pgrep "$SESSIOND_MATCH")
529bb942
MD
667
668 if [ -n "$runas_pids" ]; then
669 pids="$pids $runas_pids"
4c80129b 670 fi
529bb942
MD
671
672 if [ -z "$pids" ]; then
673 if [ "$withtap" -eq "1" ]; then
d3d783bb
FD
674 fail "No session daemon to kill"
675 else
676 BAIL_OUT "No session daemon to kill"
529bb942
MD
677 fi
678 return 0
8490897a 679 fi
29655db7 680
529bb942
MD
681 diag "Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
682
683 # shellcheck disable=SC2086
684 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
685 retval=1
686 if [ "$withtap" -eq "1" ]; then
05aa48da
MD
687 fail "Kill sessions daemon"
688 fi
d3e8f6bb 689 else
5fa32580
DG
690 out=1
691 while [ -n "$out" ]; do
7cb78e2f 692 out=$(lttng_pgrep "${SESSIOND_MATCH}")
529bb942
MD
693 if [ -n "$dtimeleft_s" ]; then
694 if [ $dtimeleft_s -lt 0 ]; then
695 out=
696 retval=1
697 fi
698 dtimeleft_s=$((dtimeleft_s - 1))
699 fi
5fa32580
DG
700 sleep 0.5
701 done
f7613992
MD
702 out=1
703 while [ -n "$out" ]; do
7cb78e2f 704 out=$(lttng_pgrep "$CONSUMERD_MATCH")
529bb942
MD
705 if [ -n "$dtimeleft_s" ]; then
706 if [ $dtimeleft_s -lt 0 ]; then
707 out=
708 retval=1
709 fi
710 dtimeleft_s=$((dtimeleft_s - 1))
711 fi
f7613992
MD
712 sleep 0.5
713 done
1c362dc7 714
529bb942
MD
715 if [ "$withtap" -eq "1" ]; then
716 if [ "$retval" -eq "0" ]; then
717 pass "Wait after kill session daemon"
718 else
719 fail "Wait after kill session daemon"
720 fi
05aa48da 721 fi
d3e8f6bb 722 fi
529bb942
MD
723 if [ "$signal" = "SIGKILL" ]; then
724 if [ "$(id -u)" -eq "0" ]; then
725 local modules=
726 modules="$(lsmod | grep ^lttng | awk '{print $1}')"
727
728 if [ -n "$modules" ]; then
729 diag "Unloading all LTTng modules"
d0e263e7 730 modprobe --remove "$modules"
529bb942
MD
731 fi
732 fi
733 fi
734
735 return $retval
d3e8f6bb
DG
736}
737
05aa48da
MD
738function stop_lttng_sessiond()
739{
740 stop_lttng_sessiond_opt 1 "$@"
741}
742
743function stop_lttng_sessiond_notap()
744{
745 stop_lttng_sessiond_opt 0 "$@"
746}
747
8490897a
MD
748function sigstop_lttng_sessiond_opt()
749{
750 local withtap=$1
751 local signal=SIGSTOP
8490897a 752
529bb942 753 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
8490897a
MD
754 # Env variable requested no session daemon
755 return
756 fi
757
7cb78e2f 758 PID_SESSIOND="$(lttng_pgrep "${SESSIOND_MATCH}") $(lttng_pgrep "$RUNAS_MATCH")"
8490897a 759
529bb942
MD
760 if [ "$withtap" -eq "1" ]; then
761 diag "Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$PID_SESSIOND" | tr '\n' ' ')"
8490897a 762 fi
8490897a 763
529bb942
MD
764 # shellcheck disable=SC2086
765 if ! kill -s $signal $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
766 if [ "$withtap" -eq "1" ]; then
8490897a
MD
767 fail "Sending SIGSTOP to session daemon"
768 fi
769 else
770 out=1
771 while [ $out -ne 0 ]; do
7cb78e2f 772 pid="$(lttng_pgrep "$SESSIOND_MATCH")"
8490897a
MD
773
774 # Wait until state becomes stopped for session
775 # daemon(s).
776 out=0
777 for sessiond_pid in $pid; do
529bb942 778 state="$(ps -p "$sessiond_pid" -o state= )"
8490897a
MD
779 if [[ -n "$state" && "$state" != "T" ]]; then
780 out=1
781 fi
782 done
783 sleep 0.5
784 done
529bb942 785 if [ "$withtap" -eq "1" ]; then
8490897a
MD
786 pass "Sending SIGSTOP to session daemon"
787 fi
788 fi
789}
790
791function sigstop_lttng_sessiond()
792{
793 sigstop_lttng_sessiond_opt 1 "$@"
794}
795
796function sigstop_lttng_sessiond_notap()
797{
798 sigstop_lttng_sessiond_opt 0 "$@"
799}
800
4c80129b
JR
801function stop_lttng_consumerd_opt()
802{
803 local withtap=$1
804 local signal=$2
4c80129b 805
529bb942
MD
806 if [ -z "$signal" ]; then
807 signal=SIGTERM
808 fi
809
810 local timeout_s=$3
811 local dtimeleft_s=
4c80129b 812
529bb942
MD
813 # Multiply time by 2 to simplify integer arithmetic
814 if [ -n "$timeout_s" ]; then
815 dtimeleft_s=$((timeout_s * 2))
4c80129b
JR
816 fi
817
529bb942
MD
818 local retval=0
819
7cb78e2f 820 PID_CONSUMERD="$(lttng_pgrep "$CONSUMERD_MATCH")"
529bb942
MD
821
822 if [ -z "$PID_CONSUMERD" ]; then
823 if [ "$withtap" -eq "1" ]; then
824 pass "No consumer daemon to kill"
825 fi
826 return 0
4c80129b 827 fi
3355fd4d 828
529bb942 829 diag "Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')"
4c80129b 830
529bb942
MD
831 # shellcheck disable=SC2086
832 if ! kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
833 retval=1
834 if [ "$withtap" -eq "1" ]; then
4c80129b
JR
835 fail "Kill consumer daemon"
836 fi
4c80129b
JR
837 else
838 out=1
839 while [ $out -ne 0 ]; do
7cb78e2f 840 pid="$(lttng_pgrep "$CONSUMERD_MATCH")"
4c80129b
JR
841
842 # If consumerds are still present check their status.
843 # A zombie status qualifies the consumerd as *killed*
844 out=0
845 for consumer_pid in $pid; do
529bb942 846 state="$(ps -p "$consumer_pid" -o state= )"
4c80129b
JR
847 if [[ -n "$state" && "$state" != "Z" ]]; then
848 out=1
849 fi
850 done
529bb942
MD
851 if [ -n "$dtimeleft_s" ]; then
852 if [ $dtimeleft_s -lt 0 ]; then
853 out=0
854 retval=1
855 fi
856 dtimeleft_s=$((dtimeleft_s - 1))
857 fi
4c80129b
JR
858 sleep 0.5
859 done
529bb942
MD
860 if [ "$withtap" -eq "1" ]; then
861 if [ "$retval" -eq "0" ]; then
862 pass "Wait after kill consumer daemon"
863 else
864 fail "Wait after kill consumer daemon"
865 fi
4c80129b
JR
866 fi
867 fi
529bb942 868
4c80129b
JR
869 return $retval
870}
871
872function stop_lttng_consumerd()
873{
874 stop_lttng_consumerd_opt 1 "$@"
875}
876
877function stop_lttng_consumerd_notap()
878{
879 stop_lttng_consumerd_opt 0 "$@"
880}
881
8490897a
MD
882function sigstop_lttng_consumerd_opt()
883{
884 local withtap=$1
885 local signal=SIGSTOP
8490897a 886
7cb78e2f 887 PID_CONSUMERD="$(lttng_pgrep "$CONSUMERD_MATCH")"
8490897a 888
529bb942 889 diag "Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')"
8490897a 890
529bb942
MD
891 # shellcheck disable=SC2086
892 kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
8490897a 893 retval=$?
8490897a 894
529bb942
MD
895 if [ $retval -eq 1 ]; then
896 if [ "$withtap" -eq "1" ]; then
8490897a
MD
897 fail "Sending SIGSTOP to consumer daemon"
898 fi
899 return 1
900 else
901 out=1
902 while [ $out -ne 0 ]; do
7cb78e2f 903 pid="$(lttng_pgrep "$CONSUMERD_MATCH")"
8490897a
MD
904
905 # Wait until state becomes stopped for all
906 # consumers.
907 out=0
908 for consumer_pid in $pid; do
529bb942 909 state="$(ps -p "$consumer_pid" -o state= )"
8490897a
MD
910 if [[ -n "$state" && "$state" != "T" ]]; then
911 out=1
912 fi
913 done
914 sleep 0.5
915 done
529bb942 916 if [ "$withtap" -eq "1" ]; then
8490897a
MD
917 pass "Sending SIGSTOP to consumer daemon"
918 fi
919 fi
920 return $retval
921}
922
923function sigstop_lttng_consumerd()
924{
925 sigstop_lttng_consumerd_opt 1 "$@"
926}
927
928function sigstop_lttng_consumerd_notap()
929{
930 sigstop_lttng_consumerd_opt 0 "$@"
931}
932
873c2aae
JRJ
933function list_lttng_with_opts ()
934{
7d0ad314 935 local opts=$1
2cf48300 936 $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
873c2aae
JRJ
937 ok $? "Lttng-tool list command with option $opts"
938}
939
07b86b52
JD
940function create_lttng_session_no_output ()
941{
7d0ad314 942 local sess_name=$1
2a166864 943 local opts="${@:2}"
07b86b52 944
2a166864 945 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
07b86b52
JD
946 ok $? "Create session $sess_name in no-output mode"
947}
948
f0d43d3d
JR
949function create_lttng_session_uri () {
950 local sess_name=$1
951 local uri=$2
952 local opts="${@:3}"
953
954 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -U $uri $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
955 ok $? "Create session $sess_name with uri:$uri and opts: $opts"
956}
957
d3e8f6bb
DG
958function create_lttng_session ()
959{
434f8068
JR
960 local withtap=$1
961 local expected_to_fail=$2
962 local sess_name=$3
963 local trace_path=$4
964 local opt=$5
d3e8f6bb 965
01654d69
JR
966 if [ -z "$trace_path" ]; then
967 # Use lttng-sessiond default output.
968 trace_path=""
969 else
970 trace_path="-o $trace_path"
971 fi
972
973 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create "$sess_name" $trace_path $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
873c2aae 974 ret=$?
434f8068 975 if [ $expected_to_fail -eq "1" ]; then
01513c3e 976 test "$ret" -ne "0"
434f8068
JR
977 ret=$?
978 if [ $withtap -eq "1" ]; then
979 ok $ret "Create session $sess_name in $trace_path failed as expected"
980 fi
873c2aae 981 else
434f8068
JR
982 if [ $withtap -eq "1" ]; then
983 ok $ret "Create session $sess_name in $trace_path"
984 fi
873c2aae 985 fi
434f8068 986 return $ret
d4018451
DG
987}
988
bf6ae429
JR
989function create_lttng_session_ok ()
990{
434f8068 991 create_lttng_session 1 0 "$@"
bf6ae429
JR
992}
993
994function create_lttng_session_fail ()
995{
434f8068
JR
996 create_lttng_session 1 1 "$@"
997}
998
999function create_lttng_session_notap ()
1000{
1001 create_lttng_session 0 0 "$@"
bf6ae429
JR
1002}
1003
1004
827caf52 1005function enable_ust_lttng_channel ()
d4018451 1006{
434f8068
JR
1007 local withtap=$1
1008 local expected_to_fail=$2
1009 local sess_name=$3
1010 local channel_name=$4
c28fcefd 1011 local opts="${@:5}"
d4018451 1012
c28fcefd 1013 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
312dabc3 1014 ret=$?
34ab15c5 1015 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1016 test "$ret" -ne "0"
434f8068
JR
1017 ret=$?
1018 if [ $withtap -eq "1" ]; then
1019 ok $ret "Enable channel $channel_name for session $sess_name failed as expected"
1020 fi
312dabc3 1021 else
434f8068
JR
1022 if [ $withtap -eq "1" ]; then
1023 ok $ret "Enable channel $channel_name for session $sess_name"
1024 fi
312dabc3 1025 fi
434f8068 1026 return $ret
d4018451
DG
1027}
1028
827caf52
JR
1029function enable_ust_lttng_channel_ok ()
1030{
434f8068 1031 enable_ust_lttng_channel 1 0 "$@"
827caf52
JR
1032}
1033
1034function enable_ust_lttng_channel_fail ()
1035{
434f8068
JR
1036 enable_ust_lttng_channel 1 1 "$@"
1037}
1038
1039function enable_ust_lttng_channel_notap ()
1040{
1041 enable_ust_lttng_channel 0 0 "$@"
827caf52
JR
1042}
1043
29655db7 1044function disable_ust_lttng_channel()
d4018451 1045{
7d0ad314
JRJ
1046 local sess_name=$1
1047 local channel_name=$2
d4018451 1048
2cf48300 1049 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 1050 ok $? "Disable channel $channel_name for session $sess_name"
d3e8f6bb
DG
1051}
1052
07b86b52
JD
1053function enable_lttng_mmap_overwrite_kernel_channel()
1054{
7d0ad314
JRJ
1055 local sess_name=$1
1056 local channel_name=$2
07b86b52 1057
2cf48300 1058 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
07b86b52
JD
1059 ok $? "Enable channel $channel_name for session $sess_name"
1060}
1061
086e6add
MD
1062function enable_lttng_mmap_discard_small_kernel_channel()
1063{
1064 local sess_name=$1
1065 local channel_name=$2
1066
1067 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --discard --subbuf-size=$(getconf PAGE_SIZE) --num-subbuf=2 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1068 ok $? "Enable small discard channel $channel_name for session $sess_name"
1069}
1070
1071function enable_lttng_mmap_overwrite_small_kernel_channel()
1072{
1073 local sess_name=$1
1074 local channel_name=$2
1075
1076 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite --subbuf-size=$(getconf PAGE_SIZE) --num-subbuf=2 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1077 ok $? "Enable small discard channel $channel_name for session $sess_name"
1078}
1079
ebaaaf5e
JD
1080function enable_lttng_mmap_overwrite_ust_channel()
1081{
7d0ad314
JRJ
1082 local sess_name=$1
1083 local channel_name=$2
ebaaaf5e 1084
2cf48300 1085 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
ebaaaf5e
JD
1086 ok $? "Enable channel $channel_name for session $sess_name"
1087}
1088
d3e8f6bb
DG
1089function enable_ust_lttng_event ()
1090{
434f8068
JR
1091 local withtap=$1
1092 local expected_to_fail=$2
1093 local sess_name=$3
1094 local event_name="$4"
1095 local channel_name=$5
ebaaaf5e
JD
1096
1097 if [ -z $channel_name ]; then
1098 # default channel if none specified
1099 chan=""
1100 else
1101 chan="-c $channel_name"
1102 fi
d3e8f6bb 1103
2cf48300 1104 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1105 ret=$?
c4926bb5 1106 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1107 test $ret -ne "0"
434f8068
JR
1108 ret=$?
1109 if [[ $withtap -eq "1" ]]; then
1110 ok $ret "Enable ust event $event_name for session $session_name failed as expected"
1111 fi
01513c3e 1112 else
434f8068
JR
1113 if [[ $withtap -eq "1" ]]; then
1114 ok $ret "Enable ust event $event_name for session $sess_name"
1115 fi
01513c3e 1116 fi
434f8068 1117 return $ret
26b53d3b
DG
1118}
1119
c4926bb5
JR
1120function enable_ust_lttng_event_ok ()
1121{
434f8068 1122 enable_ust_lttng_event 1 0 "$@"
c4926bb5
JR
1123}
1124
1125function enable_ust_lttng_event_fail ()
1126{
434f8068
JR
1127 enable_ust_lttng_event 1 1 "$@"
1128}
1129
1130function enable_ust_lttng_event_notap ()
1131{
1132 enable_ust_lttng_event 0 0 "$@"
c4926bb5
JR
1133}
1134
37175ce4
DG
1135function enable_jul_lttng_event()
1136{
1137 sess_name=$1
1138 event_name="$2"
1139 channel_name=$3
1140
1141 if [ -z $channel_name ]; then
1142 # default channel if none specified
1143 chan=""
1144 else
1145 chan="-c $channel_name"
1146 fi
1147
2cf48300 1148 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
37175ce4
DG
1149 ok $? "Enable JUL event $event_name for session $sess_name"
1150}
1151
b2064f54
DG
1152function enable_jul_lttng_event_loglevel()
1153{
7d0ad314
JRJ
1154 local sess_name=$1
1155 local event_name="$2"
1156 local loglevel=$3
1157 local channel_name=$4
b2064f54
DG
1158
1159 if [ -z $channel_name ]; then
1160 # default channel if none specified
1161 chan=""
1162 else
1163 chan="-c $channel_name"
1164 fi
1165
2cf48300 1166 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
b2064f54
DG
1167 ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
1168}
1169
504d4ace
DG
1170function enable_log4j_lttng_event()
1171{
1172 sess_name=$1
1173 event_name="$2"
1174 channel_name=$3
1175
1176 if [ -z $channel_name ]; then
1177 # default channel if none specified
1178 chan=""
1179 else
1180 chan="-c $channel_name"
1181 fi
1182
2cf48300 1183 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
504d4ace
DG
1184 ok $? "Enable LOG4J event $event_name for session $sess_name"
1185}
1186
1187function enable_log4j_lttng_event_loglevel()
1188{
1189 local sess_name=$1
1190 local event_name="$2"
1191 local loglevel=$3
1192 local channel_name=$4
1193
1194 if [ -z $channel_name ]; then
1195 # default channel if none specified
1196 chan=""
1197 else
1198 chan="-c $channel_name"
1199 fi
1200
2cf48300 1201 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
504d4ace
DG
1202 ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
1203}
1204
0e115563
DG
1205function enable_python_lttng_event()
1206{
1207 sess_name=$1
1208 event_name="$2"
1209 channel_name=$3
1210
1211 if [ -z $channel_name ]; then
1212 # default channel if none specified
1213 chan=""
1214 else
1215 chan="-c $channel_name"
1216 fi
1217
2cf48300 1218 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
0e115563
DG
1219 ok $? "Enable Python event $event_name for session $sess_name"
1220}
1221
1222function enable_python_lttng_event_loglevel()
1223{
1224 local sess_name=$1
1225 local event_name="$2"
1226 local loglevel=$3
1227 local channel_name=$4
1228
1229 if [ -z $channel_name ]; then
1230 # default channel if none specified
1231 chan=""
1232 else
1233 chan="-c $channel_name"
1234 fi
1235
2cf48300 1236 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
0e115563
DG
1237 ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel"
1238}
1239
26b53d3b
DG
1240function enable_ust_lttng_event_filter()
1241{
7d0ad314
JRJ
1242 local sess_name="$1"
1243 local event_name="$2"
1244 local filter="$3"
bc3c79ae
JG
1245 local channel_name=$4
1246
1247 if [ -z $channel_name ]; then
1248 # default channel if none specified
1249 chan=""
1250 else
1251 chan="-c $channel_name"
1252 fi
26b53d3b 1253
bc3c79ae 1254 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $chan "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 1255 ok $? "Enable event $event_name with filtering for session $sess_name"
26b53d3b
DG
1256}
1257
1258function enable_ust_lttng_event_loglevel()
1259{
7d0ad314
JRJ
1260 local sess_name="$1"
1261 local event_name="$2"
1262 local loglevel="$3"
26b53d3b 1263
2cf48300 1264 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 1265 ok $? "Enable event $event_name with loglevel $loglevel"
26b53d3b
DG
1266}
1267
1268function enable_ust_lttng_event_loglevel_only()
1269{
7d0ad314
JRJ
1270 local sess_name="$1"
1271 local event_name="$2"
1272 local loglevel="$3"
26b53d3b 1273
2cf48300 1274 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 1275 ok $? "Enable event $event_name with loglevel-only $loglevel"
26b53d3b
DG
1276}
1277
1278function disable_ust_lttng_event ()
1279{
7d0ad314
JRJ
1280 local sess_name="$1"
1281 local event_name="$2"
01513c3e 1282 local channel_name="$3"
26b53d3b 1283
01513c3e
JRJ
1284 if [ -z $channel_name ]; then
1285 # default channel if none specified
1286 chan=""
1287 else
1288 chan="-c $channel_name"
1289 fi
1290
2cf48300 1291 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 1292 ok $? "Disable event $event_name for session $sess_name"
d3e8f6bb
DG
1293}
1294
1d842d5a
DG
1295function disable_jul_lttng_event ()
1296{
1297 local sess_name="$1"
1298 local event_name="$2"
1299
1300 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1
1301 ok $? "Disable JUL event $event_name for session $sess_name"
1302}
1303
504d4ace
DG
1304function disable_log4j_lttng_event ()
1305{
1306 local sess_name="$1"
1307 local event_name="$2"
1308
1309 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1
1310 ok $? "Disable LOG4J event $event_name for session $sess_name"
1311}
1312
0e115563
DG
1313function disable_python_lttng_event ()
1314{
1315 local sess_name="$1"
1316 local event_name="$2"
1317
2cf48300 1318 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
0e115563
DG
1319 ok $? "Disable Python event $event_name for session $sess_name"
1320}
1321
7fe98a98 1322function start_lttng_tracing_opt ()
d3e8f6bb 1323{
7fe98a98
JG
1324 local withtap=$1
1325 local expected_to_fail=$2
1326 local sess_name=$3
d3e8f6bb 1327
2cf48300 1328 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1329 ret=$?
e563bbdb 1330 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1331 test "$ret" -ne "0"
7fe98a98
JG
1332 ret=$?
1333 if [ $withtap -eq "1" ]; then
1334 ok $? "Start tracing for session $sess_name failed as expected"
1335 fi
01513c3e 1336 else
7fe98a98
JG
1337 if [ $withtap -eq "1" ]; then
1338 ok $ret "Start tracing for session $sess_name"
1339 fi
01513c3e 1340 fi
d3e8f6bb
DG
1341}
1342
e563bbdb
JR
1343function start_lttng_tracing_ok ()
1344{
7fe98a98 1345 start_lttng_tracing_opt 1 0 "$@"
e563bbdb
JR
1346}
1347
1348function start_lttng_tracing_fail ()
1349{
7fe98a98 1350 start_lttng_tracing_opt 1 1 "$@"
e563bbdb
JR
1351}
1352
7fe98a98 1353function start_lttng_tracing_notap ()
d3e8f6bb 1354{
7fe98a98
JG
1355 start_lttng_tracing_opt 0 1 "$@"
1356}
1357
1358function stop_lttng_tracing_opt ()
1359{
1360 local withtap=$1
1361 local expected_to_fail=$2
1362 local sess_name=$3
d3e8f6bb 1363
2cf48300 1364 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1365 ret=$?
96340a01 1366 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1367 test "$ret" -ne "0"
7fe98a98
JG
1368 ret=$?
1369 if [ $withtap -eq "1" ]; then
1370 ok $? "Stop lttng tracing for session $sess_name failed as expected"
1371 fi
01513c3e 1372 else
7fe98a98
JG
1373 if [ $withtap -eq "1" ]; then
1374 ok $ret "Stop lttng tracing for session $sess_name"
1375 fi
01513c3e 1376 fi
d3e8f6bb
DG
1377}
1378
96340a01
JR
1379function stop_lttng_tracing_ok ()
1380{
7fe98a98 1381 stop_lttng_tracing_opt 1 0 "$@"
96340a01
JR
1382}
1383
1384function stop_lttng_tracing_fail ()
1385{
7fe98a98
JG
1386 stop_lttng_tracing_opt 1 1 "$@"
1387}
1388
1389function stop_lttng_tracing_notap ()
1390{
1391 stop_lttng_tracing_opt 0 0 "$@"
96340a01
JR
1392}
1393
d3e8f6bb
DG
1394function destroy_lttng_session ()
1395{
854382b8
JR
1396 local withtap=$1
1397 local expected_to_fail=$2
1398 local sess_name=$3
d3e8f6bb 1399
2cf48300 1400 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1401 ret=$?
96340a01 1402 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1403 test "$ret" -ne "0"
854382b8
JR
1404 ret=$?
1405 if [ $withtap -eq "1" ]; then
1406 ok $ret "Destroy session $sess_name failed as expected"
1407 fi
01513c3e 1408 else
854382b8
JR
1409 if [ $withtap -eq "1" ]; then
1410 ok $ret "Destroy session $sess_name"
1411 fi
01513c3e 1412 fi
d3e8f6bb
DG
1413}
1414
67b4c664
JR
1415function destroy_lttng_session_ok ()
1416{
854382b8 1417 destroy_lttng_session 1 0 "$@"
67b4c664
JR
1418
1419}
1420
1421function destroy_lttng_session_fail ()
1422{
854382b8 1423 destroy_lttng_session 1 1 "$@"
67b4c664
JR
1424}
1425
854382b8
JR
1426function destroy_lttng_session_notap ()
1427{
1428 destroy_lttng_session 0 0 "$@"
1429}
67b4c664 1430
873c2aae
JRJ
1431function destroy_lttng_sessions ()
1432{
2cf48300 1433 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
873c2aae
JRJ
1434 ok $? "Destroy all lttng sessions"
1435}
1436
07b86b52
JD
1437function lttng_snapshot_add_output ()
1438{
b5633831
JR
1439 local expected_to_fail=$1
1440 local sess_name=$2
1441 local trace_path=$3
9f0e230a 1442 local opts=$4
07b86b52 1443
9f0e230a 1444 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name $trace_path $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1445 ret=$?
b5633831 1446 if [[ $expected_to_fail -eq 1 ]]; then
01513c3e 1447 test "$ret" -ne "0"
9f0e230a 1448 ok $? "Added snapshot output $trace_path failed as expected"
01513c3e 1449 else
9f0e230a 1450 ok $ret "Added snapshot output $trace_path"
01513c3e 1451 fi
07b86b52
JD
1452}
1453
b5633831
JR
1454function lttng_snapshot_add_output_ok ()
1455{
1456 lttng_snapshot_add_output 0 "$@"
1457}
1458
1459function lttng_snapshot_add_output_fail ()
1460{
1461 lttng_snapshot_add_output 1 "$@"
1462}
1463
26402e0c
DG
1464function lttng_snapshot_del_output ()
1465{
31580dc7
JR
1466 local expected_to_fail=$1
1467 local sess_name=$2
1468 local id=$3
26402e0c 1469
2cf48300 1470 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1471 ret=$?
31580dc7 1472 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1473 test "$ret" -ne "0"
34ab15c5 1474 ok $? "Deleted snapshot output id $id failed as expected"
01513c3e
JRJ
1475 else
1476 ok $ret "Deleted snapshot output id $id"
1477 fi
26402e0c
DG
1478}
1479
31580dc7
JR
1480function lttng_snapshot_del_output_ok ()
1481{
1482 lttng_snapshot_del_output 0 "$@"
1483}
1484
1485function lttng_snapshot_del_output_fail ()
1486{
1487 lttng_snapshot_del_output 1 "$@"
1488}
1489
07b86b52
JD
1490function lttng_snapshot_record ()
1491{
7d0ad314 1492 local sess_name=$1
07b86b52 1493
2a166864 1494 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name $trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
07b86b52
JD
1495 ok $? "Snapshot recorded"
1496}
1497
01513c3e
JRJ
1498function lttng_snapshot_list ()
1499{
1500 local sess_name=$1
2cf48300 1501 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e
JRJ
1502 ok $? "Snapshot list"
1503}
1504
e02b109b
DG
1505function lttng_save()
1506{
1507 local sess_name=$1
1508 local opts=$2
1509
2cf48300 1510 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
34ab15c5 1511 ok $? "Session saved"
e02b109b
DG
1512}
1513
1514function lttng_load()
1515{
192ac418
JR
1516 local expected_to_fail=$1
1517 local opts=$2
e02b109b 1518
2cf48300 1519 $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
192ac418
JR
1520 ret=$?
1521 if [[ $expected_to_fail -eq "1" ]]; then
1522 test $ret -ne "0"
1523 ok $? "Load command failed as expected with opts: $opts"
1524 else
1525 ok $ret "Load command with opts: $opts"
1526 fi
1527}
1528
1529function lttng_load_ok()
1530{
1531 lttng_load 0 "$@"
1532}
1533
1534function lttng_load_fail()
1535{
1536 lttng_load 1 "$@"
e02b109b
DG
1537}
1538
e83a8bdb
JR
1539function lttng_track()
1540{
ba5e8d0a 1541 local expected_to_fail="$1"
c47a705b 1542 shift 1
ba5e8d0a 1543 local opts="$@"
e83a8bdb
JR
1544 $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST
1545 ret=$?
1546 if [[ $expected_to_fail -eq "1" ]]; then
1547 test $ret -ne "0"
1548 ok $? "Track command failed as expected with opts: $opts"
1549 else
34ab15c5 1550 ok $ret "Track command with opts: $opts"
e83a8bdb
JR
1551 fi
1552}
1553
1554function lttng_track_ok()
1555{
1556 lttng_track 0 "$@"
1557}
1558
1559function lttng_track_fail()
1560{
1561 lttng_track 1 "$@"
1562}
1563
1564function lttng_untrack()
1565{
ba5e8d0a 1566 local expected_to_fail="$1"
c47a705b 1567 shift 1
ba5e8d0a 1568 local opts="$@"
e83a8bdb
JR
1569 $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST
1570 ret=$?
1571 if [[ $expected_to_fail -eq "1" ]]; then
1572 test $ret -ne "0"
1573 ok $? "Untrack command failed as expected with opts: $opts"
1574 else
34ab15c5 1575 ok $ret "Untrack command with opts: $opts"
e83a8bdb
JR
1576 fi
1577}
1578
1579function lttng_untrack_ok()
1580{
1581 lttng_untrack 0 "$@"
1582}
1583
1584function lttng_untrack_fail()
1585{
1586 lttng_untrack 1 "$@"
1587}
1588
c8e51d15
FD
1589function lttng_track_pid_ok()
1590{
1591 PID=$1
1592 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track --kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1593 ok $? "Lttng track pid on the kernel domain"
1594}
1595
1596function lttng_untrack_kernel_all_ok()
1597{
1598 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack --kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1599 ok $? "Lttng untrack all pid on the kernel domain"
1600}
1601
ba5e8d0a
MD
1602function lttng_track_ust_ok()
1603{
1604 lttng_track_ok -u "$@"
1605}
1606
1607function lttng_track_ust_fail()
1608{
1609 lttng_track_fail -u "$@"
1610}
1611
1612function lttng_track_kernel_ok()
1613{
1614 lttng_track_ok -k "$@"
1615}
1616
1617function lttng_track_kernel_fail()
1618{
1619 lttng_track_fail -k "$@"
1620}
1621
1622function lttng_untrack_ust_ok()
1623{
1624 lttng_untrack_ok -u "$@"
1625}
1626
1627function lttng_untrack_ust_fail()
1628{
1629 lttng_untrack_fail -u "$@"
1630}
1631
1632function lttng_untrack_kernel_ok()
1633{
1634 lttng_untrack_ok -k "$@"
1635}
1636
1637function lttng_untrack_kernel_fail()
1638{
1639 lttng_untrack_fail -k "$@"
1640}
1641
59deec0c
JR
1642function lttng_add_context_list()
1643{
1644 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context --list 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1645 ret=$?
1646 ok $ret "Context listing"
1647}
1648
8dcef147
JR
1649function add_context_lttng()
1650{
1651 local expected_to_fail="$1"
1652 local domain="$2"
1653 local session_name="$3"
1654 local channel_name="$4"
1655 local type="$5"
1656
1657 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context -s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1658 ret=$?
1659 if [[ $expected_to_fail -eq "1" ]]; then
1660 test $ret -ne "0"
1661 ok $? "Add context command failed as expected for type: $type"
1662 else
1663 ok $ret "Add context command for type: $type"
1664 fi
1665}
1666
1667function add_context_ust_ok()
1668{
1669 add_context_lttng 0 -u "$@"
1670}
1671
1672function add_context_ust_fail()
1673{
1674 add_context_lttng 1 -u "$@"
1675}
1676
1677function add_context_kernel_ok()
1678{
1679 add_context_lttng 0 -k "$@"
1680}
1681
1682function add_context_kernel_fail()
1683{
1684 add_context_lttng 1 -k "$@"
1685}
1686
c28fcefd
JR
1687function wait_live_trace_ready ()
1688{
1689 local url=$1
1690 local zero_client_match=0
1691
1692 diag "Waiting for live trace at url: $url"
1693 while [ $zero_client_match -eq 0 ]; do
1694 zero_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "0 client(s) connected" | wc -l)
1695 sleep 0.5
1696 done
1697 pass "Waiting for live trace at url: $url"
1698}
1699
1700function wait_live_viewer_connect ()
1701{
1702 local url=$1
1703 local one_client_match=0
1704
1705 diag "Waiting for live viewers on url: $url"
1706 while [ $one_client_match -eq 0 ]; do
1707 one_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "1 client(s) connected" | wc -l)
1708 sleep 0.5
1709 done
1710 pass "Waiting for live viewers on url: $url"
1711}
1712
c54b437e
FD
1713function validate_metadata_event ()
1714{
1715 local event_name=$1
1716 local nr_event_id=$2
1717 local trace_path=$3
1718
1719 local metadata_file=$(find $trace_path | grep metadata)
1720 local metadata_path=$(dirname $metadata_file)
1721
1722 which $BABELTRACE_BIN >/dev/null
1723 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1724
1725 local count=$($BABELTRACE_BIN --output-format=ctf-metadata $metadata_path | grep $event_name | wc -l)
1726
1727 if [ "$count" -ne "$nr_event_id" ]; then
1728 fail "Metadata match with the metadata of $count event(s) named $event_name"
1729 diag "$count matching event id found in metadata"
1730 else
1731 pass "Metadata match with the metadata of $count event(s) named $event_name"
1732 fi
1733
1734}
1735
d3e8f6bb
DG
1736function trace_matches ()
1737{
7d0ad314
JRJ
1738 local event_name=$1
1739 local nr_iter=$2
1740 local trace_path=$3
d3e8f6bb 1741
317eef93 1742 which $BABELTRACE_BIN >/dev/null
29655db7 1743 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
d3e8f6bb 1744
7d0ad314 1745 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
29655db7 1746
d3e8f6bb 1747 if [ "$count" -ne "$nr_iter" ]; then
29655db7 1748 fail "Trace match"
af91abc9 1749 diag "$count matching events found in trace"
d3e8f6bb 1750 else
29655db7 1751 pass "Trace match"
d3e8f6bb
DG
1752 fi
1753}
f4e40ab6 1754
d53addeb
DG
1755function trace_match_only()
1756{
1757 local event_name=$1
1758 local nr_iter=$2
1759 local trace_path=$3
1760
1761 which $BABELTRACE_BIN >/dev/null
1762 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1763
1764 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
1765 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1766
08f96a38
JG
1767 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1768 pass "Trace match with $total event $event_name"
1769 else
1770 fail "Trace match"
1771 diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1772 fi
d53addeb
DG
1773}
1774
f4e40ab6
DG
1775function validate_trace
1776{
7d0ad314
JRJ
1777 local event_name=$1
1778 local trace_path=$2
f4e40ab6
DG
1779
1780 which $BABELTRACE_BIN >/dev/null
29655db7
CB
1781 if [ $? -ne 0 ]; then
1782 skip 0 "Babeltrace binary not found. Skipping trace validation"
f4e40ab6
DG
1783 fi
1784
07b86b52
JD
1785 OLDIFS=$IFS
1786 IFS=","
1787 for i in $event_name; do
1788 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1789 if [ "$traced" -ne 0 ]; then
ebaaaf5e 1790 pass "Validate trace for event $i, $traced events"
07b86b52
JD
1791 else
1792 fail "Validate trace for event $i"
1793 diag "Found $traced occurences of $i"
1794 fi
1795 done
1796 ret=$?
1797 IFS=$OLDIFS
1798 return $ret
f4e40ab6 1799}
8cfcd41c 1800
54cd6107
JD
1801function validate_trace_count
1802{
1803 local event_name=$1
1804 local trace_path=$2
1805 local expected_count=$3
1806
1807 which $BABELTRACE_BIN >/dev/null
1808 if [ $? -ne 0 ]; then
1809 skip 0 "Babeltrace binary not found. Skipping trace validation"
1810 fi
1811
1812 cnt=0
1813 OLDIFS=$IFS
1814 IFS=","
1815 for i in $event_name; do
1816 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1817 if [ "$traced" -ne 0 ]; then
1818 pass "Validate trace for event $i, $traced events"
1819 else
1820 fail "Validate trace for event $i"
1821 diag "Found $traced occurences of $i"
1822 fi
1823 cnt=$(($cnt + $traced))
1824 done
1825 IFS=$OLDIFS
1826 test $cnt -eq $expected_count
1827 ok $? "Read a total of $cnt events, expected $expected_count"
1828}
1829
c28fcefd
JR
1830function validate_trace_count_range_incl_min_excl_max
1831{
1832 local event_name=$1
1833 local trace_path=$2
1834 local expected_min=$3
1835 local expected_max=$4
1836
1837 which $BABELTRACE_BIN >/dev/null
1838 if [ $? -ne 0 ]; then
1839 skip 0 "Babeltrace binary not found. Skipping trace validation"
1840 fi
1841
1842 cnt=0
1843 OLDIFS=$IFS
1844 IFS=","
1845 for i in $event_name; do
1846 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1847 if [ "$traced" -ge $expected_min ]; then
1848 pass "Validate trace for event $i, $traced events"
1849 else
1850 fail "Validate trace for event $i"
1851 diag "Found $traced occurences of $i"
1852 fi
1853 cnt=$(($cnt + $traced))
1854 done
1855 IFS=$OLDIFS
1856 test $cnt -lt $expected_max
1857 ok $? "Read a total of $cnt events, expected between [$expected_min, $expected_max["
1858}
1859
086e6add
MD
1860function trace_first_line
1861{
1862 local trace_path=$1
1863
1864 which $BABELTRACE_BIN >/dev/null
1865 if [ $? -ne 0 ]; then
1866 skip 0 "Babeltrace binary not found. Skipping trace validation"
1867 fi
1868
1869 $BABELTRACE_BIN $trace_path 2>/dev/null | head -n 1
1870}
1871
8cfcd41c
MD
1872function validate_trace_exp()
1873{
1874 local event_exp=$1
1875 local trace_path=$2
1876
1877 which $BABELTRACE_BIN >/dev/null
1878 skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
1879
49538c32 1880 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep --extended-regexp ${event_exp} | wc -l)
8cfcd41c
MD
1881 if [ "$traced" -ne 0 ]; then
1882 pass "Validate trace for expression '${event_exp}', $traced events"
1883 else
1884 fail "Validate trace for expression '${event_exp}'"
1885 diag "Found $traced occurences of '${event_exp}'"
1886 fi
1887 ret=$?
1888 return $ret
1889}
1890
1891function validate_trace_only_exp()
1892{
1893 local event_exp=$1
1894 local trace_path=$2
1895
1896 which $BABELTRACE_BIN >/dev/null
1897 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1898
49538c32 1899 local count=$($BABELTRACE_BIN $trace_path | grep --extended-regexp ${event_exp} | wc -l)
8cfcd41c
MD
1900 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1901
1902 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
ab95d85d 1903 pass "Trace match with $total for expression '${event_exp}'"
8cfcd41c
MD
1904 else
1905 fail "Trace match"
1906 diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1907 fi
1908 ret=$?
1909 return $ret
1910}
1911
1912function validate_trace_empty()
1913{
1914 local trace_path=$1
1915
1916 which $BABELTRACE_BIN >/dev/null
1917 if [ $? -ne 0 ]; then
1918 skip 0 "Babeltrace binary not found. Skipping trace validation"
1919 fi
1920
2462eee7
JD
1921 events=$($BABELTRACE_BIN $trace_path 2>/dev/null)
1922 ret=$?
1923 if [ $ret -ne 0 ]; then
1924 fail "Failed to parse trace"
1925 return $ret
1926 fi
1927
1928 traced=$(echo -n "$events" | wc -l)
8cfcd41c
MD
1929 if [ "$traced" -eq 0 ]; then
1930 pass "Validate empty trace"
1931 else
1932 fail "Validate empty trace"
1933 diag "Found $traced events in trace"
1934 fi
1935 ret=$?
1936 return $ret
1937}
801236b0 1938
94360c17 1939function validate_directory_empty ()
ba5e8d0a 1940{
94360c17
FD
1941 local trace_path="$1"
1942
c8e000ef
FD
1943 # Do not double quote `$trace_path` below as we want wildcards to be
1944 # expanded.
1945 files="$(ls -A $trace_path)"
94360c17
FD
1946 ret=$?
1947 if [ $ret -ne 0 ]; then
1948 fail "Failed to list content of directory \"$trace_path\""
1949 return $ret
1950 fi
ba5e8d0a 1951
94360c17
FD
1952 nb_files="$(echo -n "$files" | wc -l)"
1953 ok $nb_files "Directory \"$trace_path\" is empty"
ba5e8d0a
MD
1954}
1955
1956function validate_trace_session_ust_empty()
1957{
94360c17 1958 validate_directory_empty "$1"/ust
ba5e8d0a
MD
1959}
1960
1961function validate_trace_session_kernel_empty()
1962{
1963 validate_trace_empty "$1"/kernel
1964}
1965
eded6438 1966function regenerate_metadata ()
801236b0
JD
1967{
1968 local expected_to_fail=$1
1969 local sess_name=$2
1970
eded6438 1971 $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate metadata -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
801236b0
JD
1972 ret=$?
1973 if [[ $expected_to_fail -eq "1" ]]; then
1974 test "$ret" -ne "0"
eded6438 1975 ok $? "Expected fail on regenerate metadata $sess_name"
801236b0
JD
1976 else
1977 ok $ret "Metadata regenerate $sess_name"
1978 fi
1979}
1980
eded6438 1981function regenerate_metadata_ok ()
801236b0 1982{
eded6438 1983 regenerate_metadata 0 "$@"
801236b0
JD
1984}
1985
eded6438 1986function regenerate_metadata_fail ()
801236b0 1987{
eded6438 1988 regenerate_metadata 1 "$@"
801236b0 1989}
512eb148 1990
54cd6107
JD
1991function regenerate_statedump ()
1992{
1993 local expected_to_fail=$1
1994 local sess_name=$2
1995
1996 $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate statedump -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1997 ret=$?
1998 if [[ $expected_to_fail -eq "1" ]]; then
1999 test "$ret" -ne "0"
2000 ok $? "Expected fail on regenerate statedump $sess_name"
2001 else
5ebb1a9f 2002 ok $ret "Statedump regenerate $sess_name"
54cd6107
JD
2003 fi
2004}
2005
2006function regenerate_statedump_ok ()
2007{
2008 regenerate_statedump 0 "$@"
2009}
2010
2011function regenerate_statedump_fail ()
2012{
2013 regenerate_statedump 1 "$@"
2014}
2015
e7716c6a
JD
2016function rotate_session ()
2017{
2018 local expected_to_fail=$1
2019 local sess_name=$2
2020
2021 $TESTDIR/../src/bin/lttng/$LTTNG_BIN rotate $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2022 ret=$?
2023 if [[ $expected_to_fail -eq "1" ]]; then
2024 test "$ret" -ne "0"
2025 ok $? "Expected fail on rotate session $sess_name"
2026 else
2027 ok $ret "Rotate session $sess_name"
2028 fi
2029}
2030
2031function rotate_session_ok ()
2032{
2033 rotate_session 0 "$@"
2034}
2035
2036function rotate_session_fail ()
2037{
2038 rotate_session 1 "$@"
2039}
2040
512eb148
JD
2041function destructive_tests_enabled ()
2042{
2043 if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then
2044 return 0
2045 else
2046 return 1
2047 fi
2048}
e7716c6a
JD
2049
2050function lttng_enable_rotation_timer ()
2051{
2052 local expected_to_fail=$1
2053 local sess_name=$2
2054 local period=$3
2055
2056 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --timer $period 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2057 ret=$?
2058 if [[ $expected_to_fail -eq "1" ]]; then
2059 test "$ret" -ne "0"
9498e289 2060 ok $? "Expected fail when setting periodic rotation ($period) of session $sess_name"
e7716c6a 2061 else
795f9063 2062 ok $ret "Set periodic rotation ($period) of session $sess_name"
e7716c6a
JD
2063 fi
2064}
2065
2066function lttng_enable_rotation_timer_ok ()
2067{
2068 lttng_enable_rotation_timer 0 $@
2069}
2070
2071function lttng_enable_rotation_timer_fail ()
2072{
2073 lttng_enable_rotation_timer 1 $@
2074}
2075
2076function lttng_enable_rotation_size ()
2077{
2078 local expected_to_fail=$1
2079 local sess_name=$2
2080 local size=$3
2081
2082 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --size $size 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2083 ret=$?
2084 if [[ $expected_to_fail -eq "1" ]]; then
2085 test "$ret" -ne "0"
2086 ok $? "Expected fail on rotate session $sess_name"
2087 else
2088 ok $ret "Rotate session $sess_name"
2089 fi
2090}
2091
2092function lttng_enable_rotation_size_ok ()
2093{
2094 lttng_enable_rotation_size 0 $@
2095}
2096
2097function lttng_enable_rotation_size_fail ()
2098{
2099 lttng_enable_rotation_size 1 $@
2100}
c28fcefd
JR
2101
2102function lttng_clear_session ()
2103{
2104 local expected_to_fail=$1
2105 local sess_name=$2
2106
2107 $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2108 ret=$?
2109 if [[ $expected_to_fail -eq "1" ]]; then
2110 test "$ret" -ne "0"
2111 ok $? "Expected fail on clear session $sess_name"
2112 else
2113 ok $ret "Clear session $sess_name"
2114 fi
2115}
2116
2117function lttng_clear_session_ok ()
2118{
2119 lttng_clear_session 0 $@
2120}
2121
2122function lttng_clear_session_fail ()
2123{
2124 lttng_clear_session 1 $@
2125}
5ee26199
JR
2126
2127function lttng_clear_all ()
2128{
2129 $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2130 ok $? "Clear all lttng sessions"
2131}
70c766ac
FD
2132
2133function lttng_add_trigger()
2134{
2135 local expected_to_fail="$1"
2136 local trigger_name="$2"
2137 shift 2
2138
2139 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-trigger --id "$trigger_name" "$@" 1> /dev/null 2> /dev/null
2140 ret=$?
2141 if [[ $expected_to_fail -eq "1" ]]; then
2142 test "$ret" -ne "0"
2143 ok $? "Add trigger $trigger_name failed as expected"
2144 else
2145 ok $ret "Add trigger $trigger_name"
2146 fi
2147}
2148
2149function lttng_remove_trigger()
2150{
2151 local expected_to_fail="$1"
2152 local trigger_name="$2"
2153
2154 $TESTDIR/../src/bin/lttng/$LTTNG_BIN remove-trigger "$trigger_name" 1> /dev/null 2> /dev/null
2155 ret=$?
2156 if [[ $expected_to_fail -eq "1" ]]; then
2157 test "$ret" -ne "0"
2158 ok $? "Remove trigger $trigger_name failed as expected"
2159 else
2160 ok $ret "Remove trigger $trigger_name"
2161 fi
2162}
2163
2164function lttng_add_trigger_ok()
2165{
2166 lttng_add_trigger 0 "$@"
2167}
2168
38eb8a68
FD
2169function lttng_add_trigger_fail()
2170{
2171 lttng_add_trigger 1 "$@"
2172}
2173
70c766ac
FD
2174function lttng_remove_trigger_ok()
2175{
2176 lttng_remove_trigger 0 "$@"
2177}
This page took 0.257978 seconds and 4 git commands to generate.