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