tests: test uid/gid/pid/vuid/vgid/vpid trackers
[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 opts="${@:5}"
335
336 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name $opts 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 process_mode=$2
401 local opt=$3
402
403 DIR=$(readlink -f "$TESTDIR")
404
405 if [ -z $(pgrep $RELAYD_MATCH) ]; then
406 # shellcheck disable=SC2086
407 $DIR/../src/bin/lttng-relayd/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
408 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
409 if [ $? -eq 1 ]; then
410 if [ $withtap -eq "1" ]; then
411 fail "Start lttng-relayd (process mode: $process_mode opt: $opt)"
412 fi
413 return 1
414 else
415 if [ $withtap -eq "1" ]; then
416 pass "Start lttng-relayd (process mode: $process_mode opt: $opt)"
417 fi
418 fi
419 else
420 pass "Start lttng-relayd (opt: $opt)"
421 fi
422 }
423
424 function start_lttng_relayd()
425 {
426 start_lttng_relayd_opt 1 "-b" "$@"
427 }
428
429 function start_lttng_relayd_notap()
430 {
431 start_lttng_relayd_opt 0 "-b" "$@"
432 }
433
434 function stop_lttng_relayd_opt()
435 {
436 local withtap=$1
437 local signal=$2
438
439 if [ -z "$signal" ]; then
440 signal="SIGTERM"
441 fi
442
443 local timeout_s=$3
444 local dtimeleft_s=
445
446 # Multiply time by 2 to simplify integer arithmetic
447 if [ -n "$timeout_s" ]; then
448 dtimeleft_s=$((timeout_s * 2))
449 fi
450
451 local retval=0
452 local pids=
453
454 pids=$(pgrep "$RELAYD_MATCH")
455 if [ -z "$pids" ]; then
456 if [ "$withtap" -eq "1" ]; then
457 pass "No relay daemon to kill"
458 fi
459 return 0
460 fi
461
462 diag "Killing (signal $signal) lttng-relayd (pid: $pids)"
463
464 # shellcheck disable=SC2086
465 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
466 retval=1
467 if [ "$withtap" -eq "1" ]; then
468 fail "Kill relay daemon"
469 fi
470 else
471 out=1
472 while [ -n "$out" ]; do
473 out=$(pgrep "$RELAYD_MATCH")
474 if [ -n "$dtimeleft_s" ]; then
475 if [ $dtimeleft_s -lt 0 ]; then
476 out=
477 retval=1
478 fi
479 dtimeleft_s=$((dtimeleft_s - 1))
480 fi
481 sleep 0.5
482 done
483 if [ "$withtap" -eq "1" ]; then
484 if [ "$retval" -eq "0" ]; then
485 pass "Wait after kill relay daemon"
486 else
487 fail "Wait after kill relay daemon"
488 fi
489 fi
490 fi
491 return $retval
492 }
493
494 function stop_lttng_relayd()
495 {
496 stop_lttng_relayd_opt 1 "$@"
497 }
498
499 function stop_lttng_relayd_notap()
500 {
501 stop_lttng_relayd_opt 0 "$@"
502 }
503
504 #First arg: show tap output
505 #Second argument: load path for automatic loading
506 function start_lttng_sessiond_opt()
507 {
508 local withtap=$1
509 local load_path=$2
510
511 local env_vars=""
512 local consumerd=""
513
514 local long_bit_value=
515 long_bit_value=$(getconf LONG_BIT)
516
517 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
518 # Env variable requested no session daemon
519 return
520 fi
521
522 DIR=$(readlink -f "$TESTDIR")
523
524 # Get long_bit value for 32/64 consumerd
525 case "$long_bit_value" in
526 32)
527 consumerd="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
528 ;;
529 64)
530 consumerd="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
531 ;;
532 *)
533 return
534 ;;
535 esac
536
537 # Check for env. variable. Allow the use of LD_PRELOAD etc.
538 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
539 env_vars="${LTTNG_SESSIOND_ENV_VARS} "
540 fi
541 env_vars="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN"
542
543 if ! validate_kernel_version; then
544 fail "Start session daemon"
545 BAIL_OUT "*** Kernel too old for session daemon tests ***"
546 fi
547
548 : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}"
549 export LTTNG_SESSION_CONFIG_XSD_PATH
550
551 if [ -z "$(pgrep "${SESSIOND_MATCH}")" ]; then
552 # Have a load path ?
553 if [ -n "$load_path" ]; then
554 # shellcheck disable=SC2086
555 env $env_vars --load "$load_path" --background "$consumerd"
556 else
557 # shellcheck disable=SC2086
558 env $env_vars --background "$consumerd"
559 fi
560 #$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
561 status=$?
562 if [ "$withtap" -eq "1" ]; then
563 ok $status "Start session daemon"
564 fi
565 fi
566 }
567
568 function start_lttng_sessiond()
569 {
570 start_lttng_sessiond_opt 1 "$@"
571 }
572
573 function start_lttng_sessiond_notap()
574 {
575 start_lttng_sessiond_opt 0 "$@"
576 }
577
578 function stop_lttng_sessiond_opt()
579 {
580 local withtap=$1
581 local signal=$2
582
583 if [ -z "$signal" ]; then
584 signal=SIGTERM
585 fi
586
587 local timeout_s=$3
588 local dtimeleft_s=
589
590 # Multiply time by 2 to simplify integer arithmetic
591 if [ -n "$timeout_s" ]; then
592 dtimeleft_s=$((timeout_s * 2))
593 fi
594
595 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
596 # Env variable requested no session daemon
597 return 0
598 fi
599
600 local retval=0
601
602 local runas_pids=
603 runas_pids=$(pgrep "$RUNAS_MATCH")
604
605 local pids=
606 pids=$(pgrep "$SESSIOND_MATCH")
607
608 if [ -n "$runas_pids" ]; then
609 pids="$pids $runas_pids"
610 fi
611
612 if [ -z "$pids" ]; then
613 if [ "$withtap" -eq "1" ]; then
614 pass "No session daemon to kill"
615 fi
616 return 0
617 fi
618
619 diag "Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')"
620
621 # shellcheck disable=SC2086
622 if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
623 retval=1
624 if [ "$withtap" -eq "1" ]; then
625 fail "Kill sessions daemon"
626 fi
627 else
628 out=1
629 while [ -n "$out" ]; do
630 out=$(pgrep "${SESSIOND_MATCH}")
631 if [ -n "$dtimeleft_s" ]; then
632 if [ $dtimeleft_s -lt 0 ]; then
633 out=
634 retval=1
635 fi
636 dtimeleft_s=$((dtimeleft_s - 1))
637 fi
638 sleep 0.5
639 done
640 out=1
641 while [ -n "$out" ]; do
642 out=$(pgrep "$CONSUMERD_MATCH")
643 if [ -n "$dtimeleft_s" ]; then
644 if [ $dtimeleft_s -lt 0 ]; then
645 out=
646 retval=1
647 fi
648 dtimeleft_s=$((dtimeleft_s - 1))
649 fi
650 sleep 0.5
651 done
652
653 if [ "$withtap" -eq "1" ]; then
654 if [ "$retval" -eq "0" ]; then
655 pass "Wait after kill session daemon"
656 else
657 fail "Wait after kill session daemon"
658 fi
659 fi
660 fi
661 if [ "$signal" = "SIGKILL" ]; then
662 if [ "$(id -u)" -eq "0" ]; then
663 local modules=
664 modules="$(lsmod | grep ^lttng | awk '{print $1}')"
665
666 if [ -n "$modules" ]; then
667 diag "Unloading all LTTng modules"
668 modprobe -r "$modules"
669 fi
670 fi
671 fi
672
673 return $retval
674 }
675
676 function stop_lttng_sessiond()
677 {
678 stop_lttng_sessiond_opt 1 "$@"
679 }
680
681 function stop_lttng_sessiond_notap()
682 {
683 stop_lttng_sessiond_opt 0 "$@"
684 }
685
686 function sigstop_lttng_sessiond_opt()
687 {
688 local withtap=$1
689 local signal=SIGSTOP
690
691 if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
692 # Env variable requested no session daemon
693 return
694 fi
695
696 PID_SESSIOND="$(pgrep "${SESSIOND_MATCH}") $(pgrep "$RUNAS_MATCH")"
697
698 if [ "$withtap" -eq "1" ]; then
699 diag "Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$PID_SESSIOND" | tr '\n' ' ')"
700 fi
701
702 # shellcheck disable=SC2086
703 if ! kill -s $signal $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
704 if [ "$withtap" -eq "1" ]; then
705 fail "Sending SIGSTOP to session daemon"
706 fi
707 else
708 out=1
709 while [ $out -ne 0 ]; do
710 pid="$(pgrep "$SESSIOND_MATCH")"
711
712 # Wait until state becomes stopped for session
713 # daemon(s).
714 out=0
715 for sessiond_pid in $pid; do
716 state="$(ps -p "$sessiond_pid" -o state= )"
717 if [[ -n "$state" && "$state" != "T" ]]; then
718 out=1
719 fi
720 done
721 sleep 0.5
722 done
723 if [ "$withtap" -eq "1" ]; then
724 pass "Sending SIGSTOP to session daemon"
725 fi
726 fi
727 }
728
729 function sigstop_lttng_sessiond()
730 {
731 sigstop_lttng_sessiond_opt 1 "$@"
732 }
733
734 function sigstop_lttng_sessiond_notap()
735 {
736 sigstop_lttng_sessiond_opt 0 "$@"
737 }
738
739 function stop_lttng_consumerd_opt()
740 {
741 local withtap=$1
742 local signal=$2
743
744 if [ -z "$signal" ]; then
745 signal=SIGTERM
746 fi
747
748 local timeout_s=$3
749 local dtimeleft_s=
750
751 # Multiply time by 2 to simplify integer arithmetic
752 if [ -n "$timeout_s" ]; then
753 dtimeleft_s=$((timeout_s * 2))
754 fi
755
756 local retval=0
757
758 PID_CONSUMERD="$(pgrep "$CONSUMERD_MATCH")"
759
760 if [ -z "$PID_CONSUMERD" ]; then
761 if [ "$withtap" -eq "1" ]; then
762 pass "No consumer daemon to kill"
763 fi
764 return 0
765 fi
766
767 diag "Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')"
768
769 # shellcheck disable=SC2086
770 if ! kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then
771 retval=1
772 if [ "$withtap" -eq "1" ]; then
773 fail "Kill consumer daemon"
774 fi
775 else
776 out=1
777 while [ $out -ne 0 ]; do
778 pid="$(pgrep "$CONSUMERD_MATCH")"
779
780 # If consumerds are still present check their status.
781 # A zombie status qualifies the consumerd as *killed*
782 out=0
783 for consumer_pid in $pid; do
784 state="$(ps -p "$consumer_pid" -o state= )"
785 if [[ -n "$state" && "$state" != "Z" ]]; then
786 out=1
787 fi
788 done
789 if [ -n "$dtimeleft_s" ]; then
790 if [ $dtimeleft_s -lt 0 ]; then
791 out=0
792 retval=1
793 fi
794 dtimeleft_s=$((dtimeleft_s - 1))
795 fi
796 sleep 0.5
797 done
798 if [ "$withtap" -eq "1" ]; then
799 if [ "$retval" -eq "0" ]; then
800 pass "Wait after kill consumer daemon"
801 else
802 fail "Wait after kill consumer daemon"
803 fi
804 fi
805 fi
806
807 return $retval
808 }
809
810 function stop_lttng_consumerd()
811 {
812 stop_lttng_consumerd_opt 1 "$@"
813 }
814
815 function stop_lttng_consumerd_notap()
816 {
817 stop_lttng_consumerd_opt 0 "$@"
818 }
819
820 function sigstop_lttng_consumerd_opt()
821 {
822 local withtap=$1
823 local signal=SIGSTOP
824
825 PID_CONSUMERD="$(pgrep "$CONSUMERD_MATCH")"
826
827 diag "Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')"
828
829 # shellcheck disable=SC2086
830 kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
831 retval=$?
832
833 if [ $retval -eq 1 ]; then
834 if [ "$withtap" -eq "1" ]; then
835 fail "Sending SIGSTOP to consumer daemon"
836 fi
837 return 1
838 else
839 out=1
840 while [ $out -ne 0 ]; do
841 pid="$(pgrep "$CONSUMERD_MATCH")"
842
843 # Wait until state becomes stopped for all
844 # consumers.
845 out=0
846 for consumer_pid in $pid; do
847 state="$(ps -p "$consumer_pid" -o state= )"
848 if [[ -n "$state" && "$state" != "T" ]]; then
849 out=1
850 fi
851 done
852 sleep 0.5
853 done
854 if [ "$withtap" -eq "1" ]; then
855 pass "Sending SIGSTOP to consumer daemon"
856 fi
857 fi
858 return $retval
859 }
860
861 function sigstop_lttng_consumerd()
862 {
863 sigstop_lttng_consumerd_opt 1 "$@"
864 }
865
866 function sigstop_lttng_consumerd_notap()
867 {
868 sigstop_lttng_consumerd_opt 0 "$@"
869 }
870
871 function list_lttng_with_opts ()
872 {
873 local opts=$1
874 $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
875 ok $? "Lttng-tool list command with option $opts"
876 }
877
878 function create_lttng_session_no_output ()
879 {
880 local sess_name=$1
881 local opts="${@:2}"
882
883 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
884 ok $? "Create session $sess_name in no-output mode"
885 }
886
887 function create_lttng_session_uri () {
888 local sess_name=$1
889 local uri=$2
890 local opts="${@:3}"
891
892 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -U $uri $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
893 ok $? "Create session $sess_name with uri:$uri and opts: $opts"
894 }
895
896 function create_lttng_session ()
897 {
898 local withtap=$1
899 local expected_to_fail=$2
900 local sess_name=$3
901 local trace_path=$4
902 local opt=$5
903
904 if [ -z "$trace_path" ]; then
905 # Use lttng-sessiond default output.
906 trace_path=""
907 else
908 trace_path="-o $trace_path"
909 fi
910
911 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create "$sess_name" $trace_path $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
912 ret=$?
913 if [ $expected_to_fail -eq "1" ]; then
914 test "$ret" -ne "0"
915 ret=$?
916 if [ $withtap -eq "1" ]; then
917 ok $ret "Create session $sess_name in $trace_path failed as expected"
918 fi
919 else
920 if [ $withtap -eq "1" ]; then
921 ok $ret "Create session $sess_name in $trace_path"
922 fi
923 fi
924 return $ret
925 }
926
927 function create_lttng_session_ok ()
928 {
929 create_lttng_session 1 0 "$@"
930 }
931
932 function create_lttng_session_fail ()
933 {
934 create_lttng_session 1 1 "$@"
935 }
936
937 function create_lttng_session_notap ()
938 {
939 create_lttng_session 0 0 "$@"
940 }
941
942
943 function enable_ust_lttng_channel ()
944 {
945 local withtap=$1
946 local expected_to_fail=$2
947 local sess_name=$3
948 local channel_name=$4
949 local opts="${@:5}"
950
951 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
952 ret=$?
953 if [[ $expected_to_fail -eq "1" ]]; then
954 test "$ret" -ne "0"
955 ret=$?
956 if [ $withtap -eq "1" ]; then
957 ok $ret "Enable channel $channel_name for session $sess_name failed as expected"
958 fi
959 else
960 if [ $withtap -eq "1" ]; then
961 ok $ret "Enable channel $channel_name for session $sess_name"
962 fi
963 fi
964 return $ret
965 }
966
967 function enable_ust_lttng_channel_ok ()
968 {
969 enable_ust_lttng_channel 1 0 "$@"
970 }
971
972 function enable_ust_lttng_channel_fail ()
973 {
974 enable_ust_lttng_channel 1 1 "$@"
975 }
976
977 function enable_ust_lttng_channel_notap ()
978 {
979 enable_ust_lttng_channel 0 0 "$@"
980 }
981
982 function disable_ust_lttng_channel()
983 {
984 local sess_name=$1
985 local channel_name=$2
986
987 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
988 ok $? "Disable channel $channel_name for session $sess_name"
989 }
990
991 function enable_lttng_mmap_overwrite_kernel_channel()
992 {
993 local sess_name=$1
994 local channel_name=$2
995
996 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
997 ok $? "Enable channel $channel_name for session $sess_name"
998 }
999
1000 function enable_lttng_mmap_discard_small_kernel_channel()
1001 {
1002 local sess_name=$1
1003 local channel_name=$2
1004
1005 $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
1006 ok $? "Enable small discard channel $channel_name for session $sess_name"
1007 }
1008
1009 function enable_lttng_mmap_overwrite_small_kernel_channel()
1010 {
1011 local sess_name=$1
1012 local channel_name=$2
1013
1014 $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
1015 ok $? "Enable small discard channel $channel_name for session $sess_name"
1016 }
1017
1018 function enable_lttng_mmap_overwrite_ust_channel()
1019 {
1020 local sess_name=$1
1021 local channel_name=$2
1022
1023 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1024 ok $? "Enable channel $channel_name for session $sess_name"
1025 }
1026
1027 function enable_ust_lttng_event ()
1028 {
1029 local withtap=$1
1030 local expected_to_fail=$2
1031 local sess_name=$3
1032 local event_name="$4"
1033 local channel_name=$5
1034
1035 if [ -z $channel_name ]; then
1036 # default channel if none specified
1037 chan=""
1038 else
1039 chan="-c $channel_name"
1040 fi
1041
1042 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1043 ret=$?
1044 if [[ $expected_to_fail -eq "1" ]]; then
1045 test $ret -ne "0"
1046 ret=$?
1047 if [[ $withtap -eq "1" ]]; then
1048 ok $ret "Enable ust event $event_name for session $session_name failed as expected"
1049 fi
1050 else
1051 if [[ $withtap -eq "1" ]]; then
1052 ok $ret "Enable ust event $event_name for session $sess_name"
1053 fi
1054 fi
1055 return $ret
1056 }
1057
1058 function enable_ust_lttng_event_ok ()
1059 {
1060 enable_ust_lttng_event 1 0 "$@"
1061 }
1062
1063 function enable_ust_lttng_event_fail ()
1064 {
1065 enable_ust_lttng_event 1 1 "$@"
1066 }
1067
1068 function enable_ust_lttng_event_notap ()
1069 {
1070 enable_ust_lttng_event 0 0 "$@"
1071 }
1072
1073 function enable_jul_lttng_event()
1074 {
1075 sess_name=$1
1076 event_name="$2"
1077 channel_name=$3
1078
1079 if [ -z $channel_name ]; then
1080 # default channel if none specified
1081 chan=""
1082 else
1083 chan="-c $channel_name"
1084 fi
1085
1086 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1087 ok $? "Enable JUL event $event_name for session $sess_name"
1088 }
1089
1090 function enable_jul_lttng_event_loglevel()
1091 {
1092 local sess_name=$1
1093 local event_name="$2"
1094 local loglevel=$3
1095 local channel_name=$4
1096
1097 if [ -z $channel_name ]; then
1098 # default channel if none specified
1099 chan=""
1100 else
1101 chan="-c $channel_name"
1102 fi
1103
1104 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1105 ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
1106 }
1107
1108 function enable_log4j_lttng_event()
1109 {
1110 sess_name=$1
1111 event_name="$2"
1112 channel_name=$3
1113
1114 if [ -z $channel_name ]; then
1115 # default channel if none specified
1116 chan=""
1117 else
1118 chan="-c $channel_name"
1119 fi
1120
1121 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1122 ok $? "Enable LOG4J event $event_name for session $sess_name"
1123 }
1124
1125 function enable_log4j_lttng_event_loglevel()
1126 {
1127 local sess_name=$1
1128 local event_name="$2"
1129 local loglevel=$3
1130 local channel_name=$4
1131
1132 if [ -z $channel_name ]; then
1133 # default channel if none specified
1134 chan=""
1135 else
1136 chan="-c $channel_name"
1137 fi
1138
1139 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1140 ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
1141 }
1142
1143 function enable_python_lttng_event()
1144 {
1145 sess_name=$1
1146 event_name="$2"
1147 channel_name=$3
1148
1149 if [ -z $channel_name ]; then
1150 # default channel if none specified
1151 chan=""
1152 else
1153 chan="-c $channel_name"
1154 fi
1155
1156 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1157 ok $? "Enable Python event $event_name for session $sess_name"
1158 }
1159
1160 function enable_python_lttng_event_loglevel()
1161 {
1162 local sess_name=$1
1163 local event_name="$2"
1164 local loglevel=$3
1165 local channel_name=$4
1166
1167 if [ -z $channel_name ]; then
1168 # default channel if none specified
1169 chan=""
1170 else
1171 chan="-c $channel_name"
1172 fi
1173
1174 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1175 ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel"
1176 }
1177
1178 function enable_ust_lttng_event_filter()
1179 {
1180 local sess_name="$1"
1181 local event_name="$2"
1182 local filter="$3"
1183
1184 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1185 ok $? "Enable event $event_name with filtering for session $sess_name"
1186 }
1187
1188 function enable_ust_lttng_event_loglevel()
1189 {
1190 local sess_name="$1"
1191 local event_name="$2"
1192 local loglevel="$3"
1193
1194 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1195 ok $? "Enable event $event_name with loglevel $loglevel"
1196 }
1197
1198 function enable_ust_lttng_event_loglevel_only()
1199 {
1200 local sess_name="$1"
1201 local event_name="$2"
1202 local loglevel="$3"
1203
1204 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1205 ok $? "Enable event $event_name with loglevel-only $loglevel"
1206 }
1207
1208 function disable_ust_lttng_event ()
1209 {
1210 local sess_name="$1"
1211 local event_name="$2"
1212 local channel_name="$3"
1213
1214 if [ -z $channel_name ]; then
1215 # default channel if none specified
1216 chan=""
1217 else
1218 chan="-c $channel_name"
1219 fi
1220
1221 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1222 ok $? "Disable event $event_name for session $sess_name"
1223 }
1224
1225 function disable_jul_lttng_event ()
1226 {
1227 local sess_name="$1"
1228 local event_name="$2"
1229
1230 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1
1231 ok $? "Disable JUL event $event_name for session $sess_name"
1232 }
1233
1234 function disable_log4j_lttng_event ()
1235 {
1236 local sess_name="$1"
1237 local event_name="$2"
1238
1239 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1
1240 ok $? "Disable LOG4J event $event_name for session $sess_name"
1241 }
1242
1243 function disable_python_lttng_event ()
1244 {
1245 local sess_name="$1"
1246 local event_name="$2"
1247
1248 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1249 ok $? "Disable Python event $event_name for session $sess_name"
1250 }
1251
1252 function start_lttng_tracing_opt ()
1253 {
1254 local withtap=$1
1255 local expected_to_fail=$2
1256 local sess_name=$3
1257
1258 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1259 ret=$?
1260 if [[ $expected_to_fail -eq "1" ]]; then
1261 test "$ret" -ne "0"
1262 ret=$?
1263 if [ $withtap -eq "1" ]; then
1264 ok $? "Start tracing for session $sess_name failed as expected"
1265 fi
1266 else
1267 if [ $withtap -eq "1" ]; then
1268 ok $ret "Start tracing for session $sess_name"
1269 fi
1270 fi
1271 }
1272
1273 function start_lttng_tracing_ok ()
1274 {
1275 start_lttng_tracing_opt 1 0 "$@"
1276 }
1277
1278 function start_lttng_tracing_fail ()
1279 {
1280 start_lttng_tracing_opt 1 1 "$@"
1281 }
1282
1283 function start_lttng_tracing_notap ()
1284 {
1285 start_lttng_tracing_opt 0 1 "$@"
1286 }
1287
1288 function stop_lttng_tracing_opt ()
1289 {
1290 local withtap=$1
1291 local expected_to_fail=$2
1292 local sess_name=$3
1293
1294 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1295 ret=$?
1296 if [[ $expected_to_fail -eq "1" ]]; then
1297 test "$ret" -ne "0"
1298 ret=$?
1299 if [ $withtap -eq "1" ]; then
1300 ok $? "Stop lttng tracing for session $sess_name failed as expected"
1301 fi
1302 else
1303 if [ $withtap -eq "1" ]; then
1304 ok $ret "Stop lttng tracing for session $sess_name"
1305 fi
1306 fi
1307 }
1308
1309 function stop_lttng_tracing_ok ()
1310 {
1311 stop_lttng_tracing_opt 1 0 "$@"
1312 }
1313
1314 function stop_lttng_tracing_fail ()
1315 {
1316 stop_lttng_tracing_opt 1 1 "$@"
1317 }
1318
1319 function stop_lttng_tracing_notap ()
1320 {
1321 stop_lttng_tracing_opt 0 0 "$@"
1322 }
1323
1324 function destroy_lttng_session ()
1325 {
1326 local withtap=$1
1327 local expected_to_fail=$2
1328 local sess_name=$3
1329
1330 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1331 ret=$?
1332 if [[ $expected_to_fail -eq "1" ]]; then
1333 test "$ret" -ne "0"
1334 ret=$?
1335 if [ $withtap -eq "1" ]; then
1336 ok $ret "Destroy session $sess_name failed as expected"
1337 fi
1338 else
1339 if [ $withtap -eq "1" ]; then
1340 ok $ret "Destroy session $sess_name"
1341 fi
1342 fi
1343 }
1344
1345 function destroy_lttng_session_ok ()
1346 {
1347 destroy_lttng_session 1 0 "$@"
1348
1349 }
1350
1351 function destroy_lttng_session_fail ()
1352 {
1353 destroy_lttng_session 1 1 "$@"
1354 }
1355
1356 function destroy_lttng_session_notap ()
1357 {
1358 destroy_lttng_session 0 0 "$@"
1359 }
1360
1361 function destroy_lttng_sessions ()
1362 {
1363 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1364 ok $? "Destroy all lttng sessions"
1365 }
1366
1367 function lttng_snapshot_add_output ()
1368 {
1369 local expected_to_fail=$1
1370 local sess_name=$2
1371 local trace_path=$3
1372 local opts=$4
1373
1374 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name $trace_path $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1375 ret=$?
1376 if [[ $expected_to_fail -eq 1 ]]; then
1377 test "$ret" -ne "0"
1378 ok $? "Added snapshot output $trace_path failed as expected"
1379 else
1380 ok $ret "Added snapshot output $trace_path"
1381 fi
1382 }
1383
1384 function lttng_snapshot_add_output_ok ()
1385 {
1386 lttng_snapshot_add_output 0 "$@"
1387 }
1388
1389 function lttng_snapshot_add_output_fail ()
1390 {
1391 lttng_snapshot_add_output 1 "$@"
1392 }
1393
1394 function lttng_snapshot_del_output ()
1395 {
1396 local expected_to_fail=$1
1397 local sess_name=$2
1398 local id=$3
1399
1400 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1401 ret=$?
1402 if [[ $expected_to_fail -eq "1" ]]; then
1403 test "$ret" -ne "0"
1404 ok $? "Deleted snapshot output id $id failed as expected"
1405 else
1406 ok $ret "Deleted snapshot output id $id"
1407 fi
1408 }
1409
1410 function lttng_snapshot_del_output_ok ()
1411 {
1412 lttng_snapshot_del_output 0 "$@"
1413 }
1414
1415 function lttng_snapshot_del_output_fail ()
1416 {
1417 lttng_snapshot_del_output 1 "$@"
1418 }
1419
1420 function lttng_snapshot_record ()
1421 {
1422 local sess_name=$1
1423
1424 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name $trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1425 ok $? "Snapshot recorded"
1426 }
1427
1428 function lttng_snapshot_list ()
1429 {
1430 local sess_name=$1
1431 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1432 ok $? "Snapshot list"
1433 }
1434
1435 function lttng_save()
1436 {
1437 local sess_name=$1
1438 local opts=$2
1439
1440 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1441 ok $? "Session saved"
1442 }
1443
1444 function lttng_load()
1445 {
1446 local expected_to_fail=$1
1447 local opts=$2
1448
1449 $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1450 ret=$?
1451 if [[ $expected_to_fail -eq "1" ]]; then
1452 test $ret -ne "0"
1453 ok $? "Load command failed as expected with opts: $opts"
1454 else
1455 ok $ret "Load command with opts: $opts"
1456 fi
1457 }
1458
1459 function lttng_load_ok()
1460 {
1461 lttng_load 0 "$@"
1462 }
1463
1464 function lttng_load_fail()
1465 {
1466 lttng_load 1 "$@"
1467 }
1468
1469 function lttng_track()
1470 {
1471 local expected_to_fail="$1"
1472 local opts="$@"
1473 $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST
1474 ret=$?
1475 if [[ $expected_to_fail -eq "1" ]]; then
1476 test $ret -ne "0"
1477 ok $? "Track command failed as expected with opts: $opts"
1478 else
1479 ok $ret "Track command with opts: $opts"
1480 fi
1481 }
1482
1483 function lttng_track_ok()
1484 {
1485 lttng_track 0 "$@"
1486 }
1487
1488 function lttng_track_fail()
1489 {
1490 lttng_track 1 "$@"
1491 }
1492
1493 function lttng_untrack()
1494 {
1495 local expected_to_fail="$1"
1496 local opts="$@"
1497 $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST
1498 ret=$?
1499 if [[ $expected_to_fail -eq "1" ]]; then
1500 test $ret -ne "0"
1501 ok $? "Untrack command failed as expected with opts: $opts"
1502 else
1503 ok $ret "Untrack command with opts: $opts"
1504 fi
1505 }
1506
1507 function lttng_untrack_ok()
1508 {
1509 lttng_untrack 0 "$@"
1510 }
1511
1512 function lttng_untrack_fail()
1513 {
1514 lttng_untrack 1 "$@"
1515 }
1516
1517 function lttng_track_pid_ok()
1518 {
1519 PID=$1
1520 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track --kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1521 ok $? "Lttng track pid on the kernel domain"
1522 }
1523
1524 function lttng_untrack_kernel_all_ok()
1525 {
1526 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack --kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1527 ok $? "Lttng untrack all pid on the kernel domain"
1528 }
1529
1530 function lttng_track_ust_ok()
1531 {
1532 lttng_track_ok -u "$@"
1533 }
1534
1535 function lttng_track_ust_fail()
1536 {
1537 lttng_track_fail -u "$@"
1538 }
1539
1540 function lttng_track_kernel_ok()
1541 {
1542 lttng_track_ok -k "$@"
1543 }
1544
1545 function lttng_track_kernel_fail()
1546 {
1547 lttng_track_fail -k "$@"
1548 }
1549
1550 function lttng_untrack_ust_ok()
1551 {
1552 lttng_untrack_ok -u "$@"
1553 }
1554
1555 function lttng_untrack_ust_fail()
1556 {
1557 lttng_untrack_fail -u "$@"
1558 }
1559
1560 function lttng_untrack_kernel_ok()
1561 {
1562 lttng_untrack_ok -k "$@"
1563 }
1564
1565 function lttng_untrack_kernel_fail()
1566 {
1567 lttng_untrack_fail -k "$@"
1568 }
1569
1570 function lttng_add_context_list()
1571 {
1572 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context --list 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1573 ret=$?
1574 ok $ret "Context listing"
1575 }
1576
1577 function add_context_lttng()
1578 {
1579 local expected_to_fail="$1"
1580 local domain="$2"
1581 local session_name="$3"
1582 local channel_name="$4"
1583 local type="$5"
1584
1585 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context -s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1586 ret=$?
1587 if [[ $expected_to_fail -eq "1" ]]; then
1588 test $ret -ne "0"
1589 ok $? "Add context command failed as expected for type: $type"
1590 else
1591 ok $ret "Add context command for type: $type"
1592 fi
1593 }
1594
1595 function add_context_ust_ok()
1596 {
1597 add_context_lttng 0 -u "$@"
1598 }
1599
1600 function add_context_ust_fail()
1601 {
1602 add_context_lttng 1 -u "$@"
1603 }
1604
1605 function add_context_kernel_ok()
1606 {
1607 add_context_lttng 0 -k "$@"
1608 }
1609
1610 function add_context_kernel_fail()
1611 {
1612 add_context_lttng 1 -k "$@"
1613 }
1614
1615 function validate_directory_empty ()
1616 {
1617 local trace_path=$1
1618
1619 ls -A $local_path > /dev/null 2>&1
1620 if [ $? -eq 0 ]; then
1621 pass "Directory empty"
1622 else
1623 fail "Directory empty"
1624 fi
1625 }
1626
1627 function wait_live_trace_ready ()
1628 {
1629 local url=$1
1630 local zero_client_match=0
1631
1632 diag "Waiting for live trace at url: $url"
1633 while [ $zero_client_match -eq 0 ]; do
1634 zero_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "0 client(s) connected" | wc -l)
1635 sleep 0.5
1636 done
1637 pass "Waiting for live trace at url: $url"
1638 }
1639
1640 function wait_live_viewer_connect ()
1641 {
1642 local url=$1
1643 local one_client_match=0
1644
1645 diag "Waiting for live viewers on url: $url"
1646 while [ $one_client_match -eq 0 ]; do
1647 one_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "1 client(s) connected" | wc -l)
1648 sleep 0.5
1649 done
1650 pass "Waiting for live viewers on url: $url"
1651 }
1652
1653 function validate_metadata_event ()
1654 {
1655 local event_name=$1
1656 local nr_event_id=$2
1657 local trace_path=$3
1658
1659 local metadata_file=$(find $trace_path | grep metadata)
1660 local metadata_path=$(dirname $metadata_file)
1661
1662 which $BABELTRACE_BIN >/dev/null
1663 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1664
1665 local count=$($BABELTRACE_BIN --output-format=ctf-metadata $metadata_path | grep $event_name | wc -l)
1666
1667 if [ "$count" -ne "$nr_event_id" ]; then
1668 fail "Metadata match with the metadata of $count event(s) named $event_name"
1669 diag "$count matching event id found in metadata"
1670 else
1671 pass "Metadata match with the metadata of $count event(s) named $event_name"
1672 fi
1673
1674 }
1675
1676 function trace_matches ()
1677 {
1678 local event_name=$1
1679 local nr_iter=$2
1680 local trace_path=$3
1681
1682 which $BABELTRACE_BIN >/dev/null
1683 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1684
1685 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
1686
1687 if [ "$count" -ne "$nr_iter" ]; then
1688 fail "Trace match"
1689 diag "$count matching events found in trace"
1690 else
1691 pass "Trace match"
1692 fi
1693 }
1694
1695 function trace_match_only()
1696 {
1697 local event_name=$1
1698 local nr_iter=$2
1699 local trace_path=$3
1700
1701 which $BABELTRACE_BIN >/dev/null
1702 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1703
1704 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
1705 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1706
1707 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1708 pass "Trace match with $total event $event_name"
1709 else
1710 fail "Trace match"
1711 diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1712 fi
1713 }
1714
1715 function validate_trace
1716 {
1717 local event_name=$1
1718 local trace_path=$2
1719
1720 which $BABELTRACE_BIN >/dev/null
1721 if [ $? -ne 0 ]; then
1722 skip 0 "Babeltrace binary not found. Skipping trace validation"
1723 fi
1724
1725 OLDIFS=$IFS
1726 IFS=","
1727 for i in $event_name; do
1728 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1729 if [ "$traced" -ne 0 ]; then
1730 pass "Validate trace for event $i, $traced events"
1731 else
1732 fail "Validate trace for event $i"
1733 diag "Found $traced occurences of $i"
1734 fi
1735 done
1736 ret=$?
1737 IFS=$OLDIFS
1738 return $ret
1739 }
1740
1741 function validate_trace_count
1742 {
1743 local event_name=$1
1744 local trace_path=$2
1745 local expected_count=$3
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 cnt=0
1753 OLDIFS=$IFS
1754 IFS=","
1755 for i in $event_name; do
1756 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1757 if [ "$traced" -ne 0 ]; then
1758 pass "Validate trace for event $i, $traced events"
1759 else
1760 fail "Validate trace for event $i"
1761 diag "Found $traced occurences of $i"
1762 fi
1763 cnt=$(($cnt + $traced))
1764 done
1765 IFS=$OLDIFS
1766 test $cnt -eq $expected_count
1767 ok $? "Read a total of $cnt events, expected $expected_count"
1768 }
1769
1770 function validate_trace_count_range_incl_min_excl_max
1771 {
1772 local event_name=$1
1773 local trace_path=$2
1774 local expected_min=$3
1775 local expected_max=$4
1776
1777 which $BABELTRACE_BIN >/dev/null
1778 if [ $? -ne 0 ]; then
1779 skip 0 "Babeltrace binary not found. Skipping trace validation"
1780 fi
1781
1782 cnt=0
1783 OLDIFS=$IFS
1784 IFS=","
1785 for i in $event_name; do
1786 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1787 if [ "$traced" -ge $expected_min ]; then
1788 pass "Validate trace for event $i, $traced events"
1789 else
1790 fail "Validate trace for event $i"
1791 diag "Found $traced occurences of $i"
1792 fi
1793 cnt=$(($cnt + $traced))
1794 done
1795 IFS=$OLDIFS
1796 test $cnt -lt $expected_max
1797 ok $? "Read a total of $cnt events, expected between [$expected_min, $expected_max["
1798 }
1799
1800 function trace_first_line
1801 {
1802 local trace_path=$1
1803
1804 which $BABELTRACE_BIN >/dev/null
1805 if [ $? -ne 0 ]; then
1806 skip 0 "Babeltrace binary not found. Skipping trace validation"
1807 fi
1808
1809 $BABELTRACE_BIN $trace_path 2>/dev/null | head -n 1
1810 }
1811
1812 function validate_trace_exp()
1813 {
1814 local event_exp=$1
1815 local trace_path=$2
1816
1817 which $BABELTRACE_BIN >/dev/null
1818 skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
1819
1820 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep --extended-regexp ${event_exp} | wc -l)
1821 if [ "$traced" -ne 0 ]; then
1822 pass "Validate trace for expression '${event_exp}', $traced events"
1823 else
1824 fail "Validate trace for expression '${event_exp}'"
1825 diag "Found $traced occurences of '${event_exp}'"
1826 fi
1827 ret=$?
1828 return $ret
1829 }
1830
1831 function validate_trace_only_exp()
1832 {
1833 local event_exp=$1
1834 local trace_path=$2
1835
1836 which $BABELTRACE_BIN >/dev/null
1837 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1838
1839 local count=$($BABELTRACE_BIN $trace_path | grep --extended-regexp ${event_exp} | wc -l)
1840 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1841
1842 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1843 pass "Trace match with $total for expression '${event_exp}'"
1844 else
1845 fail "Trace match"
1846 diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1847 fi
1848 ret=$?
1849 return $ret
1850 }
1851
1852 function validate_trace_empty()
1853 {
1854 local trace_path=$1
1855
1856 which $BABELTRACE_BIN >/dev/null
1857 if [ $? -ne 0 ]; then
1858 skip 0 "Babeltrace binary not found. Skipping trace validation"
1859 fi
1860
1861 events=$($BABELTRACE_BIN $trace_path 2>/dev/null)
1862 ret=$?
1863 if [ $ret -ne 0 ]; then
1864 fail "Failed to parse trace"
1865 return $ret
1866 fi
1867
1868 traced=$(echo -n "$events" | wc -l)
1869 if [ "$traced" -eq 0 ]; then
1870 pass "Validate empty trace"
1871 else
1872 fail "Validate empty trace"
1873 diag "Found $traced events in trace"
1874 fi
1875 ret=$?
1876 return $ret
1877 }
1878
1879 function validate_folder_is_empty()
1880 {
1881 local folder=$1
1882
1883 test -z "$(ls -A "$folder")"
1884 ok $? "Folder ${folder} is empty"
1885 }
1886
1887 function validate_trace_session_ust_empty()
1888 {
1889 validate_folder_is_empty "$1"/ust
1890 }
1891
1892 function validate_trace_session_kernel_empty()
1893 {
1894 validate_trace_empty "$1"/kernel
1895 }
1896
1897 function regenerate_metadata ()
1898 {
1899 local expected_to_fail=$1
1900 local sess_name=$2
1901
1902 $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate metadata -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1903 ret=$?
1904 if [[ $expected_to_fail -eq "1" ]]; then
1905 test "$ret" -ne "0"
1906 ok $? "Expected fail on regenerate metadata $sess_name"
1907 else
1908 ok $ret "Metadata regenerate $sess_name"
1909 fi
1910 }
1911
1912 function regenerate_metadata_ok ()
1913 {
1914 regenerate_metadata 0 "$@"
1915 }
1916
1917 function regenerate_metadata_fail ()
1918 {
1919 regenerate_metadata 1 "$@"
1920 }
1921
1922 function regenerate_statedump ()
1923 {
1924 local expected_to_fail=$1
1925 local sess_name=$2
1926
1927 $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate statedump -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1928 ret=$?
1929 if [[ $expected_to_fail -eq "1" ]]; then
1930 test "$ret" -ne "0"
1931 ok $? "Expected fail on regenerate statedump $sess_name"
1932 else
1933 ok $ret "Statedump regenerate $sess_name"
1934 fi
1935 }
1936
1937 function regenerate_statedump_ok ()
1938 {
1939 regenerate_statedump 0 "$@"
1940 }
1941
1942 function regenerate_statedump_fail ()
1943 {
1944 regenerate_statedump 1 "$@"
1945 }
1946
1947 function rotate_session ()
1948 {
1949 local expected_to_fail=$1
1950 local sess_name=$2
1951
1952 $TESTDIR/../src/bin/lttng/$LTTNG_BIN rotate $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1953 ret=$?
1954 if [[ $expected_to_fail -eq "1" ]]; then
1955 test "$ret" -ne "0"
1956 ok $? "Expected fail on rotate session $sess_name"
1957 else
1958 ok $ret "Rotate session $sess_name"
1959 fi
1960 }
1961
1962 function rotate_session_ok ()
1963 {
1964 rotate_session 0 "$@"
1965 }
1966
1967 function rotate_session_fail ()
1968 {
1969 rotate_session 1 "$@"
1970 }
1971
1972 function destructive_tests_enabled ()
1973 {
1974 if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then
1975 return 0
1976 else
1977 return 1
1978 fi
1979 }
1980
1981 function lttng_enable_rotation_timer ()
1982 {
1983 local expected_to_fail=$1
1984 local sess_name=$2
1985 local period=$3
1986
1987 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --timer $period 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1988 ret=$?
1989 if [[ $expected_to_fail -eq "1" ]]; then
1990 test "$ret" -ne "0"
1991 ok $? "Expected fail when setting periodic rotation ($period) of session $sess_name"
1992 else
1993 ok $ret "Set periodic rotation ($period) of session $sess_name"
1994 fi
1995 }
1996
1997 function lttng_enable_rotation_timer_ok ()
1998 {
1999 lttng_enable_rotation_timer 0 $@
2000 }
2001
2002 function lttng_enable_rotation_timer_fail ()
2003 {
2004 lttng_enable_rotation_timer 1 $@
2005 }
2006
2007 function lttng_enable_rotation_size ()
2008 {
2009 local expected_to_fail=$1
2010 local sess_name=$2
2011 local size=$3
2012
2013 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --size $size 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2014 ret=$?
2015 if [[ $expected_to_fail -eq "1" ]]; then
2016 test "$ret" -ne "0"
2017 ok $? "Expected fail on rotate session $sess_name"
2018 else
2019 ok $ret "Rotate session $sess_name"
2020 fi
2021 }
2022
2023 function lttng_enable_rotation_size_ok ()
2024 {
2025 lttng_enable_rotation_size 0 $@
2026 }
2027
2028 function lttng_enable_rotation_size_fail ()
2029 {
2030 lttng_enable_rotation_size 1 $@
2031 }
2032
2033 function lttng_clear_session ()
2034 {
2035 local expected_to_fail=$1
2036 local sess_name=$2
2037
2038 $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2039 ret=$?
2040 if [[ $expected_to_fail -eq "1" ]]; then
2041 test "$ret" -ne "0"
2042 ok $? "Expected fail on clear session $sess_name"
2043 else
2044 ok $ret "Clear session $sess_name"
2045 fi
2046 }
2047
2048 function lttng_clear_session_ok ()
2049 {
2050 lttng_clear_session 0 $@
2051 }
2052
2053 function lttng_clear_session_fail ()
2054 {
2055 lttng_clear_session 1 $@
2056 }
2057
2058 function lttng_clear_all ()
2059 {
2060 $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
2061 ok $? "Clear all lttng sessions"
2062 }
This page took 0.12678 seconds and 4 git commands to generate.