Commit | Line | Data |
---|---|---|
504d4ace DG |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) - 2014 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 LOG4J 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="log4j" | |
28 | EVENT_NAME="log4j-event" | |
29 | EVENT_NAME2="log4j-event-2" | |
0b7af945 | 30 | JAVA_CP="$CURDIR:$CLASSPATH" |
504d4ace DG |
31 | OUTPUT_DEST="/dev/null" |
32 | ||
42aad3d2 | 33 | NUM_TESTS=195 |
504d4ace DG |
34 | |
35 | source $TESTDIR/utils/utils.sh | |
36 | ||
37 | function run_app | |
38 | { | |
39 | local debug_tp=$1 | |
40 | local fire_second_tp=$2 | |
41 | ||
5fcaccbc | 42 | # FIXME: test app should have synchro. |
0b7af945 | 43 | java -cp $JAVA_CP -Djava.library.path="$LD_LIBRARY_PATH:/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $debug_tp $fire_second_tp >/dev/null 2>&1 |
504d4ace DG |
44 | } |
45 | ||
46 | function run_app_background | |
47 | { | |
48 | run_app $@ & | |
49 | } | |
50 | ||
51 | function enable_log4j_loglevel_only() | |
52 | { | |
53 | sess_name=$1 | |
54 | event_name="$2" | |
55 | loglevel=$3 | |
56 | channel_name=$4 | |
57 | ||
58 | if [ -z $channel_name ]; then | |
59 | # default channel if none specified | |
60 | chan="" | |
61 | else | |
62 | chan="-c $channel_name" | |
63 | fi | |
64 | ||
65 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel-only $loglevel "$event_name" $chan -s $sess_name -l >/dev/null 2>&1 | |
66 | ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel-only $loglevel" | |
67 | } | |
68 | ||
69 | function enable_log4j_filter() | |
70 | { | |
71 | local sess_name="$1" | |
72 | local event_name="$2" | |
73 | local filter="$3" | |
74 | ||
75 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -l --filter "$filter" >/dev/null 2>&1 | |
76 | ok $? "Enable event $event_name with filter $filter for session $sess_name" | |
77 | } | |
78 | ||
79 | function enable_log4j_filter_loglevel_only() | |
80 | { | |
81 | local sess_name="$1" | |
82 | local event_name="$2" | |
83 | local filter="$3" | |
84 | local loglevel="$4" | |
85 | ||
86 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel-only $loglevel "$event_name" -s $sess_name -l --filter "$filter" >/dev/null 2>&1 | |
87 | ok $? "Enable event $event_name with filter \"$filter\" and loglevel-only $loglevel for session $sess_name" | |
88 | } | |
89 | ||
90 | # MUST set TESTDIR before calling those functions | |
91 | ||
92 | function test_log4j_before_start () | |
93 | { | |
5fcaccbc MD |
94 | local file_sync_after_first=$(mktemp -u) |
95 | local file_sync_before_last=$(mktemp -u) | |
96 | ||
504d4ace | 97 | diag "Test LOG4J application BEFORE tracing starts" |
bf6ae429 | 98 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
504d4ace DG |
99 | enable_log4j_lttng_event $SESSION_NAME $EVENT_NAME |
100 | ||
101 | # Run 5 times with a 1 second delay | |
102 | run_app_background | |
103 | ||
e563bbdb | 104 | start_lttng_tracing_ok $SESSION_NAME |
504d4ace | 105 | |
5fcaccbc MD |
106 | touch ${file_sync_before_last} |
107 | ||
504d4ace | 108 | # Wait for the applications started in background |
0fc2834c | 109 | wait |
504d4ace | 110 | |
96340a01 | 111 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 112 | destroy_lttng_session_ok $SESSION_NAME |
504d4ace | 113 | |
5fcaccbc MD |
114 | rm -f ${file_sync_after_first} |
115 | rm -f ${file_sync_before_last} | |
116 | ||
504d4ace DG |
117 | # Validate test. Expecting all events. |
118 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH | |
119 | if [ $? -ne 0 ]; then | |
120 | return $? | |
121 | fi | |
122 | } | |
123 | ||
124 | function test_log4j_after_start () | |
125 | { | |
126 | diag "Test LOG4J application AFTER tracing starts" | |
127 | ||
bf6ae429 | 128 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
504d4ace | 129 | enable_log4j_lttng_event $SESSION_NAME $EVENT_NAME |
e563bbdb | 130 | start_lttng_tracing_ok $SESSION_NAME |
504d4ace DG |
131 | |
132 | # Run 5 times with a 1 second delay | |
133 | run_app | |
134 | ||
96340a01 | 135 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 136 | destroy_lttng_session_ok $SESSION_NAME |
504d4ace DG |
137 | |
138 | # Validate test. Expecting all events. | |
139 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH | |
140 | if [ $? -ne 0 ]; then | |
141 | return $? | |
142 | fi | |
143 | } | |
144 | ||
145 | function test_log4j_loglevel () | |
146 | { | |
147 | diag "Test LOG4J application with loglevel" | |
148 | ||
bf6ae429 | 149 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
504d4ace | 150 | enable_log4j_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "LOG4J_INFO" |
e563bbdb | 151 | start_lttng_tracing_ok $SESSION_NAME |
504d4ace DG |
152 | |
153 | # Run 5 times with a 1 second delay | |
154 | run_app | |
155 | ||
96340a01 | 156 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 157 | destroy_lttng_session_ok $SESSION_NAME |
504d4ace DG |
158 | |
159 | # Validate test. Expecting all events. | |
160 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH | |
161 | if [ $? -ne 0 ]; then | |
162 | return $? | |
163 | fi | |
164 | ||
165 | diag "Test LOG4J applications with lower loglevel" | |
166 | ||
bf6ae429 | 167 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
504d4ace | 168 | enable_log4j_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "LOG4J_FATAL" |
e563bbdb | 169 | start_lttng_tracing_ok $SESSION_NAME |
504d4ace DG |
170 | |
171 | # Run 5 times with a 1 second delay | |
172 | run_app | |
173 | ||
96340a01 | 174 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 175 | destroy_lttng_session_ok $SESSION_NAME |
504d4ace DG |
176 | |
177 | # Validate test. Expecting 0 events. | |
178 | trace_match_only $EVENT_NAME 0 $TRACE_PATH | |
179 | if [ $? -ne 0 ]; then | |
180 | return $? | |
181 | fi | |
182 | ||
183 | diag "Test LOG4J applications with higher loglevel" | |
184 | ||
bf6ae429 | 185 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
504d4ace | 186 | enable_log4j_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "LOG4J_TRACE" |
e563bbdb | 187 | start_lttng_tracing_ok $SESSION_NAME |
504d4ace DG |
188 | |
189 | # Run 5 times with a 1 second delay | |
190 | run_app | |
191 | ||
96340a01 | 192 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 193 | destroy_lttng_session_ok $SESSION_NAME |
504d4ace DG |
194 | |
195 | # Validate test. Expecting all events. | |
196 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH | |
197 | return $? | |
198 | } | |
199 | ||
200 | function test_log4j_loglevel_multiple () | |
201 | { | |
202 | diag "Test LOG4J application with multiple loglevel" | |
203 | ||
bf6ae429 | 204 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
504d4ace DG |
205 | enable_log4j_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "LOG4J_INFO" |
206 | enable_log4j_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "LOG4J_DEBUG" | |
e563bbdb | 207 | start_lttng_tracing_ok $SESSION_NAME |
504d4ace DG |
208 | |
209 | # Run 5 times with a 1 second delay and fire two TP. | |
210 | run_app 1 | |
211 | ||
96340a01 | 212 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 213 | destroy_lttng_session_ok $SESSION_NAME |
504d4ace DG |
214 | |
215 | # Validate test. Expecting all events times two. | |
216 | trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH | |
217 | if [ $? -ne 0 ]; then | |
218 | return $? | |
219 | fi | |
220 | ||
bf6ae429 | 221 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
504d4ace DG |
222 | enable_log4j_lttng_event_loglevel $SESSION_NAME '*' "LOG4J_INFO" |
223 | enable_log4j_lttng_event_loglevel $SESSION_NAME '*' "LOG4J_DEBUG" | |
e563bbdb | 224 | start_lttng_tracing_ok $SESSION_NAME |
504d4ace DG |
225 | |
226 | # Run 5 times with a 1 second delay and fire two TP. | |
227 | run_app 1 | |
228 | ||
96340a01 | 229 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 230 | destroy_lttng_session_ok $SESSION_NAME |
504d4ace DG |
231 | |
232 | # Validate test. Expecting all events times two. | |
233 | trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH | |
234 | if [ $? -ne 0 ]; then | |
235 | return $? | |
236 | fi | |
237 | } | |
238 | ||
239 | function test_log4j_multi_session_loglevel() | |
240 | { | |
241 | diag "Test LOG4J with multiple session" | |
242 | ||
bf6ae429 | 243 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 |
504d4ace | 244 | enable_log4j_loglevel_only $SESSION_NAME-1 '*' "LOG4J_INFO" |
e563bbdb | 245 | start_lttng_tracing_ok $SESSION_NAME-1 |
504d4ace | 246 | |
bf6ae429 | 247 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 |
504d4ace | 248 | enable_log4j_loglevel_only $SESSION_NAME-2 '*' "LOG4J_DEBUG" |
e563bbdb | 249 | start_lttng_tracing_ok $SESSION_NAME-2 |
504d4ace DG |
250 | |
251 | # Run 5 times with a 1 second delay and fire second TP. | |
252 | run_app 1 1 | |
253 | ||
96340a01 JR |
254 | stop_lttng_tracing_ok $SESSION_NAME-1 |
255 | stop_lttng_tracing_ok $SESSION_NAME-2 | |
67b4c664 JR |
256 | destroy_lttng_session_ok $SESSION_NAME-1 |
257 | destroy_lttng_session_ok $SESSION_NAME-2 | |
504d4ace DG |
258 | |
259 | # Expecting 6 events being the main event plus the second tp. | |
260 | trace_match_only $EVENT_NAME $(($NR_ITER + 1)) $TRACE_PATH/$SESSION_NAME-1 | |
261 | if [ $? -ne 0 ]; then | |
262 | return $? | |
263 | fi | |
264 | ||
265 | # Expectin 5 events being the debug TP. | |
266 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2 | |
267 | if [ $? -ne 0 ]; then | |
268 | return $? | |
269 | fi | |
270 | } | |
271 | ||
272 | function test_log4j_multi_session_disable() | |
273 | { | |
274 | diag "Test LOG4J with multiple session with disabled event" | |
275 | ||
bf6ae429 | 276 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 |
504d4ace DG |
277 | enable_log4j_lttng_event $SESSION_NAME-1 $EVENT_NAME |
278 | enable_log4j_lttng_event $SESSION_NAME-1 $EVENT_NAME2 | |
279 | disable_log4j_lttng_event $SESSION_NAME-1 $EVENT_NAME | |
e563bbdb | 280 | start_lttng_tracing_ok $SESSION_NAME-1 |
504d4ace | 281 | |
bf6ae429 | 282 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 |
504d4ace | 283 | enable_log4j_lttng_event $SESSION_NAME-2 $EVENT_NAME2 |
e563bbdb | 284 | start_lttng_tracing_ok $SESSION_NAME-2 |
504d4ace DG |
285 | |
286 | # Run 5 times with a 1 second delay and fire second TP. | |
287 | run_app 0 1 | |
288 | ||
96340a01 JR |
289 | stop_lttng_tracing_ok $SESSION_NAME-1 |
290 | stop_lttng_tracing_ok $SESSION_NAME-2 | |
67b4c664 JR |
291 | destroy_lttng_session_ok $SESSION_NAME-1 |
292 | destroy_lttng_session_ok $SESSION_NAME-2 | |
504d4ace DG |
293 | |
294 | # Validate test. Expecting one event of the second TP. | |
295 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1 | |
296 | if [ $? -ne 0 ]; then | |
297 | return $? | |
298 | fi | |
299 | ||
300 | # Validate test. Expecting one event of the second TP. | |
301 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2 | |
302 | if [ $? -ne 0 ]; then | |
303 | return $? | |
304 | fi | |
305 | } | |
306 | ||
307 | function test_log4j_multi_session_disable_wildcard() | |
308 | { | |
309 | diag "Test LOG4J with multiple session with disabled wildcard event" | |
310 | ||
bf6ae429 | 311 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 |
504d4ace DG |
312 | enable_log4j_lttng_event $SESSION_NAME-1 '*' |
313 | ||
bf6ae429 | 314 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 |
504d4ace DG |
315 | enable_log4j_lttng_event $SESSION_NAME-2 '*' |
316 | ||
317 | disable_log4j_lttng_event $SESSION_NAME-1 '*' | |
318 | ||
e563bbdb JR |
319 | start_lttng_tracing_ok $SESSION_NAME-1 |
320 | start_lttng_tracing_ok $SESSION_NAME-2 | |
504d4ace DG |
321 | |
322 | run_app | |
323 | ||
96340a01 JR |
324 | stop_lttng_tracing_ok $SESSION_NAME-1 |
325 | stop_lttng_tracing_ok $SESSION_NAME-2 | |
67b4c664 JR |
326 | destroy_lttng_session_ok $SESSION_NAME-1 |
327 | destroy_lttng_session_ok $SESSION_NAME-2 | |
504d4ace DG |
328 | |
329 | # Validate test. Expecting NO event of the first TP. | |
330 | trace_match_only $EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME-1 | |
331 | if [ $? -ne 0 ]; then | |
332 | return $? | |
333 | fi | |
334 | ||
335 | # Validate test. Expecting all events of the first TP. | |
336 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2 | |
337 | if [ $? -ne 0 ]; then | |
338 | return $? | |
339 | fi | |
340 | } | |
341 | ||
42aad3d2 PP |
342 | function test_log4j_multi_session_disable_wildcard_begin() |
343 | { | |
344 | ev_name='*-event' | |
345 | diag "Test LOG4J with multiple session with disabled wildcard (at the beginning) event" | |
346 | ||
347 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 | |
348 | enable_log4j_lttng_event $SESSION_NAME-1 "$ev_name" | |
349 | ||
350 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 | |
351 | enable_log4j_lttng_event $SESSION_NAME-2 "$ev_name" | |
352 | ||
353 | disable_log4j_lttng_event $SESSION_NAME-1 "$ev_name" | |
354 | ||
355 | start_lttng_tracing_ok $SESSION_NAME-1 | |
356 | start_lttng_tracing_ok $SESSION_NAME-2 | |
357 | ||
358 | run_app 0 1 | |
359 | ||
360 | stop_lttng_tracing_ok $SESSION_NAME-1 | |
361 | stop_lttng_tracing_ok $SESSION_NAME-2 | |
362 | destroy_lttng_session_ok $SESSION_NAME-1 | |
363 | destroy_lttng_session_ok $SESSION_NAME-2 | |
364 | ||
365 | # Validate test. Expecting NO event of the first TP. | |
366 | trace_match_only $EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME-1 | |
367 | if [ $? -ne 0 ]; then | |
368 | return $? | |
369 | fi | |
370 | ||
371 | # Validate test. Expecting all events of the first TP. | |
372 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2 | |
373 | if [ $? -ne 0 ]; then | |
374 | return $? | |
375 | fi | |
376 | } | |
377 | ||
378 | function test_log4j_multi_session_disable_wildcard_middle() | |
379 | { | |
380 | ev_name='log*nt' | |
381 | diag "Test LOG4J with multiple session with disabled wildcard (at the middle) event" | |
382 | ||
383 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 | |
384 | enable_log4j_lttng_event $SESSION_NAME-1 "$ev_name" | |
385 | ||
386 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 | |
387 | enable_log4j_lttng_event $SESSION_NAME-2 "$ev_name" | |
388 | ||
389 | disable_log4j_lttng_event $SESSION_NAME-1 "$ev_name" | |
390 | ||
391 | start_lttng_tracing_ok $SESSION_NAME-1 | |
392 | start_lttng_tracing_ok $SESSION_NAME-2 | |
393 | ||
394 | run_app 0 1 | |
395 | ||
396 | stop_lttng_tracing_ok $SESSION_NAME-1 | |
397 | stop_lttng_tracing_ok $SESSION_NAME-2 | |
398 | destroy_lttng_session_ok $SESSION_NAME-1 | |
399 | destroy_lttng_session_ok $SESSION_NAME-2 | |
400 | ||
401 | # Validate test. Expecting NO event of the first TP. | |
402 | trace_match_only $EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME-1 | |
403 | if [ $? -ne 0 ]; then | |
404 | return $? | |
405 | fi | |
406 | ||
407 | # Validate test. Expecting all events of the first TP. | |
408 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2 | |
409 | if [ $? -ne 0 ]; then | |
410 | return $? | |
411 | fi | |
412 | } | |
413 | ||
414 | function test_log4j_multi_session_disable_wildcard_end() | |
415 | { | |
416 | ev_name='log4j-ev*' | |
417 | diag "Test LOG4J with multiple session with disabled wildcard (at the end) event" | |
418 | ||
419 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 | |
420 | enable_log4j_lttng_event $SESSION_NAME-1 "$ev_name" | |
421 | ||
422 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 | |
423 | enable_log4j_lttng_event $SESSION_NAME-2 "$ev_name" | |
424 | ||
425 | disable_log4j_lttng_event $SESSION_NAME-1 "$ev_name" | |
426 | ||
427 | start_lttng_tracing_ok $SESSION_NAME-1 | |
428 | start_lttng_tracing_ok $SESSION_NAME-2 | |
429 | ||
430 | run_app 0 1 | |
431 | ||
432 | stop_lttng_tracing_ok $SESSION_NAME-1 | |
433 | stop_lttng_tracing_ok $SESSION_NAME-2 | |
434 | destroy_lttng_session_ok $SESSION_NAME-1 | |
435 | destroy_lttng_session_ok $SESSION_NAME-2 | |
436 | ||
437 | # Validate test. Expecting NO event of the first TP. | |
438 | trace_match_only $EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME-1 | |
439 | if [ $? -ne 0 ]; then | |
440 | return $? | |
441 | fi | |
442 | ||
443 | # Validate test. Expecting all events of the first TP. | |
444 | trace_matches $EVENT_NAME $(( $NR_ITER + 1 )) $TRACE_PATH/$SESSION_NAME-2 | |
445 | if [ $? -ne 0 ]; then | |
446 | return $? | |
447 | fi | |
448 | ||
449 | trace_matches $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2 | |
450 | if [ $? -ne 0 ]; then | |
451 | return $? | |
452 | fi | |
453 | } | |
454 | ||
504d4ace DG |
455 | function test_log4j_disable_all() |
456 | { | |
457 | diag "Test LOG4J with multiple session with disabled all event" | |
458 | ||
bf6ae429 | 459 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
504d4ace DG |
460 | enable_log4j_lttng_event $SESSION_NAME '*' |
461 | enable_log4j_lttng_event $SESSION_NAME $EVENT_NAME | |
462 | enable_log4j_lttng_event $SESSION_NAME $EVENT_NAME2 | |
463 | ||
c364f6e0 | 464 | disable_log4j_lttng_event $SESSION_NAME -a |
504d4ace | 465 | |
e563bbdb | 466 | start_lttng_tracing_ok $SESSION_NAME |
504d4ace DG |
467 | |
468 | run_app 0 1 | |
469 | ||
96340a01 | 470 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 471 | destroy_lttng_session_ok $SESSION_NAME |
504d4ace DG |
472 | |
473 | # Validate test. Expecting NO event of the first TP and second TP. | |
474 | trace_match_only $EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME | |
475 | trace_match_only $EVENT_NAME2 0 $TRACE_PATH/$SESSION_NAME | |
476 | if [ $? -ne 0 ]; then | |
477 | return $? | |
478 | fi | |
479 | } | |
480 | ||
481 | function test_log4j_multi_session() | |
482 | { | |
483 | diag "Test LOG4J with multiple session" | |
484 | ||
bf6ae429 | 485 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 |
504d4ace | 486 | enable_log4j_lttng_event $SESSION_NAME-1 $EVENT_NAME |
e563bbdb | 487 | start_lttng_tracing_ok $SESSION_NAME-1 |
504d4ace | 488 | |
bf6ae429 | 489 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 |
504d4ace | 490 | enable_log4j_lttng_event $SESSION_NAME-2 $EVENT_NAME2 |
e563bbdb | 491 | start_lttng_tracing_ok $SESSION_NAME-2 |
504d4ace DG |
492 | |
493 | # Run 5 times with a 1 second delay and fire second TP. | |
494 | run_app 0 1 | |
495 | ||
96340a01 JR |
496 | stop_lttng_tracing_ok $SESSION_NAME-1 |
497 | stop_lttng_tracing_ok $SESSION_NAME-2 | |
67b4c664 JR |
498 | destroy_lttng_session_ok $SESSION_NAME-1 |
499 | destroy_lttng_session_ok $SESSION_NAME-2 | |
504d4ace DG |
500 | |
501 | # Validate test. Expecting all events of first TP | |
502 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1 | |
503 | if [ $? -ne 0 ]; then | |
504 | return $? | |
505 | fi | |
506 | ||
507 | # Validate test. Expecting one event of the second TP. | |
508 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2 | |
509 | if [ $? -ne 0 ]; then | |
510 | return $? | |
511 | fi | |
512 | } | |
513 | ||
514 | function test_log4j_destroy_session() | |
515 | { | |
516 | diag "Test LOG4J two session with destroy" | |
517 | ||
bf6ae429 | 518 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/first-sess |
504d4ace | 519 | enable_log4j_lttng_event $SESSION_NAME $EVENT_NAME |
e563bbdb | 520 | start_lttng_tracing_ok $SESSION_NAME |
504d4ace DG |
521 | |
522 | # Run 5 times with a 1 second delay | |
523 | run_app_background 0 1 | |
0fc2834c MD |
524 | # Wait for the applications started in background |
525 | wait | |
504d4ace | 526 | |
96340a01 | 527 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 528 | destroy_lttng_session_ok $SESSION_NAME |
504d4ace DG |
529 | |
530 | # Validate test. Expecting at least one event num 1 | |
531 | validate_trace $EVENT_NAME $TRACE_PATH/first-sess | |
532 | if [ $? -ne 0 ]; then | |
533 | return $? | |
534 | fi | |
535 | ||
bf6ae429 | 536 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/second-sess |
504d4ace | 537 | enable_log4j_lttng_event $SESSION_NAME $EVENT_NAME2 |
e563bbdb | 538 | start_lttng_tracing_ok $SESSION_NAME |
504d4ace | 539 | |
0fc2834c MD |
540 | # Run 5 times with a 1 second delay |
541 | run_app_background 0 1 | |
504d4ace | 542 | # Wait for the applications started in background |
0fc2834c | 543 | wait |
504d4ace | 544 | |
96340a01 | 545 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 546 | destroy_lttng_session_ok $SESSION_NAME |
504d4ace DG |
547 | |
548 | # Validate test. Expecting only one event num 2 | |
549 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/second-sess | |
550 | if [ $? -ne 0 ]; then | |
551 | return $? | |
552 | fi | |
553 | } | |
554 | ||
555 | function test_log4j_filtering() | |
556 | { | |
557 | diag "Test LOG4J filtering" | |
558 | ||
bf6ae429 | 559 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
504d4ace DG |
560 | # Enable all event with a filter. |
561 | enable_log4j_filter $SESSION_NAME '*' 'msg == "LOG4J second logger fired"' | |
e563bbdb | 562 | start_lttng_tracing_ok $SESSION_NAME |
504d4ace DG |
563 | |
564 | # Run 5 times with a 1 second delay and fire second TP. | |
565 | run_app 0 1 | |
566 | ||
96340a01 | 567 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 568 | destroy_lttng_session_ok $SESSION_NAME |
504d4ace DG |
569 | |
570 | # Validate test. Expecting one event of the second TP only. | |
571 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME | |
572 | if [ $? -ne 0 ]; then | |
573 | return $? | |
574 | fi | |
575 | ||
bf6ae429 | 576 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
504d4ace DG |
577 | # Enable first Logger but filter msg payload for the INFO one while |
578 | # triggering the debug and second TP. | |
579 | enable_log4j_filter $SESSION_NAME $EVENT_NAME 'msg == "LOG4J tp fired!"' | |
e563bbdb | 580 | start_lttng_tracing_ok $SESSION_NAME |
504d4ace DG |
581 | |
582 | # Run 5 times with a 1 second delay, fire debug and second TP. | |
583 | run_app 1 1 | |
584 | ||
96340a01 | 585 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 586 | destroy_lttng_session_ok $SESSION_NAME |
504d4ace DG |
587 | |
588 | # Validate test. Expecting NR_ITER event of the main INFO tp. | |
589 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME | |
590 | if [ $? -ne 0 ]; then | |
591 | return $? | |
592 | fi | |
593 | } | |
594 | ||
595 | function test_log4j_disable() | |
596 | { | |
597 | diag "Test LOG4J disable event" | |
598 | ||
bf6ae429 | 599 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
504d4ace DG |
600 | # Enable all event with a filter. |
601 | enable_log4j_lttng_event $SESSION_NAME $EVENT_NAME | |
602 | enable_log4j_lttng_event $SESSION_NAME $EVENT_NAME2 | |
603 | disable_log4j_lttng_event $SESSION_NAME $EVENT_NAME | |
e563bbdb | 604 | start_lttng_tracing_ok $SESSION_NAME |
504d4ace DG |
605 | |
606 | # Run 5 times with a 1 second delay and fire second TP. | |
607 | run_app 0 1 | |
608 | ||
96340a01 | 609 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 610 | destroy_lttng_session_ok $SESSION_NAME |
504d4ace DG |
611 | |
612 | # Validate test. Expecting one event of the second TP only. | |
613 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME | |
614 | if [ $? -ne 0 ]; then | |
615 | return $? | |
616 | fi | |
617 | } | |
618 | ||
619 | function test_log4j_disable_enable() | |
620 | { | |
621 | diag "Test LOG4J disable event followed by an enable" | |
622 | ||
bf6ae429 | 623 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
504d4ace DG |
624 | # Enable all event with a filter. |
625 | enable_log4j_lttng_event $SESSION_NAME $EVENT_NAME | |
626 | disable_log4j_lttng_event $SESSION_NAME $EVENT_NAME | |
627 | enable_log4j_lttng_event $SESSION_NAME $EVENT_NAME | |
e563bbdb | 628 | start_lttng_tracing_ok $SESSION_NAME |
504d4ace DG |
629 | |
630 | # Run 5 times with a 1 second delay and fire second TP. | |
631 | run_app 0 1 | |
632 | ||
96340a01 | 633 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 634 | destroy_lttng_session_ok $SESSION_NAME |
504d4ace DG |
635 | |
636 | # Validate test. Expecting NR_ITER event of the main INFO tp. | |
637 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME | |
638 | if [ $? -ne 0 ]; then | |
639 | return $? | |
640 | fi | |
641 | } | |
642 | ||
643 | function test_log4j_filter_loglevel() | |
644 | { | |
645 | local BOGUS_EVENT_NAME="not_a_real_event" | |
646 | local FILTER="int_loglevel > 700 || int_loglevel < 700" | |
647 | local ALL_EVENTS="." | |
648 | ||
649 | diag "Test LOG4J a filter with a loglevel" | |
650 | ||
bf6ae429 | 651 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
504d4ace DG |
652 | # Enable an event with a filter and the loglevel-only option. |
653 | enable_log4j_filter_loglevel_only $SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" LOG4J_INFO | |
654 | disable_log4j_lttng_event $SESSION_NAME $BOGUS_EVENT_NAME | |
655 | enable_log4j_filter_loglevel_only $SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" LOG4J_INFO | |
e563bbdb | 656 | start_lttng_tracing_ok $SESSION_NAME |
504d4ace DG |
657 | |
658 | # Run 5 times with a 1 second delay and fire second TP. | |
659 | run_app 0 1 | |
660 | ||
96340a01 | 661 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 662 | destroy_lttng_session_ok $SESSION_NAME |
504d4ace DG |
663 | |
664 | # Validate test. Expecting no events. | |
665 | trace_match_only $ALL_EVENTS 0 $TRACE_PATH/$SESSION_NAME | |
666 | if [ $? -ne 0 ]; then | |
667 | return $? | |
668 | fi | |
669 | } | |
670 | ||
671 | plan_tests $NUM_TESTS | |
672 | ||
673 | print_test_banner "$TEST_DESC" | |
674 | ||
675 | if [ ! -f "$TESTAPP_PATH.class" ]; then | |
676 | withapp=0 | |
677 | else | |
678 | withapp=1 | |
679 | fi | |
680 | ||
681 | skip $withapp "LOG4J support is needed. Skipping all tests." $NUM_TESTS || | |
682 | { | |
683 | start_lttng_sessiond | |
684 | ||
685 | tests=( | |
686 | test_log4j_multi_session_disable_wildcard | |
42aad3d2 PP |
687 | test_log4j_multi_session_disable_wildcard_begin |
688 | test_log4j_multi_session_disable_wildcard_middle | |
689 | test_log4j_multi_session_disable_wildcard_end | |
504d4ace DG |
690 | test_log4j_multi_session_disable |
691 | test_log4j_disable | |
692 | test_log4j_disable_enable | |
693 | test_log4j_disable_all | |
694 | test_log4j_filtering | |
695 | test_log4j_multi_session_loglevel | |
696 | test_log4j_destroy_session | |
697 | test_log4j_loglevel | |
698 | test_log4j_loglevel_multiple | |
699 | test_log4j_before_start | |
700 | test_log4j_after_start | |
701 | test_log4j_multi_session | |
702 | test_log4j_filter_loglevel | |
703 | ) | |
704 | ||
705 | for fct_test in ${tests[@]}; | |
706 | do | |
707 | TRACE_PATH=$(mktemp -d) | |
708 | ||
709 | ${fct_test} | |
710 | if [ $? -ne 0 ]; then | |
711 | break; | |
712 | fi | |
713 | rm -rf $TRACE_PATH | |
714 | done | |
715 | ||
716 | stop_lttng_sessiond | |
717 | } |