Adding log4j agent support
[lttng-tools.git] / tests / regression / ust / java-jul / test_java_jul
CommitLineData
37175ce4
DG
1#!/bin/bash
2#
3# Copyright (C) - 2013 David Goulet <dgoulet@efficios.com>
4#
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.
8#
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
12# details.
13#
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.
17
18TEST_DESC="Java JUL support"
19
20CURDIR=$(dirname $0)/
21TESTDIR=$CURDIR/../../..
22NR_ITER=6
23NR_MSEC_WAIT=1000
24TESTAPP_NAME="JTestLTTng"
25TESTAPP_BIN="$TESTAPP_NAME.java"
26TESTAPP_PATH="$CURDIR/$TESTAPP_NAME"
27SESSION_NAME="jul"
28EVENT_NAME="JTestLTTng"
9b21e6d5 29EVENT_NAME2="JTestLTTng2"
37175ce4
DG
30JAVA_CP="$CURDIR:/usr/local/lib/lttng/java/liblttng-ust-jul.jar:/usr/lib/lttng/java/liblttng-ust-jul.jar"
31
1d842d5a 32NUM_TESTS=139
37175ce4
DG
33
34source $TESTDIR/utils/utils.sh
35
36function run_app
37{
88f54ca9 38 local finest_tp=$1
9b21e6d5 39 local fire_second_tp=$2
88f54ca9 40
9b21e6d5 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 &
37175ce4
DG
42}
43
44function wait_apps
45{
46 while [ -n "$(pidof java)" ]; do
47 sleep 0.5
48 done
49 pass "Wait for applications to end"
50}
51
3e1c9ff7
DG
52function enable_jul_loglevel_only()
53{
54 sess_name=$1
55 event_name="$2"
56 loglevel=$3
57 channel_name=$4
58
59 if [ -z $channel_name ]; then
60 # default channel if none specified
61 chan=""
62 else
63 chan="-c $channel_name"
64 fi
65
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"
68}
69
34c40351
DG
70function enable_jul_filter()
71{
72 local sess_name="$1"
73 local event_name="$2"
74 local filter="$3"
75
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"
78}
79
37175ce4
DG
80# MUST set TESTDIR before calling those functions
81
82function test_jul_before_start ()
83{
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
87
88 # Run 5 times with a 1 second delay
89 run_app
90
91 start_lttng_tracing $SESSION_NAME
92
93 wait_apps
94
95 stop_lttng_tracing $SESSION_NAME
96 destroy_lttng_session $SESSION_NAME
b2064f54
DG
97
98 # Validate test. Expecting all events.
1b500e7a 99 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
100 if [ $? -ne 0 ]; then
101 return $?
102 fi
37175ce4
DG
103}
104
105function test_jul_after_start ()
106{
107 diag "Test JUL application AFTER tracing starts"
108
109 create_lttng_session $SESSION_NAME $TRACE_PATH
110 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
111 start_lttng_tracing $SESSION_NAME
112
113 # Run 5 times with a 1 second delay
114 run_app
115
116 wait_apps
117
118 stop_lttng_tracing $SESSION_NAME
119 destroy_lttng_session $SESSION_NAME
b2064f54
DG
120
121 # Validate test. Expecting all events.
1b500e7a 122 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
123 if [ $? -ne 0 ]; then
124 return $?
125 fi
126}
127
128function test_jul_loglevel ()
129{
130 diag "Test JUL application with loglevel"
131
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
135
136 # Run 5 times with a 1 second delay
137 run_app
138
139 wait_apps
140
141 stop_lttng_tracing $SESSION_NAME
142 destroy_lttng_session $SESSION_NAME
143
144 # Validate test. Expecting all events.
1b500e7a 145 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
146 if [ $? -ne 0 ]; then
147 return $?
148 fi
149
150 diag "Test JUL applications with lower loglevel"
151
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
155
156 # Run 5 times with a 1 second delay
157 run_app
158
159 wait_apps
160
161 stop_lttng_tracing $SESSION_NAME
162 destroy_lttng_session $SESSION_NAME
163
164 # Validate test. Expecting 0 events.
165 trace_matches $EVENT_NAME 0 $TRACE_PATH
166 if [ $? -ne 0 ]; then
167 return $?
168 fi
169
170 diag "Test JUL applications with higher loglevel"
171
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
175
176 # Run 5 times with a 1 second delay
177 run_app
178
179 wait_apps
180
181 stop_lttng_tracing $SESSION_NAME
182 destroy_lttng_session $SESSION_NAME
183
184 # Validate test. Expecting all events.
1b500e7a 185 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54 186 return $?
37175ce4
DG
187}
188
88f54ca9
DG
189function test_jul_loglevel_multiple ()
190{
191 diag "Test JUL application with multiple loglevel"
192
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
197
198 # Run 5 times with a 1 second delay and fire two TP.
199 run_app 1
200 wait_apps
201
202 stop_lttng_tracing $SESSION_NAME
203 destroy_lttng_session $SESSION_NAME
204
205 # Validate test. Expecting all events times two.
206 trace_matches $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
207 if [ $? -ne 0 ]; then
208 return $?
209 fi
210
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
215
216 # Run 5 times with a 1 second delay and fire two TP.
217 run_app 1
218 wait_apps
219
220 stop_lttng_tracing $SESSION_NAME
221 destroy_lttng_session $SESSION_NAME
222
223 # Validate test. Expecting all events times two.
224 trace_matches $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
225 if [ $? -ne 0 ]; then
226 return $?
227 fi
228}
229
3e1c9ff7
DG
230function test_jul_multi_session_loglevel()
231{
232 diag "Test JUL with multiple session"
233
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
237
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
241
242 # Run 5 times with a 1 second delay and fire second TP.
243 run_app 1 1
244 wait_apps
245
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
250
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
254 return $?
255 fi
256
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
260 return $?
261 fi
262}
263
1d842d5a
DG
264function test_jul_multi_session_disable()
265{
266 diag "Test JUL with multiple session with disabled event"
267
268 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
269 enable_jul_lttng_event $SESSION_NAME-1 $EVENT_NAME
270 enable_jul_lttng_event $SESSION_NAME-1 $EVENT_NAME2
271 disable_jul_lttng_event $SESSION_NAME-1 $EVENT_NAME
272 start_lttng_tracing $SESSION_NAME-1
273
274 create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
275 enable_jul_lttng_event $SESSION_NAME-2 $EVENT_NAME2
276 start_lttng_tracing $SESSION_NAME-2
277
278 # Run 5 times with a 1 second delay and fire second TP.
279 run_app 0 1
280 wait_apps
281
282 stop_lttng_tracing $SESSION_NAME-1
283 stop_lttng_tracing $SESSION_NAME-2
284 destroy_lttng_session $SESSION_NAME-1
285 destroy_lttng_session $SESSION_NAME-2
286
287 # Validate test. Expecting one event of the second TP.
288 trace_matches $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1
289 if [ $? -ne 0 ]; then
290 return $?
291 fi
292
293 # Validate test. Expecting one event of the second TP.
294 trace_matches $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
295 if [ $? -ne 0 ]; then
296 return $?
297 fi
298}
299
9b21e6d5
DG
300function test_jul_multi_session()
301{
302 diag "Test JUL with multiple session"
303
304 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
305 enable_jul_lttng_event $SESSION_NAME-1 $EVENT_NAME
306 start_lttng_tracing $SESSION_NAME-1
307
308 create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
309 enable_jul_lttng_event $SESSION_NAME-2 $EVENT_NAME2
310 start_lttng_tracing $SESSION_NAME-2
311
312 # Run 5 times with a 1 second delay and fire second TP.
313 run_app 0 1
314 wait_apps
315
316 stop_lttng_tracing $SESSION_NAME-1
317 stop_lttng_tracing $SESSION_NAME-2
318 destroy_lttng_session $SESSION_NAME-1
319 destroy_lttng_session $SESSION_NAME-2
320
321 # Validate test. Expecting all events of first TP
322 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
323 if [ $? -ne 0 ]; then
324 return $?
325 fi
326
327 # Validate test. Expecting one event of the second TP.
328 trace_matches $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
329 if [ $? -ne 0 ]; then
330 return $?
331 fi
332}
333
3e1c9ff7
DG
334function test_jul_destroy_session()
335{
336 diag "Test JUL two session with destroy"
337
338 create_lttng_session $SESSION_NAME $TRACE_PATH/first-sess
339 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
340 start_lttng_tracing $SESSION_NAME
341
342 # Run 5 times with a 1 second delay
343 run_app 0 1
344
345 sleep 1
346
347 stop_lttng_tracing $SESSION_NAME
348 destroy_lttng_session $SESSION_NAME
349
350 # Validate test. Expecting at least one event num 1
351 validate_trace $EVENT_NAME $TRACE_PATH/first-sess
352 if [ $? -ne 0 ]; then
353 return $?
354 fi
355
356 create_lttng_session $SESSION_NAME $TRACE_PATH/second-sess
357 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME2
358 start_lttng_tracing $SESSION_NAME
359
360 wait_apps
361
362 stop_lttng_tracing $SESSION_NAME
363 destroy_lttng_session $SESSION_NAME
364
365 # Validate test. Expecting only one event num 2
366 trace_matches $EVENT_NAME2 1 $TRACE_PATH/second-sess
367 if [ $? -ne 0 ]; then
368 return $?
369 fi
370}
371
34c40351
DG
372function test_jul_filtering()
373{
374 diag "Test JUL filtering"
375
376 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
377 # Enable all event with a filter.
378 enable_jul_filter $SESSION_NAME '*' 'msg == "JUL second logger fired"'
379 start_lttng_tracing $SESSION_NAME
380
381 # Run 5 times with a 1 second delay and fire second TP.
382 run_app 0 1
383 wait_apps
384
385 stop_lttng_tracing $SESSION_NAME
386 destroy_lttng_session $SESSION_NAME
387
388 # Validate test. Expecting one event of the second TP only.
389 trace_matches $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
390 if [ $? -ne 0 ]; then
391 return $?
392 fi
393
394 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
395 # Enable first Logger but filter msg payload for the INFO one while
396 # triggering the finest and second TP.
397 enable_jul_filter $SESSION_NAME $EVENT_NAME 'msg == "JUL tp fired!"'
398 start_lttng_tracing $SESSION_NAME
399
400 # Run 5 times with a 1 second delay, fire finest and second TP.
401 run_app 1 1
402 wait_apps
403
404 stop_lttng_tracing $SESSION_NAME
405 destroy_lttng_session $SESSION_NAME
406
407 # Validate test. Expecting NR_ITER event of the main INFO tp.
408 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
409 if [ $? -ne 0 ]; then
410 return $?
411 fi
412}
413
1d842d5a
DG
414function test_jul_disable()
415{
416 diag "Test JUL disable event"
417
418 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
419 # Enable all event with a filter.
420 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
421 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME2
422 disable_jul_lttng_event $SESSION_NAME $EVENT_NAME
423 start_lttng_tracing $SESSION_NAME
424
425 # Run 5 times with a 1 second delay and fire second TP.
426 run_app 0 1
427 wait_apps
428
429 stop_lttng_tracing $SESSION_NAME
430 destroy_lttng_session $SESSION_NAME
431
432 # Validate test. Expecting one event of the second TP only.
433 trace_matches $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
434 if [ $? -ne 0 ]; then
435 return $?
436 fi
437}
438
439function test_jul_disable_enable()
440{
441 diag "Test JUL disable event followed by an enable"
442
443 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
444 # Enable all event with a filter.
445 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
446 disable_jul_lttng_event $SESSION_NAME $EVENT_NAME
447 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
448 start_lttng_tracing $SESSION_NAME
449
450 # Run 5 times with a 1 second delay and fire second TP.
451 run_app 0 1
452 wait_apps
453
454 stop_lttng_tracing $SESSION_NAME
455 destroy_lttng_session $SESSION_NAME
456
457 # Validate test. Expecting NR_ITER event of the main INFO tp.
458 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
459 if [ $? -ne 0 ]; then
460 return $?
461 fi
462}
463
37175ce4
DG
464plan_tests $NUM_TESTS
465
466print_test_banner "$TEST_DESC"
467
468if [ ! -f "$TESTAPP_PATH.class" ]; then
469 withapp=0
470else
471 withapp=1
472fi
473
474skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
475{
476 start_lttng_sessiond
477
478 tests=(
1d842d5a
DG
479 test_jul_multi_session_disable
480 test_jul_disable
481 test_jul_disable_enable
34c40351 482 test_jul_filtering
3e1c9ff7
DG
483 test_jul_multi_session_loglevel
484 test_jul_destroy_session
b2064f54 485 test_jul_loglevel
88f54ca9 486 test_jul_loglevel_multiple
37175ce4
DG
487 test_jul_before_start
488 test_jul_after_start
9b21e6d5 489 test_jul_multi_session
37175ce4
DG
490 )
491
492 for fct_test in ${tests[@]};
493 do
3e1c9ff7
DG
494 TRACE_PATH=$(mktemp -d)
495
37175ce4 496 ${fct_test}
b2064f54
DG
497 if [ $? -ne 0 ]; then
498 break;
37175ce4 499 fi
b2064f54 500 rm -rf $TRACE_PATH
37175ce4
DG
501 done
502
503 stop_lttng_sessiond
504}
This page took 0.067418 seconds and 4 git commands to generate.