Fix: index JUL event by name *and* loglevel
[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"
29JAVA_CP="$CURDIR:/usr/local/lib/lttng/java/liblttng-ust-jul.jar:/usr/lib/lttng/java/liblttng-ust-jul.jar"
30
31TRACE_PATH=$(mktemp -d)
32
b2064f54 33NUM_TESTS=37
37175ce4
DG
34
35source $TESTDIR/utils/utils.sh
36
37function 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
42function 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
52function 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
b2064f54
DG
67
68 # Validate test. Expecting all events.
1b500e7a 69 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
70 if [ $? -ne 0 ]; then
71 return $?
72 fi
37175ce4
DG
73}
74
75function 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
b2064f54
DG
90
91 # Validate test. Expecting all events.
1b500e7a 92 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
93 if [ $? -ne 0 ]; then
94 return $?
95 fi
96}
97
98function 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.
1b500e7a 115 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54
DG
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.
1b500e7a 155 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
b2064f54 156 return $?
37175ce4
DG
157}
158
159plan_tests $NUM_TESTS
160
161print_test_banner "$TEST_DESC"
162
163if [ ! -f "$TESTAPP_PATH.class" ]; then
164 withapp=0
165else
166 withapp=1
167fi
168
169skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
170{
171 start_lttng_sessiond
172
173 tests=(
b2064f54 174 test_jul_loglevel
37175ce4
DG
175 test_jul_before_start
176 test_jul_after_start
177 )
178
179 for fct_test in ${tests[@]};
180 do
181 ${fct_test}
b2064f54
DG
182 if [ $? -ne 0 ]; then
183 break;
37175ce4 184 fi
b2064f54 185 rm -rf $TRACE_PATH
37175ce4
DG
186 done
187
188 stop_lttng_sessiond
189}
This page took 0.044278 seconds and 4 git commands to generate.