Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2109,13 +2109,13 @@
</target>

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

<target name="test-only-nio" description="Runs the JUnit test cases or NIO without test preparations. Does not stop on errors."
depends="-test-name-default,setup-jacoco,test-openssl-exists" if="${execute.test.nio}">
depends="-test-name-default,setup-jacoco,test-openssl-exists,test-tcnative-exists" if="${execute.test.nio}">
<runtests protocol="org.apache.coyote.http11.Http11NioProtocol"
extension=".NIO" />
</target>
Expand All @@ -2134,6 +2134,30 @@
</and>
</or>
</condition>
<echo message="OpenSSL is not available. OpenSSL-related tests will be skipped or may fail." level="warning" unless:set="test.openssl.exists"/>
</target>

<target name="test-tcnative-exists" description="Verifies tomcat-native library can be loaded"
depends="test-compile">
<!-- Build library path including both test location and system paths -->
<condition property="tcnative.library.path" value="${test.apr.loc};C:\Windows\System32">
<os family="windows"/>
</condition>
<condition property="tcnative.library.path" value="${test.apr.loc}:/usr/local/lib:/opt/homebrew/lib:/usr/lib">
<os family="mac"/>
</condition>
<property name="tcnative.library.path" value="${test.apr.loc}:/lib:/usr/lib:/lib64:/usr/lib64"/>

<!-- Run test - it will check both test.apr.loc and system library paths -->
<junit printsummary="no" fork="yes" showoutput="false" haltonfailure="false"
failureproperty="test.tcnative.error" logfailedtests="false">
<jvmarg value="-Djava.library.path=${tcnative.library.path}"/>
<jvmarg value="--enable-native-access=ALL-UNNAMED"/>
<classpath refid="tomcat.test.classpath"/>
<test name="org.apache.tomcat.jni.TesterLibraryLoad"/>
</junit>

<echo message="Tomcat Native is not available. Tomcat Native (JNI) tests will be skipped." if:set="test.tcnative.error" level="warning"/>
</target>

<target name="test-httpd-exists" description="Checks for the httpd binary">
Expand Down
38 changes: 38 additions & 0 deletions test/org/apache/tomcat/jni/TesterLibraryLoad.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.tomcat.jni;

import static org.junit.Assert.fail;

import org.junit.Test;

/**
* Simple test to verify tomcat-native library can be loaded.
*/
public class TesterLibraryLoad {

@Test
public void testLibraryLoads() throws Exception {
try {
Library.initialize(null);
Library.terminate();
} catch (LibraryNotFoundError e) {
// Library not available - fail test to set property
fail("Library not found");
}
}
}
7 changes: 7 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,13 @@
<update>
Update Derby to 10.17.1.0. (markt)
</update>
<add>
Add warning when OpenSSL binary is not found. (csutherl)
</add>
<add>
Add check for Tomcat Native library, and log warning when it's not found
to make it easier to see when it's not used by the suite. (csutherl)
</add>
<!-- Entries for backport and removal before 12.0.0-M1 below this line -->
</changelog>
</subsection>
Expand Down
Loading