Test: add disable-event JUL tests
[lttng-tools.git] / tests / regression / ust / java-jul / test_java_jul
CommitLineData
37175ce4
DG
1#!/bin/bash
2#
3# Copyright (C) - 2013 David Goulet <dgoulet@efficios.com>
4#
5# This program is free software; you can redistribute it and/or modify it under
6# the terms of the GNU General Public License, version 2 only, as published by
7# the Free Software Foundation.
8#
9# This program 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 General Public License for more
12# details.
13#
14# You should have received a copy of the GNU General Public License along with
15# this program; if not, write to the Free Software Foundation, Inc., 51
16# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18TEST_DESC="Java JUL support"
19
20CURDIR=$(dirname $0)/
21TESTDIR=$CURDIR/../../..
22NR_ITER=6
23NR_MSEC_WAIT=1000
24TESTAPP_NAME="JTestLTTng"
25TESTAPP_BIN="$TESTAPP_NAME.java"
26TESTAPP_PATH="$CURDIR/$TESTAPP_NAME"
27SESSION_NAME="jul"
28EVENT_NAME="JTestLTTng"
9b21e6d5 29EVENT_NAME2="JTestLTTng2"
37175ce4
DG
30JAVA_CP="$CURDIR:/usr/local/lib/lttng/java/liblttng-ust-jul.jar:/usr/lib/lttng/java/liblttng-ust-jul.jar"
31
958d2529 32NUM_TESTS=155
37175ce4
DG
33
34source $TESTDIR/utils/utils.sh
35
36function run_app
37{
88f54ca9 38 local finest_tp=$1
9b21e6d5 39 local fire_second_tp=$2
88f54ca9 40
b06d6a6f 41 java -cp $JAVA_CP -Djava.library.path="/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $finest_tp $fire_second_tp >/dev/null 2>&1
37175ce4
DG
42}
43
b06d6a6f 44function run_app_background
37175ce4 45{
b06d6a6f 46 run_app $@ &
37175ce4
DG
47}
48
3e1c9ff7
DG
49function enable_jul_loglevel_only()
50{
51 sess_name=$1
52 event_name="$2"
53 loglevel=$3
54 channel_name=$4
55
56 if [ -z $channel_name ]; then
57 # default channel if none specified
58 chan=""
59 else
60 chan="-c $channel_name"
61 fi
62
63 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel-only $loglevel "$event_name" $chan -s $sess_name -j >/dev/null 2>&1
64 ok $? "Enable JUL event $event_name for session $sess_name with loglevel-only $loglevel"
65}
66
34c40351
DG
67function enable_jul_filter()
68{
69 local sess_name="$1"
70 local event_name="$2"
71 local filter="$3"
72
73 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -j --filter "$filter" >/dev/null 2>&1
74 ok $? "Enable event $event_name with filter $filter for session $sess_name"
75}
76
c4fd489f
JG
77function enable_jul_filter_loglevel_only()
78{
79 local sess_name="$1"
80 local event_name="$2"
81 local filter="$3"
82 local loglevel="$4"
83
84 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel-only $loglevel "$event_name" -s $sess_name -j --filter "$filter" >/dev/null 2>&1
85 ok $? "Enable event $event_name with filter \"$filter\" and loglevel-only $loglevel for session $sess_name"
86}
87
37175ce4
DG
88# MUST set TESTDIR before calling those functions
89
90function test_jul_before_start ()
91{
92 diag "Test JUL application BEFORE tracing starts"
93 create_lttng_session $SESSION_NAME $TRACE_PATH
94 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
95
96 # Run 5 times with a 1 second delay
b06d6a6f 97 run_app_background
37175ce4
DG
98
99 start_lttng_tracing $SESSION_NAME
100
b06d6a6f
DG
101 # Wait for the applications started in background
102 wait ${!}
37175ce4
DG
103
104 stop_lttng_tracing $SESSION_NAME
105 destroy_lttng_session $SESSION_NAME
b2064f54
DG
106
107 # Validate test. Expecting all events.
d53addeb 108 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
109 if [ $? -ne 0 ]; then
110 return $?
111 fi
37175ce4
DG
112}
113
114function test_jul_after_start ()
115{
116 diag "Test JUL application AFTER tracing starts"
117
118 create_lttng_session $SESSION_NAME $TRACE_PATH
119 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
120 start_lttng_tracing $SESSION_NAME
121
122 # Run 5 times with a 1 second delay
123 run_app
124
37175ce4
DG
125 stop_lttng_tracing $SESSION_NAME
126 destroy_lttng_session $SESSION_NAME
b2064f54
DG
127
128 # Validate test. Expecting all events.
d53addeb 129 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
130 if [ $? -ne 0 ]; then
131 return $?
132 fi
133}
134
135function test_jul_loglevel ()
136{
137 diag "Test JUL application with loglevel"
138
139 create_lttng_session $SESSION_NAME $TRACE_PATH
140 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_INFO"
141 start_lttng_tracing $SESSION_NAME
142
143 # Run 5 times with a 1 second delay
144 run_app
145
b2064f54
DG
146 stop_lttng_tracing $SESSION_NAME
147 destroy_lttng_session $SESSION_NAME
148
149 # Validate test. Expecting all events.
d53addeb 150 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
151 if [ $? -ne 0 ]; then
152 return $?
153 fi
154
155 diag "Test JUL applications with lower loglevel"
156
157 create_lttng_session $SESSION_NAME $TRACE_PATH
158 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_SEVERE"
159 start_lttng_tracing $SESSION_NAME
160
161 # Run 5 times with a 1 second delay
162 run_app
163
b2064f54
DG
164 stop_lttng_tracing $SESSION_NAME
165 destroy_lttng_session $SESSION_NAME
166
167 # Validate test. Expecting 0 events.
d53addeb 168 trace_match_only $EVENT_NAME 0 $TRACE_PATH
b2064f54
DG
169 if [ $? -ne 0 ]; then
170 return $?
171 fi
172
173 diag "Test JUL applications with higher loglevel"
174
175 create_lttng_session $SESSION_NAME $TRACE_PATH
176 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_FINER"
177 start_lttng_tracing $SESSION_NAME
178
179 # Run 5 times with a 1 second delay
180 run_app
181
b2064f54
DG
182 stop_lttng_tracing $SESSION_NAME
183 destroy_lttng_session $SESSION_NAME
184
185 # Validate test. Expecting all events.
d53addeb 186 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54 187 return $?
37175ce4
DG
188}
189
88f54ca9
DG
190function test_jul_loglevel_multiple ()
191{
192 diag "Test JUL application with multiple loglevel"
193
194 create_lttng_session $SESSION_NAME $TRACE_PATH
195 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_INFO"
196 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_FINEST"
197 start_lttng_tracing $SESSION_NAME
198
199 # Run 5 times with a 1 second delay and fire two TP.
200 run_app 1
88f54ca9
DG
201
202 stop_lttng_tracing $SESSION_NAME
203 destroy_lttng_session $SESSION_NAME
204
205 # Validate test. Expecting all events times two.
d53addeb 206 trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
88f54ca9
DG
207 if [ $? -ne 0 ]; then
208 return $?
209 fi
210
211 create_lttng_session $SESSION_NAME $TRACE_PATH
212 enable_jul_lttng_event_loglevel $SESSION_NAME '*' "JUL_INFO"
213 enable_jul_lttng_event_loglevel $SESSION_NAME '*' "JUL_FINEST"
214 start_lttng_tracing $SESSION_NAME
215
216 # Run 5 times with a 1 second delay and fire two TP.
217 run_app 1
88f54ca9
DG
218
219 stop_lttng_tracing $SESSION_NAME
220 destroy_lttng_session $SESSION_NAME
221
222 # Validate test. Expecting all events times two.
d53addeb 223 trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
88f54ca9
DG
224 if [ $? -ne 0 ]; then
225 return $?
226 fi
227}
228
3e1c9ff7
DG
229function test_jul_multi_session_loglevel()
230{
231 diag "Test JUL with multiple session"
232
233 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
234 enable_jul_loglevel_only $SESSION_NAME-1 '*' "JUL_INFO"
235 start_lttng_tracing $SESSION_NAME-1
236
237 create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
238 enable_jul_loglevel_only $SESSION_NAME-2 '*' "JUL_FINEST"
239 start_lttng_tracing $SESSION_NAME-2
240
241 # Run 5 times with a 1 second delay and fire second TP.
242 run_app 1 1
3e1c9ff7
DG
243
244 stop_lttng_tracing $SESSION_NAME-1
245 stop_lttng_tracing $SESSION_NAME-2
246 destroy_lttng_session $SESSION_NAME-1
247 destroy_lttng_session $SESSION_NAME-2
248
249 # Expecting 6 events being the main event plus the second tp.
d53addeb 250 trace_match_only $EVENT_NAME $(($NR_ITER + 1)) $TRACE_PATH/$SESSION_NAME-1
3e1c9ff7
DG
251 if [ $? -ne 0 ]; then
252 return $?
253 fi
254
255 # Expectin 5 events being the finest TP.
d53addeb 256 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
3e1c9ff7
DG
257 if [ $? -ne 0 ]; then
258 return $?
259 fi
260}
261
1d842d5a
DG
262function test_jul_multi_session_disable()
263{
264 diag "Test JUL with multiple session with disabled event"
265
266 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
267 enable_jul_lttng_event $SESSION_NAME-1 $EVENT_NAME
268 enable_jul_lttng_event $SESSION_NAME-1 $EVENT_NAME2
269 disable_jul_lttng_event $SESSION_NAME-1 $EVENT_NAME
270 start_lttng_tracing $SESSION_NAME-1
271
272 create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
273 enable_jul_lttng_event $SESSION_NAME-2 $EVENT_NAME2
274 start_lttng_tracing $SESSION_NAME-2
275
276 # Run 5 times with a 1 second delay and fire second TP.
277 run_app 0 1
1d842d5a
DG
278
279 stop_lttng_tracing $SESSION_NAME-1
280 stop_lttng_tracing $SESSION_NAME-2
281 destroy_lttng_session $SESSION_NAME-1
282 destroy_lttng_session $SESSION_NAME-2
283
284 # Validate test. Expecting one event of the second TP.
d53addeb 285 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1
1d842d5a
DG
286 if [ $? -ne 0 ]; then
287 return $?
288 fi
289
290 # Validate test. Expecting one event of the second TP.
d53addeb 291 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
1d842d5a
DG
292 if [ $? -ne 0 ]; then
293 return $?
294 fi
295}
296
958d2529
DG
297function test_jul_multi_session_disable_wildcard()
298{
299 diag "Test JUL with multiple session with disabled wildcard event"
300
301 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
302 enable_jul_lttng_event $SESSION_NAME-1 '*'
303
304 create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
305 enable_jul_lttng_event $SESSION_NAME-2 '*'
306
307 disable_jul_lttng_event $SESSION_NAME-1 '*'
308
309 start_lttng_tracing $SESSION_NAME-1
310 start_lttng_tracing $SESSION_NAME-2
311
312 run_app
313
314 stop_lttng_tracing $SESSION_NAME-1
315 stop_lttng_tracing $SESSION_NAME-2
316 destroy_lttng_session $SESSION_NAME-1
317 destroy_lttng_session $SESSION_NAME-2
318
319 # Validate test. Expecting NO event of the first TP.
320 trace_match_only $EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME-1
321 if [ $? -ne 0 ]; then
322 return $?
323 fi
324
325 # Validate test. Expecting all events of the first TP.
326 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
327 if [ $? -ne 0 ]; then
328 return $?
329 fi
330}
331
332function test_jul_disable_all()
333{
334 diag "Test JUL with multiple session with disabled all event"
335
336 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
337 enable_jul_lttng_event $SESSION_NAME '*'
338 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
339 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME2
340
341 disable_jul_lttng_event $SESSION_NAME '*'
342
343 start_lttng_tracing $SESSION_NAME
344
345 run_app 0 1
346
347 stop_lttng_tracing $SESSION_NAME
348 destroy_lttng_session $SESSION_NAME
349
350 # Validate test. Expecting NO event of the first TP and second TP.
351 trace_match_only $EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME
352 trace_match_only $EVENT_NAME2 0 $TRACE_PATH/$SESSION_NAME
353 if [ $? -ne 0 ]; then
354 return $?
355 fi
356}
357
9b21e6d5
DG
358function test_jul_multi_session()
359{
360 diag "Test JUL with multiple session"
361
362 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
363 enable_jul_lttng_event $SESSION_NAME-1 $EVENT_NAME
364 start_lttng_tracing $SESSION_NAME-1
365
366 create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
367 enable_jul_lttng_event $SESSION_NAME-2 $EVENT_NAME2
368 start_lttng_tracing $SESSION_NAME-2
369
370 # Run 5 times with a 1 second delay and fire second TP.
371 run_app 0 1
9b21e6d5
DG
372
373 stop_lttng_tracing $SESSION_NAME-1
374 stop_lttng_tracing $SESSION_NAME-2
375 destroy_lttng_session $SESSION_NAME-1
376 destroy_lttng_session $SESSION_NAME-2
377
378 # Validate test. Expecting all events of first TP
d53addeb 379 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
9b21e6d5
DG
380 if [ $? -ne 0 ]; then
381 return $?
382 fi
383
384 # Validate test. Expecting one event of the second TP.
d53addeb 385 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
9b21e6d5
DG
386 if [ $? -ne 0 ]; then
387 return $?
388 fi
389}
390
3e1c9ff7
DG
391function test_jul_destroy_session()
392{
393 diag "Test JUL two session with destroy"
394
395 create_lttng_session $SESSION_NAME $TRACE_PATH/first-sess
396 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
397 start_lttng_tracing $SESSION_NAME
398
399 # Run 5 times with a 1 second delay
b06d6a6f 400 run_app_background 0 1
3e1c9ff7
DG
401
402 sleep 1
403
404 stop_lttng_tracing $SESSION_NAME
405 destroy_lttng_session $SESSION_NAME
406
407 # Validate test. Expecting at least one event num 1
408 validate_trace $EVENT_NAME $TRACE_PATH/first-sess
409 if [ $? -ne 0 ]; then
410 return $?
411 fi
412
413 create_lttng_session $SESSION_NAME $TRACE_PATH/second-sess
414 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME2
415 start_lttng_tracing $SESSION_NAME
416
b06d6a6f
DG
417 # Wait for the applications started in background
418 wait ${!}
3e1c9ff7
DG
419
420 stop_lttng_tracing $SESSION_NAME
421 destroy_lttng_session $SESSION_NAME
422
423 # Validate test. Expecting only one event num 2
d53addeb 424 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/second-sess
3e1c9ff7
DG
425 if [ $? -ne 0 ]; then
426 return $?
427 fi
428}
429
34c40351
DG
430function test_jul_filtering()
431{
432 diag "Test JUL filtering"
433
434 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
435 # Enable all event with a filter.
436 enable_jul_filter $SESSION_NAME '*' 'msg == "JUL second logger fired"'
437 start_lttng_tracing $SESSION_NAME
438
439 # Run 5 times with a 1 second delay and fire second TP.
440 run_app 0 1
34c40351
DG
441
442 stop_lttng_tracing $SESSION_NAME
443 destroy_lttng_session $SESSION_NAME
444
445 # Validate test. Expecting one event of the second TP only.
d53addeb 446 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
34c40351
DG
447 if [ $? -ne 0 ]; then
448 return $?
449 fi
450
451 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
452 # Enable first Logger but filter msg payload for the INFO one while
453 # triggering the finest and second TP.
454 enable_jul_filter $SESSION_NAME $EVENT_NAME 'msg == "JUL tp fired!"'
455 start_lttng_tracing $SESSION_NAME
456
457 # Run 5 times with a 1 second delay, fire finest and second TP.
458 run_app 1 1
34c40351
DG
459
460 stop_lttng_tracing $SESSION_NAME
461 destroy_lttng_session $SESSION_NAME
462
463 # Validate test. Expecting NR_ITER event of the main INFO tp.
d53addeb 464 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
34c40351
DG
465 if [ $? -ne 0 ]; then
466 return $?
467 fi
468}
469
1d842d5a
DG
470function test_jul_disable()
471{
472 diag "Test JUL disable event"
473
474 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
475 # Enable all event with a filter.
476 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
477 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME2
478 disable_jul_lttng_event $SESSION_NAME $EVENT_NAME
479 start_lttng_tracing $SESSION_NAME
480
481 # Run 5 times with a 1 second delay and fire second TP.
482 run_app 0 1
1d842d5a
DG
483
484 stop_lttng_tracing $SESSION_NAME
485 destroy_lttng_session $SESSION_NAME
486
487 # Validate test. Expecting one event of the second TP only.
d53addeb 488 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
1d842d5a
DG
489 if [ $? -ne 0 ]; then
490 return $?
491 fi
492}
493
494function test_jul_disable_enable()
495{
496 diag "Test JUL disable event followed by an enable"
497
498 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
499 # Enable all event with a filter.
500 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
501 disable_jul_lttng_event $SESSION_NAME $EVENT_NAME
502 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
503 start_lttng_tracing $SESSION_NAME
504
505 # Run 5 times with a 1 second delay and fire second TP.
506 run_app 0 1
1d842d5a
DG
507
508 stop_lttng_tracing $SESSION_NAME
509 destroy_lttng_session $SESSION_NAME
510
511 # Validate test. Expecting NR_ITER event of the main INFO tp.
d53addeb 512 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
1d842d5a
DG
513 if [ $? -ne 0 ]; then
514 return $?
515 fi
516}
517
c4fd489f
JG
518function test_jul_filter_loglevel()
519{
520 local BOGUS_EVENT_NAME="not_a_real_event"
521 local FILTER="int_loglevel > 700 || int_loglevel < 700"
522 local ALL_EVENTS="."
523
524 diag "Test JUL a filter with a loglevel"
525
526 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
527 # Enable an event with a filter and the loglevel-only option.
528 enable_jul_filter_loglevel_only $SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" JUL_CONFIG
529 disable_jul_lttng_event $SESSION_NAME $BOGUS_EVENT_NAME
530 enable_jul_filter_loglevel_only $SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" JUL_CONFIG
531 start_lttng_tracing $SESSION_NAME
532
533 # Run 5 times with a 1 second delay and fire second TP.
534 run_app 0 1
535
536 stop_lttng_tracing $SESSION_NAME
537 destroy_lttng_session $SESSION_NAME
538
539 # Validate test. Expecting no events.
540 trace_match_only $ALL_EVENTS 0 $TRACE_PATH/$SESSION_NAME
541 if [ $? -ne 0 ]; then
542 return $?
543 fi
544}
545
37175ce4
DG
546plan_tests $NUM_TESTS
547
548print_test_banner "$TEST_DESC"
549
550if [ ! -f "$TESTAPP_PATH.class" ]; then
551 withapp=0
552else
553 withapp=1
554fi
555
556skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
557{
558 start_lttng_sessiond
559
560 tests=(
958d2529 561 test_jul_multi_session_disable_wildcard
1d842d5a
DG
562 test_jul_multi_session_disable
563 test_jul_disable
564 test_jul_disable_enable
958d2529 565 test_jul_disable_all
34c40351 566 test_jul_filtering
3e1c9ff7
DG
567 test_jul_multi_session_loglevel
568 test_jul_destroy_session
b2064f54 569 test_jul_loglevel
88f54ca9 570 test_jul_loglevel_multiple
37175ce4
DG
571 test_jul_before_start
572 test_jul_after_start
9b21e6d5 573 test_jul_multi_session
c4fd489f 574 test_jul_filter_loglevel
37175ce4
DG
575 )
576
577 for fct_test in ${tests[@]};
578 do
3e1c9ff7
DG
579 TRACE_PATH=$(mktemp -d)
580
37175ce4 581 ${fct_test}
b2064f54
DG
582 if [ $? -ne 0 ]; then
583 break;
37175ce4 584 fi
b2064f54 585 rm -rf $TRACE_PATH
37175ce4
DG
586 done
587
588 stop_lttng_sessiond
589}
This page took 0.078392 seconds and 4 git commands to generate.