Fix: test flaky sleep and wait patterns
[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/share/java/liblttng-ust-agent.jar:/usr/share/java/liblttng-ust-agent.jar"
31
32 NUM_TESTS=155
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_disable_wildcard()
298 {
299 diag "Test JUL with multiple session with disabled wildcard event"
300
301 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
302 enable_jul_lttng_event $SESSION_NAME-1 '*'
303
304 create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
305 enable_jul_lttng_event $SESSION_NAME-2 '*'
306
307 disable_jul_lttng_event $SESSION_NAME-1 '*'
308
309 start_lttng_tracing $SESSION_NAME-1
310 start_lttng_tracing $SESSION_NAME-2
311
312 run_app
313
314 stop_lttng_tracing $SESSION_NAME-1
315 stop_lttng_tracing $SESSION_NAME-2
316 destroy_lttng_session $SESSION_NAME-1
317 destroy_lttng_session $SESSION_NAME-2
318
319 # Validate test. Expecting NO event of the first TP.
320 trace_match_only $EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME-1
321 if [ $? -ne 0 ]; then
322 return $?
323 fi
324
325 # Validate test. Expecting all events of the first TP.
326 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
327 if [ $? -ne 0 ]; then
328 return $?
329 fi
330 }
331
332 function test_jul_disable_all()
333 {
334 diag "Test JUL with multiple session with disabled all event"
335
336 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
337 enable_jul_lttng_event $SESSION_NAME '*'
338 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
339 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME2
340
341 disable_jul_lttng_event $SESSION_NAME '*'
342
343 start_lttng_tracing $SESSION_NAME
344
345 run_app 0 1
346
347 stop_lttng_tracing $SESSION_NAME
348 destroy_lttng_session $SESSION_NAME
349
350 # Validate test. Expecting NO event of the first TP and second TP.
351 trace_match_only $EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME
352 trace_match_only $EVENT_NAME2 0 $TRACE_PATH/$SESSION_NAME
353 if [ $? -ne 0 ]; then
354 return $?
355 fi
356 }
357
358 function test_jul_multi_session()
359 {
360 diag "Test JUL with multiple session"
361
362 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
363 enable_jul_lttng_event $SESSION_NAME-1 $EVENT_NAME
364 start_lttng_tracing $SESSION_NAME-1
365
366 create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
367 enable_jul_lttng_event $SESSION_NAME-2 $EVENT_NAME2
368 start_lttng_tracing $SESSION_NAME-2
369
370 # Run 5 times with a 1 second delay and fire second TP.
371 run_app 0 1
372
373 stop_lttng_tracing $SESSION_NAME-1
374 stop_lttng_tracing $SESSION_NAME-2
375 destroy_lttng_session $SESSION_NAME-1
376 destroy_lttng_session $SESSION_NAME-2
377
378 # Validate test. Expecting all events of first TP
379 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
380 if [ $? -ne 0 ]; then
381 return $?
382 fi
383
384 # Validate test. Expecting one event of the second TP.
385 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
386 if [ $? -ne 0 ]; then
387 return $?
388 fi
389 }
390
391 function test_jul_destroy_session()
392 {
393 diag "Test JUL two session with destroy"
394
395 create_lttng_session $SESSION_NAME $TRACE_PATH/first-sess
396 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
397 start_lttng_tracing $SESSION_NAME
398
399 # Run 5 times with a 1 second delay
400 run_app_background 0 1
401
402 # Wait for the applications started in background
403 wait
404
405 stop_lttng_tracing $SESSION_NAME
406 destroy_lttng_session $SESSION_NAME
407
408 # Validate test. Expecting at least one event num 1
409 validate_trace $EVENT_NAME $TRACE_PATH/first-sess
410 if [ $? -ne 0 ]; then
411 return $?
412 fi
413
414 create_lttng_session $SESSION_NAME $TRACE_PATH/second-sess
415 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME2
416 start_lttng_tracing $SESSION_NAME
417
418 # Run 5 times with a 1 second delay
419 run_app_background 0 1
420
421 # Wait for the applications started in background
422 wait
423
424 stop_lttng_tracing $SESSION_NAME
425 destroy_lttng_session $SESSION_NAME
426
427 # Validate test. Expecting only one event num 2
428 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/second-sess
429 if [ $? -ne 0 ]; then
430 return $?
431 fi
432 }
433
434 function test_jul_filtering()
435 {
436 diag "Test JUL filtering"
437
438 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
439 # Enable all event with a filter.
440 enable_jul_filter $SESSION_NAME '*' 'msg == "JUL second logger fired"'
441 start_lttng_tracing $SESSION_NAME
442
443 # Run 5 times with a 1 second delay and fire second TP.
444 run_app 0 1
445
446 stop_lttng_tracing $SESSION_NAME
447 destroy_lttng_session $SESSION_NAME
448
449 # Validate test. Expecting one event of the second TP only.
450 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
451 if [ $? -ne 0 ]; then
452 return $?
453 fi
454
455 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
456 # Enable first Logger but filter msg payload for the INFO one while
457 # triggering the finest and second TP.
458 enable_jul_filter $SESSION_NAME $EVENT_NAME 'msg == "JUL tp fired!"'
459 start_lttng_tracing $SESSION_NAME
460
461 # Run 5 times with a 1 second delay, fire finest and second TP.
462 run_app 1 1
463
464 stop_lttng_tracing $SESSION_NAME
465 destroy_lttng_session $SESSION_NAME
466
467 # Validate test. Expecting NR_ITER event of the main INFO tp.
468 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
469 if [ $? -ne 0 ]; then
470 return $?
471 fi
472 }
473
474 function test_jul_disable()
475 {
476 diag "Test JUL disable event"
477
478 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
479 # Enable all event with a filter.
480 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
481 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME2
482 disable_jul_lttng_event $SESSION_NAME $EVENT_NAME
483 start_lttng_tracing $SESSION_NAME
484
485 # Run 5 times with a 1 second delay and fire second TP.
486 run_app 0 1
487
488 stop_lttng_tracing $SESSION_NAME
489 destroy_lttng_session $SESSION_NAME
490
491 # Validate test. Expecting one event of the second TP only.
492 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
493 if [ $? -ne 0 ]; then
494 return $?
495 fi
496 }
497
498 function test_jul_disable_enable()
499 {
500 diag "Test JUL disable event followed by an enable"
501
502 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
503 # Enable all event with a filter.
504 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
505 disable_jul_lttng_event $SESSION_NAME $EVENT_NAME
506 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
507 start_lttng_tracing $SESSION_NAME
508
509 # Run 5 times with a 1 second delay and fire second TP.
510 run_app 0 1
511
512 stop_lttng_tracing $SESSION_NAME
513 destroy_lttng_session $SESSION_NAME
514
515 # Validate test. Expecting NR_ITER event of the main INFO tp.
516 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
517 if [ $? -ne 0 ]; then
518 return $?
519 fi
520 }
521
522 function test_jul_filter_loglevel()
523 {
524 local BOGUS_EVENT_NAME="not_a_real_event"
525 local FILTER="int_loglevel > 700 || int_loglevel < 700"
526 local ALL_EVENTS="."
527
528 diag "Test JUL a filter with a loglevel"
529
530 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
531 # Enable an event with a filter and the loglevel-only option.
532 enable_jul_filter_loglevel_only $SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" JUL_CONFIG
533 disable_jul_lttng_event $SESSION_NAME $BOGUS_EVENT_NAME
534 enable_jul_filter_loglevel_only $SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" JUL_CONFIG
535 start_lttng_tracing $SESSION_NAME
536
537 # Run 5 times with a 1 second delay and fire second TP.
538 run_app 0 1
539
540 stop_lttng_tracing $SESSION_NAME
541 destroy_lttng_session $SESSION_NAME
542
543 # Validate test. Expecting no events.
544 trace_match_only $ALL_EVENTS 0 $TRACE_PATH/$SESSION_NAME
545 if [ $? -ne 0 ]; then
546 return $?
547 fi
548 }
549
550 plan_tests $NUM_TESTS
551
552 print_test_banner "$TEST_DESC"
553
554 if [ ! -f "$TESTAPP_PATH.class" ]; then
555 withapp=0
556 else
557 withapp=1
558 fi
559
560 skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
561 {
562 start_lttng_sessiond
563
564 tests=(
565 test_jul_multi_session_disable_wildcard
566 test_jul_multi_session_disable
567 test_jul_disable
568 test_jul_disable_enable
569 test_jul_disable_all
570 test_jul_filtering
571 test_jul_multi_session_loglevel
572 test_jul_destroy_session
573 test_jul_loglevel
574 test_jul_loglevel_multiple
575 test_jul_before_start
576 test_jul_after_start
577 test_jul_multi_session
578 test_jul_filter_loglevel
579 )
580
581 for fct_test in ${tests[@]};
582 do
583 TRACE_PATH=$(mktemp -d)
584
585 ${fct_test}
586 if [ $? -ne 0 ]; then
587 break;
588 fi
589 rm -rf $TRACE_PATH
590 done
591
592 stop_lttng_sessiond
593 }
This page took 0.065406 seconds and 4 git commands to generate.