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