Tests: Validate that filters may be used with JUL's logger_name filtering
[lttng-tools.git] / tests / regression / ust / java-jul / test_java_jul
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
18 TEST_DESC="Java JUL support"
19
20 CURDIR=$(dirname $0)/
21 TESTDIR=$CURDIR/../../..
22 NR_ITER=6
23 NR_MSEC_WAIT=1000
24 TESTAPP_NAME="JTestLTTng"
25 TESTAPP_BIN="$TESTAPP_NAME.java"
26 TESTAPP_PATH="$CURDIR/$TESTAPP_NAME"
27 SESSION_NAME="jul"
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"
31
32 NUM_TESTS=131
33
34 source $TESTDIR/utils/utils.sh
35
36 function run_app
37 {
38 local finest_tp=$1
39 local fire_second_tp=$2
40
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
42 }
43
44 function run_app_background
45 {
46 run_app $@ &
47 }
48
49 function 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
67 function 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
77 function 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
88 # MUST set TESTDIR before calling those functions
89
90 function 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
97 run_app_background
98
99 start_lttng_tracing $SESSION_NAME
100
101 # Wait for the applications started in background
102 wait ${!}
103
104 stop_lttng_tracing $SESSION_NAME
105 destroy_lttng_session $SESSION_NAME
106
107 # Validate test. Expecting all events.
108 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
109 if [ $? -ne 0 ]; then
110 return $?
111 fi
112 }
113
114 function 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
125 stop_lttng_tracing $SESSION_NAME
126 destroy_lttng_session $SESSION_NAME
127
128 # Validate test. Expecting all events.
129 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
130 if [ $? -ne 0 ]; then
131 return $?
132 fi
133 }
134
135 function 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
146 stop_lttng_tracing $SESSION_NAME
147 destroy_lttng_session $SESSION_NAME
148
149 # Validate test. Expecting all events.
150 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
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
164 stop_lttng_tracing $SESSION_NAME
165 destroy_lttng_session $SESSION_NAME
166
167 # Validate test. Expecting 0 events.
168 trace_match_only $EVENT_NAME 0 $TRACE_PATH
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
182 stop_lttng_tracing $SESSION_NAME
183 destroy_lttng_session $SESSION_NAME
184
185 # Validate test. Expecting all events.
186 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
187 return $?
188 }
189
190 function 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
201
202 stop_lttng_tracing $SESSION_NAME
203 destroy_lttng_session $SESSION_NAME
204
205 # Validate test. Expecting all events times two.
206 trace_match_only $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
219 stop_lttng_tracing $SESSION_NAME
220 destroy_lttng_session $SESSION_NAME
221
222 # Validate test. Expecting all events times two.
223 trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
224 if [ $? -ne 0 ]; then
225 return $?
226 fi
227 }
228
229 function 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
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.
250 trace_match_only $EVENT_NAME $(($NR_ITER + 1)) $TRACE_PATH/$SESSION_NAME-1
251 if [ $? -ne 0 ]; then
252 return $?
253 fi
254
255 # Expectin 5 events being the finest TP.
256 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
257 if [ $? -ne 0 ]; then
258 return $?
259 fi
260 }
261
262 function 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
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.
285 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1
286 if [ $? -ne 0 ]; then
287 return $?
288 fi
289
290 # Validate test. Expecting one event of the second TP.
291 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
292 if [ $? -ne 0 ]; then
293 return $?
294 fi
295 }
296
297 function 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
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
318 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
319 if [ $? -ne 0 ]; then
320 return $?
321 fi
322
323 # Validate test. Expecting one event of the second TP.
324 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
325 if [ $? -ne 0 ]; then
326 return $?
327 fi
328 }
329
330 function 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
339 run_app_background 0 1
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
356 # Wait for the applications started in background
357 wait ${!}
358
359 stop_lttng_tracing $SESSION_NAME
360 destroy_lttng_session $SESSION_NAME
361
362 # Validate test. Expecting only one event num 2
363 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/second-sess
364 if [ $? -ne 0 ]; then
365 return $?
366 fi
367 }
368
369 function 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
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.
385 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
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
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.
403 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
404 if [ $? -ne 0 ]; then
405 return $?
406 fi
407 }
408
409 function 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
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.
427 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
428 if [ $? -ne 0 ]; then
429 return $?
430 fi
431 }
432
433 function 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
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.
451 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
452 if [ $? -ne 0 ]; then
453 return $?
454 fi
455 }
456
457 function 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
485 plan_tests $NUM_TESTS
486
487 print_test_banner "$TEST_DESC"
488
489 if [ ! -f "$TESTAPP_PATH.class" ]; then
490 withapp=0
491 else
492 withapp=1
493 fi
494
495 skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
496 {
497 start_lttng_sessiond
498
499 tests=(
500 test_jul_multi_session_disable
501 test_jul_disable
502 test_jul_disable_enable
503 test_jul_filtering
504 test_jul_multi_session_loglevel
505 test_jul_destroy_session
506 test_jul_loglevel
507 test_jul_loglevel_multiple
508 test_jul_before_start
509 test_jul_after_start
510 test_jul_multi_session
511 test_jul_filter_loglevel
512 )
513
514 for fct_test in ${tests[@]};
515 do
516 TRACE_PATH=$(mktemp -d)
517
518 ${fct_test}
519 if [ $? -ne 0 ]; then
520 break;
521 fi
522 rm -rf $TRACE_PATH
523 done
524
525 stop_lttng_sessiond
526 }
This page took 0.067903 seconds and 5 git commands to generate.