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