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