100f4fd2a1fc02566518168a2d2cd57447d71061
[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 SESSIOND_PIDS=""
19 RUNAS_BIN="lttng-runas"
20 RUNAS_MATCH=".*lttng-runas.*"
21 CONSUMERD_BIN="lttng-consumerd"
22 CONSUMERD_MATCH=".*lttng-consumerd.*"
23 RELAYD_BIN="lttng-relayd"
24 RELAYD_MATCH=".*lttng-relayd.*"
25 RELAYD_PIDS=""
26 LTTNG_BIN="lttng"
27 BABELTRACE_BIN="babeltrace"
28 OUTPUT_DEST=/dev/null
29 ERROR_OUTPUT_DEST=/dev/null
30
31 # Minimal kernel version supported for session daemon tests
32 KERNEL_MAJOR_VERSION=2
33 KERNEL_MINOR_VERSION=6
34 KERNEL_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.
39 export LTTNG_UST_REGISTER_TIMEOUT=-1
40 export LTTNG_NETWORK_SOCKET_TIMEOUT=-1
41 export 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.
47 export LTTNG_SESSIOND_PATH="/bin/true"
48
49 source $TESTDIR/utils/tap/tap.sh
50
51 function 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
65 trap full_cleanup SIGINT SIGTERM
66
67 function 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
77 function 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
87 function print_test_banner ()
88 {
89 local desc="$1"
90 diag "$desc"
91 }
92
93 function 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
111 function 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.
119 function 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 function enable_kernel_lttng_event
129 {
130 local expected_to_fail="$1"
131 local sess_name="$2"
132 local event_name="$3"
133 local channel_name="$4"
134
135 if [ -z "$event_name" ]; then
136 # Enable all event if no event name specified
137 event_name="-a"
138 fi
139
140 if [ -z "$channel_name" ]; then
141 # default channel if none specified
142 chan=""
143 else
144 chan="-c $channel_name"
145 fi
146
147 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
148 ret=$?
149 if [[ $expected_to_fail -eq "1" ]]; then
150 test $ret -ne "0"
151 ok $? "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected"
152 else
153 ok $ret "Enable kernel event $event_name for session $sess_name"
154 fi
155 }
156
157 function enable_kernel_lttng_event_ok ()
158 {
159 enable_kernel_lttng_event 0 "$@"
160 }
161
162 function enable_kernel_lttng_event_fail ()
163 {
164 enable_kernel_lttng_event 1 "$@"
165 }
166
167 # Old interface
168 function lttng_enable_kernel_event
169 {
170 enable_kernel_lttng_event_ok "$@"
171 }
172
173 function lttng_enable_kernel_syscall()
174 {
175 local expected_to_fail=$1
176 local sess_name=$2
177 local syscall_name=$3
178 local channel_name=$4
179
180 if [ -z $syscall_name ]; then
181 # Enable all event if no syscall name specified
182 syscall_name="-a"
183 fi
184
185 if [ -z $channel_name ]; then
186 # default channel if none specified
187 chan=""
188 else
189 chan="-c $channel_name"
190 fi
191
192 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
193 ret=$?
194 if [[ $expected_to_fail -eq "1" ]]; then
195 test $ret -ne "0"
196 ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
197 else
198 ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
199 fi
200 }
201
202 function lttng_enable_kernel_syscall_ok()
203 {
204 lttng_enable_kernel_syscall 0 "$@"
205 }
206
207 function lttng_enable_kernel_syscall_fail()
208 {
209 lttng_enable_kernel_syscall 1 "$@"
210 }
211
212 function lttng_disable_kernel_syscall()
213 {
214 local expected_to_fail=$1
215 local sess_name=$2
216 local syscall_name=$3
217 local channel_name=$4
218
219 if [ -z $syscall_name ]; then
220 # Enable all event if no syscall name specified
221 syscall_name="-a"
222 fi
223
224 if [ -z $channel_name ]; then
225 # default channel if none specified
226 chan=""
227 else
228 chan="-c $channel_name"
229 fi
230
231 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
232
233 ret=$?
234 if [[ $expected_to_fail -eq "1" ]]; then
235 test $ret -ne "0"
236 ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
237 else
238 ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
239 fi
240 }
241
242 function lttng_disable_kernel_syscall_ok()
243 {
244 lttng_disable_kernel_syscall 0 "$@"
245 }
246
247 function lttng_disable_kernel_syscall_fail()
248 {
249 lttng_disable_kernel_syscall 1 "$@"
250 }
251
252 function lttng_enable_kernel_channel()
253 {
254 local expected_to_fail=$1
255 local sess_name=$2
256 local channel_name=$3
257
258 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
259 ret=$?
260 if [[ $expected_to_fail -eq "1" ]]; then
261 test "$ret" -ne "0"
262 ok $? "Enable channel $channel_name for session $sess_name failed as expected"
263 else
264 ok $ret "Enable channel $channel_name for session $sess_name"
265 fi
266 }
267
268 function lttng_enable_kernel_channel_ok()
269 {
270 lttng_enable_kernel_channel 0 "$@"
271 }
272
273 function lttng_enable_kernel_channel_fail()
274 {
275 lttng_enable_kernel_channel 1 "$@"
276 }
277
278 function lttng_disable_kernel_channel()
279 {
280 local expected_to_fail=$1
281 local sess_name=$2
282 local channel_name=$3
283
284 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
285 ret=$?
286 if [[ $expected_to_fail -eq "1" ]]; then
287 test "$ret" -ne "0"
288 ok $? "Disable channel $channel_name for session $sess_name failed as expected"
289 else
290 ok $ret "Disable channel $channel_name for session $sess_name"
291 fi
292 }
293
294 function lttng_disable_kernel_channel_ok()
295 {
296 lttng_disable_kernel_channel 0 "$@"
297 }
298
299 function lttng_disable_kernel_channel_fail()
300 {
301 lttng_disable_kernel_channel 1 "$@"
302 }
303
304 function start_lttng_relayd_opt()
305 {
306 local withtap=$1
307 local opt=$2
308
309 DIR=$(readlink -f $TESTDIR)
310
311 if [ -z $(pgrep $RELAYD_MATCH) ]; then
312 $DIR/../src/bin/lttng-relayd/$RELAYD_BIN -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
313 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
314 if [ $? -eq 1 ]; then
315 if [ $withtap -eq "1" ]; then
316 fail "Start lttng-relayd (opt: $opt)"
317 fi
318 return 1
319 else
320 if [ $withtap -eq "1" ]; then
321 pass "Start lttng-relayd (opt: $opt)"
322 fi
323 fi
324 else
325 pass "Start lttng-relayd (opt: $opt)"
326 fi
327
328 RELAYD_PIDS=$(pgrep $RELAYD_MATCH)
329 }
330
331 function start_lttng_relayd()
332 {
333 start_lttng_relayd_opt 1 "$@"
334 }
335
336 function start_lttng_relayd_notap()
337 {
338 start_lttng_relayd_opt 0 "$@"
339 }
340
341 function stop_lttng_relayd_opt()
342 {
343 local withtap=$1
344
345 if [ $withtap -eq "1" ]; then
346 diag "Killing lttng-relayd (pid: $RELAYD_PIDS)"
347 fi
348 kill $RELAYD_PIDS 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
349 retval=$?
350
351 if [ $? -eq 1 ]; then
352 if [ $withtap -eq "1" ]; then
353 fail "Kill relay daemon"
354 fi
355 return 1
356 else
357 out=1
358 while [ -n "$out" ]; do
359 out=$(pgrep $RELAYD_MATCH)
360 sleep 0.5
361 done
362 if [ $withtap -eq "1" ]; then
363 pass "Kill relay daemon"
364 fi
365 fi
366 RELAYD_PIDS=""
367 return $retval
368 }
369
370 function stop_lttng_relayd()
371 {
372 stop_lttng_relayd_opt 1 "$@"
373 }
374
375 function stop_lttng_relayd_notap()
376 {
377 stop_lttng_relayd_opt 0 "$@"
378 }
379
380 #First arg: show tap output
381 #Second argument: load path for automatic loading
382 function start_lttng_sessiond_opt()
383 {
384 local withtap=$1
385 local load_path=$2
386
387 local env_vars=""
388 local consumerd=""
389 local long_bit_value=$(getconf LONG_BIT)
390
391 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
392 # Env variable requested no session daemon
393 return
394 fi
395
396 DIR=$(readlink -f $TESTDIR)
397
398 # Get long_bit value for 32/64 consumerd
399 case "$long_bit_value" in
400 32)
401 consumerd="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
402 ;;
403 64)
404 consumerd="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
405 ;;
406 *)
407 return
408 ;;
409 esac
410
411 # Check for env. variable. Allow the use of LD_PRELOAD etc.
412 if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then
413 env_vars=${LTTNG_SESSIOND_ENV_VARS}
414 fi
415
416 validate_kernel_version
417 if [ $? -ne 0 ]; then
418 fail "Start session daemon"
419 BAIL_OUT "*** Kernel too old for session daemon tests ***"
420 fi
421
422 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
423 export LTTNG_SESSION_CONFIG_XSD_PATH
424
425 if [ -z $(pgrep ${SESSIOND_MATCH}) ]; then
426 # Have a load path ?
427 if [ -n "$load_path" ]; then
428 env $env_vars $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --load "$load_path" --background $consumerd
429 else
430 env $env_vars $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --background $consumerd
431 fi
432 #$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
433 status=$?
434 if [ $withtap -eq "1" ]; then
435 ok $status "Start session daemon"
436 fi
437 fi
438 SESSIOND_PIDS=$(pgrep $SESSIOND_MATCH)
439 }
440
441 function start_lttng_sessiond()
442 {
443 start_lttng_sessiond_opt 1 "$@"
444 }
445
446 function start_lttng_sessiond_notap()
447 {
448 start_lttng_sessiond_opt 0 "$@"
449 }
450
451 function stop_lttng_sessiond_opt()
452 {
453 local withtap=$1
454 local signal=$2
455 local kill_opt=""
456
457 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
458 # Env variable requested no session daemon
459 return
460 fi
461
462 local pids="${SESSIOND_PIDS} $(pgrep $RUNAS_MATCH)"
463
464 if [ -n "$2" ]; then
465 kill_opt="$kill_opt -s $signal"
466 fi
467 if [ $withtap -eq "1" ]; then
468 diag "Killing $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo $pids | tr '\n' ' ')"
469 fi
470 kill $kill_opt $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
471
472 if [ $? -eq 1 ]; then
473 if [ $withtap -eq "1" ]; then
474 fail "Kill sessions daemon"
475 fi
476 else
477 out=1
478 while [ -n "$out" ]; do
479 out=$(pgrep ${SESSIOND_MATCH})
480 sleep 0.5
481 done
482 out=1
483 while [ -n "$out" ]; do
484 out=$(pgrep $CONSUMERD_MATCH)
485 sleep 0.5
486 done
487
488 SESSIOND_PIDS=""
489 if [ $withtap -eq "1" ]; then
490 pass "Kill session daemon"
491 fi
492 fi
493 }
494
495 function stop_lttng_sessiond()
496 {
497 stop_lttng_sessiond_opt 1 "$@"
498 }
499
500 function stop_lttng_sessiond_notap()
501 {
502 stop_lttng_sessiond_opt 0 "$@"
503 }
504
505 function sigstop_lttng_sessiond_opt()
506 {
507 local withtap=$1
508 local signal=SIGSTOP
509 local kill_opt=""
510
511 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
512 # Env variable requested no session daemon
513 return
514 fi
515
516 PID_SESSIOND="$(pgrep ${SESSIOND_MATCH}) $(pgrep $RUNAS_MATCH)"
517
518 kill_opt="$kill_opt -s $signal"
519
520 if [ $withtap -eq "1" ]; then
521 diag "Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo $PID_SESSIOND | tr '\n' ' ')"
522 fi
523 kill $kill_opt $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
524
525 if [ $? -eq 1 ]; then
526 if [ $withtap -eq "1" ]; then
527 fail "Sending SIGSTOP to session daemon"
528 fi
529 else
530 out=1
531 while [ $out -ne 0 ]; do
532 pid=$(pgrep $SESSIOND_MATCH)
533
534 # Wait until state becomes stopped for session
535 # daemon(s).
536 out=0
537 for sessiond_pid in $pid; do
538 state=$(ps -p $sessiond_pid -o state= )
539 if [[ -n "$state" && "$state" != "T" ]]; then
540 out=1
541 fi
542 done
543 sleep 0.5
544 done
545 if [ $withtap -eq "1" ]; then
546 pass "Sending SIGSTOP to session daemon"
547 fi
548 fi
549 }
550
551 function sigstop_lttng_sessiond()
552 {
553 sigstop_lttng_sessiond_opt 1 "$@"
554 }
555
556 function sigstop_lttng_sessiond_notap()
557 {
558 sigstop_lttng_sessiond_opt 0 "$@"
559 }
560
561 function stop_lttng_consumerd_opt()
562 {
563 local withtap=$1
564 local signal=$2
565 local kill_opt=""
566
567 PID_CONSUMERD=$(pgrep $CONSUMERD_MATCH)
568
569 if [ -n "$2" ]; then
570 kill_opt="$kill_opt -s $signal"
571 fi
572
573 if [ $withtap -eq "1" ]; then
574 diag "Killing $CONSUMERD_BIN pids: $(echo $PID_CONSUMERD | tr '\n' ' ')"
575 fi
576 kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
577 retval=$?
578 set +x
579
580 if [ $? -eq 1 ]; then
581 if [ $withtap -eq "1" ]; then
582 fail "Kill consumer daemon"
583 fi
584 return 1
585 else
586 out=1
587 while [ $out -ne 0 ]; do
588 pid=$(pgrep $CONSUMERD_MATCH)
589
590 # If consumerds are still present check their status.
591 # A zombie status qualifies the consumerd as *killed*
592 out=0
593 for consumer_pid in $pid; do
594 state=$(ps -p $consumer_pid -o state= )
595 if [[ -n "$state" && "$state" != "Z" ]]; then
596 out=1
597 fi
598 done
599 sleep 0.5
600 done
601 if [ $withtap -eq "1" ]; then
602 pass "Kill consumer daemon"
603 fi
604 fi
605 return $retval
606 }
607
608 function stop_lttng_consumerd()
609 {
610 stop_lttng_consumerd_opt 1 "$@"
611 }
612
613 function stop_lttng_consumerd_notap()
614 {
615 stop_lttng_consumerd_opt 0 "$@"
616 }
617
618 function sigstop_lttng_consumerd_opt()
619 {
620 local withtap=$1
621 local signal=SIGSTOP
622 local kill_opt=""
623
624 PID_CONSUMERD=$(pgrep $CONSUMERD_MATCH)
625
626 kill_opt="$kill_opt -s $signal"
627
628 if [ $withtap -eq "1" ]; then
629 diag "Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo $PID_CONSUMERD | tr '\n' ' ')"
630 fi
631 kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
632 retval=$?
633 set +x
634
635 if [ $? -eq 1 ]; then
636 if [ $withtap -eq "1" ]; then
637 fail "Sending SIGSTOP to consumer daemon"
638 fi
639 return 1
640 else
641 out=1
642 while [ $out -ne 0 ]; do
643 pid=$(pgrep $CONSUMERD_MATCH)
644
645 # Wait until state becomes stopped for all
646 # consumers.
647 out=0
648 for consumer_pid in $pid; do
649 state=$(ps -p $consumer_pid -o state= )
650 if [[ -n "$state" && "$state" != "T" ]]; then
651 out=1
652 fi
653 done
654 sleep 0.5
655 done
656 if [ $withtap -eq "1" ]; then
657 pass "Sending SIGSTOP to consumer daemon"
658 fi
659 fi
660 return $retval
661 }
662
663 function sigstop_lttng_consumerd()
664 {
665 sigstop_lttng_consumerd_opt 1 "$@"
666 }
667
668 function sigstop_lttng_consumerd_notap()
669 {
670 sigstop_lttng_consumerd_opt 0 "$@"
671 }
672
673 function list_lttng_with_opts ()
674 {
675 local opts=$1
676 $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
677 ok $? "Lttng-tool list command with option $opts"
678 }
679
680 function create_lttng_session_no_output ()
681 {
682 local sess_name=$1
683
684 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
685 ok $? "Create session $sess_name in no-output mode"
686 }
687
688 function create_lttng_session ()
689 {
690 local expected_to_fail=$1
691 local sess_name=$2
692 local trace_path=$3
693 local opt=$4
694
695 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path $opt > $OUTPUT_DEST
696 ret=$?
697 if [[ $expected_to_fail -eq "1" ]]; then
698 test "$ret" -ne "0"
699 ok $? "Create session $sess_name in $trace_path failed as expected"
700 else
701 ok $ret "Create session $sess_name in $trace_path"
702 fi
703 }
704
705 function create_lttng_session_ok ()
706 {
707 create_lttng_session 0 "$@"
708 }
709
710 function create_lttng_session_fail ()
711 {
712 create_lttng_session 1 "$@"
713 }
714
715
716 function enable_ust_lttng_channel ()
717 {
718 local expected_to_fail=$1
719 local sess_name=$2
720 local channel_name=$3
721 local opt=$4
722
723 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
724 ret=$?
725 if [[ $expected_to_fail -eq "1" ]]; then
726 test "$ret" -ne "0"
727 ok $? "Enable channel $channel_name for session $sess_name failed as expected"
728 else
729 ok $ret "Enable channel $channel_name for session $sess_name"
730 fi
731 }
732
733 function enable_ust_lttng_channel_ok ()
734 {
735 enable_ust_lttng_channel 0 "$@"
736 }
737
738 function enable_ust_lttng_channel_fail ()
739 {
740 enable_ust_lttng_channel 1 "$@"
741 }
742
743 function disable_ust_lttng_channel()
744 {
745 local sess_name=$1
746 local channel_name=$2
747
748 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
749 ok $? "Disable channel $channel_name for session $sess_name"
750 }
751
752 function enable_lttng_mmap_overwrite_kernel_channel()
753 {
754 local sess_name=$1
755 local channel_name=$2
756
757 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
758 ok $? "Enable channel $channel_name for session $sess_name"
759 }
760
761 function enable_lttng_mmap_discard_small_kernel_channel()
762 {
763 local sess_name=$1
764 local channel_name=$2
765
766 $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
767 ok $? "Enable small discard channel $channel_name for session $sess_name"
768 }
769
770 function enable_lttng_mmap_overwrite_small_kernel_channel()
771 {
772 local sess_name=$1
773 local channel_name=$2
774
775 $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
776 ok $? "Enable small discard channel $channel_name for session $sess_name"
777 }
778
779 function enable_lttng_mmap_overwrite_ust_channel()
780 {
781 local sess_name=$1
782 local channel_name=$2
783
784 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
785 ok $? "Enable channel $channel_name for session $sess_name"
786 }
787
788 function enable_ust_lttng_event ()
789 {
790 local expected_to_fail=$1
791 local sess_name=$2
792 local event_name="$3"
793 local channel_name=$4
794
795 if [ -z $channel_name ]; then
796 # default channel if none specified
797 chan=""
798 else
799 chan="-c $channel_name"
800 fi
801
802 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
803 ret=$?
804 if [[ $expected_to_fail -eq "1" ]]; then
805 test $ret -ne "0"
806 ok $? "Enable ust event $event_name for session $session_name failed as expected"
807 else
808 ok $ret "Enable ust event $event_name for session $sess_name"
809 fi
810 }
811
812 function enable_ust_lttng_event_ok ()
813 {
814 enable_ust_lttng_event 0 "$@"
815 }
816
817 function enable_ust_lttng_event_fail ()
818 {
819 enable_ust_lttng_event 1 "$@"
820 }
821
822 function enable_jul_lttng_event()
823 {
824 sess_name=$1
825 event_name="$2"
826 channel_name=$3
827
828 if [ -z $channel_name ]; then
829 # default channel if none specified
830 chan=""
831 else
832 chan="-c $channel_name"
833 fi
834
835 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
836 ok $? "Enable JUL event $event_name for session $sess_name"
837 }
838
839 function enable_jul_lttng_event_loglevel()
840 {
841 local sess_name=$1
842 local event_name="$2"
843 local loglevel=$3
844 local channel_name=$4
845
846 if [ -z $channel_name ]; then
847 # default channel if none specified
848 chan=""
849 else
850 chan="-c $channel_name"
851 fi
852
853 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
854 ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
855 }
856
857 function enable_log4j_lttng_event()
858 {
859 sess_name=$1
860 event_name="$2"
861 channel_name=$3
862
863 if [ -z $channel_name ]; then
864 # default channel if none specified
865 chan=""
866 else
867 chan="-c $channel_name"
868 fi
869
870 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
871 ok $? "Enable LOG4J event $event_name for session $sess_name"
872 }
873
874 function enable_log4j_lttng_event_loglevel()
875 {
876 local sess_name=$1
877 local event_name="$2"
878 local loglevel=$3
879 local channel_name=$4
880
881 if [ -z $channel_name ]; then
882 # default channel if none specified
883 chan=""
884 else
885 chan="-c $channel_name"
886 fi
887
888 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
889 ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
890 }
891
892 function enable_python_lttng_event()
893 {
894 sess_name=$1
895 event_name="$2"
896 channel_name=$3
897
898 if [ -z $channel_name ]; then
899 # default channel if none specified
900 chan=""
901 else
902 chan="-c $channel_name"
903 fi
904
905 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
906 ok $? "Enable Python event $event_name for session $sess_name"
907 }
908
909 function enable_python_lttng_event_loglevel()
910 {
911 local sess_name=$1
912 local event_name="$2"
913 local loglevel=$3
914 local channel_name=$4
915
916 if [ -z $channel_name ]; then
917 # default channel if none specified
918 chan=""
919 else
920 chan="-c $channel_name"
921 fi
922
923 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
924 ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel"
925 }
926
927 function enable_ust_lttng_event_filter()
928 {
929 local sess_name="$1"
930 local event_name="$2"
931 local filter="$3"
932
933 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
934 ok $? "Enable event $event_name with filtering for session $sess_name"
935 }
936
937 function enable_ust_lttng_event_loglevel()
938 {
939 local sess_name="$1"
940 local event_name="$2"
941 local loglevel="$3"
942
943 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
944 ok $? "Enable event $event_name with loglevel $loglevel"
945 }
946
947 function enable_ust_lttng_event_loglevel_only()
948 {
949 local sess_name="$1"
950 local event_name="$2"
951 local loglevel="$3"
952
953 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
954 ok $? "Enable event $event_name with loglevel-only $loglevel"
955 }
956
957 function disable_ust_lttng_event ()
958 {
959 local sess_name="$1"
960 local event_name="$2"
961 local channel_name="$3"
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 disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
971 ok $? "Disable event $event_name for session $sess_name"
972 }
973
974 function disable_jul_lttng_event ()
975 {
976 local sess_name="$1"
977 local event_name="$2"
978
979 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1
980 ok $? "Disable JUL event $event_name for session $sess_name"
981 }
982
983 function disable_log4j_lttng_event ()
984 {
985 local sess_name="$1"
986 local event_name="$2"
987
988 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1
989 ok $? "Disable LOG4J event $event_name for session $sess_name"
990 }
991
992 function disable_python_lttng_event ()
993 {
994 local sess_name="$1"
995 local event_name="$2"
996
997 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
998 ok $? "Disable Python event $event_name for session $sess_name"
999 }
1000
1001 function start_lttng_tracing ()
1002 {
1003 local expected_to_fail=$1
1004 local sess_name=$2
1005
1006 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1007 ret=$?
1008 if [[ $expected_to_fail -eq "1" ]]; then
1009 test "$ret" -ne "0"
1010 ok $? "Start tracing for session $sess_name failed as expected"
1011 else
1012 ok $ret "Start tracing for session $sess_name"
1013 fi
1014 }
1015
1016 function start_lttng_tracing_ok ()
1017 {
1018 start_lttng_tracing 0 "$@"
1019 }
1020
1021 function start_lttng_tracing_fail ()
1022 {
1023 start_lttng_tracing 1 "$@"
1024 }
1025
1026 function stop_lttng_tracing ()
1027 {
1028 local expected_to_fail=$1
1029 local sess_name=$2
1030
1031 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1032 ret=$?
1033 if [[ $expected_to_fail -eq "1" ]]; then
1034 test "$ret" -ne "0"
1035 ok $? "Stop lttng tracing for session $sess_name failed as expected"
1036 else
1037 ok $ret "Stop lttng tracing for session $sess_name"
1038 fi
1039 }
1040
1041 function stop_lttng_tracing_ok ()
1042 {
1043 stop_lttng_tracing 0 "$@"
1044 }
1045
1046 function stop_lttng_tracing_fail ()
1047 {
1048 stop_lttng_tracing 1 "$@"
1049 }
1050
1051 function destroy_lttng_session ()
1052 {
1053 local expected_to_fail=$1
1054 local sess_name=$2
1055
1056 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1057 ret=$?
1058 if [[ $expected_to_fail -eq "1" ]]; then
1059 test "$ret" -ne "0"
1060 ok $? "Destroy session $sess_name failed as expected"
1061 else
1062 ok $ret "Destroy session $sess_name"
1063 fi
1064 }
1065
1066 function destroy_lttng_session_ok ()
1067 {
1068 destroy_lttng_session 0 "$@"
1069
1070 }
1071
1072 function destroy_lttng_session_fail ()
1073 {
1074 destroy_lttng_session 1 "$@"
1075 }
1076
1077
1078 function destroy_lttng_sessions ()
1079 {
1080 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1081 ok $? "Destroy all lttng sessions"
1082 }
1083
1084 function lttng_snapshot_add_output ()
1085 {
1086 local expected_to_fail=$1
1087 local sess_name=$2
1088 local trace_path=$3
1089
1090 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name file://$trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1091 ret=$?
1092 if [[ $expected_to_fail -eq 1 ]]; then
1093 test "$ret" -ne "0"
1094 ok $? "Added snapshot output file://$trace_path failed as expected"
1095 else
1096 ok $ret "Added snapshot output file://$trace_path"
1097 fi
1098 }
1099
1100 function lttng_snapshot_add_output_ok ()
1101 {
1102 lttng_snapshot_add_output 0 "$@"
1103 }
1104
1105 function lttng_snapshot_add_output_fail ()
1106 {
1107 lttng_snapshot_add_output 1 "$@"
1108 }
1109
1110 function lttng_snapshot_del_output ()
1111 {
1112 local expected_to_fail=$1
1113 local sess_name=$2
1114 local id=$3
1115
1116 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1117 ret=$?
1118 if [[ $expected_to_fail -eq "1" ]]; then
1119 test "$ret" -ne "0"
1120 ok $? "Deleted snapshot output id $id failed as expected"
1121 else
1122 ok $ret "Deleted snapshot output id $id"
1123 fi
1124 }
1125
1126 function lttng_snapshot_del_output_ok ()
1127 {
1128 lttng_snapshot_del_output 0 "$@"
1129 }
1130
1131 function lttng_snapshot_del_output_fail ()
1132 {
1133 lttng_snapshot_del_output 1 "$@"
1134 }
1135
1136 function lttng_snapshot_record ()
1137 {
1138 local sess_name=$1
1139 local trace_path=$2
1140
1141 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1142 ok $? "Snapshot recorded"
1143 }
1144
1145 function lttng_snapshot_list ()
1146 {
1147 local sess_name=$1
1148 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1149 ok $? "Snapshot list"
1150 }
1151
1152 function lttng_save()
1153 {
1154 local sess_name=$1
1155 local opts=$2
1156
1157 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1158 ok $? "Session saved"
1159 }
1160
1161 function lttng_load()
1162 {
1163 local expected_to_fail=$1
1164 local opts=$2
1165
1166 $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1167 ret=$?
1168 if [[ $expected_to_fail -eq "1" ]]; then
1169 test $ret -ne "0"
1170 ok $? "Load command failed as expected with opts: $opts"
1171 else
1172 ok $ret "Load command with opts: $opts"
1173 fi
1174 }
1175
1176 function lttng_load_ok()
1177 {
1178 lttng_load 0 "$@"
1179 }
1180
1181 function lttng_load_fail()
1182 {
1183 lttng_load 1 "$@"
1184 }
1185
1186 function lttng_track()
1187 {
1188 local expected_to_fail=$1
1189 local opts=$2
1190 $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST
1191 ret=$?
1192 if [[ $expected_to_fail -eq "1" ]]; then
1193 test $ret -ne "0"
1194 ok $? "Track command failed as expected with opts: $opts"
1195 else
1196 ok $ret "Track command with opts: $opts"
1197 fi
1198 }
1199
1200 function lttng_track_ok()
1201 {
1202 lttng_track 0 "$@"
1203 }
1204
1205 function lttng_track_fail()
1206 {
1207 lttng_track 1 "$@"
1208 }
1209
1210 function lttng_untrack()
1211 {
1212 local expected_to_fail=$1
1213 local opts=$2
1214 $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST
1215 ret=$?
1216 if [[ $expected_to_fail -eq "1" ]]; then
1217 test $ret -ne "0"
1218 ok $? "Untrack command failed as expected with opts: $opts"
1219 else
1220 ok $ret "Untrack command with opts: $opts"
1221 fi
1222 }
1223
1224 function lttng_untrack_ok()
1225 {
1226 lttng_untrack 0 "$@"
1227 }
1228
1229 function lttng_untrack_fail()
1230 {
1231 lttng_untrack 1 "$@"
1232 }
1233
1234 function add_context_lttng()
1235 {
1236 local expected_to_fail="$1"
1237 local domain="$2"
1238 local session_name="$3"
1239 local channel_name="$4"
1240 local type="$5"
1241
1242 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context -s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1243 ret=$?
1244 if [[ $expected_to_fail -eq "1" ]]; then
1245 test $ret -ne "0"
1246 ok $? "Add context command failed as expected for type: $type"
1247 else
1248 ok $ret "Add context command for type: $type"
1249 fi
1250 }
1251
1252 function add_context_ust_ok()
1253 {
1254 add_context_lttng 0 -u "$@"
1255 }
1256
1257 function add_context_ust_fail()
1258 {
1259 add_context_lttng 1 -u "$@"
1260 }
1261
1262 function add_context_kernel_ok()
1263 {
1264 add_context_lttng 0 -k "$@"
1265 }
1266
1267 function add_context_kernel_fail()
1268 {
1269 add_context_lttng 1 -k "$@"
1270 }
1271
1272 function trace_matches ()
1273 {
1274 local event_name=$1
1275 local nr_iter=$2
1276 local trace_path=$3
1277
1278 which $BABELTRACE_BIN >/dev/null
1279 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1280
1281 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
1282
1283 if [ "$count" -ne "$nr_iter" ]; then
1284 fail "Trace match"
1285 diag "$count matching events found in trace"
1286 else
1287 pass "Trace match"
1288 fi
1289 }
1290
1291 function trace_match_only()
1292 {
1293 local event_name=$1
1294 local nr_iter=$2
1295 local trace_path=$3
1296
1297 which $BABELTRACE_BIN >/dev/null
1298 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1299
1300 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
1301 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1302
1303 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1304 pass "Trace match with $total event $event_name"
1305 else
1306 fail "Trace match"
1307 diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1308 fi
1309 }
1310
1311 function validate_trace
1312 {
1313 local event_name=$1
1314 local trace_path=$2
1315
1316 which $BABELTRACE_BIN >/dev/null
1317 if [ $? -ne 0 ]; then
1318 skip 0 "Babeltrace binary not found. Skipping trace validation"
1319 fi
1320
1321 OLDIFS=$IFS
1322 IFS=","
1323 for i in $event_name; do
1324 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1325 if [ "$traced" -ne 0 ]; then
1326 pass "Validate trace for event $i, $traced events"
1327 else
1328 fail "Validate trace for event $i"
1329 diag "Found $traced occurences of $i"
1330 fi
1331 done
1332 ret=$?
1333 IFS=$OLDIFS
1334 return $ret
1335 }
1336
1337 function validate_trace_count
1338 {
1339 local event_name=$1
1340 local trace_path=$2
1341 local expected_count=$3
1342
1343 which $BABELTRACE_BIN >/dev/null
1344 if [ $? -ne 0 ]; then
1345 skip 0 "Babeltrace binary not found. Skipping trace validation"
1346 fi
1347
1348 cnt=0
1349 OLDIFS=$IFS
1350 IFS=","
1351 for i in $event_name; do
1352 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1353 if [ "$traced" -ne 0 ]; then
1354 pass "Validate trace for event $i, $traced events"
1355 else
1356 fail "Validate trace for event $i"
1357 diag "Found $traced occurences of $i"
1358 fi
1359 cnt=$(($cnt + $traced))
1360 done
1361 IFS=$OLDIFS
1362 test $cnt -eq $expected_count
1363 ok $? "Read a total of $cnt events, expected $expected_count"
1364 }
1365
1366 function trace_first_line
1367 {
1368 local trace_path=$1
1369
1370 which $BABELTRACE_BIN >/dev/null
1371 if [ $? -ne 0 ]; then
1372 skip 0 "Babeltrace binary not found. Skipping trace validation"
1373 fi
1374
1375 $BABELTRACE_BIN $trace_path 2>/dev/null | head -n 1
1376 }
1377
1378 function validate_trace_exp()
1379 {
1380 local event_exp=$1
1381 local trace_path=$2
1382
1383 which $BABELTRACE_BIN >/dev/null
1384 skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
1385
1386 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep ${event_exp} | wc -l)
1387 if [ "$traced" -ne 0 ]; then
1388 pass "Validate trace for expression '${event_exp}', $traced events"
1389 else
1390 fail "Validate trace for expression '${event_exp}'"
1391 diag "Found $traced occurences of '${event_exp}'"
1392 fi
1393 ret=$?
1394 return $ret
1395 }
1396
1397 function validate_trace_only_exp()
1398 {
1399 local event_exp=$1
1400 local trace_path=$2
1401
1402 which $BABELTRACE_BIN >/dev/null
1403 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1404
1405 local count=$($BABELTRACE_BIN $trace_path | grep ${event_exp} | wc -l)
1406 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1407
1408 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1409 pass "Trace match with $total for expression '${event_exp}"
1410 else
1411 fail "Trace match"
1412 diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1413 fi
1414 ret=$?
1415 return $ret
1416 }
1417
1418 function validate_trace_empty()
1419 {
1420 local trace_path=$1
1421
1422 which $BABELTRACE_BIN >/dev/null
1423 if [ $? -ne 0 ]; then
1424 skip 0 "Babeltrace binary not found. Skipping trace validation"
1425 fi
1426
1427 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | wc -l)
1428 if [ "$traced" -eq 0 ]; then
1429 pass "Validate empty trace"
1430 else
1431 fail "Validate empty trace"
1432 diag "Found $traced events in trace"
1433 fi
1434 ret=$?
1435 return $ret
1436 }
1437
1438 function regenerate_metadata ()
1439 {
1440 local expected_to_fail=$1
1441 local sess_name=$2
1442
1443 $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate metadata -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1444 ret=$?
1445 if [[ $expected_to_fail -eq "1" ]]; then
1446 test "$ret" -ne "0"
1447 ok $? "Expected fail on regenerate metadata $sess_name"
1448 else
1449 ok $ret "Metadata regenerate $sess_name"
1450 fi
1451 }
1452
1453 function regenerate_metadata_ok ()
1454 {
1455 regenerate_metadata 0 "$@"
1456 }
1457
1458 function regenerate_metadata_fail ()
1459 {
1460 regenerate_metadata 1 "$@"
1461 }
1462
1463 function regenerate_statedump ()
1464 {
1465 local expected_to_fail=$1
1466 local sess_name=$2
1467
1468 $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate statedump -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1469 ret=$?
1470 if [[ $expected_to_fail -eq "1" ]]; then
1471 test "$ret" -ne "0"
1472 ok $? "Expected fail on regenerate statedump $sess_name"
1473 else
1474 ok $ret "Metadata regenerate $sess_name"
1475 fi
1476 }
1477
1478 function regenerate_statedump_ok ()
1479 {
1480 regenerate_statedump 0 "$@"
1481 }
1482
1483 function regenerate_statedump_fail ()
1484 {
1485 regenerate_statedump 1 "$@"
1486 }
1487
1488 function destructive_tests_enabled ()
1489 {
1490 if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then
1491 return 0
1492 else
1493 return 1
1494 fi
1495 }
This page took 0.067211 seconds and 3 git commands to generate.