Fix: disable JUL event on UST side
[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
34c40351 32NUM_TESTS=106
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
9b21e6d5
DG
264function test_jul_multi_session()
265{
266 diag "Test JUL with multiple session"
267
268 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
269 enable_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 wait_apps
279
280 stop_lttng_tracing $SESSION_NAME-1
281 stop_lttng_tracing $SESSION_NAME-2
282 destroy_lttng_session $SESSION_NAME-1
283 destroy_lttng_session $SESSION_NAME-2
284
285 # Validate test. Expecting all events of first TP
286 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
287 if [ $? -ne 0 ]; then
288 return $?
289 fi
290
291 # Validate test. Expecting one event of the second TP.
292 trace_matches $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
293 if [ $? -ne 0 ]; then
294 return $?
295 fi
296}
297
3e1c9ff7
DG
298function test_jul_destroy_session()
299{
300 diag "Test JUL two session with destroy"
301
302 create_lttng_session $SESSION_NAME $TRACE_PATH/first-sess
303 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
304 start_lttng_tracing $SESSION_NAME
305
306 # Run 5 times with a 1 second delay
307 run_app 0 1
308
309 sleep 1
310
311 stop_lttng_tracing $SESSION_NAME
312 destroy_lttng_session $SESSION_NAME
313
314 # Validate test. Expecting at least one event num 1
315 validate_trace $EVENT_NAME $TRACE_PATH/first-sess
316 if [ $? -ne 0 ]; then
317 return $?
318 fi
319
320 create_lttng_session $SESSION_NAME $TRACE_PATH/second-sess
321 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME2
322 start_lttng_tracing $SESSION_NAME
323
324 wait_apps
325
326 stop_lttng_tracing $SESSION_NAME
327 destroy_lttng_session $SESSION_NAME
328
329 # Validate test. Expecting only one event num 2
330 trace_matches $EVENT_NAME2 1 $TRACE_PATH/second-sess
331 if [ $? -ne 0 ]; then
332 return $?
333 fi
334}
335
34c40351
DG
336function test_jul_filtering()
337{
338 diag "Test JUL filtering"
339
340 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
341 # Enable all event with a filter.
342 enable_jul_filter $SESSION_NAME '*' 'msg == "JUL second logger fired"'
343 start_lttng_tracing $SESSION_NAME
344
345 # Run 5 times with a 1 second delay and fire second TP.
346 run_app 0 1
347 wait_apps
348
349 stop_lttng_tracing $SESSION_NAME
350 destroy_lttng_session $SESSION_NAME
351
352 # Validate test. Expecting one event of the second TP only.
353 trace_matches $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
354 if [ $? -ne 0 ]; then
355 return $?
356 fi
357
358 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
359 # Enable first Logger but filter msg payload for the INFO one while
360 # triggering the finest and second TP.
361 enable_jul_filter $SESSION_NAME $EVENT_NAME 'msg == "JUL tp fired!"'
362 start_lttng_tracing $SESSION_NAME
363
364 # Run 5 times with a 1 second delay, fire finest and second TP.
365 run_app 1 1
366 wait_apps
367
368 stop_lttng_tracing $SESSION_NAME
369 destroy_lttng_session $SESSION_NAME
370
371 # Validate test. Expecting NR_ITER event of the main INFO tp.
372 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
373 if [ $? -ne 0 ]; then
374 return $?
375 fi
376}
377
37175ce4
DG
378plan_tests $NUM_TESTS
379
380print_test_banner "$TEST_DESC"
381
382if [ ! -f "$TESTAPP_PATH.class" ]; then
383 withapp=0
384else
385 withapp=1
386fi
387
388skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
389{
390 start_lttng_sessiond
391
392 tests=(
34c40351 393 test_jul_filtering
3e1c9ff7
DG
394 test_jul_multi_session_loglevel
395 test_jul_destroy_session
b2064f54 396 test_jul_loglevel
88f54ca9 397 test_jul_loglevel_multiple
37175ce4
DG
398 test_jul_before_start
399 test_jul_after_start
9b21e6d5 400 test_jul_multi_session
37175ce4
DG
401 )
402
403 for fct_test in ${tests[@]};
404 do
3e1c9ff7
DG
405 TRACE_PATH=$(mktemp -d)
406
37175ce4 407 ${fct_test}
b2064f54
DG
408 if [ $? -ne 0 ]; then
409 break;
37175ce4 410 fi
b2064f54 411 rm -rf $TRACE_PATH
37175ce4
DG
412 done
413
414 stop_lttng_sessiond
415}
This page took 0.060695 seconds and 4 git commands to generate.