a91904af4b28f1323a9f5a04aad4e2d97d2c4151
[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=92
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 wait_apps
45 {
46 while [ -n "$(pidof java)" ]; do
47 sleep 0.5
48 done
49 pass "Wait for applications to end"
50 }
51
52 function 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
70 # MUST set TESTDIR before calling those functions
71
72 function 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
87
88 # Validate test. Expecting all events.
89 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
90 if [ $? -ne 0 ]; then
91 return $?
92 fi
93 }
94
95 function 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
110
111 # Validate test. Expecting all events.
112 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
113 if [ $? -ne 0 ]; then
114 return $?
115 fi
116 }
117
118 function 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.
135 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
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.
175 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
176 return $?
177 }
178
179 function 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
220 function 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
254 function 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
288 function 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
326 plan_tests $NUM_TESTS
327
328 print_test_banner "$TEST_DESC"
329
330 if [ ! -f "$TESTAPP_PATH.class" ]; then
331 withapp=0
332 else
333 withapp=1
334 fi
335
336 skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
337 {
338 start_lttng_sessiond
339
340 tests=(
341 test_jul_multi_session_loglevel
342 test_jul_destroy_session
343 test_jul_loglevel
344 test_jul_loglevel_multiple
345 test_jul_before_start
346 test_jul_after_start
347 test_jul_multi_session
348 )
349
350 for fct_test in ${tests[@]};
351 do
352 TRACE_PATH=$(mktemp -d)
353
354 ${fct_test}
355 if [ $? -ne 0 ]; then
356 break;
357 fi
358 rm -rf $TRACE_PATH
359 done
360
361 stop_lttng_sessiond
362 }
This page took 0.056095 seconds and 4 git commands to generate.