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