Skip to content

Commit f372ad4

Browse files
csutherlclaude
andcommitted
Add comprehensive testing documentation
Added TESTING.txt with complete guide for building and testing Tomcat Native including prerequisites, build instructions with correct buildconf syntax, test execution workflows, and troubleshooting for common issues. Covers all platforms (Linux, macOS, Windows) and advanced scenarios like debugging native code, memory leak detection, and testing with Tomcat. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 8b77c37 commit f372ad4

1 file changed

Lines changed: 387 additions & 0 deletions

File tree

TESTING.txt

Lines changed: 387 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,387 @@
1+
Apache Tomcat Native Library - Testing Guide
2+
==============================================
3+
4+
This document provides comprehensive instructions for building and testing
5+
the Apache Tomcat Native Library.
6+
7+
Table of Contents
8+
-----------------
9+
1. Prerequisites
10+
2. Quick Start
11+
3. Building the Native Library
12+
4. Running Tests
13+
5. Troubleshooting
14+
6. Advanced Testing
15+
16+
═══════════════════════════════════════════════════════════════════════════
17+
18+
1. PREREQUISITES
19+
═══════════════════════════════════════════════════════════════════════════
20+
21+
Required Software:
22+
- Java 21 or higher (OpenJDK or Oracle JDK)
23+
- Apache Ant (for building Java code and running tests)
24+
- C compiler (GCC, Clang, or Visual Studio)
25+
- APR 1.7.0+ (Apache Portable Runtime)
26+
- OpenSSL 3.0.0+ (3.5.x recommended for latest features)
27+
- autoconf, automake, libtool (for generating configure script)
28+
29+
Linux/macOS Installation:
30+
31+
Fedora/RHEL:
32+
sudo dnf install java-21-openjdk-devel ant apr-devel openssl-devel \
33+
autoconf automake libtool gcc
34+
35+
Ubuntu/Debian:
36+
sudo apt-get install openjdk-21-jdk ant libapr1-dev libssl-dev \
37+
autoconf automake libtool build-essential
38+
39+
macOS (using Homebrew):
40+
brew install openjdk@21 ant apr openssl@3 autoconf automake libtool
41+
42+
Windows:
43+
- Install Visual Studio 2019 or later
44+
- Download and build APR from https://apr.apache.org/
45+
- Download OpenSSL from https://www.openssl.org/ or use prebuilt binaries
46+
- See native/BUILDING for detailed Windows build instructions
47+
48+
Verify Prerequisites:
49+
java -version # Should be 21 or higher
50+
ant -version # Any recent version
51+
apr-1-config --version # Should be 1.7.0 or higher
52+
openssl version # Should be 3.0.0 or higher
53+
54+
═══════════════════════════════════════════════════════════════════════════
55+
56+
2. QUICK START
57+
═══════════════════════════════════════════════════════════════════════════
58+
59+
The fastest way to build and test everything:
60+
61+
./build-and-test.sh
62+
63+
This script will:
64+
1. Check all prerequisites
65+
2. Build the native library
66+
3. Compile Java code and tests
67+
4. Run the full test suite
68+
5. Report results
69+
70+
Options:
71+
-v, --verbose Show detailed build output
72+
--apr=PATH APR installation prefix (default: /usr)
73+
--ssl=PATH OpenSSL installation prefix (default: /usr)
74+
75+
Example with custom paths:
76+
./build-and-test.sh --apr=/usr/local/apr --ssl=/opt/openssl
77+
78+
═══════════════════════════════════════════════════════════════════════════
79+
80+
3. BUILDING THE NATIVE LIBRARY
81+
═══════════════════════════════════════════════════════════════════════════
82+
83+
3.1 Linux/Unix/macOS Build
84+
---------------------------
85+
86+
Step 1: Generate configure script (if building from git checkout)
87+
88+
cd native
89+
sh buildconf --with-apr=/path/to/apr/source
90+
91+
Note: buildconf expects the path to APR *source* directory, not the
92+
installed prefix. If you have APR installed from packages, you
93+
can skip buildconf as the configure script is included in release
94+
tarballs.
95+
96+
Step 2: Configure the build
97+
98+
./configure --with-apr=/usr --with-ssl=/usr
99+
100+
Common options:
101+
--with-apr=PATH APR installation prefix
102+
--with-ssl=PATH OpenSSL installation prefix
103+
CFLAGS="-g -O0" Build with debug symbols and no optimization
104+
105+
If APR is installed in a custom location:
106+
./configure --with-apr=/usr/local/apr --with-ssl=/usr
107+
108+
Step 3: Build
109+
110+
make
111+
112+
The native library will be created in native/.libs/:
113+
- libtcnative-2.so (Linux)
114+
- libtcnative-2.dylib (macOS)
115+
- libtcnative-2.dll (Windows)
116+
117+
Step 4: Clean (if needed)
118+
119+
make clean # Remove build artifacts
120+
rm -rf autom4te.cache # Remove autoconf cache
121+
122+
3.2 Windows Build
123+
-----------------
124+
125+
See native/BUILDING for detailed Windows build instructions using Visual
126+
Studio and nmake.
127+
128+
═══════════════════════════════════════════════════════════════════════════
129+
130+
4. RUNNING TESTS
131+
═══════════════════════════════════════════════════════════════════════════
132+
133+
4.1 Run All Tests
134+
-----------------
135+
136+
From the tomcat-native root directory:
137+
138+
ant test
139+
140+
This will:
141+
1. Compile Java sources
142+
2. Compile test classes
143+
3. Run all tests
144+
4. Generate reports in logs/ directory
145+
146+
4.2 Run Specific Test Classes
147+
------------------------------
148+
149+
Run a single test class:
150+
151+
ant test -Dtest.name="**/TestSSL.java"
152+
ant test -Dtest.name="**/TestPool.java"
153+
154+
Run multiple test classes:
155+
156+
ant test -Dtest.name="**/Test{SSL,Pool,Library}.java"
157+
158+
4.3 Run Diagnostic Tests First
159+
-------------------------------
160+
161+
Before running the full test suite, run diagnostic tests to verify your
162+
environment is correctly configured:
163+
164+
ant test -Dtest.name="**/TestBuildEnvironment.java"
165+
166+
This will check:
167+
- Java version (21+)
168+
- Library path configuration
169+
- Native library availability
170+
- OpenSSL version compatibility
171+
- APR dependencies
172+
173+
4.4 Test Output Locations
174+
--------------------------
175+
176+
logs/TEST-*.txt - Detailed test results for each test class
177+
logs/TEST-*.xml - JUnit XML format results
178+
179+
4.5 Running Tests with Custom Library Path
180+
-------------------------------------------
181+
182+
If you built the native library in a custom location:
183+
184+
ant test -Djava.library.path=/path/to/native/.libs
185+
186+
═══════════════════════════════════════════════════════════════════════════
187+
188+
5. TROUBLESHOOTING
189+
═══════════════════════════════════════════════════════════════════════════
190+
191+
5.1 "Native library not found"
192+
-------------------------------
193+
194+
Error: java.lang.UnsatisfiedLinkError: no tcnative-2 in java.library.path
195+
196+
Solution:
197+
1. Verify native library was built:
198+
ls -la native/.libs/libtcnative-2.*
199+
200+
2. Rebuild the native library:
201+
cd native && make clean && make
202+
203+
3. Check that build.xml is setting java.library.path correctly
204+
205+
5.2 "OpenSSL version mismatch"
206+
------------------------------
207+
208+
Error: Library built for OpenSSL 1.1 but system has OpenSSL 3.x
209+
210+
Solution:
211+
Rebuild the native library against your current OpenSSL version:
212+
213+
cd native
214+
make clean
215+
rm -rf autom4te.cache
216+
./configure --with-apr=/usr --with-ssl=/usr
217+
make
218+
219+
5.3 "configure: error: APR not found"
220+
-------------------------------------
221+
222+
Error: configure: error: APR could not be located
223+
224+
Solution:
225+
1. Install APR development package (see Prerequisites section)
226+
227+
2. If APR is installed in custom location, specify path:
228+
./configure --with-apr=/usr/local/apr
229+
230+
3. Verify apr-1-config is in PATH:
231+
which apr-1-config
232+
apr-1-config --prefix
233+
234+
5.4 "Java version too old"
235+
---------------------------
236+
237+
Error: Java 21 or higher required
238+
239+
Solution:
240+
1. Install Java 21:
241+
- Fedora/RHEL: sudo dnf install java-21-openjdk-devel
242+
- Ubuntu/Debian: sudo apt-get install openjdk-21-jdk
243+
- macOS: brew install openjdk@21
244+
245+
2. Set JAVA_HOME and PATH:
246+
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk
247+
export PATH=$JAVA_HOME/bin:$PATH
248+
249+
5.5 Test Failures
250+
-----------------
251+
252+
If specific tests fail:
253+
254+
1. Check logs/TEST-*.txt for detailed error messages
255+
256+
2. Run diagnostics:
257+
ant test -Dtest.name="**/TestBuildEnvironment.java"
258+
259+
3. Verify OpenSSL version:
260+
openssl version
261+
# Should be 3.0.0 or higher
262+
263+
4. Check for library dependency issues:
264+
ldd native/.libs/libtcnative-2.so # Linux
265+
otool -L native/.libs/libtcnative-2.dylib # macOS
266+
267+
5.6 JVM Crashes During Tests
268+
-----------------------------
269+
270+
If the JVM crashes with SIGSEGV or similar:
271+
272+
1. This usually indicates a bug in the native code (JNI layer)
273+
274+
2. Rebuild with debug symbols:
275+
cd native
276+
make clean
277+
./configure --with-apr=/usr --with-ssl=/usr CFLAGS="-g -O0"
278+
make
279+
280+
3. Run under debugger:
281+
gdb --args java -Djava.library.path=native/.libs \
282+
-cp ... org.junit.runner.JUnitCore TestClass
283+
284+
4. Report the issue with:
285+
- Crash stack trace
286+
- OpenSSL version (openssl version)
287+
- APR version (apr-1-config --version)
288+
- OS and architecture (uname -a)
289+
290+
═══════════════════════════════════════════════════════════════════════════
291+
292+
6. ADVANCED TESTING
293+
═══════════════════════════════════════════════════════════════════════════
294+
295+
6.1 Testing with Different OpenSSL Versions
296+
--------------------------------------------
297+
298+
To test against a custom OpenSSL installation:
299+
300+
cd native
301+
make clean
302+
./configure --with-apr=/usr --with-ssl=/path/to/openssl
303+
make
304+
cd ..
305+
ant test
306+
307+
6.2 Thread Safety Testing
308+
--------------------------
309+
310+
The test suite includes thread safety tests that verify concurrent usage
311+
of APR pools and SSL contexts. These tests only run if the native library
312+
was built with thread support (APR_HAS_THREADS).
313+
314+
To verify thread support is enabled:
315+
ant test -Dtest.name="**/TestThreadSafety.java"
316+
317+
6.3 Stress Testing
318+
------------------
319+
320+
Some tests create hundreds of objects to verify memory management and
321+
detect leaks. These tests are marked with @Category(StressTest.class).
322+
323+
Run only stress tests:
324+
ant test -Dtest.name="**/TestStress*.java"
325+
326+
6.4 Memory Leak Detection
327+
--------------------------
328+
329+
To detect memory leaks in the native code:
330+
331+
1. Build with AddressSanitizer (Linux/macOS):
332+
cd native
333+
make clean
334+
./configure --with-apr=/usr --with-ssl=/usr \
335+
CFLAGS="-g -O0 -fsanitize=address"
336+
make
337+
338+
2. Run tests:
339+
ant test
340+
341+
3. Check for leak reports in test output
342+
343+
6.5 Debugging Native Code
344+
--------------------------
345+
346+
To debug native code during test execution:
347+
348+
1. Build with debug symbols (see 5.6 above)
349+
350+
2. Find the Java command used by Ant:
351+
ant test -v -Dtest.name="**/TestSSL.java" 2>&1 | grep "java.*junit"
352+
353+
3. Run that command under gdb:
354+
gdb --args java -Djava.library.path=... org.junit.runner.JUnitCore ...
355+
356+
4. Set breakpoints:
357+
(gdb) break Java_org_apache_tomcat_jni_SSL_initialize
358+
(gdb) run
359+
360+
6.6 Testing Against Tomcat
361+
---------------------------
362+
363+
To test the library with actual Tomcat:
364+
365+
1. Build the native library and JAR:
366+
ant jar
367+
cd native && make
368+
369+
2. Copy to Tomcat:
370+
cp dist/tomcat-native-*.jar $CATALINA_HOME/lib/
371+
cp native/.libs/libtcnative-2.so $CATALINA_HOME/lib/
372+
373+
3. Configure Tomcat to use APR:
374+
Edit conf/server.xml and add:
375+
<Listener className="org.apache.catalina.core.AprLifecycleListener" />
376+
377+
4. Start Tomcat and check logs for:
378+
"Loaded Apache Tomcat Native library"
379+
380+
═══════════════════════════════════════════════════════════════════════════
381+
382+
For more information:
383+
- Project home: https://tomcat.apache.org/native-doc/
384+
- APR documentation: https://apr.apache.org/docs/apr/
385+
- OpenSSL documentation: https://www.openssl.org/docs/
386+
387+
Report issues at: https://github.com/apache/tomcat-native/issues

0 commit comments

Comments
 (0)