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/lib/lttng/java/liblttng-ust-jul.jar:/usr/lib/lttng/java/liblttng-ust-jul.jar"
34 source $TESTDIR/utils
/utils.sh
39 local fire_second_tp
=$2
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 &
46 while [ -n "$(pidof java)" ]; do
49 pass
"Wait for applications to end"
52 function enable_jul_loglevel_only
()
59 if [ -z $channel_name ]; then
60 # default channel if none specified
63 chan
="-c $channel_name"
66 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel-only $loglevel "$event_name" $chan -s $sess_name -j >/dev
/null
2>&1
67 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel-only $loglevel"
70 function enable_jul_filter
()
76 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -j --filter "$filter" >/dev
/null
2>&1
77 ok $?
"Enable event $event_name with filter $filter for session $sess_name"
80 # MUST set TESTDIR before calling those functions
82 function test_jul_before_start
()
84 diag
"Test JUL application BEFORE tracing starts"
85 create_lttng_session
$SESSION_NAME $TRACE_PATH
86 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
88 # Run 5 times with a 1 second delay
91 start_lttng_tracing
$SESSION_NAME
93 # Wait for the applications started in background
96 stop_lttng_tracing
$SESSION_NAME
97 destroy_lttng_session
$SESSION_NAME
99 # Validate test. Expecting all events.
100 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH
101 if [ $?
-ne 0 ]; then
106 function test_jul_after_start
()
108 diag
"Test JUL application AFTER tracing starts"
110 create_lttng_session
$SESSION_NAME $TRACE_PATH
111 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
112 start_lttng_tracing
$SESSION_NAME
114 # Run 5 times with a 1 second delay
119 stop_lttng_tracing
$SESSION_NAME
120 destroy_lttng_session
$SESSION_NAME
122 # Validate test. Expecting all events.
123 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH
124 if [ $?
-ne 0 ]; then
129 function test_jul_loglevel
()
131 diag
"Test JUL application with loglevel"
133 create_lttng_session
$SESSION_NAME $TRACE_PATH
134 enable_jul_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "JUL_INFO"
135 start_lttng_tracing
$SESSION_NAME
137 # Run 5 times with a 1 second delay
142 stop_lttng_tracing
$SESSION_NAME
143 destroy_lttng_session
$SESSION_NAME
145 # Validate test. Expecting all events.
146 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH
147 if [ $?
-ne 0 ]; then
151 diag
"Test JUL applications with lower loglevel"
153 create_lttng_session
$SESSION_NAME $TRACE_PATH
154 enable_jul_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "JUL_SEVERE"
155 start_lttng_tracing
$SESSION_NAME
157 # Run 5 times with a 1 second delay
162 stop_lttng_tracing
$SESSION_NAME
163 destroy_lttng_session
$SESSION_NAME
165 # Validate test. Expecting 0 events.
166 trace_matches
$EVENT_NAME 0 $TRACE_PATH
167 if [ $?
-ne 0 ]; then
171 diag
"Test JUL applications with higher loglevel"
173 create_lttng_session
$SESSION_NAME $TRACE_PATH
174 enable_jul_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "JUL_FINER"
175 start_lttng_tracing
$SESSION_NAME
177 # Run 5 times with a 1 second delay
182 stop_lttng_tracing
$SESSION_NAME
183 destroy_lttng_session
$SESSION_NAME
185 # Validate test. Expecting all events.
186 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH
190 function test_jul_loglevel_multiple
()
192 diag
"Test JUL application with multiple loglevel"
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
199 # Run 5 times with a 1 second delay and fire two TP.
203 stop_lttng_tracing
$SESSION_NAME
204 destroy_lttng_session
$SESSION_NAME
206 # Validate test. Expecting all events times two.
207 trace_matches
$EVENT_NAME $
(($NR_ITER * 2)) $TRACE_PATH
208 if [ $?
-ne 0 ]; then
212 create_lttng_session
$SESSION_NAME $TRACE_PATH
213 enable_jul_lttng_event_loglevel
$SESSION_NAME '*' "JUL_INFO"
214 enable_jul_lttng_event_loglevel
$SESSION_NAME '*' "JUL_FINEST"
215 start_lttng_tracing
$SESSION_NAME
217 # Run 5 times with a 1 second delay and fire two TP.
221 stop_lttng_tracing
$SESSION_NAME
222 destroy_lttng_session
$SESSION_NAME
224 # Validate test. Expecting all events times two.
225 trace_matches
$EVENT_NAME $
(($NR_ITER * 2)) $TRACE_PATH
226 if [ $?
-ne 0 ]; then
231 function test_jul_multi_session_loglevel
()
233 diag
"Test JUL with multiple session"
235 create_lttng_session
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
236 enable_jul_loglevel_only
$SESSION_NAME-1 '*' "JUL_INFO"
237 start_lttng_tracing
$SESSION_NAME-1
239 create_lttng_session
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
240 enable_jul_loglevel_only
$SESSION_NAME-2 '*' "JUL_FINEST"
241 start_lttng_tracing
$SESSION_NAME-2
243 # Run 5 times with a 1 second delay and fire second TP.
247 stop_lttng_tracing
$SESSION_NAME-1
248 stop_lttng_tracing
$SESSION_NAME-2
249 destroy_lttng_session
$SESSION_NAME-1
250 destroy_lttng_session
$SESSION_NAME-2
252 # Expecting 6 events being the main event plus the second tp.
253 trace_matches
$EVENT_NAME $
(($NR_ITER + 1)) $TRACE_PATH/$SESSION_NAME-1
254 if [ $?
-ne 0 ]; then
258 # Expectin 5 events being the finest TP.
259 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
260 if [ $?
-ne 0 ]; then
265 function test_jul_multi_session_disable
()
267 diag
"Test JUL with multiple session with disabled event"
269 create_lttng_session
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
270 enable_jul_lttng_event
$SESSION_NAME-1 $EVENT_NAME
271 enable_jul_lttng_event
$SESSION_NAME-1 $EVENT_NAME2
272 disable_jul_lttng_event
$SESSION_NAME-1 $EVENT_NAME
273 start_lttng_tracing
$SESSION_NAME-1
275 create_lttng_session
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
276 enable_jul_lttng_event
$SESSION_NAME-2 $EVENT_NAME2
277 start_lttng_tracing
$SESSION_NAME-2
279 # Run 5 times with a 1 second delay and fire second TP.
283 stop_lttng_tracing
$SESSION_NAME-1
284 stop_lttng_tracing
$SESSION_NAME-2
285 destroy_lttng_session
$SESSION_NAME-1
286 destroy_lttng_session
$SESSION_NAME-2
288 # Validate test. Expecting one event of the second TP.
289 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1
290 if [ $?
-ne 0 ]; then
294 # Validate test. Expecting one event of the second TP.
295 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
296 if [ $?
-ne 0 ]; then
301 function test_jul_multi_session
()
303 diag
"Test JUL with multiple session"
305 create_lttng_session
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
306 enable_jul_lttng_event
$SESSION_NAME-1 $EVENT_NAME
307 start_lttng_tracing
$SESSION_NAME-1
309 create_lttng_session
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
310 enable_jul_lttng_event
$SESSION_NAME-2 $EVENT_NAME2
311 start_lttng_tracing
$SESSION_NAME-2
313 # Run 5 times with a 1 second delay and fire second TP.
317 stop_lttng_tracing
$SESSION_NAME-1
318 stop_lttng_tracing
$SESSION_NAME-2
319 destroy_lttng_session
$SESSION_NAME-1
320 destroy_lttng_session
$SESSION_NAME-2
322 # Validate test. Expecting all events of first TP
323 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
324 if [ $?
-ne 0 ]; then
328 # Validate test. Expecting one event of the second TP.
329 trace_matches
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
330 if [ $?
-ne 0 ]; then
335 function test_jul_destroy_session
()
337 diag
"Test JUL two session with destroy"
339 create_lttng_session
$SESSION_NAME $TRACE_PATH/first-sess
340 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
341 start_lttng_tracing
$SESSION_NAME
343 # Run 5 times with a 1 second delay
346 # Wait for the applications started in background
349 stop_lttng_tracing
$SESSION_NAME
350 destroy_lttng_session
$SESSION_NAME
352 # Validate test. Expecting at least one event num 1
353 validate_trace
$EVENT_NAME $TRACE_PATH/first-sess
354 if [ $?
-ne 0 ]; then
358 create_lttng_session
$SESSION_NAME $TRACE_PATH/second-sess
359 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME2
360 start_lttng_tracing
$SESSION_NAME
362 # Run 5 times with a 1 second delay
363 run_app_background
0 1
365 # Wait for the applications started in background
368 stop_lttng_tracing
$SESSION_NAME
369 destroy_lttng_session
$SESSION_NAME
371 # Validate test. Expecting only one event num 2
372 trace_matches
$EVENT_NAME2 1 $TRACE_PATH/second-sess
373 if [ $?
-ne 0 ]; then
378 function test_jul_filtering
()
380 diag
"Test JUL filtering"
382 create_lttng_session
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
383 # Enable all event with a filter.
384 enable_jul_filter
$SESSION_NAME '*' 'msg == "JUL second logger fired"'
385 start_lttng_tracing
$SESSION_NAME
387 # Run 5 times with a 1 second delay and fire second TP.
391 stop_lttng_tracing
$SESSION_NAME
392 destroy_lttng_session
$SESSION_NAME
394 # Validate test. Expecting one event of the second TP only.
395 trace_matches
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
396 if [ $?
-ne 0 ]; then
400 create_lttng_session
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
401 # Enable first Logger but filter msg payload for the INFO one while
402 # triggering the finest and second TP.
403 enable_jul_filter
$SESSION_NAME $EVENT_NAME 'msg == "JUL tp fired!"'
404 start_lttng_tracing
$SESSION_NAME
406 # Run 5 times with a 1 second delay, fire finest and second TP.
410 stop_lttng_tracing
$SESSION_NAME
411 destroy_lttng_session
$SESSION_NAME
413 # Validate test. Expecting NR_ITER event of the main INFO tp.
414 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
415 if [ $?
-ne 0 ]; then
420 function test_jul_disable
()
422 diag
"Test JUL disable event"
424 create_lttng_session
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
425 # Enable all event with a filter.
426 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
427 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME2
428 disable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
429 start_lttng_tracing
$SESSION_NAME
431 # Run 5 times with a 1 second delay and fire second TP.
435 stop_lttng_tracing
$SESSION_NAME
436 destroy_lttng_session
$SESSION_NAME
438 # Validate test. Expecting one event of the second TP only.
439 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
440 if [ $?
-ne 0 ]; then
445 function test_jul_disable_enable
()
447 diag
"Test JUL disable event followed by an enable"
449 create_lttng_session
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
450 # Enable all event with a filter.
451 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
452 disable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
453 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
454 start_lttng_tracing
$SESSION_NAME
456 # Run 5 times with a 1 second delay and fire second TP.
460 stop_lttng_tracing
$SESSION_NAME
461 destroy_lttng_session
$SESSION_NAME
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
470 plan_tests
$NUM_TESTS
472 print_test_banner
"$TEST_DESC"
474 if [ ! -f "$TESTAPP_PATH.class" ]; then
480 skip
$withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
485 test_jul_multi_session_disable
487 test_jul_disable_enable
489 test_jul_multi_session_loglevel
490 test_jul_destroy_session
492 test_jul_loglevel_multiple
493 test_jul_before_start
495 test_jul_multi_session
498 for fct_test
in ${tests[@]};
500 TRACE_PATH
=$
(mktemp
-d)
503 if [ $?
-ne 0 ]; then