Implement tests for kernel syscall tracing feature
[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"
f7613992 19CONSUMERD_BIN="lttng-consumerd"
f4e40ab6 20RELAYD_BIN="lttng-relayd"
d3e8f6bb
DG
21LTTNG_BIN="lttng"
22BABELTRACE_BIN="babeltrace"
873c2aae 23OUTPUT_DEST=/dev/null 2>&1
d3e8f6bb 24
fd4dfcec
DG
25# Minimal kernel version supported for session daemon tests
26KERNEL_MAJOR_VERSION=2
27KERNEL_MINOR_VERSION=6
28KERNEL_PATCHLEVEL_VERSION=27
29
29655db7
CB
30source $TESTDIR/utils/tap/tap.sh
31
fec81a7e
CB
32function print_ok ()
33{
34 # Check if we are a terminal
35 if [ -t 1 ]; then
36 echo -e "\e[1;32mOK\e[0m"
37 else
38 echo -e "OK"
39 fi
40}
41
42function print_fail ()
43{
44 # Check if we are a terminal
45 if [ -t 1 ]; then
46 echo -e "\e[1;31mFAIL\e[0m"
47 else
48 echo -e "FAIL"
49 fi
50}
51
52function print_test_banner ()
53{
7d0ad314 54 local desc="$1"
29655db7 55 diag "$desc"
fec81a7e
CB
56}
57
fd4dfcec
DG
58function validate_kernel_version ()
59{
7d0ad314 60 local kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n'))
fd4dfcec
DG
61 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
62 return 0
63 fi
64 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
65 return 0
66 fi
67 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
68 return 0
69 fi
70 return 1
71}
72
9ac429ef 73# Generate a random string
f4e40ab6
DG
74# $1 = number of characters; defaults to 16
75# $2 = include special characters; 1 = yes, 0 = no; defaults to yes
9ac429ef 76function randstring()
f4e40ab6
DG
77{
78 [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
79 cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-16}
80 echo
81}
82
f4e40ab6
DG
83function lttng_enable_kernel_event
84{
7d0ad314
JRJ
85 local sess_name=$1
86 local event_name=$2
87 local channel_name=$3
f4e40ab6
DG
88
89 if [ -z $event_name ]; then
90 # Enable all event if no event name specified
29655db7 91 event_name="-a"
f4e40ab6
DG
92 fi
93
07b86b52
JD
94 if [ -z $channel_name ]; then
95 # default channel if none specified
96 chan=""
97 else
98 chan="-c $channel_name"
99 fi
100
873c2aae 101 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k >$OUTPUT_DEST
29655db7 102 ok $? "Enable kernel event $event_name for session $sess_name"
f4e40ab6
DG
103}
104
8cfcd41c
MD
105function lttng_enable_kernel_syscall()
106{
107 local expected_to_fail=$1
108 local sess_name=$2
109 local syscall_name=$3
110 local channel_name=$4
111
112 if [ -z $syscall_name ]; then
113 # Enable all event if no syscall name specified
114 syscall_name="-a"
115 fi
116
117 if [ -z $channel_name ]; then
118 # default channel if none specified
119 chan=""
120 else
121 chan="-c $channel_name"
122 fi
123
124 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --syscall "$syscall_name" $chan -s $sess_name -k >$OUTPUT_DEST
125 ret=$?
126 if [[ $expected_to_fail -eq "1" ]]; then
127 test $ret -ne "0"
128 ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
129 else
130 ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
131 fi
132}
133
134function lttng_enable_kernel_syscall_ok()
135{
136 lttng_enable_kernel_syscall 0 ${*}
137}
138
139function lttng_enable_kernel_syscall_fail()
140{
141 lttng_enable_kernel_syscall 1 ${*}
142}
143
144function lttng_disable_kernel_syscall()
145{
146 local expected_to_fail=$1
147 local sess_name=$2
148 local syscall_name=$3
149 local channel_name=$4
150
151 if [ -z $syscall_name ]; then
152 # Enable all event if no syscall name specified
153 syscall_name="-a"
154 fi
155
156 if [ -z $channel_name ]; then
157 # default channel if none specified
158 chan=""
159 else
160 chan="-c $channel_name"
161 fi
162
163 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event --syscall "$syscall_name" $chan -s $sess_name -k >$OUTPUT_DEST
164
165 ret=$?
166 if [[ $expected_to_fail -eq "1" ]]; then
167 test $ret -ne "0"
168 ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
169 else
170 ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
171 fi
172}
173
174function lttng_disable_kernel_syscall_ok()
175{
176 lttng_disable_kernel_syscall 0 ${*}
177}
178
179function lttng_disable_kernel_syscall_fail()
180{
181 lttng_disable_kernel_syscall 1 ${*}
182}
183
fb3268e3 184function start_lttng_relayd
f4e40ab6 185{
198e7caf 186 local opt=$1
173af62f 187
f4e40ab6
DG
188 DIR=$(readlink -f $TESTDIR)
189
190 if [ -z $(pidof lt-$RELAYD_BIN) ]; then
873c2aae 191 $DIR/../src/bin/lttng-relayd/$RELAYD_BIN -b $opt >$OUTPUT_DEST
25a818af 192 #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
f4e40ab6 193 if [ $? -eq 1 ]; then
29655db7 194 fail "Start lttng-relayd (opt: $opt)"
f4e40ab6
DG
195 return 1
196 else
29655db7 197 pass "Start lttng-relayd (opt: $opt)"
f4e40ab6
DG
198 fi
199 else
29655db7 200 pass "Start lttng-relayd (opt: $opt)"
f4e40ab6
DG
201 fi
202}
203
1fb23888 204function stop_lttng_relayd_nocheck
f4e40ab6
DG
205{
206 PID_RELAYD=`pidof lt-$RELAYD_BIN`
207
1fb23888 208 diag "Killing lttng-relayd (pid: $PID_RELAYD)"
873c2aae 209 kill $PID_RELAYD >$OUTPUT_DEST
1fb23888 210 retval=$?
29655db7 211
1fb23888 212 if [ $retval -eq 1 ]; then
f4e40ab6
DG
213 out=1
214 while [ -n "$out" ]; do
215 out=$(pidof lt-$RELAYD_BIN)
216 sleep 0.5
217 done
1fb23888
MD
218 fi
219 return $retval
220}
221
222function stop_lttng_relayd
223{
224 stop_lttng_relayd_nocheck
225
226 if [ $? -eq 1 ]; then
227 fail "Killed lttng-relayd (pid: $PID_RELAYD)"
228 return 1
229 else
230 pass "Killed lttng-relayd (pid: $PID_RELAYD)"
f4e40ab6
DG
231 return 0
232 fi
233}
234
8d51ddbc 235#First argument: load path for automatic loading
fb3268e3 236function start_lttng_sessiond()
355f483d 237{
8d51ddbc
JRJ
238
239 local load_path="$1"
355f483d
DG
240 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
241 # Env variable requested no session daemon
242 return
243 fi
244
29655db7
CB
245 validate_kernel_version
246 if [ $? -ne 0 ]; then
247 fail "Start session daemon"
248 BAIL_OUT "*** Kernel too old for session daemon tests ***"
355f483d
DG
249 fi
250
29655db7 251 DIR=$(readlink -f $TESTDIR)
d3d97763
JG
252 : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/}
253 export LTTNG_SESSION_CONFIG_XSD_PATH
29655db7
CB
254
255 if [ -z $(pidof lt-$SESSIOND_BIN) ]; then
8d51ddbc
JRJ
256 # Have a load path ?
257 if [ -n "$1" ]; then
258 $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --load "$1" --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
259 else
260 $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"
261 fi
29655db7
CB
262 #$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --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 &
263 status=$?
29655db7
CB
264 ok $status "Start session daemon"
265 fi
355f483d
DG
266}
267
fb3268e3 268function stop_lttng_sessiond ()
d3e8f6bb 269{
355f483d
DG
270 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
271 # Env variable requested no session daemon
272 return
273 fi
274
d3e8f6bb
DG
275 PID_SESSIOND=`pidof lt-$SESSIOND_BIN`
276
873c2aae 277 kill $PID_SESSIOND >$OUTPUT_DEST
29655db7 278
d3e8f6bb 279 if [ $? -eq 1 ]; then
29655db7 280 fail "Kill sessions daemon"
d3e8f6bb
DG
281 return 1
282 else
5fa32580
DG
283 out=1
284 while [ -n "$out" ]; do
285 out=$(pidof lt-$SESSIOND_BIN)
286 sleep 0.5
287 done
f7613992
MD
288 out=1
289 while [ -n "$out" ]; do
290 out=$(pidof $CONSUMERD_BIN)
291 sleep 0.5
292 done
29655db7 293 pass "Kill session daemon"
d3e8f6bb
DG
294 fi
295}
296
873c2aae
JRJ
297function list_lttng_with_opts ()
298{
7d0ad314 299 local opts=$1
312dabc3 300 $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts >$OUTPUT_DEST
873c2aae
JRJ
301 ok $? "Lttng-tool list command with option $opts"
302}
303
07b86b52
JD
304function create_lttng_session_no_output ()
305{
7d0ad314 306 local sess_name=$1
07b86b52 307
873c2aae 308 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output >$OUTPUT_DEST
07b86b52
JD
309 ok $? "Create session $sess_name in no-output mode"
310}
311
d3e8f6bb
DG
312function create_lttng_session ()
313{
7d0ad314
JRJ
314 local sess_name=$1
315 local trace_path=$2
316 local expected_to_fail=$3
d3e8f6bb 317
873c2aae
JRJ
318 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path > $OUTPUT_DEST
319 ret=$?
312dabc3 320 if [[ $expected_to_fail ]]; then
01513c3e
JRJ
321 test "$ret" -ne "0"
322 ok $? "Expected fail on session creation $sess_name in $trace_path"
873c2aae
JRJ
323 else
324 ok $ret "Create session $sess_name in $trace_path"
325 fi
d4018451
DG
326}
327
29655db7 328function enable_ust_lttng_channel()
d4018451 329{
7d0ad314
JRJ
330 local sess_name=$1
331 local channel_name=$2
332 local expect_fail=$3
d4018451 333
873c2aae 334 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name >$OUTPUT_DEST
312dabc3
JRJ
335 ret=$?
336 if [[ $expect_fail ]]; then
01513c3e
JRJ
337 test "$ret" -ne "0"
338 ok $? "Expected fail on ust channel creation $channel_name in $sess_name"
312dabc3
JRJ
339 else
340 ok $ret "Enable channel $channel_name for session $sess_name"
341 fi
d4018451
DG
342}
343
29655db7 344function disable_ust_lttng_channel()
d4018451 345{
7d0ad314
JRJ
346 local sess_name=$1
347 local channel_name=$2
d4018451 348
873c2aae 349 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name >$OUTPUT_DEST
29655db7 350 ok $? "Disable channel $channel_name for session $sess_name"
d3e8f6bb
DG
351}
352
07b86b52
JD
353function enable_lttng_mmap_overwrite_kernel_channel()
354{
7d0ad314
JRJ
355 local sess_name=$1
356 local channel_name=$2
07b86b52 357
873c2aae 358 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite >$OUTPUT_DEST
07b86b52
JD
359 ok $? "Enable channel $channel_name for session $sess_name"
360}
361
ebaaaf5e
JD
362function enable_lttng_mmap_overwrite_ust_channel()
363{
7d0ad314
JRJ
364 local sess_name=$1
365 local channel_name=$2
ebaaaf5e 366
873c2aae 367 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite >$OUTPUT_DEST
ebaaaf5e
JD
368 ok $? "Enable channel $channel_name for session $sess_name"
369}
370
d3e8f6bb
DG
371function enable_ust_lttng_event ()
372{
7d0ad314
JRJ
373 local sess_name=$1
374 local event_name="$2"
375 local channel_name=$3
01513c3e 376 local expected_to_fail=$4
ebaaaf5e
JD
377
378 if [ -z $channel_name ]; then
379 # default channel if none specified
380 chan=""
381 else
382 chan="-c $channel_name"
383 fi
d3e8f6bb 384
873c2aae 385 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u >$OUTPUT_DEST
01513c3e
JRJ
386 ret=$?
387 if [[ $expected_to_fail ]]; then
388 test $ret -ne "0"
389 ok $? "Enable ust event $event_name for session $session_name on channel $channel_name failed as expected"
390 else
391 ok $ret "Enable event $event_name for session $sess_name"
392 fi
26b53d3b
DG
393}
394
37175ce4
DG
395function enable_jul_lttng_event()
396{
397 sess_name=$1
398 event_name="$2"
399 channel_name=$3
400
401 if [ -z $channel_name ]; then
402 # default channel if none specified
403 chan=""
404 else
405 chan="-c $channel_name"
406 fi
407
873c2aae 408 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j >$OUTPUT_DEST
37175ce4
DG
409 ok $? "Enable JUL event $event_name for session $sess_name"
410}
411
b2064f54
DG
412function enable_jul_lttng_event_loglevel()
413{
7d0ad314
JRJ
414 local sess_name=$1
415 local event_name="$2"
416 local loglevel=$3
417 local channel_name=$4
b2064f54
DG
418
419 if [ -z $channel_name ]; then
420 # default channel if none specified
421 chan=""
422 else
423 chan="-c $channel_name"
424 fi
425
873c2aae 426 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j >$OUTPUT_DEST
b2064f54
DG
427 ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel"
428}
429
504d4ace
DG
430function enable_log4j_lttng_event()
431{
432 sess_name=$1
433 event_name="$2"
434 channel_name=$3
435
436 if [ -z $channel_name ]; then
437 # default channel if none specified
438 chan=""
439 else
440 chan="-c $channel_name"
441 fi
442
443 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l >$OUTPUT_DEST
444 ok $? "Enable LOG4J event $event_name for session $sess_name"
445}
446
447function enable_log4j_lttng_event_loglevel()
448{
449 local sess_name=$1
450 local event_name="$2"
451 local loglevel=$3
452 local channel_name=$4
453
454 if [ -z $channel_name ]; then
455 # default channel if none specified
456 chan=""
457 else
458 chan="-c $channel_name"
459 fi
460
461 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l >$OUTPUT_DEST
462 ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
463}
464
26b53d3b
DG
465function enable_ust_lttng_event_filter()
466{
7d0ad314
JRJ
467 local sess_name="$1"
468 local event_name="$2"
469 local filter="$3"
26b53d3b 470
873c2aae 471 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" >$OUTPUT_DEST
29655db7 472 ok $? "Enable event $event_name with filtering for session $sess_name"
26b53d3b
DG
473}
474
475function enable_ust_lttng_event_loglevel()
476{
7d0ad314
JRJ
477 local sess_name="$1"
478 local event_name="$2"
479 local loglevel="$3"
26b53d3b 480
873c2aae 481 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel >$OUTPUT_DEST
29655db7 482 ok $? "Enable event $event_name with loglevel $loglevel"
26b53d3b
DG
483}
484
485function enable_ust_lttng_event_loglevel_only()
486{
7d0ad314
JRJ
487 local sess_name="$1"
488 local event_name="$2"
489 local loglevel="$3"
26b53d3b 490
873c2aae 491 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel >$OUTPUT_DEST
29655db7 492 ok $? "Enable event $event_name with loglevel-only $loglevel"
26b53d3b
DG
493}
494
495function disable_ust_lttng_event ()
496{
7d0ad314
JRJ
497 local sess_name="$1"
498 local event_name="$2"
01513c3e 499 local channel_name="$3"
26b53d3b 500
01513c3e
JRJ
501 if [ -z $channel_name ]; then
502 # default channel if none specified
503 chan=""
504 else
505 chan="-c $channel_name"
506 fi
507
508 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u >$OUTPUT_DEST
29655db7 509 ok $? "Disable event $event_name for session $sess_name"
d3e8f6bb
DG
510}
511
1d842d5a
DG
512function disable_jul_lttng_event ()
513{
514 local sess_name="$1"
515 local event_name="$2"
516
517 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1
518 ok $? "Disable JUL event $event_name for session $sess_name"
519}
520
504d4ace
DG
521function disable_log4j_lttng_event ()
522{
523 local sess_name="$1"
524 local event_name="$2"
525
526 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1
527 ok $? "Disable LOG4J event $event_name for session $sess_name"
528}
529
fb3268e3 530function start_lttng_tracing ()
d3e8f6bb 531{
7d0ad314 532 local sess_name=$1
01513c3e 533 local expected_to_fail=$2
d3e8f6bb 534
873c2aae 535 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name >$OUTPUT_DEST
01513c3e
JRJ
536 ret=$?
537 if [[ $expected_to_fail ]]; then
538 test "$ret" -ne "0"
539 ok $? "Expected fail on start tracing for session: $sess_name"
540 else
541 ok $ret "Start tracing for session $sess_name"
542 fi
d3e8f6bb
DG
543}
544
fb3268e3 545function stop_lttng_tracing ()
d3e8f6bb 546{
7d0ad314 547 local sess_name=$1
01513c3e 548 local expected_to_fail=$2
d3e8f6bb 549
873c2aae 550 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name >$OUTPUT_DEST
01513c3e
JRJ
551 ret=$?
552 if [[ $expected_to_fail ]]; then
553 test "$ret" -ne "0"
554 ok $? "Expected fail on stop tracing for session: $sess_name"
555 else
556 ok $ret "Stop lttng tracing for session $sess_name"
557 fi
d3e8f6bb
DG
558}
559
560function destroy_lttng_session ()
561{
7d0ad314 562 local sess_name=$1
01513c3e 563 local expected_to_fail=$2
d3e8f6bb 564
873c2aae 565 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name >$OUTPUT_DEST
01513c3e
JRJ
566 ret=$?
567 if [[ $expected_to_fail ]]; then
568 test "$ret" -ne "0"
569 ok $? "Expected fail on session deletion $sess_name"
570 else
571 ok $ret "Destroy session $sess_name"
572 fi
d3e8f6bb
DG
573}
574
873c2aae
JRJ
575function destroy_lttng_sessions ()
576{
577 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all >$OUTPUT_DEST
578 ok $? "Destroy all lttng sessions"
579}
580
07b86b52
JD
581function lttng_snapshot_add_output ()
582{
7d0ad314
JRJ
583 local sess_name=$1
584 local trace_path=$2
01513c3e 585 local expected_to_fail=$3
07b86b52 586
873c2aae 587 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name file://$trace_path >$OUTPUT_DEST
01513c3e
JRJ
588 ret=$?
589 if [[ $expected_to_fail ]]; then
590 test "$ret" -ne "0"
591 ok $? "Failed to add a snapshot output file://$trace_path as expected"
592 else
593 ok $ret "Added snapshot output file://$trace_path"
594 fi
07b86b52
JD
595}
596
26402e0c
DG
597function lttng_snapshot_del_output ()
598{
599 local sess_name=$1
600 local id=$2
01513c3e 601 local expected_to_fail=$3
26402e0c 602
873c2aae 603 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id >$OUTPUT_DEST
01513c3e
JRJ
604 ret=$?
605 if [[ $expected_to_fail ]]; then
606 test "$ret" -ne "0"
607 ok $? "Expect fail on deletion of snapshot output id $id"
608 else
609 ok $ret "Deleted snapshot output id $id"
610 fi
26402e0c
DG
611}
612
07b86b52
JD
613function lttng_snapshot_record ()
614{
7d0ad314
JRJ
615 local sess_name=$1
616 local trace_path=$2
07b86b52 617
873c2aae 618 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name >$OUTPUT_DEST
07b86b52
JD
619 ok $? "Snapshot recorded"
620}
621
01513c3e
JRJ
622function lttng_snapshot_list ()
623{
624 local sess_name=$1
625 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name >$OUTPUT_DEST
626 ok $? "Snapshot list"
627}
628
e02b109b
DG
629function lttng_save()
630{
631 local sess_name=$1
632 local opts=$2
633
873c2aae 634 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts >$OUTPUT_DEST
e02b109b
DG
635 ok $? "Session successfully saved"
636}
637
638function lttng_load()
639{
640 local opts=$1
641
873c2aae 642 $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts >$OUTPUT_DEST
e02b109b
DG
643 ok $? "Load command successful"
644}
645
d3e8f6bb
DG
646function trace_matches ()
647{
7d0ad314
JRJ
648 local event_name=$1
649 local nr_iter=$2
650 local trace_path=$3
d3e8f6bb 651
317eef93 652 which $BABELTRACE_BIN >/dev/null
29655db7 653 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
d3e8f6bb 654
7d0ad314 655 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
29655db7 656
d3e8f6bb 657 if [ "$count" -ne "$nr_iter" ]; then
29655db7
CB
658 fail "Trace match"
659 diag "$count events found in trace"
d3e8f6bb 660 else
29655db7 661 pass "Trace match"
d3e8f6bb
DG
662 fi
663}
f4e40ab6 664
d53addeb
DG
665function trace_match_only()
666{
667 local event_name=$1
668 local nr_iter=$2
669 local trace_path=$3
670
671 which $BABELTRACE_BIN >/dev/null
672 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
673
674 local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
675 local total=$($BABELTRACE_BIN $trace_path | wc -l)
676
677 if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then
678 pass "Trace match with $total event $event_name"
679 else
680 fail "Trace match"
681 diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count"
682 fi
683}
684
f4e40ab6
DG
685function validate_trace
686{
7d0ad314
JRJ
687 local event_name=$1
688 local trace_path=$2
f4e40ab6
DG
689
690 which $BABELTRACE_BIN >/dev/null
29655db7
CB
691 if [ $? -ne 0 ]; then
692 skip 0 "Babeltrace binary not found. Skipping trace validation"
f4e40ab6
DG
693 fi
694
07b86b52
JD
695 OLDIFS=$IFS
696 IFS=","
697 for i in $event_name; do
698 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
699 if [ "$traced" -ne 0 ]; then
ebaaaf5e 700 pass "Validate trace for event $i, $traced events"
07b86b52
JD
701 else
702 fail "Validate trace for event $i"
703 diag "Found $traced occurences of $i"
704 fi
705 done
706 ret=$?
707 IFS=$OLDIFS
708 return $ret
f4e40ab6 709}
8cfcd41c
MD
710
711function validate_trace_exp()
712{
713 local event_exp=$1
714 local trace_path=$2
715
716 which $BABELTRACE_BIN >/dev/null
717 skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
718
719 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep ${event_exp} | wc -l)
720 if [ "$traced" -ne 0 ]; then
721 pass "Validate trace for expression '${event_exp}', $traced events"
722 else
723 fail "Validate trace for expression '${event_exp}'"
724 diag "Found $traced occurences of '${event_exp}'"
725 fi
726 ret=$?
727 return $ret
728}
729
730function validate_trace_only_exp()
731{
732 local event_exp=$1
733 local trace_path=$2
734
735 which $BABELTRACE_BIN >/dev/null
736 skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
737
738 local count=$($BABELTRACE_BIN $trace_path | grep ${event_exp} | wc -l)
739 local total=$($BABELTRACE_BIN $trace_path | wc -l)
740
741 if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
742 pass "Trace match with $total for expression '${event_exp}"
743 else
744 fail "Trace match"
745 diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
746 fi
747 ret=$?
748 return $ret
749}
750
751function validate_trace_empty()
752{
753 local trace_path=$1
754
755 which $BABELTRACE_BIN >/dev/null
756 if [ $? -ne 0 ]; then
757 skip 0 "Babeltrace binary not found. Skipping trace validation"
758 fi
759
760 traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | wc -l)
761 if [ "$traced" -eq 0 ]; then
762 pass "Validate empty trace"
763 else
764 fail "Validate empty trace"
765 diag "Found $traced events in trace"
766 fi
767 ret=$?
768 return $ret
769}
This page took 0.072926 seconds and 5 git commands to generate.