Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
88f54ca9 | 33 | NUM_TESTS=53 |
37175ce4 DG |
34 | |
35 | source $TESTDIR/utils/utils.sh | |
36 | ||
37 | function run_app | |
38 | { | |
88f54ca9 DG |
39 | local finest_tp=$1 |
40 | ||
41 | java -cp $JAVA_CP -Djava.library.path="/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $finest_tp >/dev/null 2>&1 & | |
37175ce4 DG |
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 | # MUST set TESTDIR before calling those functions | |
53 | ||
54 | function test_jul_before_start () | |
55 | { | |
56 | diag "Test JUL application BEFORE tracing starts" | |
57 | create_lttng_session $SESSION_NAME $TRACE_PATH | |
58 | enable_jul_lttng_event $SESSION_NAME $EVENT_NAME | |
59 | ||
60 | # Run 5 times with a 1 second delay | |
61 | run_app | |
62 | ||
63 | start_lttng_tracing $SESSION_NAME | |
64 | ||
65 | wait_apps | |
66 | ||
67 | stop_lttng_tracing $SESSION_NAME | |
68 | destroy_lttng_session $SESSION_NAME | |
b2064f54 DG |
69 | |
70 | # Validate test. Expecting all events. | |
1b500e7a | 71 | trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH |
b2064f54 DG |
72 | if [ $? -ne 0 ]; then |
73 | return $? | |
74 | fi | |
37175ce4 DG |
75 | } |
76 | ||
77 | function test_jul_after_start () | |
78 | { | |
79 | diag "Test JUL application AFTER tracing starts" | |
80 | ||
81 | create_lttng_session $SESSION_NAME $TRACE_PATH | |
82 | enable_jul_lttng_event $SESSION_NAME $EVENT_NAME | |
83 | start_lttng_tracing $SESSION_NAME | |
84 | ||
85 | # Run 5 times with a 1 second delay | |
86 | run_app | |
87 | ||
88 | wait_apps | |
89 | ||
90 | stop_lttng_tracing $SESSION_NAME | |
91 | destroy_lttng_session $SESSION_NAME | |
b2064f54 DG |
92 | |
93 | # Validate test. Expecting all events. | |
1b500e7a | 94 | trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH |
b2064f54 DG |
95 | if [ $? -ne 0 ]; then |
96 | return $? | |
97 | fi | |
98 | } | |
99 | ||
100 | function test_jul_loglevel () | |
101 | { | |
102 | diag "Test JUL application with loglevel" | |
103 | ||
104 | create_lttng_session $SESSION_NAME $TRACE_PATH | |
105 | enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_INFO" | |
106 | start_lttng_tracing $SESSION_NAME | |
107 | ||
108 | # Run 5 times with a 1 second delay | |
109 | run_app | |
110 | ||
111 | wait_apps | |
112 | ||
113 | stop_lttng_tracing $SESSION_NAME | |
114 | destroy_lttng_session $SESSION_NAME | |
115 | ||
116 | # Validate test. Expecting all events. | |
1b500e7a | 117 | trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH |
b2064f54 DG |
118 | if [ $? -ne 0 ]; then |
119 | return $? | |
120 | fi | |
121 | ||
122 | diag "Test JUL applications with lower loglevel" | |
123 | ||
124 | create_lttng_session $SESSION_NAME $TRACE_PATH | |
125 | enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_SEVERE" | |
126 | start_lttng_tracing $SESSION_NAME | |
127 | ||
128 | # Run 5 times with a 1 second delay | |
129 | run_app | |
130 | ||
131 | wait_apps | |
132 | ||
133 | stop_lttng_tracing $SESSION_NAME | |
134 | destroy_lttng_session $SESSION_NAME | |
135 | ||
136 | # Validate test. Expecting 0 events. | |
137 | trace_matches $EVENT_NAME 0 $TRACE_PATH | |
138 | if [ $? -ne 0 ]; then | |
139 | return $? | |
140 | fi | |
141 | ||
142 | diag "Test JUL applications with higher loglevel" | |
143 | ||
144 | create_lttng_session $SESSION_NAME $TRACE_PATH | |
145 | enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_FINER" | |
146 | start_lttng_tracing $SESSION_NAME | |
147 | ||
148 | # Run 5 times with a 1 second delay | |
149 | run_app | |
150 | ||
151 | wait_apps | |
152 | ||
153 | stop_lttng_tracing $SESSION_NAME | |
154 | destroy_lttng_session $SESSION_NAME | |
155 | ||
156 | # Validate test. Expecting all events. | |
1b500e7a | 157 | trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH |
b2064f54 | 158 | return $? |
37175ce4 DG |
159 | } |
160 | ||
88f54ca9 DG |
161 | function test_jul_loglevel_multiple () |
162 | { | |
163 | diag "Test JUL application with multiple loglevel" | |
164 | ||
165 | create_lttng_session $SESSION_NAME $TRACE_PATH | |
166 | enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_INFO" | |
167 | enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_FINEST" | |
168 | start_lttng_tracing $SESSION_NAME | |
169 | ||
170 | # Run 5 times with a 1 second delay and fire two TP. | |
171 | run_app 1 | |
172 | wait_apps | |
173 | ||
174 | stop_lttng_tracing $SESSION_NAME | |
175 | destroy_lttng_session $SESSION_NAME | |
176 | ||
177 | # Validate test. Expecting all events times two. | |
178 | trace_matches $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH | |
179 | if [ $? -ne 0 ]; then | |
180 | return $? | |
181 | fi | |
182 | ||
183 | create_lttng_session $SESSION_NAME $TRACE_PATH | |
184 | enable_jul_lttng_event_loglevel $SESSION_NAME '*' "JUL_INFO" | |
185 | enable_jul_lttng_event_loglevel $SESSION_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 | ||
37175ce4 DG |
202 | plan_tests $NUM_TESTS |
203 | ||
204 | print_test_banner "$TEST_DESC" | |
205 | ||
206 | if [ ! -f "$TESTAPP_PATH.class" ]; then | |
207 | withapp=0 | |
208 | else | |
209 | withapp=1 | |
210 | fi | |
211 | ||
212 | skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS || | |
213 | { | |
214 | start_lttng_sessiond | |
215 | ||
216 | tests=( | |
b2064f54 | 217 | test_jul_loglevel |
88f54ca9 | 218 | test_jul_loglevel_multiple |
37175ce4 DG |
219 | test_jul_before_start |
220 | test_jul_after_start | |
221 | ) | |
222 | ||
223 | for fct_test in ${tests[@]}; | |
224 | do | |
225 | ${fct_test} | |
b2064f54 DG |
226 | if [ $? -ne 0 ]; then |
227 | break; | |
37175ce4 | 228 | fi |
b2064f54 | 229 | rm -rf $TRACE_PATH |
37175ce4 DG |
230 | done |
231 | ||
232 | stop_lttng_sessiond | |
233 | } |