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