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