Fix: regression tests
[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 function lttng_enable_kernel_event
90 {
91 local sess_name=$1
92 local event_name=$2
93 local channel_name=$3
94
95 if [ -z $event_name ]; then
96 # Enable all event if no event name specified
97 event_name="-a"
98 fi
99
100 if [ -z $channel_name ]; then
101 # default channel if none specified
102 chan=""
103 else
104 chan="-c $channel_name"
105 fi
106
107 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
108 ok $? "Enable kernel event $event_name for session $sess_name"
109 }
110
111 function lttng_enable_kernel_syscall()
112 {
113 local expected_to_fail=$1
114 local sess_name=$2
115 local syscall_name=$3
116 local channel_name=$4
117
118 if [ -z $syscall_name ]; then
119 # Enable all event if no syscall name specified
120 syscall_name="-a"
121 fi
122
123 if [ -z $channel_name ]; then
124 # default channel if none specified
125 chan=""
126 else
127 chan="-c $channel_name"
128 fi
129
130 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
131 ret=$?
132 if [[ $expected_to_fail -eq "1" ]]; then
133 test $ret -ne "0"
134 ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
135 else
136 ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
137 fi
138 }
139
140 function lttng_enable_kernel_syscall_ok()
141 {
142 lttng_enable_kernel_syscall 0 "$@"
143 }
144
145 function lttng_enable_kernel_syscall_fail()
146 {
147 lttng_enable_kernel_syscall 1 "$@"
148 }
149
150 function lttng_disable_kernel_syscall()
151 {
152 local expected_to_fail=$1
153 local sess_name=$2
154 local syscall_name=$3
155 local channel_name=$4
156
157 if [ -z $syscall_name ]; then
158 # Enable all event if no syscall name specified
159 syscall_name="-a"
160 fi
161
162 if [ -z $channel_name ]; then
163 # default channel if none specified
164 chan=""
165 else
166 chan="-c $channel_name"
167 fi
168
169 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
170
171 ret=$?
172 if [[ $expected_to_fail -eq "1" ]]; then
173 test $ret -ne "0"
174 ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
175 else
176 ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
177 fi
178 }
179
180 function lttng_disable_kernel_syscall_ok()
181 {
182 lttng_disable_kernel_syscall 0 "$@"
183 }
184
185 function lttng_disable_kernel_syscall_fail()
186 {
187 lttng_disable_kernel_syscall 1 "$@"
188 }
189
190 function lttng_enable_kernel_channel()
191 {
192 local expected_to_fail=$1
193 local sess_name=$2
194 local channel_name=$3
195
196 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
197 ret=$?
198 if [[ $expected_to_fail -eq "1" ]]; then
199 test "$ret" -ne "0"
200 ok $? "Expected failure on kernel channel creation $channel_name in $sess_name"
201 else
202 ok $ret "Enable channel $channel_name for session $sess_name"
203 fi
204 }
205
206 function lttng_enable_kernel_channel_ok()
207 {
208 lttng_enable_kernel_channel 0 "$@"
209 }
210
211 function lttng_enable_kernel_channel_fail()
212 {
213 lttng_enable_kernel_channel 1 "$@"
214 }
215
216 function lttng_disable_kernel_channel()
217 {
218 local expected_to_fail=$1
219 local sess_name=$2
220 local channel_name=$3
221
222 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
223 ret=$?
224 if [[ $expected_to_fail -eq "1" ]]; then
225 test "$ret" -ne "0"
226 ok $? "Expected failure on kernel channel creation $channel_name in $sess_name"
227 else
228 ok $ret "disable channel $channel_name for session $sess_name"
229 fi
230 }
231
232 function lttng_disable_kernel_channel_ok()
233 {
234 lttng_disable_kernel_channel 0 "$@"
235 }
236
237 function lttng_disable_kernel_channel_fail()
238 {
239 lttng_disable_kernel_channel 1 "$@"
240 }
241
242 function start_lttng_relayd_opt()
243 {
244 local withtap=$1
245 local opt=$2
246
247 DIR=$(readlink -f $TESTDIR)
248
249 if [ -z $(pidof lt-$RELAYD_BIN) ]; then
250 $DIR/../src/bin/lttng-relayd/$RELAYD_BIN -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
251 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
252 if [ $? -eq 1 ]; then
253 if [ $withtap -eq "1" ]; then
254 fail "Start lttng-relayd (opt: $opt)"
255 fi
256 return 1
257 else
258 if [ $withtap -eq "1" ]; then
259 pass "Start lttng-relayd (opt: $opt)"
260 fi
261 fi
262 else
263 pass "Start lttng-relayd (opt: $opt)"
264 fi
265 }
266
267 function start_lttng_relayd()
268 {
269 start_lttng_relayd_opt 1 "$@"
270 }
271
272 function start_lttng_relayd_notap()
273 {
274 start_lttng_relayd_opt 0 "$@"
275 }
276
277 function stop_lttng_relayd_opt()
278 {
279 local withtap=$1
280
281 PID_RELAYD=`pidof lt-$RELAYD_BIN`
282
283 if [ $withtap -eq "1" ]; then
284 diag "Killing lttng-relayd (pid: $PID_RELAYD)"
285 fi
286 kill $PID_RELAYD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
287 retval=$?
288
289 if [ $? -eq 1 ]; then
290 if [ $withtap -eq "1" ]; then
291 fail "Kill relay daemon"
292 fi
293 return 1
294 else
295 out=1
296 while [ -n "$out" ]; do
297 out=$(pidof lt-$RELAYD_BIN)
298 sleep 0.5
299 done
300 if [ $withtap -eq "1" ]; then
301 pass "Kill relay daemon"
302 fi
303 fi
304 return $retval
305 }
306
307 function stop_lttng_relayd()
308 {
309 stop_lttng_relayd_opt 1 "$@"
310 }
311
312 function stop_lttng_relayd_notap()
313 {
314 stop_lttng_relayd_opt 0 "$@"
315 }
316
317 #First arg: show tap output
318 #Second argument: load path for automatic loading
319 function start_lttng_sessiond_opt()
320 {
321 local withtap=$1
322 local load_path=$2
323
324 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
325 # Env variable requested no session daemon
326 return
327 fi
328
329 validate_kernel_version
330 if [ $? -ne 0 ]; then
331 fail "Start session daemon"
332 BAIL_OUT "*** Kernel too old for session daemon tests ***"
333 fi
334
335 DIR=$(readlink -f $TESTDIR)
336 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
337 export LTTNG_SESSION_CONFIG_XSD_PATH
338
339 if [ -z $(pidof lt-$SESSIOND_BIN) ]; then
340 # Have a load path ?
341 if [ -n "$load_path" ]; then
342 $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --load "$1" --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
343 else
344 $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"
345 fi
346 #$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
347 status=$?
348 if [ $withtap -eq "1" ]; then
349 ok $status "Start session daemon"
350 fi
351 fi
352 }
353
354 function start_lttng_sessiond()
355 {
356 start_lttng_sessiond_opt 1 "$@"
357 }
358
359 function start_lttng_sessiond_notap()
360 {
361 start_lttng_sessiond_opt 0 "$@"
362 }
363
364 function stop_lttng_sessiond_opt()
365 {
366 local withtap=$1
367
368 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
369 # Env variable requested no session daemon
370 return
371 fi
372
373 PID_SESSIOND=`pidof lt-$SESSIOND_BIN`
374
375 kill $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
376
377 if [ $? -eq 1 ]; then
378 if [ $withtap -eq "1" ]; then
379 fail "Kill sessions daemon"
380 fi
381 else
382 out=1
383 while [ -n "$out" ]; do
384 out=$(pidof lt-$SESSIOND_BIN)
385 sleep 0.5
386 done
387 out=1
388 while [ -n "$out" ]; do
389 out=$(pidof $CONSUMERD_BIN)
390 sleep 0.5
391 done
392 if [ $withtap -eq "1" ]; then
393 pass "Kill session daemon"
394 fi
395 fi
396 }
397
398 function stop_lttng_sessiond()
399 {
400 stop_lttng_sessiond_opt 1 "$@"
401 }
402
403 function stop_lttng_sessiond_notap()
404 {
405 stop_lttng_sessiond_opt 0 "$@"
406 }
407
408 function list_lttng_with_opts ()
409 {
410 local opts=$1
411 $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
412 ok $? "Lttng-tool list command with option $opts"
413 }
414
415 function create_lttng_session_no_output ()
416 {
417 local sess_name=$1
418
419 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
420 ok $? "Create session $sess_name in no-output mode"
421 }
422
423 function create_lttng_session ()
424 {
425 local expected_to_fail=$1
426 local sess_name=$2
427 local trace_path=$3
428
429 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path > $OUTPUT_DEST
430 ret=$?
431 if [[ $expected_to_fail -eq "1" ]]; then
432 test "$ret" -ne "0"
433 ok $? "Expected fail on session creation $sess_name in $trace_path"
434 else
435 ok $ret "Create session $sess_name in $trace_path"
436 fi
437 }
438
439 function create_lttng_session_ok ()
440 {
441 create_lttng_session 0 "$@"
442 }
443
444 function create_lttng_session_fail ()
445 {
446 create_lttng_session 1 "$@"
447 }
448
449
450 function enable_ust_lttng_channel ()
451 {
452 local expect_fail=$1
453 local sess_name=$2
454 local channel_name=$3
455
456 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
457 ret=$?
458 if [[ $expect_fail -eq "1" ]]; then
459 test "$ret" -ne "0"
460 ok $? "Expected fail on ust channel creation $channel_name in $sess_name"
461 else
462 ok $ret "Enable channel $channel_name for session $sess_name"
463 fi
464 }
465
466 function enable_ust_lttng_channel_ok ()
467 {
468 enable_ust_lttng_channel 0 "$@"
469 }
470
471 function enable_ust_lttng_channel_fail ()
472 {
473 enable_ust_lttng_channel 1 "$@"
474 }
475
476 function disable_ust_lttng_channel()
477 {
478 local sess_name=$1
479 local channel_name=$2
480
481 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
482 ok $? "Disable channel $channel_name for session $sess_name"
483 }
484
485 function enable_lttng_mmap_overwrite_kernel_channel()
486 {
487 local sess_name=$1
488 local channel_name=$2
489
490 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
491 ok $? "Enable channel $channel_name for session $sess_name"
492 }
493
494 function enable_lttng_mmap_overwrite_ust_channel()
495 {
496 local sess_name=$1
497 local channel_name=$2
498
499 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
500 ok $? "Enable channel $channel_name for session $sess_name"
501 }
502
503 function enable_ust_lttng_event ()
504 {
505 local expected_to_fail=$1
506 local sess_name=$2
507 local event_name="$3"
508 local channel_name=$4
509
510 if [ -z $channel_name ]; then
511 # default channel if none specified
512 chan=""
513 else
514 chan="-c $channel_name"
515 fi
516
517 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
518 ret=$?
519 if [[ $expected_to_fail -eq "1" ]]; then
520 test $ret -ne "0"
521 ok $? "Enable ust event $event_name for session $session_name on channel $channel_name failed as expected"
522 else
523 ok $ret "Enable event $event_name for session $sess_name"
524 fi
525 }
526
527 function enable_ust_lttng_event_ok ()
528 {
529 enable_ust_lttng_event 0 "$@"
530 }
531
532 function enable_ust_lttng_event_fail ()
533 {
534 enable_ust_lttng_event 1 "$@"
535 }
536
537 function enable_jul_lttng_event()
538 {
539 sess_name=$1
540 event_name="$2"
541 channel_name=$3
542
543 if [ -z $channel_name ]; then
544 # default channel if none specified
545 chan=""
546 else
547 chan="-c $channel_name"
548 fi
549
550 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
551 ok $? "Enable JUL event $event_name for session $sess_name"
552 }
553
554 function enable_jul_lttng_event_loglevel()
555 {
556 local sess_name=$1
557 local event_name="$2"
558 local loglevel=$3
559 local channel_name=$4
560
561 if [ -z $channel_name ]; then
562 # default channel if none specified
563 chan=""
564 else
565 chan="-c $channel_name"
566 fi
567
568 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
569 ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
570 }
571
572 function enable_log4j_lttng_event()
573 {
574 sess_name=$1
575 event_name="$2"
576 channel_name=$3
577
578 if [ -z $channel_name ]; then
579 # default channel if none specified
580 chan=""
581 else
582 chan="-c $channel_name"
583 fi
584
585 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
586 ok $? "Enable LOG4J event $event_name for session $sess_name"
587 }
588
589 function enable_log4j_lttng_event_loglevel()
590 {
591 local sess_name=$1
592 local event_name="$2"
593 local loglevel=$3
594 local channel_name=$4
595
596 if [ -z $channel_name ]; then
597 # default channel if none specified
598 chan=""
599 else
600 chan="-c $channel_name"
601 fi
602
603 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
604 ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
605 }
606
607 function enable_python_lttng_event()
608 {
609 sess_name=$1
610 event_name="$2"
611 channel_name=$3
612
613 if [ -z $channel_name ]; then
614 # default channel if none specified
615 chan=""
616 else
617 chan="-c $channel_name"
618 fi
619
620 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
621 ok $? "Enable Python event $event_name for session $sess_name"
622 }
623
624 function enable_python_lttng_event_loglevel()
625 {
626 local sess_name=$1
627 local event_name="$2"
628 local loglevel=$3
629 local channel_name=$4
630
631 if [ -z $channel_name ]; then
632 # default channel if none specified
633 chan=""
634 else
635 chan="-c $channel_name"
636 fi
637
638 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
639 ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel"
640 }
641
642 function enable_ust_lttng_event_filter()
643 {
644 local sess_name="$1"
645 local event_name="$2"
646 local filter="$3"
647
648 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
649 ok $? "Enable event $event_name with filtering for session $sess_name"
650 }
651
652 function enable_ust_lttng_event_loglevel()
653 {
654 local sess_name="$1"
655 local event_name="$2"
656 local loglevel="$3"
657
658 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
659 ok $? "Enable event $event_name with loglevel $loglevel"
660 }
661
662 function enable_ust_lttng_event_loglevel_only()
663 {
664 local sess_name="$1"
665 local event_name="$2"
666 local loglevel="$3"
667
668 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
669 ok $? "Enable event $event_name with loglevel-only $loglevel"
670 }
671
672 function disable_ust_lttng_event ()
673 {
674 local sess_name="$1"
675 local event_name="$2"
676 local channel_name="$3"
677
678 if [ -z $channel_name ]; then
679 # default channel if none specified
680 chan=""
681 else
682 chan="-c $channel_name"
683 fi
684
685 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
686 ok $? "Disable event $event_name for session $sess_name"
687 }
688
689 function disable_jul_lttng_event ()
690 {
691 local sess_name="$1"
692 local event_name="$2"
693
694 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1
695 ok $? "Disable JUL event $event_name for session $sess_name"
696 }
697
698 function disable_log4j_lttng_event ()
699 {
700 local sess_name="$1"
701 local event_name="$2"
702
703 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1
704 ok $? "Disable LOG4J event $event_name for session $sess_name"
705 }
706
707 function disable_python_lttng_event ()
708 {
709 local sess_name="$1"
710 local event_name="$2"
711
712 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
713 ok $? "Disable Python event $event_name for session $sess_name"
714 }
715
716 function start_lttng_tracing ()
717 {
718 local expected_to_fail=$1
719 local sess_name=$2
720
721 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
722 ret=$?
723 if [[ $expected_to_fail -eq "1" ]]; then
724 test "$ret" -ne "0"
725 ok $? "Expected fail on start tracing for session: $sess_name"
726 else
727 ok $ret "Start tracing for session $sess_name"
728 fi
729 }
730
731 function start_lttng_tracing_ok ()
732 {
733 start_lttng_tracing 0 "$@"
734 }
735
736 function start_lttng_tracing_fail ()
737 {
738 start_lttng_tracing 1 "$@"
739 }
740
741 function stop_lttng_tracing ()
742 {
743 local expected_to_fail=$1
744 local sess_name=$2
745
746 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
747 ret=$?
748 if [[ $expected_to_fail -eq "1" ]]; then
749 test "$ret" -ne "0"
750 ok $? "Expected fail on stop tracing for session: $sess_name"
751 else
752 ok $ret "Stop lttng tracing for session $sess_name"
753 fi
754 }
755
756 function stop_lttng_tracing_ok ()
757 {
758 stop_lttng_tracing 0 "$@"
759 }
760
761 function stop_lttng_tracing_fail ()
762 {
763 stop_lttng_tracing 1 "$@"
764 }
765
766 function destroy_lttng_session ()
767 {
768 local expected_to_fail=$1
769 local sess_name=$2
770
771 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
772 ret=$?
773 if [[ $expected_to_fail -eq "1" ]]; then
774 test "$ret" -ne "0"
775 ok $? "Expected fail on session deletion $sess_name"
776 else
777 ok $ret "Destroy session $sess_name"
778 fi
779 }
780
781 function destroy_lttng_session_ok ()
782 {
783 destroy_lttng_session 0 "$@"
784
785 }
786
787 function destroy_lttng_session_fail ()
788 {
789 destroy_lttng_session 1 "$@"
790 }
791
792
793 function destroy_lttng_sessions ()
794 {
795 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
796 ok $? "Destroy all lttng sessions"
797 }
798
799 function lttng_snapshot_add_output ()
800 {
801 local expected_to_fail=$1
802 local sess_name=$2
803 local trace_path=$3
804
805 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name file://$trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
806 ret=$?
807 if [[ $expected_to_fail -eq 1 ]]; then
808 test "$ret" -ne "0"
809 ok $? "Failed to add a snapshot output file://$trace_path as expected"
810 else
811 ok $ret "Added snapshot output file://$trace_path"
812 fi
813 }
814
815 function lttng_snapshot_add_output_ok ()
816 {
817 lttng_snapshot_add_output 0 "$@"
818 }
819
820 function lttng_snapshot_add_output_fail ()
821 {
822 lttng_snapshot_add_output 1 "$@"
823 }
824
825 function lttng_snapshot_del_output ()
826 {
827 local expected_to_fail=$1
828 local sess_name=$2
829 local id=$3
830
831 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
832 ret=$?
833 if [[ $expected_to_fail -eq "1" ]]; then
834 test "$ret" -ne "0"
835 ok $? "Expect fail on deletion of snapshot output id $id"
836 else
837 ok $ret "Deleted snapshot output id $id"
838 fi
839 }
840
841 function lttng_snapshot_del_output_ok ()
842 {
843 lttng_snapshot_del_output 0 "$@"
844 }
845
846 function lttng_snapshot_del_output_fail ()
847 {
848 lttng_snapshot_del_output 1 "$@"
849 }
850
851 function lttng_snapshot_record ()
852 {
853 local sess_name=$1
854 local trace_path=$2
855
856 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
857 ok $? "Snapshot recorded"
858 }
859
860 function lttng_snapshot_list ()
861 {
862 local sess_name=$1
863 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
864 ok $? "Snapshot list"
865 }
866
867 function lttng_save()
868 {
869 local sess_name=$1
870 local opts=$2
871
872 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
873 ok $? "Session successfully saved"
874 }
875
876 function lttng_load()
877 {
878 local opts=$1
879
880 $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
881 ok $? "Load command successful"
882 }
883
884 function lttng_track()
885 {
886 local expected_to_fail=$1
887 local opts=$2
888 $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST
889 ret=$?
890 if [[ $expected_to_fail -eq "1" ]]; then
891 test $ret -ne "0"
892 ok $? "Track command failed as expected with opts: $opts"
893 else
894 ok $ret "Track command success as expected with opts: $opts"
895 fi
896 }
897
898 function lttng_track_ok()
899 {
900 lttng_track 0 "$@"
901 }
902
903 function lttng_track_fail()
904 {
905 lttng_track 1 "$@"
906 }
907
908 function lttng_untrack()
909 {
910 local expected_to_fail=$1
911 local opts=$2
912 $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST
913 ret=$?
914 if [[ $expected_to_fail -eq "1" ]]; then
915 test $ret -ne "0"
916 ok $? "Untrack command failed as expected with opts: $opts"
917 else
918 ok $ret "Untrack command success as expected with opts: $opts"
919 fi
920 }
921
922 function lttng_untrack_ok()
923 {
924 lttng_untrack 0 "$@"
925 }
926
927 function lttng_untrack_fail()
928 {
929 lttng_untrack 1 "$@"
930 }
931
932 function trace_matches ()
933 {
934 local event_name=$1
935 local nr_iter=$2
936 local trace_path=$3
937
938 which $BABELTRACE_BIN >/dev/null
939 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
940
941 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
942
943 if [ "$count" -ne "$nr_iter" ]; then
944 fail "Trace match"
945 diag "$count events found in trace"
946 else
947 pass "Trace match"
948 fi
949 }
950
951 function trace_match_only()
952 {
953 local event_name=$1
954 local nr_iter=$2
955 local trace_path=$3
956
957 which $BABELTRACE_BIN >/dev/null
958 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
959
960 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
961 local total=$($BABELTRACE_BIN $trace_path | wc -l)
962
963 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
964 pass "Trace match with $total event $event_name"
965 else
966 fail "Trace match"
967 diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
968 fi
969 }
970
971 function validate_trace
972 {
973 local event_name=$1
974 local trace_path=$2
975
976 which $BABELTRACE_BIN >/dev/null
977 if [ $? -ne 0 ]; then
978 skip 0 "Babeltrace binary not found. Skipping trace validation"
979 fi
980
981 OLDIFS=$IFS
982 IFS=","
983 for i in $event_name; do
984 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
985 if [ "$traced" -ne 0 ]; then
986 pass "Validate trace for event $i, $traced events"
987 else
988 fail "Validate trace for event $i"
989 diag "Found $traced occurences of $i"
990 fi
991 done
992 ret=$?
993 IFS=$OLDIFS
994 return $ret
995 }
996
997 function validate_trace_exp()
998 {
999 local event_exp=$1
1000 local trace_path=$2
1001
1002 which $BABELTRACE_BIN >/dev/null
1003 skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
1004
1005 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep ${event_exp} | wc -l)
1006 if [ "$traced" -ne 0 ]; then
1007 pass "Validate trace for expression '${event_exp}', $traced events"
1008 else
1009 fail "Validate trace for expression '${event_exp}'"
1010 diag "Found $traced occurences of '${event_exp}'"
1011 fi
1012 ret=$?
1013 return $ret
1014 }
1015
1016 function validate_trace_only_exp()
1017 {
1018 local event_exp=$1
1019 local trace_path=$2
1020
1021 which $BABELTRACE_BIN >/dev/null
1022 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1023
1024 local count=$($BABELTRACE_BIN $trace_path | grep ${event_exp} | wc -l)
1025 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1026
1027 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1028 pass "Trace match with $total for expression '${event_exp}"
1029 else
1030 fail "Trace match"
1031 diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1032 fi
1033 ret=$?
1034 return $ret
1035 }
1036
1037 function validate_trace_empty()
1038 {
1039 local trace_path=$1
1040
1041 which $BABELTRACE_BIN >/dev/null
1042 if [ $? -ne 0 ]; then
1043 skip 0 "Babeltrace binary not found. Skipping trace validation"
1044 fi
1045
1046 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | wc -l)
1047 if [ "$traced" -eq 0 ]; then
1048 pass "Validate empty trace"
1049 else
1050 fail "Validate empty trace"
1051 diag "Found $traced events in trace"
1052 fi
1053 ret=$?
1054 return $ret
1055 }
This page took 0.083824 seconds and 4 git commands to generate.