Tests: Validate that filters may be used with JUL's logger_name filtering
[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
c4fd489f 32NUM_TESTS=131
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
b06d6a6f 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
b06d6a6f 44function run_app_background
37175ce4 45{
b06d6a6f 46 run_app $@ &
37175ce4
DG
47}
48
3e1c9ff7
DG
49function enable_jul_loglevel_only()
50{
51 sess_name=$1
52 event_name="$2"
53 loglevel=$3
54 channel_name=$4
55
56 if [ -z $channel_name ]; then
57 # default channel if none specified
58 chan=""
59 else
60 chan="-c $channel_name"
61 fi
62
63 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel-only $loglevel "$event_name" $chan -s $sess_name -j >/dev/null 2>&1
64 ok $? "Enable JUL event $event_name for session $sess_name with loglevel-only $loglevel"
65}
66
34c40351
DG
67function enable_jul_filter()
68{
69 local sess_name="$1"
70 local event_name="$2"
71 local filter="$3"
72
73 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -j --filter "$filter" >/dev/null 2>&1
74 ok $? "Enable event $event_name with filter $filter for session $sess_name"
75}
76
c4fd489f
JG
77function enable_jul_filter_loglevel_only()
78{
79 local sess_name="$1"
80 local event_name="$2"
81 local filter="$3"
82 local loglevel="$4"
83
84 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel-only $loglevel "$event_name" -s $sess_name -j --filter "$filter" >/dev/null 2>&1
85 ok $? "Enable event $event_name with filter \"$filter\" and loglevel-only $loglevel for session $sess_name"
86}
87
37175ce4
DG
88# MUST set TESTDIR before calling those functions
89
90function test_jul_before_start ()
91{
92 diag "Test JUL application BEFORE tracing starts"
93 create_lttng_session $SESSION_NAME $TRACE_PATH
94 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
95
96 # Run 5 times with a 1 second delay
b06d6a6f 97 run_app_background
37175ce4
DG
98
99 start_lttng_tracing $SESSION_NAME
100
b06d6a6f
DG
101 # Wait for the applications started in background
102 wait ${!}
37175ce4
DG
103
104 stop_lttng_tracing $SESSION_NAME
105 destroy_lttng_session $SESSION_NAME
b2064f54
DG
106
107 # Validate test. Expecting all events.
d53addeb 108 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
109 if [ $? -ne 0 ]; then
110 return $?
111 fi
37175ce4
DG
112}
113
114function test_jul_after_start ()
115{
116 diag "Test JUL application AFTER tracing starts"
117
118 create_lttng_session $SESSION_NAME $TRACE_PATH
119 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
120 start_lttng_tracing $SESSION_NAME
121
122 # Run 5 times with a 1 second delay
123 run_app
124
37175ce4
DG
125 stop_lttng_tracing $SESSION_NAME
126 destroy_lttng_session $SESSION_NAME
b2064f54
DG
127
128 # Validate test. Expecting all events.
d53addeb 129 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
130 if [ $? -ne 0 ]; then
131 return $?
132 fi
133}
134
135function test_jul_loglevel ()
136{
137 diag "Test JUL application with loglevel"
138
139 create_lttng_session $SESSION_NAME $TRACE_PATH
140 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_INFO"
141 start_lttng_tracing $SESSION_NAME
142
143 # Run 5 times with a 1 second delay
144 run_app
145
b2064f54
DG
146 stop_lttng_tracing $SESSION_NAME
147 destroy_lttng_session $SESSION_NAME
148
149 # Validate test. Expecting all events.
d53addeb 150 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
151 if [ $? -ne 0 ]; then
152 return $?
153 fi
154
155 diag "Test JUL applications with lower loglevel"
156
157 create_lttng_session $SESSION_NAME $TRACE_PATH
158 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_SEVERE"
159 start_lttng_tracing $SESSION_NAME
160
161 # Run 5 times with a 1 second delay
162 run_app
163
b2064f54
DG
164 stop_lttng_tracing $SESSION_NAME
165 destroy_lttng_session $SESSION_NAME
166
167 # Validate test. Expecting 0 events.
d53addeb 168 trace_match_only $EVENT_NAME 0 $TRACE_PATH
b2064f54
DG
169 if [ $? -ne 0 ]; then
170 return $?
171 fi
172
173 diag "Test JUL applications with higher loglevel"
174
175 create_lttng_session $SESSION_NAME $TRACE_PATH
176 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_FINER"
177 start_lttng_tracing $SESSION_NAME
178
179 # Run 5 times with a 1 second delay
180 run_app
181
b2064f54
DG
182 stop_lttng_tracing $SESSION_NAME
183 destroy_lttng_session $SESSION_NAME
184
185 # Validate test. Expecting all events.
d53addeb 186 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54 187 return $?
37175ce4
DG
188}
189
88f54ca9
DG
190function test_jul_loglevel_multiple ()
191{
192 diag "Test JUL application with multiple loglevel"
193
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
198
199 # Run 5 times with a 1 second delay and fire two TP.
200 run_app 1
88f54ca9
DG
201
202 stop_lttng_tracing $SESSION_NAME
203 destroy_lttng_session $SESSION_NAME
204
205 # Validate test. Expecting all events times two.
d53addeb 206 trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
88f54ca9
DG
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
88f54ca9
DG
218
219 stop_lttng_tracing $SESSION_NAME
220 destroy_lttng_session $SESSION_NAME
221
222 # Validate test. Expecting all events times two.
d53addeb 223 trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
88f54ca9
DG
224 if [ $? -ne 0 ]; then
225 return $?
226 fi
227}
228
3e1c9ff7
DG
229function test_jul_multi_session_loglevel()
230{
231 diag "Test JUL with multiple session"
232
233 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
234 enable_jul_loglevel_only $SESSION_NAME-1 '*' "JUL_INFO"
235 start_lttng_tracing $SESSION_NAME-1
236
237 create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
238 enable_jul_loglevel_only $SESSION_NAME-2 '*' "JUL_FINEST"
239 start_lttng_tracing $SESSION_NAME-2
240
241 # Run 5 times with a 1 second delay and fire second TP.
242 run_app 1 1
3e1c9ff7
DG
243
244 stop_lttng_tracing $SESSION_NAME-1
245 stop_lttng_tracing $SESSION_NAME-2
246 destroy_lttng_session $SESSION_NAME-1
247 destroy_lttng_session $SESSION_NAME-2
248
249 # Expecting 6 events being the main event plus the second tp.
d53addeb 250 trace_match_only $EVENT_NAME $(($NR_ITER + 1)) $TRACE_PATH/$SESSION_NAME-1
3e1c9ff7
DG
251 if [ $? -ne 0 ]; then
252 return $?
253 fi
254
255 # Expectin 5 events being the finest TP.
d53addeb 256 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
3e1c9ff7
DG
257 if [ $? -ne 0 ]; then
258 return $?
259 fi
260}
261
1d842d5a
DG
262function test_jul_multi_session_disable()
263{
264 diag "Test JUL with multiple session with disabled event"
265
266 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
267 enable_jul_lttng_event $SESSION_NAME-1 $EVENT_NAME
268 enable_jul_lttng_event $SESSION_NAME-1 $EVENT_NAME2
269 disable_jul_lttng_event $SESSION_NAME-1 $EVENT_NAME
270 start_lttng_tracing $SESSION_NAME-1
271
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
275
276 # Run 5 times with a 1 second delay and fire second TP.
277 run_app 0 1
1d842d5a
DG
278
279 stop_lttng_tracing $SESSION_NAME-1
280 stop_lttng_tracing $SESSION_NAME-2
281 destroy_lttng_session $SESSION_NAME-1
282 destroy_lttng_session $SESSION_NAME-2
283
284 # Validate test. Expecting one event of the second TP.
d53addeb 285 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1
1d842d5a
DG
286 if [ $? -ne 0 ]; then
287 return $?
288 fi
289
290 # Validate test. Expecting one event of the second TP.
d53addeb 291 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
1d842d5a
DG
292 if [ $? -ne 0 ]; then
293 return $?
294 fi
295}
296
9b21e6d5
DG
297function test_jul_multi_session()
298{
299 diag "Test JUL with multiple session"
300
301 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
302 enable_jul_lttng_event $SESSION_NAME-1 $EVENT_NAME
303 start_lttng_tracing $SESSION_NAME-1
304
305 create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
306 enable_jul_lttng_event $SESSION_NAME-2 $EVENT_NAME2
307 start_lttng_tracing $SESSION_NAME-2
308
309 # Run 5 times with a 1 second delay and fire second TP.
310 run_app 0 1
9b21e6d5
DG
311
312 stop_lttng_tracing $SESSION_NAME-1
313 stop_lttng_tracing $SESSION_NAME-2
314 destroy_lttng_session $SESSION_NAME-1
315 destroy_lttng_session $SESSION_NAME-2
316
317 # Validate test. Expecting all events of first TP
d53addeb 318 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
9b21e6d5
DG
319 if [ $? -ne 0 ]; then
320 return $?
321 fi
322
323 # Validate test. Expecting one event of the second TP.
d53addeb 324 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
9b21e6d5
DG
325 if [ $? -ne 0 ]; then
326 return $?
327 fi
328}
329
3e1c9ff7
DG
330function test_jul_destroy_session()
331{
332 diag "Test JUL two session with destroy"
333
334 create_lttng_session $SESSION_NAME $TRACE_PATH/first-sess
335 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
336 start_lttng_tracing $SESSION_NAME
337
338 # Run 5 times with a 1 second delay
b06d6a6f 339 run_app_background 0 1
3e1c9ff7
DG
340
341 sleep 1
342
343 stop_lttng_tracing $SESSION_NAME
344 destroy_lttng_session $SESSION_NAME
345
346 # Validate test. Expecting at least one event num 1
347 validate_trace $EVENT_NAME $TRACE_PATH/first-sess
348 if [ $? -ne 0 ]; then
349 return $?
350 fi
351
352 create_lttng_session $SESSION_NAME $TRACE_PATH/second-sess
353 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME2
354 start_lttng_tracing $SESSION_NAME
355
b06d6a6f
DG
356 # Wait for the applications started in background
357 wait ${!}
3e1c9ff7
DG
358
359 stop_lttng_tracing $SESSION_NAME
360 destroy_lttng_session $SESSION_NAME
361
362 # Validate test. Expecting only one event num 2
d53addeb 363 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/second-sess
3e1c9ff7
DG
364 if [ $? -ne 0 ]; then
365 return $?
366 fi
367}
368
34c40351
DG
369function test_jul_filtering()
370{
371 diag "Test JUL filtering"
372
373 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
374 # Enable all event with a filter.
375 enable_jul_filter $SESSION_NAME '*' 'msg == "JUL second logger fired"'
376 start_lttng_tracing $SESSION_NAME
377
378 # Run 5 times with a 1 second delay and fire second TP.
379 run_app 0 1
34c40351
DG
380
381 stop_lttng_tracing $SESSION_NAME
382 destroy_lttng_session $SESSION_NAME
383
384 # Validate test. Expecting one event of the second TP only.
d53addeb 385 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
34c40351
DG
386 if [ $? -ne 0 ]; then
387 return $?
388 fi
389
390 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
391 # Enable first Logger but filter msg payload for the INFO one while
392 # triggering the finest and second TP.
393 enable_jul_filter $SESSION_NAME $EVENT_NAME 'msg == "JUL tp fired!"'
394 start_lttng_tracing $SESSION_NAME
395
396 # Run 5 times with a 1 second delay, fire finest and second TP.
397 run_app 1 1
34c40351
DG
398
399 stop_lttng_tracing $SESSION_NAME
400 destroy_lttng_session $SESSION_NAME
401
402 # Validate test. Expecting NR_ITER event of the main INFO tp.
d53addeb 403 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
34c40351
DG
404 if [ $? -ne 0 ]; then
405 return $?
406 fi
407}
408
1d842d5a
DG
409function test_jul_disable()
410{
411 diag "Test JUL disable event"
412
413 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
414 # Enable all event with a filter.
415 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
416 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME2
417 disable_jul_lttng_event $SESSION_NAME $EVENT_NAME
418 start_lttng_tracing $SESSION_NAME
419
420 # Run 5 times with a 1 second delay and fire second TP.
421 run_app 0 1
1d842d5a
DG
422
423 stop_lttng_tracing $SESSION_NAME
424 destroy_lttng_session $SESSION_NAME
425
426 # Validate test. Expecting one event of the second TP only.
d53addeb 427 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
1d842d5a
DG
428 if [ $? -ne 0 ]; then
429 return $?
430 fi
431}
432
433function test_jul_disable_enable()
434{
435 diag "Test JUL disable event followed by an enable"
436
437 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
438 # Enable all event with a filter.
439 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
440 disable_jul_lttng_event $SESSION_NAME $EVENT_NAME
441 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
442 start_lttng_tracing $SESSION_NAME
443
444 # Run 5 times with a 1 second delay and fire second TP.
445 run_app 0 1
1d842d5a
DG
446
447 stop_lttng_tracing $SESSION_NAME
448 destroy_lttng_session $SESSION_NAME
449
450 # Validate test. Expecting NR_ITER event of the main INFO tp.
d53addeb 451 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
1d842d5a
DG
452 if [ $? -ne 0 ]; then
453 return $?
454 fi
455}
456
c4fd489f
JG
457function test_jul_filter_loglevel()
458{
459 local BOGUS_EVENT_NAME="not_a_real_event"
460 local FILTER="int_loglevel > 700 || int_loglevel < 700"
461 local ALL_EVENTS="."
462
463 diag "Test JUL a filter with a loglevel"
464
465 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
466 # Enable an event with a filter and the loglevel-only option.
467 enable_jul_filter_loglevel_only $SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" JUL_CONFIG
468 disable_jul_lttng_event $SESSION_NAME $BOGUS_EVENT_NAME
469 enable_jul_filter_loglevel_only $SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" JUL_CONFIG
470 start_lttng_tracing $SESSION_NAME
471
472 # Run 5 times with a 1 second delay and fire second TP.
473 run_app 0 1
474
475 stop_lttng_tracing $SESSION_NAME
476 destroy_lttng_session $SESSION_NAME
477
478 # Validate test. Expecting no events.
479 trace_match_only $ALL_EVENTS 0 $TRACE_PATH/$SESSION_NAME
480 if [ $? -ne 0 ]; then
481 return $?
482 fi
483}
484
37175ce4
DG
485plan_tests $NUM_TESTS
486
487print_test_banner "$TEST_DESC"
488
489if [ ! -f "$TESTAPP_PATH.class" ]; then
490 withapp=0
491else
492 withapp=1
493fi
494
495skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
496{
497 start_lttng_sessiond
498
499 tests=(
1d842d5a
DG
500 test_jul_multi_session_disable
501 test_jul_disable
502 test_jul_disable_enable
34c40351 503 test_jul_filtering
3e1c9ff7
DG
504 test_jul_multi_session_loglevel
505 test_jul_destroy_session
b2064f54 506 test_jul_loglevel
88f54ca9 507 test_jul_loglevel_multiple
37175ce4
DG
508 test_jul_before_start
509 test_jul_after_start
9b21e6d5 510 test_jul_multi_session
c4fd489f 511 test_jul_filter_loglevel
37175ce4
DG
512 )
513
514 for fct_test in ${tests[@]};
515 do
3e1c9ff7
DG
516 TRACE_PATH=$(mktemp -d)
517
37175ce4 518 ${fct_test}
b2064f54
DG
519 if [ $? -ne 0 ]; then
520 break;
37175ce4 521 fi
b2064f54 522 rm -rf $TRACE_PATH
37175ce4
DG
523 done
524
525 stop_lttng_sessiond
526}
This page took 0.07177 seconds and 4 git commands to generate.