Skip to content

Commit 0ceaf8b

Browse files
authored
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 31e120f commit 0ceaf8b

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
@@ -2109,13 +2109,13 @@
21092109
</target>
21102110

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

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

21392181
<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
@@ -397,6 +397,13 @@
397397
<update>
398398
Update Derby to 10.17.1.0. (markt)
399399
</update>
400+
<add>
401+
Add warning when OpenSSL binary is not found. (csutherl)
402+
</add>
403+
<add>
404+
Add check for Tomcat Native library, and log warning when it's not found
405+
to make it easier to see when it's not used by the suite. (csutherl)
406+
</add>
400407
<!-- Entries for backport and removal before 12.0.0-M1 below this line -->
401408
<fix>
402409
<bug>69993</bug>: Update the URL to the CDDL 1.0 license. (markt)

0 commit comments

Comments
 (0)