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