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 # MUST set TESTDIR before calling those functions
72 function test_jul_before_start
()
74 diag
"Test JUL application BEFORE tracing starts"
75 create_lttng_session
$SESSION_NAME $TRACE_PATH
76 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
78 # Run 5 times with a 1 second delay
81 #FIXME: racy missing synchronization
83 start_lttng_tracing
$SESSION_NAME
85 # Wait for the applications started in background
88 stop_lttng_tracing
$SESSION_NAME
89 destroy_lttng_session
$SESSION_NAME
91 # Validate test. Expecting all events.
92 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH
98 function test_jul_after_start
()
100 diag
"Test JUL application AFTER tracing starts"
102 create_lttng_session
$SESSION_NAME $TRACE_PATH
103 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
104 start_lttng_tracing
$SESSION_NAME
106 # Run 5 times with a 1 second delay
111 stop_lttng_tracing
$SESSION_NAME
112 destroy_lttng_session
$SESSION_NAME
114 # Validate test. Expecting all events.
115 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH
116 if [ $?
-ne 0 ]; then
121 function test_jul_loglevel
()
123 diag
"Test JUL application with loglevel"
125 create_lttng_session
$SESSION_NAME $TRACE_PATH
126 enable_jul_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "JUL_INFO"
127 start_lttng_tracing
$SESSION_NAME
129 # Run 5 times with a 1 second delay
134 stop_lttng_tracing
$SESSION_NAME
135 destroy_lttng_session
$SESSION_NAME
137 # Validate test. Expecting all events.
138 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH
139 if [ $?
-ne 0 ]; then
143 diag
"Test JUL applications with lower loglevel"
145 create_lttng_session
$SESSION_NAME $TRACE_PATH
146 enable_jul_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "JUL_SEVERE"
147 start_lttng_tracing
$SESSION_NAME
149 # Run 5 times with a 1 second delay
154 stop_lttng_tracing
$SESSION_NAME
155 destroy_lttng_session
$SESSION_NAME
157 # Validate test. Expecting 0 events.
158 trace_matches
$EVENT_NAME 0 $TRACE_PATH
159 if [ $?
-ne 0 ]; then
163 diag
"Test JUL applications with higher loglevel"
165 create_lttng_session
$SESSION_NAME $TRACE_PATH
166 enable_jul_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "JUL_FINER"
167 start_lttng_tracing
$SESSION_NAME
169 # Run 5 times with a 1 second delay
174 stop_lttng_tracing
$SESSION_NAME
175 destroy_lttng_session
$SESSION_NAME
177 # Validate test. Expecting all events.
178 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH
182 function test_jul_loglevel_multiple
()
184 diag
"Test JUL application with multiple loglevel"
186 create_lttng_session
$SESSION_NAME $TRACE_PATH
187 enable_jul_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "JUL_INFO"
188 enable_jul_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "JUL_FINEST"
189 start_lttng_tracing
$SESSION_NAME
191 # Run 5 times with a 1 second delay and fire two TP.
195 stop_lttng_tracing
$SESSION_NAME
196 destroy_lttng_session
$SESSION_NAME
198 # Validate test. Expecting all events times two.
199 trace_matches
$EVENT_NAME $
(($NR_ITER * 2)) $TRACE_PATH
200 if [ $?
-ne 0 ]; then
204 create_lttng_session
$SESSION_NAME $TRACE_PATH
205 enable_jul_lttng_event_loglevel
$SESSION_NAME '*' "JUL_INFO"
206 enable_jul_lttng_event_loglevel
$SESSION_NAME '*' "JUL_FINEST"
207 start_lttng_tracing
$SESSION_NAME
209 # Run 5 times with a 1 second delay and fire two TP.
213 stop_lttng_tracing
$SESSION_NAME
214 destroy_lttng_session
$SESSION_NAME
216 # Validate test. Expecting all events times two.
217 trace_matches
$EVENT_NAME $
(($NR_ITER * 2)) $TRACE_PATH
218 if [ $?
-ne 0 ]; then
223 function test_jul_multi_session_loglevel
()
225 diag
"Test JUL with multiple session"
227 create_lttng_session
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
228 enable_jul_loglevel_only
$SESSION_NAME-1 '*' "JUL_INFO"
229 start_lttng_tracing
$SESSION_NAME-1
231 create_lttng_session
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
232 enable_jul_loglevel_only
$SESSION_NAME-2 '*' "JUL_FINEST"
233 start_lttng_tracing
$SESSION_NAME-2
235 # Run 5 times with a 1 second delay and fire second TP.
239 stop_lttng_tracing
$SESSION_NAME-1
240 stop_lttng_tracing
$SESSION_NAME-2
241 destroy_lttng_session
$SESSION_NAME-1
242 destroy_lttng_session
$SESSION_NAME-2
244 # Expecting 6 events being the main event plus the second tp.
245 trace_matches
$EVENT_NAME $
(($NR_ITER + 1)) $TRACE_PATH/$SESSION_NAME-1
246 if [ $?
-ne 0 ]; then
250 # Expectin 5 events being the finest TP.
251 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
252 if [ $?
-ne 0 ]; then
257 function test_jul_multi_session
()
259 diag
"Test JUL with multiple session"
261 create_lttng_session
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
262 enable_jul_lttng_event
$SESSION_NAME-1 $EVENT_NAME
263 start_lttng_tracing
$SESSION_NAME-1
265 create_lttng_session
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
266 enable_jul_lttng_event
$SESSION_NAME-2 $EVENT_NAME2
267 start_lttng_tracing
$SESSION_NAME-2
269 # Run 5 times with a 1 second delay and fire second TP.
273 stop_lttng_tracing
$SESSION_NAME-1
274 stop_lttng_tracing
$SESSION_NAME-2
275 destroy_lttng_session
$SESSION_NAME-1
276 destroy_lttng_session
$SESSION_NAME-2
278 # Validate test. Expecting all events of first TP
279 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
280 if [ $?
-ne 0 ]; then
284 # Validate test. Expecting one event of the second TP.
285 trace_matches
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
286 if [ $?
-ne 0 ]; then
291 function test_jul_destroy_session
()
293 diag
"Test JUL two session with destroy"
295 create_lttng_session
$SESSION_NAME $TRACE_PATH/first-sess
296 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
297 start_lttng_tracing
$SESSION_NAME
299 # Run 5 times with a 1 second delay
302 # Wait for the applications started in background
305 stop_lttng_tracing
$SESSION_NAME
306 destroy_lttng_session
$SESSION_NAME
308 # Validate test. Expecting at least one event num 1
309 validate_trace
$EVENT_NAME $TRACE_PATH/first-sess
310 if [ $?
-ne 0 ]; then
314 create_lttng_session
$SESSION_NAME $TRACE_PATH/second-sess
315 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME2
316 start_lttng_tracing
$SESSION_NAME
318 # Run 5 times with a 1 second delay
319 run_app_background
0 1
321 # Wait for the applications started in background
324 stop_lttng_tracing
$SESSION_NAME
325 destroy_lttng_session
$SESSION_NAME
327 # Validate test. Expecting only one event num 2
328 trace_matches
$EVENT_NAME2 1 $TRACE_PATH/second-sess
329 if [ $?
-ne 0 ]; then
334 function test_jul_disable
()
336 diag
"Test JUL disable event"
338 create_lttng_session
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
339 # Enable all event with a filter.
340 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
341 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME2
342 disable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
343 start_lttng_tracing
$SESSION_NAME
345 # Fire second TP but not the finest one.
349 stop_lttng_tracing
$SESSION_NAME
350 destroy_lttng_session
$SESSION_NAME
352 # Validate test. Expecting one event of the second TP only.
353 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
354 if [ $?
-ne 0 ]; then
359 plan_tests
$NUM_TESTS
361 print_test_banner
"$TEST_DESC"
363 if [ ! -f "$TESTAPP_PATH.class" ]; then
369 skip
$withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
375 test_jul_multi_session_loglevel
376 test_jul_destroy_session
378 test_jul_loglevel_multiple
379 test_jul_before_start
381 test_jul_multi_session
384 for fct_test
in ${tests[@]};
386 TRACE_PATH
=$
(mktemp
-d)
389 if [ $?
-ne 0 ]; then