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