Allow regenerating the statedump of a running session
[lttng-tools.git] / tests / utils / utils.sh
CommitLineData
10a8a223 1#!/src/bin/bash
d3e8f6bb
DG
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
18SESSIOND_BIN="lttng-sessiond"
725f658e 19SESSIOND_MATCH=".*lttng-sess.*"
1c362dc7 20SESSIOND_PIDS=""
19356f3a 21RUNAS_BIN="lttng-runas"
725f658e 22RUNAS_MATCH=".*lttng-runas.*"
f7613992 23CONSUMERD_BIN="lttng-consumerd"
725f658e 24CONSUMERD_MATCH=".*lttng-consumerd.*"
f4e40ab6 25RELAYD_BIN="lttng-relayd"
725f658e 26RELAYD_MATCH=".*lttng-relayd.*"
1c362dc7 27RELAYD_PIDS=""
d3e8f6bb
DG
28LTTNG_BIN="lttng"
29BABELTRACE_BIN="babeltrace"
2cf48300
JR
30OUTPUT_DEST=/dev/null
31ERROR_OUTPUT_DEST=/dev/null
d3e8f6bb 32
fd4dfcec
DG
33# Minimal kernel version supported for session daemon tests
34KERNEL_MAJOR_VERSION=2
35KERNEL_MINOR_VERSION=6
36KERNEL_PATCHLEVEL_VERSION=27
37
629b9335
MD
38# We set the default UST register timeout to "wait forever", so that
39# basic tests don't have to worry about hitting timeouts on busy
40# systems. Specialized tests should test those corner-cases.
41export LTTNG_UST_REGISTER_TIMEOUT=-1
42
fd7fe1a8
JR
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
29655db7
CB
49source $TESTDIR/utils/tap/tap.sh
50
1c362dc7
JR
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
fec81a7e
CB
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{
7d0ad314 89 local desc="$1"
29655db7 90 diag "$desc"
fec81a7e
CB
91}
92
fd4dfcec
DG
93function validate_kernel_version ()
94{
7d0ad314 95 local kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n'))
fd4dfcec
DG
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
9ac429ef 108# Generate a random string
f4e40ab6
DG
109# $1 = number of characters; defaults to 16
110# $2 = include special characters; 1 = yes, 0 = no; defaults to yes
9ac429ef 111function randstring()
f4e40ab6
DG
112{
113 [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
b89c3a68 114 cat /dev/urandom 2>/dev/null | tr -cd "$CHAR" 2>/dev/null | head -c ${1:-16} 2>/dev/null
f4e40ab6
DG
115 echo
116}
117
9e136324
JG
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
4a180d9f 128function enable_kernel_lttng_event
f4e40ab6 129{
4a180d9f
MD
130 local expected_to_fail="$1"
131 local sess_name="$2"
132 local event_name="$3"
133 local channel_name="$4"
f4e40ab6 134
4a180d9f 135 if [ -z "$event_name" ]; then
f4e40ab6 136 # Enable all event if no event name specified
29655db7 137 event_name="-a"
f4e40ab6
DG
138 fi
139
4a180d9f 140 if [ -z "$channel_name" ]; then
07b86b52
JD
141 # default channel if none specified
142 chan=""
143 else
144 chan="-c $channel_name"
145 fi
146
2cf48300 147 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
4a180d9f
MD
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 "$@"
f4e40ab6
DG
171}
172
8cfcd41c
MD
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
2cf48300 192 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
8cfcd41c
MD
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{
421b83dc 204 lttng_enable_kernel_syscall 0 "$@"
8cfcd41c
MD
205}
206
207function lttng_enable_kernel_syscall_fail()
208{
421b83dc 209 lttng_enable_kernel_syscall 1 "$@"
8cfcd41c
MD
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
2cf48300 231 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
8cfcd41c
MD
232
233 ret=$?
234 if [[ $expected_to_fail -eq "1" ]]; then
235 test $ret -ne "0"
34ab15c5 236 ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected"
8cfcd41c
MD
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{
421b83dc 244 lttng_disable_kernel_syscall 0 "$@"
8cfcd41c
MD
245}
246
247function lttng_disable_kernel_syscall_fail()
248{
421b83dc 249 lttng_disable_kernel_syscall 1 "$@"
8cfcd41c
MD
250}
251
d96f6315
MD
252function lttng_enable_kernel_channel()
253{
254 local expected_to_fail=$1
255 local sess_name=$2
256 local channel_name=$3
257
2cf48300 258 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
d96f6315
MD
259 ret=$?
260 if [[ $expected_to_fail -eq "1" ]]; then
261 test "$ret" -ne "0"
34ab15c5 262 ok $? "Enable channel $channel_name for session $sess_name failed as expected"
d96f6315
MD
263 else
264 ok $ret "Enable channel $channel_name for session $sess_name"
265 fi
266}
267
268function lttng_enable_kernel_channel_ok()
269{
421b83dc 270 lttng_enable_kernel_channel 0 "$@"
d96f6315
MD
271}
272
273function lttng_enable_kernel_channel_fail()
274{
421b83dc 275 lttng_enable_kernel_channel 1 "$@"
d96f6315
MD
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
2cf48300 284 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
d96f6315
MD
285 ret=$?
286 if [[ $expected_to_fail -eq "1" ]]; then
287 test "$ret" -ne "0"
34ab15c5 288 ok $? "Disable channel $channel_name for session $sess_name failed as expected"
d96f6315 289 else
34ab15c5 290 ok $ret "Disable channel $channel_name for session $sess_name"
d96f6315
MD
291 fi
292}
293
294function lttng_disable_kernel_channel_ok()
295{
421b83dc 296 lttng_disable_kernel_channel 0 "$@"
d96f6315
MD
297}
298
299function lttng_disable_kernel_channel_fail()
300{
421b83dc 301 lttng_disable_kernel_channel 1 "$@"
d96f6315
MD
302}
303
05aa48da 304function start_lttng_relayd_opt()
f4e40ab6 305{
05aa48da
MD
306 local withtap=$1
307 local opt=$2
173af62f 308
f4e40ab6
DG
309 DIR=$(readlink -f $TESTDIR)
310
725f658e 311 if [ -z $(pgrep $RELAYD_MATCH) ]; then
2cf48300 312 $DIR/../src/bin/lttng-relayd/$RELAYD_BIN -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
25a818af 313 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
f4e40ab6 314 if [ $? -eq 1 ]; then
05aa48da
MD
315 if [ $withtap -eq "1" ]; then
316 fail "Start lttng-relayd (opt: $opt)"
317 fi
f4e40ab6
DG
318 return 1
319 else
05aa48da
MD
320 if [ $withtap -eq "1" ]; then
321 pass "Start lttng-relayd (opt: $opt)"
322 fi
f4e40ab6
DG
323 fi
324 else
29655db7 325 pass "Start lttng-relayd (opt: $opt)"
f4e40ab6 326 fi
1c362dc7 327
725f658e 328 RELAYD_PIDS=$(pgrep $RELAYD_MATCH)
f4e40ab6
DG
329}
330
05aa48da 331function start_lttng_relayd()
f4e40ab6 332{
05aa48da
MD
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
05aa48da 345 if [ $withtap -eq "1" ]; then
1c362dc7 346 diag "Killing lttng-relayd (pid: $RELAYD_PIDS)"
05aa48da 347 fi
1c362dc7 348 kill $RELAYD_PIDS 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1fb23888 349 retval=$?
29655db7 350
05aa48da
MD
351 if [ $? -eq 1 ]; then
352 if [ $withtap -eq "1" ]; then
353 fail "Kill relay daemon"
354 fi
355 return 1
356 else
f4e40ab6
DG
357 out=1
358 while [ -n "$out" ]; do
725f658e 359 out=$(pgrep $RELAYD_MATCH)
f4e40ab6
DG
360 sleep 0.5
361 done
05aa48da
MD
362 if [ $withtap -eq "1" ]; then
363 pass "Kill relay daemon"
364 fi
1fb23888 365 fi
1c362dc7 366 RELAYD_PIDS=""
1fb23888
MD
367 return $retval
368}
369
05aa48da 370function stop_lttng_relayd()
1fb23888 371{
05aa48da
MD
372 stop_lttng_relayd_opt 1 "$@"
373}
1fb23888 374
05aa48da
MD
375function stop_lttng_relayd_notap()
376{
377 stop_lttng_relayd_opt 0 "$@"
f4e40ab6
DG
378}
379
05aa48da
MD
380#First arg: show tap output
381#Second argument: load path for automatic loading
382function start_lttng_sessiond_opt()
355f483d 383{
05aa48da
MD
384 local withtap=$1
385 local load_path=$2
8d51ddbc 386
355f483d
DG
387 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
388 # Env variable requested no session daemon
389 return
390 fi
391
29655db7
CB
392 validate_kernel_version
393 if [ $? -ne 0 ]; then
394 fail "Start session daemon"
395 BAIL_OUT "*** Kernel too old for session daemon tests ***"
355f483d
DG
396 fi
397
29655db7 398 DIR=$(readlink -f $TESTDIR)
d3d97763
JG
399 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
400 export LTTNG_SESSION_CONFIG_XSD_PATH
29655db7 401
725f658e 402 if [ -z $(pgrep ${SESSIOND_MATCH}) ]; then
8d51ddbc 403 # Have a load path ?
05aa48da 404 if [ -n "$load_path" ]; then
e4f8013b 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"
8d51ddbc
JRJ
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
0fc2834c 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
29655db7 410 status=$?
05aa48da
MD
411 if [ $withtap -eq "1" ]; then
412 ok $status "Start session daemon"
413 fi
29655db7 414 fi
725f658e 415 SESSIOND_PIDS=$(pgrep $SESSIOND_MATCH)
355f483d
DG
416}
417
05aa48da
MD
418function start_lttng_sessiond()
419{
420 start_lttng_sessiond_opt 1 "$@"
421}
422
423function start_lttng_sessiond_notap()
d3e8f6bb 424{
05aa48da
MD
425 start_lttng_sessiond_opt 0 "$@"
426}
427
428function stop_lttng_sessiond_opt()
429{
430 local withtap=$1
4c80129b
JR
431 local signal=$2
432 local kill_opt=""
05aa48da 433
355f483d
DG
434 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
435 # Env variable requested no session daemon
436 return
437 fi
438
725f658e 439 local pids="${SESSIOND_PIDS} $(pgrep $RUNAS_MATCH)"
d3e8f6bb 440
4c80129b
JR
441 if [ -n "$2" ]; then
442 kill_opt="$kill_opt -s $signal"
443 fi
8490897a 444 if [ $withtap -eq "1" ]; then
725f658e 445 diag "Killing $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo $pids | tr '\n' ' ')"
8490897a 446 fi
1c362dc7 447 kill $kill_opt $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 448
d3e8f6bb 449 if [ $? -eq 1 ]; then
05aa48da
MD
450 if [ $withtap -eq "1" ]; then
451 fail "Kill sessions daemon"
452 fi
d3e8f6bb 453 else
5fa32580
DG
454 out=1
455 while [ -n "$out" ]; do
725f658e 456 out=$(pgrep ${SESSIOND_MATCH})
5fa32580
DG
457 sleep 0.5
458 done
f7613992
MD
459 out=1
460 while [ -n "$out" ]; do
725f658e 461 out=$(pgrep $CONSUMERD_MATCH)
f7613992
MD
462 sleep 0.5
463 done
1c362dc7
JR
464
465 SESSIOND_PIDS=""
05aa48da
MD
466 if [ $withtap -eq "1" ]; then
467 pass "Kill session daemon"
468 fi
d3e8f6bb
DG
469 fi
470}
471
05aa48da
MD
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
8490897a
MD
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
725f658e 493 PID_SESSIOND="$(pgrep ${SESSIOND_MATCH}) $(pgrep $RUNAS_MATCH)"
8490897a
MD
494
495 kill_opt="$kill_opt -s $signal"
496
497 if [ $withtap -eq "1" ]; then
725f658e 498 diag "Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo $PID_SESSIOND | tr '\n' ' ')"
8490897a
MD
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
725f658e 509 pid=$(pgrep $SESSIOND_MATCH)
8490897a
MD
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
4c80129b
JR
538function stop_lttng_consumerd_opt()
539{
540 local withtap=$1
541 local signal=$2
542 local kill_opt=""
543
725f658e 544 PID_CONSUMERD=$(pgrep $CONSUMERD_MATCH)
4c80129b
JR
545
546 if [ -n "$2" ]; then
547 kill_opt="$kill_opt -s $signal"
548 fi
549
550 if [ $withtap -eq "1" ]; then
8490897a 551 diag "Killing $CONSUMERD_BIN pids: $(echo $PID_CONSUMERD | tr '\n' ' ')"
4c80129b
JR
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
725f658e 565 pid=$(pgrep $CONSUMERD_MATCH)
4c80129b
JR
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
8490897a
MD
595function sigstop_lttng_consumerd_opt()
596{
597 local withtap=$1
598 local signal=SIGSTOP
599 local kill_opt=""
600
725f658e 601 PID_CONSUMERD=$(pgrep $CONSUMERD_MATCH)
8490897a
MD
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
725f658e 620 pid=$(pgrep $CONSUMERD_MATCH)
8490897a
MD
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
873c2aae
JRJ
650function list_lttng_with_opts ()
651{
7d0ad314 652 local opts=$1
2cf48300 653 $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
873c2aae
JRJ
654 ok $? "Lttng-tool list command with option $opts"
655}
656
07b86b52
JD
657function create_lttng_session_no_output ()
658{
7d0ad314 659 local sess_name=$1
07b86b52 660
2cf48300 661 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
07b86b52
JD
662 ok $? "Create session $sess_name in no-output mode"
663}
664
d3e8f6bb
DG
665function create_lttng_session ()
666{
bf6ae429
JR
667 local expected_to_fail=$1
668 local sess_name=$2
669 local trace_path=$3
4c80129b 670 local opt=$4
d3e8f6bb 671
4c80129b 672 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path $opt > $OUTPUT_DEST
873c2aae 673 ret=$?
bf6ae429 674 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 675 test "$ret" -ne "0"
34ab15c5 676 ok $? "Create session $sess_name in $trace_path failed as expected"
873c2aae
JRJ
677 else
678 ok $ret "Create session $sess_name in $trace_path"
679 fi
d4018451
DG
680}
681
bf6ae429
JR
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
827caf52 693function enable_ust_lttng_channel ()
d4018451 694{
34ab15c5 695 local expected_to_fail=$1
827caf52
JR
696 local sess_name=$2
697 local channel_name=$3
4c80129b 698 local opt=$4
d4018451 699
4c80129b 700 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
312dabc3 701 ret=$?
34ab15c5 702 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 703 test "$ret" -ne "0"
34ab15c5 704 ok $? "Enable channel $channel_name for session $sess_name failed as expected"
312dabc3
JRJ
705 else
706 ok $ret "Enable channel $channel_name for session $sess_name"
707 fi
d4018451
DG
708}
709
827caf52
JR
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
29655db7 720function disable_ust_lttng_channel()
d4018451 721{
7d0ad314
JRJ
722 local sess_name=$1
723 local channel_name=$2
d4018451 724
2cf48300 725 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 726 ok $? "Disable channel $channel_name for session $sess_name"
d3e8f6bb
DG
727}
728
07b86b52
JD
729function enable_lttng_mmap_overwrite_kernel_channel()
730{
7d0ad314
JRJ
731 local sess_name=$1
732 local channel_name=$2
07b86b52 733
2cf48300 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
07b86b52
JD
735 ok $? "Enable channel $channel_name for session $sess_name"
736}
737
086e6add
MD
738function enable_lttng_mmap_discard_small_kernel_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 -k --output mmap --discard --subbuf-size=$(getconf PAGE_SIZE) --num-subbuf=2 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
744 ok $? "Enable small discard channel $channel_name for session $sess_name"
745}
746
747function enable_lttng_mmap_overwrite_small_kernel_channel()
748{
749 local sess_name=$1
750 local channel_name=$2
751
752 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite --subbuf-size=$(getconf PAGE_SIZE) --num-subbuf=2 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
753 ok $? "Enable small discard channel $channel_name for session $sess_name"
754}
755
ebaaaf5e
JD
756function enable_lttng_mmap_overwrite_ust_channel()
757{
7d0ad314
JRJ
758 local sess_name=$1
759 local channel_name=$2
ebaaaf5e 760
2cf48300 761 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
ebaaaf5e
JD
762 ok $? "Enable channel $channel_name for session $sess_name"
763}
764
d3e8f6bb
DG
765function enable_ust_lttng_event ()
766{
c4926bb5
JR
767 local expected_to_fail=$1
768 local sess_name=$2
769 local event_name="$3"
770 local channel_name=$4
ebaaaf5e
JD
771
772 if [ -z $channel_name ]; then
773 # default channel if none specified
774 chan=""
775 else
776 chan="-c $channel_name"
777 fi
d3e8f6bb 778
2cf48300 779 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 780 ret=$?
c4926bb5 781 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 782 test $ret -ne "0"
34ab15c5 783 ok $? "Enable ust event $event_name for session $session_name failed as expected"
01513c3e 784 else
34ab15c5 785 ok $ret "Enable ust event $event_name for session $sess_name"
01513c3e 786 fi
26b53d3b
DG
787}
788
c4926bb5
JR
789function enable_ust_lttng_event_ok ()
790{
791 enable_ust_lttng_event 0 "$@"
792}
793
794function enable_ust_lttng_event_fail ()
795{
796 enable_ust_lttng_event 1 "$@"
797}
798
37175ce4
DG
799function enable_jul_lttng_event()
800{
801 sess_name=$1
802 event_name="$2"
803 channel_name=$3
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
2cf48300 812 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
37175ce4
DG
813 ok $? "Enable JUL event $event_name for session $sess_name"
814}
815
b2064f54
DG
816function enable_jul_lttng_event_loglevel()
817{
7d0ad314
JRJ
818 local sess_name=$1
819 local event_name="$2"
820 local loglevel=$3
821 local channel_name=$4
b2064f54
DG
822
823 if [ -z $channel_name ]; then
824 # default channel if none specified
825 chan=""
826 else
827 chan="-c $channel_name"
828 fi
829
2cf48300 830 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
b2064f54
DG
831 ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
832}
833
504d4ace
DG
834function enable_log4j_lttng_event()
835{
836 sess_name=$1
837 event_name="$2"
838 channel_name=$3
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
2cf48300 847 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
504d4ace
DG
848 ok $? "Enable LOG4J event $event_name for session $sess_name"
849}
850
851function enable_log4j_lttng_event_loglevel()
852{
853 local sess_name=$1
854 local event_name="$2"
855 local loglevel=$3
856 local channel_name=$4
857
858 if [ -z $channel_name ]; then
859 # default channel if none specified
860 chan=""
861 else
862 chan="-c $channel_name"
863 fi
864
2cf48300 865 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
504d4ace
DG
866 ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
867}
868
0e115563
DG
869function enable_python_lttng_event()
870{
871 sess_name=$1
872 event_name="$2"
873 channel_name=$3
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
2cf48300 882 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
0e115563
DG
883 ok $? "Enable Python event $event_name for session $sess_name"
884}
885
886function enable_python_lttng_event_loglevel()
887{
888 local sess_name=$1
889 local event_name="$2"
890 local loglevel=$3
891 local channel_name=$4
892
893 if [ -z $channel_name ]; then
894 # default channel if none specified
895 chan=""
896 else
897 chan="-c $channel_name"
898 fi
899
2cf48300 900 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
0e115563
DG
901 ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel"
902}
903
26b53d3b
DG
904function enable_ust_lttng_event_filter()
905{
7d0ad314
JRJ
906 local sess_name="$1"
907 local event_name="$2"
908 local filter="$3"
26b53d3b 909
2cf48300 910 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 911 ok $? "Enable event $event_name with filtering for session $sess_name"
26b53d3b
DG
912}
913
914function enable_ust_lttng_event_loglevel()
915{
7d0ad314
JRJ
916 local sess_name="$1"
917 local event_name="$2"
918 local loglevel="$3"
26b53d3b 919
2cf48300 920 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 921 ok $? "Enable event $event_name with loglevel $loglevel"
26b53d3b
DG
922}
923
924function enable_ust_lttng_event_loglevel_only()
925{
7d0ad314
JRJ
926 local sess_name="$1"
927 local event_name="$2"
928 local loglevel="$3"
26b53d3b 929
2cf48300 930 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 931 ok $? "Enable event $event_name with loglevel-only $loglevel"
26b53d3b
DG
932}
933
934function disable_ust_lttng_event ()
935{
7d0ad314
JRJ
936 local sess_name="$1"
937 local event_name="$2"
01513c3e 938 local channel_name="$3"
26b53d3b 939
01513c3e
JRJ
940 if [ -z $channel_name ]; then
941 # default channel if none specified
942 chan=""
943 else
944 chan="-c $channel_name"
945 fi
946
2cf48300 947 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
29655db7 948 ok $? "Disable event $event_name for session $sess_name"
d3e8f6bb
DG
949}
950
1d842d5a
DG
951function disable_jul_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 -j >/dev/null 2>&1
957 ok $? "Disable JUL event $event_name for session $sess_name"
958}
959
504d4ace
DG
960function disable_log4j_lttng_event ()
961{
962 local sess_name="$1"
963 local event_name="$2"
964
965 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1
966 ok $? "Disable LOG4J event $event_name for session $sess_name"
967}
968
0e115563
DG
969function disable_python_lttng_event ()
970{
971 local sess_name="$1"
972 local event_name="$2"
973
2cf48300 974 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
0e115563
DG
975 ok $? "Disable Python event $event_name for session $sess_name"
976}
977
fb3268e3 978function start_lttng_tracing ()
d3e8f6bb 979{
e563bbdb
JR
980 local expected_to_fail=$1
981 local sess_name=$2
d3e8f6bb 982
2cf48300 983 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 984 ret=$?
e563bbdb 985 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 986 test "$ret" -ne "0"
34ab15c5 987 ok $? "Start tracing for session $sess_name failed as expected"
01513c3e
JRJ
988 else
989 ok $ret "Start tracing for session $sess_name"
990 fi
d3e8f6bb
DG
991}
992
e563bbdb
JR
993function start_lttng_tracing_ok ()
994{
995 start_lttng_tracing 0 "$@"
996}
997
998function start_lttng_tracing_fail ()
999{
1000 start_lttng_tracing 1 "$@"
1001}
1002
fb3268e3 1003function stop_lttng_tracing ()
d3e8f6bb 1004{
96340a01
JR
1005 local expected_to_fail=$1
1006 local sess_name=$2
d3e8f6bb 1007
2cf48300 1008 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1009 ret=$?
96340a01 1010 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1011 test "$ret" -ne "0"
34ab15c5 1012 ok $? "Stop lttng tracing for session $sess_name failed as expected"
01513c3e
JRJ
1013 else
1014 ok $ret "Stop lttng tracing for session $sess_name"
1015 fi
d3e8f6bb
DG
1016}
1017
96340a01
JR
1018function stop_lttng_tracing_ok ()
1019{
1020 stop_lttng_tracing 0 "$@"
1021}
1022
1023function stop_lttng_tracing_fail ()
1024{
1025 stop_lttng_tracing 1 "$@"
1026}
1027
d3e8f6bb
DG
1028function destroy_lttng_session ()
1029{
67b4c664
JR
1030 local expected_to_fail=$1
1031 local sess_name=$2
d3e8f6bb 1032
2cf48300 1033 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1034 ret=$?
96340a01 1035 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1036 test "$ret" -ne "0"
34ab15c5 1037 ok $? "Destroy session $sess_name failed as expected"
01513c3e
JRJ
1038 else
1039 ok $ret "Destroy session $sess_name"
1040 fi
d3e8f6bb
DG
1041}
1042
67b4c664
JR
1043function destroy_lttng_session_ok ()
1044{
1045 destroy_lttng_session 0 "$@"
1046
1047}
1048
1049function destroy_lttng_session_fail ()
1050{
1051 destroy_lttng_session 1 "$@"
1052}
1053
1054
873c2aae
JRJ
1055function destroy_lttng_sessions ()
1056{
2cf48300 1057 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
873c2aae
JRJ
1058 ok $? "Destroy all lttng sessions"
1059}
1060
07b86b52
JD
1061function lttng_snapshot_add_output ()
1062{
b5633831
JR
1063 local expected_to_fail=$1
1064 local sess_name=$2
1065 local trace_path=$3
07b86b52 1066
2cf48300 1067 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name file://$trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1068 ret=$?
b5633831 1069 if [[ $expected_to_fail -eq 1 ]]; then
01513c3e 1070 test "$ret" -ne "0"
34ab15c5 1071 ok $? "Added snapshot output file://$trace_path failed as expected"
01513c3e
JRJ
1072 else
1073 ok $ret "Added snapshot output file://$trace_path"
1074 fi
07b86b52
JD
1075}
1076
b5633831
JR
1077function lttng_snapshot_add_output_ok ()
1078{
1079 lttng_snapshot_add_output 0 "$@"
1080}
1081
1082function lttng_snapshot_add_output_fail ()
1083{
1084 lttng_snapshot_add_output 1 "$@"
1085}
1086
26402e0c
DG
1087function lttng_snapshot_del_output ()
1088{
31580dc7
JR
1089 local expected_to_fail=$1
1090 local sess_name=$2
1091 local id=$3
26402e0c 1092
2cf48300 1093 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e 1094 ret=$?
31580dc7 1095 if [[ $expected_to_fail -eq "1" ]]; then
01513c3e 1096 test "$ret" -ne "0"
34ab15c5 1097 ok $? "Deleted snapshot output id $id failed as expected"
01513c3e
JRJ
1098 else
1099 ok $ret "Deleted snapshot output id $id"
1100 fi
26402e0c
DG
1101}
1102
31580dc7
JR
1103function lttng_snapshot_del_output_ok ()
1104{
1105 lttng_snapshot_del_output 0 "$@"
1106}
1107
1108function lttng_snapshot_del_output_fail ()
1109{
1110 lttng_snapshot_del_output 1 "$@"
1111}
1112
07b86b52
JD
1113function lttng_snapshot_record ()
1114{
7d0ad314
JRJ
1115 local sess_name=$1
1116 local trace_path=$2
07b86b52 1117
2cf48300 1118 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
07b86b52
JD
1119 ok $? "Snapshot recorded"
1120}
1121
01513c3e
JRJ
1122function lttng_snapshot_list ()
1123{
1124 local sess_name=$1
2cf48300 1125 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
01513c3e
JRJ
1126 ok $? "Snapshot list"
1127}
1128
e02b109b
DG
1129function lttng_save()
1130{
1131 local sess_name=$1
1132 local opts=$2
1133
2cf48300 1134 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
34ab15c5 1135 ok $? "Session saved"
e02b109b
DG
1136}
1137
1138function lttng_load()
1139{
1140 local opts=$1
1141
2cf48300 1142 $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
34ab15c5 1143 ok $? "Load command with opts: $opts"
e02b109b
DG
1144}
1145
e83a8bdb
JR
1146function lttng_track()
1147{
1148 local expected_to_fail=$1
1149 local opts=$2
1150 $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST
1151 ret=$?
1152 if [[ $expected_to_fail -eq "1" ]]; then
1153 test $ret -ne "0"
1154 ok $? "Track command failed as expected with opts: $opts"
1155 else
34ab15c5 1156 ok $ret "Track command with opts: $opts"
e83a8bdb
JR
1157 fi
1158}
1159
1160function lttng_track_ok()
1161{
1162 lttng_track 0 "$@"
1163}
1164
1165function lttng_track_fail()
1166{
1167 lttng_track 1 "$@"
1168}
1169
1170function lttng_untrack()
1171{
1172 local expected_to_fail=$1
1173 local opts=$2
1174 $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST
1175 ret=$?
1176 if [[ $expected_to_fail -eq "1" ]]; then
1177 test $ret -ne "0"
1178 ok $? "Untrack command failed as expected with opts: $opts"
1179 else
34ab15c5 1180 ok $ret "Untrack command with opts: $opts"
e83a8bdb
JR
1181 fi
1182}
1183
1184function lttng_untrack_ok()
1185{
1186 lttng_untrack 0 "$@"
1187}
1188
1189function lttng_untrack_fail()
1190{
1191 lttng_untrack 1 "$@"
1192}
1193
8dcef147
JR
1194function add_context_lttng()
1195{
1196 local expected_to_fail="$1"
1197 local domain="$2"
1198 local session_name="$3"
1199 local channel_name="$4"
1200 local type="$5"
1201
1202 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context -s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
1203 ret=$?
1204 if [[ $expected_to_fail -eq "1" ]]; then
1205 test $ret -ne "0"
1206 ok $? "Add context command failed as expected for type: $type"
1207 else
1208 ok $ret "Add context command for type: $type"
1209 fi
1210}
1211
1212function add_context_ust_ok()
1213{
1214 add_context_lttng 0 -u "$@"
1215}
1216
1217function add_context_ust_fail()
1218{
1219 add_context_lttng 1 -u "$@"
1220}
1221
1222function add_context_kernel_ok()
1223{
1224 add_context_lttng 0 -k "$@"
1225}
1226
1227function add_context_kernel_fail()
1228{
1229 add_context_lttng 1 -k "$@"
1230}
1231
d3e8f6bb
DG
1232function trace_matches ()
1233{
7d0ad314
JRJ
1234 local event_name=$1
1235 local nr_iter=$2
1236 local trace_path=$3
d3e8f6bb 1237
317eef93 1238 which $BABELTRACE_BIN >/dev/null
29655db7 1239 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
d3e8f6bb 1240
7d0ad314 1241 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
29655db7 1242
d3e8f6bb 1243 if [ "$count" -ne "$nr_iter" ]; then
29655db7 1244 fail "Trace match"
af91abc9 1245 diag "$count matching events found in trace"
d3e8f6bb 1246 else
29655db7 1247 pass "Trace match"
d3e8f6bb
DG
1248 fi
1249}
f4e40ab6 1250
d53addeb
DG
1251function trace_match_only()
1252{
1253 local event_name=$1
1254 local nr_iter=$2
1255 local trace_path=$3
1256
1257 which $BABELTRACE_BIN >/dev/null
1258 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1259
1260 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
1261 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1262
1263 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
1264 pass "Trace match with $total event $event_name"
1265 else
1266 fail "Trace match"
1267 diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
1268 fi
1269}
1270
f4e40ab6
DG
1271function validate_trace
1272{
7d0ad314
JRJ
1273 local event_name=$1
1274 local trace_path=$2
f4e40ab6
DG
1275
1276 which $BABELTRACE_BIN >/dev/null
29655db7
CB
1277 if [ $? -ne 0 ]; then
1278 skip 0 "Babeltrace binary not found. Skipping trace validation"
f4e40ab6
DG
1279 fi
1280
07b86b52
JD
1281 OLDIFS=$IFS
1282 IFS=","
1283 for i in $event_name; do
1284 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
1285 if [ "$traced" -ne 0 ]; then
ebaaaf5e 1286 pass "Validate trace for event $i, $traced events"
07b86b52
JD
1287 else
1288 fail "Validate trace for event $i"
1289 diag "Found $traced occurences of $i"
1290 fi
1291 done
1292 ret=$?
1293 IFS=$OLDIFS
1294 return $ret
f4e40ab6 1295}
8cfcd41c 1296
086e6add
MD
1297function trace_first_line
1298{
1299 local trace_path=$1
1300
1301 which $BABELTRACE_BIN >/dev/null
1302 if [ $? -ne 0 ]; then
1303 skip 0 "Babeltrace binary not found. Skipping trace validation"
1304 fi
1305
1306 $BABELTRACE_BIN $trace_path 2>/dev/null | head -n 1
1307}
1308
8cfcd41c
MD
1309function validate_trace_exp()
1310{
1311 local event_exp=$1
1312 local trace_path=$2
1313
1314 which $BABELTRACE_BIN >/dev/null
1315 skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
1316
1317 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep ${event_exp} | wc -l)
1318 if [ "$traced" -ne 0 ]; then
1319 pass "Validate trace for expression '${event_exp}', $traced events"
1320 else
1321 fail "Validate trace for expression '${event_exp}'"
1322 diag "Found $traced occurences of '${event_exp}'"
1323 fi
1324 ret=$?
1325 return $ret
1326}
1327
1328function validate_trace_only_exp()
1329{
1330 local event_exp=$1
1331 local trace_path=$2
1332
1333 which $BABELTRACE_BIN >/dev/null
1334 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
1335
1336 local count=$($BABELTRACE_BIN $trace_path | grep ${event_exp} | wc -l)
1337 local total=$($BABELTRACE_BIN $trace_path | wc -l)
1338
1339 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
1340 pass "Trace match with $total for expression '${event_exp}"
1341 else
1342 fail "Trace match"
1343 diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
1344 fi
1345 ret=$?
1346 return $ret
1347}
1348
1349function validate_trace_empty()
1350{
1351 local trace_path=$1
1352
1353 which $BABELTRACE_BIN >/dev/null
1354 if [ $? -ne 0 ]; then
1355 skip 0 "Babeltrace binary not found. Skipping trace validation"
1356 fi
1357
1358 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | wc -l)
1359 if [ "$traced" -eq 0 ]; then
1360 pass "Validate empty trace"
1361 else
1362 fail "Validate empty trace"
1363 diag "Found $traced events in trace"
1364 fi
1365 ret=$?
1366 return $ret
1367}
801236b0 1368
eded6438 1369function regenerate_metadata ()
801236b0
JD
1370{
1371 local expected_to_fail=$1
1372 local sess_name=$2
1373
eded6438 1374 $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate metadata -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
801236b0
JD
1375 ret=$?
1376 if [[ $expected_to_fail -eq "1" ]]; then
1377 test "$ret" -ne "0"
eded6438 1378 ok $? "Expected fail on regenerate metadata $sess_name"
801236b0
JD
1379 else
1380 ok $ret "Metadata regenerate $sess_name"
1381 fi
1382}
1383
eded6438 1384function regenerate_metadata_ok ()
801236b0 1385{
eded6438 1386 regenerate_metadata 0 "$@"
801236b0
JD
1387}
1388
eded6438 1389function regenerate_metadata_fail ()
801236b0 1390{
eded6438 1391 regenerate_metadata 1 "$@"
801236b0 1392}
512eb148
JD
1393
1394function destructive_tests_enabled ()
1395{
1396 if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then
1397 return 0
1398 else
1399 return 1
1400 fi
1401}
This page took 0.112444 seconds and 5 git commands to generate.