3 # Copyright (C) - 2013 David Goulet <dgoulet@efficios.com>
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.
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
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.
18 TEST_DESC
="Java JUL support"
21 TESTDIR
=$CURDIR/..
/..
/..
24 TESTAPP_NAME
="JTestLTTng"
25 TESTAPP_BIN
="$TESTAPP_NAME.java"
26 TESTAPP_PATH
="$CURDIR/$TESTAPP_NAME"
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"
34 source $TESTDIR/utils
/utils.sh
39 local fire_second_tp
=$2
41 #FIXME: app should have synchro.
42 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
45 function run_app_background
50 function enable_jul_loglevel_only
()
57 if [ -z $channel_name ]; then
58 # default channel if none specified
61 chan
="-c $channel_name"
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"
68 function enable_jul_filter
()
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"
78 function enable_jul_filter_loglevel_only
()
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"
89 # MUST set TESTDIR before calling those functions
91 function test_jul_before_start
()
93 local file_sync_after_first
=$
(mktemp
-u)
94 local file_sync_before_last
=$
(mktemp
-u)
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
100 # Run 5 times with a 1 second delay
103 start_lttng_tracing_ok
$SESSION_NAME
105 touch ${file_sync_before_last}
107 # Wait for the applications started in background
110 stop_lttng_tracing_ok
$SESSION_NAME
111 destroy_lttng_session
$SESSION_NAME
113 rm -f ${file_sync_after_first}
114 rm -f ${file_sync_before_last}
116 # Validate test. Expecting all events.
117 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH
118 if [ $?
-ne 0 ]; then
123 function test_jul_after_start
()
125 diag
"Test JUL application AFTER tracing starts"
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
131 # Run 5 times with a 1 second delay
134 stop_lttng_tracing_ok
$SESSION_NAME
135 destroy_lttng_session
$SESSION_NAME
137 # Validate test. Expecting all events.
138 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH
139 if [ $?
-ne 0 ]; then
144 function test_jul_loglevel
()
146 diag
"Test JUL application with loglevel"
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
152 # Run 5 times with a 1 second delay
155 stop_lttng_tracing_ok
$SESSION_NAME
156 destroy_lttng_session
$SESSION_NAME
158 # Validate test. Expecting all events.
159 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH
160 if [ $?
-ne 0 ]; then
164 diag
"Test JUL applications with lower loglevel"
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
170 # Run 5 times with a 1 second delay
173 stop_lttng_tracing_ok
$SESSION_NAME
174 destroy_lttng_session
$SESSION_NAME
176 # Validate test. Expecting 0 events.
177 trace_match_only
$EVENT_NAME 0 $TRACE_PATH
178 if [ $?
-ne 0 ]; then
182 diag
"Test JUL applications with higher loglevel"
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
188 # Run 5 times with a 1 second delay
191 stop_lttng_tracing_ok
$SESSION_NAME
192 destroy_lttng_session
$SESSION_NAME
194 # Validate test. Expecting all events.
195 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH
199 function test_jul_loglevel_multiple
()
201 diag
"Test JUL application with multiple loglevel"
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
208 # Run 5 times with a 1 second delay and fire two TP.
211 stop_lttng_tracing_ok
$SESSION_NAME
212 destroy_lttng_session
$SESSION_NAME
214 # Validate test. Expecting all events times two.
215 trace_match_only
$EVENT_NAME $
(($NR_ITER * 2)) $TRACE_PATH
216 if [ $?
-ne 0 ]; then
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
225 # Run 5 times with a 1 second delay and fire two TP.
228 stop_lttng_tracing_ok
$SESSION_NAME
229 destroy_lttng_session
$SESSION_NAME
231 # Validate test. Expecting all events times two.
232 trace_match_only
$EVENT_NAME $
(($NR_ITER * 2)) $TRACE_PATH
233 if [ $?
-ne 0 ]; then
238 function test_jul_multi_session_loglevel
()
240 diag
"Test JUL with multiple session"
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
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
250 # Run 5 times with a 1 second delay and fire second TP.
253 stop_lttng_tracing_ok
$SESSION_NAME-1
254 stop_lttng_tracing_ok
$SESSION_NAME-2
255 destroy_lttng_session
$SESSION_NAME-1
256 destroy_lttng_session
$SESSION_NAME-2
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
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
271 function test_jul_multi_session_disable
()
273 diag
"Test JUL with multiple session with disabled event"
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
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
285 # Run 5 times with a 1 second delay and fire second TP.
288 stop_lttng_tracing_ok
$SESSION_NAME-1
289 stop_lttng_tracing_ok
$SESSION_NAME-2
290 destroy_lttng_session
$SESSION_NAME-1
291 destroy_lttng_session
$SESSION_NAME-2
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
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
306 function test_jul_multi_session_disable_wildcard
()
308 diag
"Test JUL with multiple session with disabled wildcard event"
310 create_lttng_session_ok
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
311 enable_jul_lttng_event
$SESSION_NAME-1 '*'
313 create_lttng_session_ok
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
314 enable_jul_lttng_event
$SESSION_NAME-2 '*'
316 disable_jul_lttng_event
$SESSION_NAME-1 '*'
318 start_lttng_tracing_ok
$SESSION_NAME-1
319 start_lttng_tracing_ok
$SESSION_NAME-2
323 stop_lttng_tracing_ok
$SESSION_NAME-1
324 stop_lttng_tracing_ok
$SESSION_NAME-2
325 destroy_lttng_session
$SESSION_NAME-1
326 destroy_lttng_session
$SESSION_NAME-2
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
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
341 function test_jul_disable_all
()
343 diag
"Test JUL with multiple session with disabled all event"
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
350 disable_jul_lttng_event
$SESSION_NAME '*'
352 start_lttng_tracing_ok
$SESSION_NAME
356 stop_lttng_tracing_ok
$SESSION_NAME
357 destroy_lttng_session
$SESSION_NAME
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
367 function test_jul_multi_session
()
369 diag
"Test JUL with multiple session"
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
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
379 # Run 5 times with a 1 second delay and fire second TP.
382 stop_lttng_tracing_ok
$SESSION_NAME-1
383 stop_lttng_tracing_ok
$SESSION_NAME-2
384 destroy_lttng_session
$SESSION_NAME-1
385 destroy_lttng_session
$SESSION_NAME-2
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
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
400 function test_jul_destroy_session
()
402 diag
"Test JUL two session with destroy"
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
408 # Run 5 times with a 1 second delay
409 run_app_background
0 1
411 # Wait for the applications started in background
414 stop_lttng_tracing_ok
$SESSION_NAME
415 destroy_lttng_session
$SESSION_NAME
417 # Validate test. Expecting at least one event num 1
418 validate_trace
$EVENT_NAME $TRACE_PATH/first-sess
419 if [ $?
-ne 0 ]; then
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
427 # Run 5 times with a 1 second delay
428 run_app_background
0 1
430 # Wait for the applications started in background
433 stop_lttng_tracing_ok
$SESSION_NAME
434 destroy_lttng_session
$SESSION_NAME
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
443 function test_jul_filtering
()
445 diag
"Test JUL filtering"
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
452 # Run 5 times with a 1 second delay and fire second TP.
455 stop_lttng_tracing_ok
$SESSION_NAME
456 destroy_lttng_session
$SESSION_NAME
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
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
470 # Run 5 times with a 1 second delay, fire finest and second TP.
473 stop_lttng_tracing_ok
$SESSION_NAME
474 destroy_lttng_session
$SESSION_NAME
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
483 function test_jul_disable
()
485 diag
"Test JUL disable event"
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
494 # Run 5 times with a 1 second delay and fire second TP.
497 stop_lttng_tracing_ok
$SESSION_NAME
498 destroy_lttng_session
$SESSION_NAME
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
507 function test_jul_disable_enable
()
509 diag
"Test JUL disable event followed by an enable"
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
518 # Run 5 times with a 1 second delay and fire second TP.
521 stop_lttng_tracing_ok
$SESSION_NAME
522 destroy_lttng_session
$SESSION_NAME
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
531 function test_jul_filter_loglevel
()
533 local BOGUS_EVENT_NAME
="not_a_real_event"
534 local FILTER
="int_loglevel > 700 || int_loglevel < 700"
537 diag
"Test JUL a filter with a loglevel"
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
546 # Run 5 times with a 1 second delay and fire second TP.
549 stop_lttng_tracing_ok
$SESSION_NAME
550 destroy_lttng_session
$SESSION_NAME
552 # Validate test. Expecting no events.
553 trace_match_only
$ALL_EVENTS 0 $TRACE_PATH/$SESSION_NAME
554 if [ $?
-ne 0 ]; then
559 plan_tests
$NUM_TESTS
561 print_test_banner
"$TEST_DESC"
563 if [ ! -f "$TESTAPP_PATH.class" ]; then
569 skip
$withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
574 test_jul_multi_session_disable_wildcard
575 test_jul_multi_session_disable
577 test_jul_disable_enable
580 test_jul_multi_session_loglevel
581 test_jul_destroy_session
583 test_jul_loglevel_multiple
584 test_jul_before_start
586 test_jul_multi_session
587 test_jul_filter_loglevel
590 for fct_test
in ${tests[@]};
592 TRACE_PATH
=$
(mktemp
-d)
595 if [ $?
-ne 0 ]; then