Fix: add missing JUL loglevel handling
[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 JAVA_CP="$CURDIR:/usr/local/lib/lttng/java/liblttng-ust-jul.jar:/usr/lib/lttng/java/liblttng-ust-jul.jar"
30
31 TRACE_PATH=$(mktemp -d)
32
33 NUM_TESTS=37
34
35 source $TESTDIR/utils/utils.sh
36
37 function run_app
38 {
39 java -cp $JAVA_CP -Djava.library.path="/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT >/dev/null 2>&1 &
40 }
41
42 function wait_apps
43 {
44 while [ -n "$(pidof java)" ]; do
45 sleep 0.5
46 done
47 pass "Wait for applications to end"
48 }
49
50 # MUST set TESTDIR before calling those functions
51
52 function test_jul_before_start ()
53 {
54 diag "Test JUL application BEFORE tracing starts"
55 create_lttng_session $SESSION_NAME $TRACE_PATH
56 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
57
58 # Run 5 times with a 1 second delay
59 run_app
60
61 start_lttng_tracing $SESSION_NAME
62
63 wait_apps
64
65 stop_lttng_tracing $SESSION_NAME
66 destroy_lttng_session $SESSION_NAME
67
68 # Validate test. Expecting all events.
69 trace_matches $EVENT_NAME $(($NR_ITER - 1)) $TRACE_PATH
70 if [ $? -ne 0 ]; then
71 return $?
72 fi
73 }
74
75 function test_jul_after_start ()
76 {
77 diag "Test JUL application AFTER tracing starts"
78
79 create_lttng_session $SESSION_NAME $TRACE_PATH
80 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
81 start_lttng_tracing $SESSION_NAME
82
83 # Run 5 times with a 1 second delay
84 run_app
85
86 wait_apps
87
88 stop_lttng_tracing $SESSION_NAME
89 destroy_lttng_session $SESSION_NAME
90
91 # Validate test. Expecting all events.
92 trace_matches $EVENT_NAME $(($NR_ITER - 1)) $TRACE_PATH
93 if [ $? -ne 0 ]; then
94 return $?
95 fi
96 }
97
98 function test_jul_loglevel ()
99 {
100 diag "Test JUL application with loglevel"
101
102 create_lttng_session $SESSION_NAME $TRACE_PATH
103 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_INFO"
104 start_lttng_tracing $SESSION_NAME
105
106 # Run 5 times with a 1 second delay
107 run_app
108
109 wait_apps
110
111 stop_lttng_tracing $SESSION_NAME
112 destroy_lttng_session $SESSION_NAME
113
114 # Validate test. Expecting all events.
115 trace_matches $EVENT_NAME $(($NR_ITER - 1)) $TRACE_PATH
116 if [ $? -ne 0 ]; then
117 return $?
118 fi
119
120 diag "Test JUL applications with lower loglevel"
121
122 create_lttng_session $SESSION_NAME $TRACE_PATH
123 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_SEVERE"
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 0 events.
135 trace_matches $EVENT_NAME 0 $TRACE_PATH
136 if [ $? -ne 0 ]; then
137 return $?
138 fi
139
140 diag "Test JUL applications with higher loglevel"
141
142 create_lttng_session $SESSION_NAME $TRACE_PATH
143 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_FINER"
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 all events.
155 trace_matches $EVENT_NAME $(($NR_ITER - 1)) $TRACE_PATH
156 return $?
157 }
158
159 plan_tests $NUM_TESTS
160
161 print_test_banner "$TEST_DESC"
162
163 if [ ! -f "$TESTAPP_PATH.class" ]; then
164 withapp=0
165 else
166 withapp=1
167 fi
168
169 skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
170 {
171 start_lttng_sessiond
172
173 tests=(
174 test_jul_loglevel
175 test_jul_before_start
176 test_jul_after_start
177 )
178
179 for fct_test in ${tests[@]};
180 do
181 ${fct_test}
182 if [ $? -ne 0 ]; then
183 break;
184 fi
185 rm -rf $TRACE_PATH
186 done
187
188 stop_lttng_sessiond
189 }
This page took 0.051305 seconds and 5 git commands to generate.