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