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