Skip to content

Commit a17b753

Browse files
committed
Add a warning for missing OpenSSL and Tomcat Native during tests
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 b628a63 commit a17b753

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

build.xml

Lines changed: 26 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,30 @@
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+
depends="test-compile">
2142+
<!-- Build library path including both test location and system paths -->
2143+
<condition property="tcnative.library.path" value="${test.apr.loc};C:\Windows\System32">
2144+
<os family="windows"/>
2145+
</condition>
2146+
<condition property="tcnative.library.path" value="${test.apr.loc}:/usr/local/lib:/opt/homebrew/lib:/usr/lib">
2147+
<os family="mac"/>
2148+
</condition>
2149+
<property name="tcnative.library.path" value="${test.apr.loc}:/lib:/usr/lib:/lib64:/usr/lib64"/>
2150+
2151+
<!-- Run test - it will check both test.apr.loc and system library paths -->
2152+
<junit printsummary="no" fork="yes" showoutput="false" haltonfailure="false"
2153+
failureproperty="test.tcnative.error" logfailedtests="false">
2154+
<jvmarg value="-Djava.library.path=${tcnative.library.path}"/>
2155+
<jvmarg value="--enable-native-access=ALL-UNNAMED"/>
2156+
<classpath refid="tomcat.test.classpath"/>
2157+
<test name="org.apache.tomcat.jni.TesterLibraryLoad"/>
2158+
</junit>
2159+
2160+
<echo message="Tomcat Native is not available. Tomcat Native (JNI) tests will be skipped." if:set="test.tcnative.error" level="warning"/>
21372161
</target>
21382162

21392163
<target name="test-httpd-exists" description="Checks for the httpd binary">
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 static org.junit.Assert.fail;
20+
21+
import org.junit.Test;
22+
23+
/**
24+
* Simple test to verify tomcat-native library can be loaded.
25+
*/
26+
public class TesterLibraryLoad {
27+
28+
@Test
29+
public void testLibraryLoads() throws Exception {
30+
try {
31+
Library.initialize(null);
32+
Library.terminate();
33+
} catch (LibraryNotFoundError e) {
34+
// Library not available - fail test to set property
35+
fail("Library not found");
36+
}
37+
}
38+
}

webapps/docs/changelog.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,13 @@
343343
<update>
344344
Update Derby to 10.17.1.0. (markt)
345345
</update>
346+
<add>
347+
Add warning when OpenSSL binary is not found. (csutherl)
348+
</add>
349+
<add>
350+
Add check for Tomcat Native library, and log warning when it's not found
351+
to make it easier to see when it's not used by the suite. (csutherl)
352+
</add>
346353
<!-- Entries for backport and removal before 12.0.0-M1 below this line -->
347354
</changelog>
348355
</subsection>

0 commit comments

Comments
 (0)