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