Fix: Don't output to stdout from lttng-ctl
[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
32TRACE_PATH=$(mktemp -d)
33
9b21e6d5 34NUM_TESTS=66
37175ce4
DG
35
36source $TESTDIR/utils/utils.sh
37
38function run_app
39{
88f54ca9 40 local finest_tp=$1
9b21e6d5 41 local fire_second_tp=$2
88f54ca9 42
9b21e6d5 43 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
44}
45
46function wait_apps
47{
48 while [ -n "$(pidof java)" ]; do
49 sleep 0.5
50 done
51 pass "Wait for applications to end"
52}
53
54# MUST set TESTDIR before calling those functions
55
56function test_jul_before_start ()
57{
58 diag "Test JUL application BEFORE tracing starts"
59 create_lttng_session $SESSION_NAME $TRACE_PATH
60 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
61
62 # Run 5 times with a 1 second delay
63 run_app
64
65 start_lttng_tracing $SESSION_NAME
66
67 wait_apps
68
69 stop_lttng_tracing $SESSION_NAME
70 destroy_lttng_session $SESSION_NAME
b2064f54
DG
71
72 # Validate test. Expecting all events.
1b500e7a 73 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
74 if [ $? -ne 0 ]; then
75 return $?
76 fi
37175ce4
DG
77}
78
79function test_jul_after_start ()
80{
81 diag "Test JUL application AFTER tracing starts"
82
83 create_lttng_session $SESSION_NAME $TRACE_PATH
84 enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
85 start_lttng_tracing $SESSION_NAME
86
87 # Run 5 times with a 1 second delay
88 run_app
89
90 wait_apps
91
92 stop_lttng_tracing $SESSION_NAME
93 destroy_lttng_session $SESSION_NAME
b2064f54
DG
94
95 # Validate test. Expecting all events.
1b500e7a 96 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
97 if [ $? -ne 0 ]; then
98 return $?
99 fi
100}
101
102function test_jul_loglevel ()
103{
104 diag "Test JUL application with loglevel"
105
106 create_lttng_session $SESSION_NAME $TRACE_PATH
107 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_INFO"
108 start_lttng_tracing $SESSION_NAME
109
110 # Run 5 times with a 1 second delay
111 run_app
112
113 wait_apps
114
115 stop_lttng_tracing $SESSION_NAME
116 destroy_lttng_session $SESSION_NAME
117
118 # Validate test. Expecting all events.
1b500e7a 119 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
120 if [ $? -ne 0 ]; then
121 return $?
122 fi
123
124 diag "Test JUL applications with lower loglevel"
125
126 create_lttng_session $SESSION_NAME $TRACE_PATH
127 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_SEVERE"
128 start_lttng_tracing $SESSION_NAME
129
130 # Run 5 times with a 1 second delay
131 run_app
132
133 wait_apps
134
135 stop_lttng_tracing $SESSION_NAME
136 destroy_lttng_session $SESSION_NAME
137
138 # Validate test. Expecting 0 events.
139 trace_matches $EVENT_NAME 0 $TRACE_PATH
140 if [ $? -ne 0 ]; then
141 return $?
142 fi
143
144 diag "Test JUL applications with higher loglevel"
145
146 create_lttng_session $SESSION_NAME $TRACE_PATH
147 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_FINER"
148 start_lttng_tracing $SESSION_NAME
149
150 # Run 5 times with a 1 second delay
151 run_app
152
153 wait_apps
154
155 stop_lttng_tracing $SESSION_NAME
156 destroy_lttng_session $SESSION_NAME
157
158 # Validate test. Expecting all events.
1b500e7a 159 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54 160 return $?
37175ce4
DG
161}
162
88f54ca9
DG
163function test_jul_loglevel_multiple ()
164{
165 diag "Test JUL application with multiple loglevel"
166
167 create_lttng_session $SESSION_NAME $TRACE_PATH
168 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_INFO"
169 enable_jul_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "JUL_FINEST"
170 start_lttng_tracing $SESSION_NAME
171
172 # Run 5 times with a 1 second delay and fire two TP.
173 run_app 1
174 wait_apps
175
176 stop_lttng_tracing $SESSION_NAME
177 destroy_lttng_session $SESSION_NAME
178
179 # Validate test. Expecting all events times two.
180 trace_matches $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
181 if [ $? -ne 0 ]; then
182 return $?
183 fi
184
185 create_lttng_session $SESSION_NAME $TRACE_PATH
186 enable_jul_lttng_event_loglevel $SESSION_NAME '*' "JUL_INFO"
187 enable_jul_lttng_event_loglevel $SESSION_NAME '*' "JUL_FINEST"
188 start_lttng_tracing $SESSION_NAME
189
190 # Run 5 times with a 1 second delay and fire two TP.
191 run_app 1
192 wait_apps
193
194 stop_lttng_tracing $SESSION_NAME
195 destroy_lttng_session $SESSION_NAME
196
197 # Validate test. Expecting all events times two.
198 trace_matches $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
199 if [ $? -ne 0 ]; then
200 return $?
201 fi
202}
203
9b21e6d5
DG
204function test_jul_multi_session()
205{
206 diag "Test JUL with multiple session"
207
208 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
209 enable_jul_lttng_event $SESSION_NAME-1 $EVENT_NAME
210 start_lttng_tracing $SESSION_NAME-1
211
212 create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
213 enable_jul_lttng_event $SESSION_NAME-2 $EVENT_NAME2
214 start_lttng_tracing $SESSION_NAME-2
215
216 # Run 5 times with a 1 second delay and fire second TP.
217 run_app 0 1
218 wait_apps
219
220 stop_lttng_tracing $SESSION_NAME-1
221 stop_lttng_tracing $SESSION_NAME-2
222 destroy_lttng_session $SESSION_NAME-1
223 destroy_lttng_session $SESSION_NAME-2
224
225 # Validate test. Expecting all events of first TP
226 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
227 if [ $? -ne 0 ]; then
228 return $?
229 fi
230
231 # Validate test. Expecting one event of the second TP.
232 trace_matches $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
233 if [ $? -ne 0 ]; then
234 return $?
235 fi
236}
237
37175ce4
DG
238plan_tests $NUM_TESTS
239
240print_test_banner "$TEST_DESC"
241
242if [ ! -f "$TESTAPP_PATH.class" ]; then
243 withapp=0
244else
245 withapp=1
246fi
247
248skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
249{
250 start_lttng_sessiond
251
252 tests=(
b2064f54 253 test_jul_loglevel
88f54ca9 254 test_jul_loglevel_multiple
37175ce4
DG
255 test_jul_before_start
256 test_jul_after_start
9b21e6d5 257 test_jul_multi_session
37175ce4
DG
258 )
259
260 for fct_test in ${tests[@]};
261 do
262 ${fct_test}
b2064f54
DG
263 if [ $? -ne 0 ]; then
264 break;
37175ce4 265 fi
b2064f54 266 rm -rf $TRACE_PATH
37175ce4
DG
267 done
268
269 stop_lttng_sessiond
270}
This page took 0.050166 seconds and 4 git commands to generate.