3 # Copyright (C) - 2014 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 LOG4J support"
21 TESTDIR
=$CURDIR/..
/..
/..
24 TESTAPP_NAME
="JTestLTTng"
25 TESTAPP_BIN
="$TESTAPP_NAME.java"
26 TESTAPP_PATH
="$CURDIR/$TESTAPP_NAME"
28 EVENT_NAME
="log4j-event"
29 EVENT_NAME2
="log4j-event-2"
30 JAVA_CP
="$CURDIR:/usr/local/share/java/liblttng-ust-agent.jar:/usr/share/java/*"
31 OUTPUT_DEST
="/dev/null"
35 source $TESTDIR/utils
/utils.sh
40 local fire_second_tp
=$2
42 # FIXME: test app should have synchro.
43 java
-cp $JAVA_CP -Djava.library.path
="/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $debug_tp $fire_second_tp >/dev
/null
2>&1
46 function run_app_background
51 function enable_log4j_loglevel_only
()
58 if [ -z $channel_name ]; then
59 # default channel if none specified
62 chan
="-c $channel_name"
65 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel-only $loglevel "$event_name" $chan -s $sess_name -l >/dev
/null
2>&1
66 ok $?
"Enable LOG4J event $event_name for session $sess_name with loglevel-only $loglevel"
69 function enable_log4j_filter
()
75 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -l --filter "$filter" >/dev
/null
2>&1
76 ok $?
"Enable event $event_name with filter $filter for session $sess_name"
79 function enable_log4j_filter_loglevel_only
()
86 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel-only $loglevel "$event_name" -s $sess_name -l --filter "$filter" >/dev
/null
2>&1
87 ok $?
"Enable event $event_name with filter \"$filter\" and loglevel-only $loglevel for session $sess_name"
90 # MUST set TESTDIR before calling those functions
92 function test_log4j_before_start
()
94 local file_sync_after_first
=$
(mktemp
-u)
95 local file_sync_before_last
=$
(mktemp
-u)
97 diag
"Test LOG4J application BEFORE tracing starts"
98 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
99 enable_log4j_lttng_event
$SESSION_NAME $EVENT_NAME
101 # Run 5 times with a 1 second delay
104 start_lttng_tracing_ok
$SESSION_NAME
106 touch ${file_sync_before_last}
108 # Wait for the applications started in background
111 stop_lttng_tracing_ok
$SESSION_NAME
112 destroy_lttng_session_ok
$SESSION_NAME
114 rm -f ${file_sync_after_first}
115 rm -f ${file_sync_before_last}
117 # Validate test. Expecting all events.
118 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH
119 if [ $?
-ne 0 ]; then
124 function test_log4j_after_start
()
126 diag
"Test LOG4J application AFTER tracing starts"
128 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
129 enable_log4j_lttng_event
$SESSION_NAME $EVENT_NAME
130 start_lttng_tracing_ok
$SESSION_NAME
132 # Run 5 times with a 1 second delay
135 stop_lttng_tracing_ok
$SESSION_NAME
136 destroy_lttng_session_ok
$SESSION_NAME
138 # Validate test. Expecting all events.
139 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH
140 if [ $?
-ne 0 ]; then
145 function test_log4j_loglevel
()
147 diag
"Test LOG4J application with loglevel"
149 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
150 enable_log4j_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "LOG4J_INFO"
151 start_lttng_tracing_ok
$SESSION_NAME
153 # Run 5 times with a 1 second delay
156 stop_lttng_tracing_ok
$SESSION_NAME
157 destroy_lttng_session_ok
$SESSION_NAME
159 # Validate test. Expecting all events.
160 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH
161 if [ $?
-ne 0 ]; then
165 diag
"Test LOG4J applications with lower loglevel"
167 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
168 enable_log4j_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "LOG4J_FATAL"
169 start_lttng_tracing_ok
$SESSION_NAME
171 # Run 5 times with a 1 second delay
174 stop_lttng_tracing_ok
$SESSION_NAME
175 destroy_lttng_session_ok
$SESSION_NAME
177 # Validate test. Expecting 0 events.
178 trace_match_only
$EVENT_NAME 0 $TRACE_PATH
179 if [ $?
-ne 0 ]; then
183 diag
"Test LOG4J applications with higher loglevel"
185 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
186 enable_log4j_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "LOG4J_TRACE"
187 start_lttng_tracing_ok
$SESSION_NAME
189 # Run 5 times with a 1 second delay
192 stop_lttng_tracing_ok
$SESSION_NAME
193 destroy_lttng_session_ok
$SESSION_NAME
195 # Validate test. Expecting all events.
196 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH
200 function test_log4j_loglevel_multiple
()
202 diag
"Test LOG4J application with multiple loglevel"
204 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
205 enable_log4j_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "LOG4J_INFO"
206 enable_log4j_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "LOG4J_DEBUG"
207 start_lttng_tracing_ok
$SESSION_NAME
209 # Run 5 times with a 1 second delay and fire two TP.
212 stop_lttng_tracing_ok
$SESSION_NAME
213 destroy_lttng_session_ok
$SESSION_NAME
215 # Validate test. Expecting all events times two.
216 trace_match_only
$EVENT_NAME $
(($NR_ITER * 2)) $TRACE_PATH
217 if [ $?
-ne 0 ]; then
221 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
222 enable_log4j_lttng_event_loglevel
$SESSION_NAME '*' "LOG4J_INFO"
223 enable_log4j_lttng_event_loglevel
$SESSION_NAME '*' "LOG4J_DEBUG"
224 start_lttng_tracing_ok
$SESSION_NAME
226 # Run 5 times with a 1 second delay and fire two TP.
229 stop_lttng_tracing_ok
$SESSION_NAME
230 destroy_lttng_session_ok
$SESSION_NAME
232 # Validate test. Expecting all events times two.
233 trace_match_only
$EVENT_NAME $
(($NR_ITER * 2)) $TRACE_PATH
234 if [ $?
-ne 0 ]; then
239 function test_log4j_multi_session_loglevel
()
241 diag
"Test LOG4J with multiple session"
243 create_lttng_session_ok
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
244 enable_log4j_loglevel_only
$SESSION_NAME-1 '*' "LOG4J_INFO"
245 start_lttng_tracing_ok
$SESSION_NAME-1
247 create_lttng_session_ok
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
248 enable_log4j_loglevel_only
$SESSION_NAME-2 '*' "LOG4J_DEBUG"
249 start_lttng_tracing_ok
$SESSION_NAME-2
251 # Run 5 times with a 1 second delay and fire second TP.
254 stop_lttng_tracing_ok
$SESSION_NAME-1
255 stop_lttng_tracing_ok
$SESSION_NAME-2
256 destroy_lttng_session_ok
$SESSION_NAME-1
257 destroy_lttng_session_ok
$SESSION_NAME-2
259 # Expecting 6 events being the main event plus the second tp.
260 trace_match_only
$EVENT_NAME $
(($NR_ITER + 1)) $TRACE_PATH/$SESSION_NAME-1
261 if [ $?
-ne 0 ]; then
265 # Expectin 5 events being the debug TP.
266 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
267 if [ $?
-ne 0 ]; then
272 function test_log4j_multi_session_disable
()
274 diag
"Test LOG4J with multiple session with disabled event"
276 create_lttng_session_ok
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
277 enable_log4j_lttng_event
$SESSION_NAME-1 $EVENT_NAME
278 enable_log4j_lttng_event
$SESSION_NAME-1 $EVENT_NAME2
279 disable_log4j_lttng_event
$SESSION_NAME-1 $EVENT_NAME
280 start_lttng_tracing_ok
$SESSION_NAME-1
282 create_lttng_session_ok
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
283 enable_log4j_lttng_event
$SESSION_NAME-2 $EVENT_NAME2
284 start_lttng_tracing_ok
$SESSION_NAME-2
286 # Run 5 times with a 1 second delay and fire second TP.
289 stop_lttng_tracing_ok
$SESSION_NAME-1
290 stop_lttng_tracing_ok
$SESSION_NAME-2
291 destroy_lttng_session_ok
$SESSION_NAME-1
292 destroy_lttng_session_ok
$SESSION_NAME-2
294 # Validate test. Expecting one event of the second TP.
295 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1
296 if [ $?
-ne 0 ]; then
300 # Validate test. Expecting one event of the second TP.
301 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
302 if [ $?
-ne 0 ]; then
307 function test_log4j_multi_session_disable_wildcard
()
309 diag
"Test LOG4J with multiple session with disabled wildcard event"
311 create_lttng_session_ok
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
312 enable_log4j_lttng_event
$SESSION_NAME-1 '*'
314 create_lttng_session_ok
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
315 enable_log4j_lttng_event
$SESSION_NAME-2 '*'
317 disable_log4j_lttng_event
$SESSION_NAME-1 '*'
319 start_lttng_tracing_ok
$SESSION_NAME-1
320 start_lttng_tracing_ok
$SESSION_NAME-2
324 stop_lttng_tracing_ok
$SESSION_NAME-1
325 stop_lttng_tracing_ok
$SESSION_NAME-2
326 destroy_lttng_session_ok
$SESSION_NAME-1
327 destroy_lttng_session_ok
$SESSION_NAME-2
329 # Validate test. Expecting NO event of the first TP.
330 trace_match_only
$EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME-1
331 if [ $?
-ne 0 ]; then
335 # Validate test. Expecting all events of the first TP.
336 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
337 if [ $?
-ne 0 ]; then
342 function test_log4j_disable_all
()
344 diag
"Test LOG4J with multiple session with disabled all event"
346 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
347 enable_log4j_lttng_event
$SESSION_NAME '*'
348 enable_log4j_lttng_event
$SESSION_NAME $EVENT_NAME
349 enable_log4j_lttng_event
$SESSION_NAME $EVENT_NAME2
351 disable_log4j_lttng_event
$SESSION_NAME '*'
353 start_lttng_tracing_ok
$SESSION_NAME
357 stop_lttng_tracing_ok
$SESSION_NAME
358 destroy_lttng_session_ok
$SESSION_NAME
360 # Validate test. Expecting NO event of the first TP and second TP.
361 trace_match_only
$EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME
362 trace_match_only
$EVENT_NAME2 0 $TRACE_PATH/$SESSION_NAME
363 if [ $?
-ne 0 ]; then
368 function test_log4j_multi_session
()
370 diag
"Test LOG4J with multiple session"
372 create_lttng_session_ok
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
373 enable_log4j_lttng_event
$SESSION_NAME-1 $EVENT_NAME
374 start_lttng_tracing_ok
$SESSION_NAME-1
376 create_lttng_session_ok
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
377 enable_log4j_lttng_event
$SESSION_NAME-2 $EVENT_NAME2
378 start_lttng_tracing_ok
$SESSION_NAME-2
380 # Run 5 times with a 1 second delay and fire second TP.
383 stop_lttng_tracing_ok
$SESSION_NAME-1
384 stop_lttng_tracing_ok
$SESSION_NAME-2
385 destroy_lttng_session_ok
$SESSION_NAME-1
386 destroy_lttng_session_ok
$SESSION_NAME-2
388 # Validate test. Expecting all events of first TP
389 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
390 if [ $?
-ne 0 ]; then
394 # Validate test. Expecting one event of the second TP.
395 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
396 if [ $?
-ne 0 ]; then
401 function test_log4j_destroy_session
()
403 diag
"Test LOG4J two session with destroy"
405 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/first-sess
406 enable_log4j_lttng_event
$SESSION_NAME $EVENT_NAME
407 start_lttng_tracing_ok
$SESSION_NAME
409 # Run 5 times with a 1 second delay
410 run_app_background
0 1
411 # Wait for the applications started in background
414 stop_lttng_tracing_ok
$SESSION_NAME
415 destroy_lttng_session_ok
$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_log4j_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
429 # Wait for the applications started in background
432 stop_lttng_tracing_ok
$SESSION_NAME
433 destroy_lttng_session_ok
$SESSION_NAME
435 # Validate test. Expecting only one event num 2
436 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/second-sess
437 if [ $?
-ne 0 ]; then
442 function test_log4j_filtering
()
444 diag
"Test LOG4J filtering"
446 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
447 # Enable all event with a filter.
448 enable_log4j_filter
$SESSION_NAME '*' 'msg == "LOG4J second logger fired"'
449 start_lttng_tracing_ok
$SESSION_NAME
451 # Run 5 times with a 1 second delay and fire second TP.
454 stop_lttng_tracing_ok
$SESSION_NAME
455 destroy_lttng_session_ok
$SESSION_NAME
457 # Validate test. Expecting one event of the second TP only.
458 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
459 if [ $?
-ne 0 ]; then
463 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
464 # Enable first Logger but filter msg payload for the INFO one while
465 # triggering the debug and second TP.
466 enable_log4j_filter
$SESSION_NAME $EVENT_NAME 'msg == "LOG4J tp fired!"'
467 start_lttng_tracing_ok
$SESSION_NAME
469 # Run 5 times with a 1 second delay, fire debug and second TP.
472 stop_lttng_tracing_ok
$SESSION_NAME
473 destroy_lttng_session_ok
$SESSION_NAME
475 # Validate test. Expecting NR_ITER event of the main INFO tp.
476 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
477 if [ $?
-ne 0 ]; then
482 function test_log4j_disable
()
484 diag
"Test LOG4J disable event"
486 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
487 # Enable all event with a filter.
488 enable_log4j_lttng_event
$SESSION_NAME $EVENT_NAME
489 enable_log4j_lttng_event
$SESSION_NAME $EVENT_NAME2
490 disable_log4j_lttng_event
$SESSION_NAME $EVENT_NAME
491 start_lttng_tracing_ok
$SESSION_NAME
493 # Run 5 times with a 1 second delay and fire second TP.
496 stop_lttng_tracing_ok
$SESSION_NAME
497 destroy_lttng_session_ok
$SESSION_NAME
499 # Validate test. Expecting one event of the second TP only.
500 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
501 if [ $?
-ne 0 ]; then
506 function test_log4j_disable_enable
()
508 diag
"Test LOG4J disable event followed by an enable"
510 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
511 # Enable all event with a filter.
512 enable_log4j_lttng_event
$SESSION_NAME $EVENT_NAME
513 disable_log4j_lttng_event
$SESSION_NAME $EVENT_NAME
514 enable_log4j_lttng_event
$SESSION_NAME $EVENT_NAME
515 start_lttng_tracing_ok
$SESSION_NAME
517 # Run 5 times with a 1 second delay and fire second TP.
520 stop_lttng_tracing_ok
$SESSION_NAME
521 destroy_lttng_session_ok
$SESSION_NAME
523 # Validate test. Expecting NR_ITER event of the main INFO tp.
524 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
525 if [ $?
-ne 0 ]; then
530 function test_log4j_filter_loglevel
()
532 local BOGUS_EVENT_NAME
="not_a_real_event"
533 local FILTER
="int_loglevel > 700 || int_loglevel < 700"
536 diag
"Test LOG4J a filter with a loglevel"
538 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
539 # Enable an event with a filter and the loglevel-only option.
540 enable_log4j_filter_loglevel_only
$SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" LOG4J_INFO
541 disable_log4j_lttng_event
$SESSION_NAME $BOGUS_EVENT_NAME
542 enable_log4j_filter_loglevel_only
$SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" LOG4J_INFO
543 start_lttng_tracing_ok
$SESSION_NAME
545 # Run 5 times with a 1 second delay and fire second TP.
548 stop_lttng_tracing_ok
$SESSION_NAME
549 destroy_lttng_session_ok
$SESSION_NAME
551 # Validate test. Expecting no events.
552 trace_match_only
$ALL_EVENTS 0 $TRACE_PATH/$SESSION_NAME
553 if [ $?
-ne 0 ]; then
558 plan_tests
$NUM_TESTS
560 print_test_banner
"$TEST_DESC"
562 if [ ! -f "$TESTAPP_PATH.class" ]; then
568 skip
$withapp "LOG4J support is needed. Skipping all tests." $NUM_TESTS ||
573 test_log4j_multi_session_disable_wildcard
574 test_log4j_multi_session_disable
576 test_log4j_disable_enable
577 test_log4j_disable_all
579 test_log4j_multi_session_loglevel
580 test_log4j_destroy_session
582 test_log4j_loglevel_multiple
583 test_log4j_before_start
584 test_log4j_after_start
585 test_log4j_multi_session
586 test_log4j_filter_loglevel
589 for fct_test
in ${tests[@]};
591 TRACE_PATH
=$
(mktemp
-d)
594 if [ $?
-ne 0 ]; then