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