Tests: wording of trace_matches is misleading
[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 # We set the default lttng-sessiond path to /bin/true to prevent the spawning
37 # of a daemonized sessiond. This is necessary since 'lttng create' will spawn
38 # its own sessiond if none is running. It also ensures that 'lttng create'
39 # fails when no sessiond is running.
40 export LTTNG_SESSIOND_PATH="/bin/true"
41
42 source $TESTDIR/utils/tap/tap.sh
43
44 function print_ok ()
45 {
46 # Check if we are a terminal
47 if [ -t 1 ]; then
48 echo -e "\e[1;32mOK\e[0m"
49 else
50 echo -e "OK"
51 fi
52 }
53
54 function print_fail ()
55 {
56 # Check if we are a terminal
57 if [ -t 1 ]; then
58 echo -e "\e[1;31mFAIL\e[0m"
59 else
60 echo -e "FAIL"
61 fi
62 }
63
64 function print_test_banner ()
65 {
66 local desc="$1"
67 diag "$desc"
68 }
69
70 function validate_kernel_version ()
71 {
72 local kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n'))
73 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
74 return 0
75 fi
76 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
77 return 0
78 fi
79 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
80 return 0
81 fi
82 return 1
83 }
84
85 # Generate a random string
86 # $1 = number of characters; defaults to 16
87 # $2 = include special characters; 1 = yes, 0 = no; defaults to yes
88 function randstring()
89 {
90 [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
91 cat /dev/urandom 2>/dev/null | tr -cd "$CHAR" 2>/dev/null | head -c ${1:-16} 2>/dev/null
92 echo
93 }
94
95 # Return the number of _configured_ CPUs.
96 function conf_proc_count()
97 {
98 getconf _NPROCESSORS_CONF
99 if [ $? -ne 0 ]; then
100 diag "Failed to get the number of configured CPUs"
101 fi
102 echo
103 }
104
105 function lttng_enable_kernel_event
106 {
107 local sess_name=$1
108 local event_name=$2
109 local channel_name=$3
110
111 if [ -z $event_name ]; then
112 # Enable all event if no event name specified
113 event_name="-a"
114 fi
115
116 if [ -z $channel_name ]; then
117 # default channel if none specified
118 chan=""
119 else
120 chan="-c $channel_name"
121 fi
122
123 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
124 ok $? "Enable kernel event $event_name for session $sess_name"
125 }
126
127 function lttng_enable_kernel_syscall()
128 {
129 local expected_to_fail=$1
130 local sess_name=$2
131 local syscall_name=$3
132 local channel_name=$4
133
134 if [ -z $syscall_name ]; then
135 # Enable all event if no syscall name specified
136 syscall_name="-a"
137 fi
138
139 if [ -z $channel_name ]; then
140 # default channel if none specified
141 chan=""
142 else
143 chan="-c $channel_name"
144 fi
145
146 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
147 ret=$?
148 if [[ $expected_to_fail -eq "1" ]]; then
149 test $ret -ne "0"
150 ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
151 else
152 ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
153 fi
154 }
155
156 function lttng_enable_kernel_syscall_ok()
157 {
158 lttng_enable_kernel_syscall 0 ${*}
159 }
160
161 function lttng_enable_kernel_syscall_fail()
162 {
163 lttng_enable_kernel_syscall 1 ${*}
164 }
165
166 function lttng_disable_kernel_syscall()
167 {
168 local expected_to_fail=$1
169 local sess_name=$2
170 local syscall_name=$3
171 local channel_name=$4
172
173 if [ -z $syscall_name ]; then
174 # Enable all event if no syscall name specified
175 syscall_name="-a"
176 fi
177
178 if [ -z $channel_name ]; then
179 # default channel if none specified
180 chan=""
181 else
182 chan="-c $channel_name"
183 fi
184
185 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
186
187 ret=$?
188 if [[ $expected_to_fail -eq "1" ]]; then
189 test $ret -ne "0"
190 ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
191 else
192 ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
193 fi
194 }
195
196 function lttng_disable_kernel_syscall_ok()
197 {
198 lttng_disable_kernel_syscall 0 ${*}
199 }
200
201 function lttng_disable_kernel_syscall_fail()
202 {
203 lttng_disable_kernel_syscall 1 ${*}
204 }
205
206 function lttng_enable_kernel_channel()
207 {
208 local expected_to_fail=$1
209 local sess_name=$2
210 local channel_name=$3
211
212 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
213 ret=$?
214 if [[ $expected_to_fail -eq "1" ]]; then
215 test "$ret" -ne "0"
216 ok $? "Expected failure on kernel channel creation $channel_name in $sess_name"
217 else
218 ok $ret "Enable channel $channel_name for session $sess_name"
219 fi
220 }
221
222 function lttng_enable_kernel_channel_ok()
223 {
224 lttng_enable_kernel_channel 0 ${*}
225 }
226
227 function lttng_enable_kernel_channel_fail()
228 {
229 lttng_enable_kernel_channel 1 ${*}
230 }
231
232 function lttng_disable_kernel_channel()
233 {
234 local expected_to_fail=$1
235 local sess_name=$2
236 local channel_name=$3
237
238 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
239 ret=$?
240 if [[ $expected_to_fail -eq "1" ]]; then
241 test "$ret" -ne "0"
242 ok $? "Expected failure on kernel channel creation $channel_name in $sess_name"
243 else
244 ok $ret "disable channel $channel_name for session $sess_name"
245 fi
246 }
247
248 function lttng_disable_kernel_channel_ok()
249 {
250 lttng_disable_kernel_channel 0 ${*}
251 }
252
253 function lttng_disable_kernel_channel_fail()
254 {
255 lttng_disable_kernel_channel 1 ${*}
256 }
257
258 function start_lttng_relayd_opt()
259 {
260 local withtap=$1
261 local opt=$2
262
263 DIR=$(readlink -f $TESTDIR)
264
265 if [ -z $(pidof lt-$RELAYD_BIN) ]; then
266 $DIR/../src/bin/lttng-relayd/$RELAYD_BIN -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
267 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
268 if [ $? -eq 1 ]; then
269 if [ $withtap -eq "1" ]; then
270 fail "Start lttng-relayd (opt: $opt)"
271 fi
272 return 1
273 else
274 if [ $withtap -eq "1" ]; then
275 pass "Start lttng-relayd (opt: $opt)"
276 fi
277 fi
278 else
279 pass "Start lttng-relayd (opt: $opt)"
280 fi
281 }
282
283 function start_lttng_relayd()
284 {
285 start_lttng_relayd_opt 1 "$@"
286 }
287
288 function start_lttng_relayd_notap()
289 {
290 start_lttng_relayd_opt 0 "$@"
291 }
292
293 function stop_lttng_relayd_opt()
294 {
295 local withtap=$1
296
297 PID_RELAYD=`pidof lt-$RELAYD_BIN`
298
299 if [ $withtap -eq "1" ]; then
300 diag "Killing lttng-relayd (pid: $PID_RELAYD)"
301 fi
302 kill $PID_RELAYD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
303 retval=$?
304
305 if [ $? -eq 1 ]; then
306 if [ $withtap -eq "1" ]; then
307 fail "Kill relay daemon"
308 fi
309 return 1
310 else
311 out=1
312 while [ -n "$out" ]; do
313 out=$(pidof lt-$RELAYD_BIN)
314 sleep 0.5
315 done
316 if [ $withtap -eq "1" ]; then
317 pass "Kill relay daemon"
318 fi
319 fi
320 return $retval
321 }
322
323 function stop_lttng_relayd()
324 {
325 stop_lttng_relayd_opt 1 "$@"
326 }
327
328 function stop_lttng_relayd_notap()
329 {
330 stop_lttng_relayd_opt 0 "$@"
331 }
332
333 #First arg: show tap output
334 #Second argument: load path for automatic loading
335 function start_lttng_sessiond_opt()
336 {
337 local withtap=$1
338 local load_path=$2
339
340 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
341 # Env variable requested no session daemon
342 return
343 fi
344
345 validate_kernel_version
346 if [ $? -ne 0 ]; then
347 fail "Start session daemon"
348 BAIL_OUT "*** Kernel too old for session daemon tests ***"
349 fi
350
351 DIR=$(readlink -f $TESTDIR)
352 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
353 export LTTNG_SESSION_CONFIG_XSD_PATH
354
355 if [ -z $(pidof lt-$SESSIOND_BIN) ]; then
356 # Have a load path ?
357 if [ -n "$load_path" ]; then
358 $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"
359 else
360 $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"
361 fi
362 #$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
363 status=$?
364 if [ $withtap -eq "1" ]; then
365 ok $status "Start session daemon"
366 fi
367 fi
368 }
369
370 function start_lttng_sessiond()
371 {
372 start_lttng_sessiond_opt 1 "$@"
373 }
374
375 function start_lttng_sessiond_notap()
376 {
377 start_lttng_sessiond_opt 0 "$@"
378 }
379
380 function stop_lttng_sessiond_opt()
381 {
382 local withtap=$1
383
384 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
385 # Env variable requested no session daemon
386 return
387 fi
388
389 PID_SESSIOND=`pidof lt-$SESSIOND_BIN`
390
391 kill $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
392
393 if [ $? -eq 1 ]; then
394 if [ $withtap -eq "1" ]; then
395 fail "Kill sessions daemon"
396 fi
397 else
398 out=1
399 while [ -n "$out" ]; do
400 out=$(pidof lt-$SESSIOND_BIN)
401 sleep 0.5
402 done
403 out=1
404 while [ -n "$out" ]; do
405 out=$(pidof $CONSUMERD_BIN)
406 sleep 0.5
407 done
408 if [ $withtap -eq "1" ]; then
409 pass "Kill session daemon"
410 fi
411 fi
412 }
413
414 function stop_lttng_sessiond()
415 {
416 stop_lttng_sessiond_opt 1 "$@"
417 }
418
419 function stop_lttng_sessiond_notap()
420 {
421 stop_lttng_sessiond_opt 0 "$@"
422 }
423
424 function list_lttng_with_opts ()
425 {
426 local opts=$1
427 $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
428 ok $? "Lttng-tool list command with option $opts"
429 }
430
431 function create_lttng_session_no_output ()
432 {
433 local sess_name=$1
434
435 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
436 ok $? "Create session $sess_name in no-output mode"
437 }
438
439 function create_lttng_session ()
440 {
441 local sess_name=$1
442 local trace_path=$2
443 local expected_to_fail=$3
444
445 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path > $OUTPUT_DEST
446 ret=$?
447 if [[ $expected_to_fail ]]; then
448 test "$ret" -ne "0"
449 ok $? "Expected fail on session creation $sess_name in $trace_path"
450 else
451 ok $ret "Create session $sess_name in $trace_path"
452 fi
453 }
454
455 function enable_ust_lttng_channel()
456 {
457 local sess_name=$1
458 local channel_name=$2
459 local expect_fail=$3
460
461 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
462 ret=$?
463 if [[ $expect_fail ]]; then
464 test "$ret" -ne "0"
465 ok $? "Expected fail on ust channel creation $channel_name in $sess_name"
466 else
467 ok $ret "Enable channel $channel_name for session $sess_name"
468 fi
469 }
470
471 function disable_ust_lttng_channel()
472 {
473 local sess_name=$1
474 local channel_name=$2
475
476 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
477 ok $? "Disable channel $channel_name for session $sess_name"
478 }
479
480 function enable_lttng_mmap_overwrite_kernel_channel()
481 {
482 local sess_name=$1
483 local channel_name=$2
484
485 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
486 ok $? "Enable channel $channel_name for session $sess_name"
487 }
488
489 function enable_lttng_mmap_overwrite_ust_channel()
490 {
491 local sess_name=$1
492 local channel_name=$2
493
494 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
495 ok $? "Enable channel $channel_name for session $sess_name"
496 }
497
498 function enable_ust_lttng_event ()
499 {
500 local sess_name=$1
501 local event_name="$2"
502 local channel_name=$3
503 local expected_to_fail=$4
504
505 if [ -z $channel_name ]; then
506 # default channel if none specified
507 chan=""
508 else
509 chan="-c $channel_name"
510 fi
511
512 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
513 ret=$?
514 if [[ $expected_to_fail ]]; then
515 test $ret -ne "0"
516 ok $? "Enable ust event $event_name for session $session_name on channel $channel_name failed as expected"
517 else
518 ok $ret "Enable event $event_name for session $sess_name"
519 fi
520 }
521
522 function enable_jul_lttng_event()
523 {
524 sess_name=$1
525 event_name="$2"
526 channel_name=$3
527
528 if [ -z $channel_name ]; then
529 # default channel if none specified
530 chan=""
531 else
532 chan="-c $channel_name"
533 fi
534
535 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
536 ok $? "Enable JUL event $event_name for session $sess_name"
537 }
538
539 function enable_jul_lttng_event_loglevel()
540 {
541 local sess_name=$1
542 local event_name="$2"
543 local loglevel=$3
544 local channel_name=$4
545
546 if [ -z $channel_name ]; then
547 # default channel if none specified
548 chan=""
549 else
550 chan="-c $channel_name"
551 fi
552
553 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
554 ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
555 }
556
557 function enable_log4j_lttng_event()
558 {
559 sess_name=$1
560 event_name="$2"
561 channel_name=$3
562
563 if [ -z $channel_name ]; then
564 # default channel if none specified
565 chan=""
566 else
567 chan="-c $channel_name"
568 fi
569
570 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
571 ok $? "Enable LOG4J event $event_name for session $sess_name"
572 }
573
574 function enable_log4j_lttng_event_loglevel()
575 {
576 local sess_name=$1
577 local event_name="$2"
578 local loglevel=$3
579 local channel_name=$4
580
581 if [ -z $channel_name ]; then
582 # default channel if none specified
583 chan=""
584 else
585 chan="-c $channel_name"
586 fi
587
588 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
589 ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
590 }
591
592 function enable_ust_lttng_event_filter()
593 {
594 local sess_name="$1"
595 local event_name="$2"
596 local filter="$3"
597
598 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
599 ok $? "Enable event $event_name with filtering for session $sess_name"
600 }
601
602 function enable_ust_lttng_event_loglevel()
603 {
604 local sess_name="$1"
605 local event_name="$2"
606 local loglevel="$3"
607
608 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
609 ok $? "Enable event $event_name with loglevel $loglevel"
610 }
611
612 function enable_ust_lttng_event_loglevel_only()
613 {
614 local sess_name="$1"
615 local event_name="$2"
616 local loglevel="$3"
617
618 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
619 ok $? "Enable event $event_name with loglevel-only $loglevel"
620 }
621
622 function disable_ust_lttng_event ()
623 {
624 local sess_name="$1"
625 local event_name="$2"
626 local channel_name="$3"
627
628 if [ -z $channel_name ]; then
629 # default channel if none specified
630 chan=""
631 else
632 chan="-c $channel_name"
633 fi
634
635 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
636 ok $? "Disable event $event_name for session $sess_name"
637 }
638
639 function disable_jul_lttng_event ()
640 {
641 local sess_name="$1"
642 local event_name="$2"
643
644 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1
645 ok $? "Disable JUL event $event_name for session $sess_name"
646 }
647
648 function disable_log4j_lttng_event ()
649 {
650 local sess_name="$1"
651 local event_name="$2"
652
653 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1
654 ok $? "Disable LOG4J event $event_name for session $sess_name"
655 }
656
657 function start_lttng_tracing ()
658 {
659 local sess_name=$1
660 local expected_to_fail=$2
661
662 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
663 ret=$?
664 if [[ $expected_to_fail ]]; then
665 test "$ret" -ne "0"
666 ok $? "Expected fail on start tracing for session: $sess_name"
667 else
668 ok $ret "Start tracing for session $sess_name"
669 fi
670 }
671
672 function stop_lttng_tracing ()
673 {
674 local sess_name=$1
675 local expected_to_fail=$2
676
677 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
678 ret=$?
679 if [[ $expected_to_fail ]]; then
680 test "$ret" -ne "0"
681 ok $? "Expected fail on stop tracing for session: $sess_name"
682 else
683 ok $ret "Stop lttng tracing for session $sess_name"
684 fi
685 }
686
687 function destroy_lttng_session ()
688 {
689 local sess_name=$1
690 local expected_to_fail=$2
691
692 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
693 ret=$?
694 if [[ $expected_to_fail ]]; then
695 test "$ret" -ne "0"
696 ok $? "Expected fail on session deletion $sess_name"
697 else
698 ok $ret "Destroy session $sess_name"
699 fi
700 }
701
702 function destroy_lttng_sessions ()
703 {
704 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
705 ok $? "Destroy all lttng sessions"
706 }
707
708 function lttng_snapshot_add_output ()
709 {
710 local sess_name=$1
711 local trace_path=$2
712 local expected_to_fail=$3
713
714 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name file://$trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
715 ret=$?
716 if [[ $expected_to_fail ]]; then
717 test "$ret" -ne "0"
718 ok $? "Failed to add a snapshot output file://$trace_path as expected"
719 else
720 ok $ret "Added snapshot output file://$trace_path"
721 fi
722 }
723
724 function lttng_snapshot_del_output ()
725 {
726 local sess_name=$1
727 local id=$2
728 local expected_to_fail=$3
729
730 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
731 ret=$?
732 if [[ $expected_to_fail ]]; then
733 test "$ret" -ne "0"
734 ok $? "Expect fail on deletion of snapshot output id $id"
735 else
736 ok $ret "Deleted snapshot output id $id"
737 fi
738 }
739
740 function lttng_snapshot_record ()
741 {
742 local sess_name=$1
743 local trace_path=$2
744
745 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
746 ok $? "Snapshot recorded"
747 }
748
749 function lttng_snapshot_list ()
750 {
751 local sess_name=$1
752 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
753 ok $? "Snapshot list"
754 }
755
756 function lttng_save()
757 {
758 local sess_name=$1
759 local opts=$2
760
761 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
762 ok $? "Session successfully saved"
763 }
764
765 function lttng_load()
766 {
767 local opts=$1
768
769 $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
770 ok $? "Load command successful"
771 }
772
773 function trace_matches ()
774 {
775 local event_name=$1
776 local nr_iter=$2
777 local trace_path=$3
778
779 which $BABELTRACE_BIN >/dev/null
780 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
781
782 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
783
784 if [ "$count" -ne "$nr_iter" ]; then
785 fail "Trace match"
786 diag "$count matching events found in trace"
787 else
788 pass "Trace match"
789 fi
790 }
791
792 function trace_match_only()
793 {
794 local event_name=$1
795 local nr_iter=$2
796 local trace_path=$3
797
798 which $BABELTRACE_BIN >/dev/null
799 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
800
801 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
802 local total=$($BABELTRACE_BIN $trace_path | wc -l)
803
804 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
805 pass "Trace match with $total event $event_name"
806 else
807 fail "Trace match"
808 diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
809 fi
810 }
811
812 function validate_trace
813 {
814 local event_name=$1
815 local trace_path=$2
816
817 which $BABELTRACE_BIN >/dev/null
818 if [ $? -ne 0 ]; then
819 skip 0 "Babeltrace binary not found. Skipping trace validation"
820 fi
821
822 OLDIFS=$IFS
823 IFS=","
824 for i in $event_name; do
825 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
826 if [ "$traced" -ne 0 ]; then
827 pass "Validate trace for event $i, $traced events"
828 else
829 fail "Validate trace for event $i"
830 diag "Found $traced occurences of $i"
831 fi
832 done
833 ret=$?
834 IFS=$OLDIFS
835 return $ret
836 }
837
838 function validate_trace_exp()
839 {
840 local event_exp=$1
841 local trace_path=$2
842
843 which $BABELTRACE_BIN >/dev/null
844 skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
845
846 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep ${event_exp} | wc -l)
847 if [ "$traced" -ne 0 ]; then
848 pass "Validate trace for expression '${event_exp}', $traced events"
849 else
850 fail "Validate trace for expression '${event_exp}'"
851 diag "Found $traced occurences of '${event_exp}'"
852 fi
853 ret=$?
854 return $ret
855 }
856
857 function validate_trace_only_exp()
858 {
859 local event_exp=$1
860 local trace_path=$2
861
862 which $BABELTRACE_BIN >/dev/null
863 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
864
865 local count=$($BABELTRACE_BIN $trace_path | grep ${event_exp} | wc -l)
866 local total=$($BABELTRACE_BIN $trace_path | wc -l)
867
868 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
869 pass "Trace match with $total for expression '${event_exp}"
870 else
871 fail "Trace match"
872 diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
873 fi
874 ret=$?
875 return $ret
876 }
877
878 function validate_trace_empty()
879 {
880 local trace_path=$1
881
882 which $BABELTRACE_BIN >/dev/null
883 if [ $? -ne 0 ]; then
884 skip 0 "Babeltrace binary not found. Skipping trace validation"
885 fi
886
887 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | wc -l)
888 if [ "$traced" -eq 0 ]; then
889 pass "Validate empty trace"
890 else
891 fail "Validate empty trace"
892 diag "Found $traced events in trace"
893 fi
894 ret=$?
895 return $ret
896 }
This page took 0.050587 seconds and 4 git commands to generate.