Test: Add the new log4j agent
[lttng-tools.git] / tests / regression / ust / java-jul / test_java_jul
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
18 TEST_DESC="Java JUL support"
19
20 CURDIR=$(dirname $0)/
21 TESTDIR=$CURDIR/../../..
22 NR_ITER=6
23 NR_MSEC_WAIT=1000
24 TESTAPP_NAME="JTestLTTng"
25 TESTAPP_BIN="$TESTAPP_NAME.java"
26 TESTAPP_PATH="$CURDIR/$TESTAPP_NAME"
27 SESSION_NAME="jul"
28 EVENT_NAME="JTestLTTng"
29 EVENT_NAME2="JTestLTTng2"
30 JAVA_CP="$CURDIR:/usr/local/share/java/liblttng-ust-agent.jar:/usr/share/java/liblttng-ust-agent.jar"
31
32 NUM_TESTS=155
33
34 source $TESTDIR/utils/utils.sh
35
36 function run_app
37 {
38 local finest_tp=$1
39 local fire_second_tp=$2
40
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
42 }
43
44 function run_app_background
45 {
46 run_app $@ &
47 }
48
49 function 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
67 function 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
77 function 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
88 # MUST set TESTDIR before calling those functions
89
90 function 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
97 run_app_background
98
99 start_lttng_tracing $SESSION_NAME
100
101 # Wait for the applications started in background
102 wait ${!}
103
104 stop_lttng_tracing $SESSION_NAME
105 destroy_lttng_session $SESSION_NAME
106
107 # Validate test. Expecting all events.
108 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
109 if [ $? -ne 0 ]; then
110 return $?
111 fi
112 }
113
114 function 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
125 stop_lttng_tracing $SESSION_NAME
126 destroy_lttng_session $SESSION_NAME
127
128 # Validate test. Expecting all events.
129 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
130 if [ $? -ne 0 ]; then
131 return $?
132 fi
133 }
134
135 function 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
146 stop_lttng_tracing $SESSION_NAME
147 destroy_lttng_session $SESSION_NAME
148
149 # Validate test. Expecting all events.
150 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
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
164 stop_lttng_tracing $SESSION_NAME
165 destroy_lttng_session $SESSION_NAME
166
167 # Validate test. Expecting 0 events.
168 trace_match_only $EVENT_NAME 0 $TRACE_PATH
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
182 stop_lttng_tracing $SESSION_NAME
183 destroy_lttng_session $SESSION_NAME
184
185 # Validate test. Expecting all events.
186 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
187 return $?
188 }
189
190 function 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
201
202 stop_lttng_tracing $SESSION_NAME
203 destroy_lttng_session $SESSION_NAME
204
205 # Validate test. Expecting all events times two.
206 trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
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
218
219 stop_lttng_tracing $SESSION_NAME
220 destroy_lttng_session $SESSION_NAME
221
222 # Validate test. Expecting all events times two.
223 trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
224 if [ $? -ne 0 ]; then
225 return $?
226 fi
227 }
228
229 function 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
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.
250 trace_match_only $EVENT_NAME $(($NR_ITER + 1)) $TRACE_PATH/$SESSION_NAME-1
251 if [ $? -ne 0 ]; then
252 return $?
253 fi
254
255 # Expectin 5 events being the finest TP.
256 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
257 if [ $? -ne 0 ]; then
258 return $?
259 fi
260 }
261
262 function 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
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.
285 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1
286 if [ $? -ne 0 ]; then
287 return $?
288 fi
289
290 # Validate test. Expecting one event of the second TP.
291 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
292 if [ $? -ne 0 ]; then
293 return $?
294 fi
295 }
296
297 function 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
332 function 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
358 function 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
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
379 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
380 if [ $? -ne 0 ]; then
381 return $?
382 fi
383
384 # Validate test. Expecting one event of the second TP.
385 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
386 if [ $? -ne 0 ]; then
387 return $?
388 fi
389 }
390
391 function 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
400 run_app_background 0 1
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
417 # Wait for the applications started in background
418 wait ${!}
419
420 stop_lttng_tracing $SESSION_NAME
421 destroy_lttng_session $SESSION_NAME
422
423 # Validate test. Expecting only one event num 2
424 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/second-sess
425 if [ $? -ne 0 ]; then
426 return $?
427 fi
428 }
429
430 function 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
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.
446 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
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
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.
464 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
465 if [ $? -ne 0 ]; then
466 return $?
467 fi
468 }
469
470 function 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
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.
488 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
489 if [ $? -ne 0 ]; then
490 return $?
491 fi
492 }
493
494 function 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
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.
512 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
513 if [ $? -ne 0 ]; then
514 return $?
515 fi
516 }
517
518 function 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
546 plan_tests $NUM_TESTS
547
548 print_test_banner "$TEST_DESC"
549
550 if [ ! -f "$TESTAPP_PATH.class" ]; then
551 withapp=0
552 else
553 withapp=1
554 fi
555
556 skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
557 {
558 start_lttng_sessiond
559
560 tests=(
561 test_jul_multi_session_disable_wildcard
562 test_jul_multi_session_disable
563 test_jul_disable
564 test_jul_disable_enable
565 test_jul_disable_all
566 test_jul_filtering
567 test_jul_multi_session_loglevel
568 test_jul_destroy_session
569 test_jul_loglevel
570 test_jul_loglevel_multiple
571 test_jul_before_start
572 test_jul_after_start
573 test_jul_multi_session
574 test_jul_filter_loglevel
575 )
576
577 for fct_test in ${tests[@]};
578 do
579 TRACE_PATH=$(mktemp -d)
580
581 ${fct_test}
582 if [ $? -ne 0 ]; then
583 break;
584 fi
585 rm -rf $TRACE_PATH
586 done
587
588 stop_lttng_sessiond
589 }
This page took 0.066345 seconds and 4 git commands to generate.