Skip to content

Commit c3e34d2

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 b59c8ef commit c3e34d2

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
@@ -2086,13 +2086,13 @@
20862086
</target>
20872087

20882088
<target name="test-nio" description="Runs the JUnit test cases for NIO. Does not stop on errors."
2089-
depends="-test-name-default,setup-jacoco,test-compile,deploy,test-openssl-exists" if="${execute.test.nio}">
2089+
depends="-test-name-default,setup-jacoco,test-compile,deploy,test-openssl-exists,test-tcnative-exists" if="${execute.test.nio}">
20902090
<runtests protocol="org.apache.coyote.http11.Http11NioProtocol"
20912091
extension=".NIO" />
20922092
</target>
20932093

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

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