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