Skip to content

Commit 11f212e

Browse files
committed
Add a warning for missing OpenSSL and Tomcat Native during tests (#970)
When either are unavailable, the tests are silently skipped or excluded without a clear explanation to the user. The new warning makes it obvious that the OpenSSL or Tomcat Native tests will be skipped without having the look for which tests were skipped.
1 parent 206921a commit 11f212e

File tree

3 files changed

+88
-2
lines changed

3 files changed

+88
-2
lines changed

build.xml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,13 +2117,13 @@
21172117
</target>
21182118

21192119
<target name="test-nio" description="Runs the JUnit test cases for NIO. Does not stop on errors."
2120-
depends="-test-name-default,setup-jacoco,test-compile,deploy,test-openssl-exists" if="${execute.test.nio}">
2120+
depends="-test-name-default,setup-jacoco,test-compile,deploy,test-openssl-exists,test-tcnative-exists" if="${execute.test.nio}">
21212121
<runtests protocol="org.apache.coyote.http11.Http11NioProtocol"
21222122
extension=".NIO" />
21232123
</target>
21242124

21252125
<target name="test-only-nio" description="Runs the JUnit test cases or NIO without test preparations. Does not stop on errors."
2126-
depends="-test-name-default,setup-jacoco,test-openssl-exists" if="${execute.test.nio}">
2126+
depends="-test-name-default,setup-jacoco,test-openssl-exists,test-tcnative-exists" if="${execute.test.nio}">
21272127
<runtests protocol="org.apache.coyote.http11.Http11NioProtocol"
21282128
extension=".NIO" />
21292129
</target>
@@ -2154,6 +2154,48 @@
21542154
</and>
21552155
</or>
21562156
</condition>
2157+
<echo message="OpenSSL is not available. OpenSSL-related tests will be skipped or may fail." level="warning" unless:set="test.openssl.exists"/>
2158+
</target>
2159+
2160+
<target name="test-tcnative-exists" description="Verifies tomcat-native library can be loaded">
2161+
<!-- Check if main classes are built -->
2162+
<available file="${test.run.classes}/org/apache/tomcat/jni/Library.class"
2163+
property="tomcat.classes.available"/>
2164+
2165+
<!-- If main classes don't exist, compile just what we need -->
2166+
<mkdir dir="${test.run.classes}" unless:set="tomcat.classes.available"/>
2167+
<javac srcdir="java" destdir="${test.run.classes}"
2168+
includes="org/apache/tomcat/jni/Library.java,org/apache/tomcat/jni/LibraryNotFoundError.java"
2169+
debug="${compile.debug}"
2170+
includeantruntime="false"
2171+
encoding="UTF-8"
2172+
unless:set="tomcat.classes.available">
2173+
<compilerarg line="-Xlint:-options"/>
2174+
</javac>
2175+
2176+
<!-- Compile the test class -->
2177+
<mkdir dir="${test.classes}"/>
2178+
<javac srcdir="test" destdir="${test.classes}"
2179+
includes="org/apache/tomcat/jni/TesterLibraryLoad.java"
2180+
debug="${compile.debug}"
2181+
includeantruntime="false"
2182+
encoding="UTF-8">
2183+
<classpath>
2184+
<pathelement location="${test.run.classes}"/>
2185+
<pathelement location="${junit.jar}"/>
2186+
</classpath>
2187+
</javac>
2188+
2189+
<!-- Run test - it will check both test.apr.loc and system library paths -->
2190+
<junit printsummary="no" fork="yes" showoutput="false" haltonfailure="false"
2191+
failureproperty="test.tcnative.error" logfailedtests="false">
2192+
<jvmarg value="${runtests.librarypath}"/>
2193+
<jvmarg value="${native.nativeaccess}"/>
2194+
<classpath refid="tomcat.test.classpath"/>
2195+
<test name="org.apache.tomcat.jni.TesterLibraryLoad"/>
2196+
</junit>
2197+
2198+
<echo message="Tomcat Native is not available. Tomcat Native (JNI) tests will be skipped." if:set="test.tcnative.error" level="warning"/>
21572199
</target>
21582200

21592201
<target name="test-httpd-exists" description="Checks for the httpd binary">
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.tomcat.jni;
18+
19+
import org.junit.Assert;
20+
import org.junit.Test;
21+
22+
/**
23+
* Simple test to verify tomcat-native library can be loaded.
24+
*/
25+
public class TesterLibraryLoad {
26+
27+
@Test
28+
public void testLibraryLoads() throws Exception {
29+
try {
30+
Library.initialize(null);
31+
Library.terminate();
32+
} catch (LibraryNotFoundError e) {
33+
// Library not available - fail test to set property
34+
Assert.fail("Library not found");
35+
}
36+
}
37+
}

webapps/docs/changelog.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@
192192
<fix>
193193
<bug>69993</bug>: Update the URL to the CDDL 1.0 license. (markt)
194194
</fix>
195+
<add>
196+
Add warning when OpenSSL binary is not found. (csutherl)
197+
</add>
198+
<add>
199+
Add check for Tomcat Native library, and log warning when it's not found
200+
to make it easier to see when it's not used by the suite. (csutherl)
201+
</add>
195202
</changelog>
196203
</subsection>
197204
</section>

0 commit comments

Comments
 (0)