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