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