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