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 #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
47 while [ -n "$(pidof java)" ]; do
50 pass
"Wait for applications to end"
53 function enable_jul_loglevel_only
()
60 if [ -z $channel_name ]; then
61 # default channel if none specified
64 chan
="-c $channel_name"
67 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel-only $loglevel "$event_name" $chan -s $sess_name -j >/dev
/null
2>&1
68 ok $?
"Enable JUL event $event_name for session $sess_name with loglevel-only $loglevel"
71 # MUST set TESTDIR before calling those functions
73 function test_jul_before_start
()
75 local file_sync_after_first
=$
(mktemp
-u)
76 local file_sync_before_last
=$
(mktemp
-u)
78 diag
"Test JUL application BEFORE tracing starts"
79 create_lttng_session
$SESSION_NAME $TRACE_PATH
80 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
82 # Run 5 times with a 1 second delay
85 start_lttng_tracing
$SESSION_NAME
87 touch ${file_sync_before_last}
89 # Wait for the applications started in background
92 stop_lttng_tracing
$SESSION_NAME
93 destroy_lttng_session
$SESSION_NAME
95 rm -f ${file_sync_after_first}
96 rm -f ${file_sync_before_last}
98 # Validate test. Expecting all events.
99 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH
100 if [ $?
-ne 0 ]; then
105 function test_jul_after_start
()
107 diag
"Test JUL application AFTER tracing starts"
109 create_lttng_session
$SESSION_NAME $TRACE_PATH
110 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
111 start_lttng_tracing
$SESSION_NAME
113 # Run 5 times with a 1 second delay
118 stop_lttng_tracing
$SESSION_NAME
119 destroy_lttng_session
$SESSION_NAME
121 # Validate test. Expecting all events.
122 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH
123 if [ $?
-ne 0 ]; then
128 function test_jul_loglevel
()
130 diag
"Test JUL application with loglevel"
132 create_lttng_session
$SESSION_NAME $TRACE_PATH
133 enable_jul_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "JUL_INFO"
134 start_lttng_tracing
$SESSION_NAME
136 # Run 5 times with a 1 second delay
141 stop_lttng_tracing
$SESSION_NAME
142 destroy_lttng_session
$SESSION_NAME
144 # Validate test. Expecting all events.
145 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH
146 if [ $?
-ne 0 ]; then
150 diag
"Test JUL applications with lower loglevel"
152 create_lttng_session
$SESSION_NAME $TRACE_PATH
153 enable_jul_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "JUL_SEVERE"
154 start_lttng_tracing
$SESSION_NAME
156 # Run 5 times with a 1 second delay
161 stop_lttng_tracing
$SESSION_NAME
162 destroy_lttng_session
$SESSION_NAME
164 # Validate test. Expecting 0 events.
165 trace_matches
$EVENT_NAME 0 $TRACE_PATH
166 if [ $?
-ne 0 ]; then
170 diag
"Test JUL applications with higher loglevel"
172 create_lttng_session
$SESSION_NAME $TRACE_PATH
173 enable_jul_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "JUL_FINER"
174 start_lttng_tracing
$SESSION_NAME
176 # Run 5 times with a 1 second delay
181 stop_lttng_tracing
$SESSION_NAME
182 destroy_lttng_session
$SESSION_NAME
184 # Validate test. Expecting all events.
185 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH
189 function test_jul_loglevel_multiple
()
191 diag
"Test JUL application with multiple loglevel"
193 create_lttng_session
$SESSION_NAME $TRACE_PATH
194 enable_jul_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "JUL_INFO"
195 enable_jul_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "JUL_FINEST"
196 start_lttng_tracing
$SESSION_NAME
198 # Run 5 times with a 1 second delay and fire two TP.
202 stop_lttng_tracing
$SESSION_NAME
203 destroy_lttng_session
$SESSION_NAME
205 # Validate test. Expecting all events times two.
206 trace_matches
$EVENT_NAME $
(($NR_ITER * 2)) $TRACE_PATH
207 if [ $?
-ne 0 ]; then
211 create_lttng_session
$SESSION_NAME $TRACE_PATH
212 enable_jul_lttng_event_loglevel
$SESSION_NAME '*' "JUL_INFO"
213 enable_jul_lttng_event_loglevel
$SESSION_NAME '*' "JUL_FINEST"
214 start_lttng_tracing
$SESSION_NAME
216 # Run 5 times with a 1 second delay and fire two TP.
220 stop_lttng_tracing
$SESSION_NAME
221 destroy_lttng_session
$SESSION_NAME
223 # Validate test. Expecting all events times two.
224 trace_matches
$EVENT_NAME $
(($NR_ITER * 2)) $TRACE_PATH
225 if [ $?
-ne 0 ]; then
230 function test_jul_multi_session_loglevel
()
232 diag
"Test JUL with multiple session"
234 create_lttng_session
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
235 enable_jul_loglevel_only
$SESSION_NAME-1 '*' "JUL_INFO"
236 start_lttng_tracing
$SESSION_NAME-1
238 create_lttng_session
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
239 enable_jul_loglevel_only
$SESSION_NAME-2 '*' "JUL_FINEST"
240 start_lttng_tracing
$SESSION_NAME-2
242 # Run 5 times with a 1 second delay and fire second TP.
246 stop_lttng_tracing
$SESSION_NAME-1
247 stop_lttng_tracing
$SESSION_NAME-2
248 destroy_lttng_session
$SESSION_NAME-1
249 destroy_lttng_session
$SESSION_NAME-2
251 # Expecting 6 events being the main event plus the second tp.
252 trace_matches
$EVENT_NAME $
(($NR_ITER + 1)) $TRACE_PATH/$SESSION_NAME-1
253 if [ $?
-ne 0 ]; then
257 # Expectin 5 events being the finest TP.
258 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
259 if [ $?
-ne 0 ]; then
264 function test_jul_multi_session
()
266 diag
"Test JUL with multiple session"
268 create_lttng_session
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
269 enable_jul_lttng_event
$SESSION_NAME-1 $EVENT_NAME
270 start_lttng_tracing
$SESSION_NAME-1
272 create_lttng_session
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
273 enable_jul_lttng_event
$SESSION_NAME-2 $EVENT_NAME2
274 start_lttng_tracing
$SESSION_NAME-2
276 # Run 5 times with a 1 second delay and fire second TP.
280 stop_lttng_tracing
$SESSION_NAME-1
281 stop_lttng_tracing
$SESSION_NAME-2
282 destroy_lttng_session
$SESSION_NAME-1
283 destroy_lttng_session
$SESSION_NAME-2
285 # Validate test. Expecting all events of first TP
286 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
287 if [ $?
-ne 0 ]; then
291 # Validate test. Expecting one event of the second TP.
292 trace_matches
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
293 if [ $?
-ne 0 ]; then
298 function test_jul_destroy_session
()
300 diag
"Test JUL two session with destroy"
302 create_lttng_session
$SESSION_NAME $TRACE_PATH/first-sess
303 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
304 start_lttng_tracing
$SESSION_NAME
306 # Run 5 times with a 1 second delay
309 # Wait for the applications started in background
312 stop_lttng_tracing
$SESSION_NAME
313 destroy_lttng_session
$SESSION_NAME
315 # Validate test. Expecting at least one event num 1
316 validate_trace
$EVENT_NAME $TRACE_PATH/first-sess
317 if [ $?
-ne 0 ]; then
321 create_lttng_session
$SESSION_NAME $TRACE_PATH/second-sess
322 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME2
323 start_lttng_tracing
$SESSION_NAME
325 # Run 5 times with a 1 second delay
326 run_app_background
0 1
328 # Wait for the applications started in background
331 stop_lttng_tracing
$SESSION_NAME
332 destroy_lttng_session
$SESSION_NAME
334 # Validate test. Expecting only one event num 2
335 trace_matches
$EVENT_NAME2 1 $TRACE_PATH/second-sess
336 if [ $?
-ne 0 ]; then
341 function test_jul_disable
()
343 diag
"Test JUL disable event"
345 create_lttng_session
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
346 # Enable all event with a filter.
347 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
348 enable_jul_lttng_event
$SESSION_NAME $EVENT_NAME2
349 disable_jul_lttng_event
$SESSION_NAME $EVENT_NAME
350 start_lttng_tracing
$SESSION_NAME
352 # Fire second TP but not the finest one.
356 stop_lttng_tracing
$SESSION_NAME
357 destroy_lttng_session
$SESSION_NAME
359 # Validate test. Expecting one event of the second TP only.
360 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
361 if [ $?
-ne 0 ]; then
366 plan_tests
$NUM_TESTS
368 print_test_banner
"$TEST_DESC"
370 if [ ! -f "$TESTAPP_PATH.class" ]; then
376 skip
$withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
382 test_jul_multi_session_loglevel
383 test_jul_destroy_session
385 test_jul_loglevel_multiple
386 test_jul_before_start
388 test_jul_multi_session
391 for fct_test
in ${tests[@]};
393 TRACE_PATH
=$
(mktemp
-d)
396 if [ $?
-ne 0 ]; then