Fix: JUL filtering for event *
[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
3e1c9ff7 32NUM_TESTS=92
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
37175ce4
DG
70# MUST set TESTDIR before calling those functions
71
72function test_jul_before_start ()
73{
74 diag "Test JUL application BEFORE tracing starts"
75 create_lttng_session $SESSION_NAME $TRACE_PATH
76 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
77
78 # Run 5 times with a 1 second delay
79 run_app
80
81 start_lttng_tracing $SESSION_NAME
82
83 wait_apps
84
85 stop_lttng_tracing $SESSION_NAME
86 destroy_lttng_session $SESSION_NAME
b2064f54
DG
87
88 # Validate test. Expecting all events.
1b500e7a 89 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
90 if [ $? -ne 0 ]; then
91 return $?
92 fi
37175ce4
DG
93}
94
95function test_jul_after_start ()
96{
97 diag "Test JUL application AFTER tracing starts"
98
99 create_lttng_session $SESSION_NAME $TRACE_PATH
100 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
101 start_lttng_tracing $SESSION_NAME
102
103 # Run 5 times with a 1 second delay
104 run_app
105
106 wait_apps
107
108 stop_lttng_tracing $SESSION_NAME
109 destroy_lttng_session $SESSION_NAME
b2064f54
DG
110
111 # Validate test. Expecting all events.
1b500e7a 112 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
113 if [ $? -ne 0 ]; then
114 return $?
115 fi
116}
117
118function test_jul_loglevel ()
119{
120 diag "Test JUL application with loglevel"
121
122 create_lttng_session $SESSION_NAME $TRACE_PATH
123 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_INFO"
124 start_lttng_tracing $SESSION_NAME
125
126 # Run 5 times with a 1 second delay
127 run_app
128
129 wait_apps
130
131 stop_lttng_tracing $SESSION_NAME
132 destroy_lttng_session $SESSION_NAME
133
134 # Validate test. Expecting all events.
1b500e7a 135 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
136 if [ $? -ne 0 ]; then
137 return $?
138 fi
139
140 diag "Test JUL applications with lower loglevel"
141
142 create_lttng_session $SESSION_NAME $TRACE_PATH
143 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_SEVERE"
144 start_lttng_tracing $SESSION_NAME
145
146 # Run 5 times with a 1 second delay
147 run_app
148
149 wait_apps
150
151 stop_lttng_tracing $SESSION_NAME
152 destroy_lttng_session $SESSION_NAME
153
154 # Validate test. Expecting 0 events.
155 trace_matches $EVENT_NAME 0 $TRACE_PATH
156 if [ $? -ne 0 ]; then
157 return $?
158 fi
159
160 diag "Test JUL applications with higher loglevel"
161
162 create_lttng_session $SESSION_NAME $TRACE_PATH
163 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_FINER"
164 start_lttng_tracing $SESSION_NAME
165
166 # Run 5 times with a 1 second delay
167 run_app
168
169 wait_apps
170
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
190 wait_apps
191
192 stop_lttng_tracing $SESSION_NAME
193 destroy_lttng_session $SESSION_NAME
194
195 # Validate test. Expecting all events times two.
196 trace_matches $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
197 if [ $? -ne 0 ]; then
198 return $?
199 fi
200
201 create_lttng_session $SESSION_NAME $TRACE_PATH
202 enable_jul_lttng_event_loglevel $SESSION_NAME '*' "JUL_INFO"
203 enable_jul_lttng_event_loglevel $SESSION_NAME '*' "JUL_FINEST"
204 start_lttng_tracing $SESSION_NAME
205
206 # Run 5 times with a 1 second delay and fire two TP.
207 run_app 1
208 wait_apps
209
210 stop_lttng_tracing $SESSION_NAME
211 destroy_lttng_session $SESSION_NAME
212
213 # Validate test. Expecting all events times two.
214 trace_matches $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
215 if [ $? -ne 0 ]; then
216 return $?
217 fi
218}
219
3e1c9ff7
DG
220function test_jul_multi_session_loglevel()
221{
222 diag "Test JUL with multiple session"
223
224 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
225 enable_jul_loglevel_only $SESSION_NAME-1 '*' "JUL_INFO"
226 start_lttng_tracing $SESSION_NAME-1
227
228 create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
229 enable_jul_loglevel_only $SESSION_NAME-2 '*' "JUL_FINEST"
230 start_lttng_tracing $SESSION_NAME-2
231
232 # Run 5 times with a 1 second delay and fire second TP.
233 run_app 1 1
234 wait_apps
235
236 stop_lttng_tracing $SESSION_NAME-1
237 stop_lttng_tracing $SESSION_NAME-2
238 destroy_lttng_session $SESSION_NAME-1
239 destroy_lttng_session $SESSION_NAME-2
240
241 # Expecting 6 events being the main event plus the second tp.
242 trace_matches $EVENT_NAME $(($NR_ITER + 1)) $TRACE_PATH/$SESSION_NAME-1
243 if [ $? -ne 0 ]; then
244 return $?
245 fi
246
247 # Expectin 5 events being the finest TP.
248 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
249 if [ $? -ne 0 ]; then
250 return $?
251 fi
252}
253
9b21e6d5
DG
254function test_jul_multi_session()
255{
256 diag "Test JUL with multiple session"
257
258 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
259 enable_jul_lttng_event $SESSION_NAME-1 $EVENT_NAME
260 start_lttng_tracing $SESSION_NAME-1
261
262 create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
263 enable_jul_lttng_event $SESSION_NAME-2 $EVENT_NAME2
264 start_lttng_tracing $SESSION_NAME-2
265
266 # Run 5 times with a 1 second delay and fire second TP.
267 run_app 0 1
268 wait_apps
269
270 stop_lttng_tracing $SESSION_NAME-1
271 stop_lttng_tracing $SESSION_NAME-2
272 destroy_lttng_session $SESSION_NAME-1
273 destroy_lttng_session $SESSION_NAME-2
274
275 # Validate test. Expecting all events of first TP
276 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
277 if [ $? -ne 0 ]; then
278 return $?
279 fi
280
281 # Validate test. Expecting one event of the second TP.
282 trace_matches $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
283 if [ $? -ne 0 ]; then
284 return $?
285 fi
286}
287
3e1c9ff7
DG
288function test_jul_destroy_session()
289{
290 diag "Test JUL two session with destroy"
291
292 create_lttng_session $SESSION_NAME $TRACE_PATH/first-sess
293 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
294 start_lttng_tracing $SESSION_NAME
295
296 # Run 5 times with a 1 second delay
297 run_app 0 1
298
299 sleep 1
300
301 stop_lttng_tracing $SESSION_NAME
302 destroy_lttng_session $SESSION_NAME
303
304 # Validate test. Expecting at least one event num 1
305 validate_trace $EVENT_NAME $TRACE_PATH/first-sess
306 if [ $? -ne 0 ]; then
307 return $?
308 fi
309
310 create_lttng_session $SESSION_NAME $TRACE_PATH/second-sess
311 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME2
312 start_lttng_tracing $SESSION_NAME
313
314 wait_apps
315
316 stop_lttng_tracing $SESSION_NAME
317 destroy_lttng_session $SESSION_NAME
318
319 # Validate test. Expecting only one event num 2
320 trace_matches $EVENT_NAME2 1 $TRACE_PATH/second-sess
321 if [ $? -ne 0 ]; then
322 return $?
323 fi
324}
325
37175ce4
DG
326plan_tests $NUM_TESTS
327
328print_test_banner "$TEST_DESC"
329
330if [ ! -f "$TESTAPP_PATH.class" ]; then
331 withapp=0
332else
333 withapp=1
334fi
335
336skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
337{
338 start_lttng_sessiond
339
340 tests=(
3e1c9ff7
DG
341 test_jul_multi_session_loglevel
342 test_jul_destroy_session
b2064f54 343 test_jul_loglevel
88f54ca9 344 test_jul_loglevel_multiple
37175ce4
DG
345 test_jul_before_start
346 test_jul_after_start
9b21e6d5 347 test_jul_multi_session
37175ce4
DG
348 )
349
350 for fct_test in ${tests[@]};
351 do
3e1c9ff7
DG
352 TRACE_PATH=$(mktemp -d)
353
37175ce4 354 ${fct_test}
b2064f54
DG
355 if [ $? -ne 0 ]; then
356 break;
37175ce4 357 fi
b2064f54 358 rm -rf $TRACE_PATH
37175ce4
DG
359 done
360
361 stop_lttng_sessiond
362}
This page took 0.057199 seconds and 4 git commands to generate.