Skip to content

Commit 827c158

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 638dc71 commit 827c158

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
@@ -2110,13 +2110,13 @@
21102110
</target>
21112111

21122112
<target name="test-nio" description="Runs the JUnit test cases for NIO. Does not stop on errors."
2113-
depends="-test-name-default,setup-jacoco,test-compile,deploy,test-openssl-exists" if="${execute.test.nio}">
2113+
depends="-test-name-default,setup-jacoco,test-compile,deploy,test-openssl-exists,test-tcnative-exists" if="${execute.test.nio}">
21142114
<runtests protocol="org.apache.coyote.http11.Http11NioProtocol"
21152115
extension=".NIO" />
21162116
</target>
21172117

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

21522194
<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)