Skip to content

Commit 1da8fd8

Browse files
author
Andrew Lu
committed
8295343: sun/security/pkcs11 tests fail on Linux RHEL 8.6 and newer
8231351: Add notes for PKCS11 tests in the test doc Reviewed-by: lucy Backport-of: 6ce0ebb858d3112f136e12d3ad595f805f6871a0
1 parent cabaf74 commit 1da8fd8

File tree

7 files changed

+52
-116
lines changed

7 files changed

+52
-116
lines changed

doc/testing.html

+13-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="generator" content="pandoc" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
77
<title>Testing the JDK</title>
8-
<style type="text/css">
8+
<style>
99
code{white-space: pre-wrap;}
1010
span.smallcaps{font-variant: small-caps;}
1111
span.underline{text-decoration: underline;}
@@ -21,7 +21,7 @@
2121
<header id="title-block-header">
2222
<h1 class="title">Testing the JDK</h1>
2323
</header>
24-
<nav id="TOC">
24+
<nav id="TOC" role="doc-toc">
2525
<ul>
2626
<li><a href="#using-the-run-test-framework">Using the run-test framework</a><ul>
2727
<li><a href="#configuration">Configuration</a></li>
@@ -40,6 +40,7 @@ <h1 class="title">Testing the JDK</h1>
4040
<li><a href="#notes-for-specific-tests">Notes for Specific Tests</a><ul>
4141
<li><a href="#docker-tests">Docker Tests</a></li>
4242
<li><a href="#client-ui-tests">Client UI Tests</a></li>
43+
<li><a href="#pkcs11-tests">PKCS11 Tests</a></li>
4344
</ul></li>
4445
</ul>
4546
</nav>
@@ -58,7 +59,7 @@ <h3 id="configuration">Configuration</h3>
5859
<p>To be able to run JTReg tests, <code>configure</code> needs to know where to find the JTReg test framework. If it is not picked up automatically by configure, use the <code>--with-jtreg=&lt;path to jtreg home&gt;</code> option to point to the JTReg framework. Note that this option should point to the JTReg home, i.e. the top directory, containing <code>lib/jtreg.jar</code> etc. (An alternative is to set the <code>JT_HOME</code> environment variable to point to the JTReg home before running <code>configure</code>.)</p>
5960
<h2 id="test-selection">Test selection</h2>
6061
<p>All functionality is available using the run-test make target. In this use case, the test or tests to be executed is controlled using the <code>TEST</code> variable. To speed up subsequent test runs with no source code changes, run-test-only can be used instead, which do not depend on the source and test image build.</p>
61-
<p>For some common top-level tests, direct make targets have been generated. This includes all JTReg test groups, the hotspot gtest, and custom tests (if present). This means that <code>make run-test-tier1</code> is equivalent to <code>make run-test TEST=&quot;tier1&quot;</code>, but the latter is more tab-completion friendly. For more complex test runs, the <code>run-test TEST=&quot;x&quot;</code> solution needs to be used.</p>
62+
<p>For some common top-level tests, direct make targets have been generated. This includes all JTReg test groups, the hotspot gtest, and custom tests (if present). This means that <code>make run-test-tier1</code> is equivalent to <code>make run-test TEST="tier1"</code>, but the latter is more tab-completion friendly. For more complex test runs, the <code>run-test TEST="x"</code> solution needs to be used.</p>
6263
<p>The test specifications given in <code>TEST</code> is parsed into fully qualified test descriptors, which clearly and unambigously show which tests will be run. As an example, <code>:tier1</code> will expand to <code>jtreg:$(TOPDIR)/test/hotspot/jtreg:tier1 jtreg:$(TOPDIR)/test/jdk:tier1 jtreg:$(TOPDIR)/test/langtools:tier1 jtreg:$(TOPDIR)/test/nashorn:tier1 jtreg:$(TOPDIR)/test/jaxp:tier1</code>. You can always submit a list of fully qualified test descriptors in the <code>TEST</code> variable if you want to shortcut the parser.</p>
6364
<h3 id="common-test-groups">Common Test Groups</h3>
6465
<p>Ideally, all tests are run for every change but this may not be practical due to the limited testing resources, the scope of the change, etc.</p>
@@ -101,8 +102,8 @@ <h2 id="test-results-and-summary">Test results and summary</h2>
101102
<p>Additional work data is stored in <code>build/$BUILD/test-support/$TEST_ID</code>. For some frameworks, this directory might contain information that is useful in determining the cause of a failed test.</p>
102103
<h2 id="test-suite-control">Test suite control</h2>
103104
<p>It is possible to control various aspects of the test suites using make control variables.</p>
104-
<p>These variables use a keyword=value approach to allow multiple values to be set. So, for instance, <code>JTREG=&quot;JOBS=1;TIMEOUT=8&quot;</code> will set the JTReg concurrency level to 1 and the timeout factor to 8. This is equivalent to setting <code>JTREG_JOBS=1 JTREG_TIMEOUT=8</code>, but using the keyword format means that the <code>JTREG</code> variable is parsed and verified for correctness, so <code>JTREG=&quot;TMIEOUT=8&quot;</code> would give an error, while <code>JTREG_TMIEOUT=8</code> would just pass unnoticed.</p>
105-
<p>To separate multiple keyword=value pairs, use <code>;</code> (semicolon). Since the shell normally eats <code>;</code>, the recommended usage is to write the assignment inside qoutes, e.g. <code>JTREG=&quot;...;...&quot;</code>. This will also make sure spaces are preserved, as in <code>JTREG=&quot;VM_OPTIONS=-XshowSettings -Xlog:gc+ref=debug&quot;</code>.</p>
105+
<p>These variables use a keyword=value approach to allow multiple values to be set. So, for instance, <code>JTREG="JOBS=1;TIMEOUT=8"</code> will set the JTReg concurrency level to 1 and the timeout factor to 8. This is equivalent to setting <code>JTREG_JOBS=1 JTREG_TIMEOUT=8</code>, but using the keyword format means that the <code>JTREG</code> variable is parsed and verified for correctness, so <code>JTREG="TMIEOUT=8"</code> would give an error, while <code>JTREG_TMIEOUT=8</code> would just pass unnoticed.</p>
106+
<p>To separate multiple keyword=value pairs, use <code>;</code> (semicolon). Since the shell normally eats <code>;</code>, the recommended usage is to write the assignment inside qoutes, e.g. <code>JTREG="...;..."</code>. This will also make sure spaces are preserved, as in <code>JTREG="VM_OPTIONS=-XshowSettings -Xlog:gc+ref=debug"</code>.</p>
106107
<p>(Other ways are possible, e.g. using backslash: <code>JTREG=JOBS=1\;TIMEOUT=8</code>. Also, as a special technique, the string <code>%20</code> will be replaced with space for certain options, e.g. <code>JTREG=VM_OPTIONS=-XshowSettings%20-Xlog:gc+ref=debug</code>. This can be useful if you have layers of scripts and have trouble getting proper quoting of command line arguments through.)</p>
107108
<p>As far as possible, the names of the keywords have been standardized between test suites.</p>
108109
<h3 id="general-keywords-test_opts">General keywords (TEST_OPTS)</h3>
@@ -152,7 +153,7 @@ <h4 id="run_problem_lists">RUN_PROBLEM_LISTS</h4>
152153
<p>Set to <code>true</code> or <code>false</code>. If <code>true</code>, JTReg will use <code>-match:</code> option, otherwise <code>-exclude:</code> will be used. Default is <code>false</code>.</p>
153154
<h4 id="options">OPTIONS</h4>
154155
<p>Additional options to the JTReg test framework.</p>
155-
<p>Use <code>JTREG=&quot;OPTIONS=--help all&quot;</code> to see all available JTReg options.</p>
156+
<p>Use <code>JTREG="OPTIONS=--help all"</code> to see all available JTReg options.</p>
156157
<h4 id="java_options-1">JAVA_OPTIONS</h4>
157158
<p>Additional Java options to JTReg (<code>-javaoption</code>).</p>
158159
<h4 id="vm_options-1">VM_OPTIONS</h4>
@@ -169,7 +170,7 @@ <h4 id="repeat">REPEAT</h4>
169170
<p>Default is 1. Set to -1 to repeat indefinitely. This can be especially useful combined with <code>OPTIONS=--gtest_break_on_failure</code> to reproduce an intermittent problem.</p>
170171
<h4 id="options-1">OPTIONS</h4>
171172
<p>Additional options to the Gtest test framework.</p>
172-
<p>Use <code>GTEST=&quot;OPTIONS=--help&quot;</code> to see all available Gtest options.</p>
173+
<p>Use <code>GTEST="OPTIONS=--help"</code> to see all available Gtest options.</p>
173174
<h4 id="aot_modules-2">AOT_MODULES</h4>
174175
<p>Generate AOT modules before testing for the specified module, or set of modules. If multiple modules are specified, they should be separated by space (or, to help avoid quoting issues, the special value <code>%20</code>).</p>
175176
<h2 id="notes-for-specific-tests">Notes for Specific Tests</h2>
@@ -178,6 +179,11 @@ <h3 id="docker-tests">Docker Tests</h3>
178179
<pre><code>$ make run-test TEST=&quot;jtreg:test/hotspot/jtreg/containers/docker&quot;</code></pre>
179180
<p>To run these tests correctly, additional parameters for the correct docker image are required on Ubuntu 18.04 by using <code>JAVA_OPTIONS</code>.</p>
180181
<pre><code>$ make run-test TEST=&quot;jtreg:test/hotspot/jtreg/containers/docker&quot; JTREG=&quot;JAVA_OPTIONS=-Djdk.test.docker.image.name=ubuntu -Djdk.test.docker.image.version=latest&quot;</code></pre>
182+
<h3 id="pkcs11-tests">PKCS11 Tests</h3>
183+
<p>It is highly recommended to use the latest NSS version when running PKCS11 tests. Improper NSS version may lead to unexpected failures which are hard to diagnose. For example, sun/security/pkcs11/Secmod/AddTrustedCert.java may fail on Ubuntu 18.04 with the default NSS version in the system. To run these tests correctly, the system property <<code>jdk.test.lib.artifacts.&lt;NAME&gt;</code> is required on Ubuntu 18.04 to specify the alternative NSS lib directories.The<code>&lt;NAME&gt;</code> component should be replaced with the name element of the appropriate <code>@Artifact</code> class. (See<code>test/jdk/sun/security/pkcs11/PKCS11Test.java</code>)</p>
184+
<p>For example:</p>
185+
<pre><code>$ make test TEST=&quot;jtreg:sun/security/pkcs11/Secmod/AddTrustedCert.java&quot; JTREG=&quot;JAVA_OPTIONS=-Djdk.test.lib.artifacts.nsslib-linux_aarch64=/path/to/NSS-libs&quot</code></pre>
186+
<p>For more notes about the PKCS11 tests, please refer to test/jdk/sun/security/pkcs11/README.</p>
181187
<h3 id="client-ui-tests">Client UI Tests</h3>
182188
<p>Some Client UI tests use key sequences which may be reserved by the operating system. Usually that causes the test failure. So it is highly recommended to disable system key shortcuts prior testing. The steps to access and disable system key shortcuts for various platforms are provided below.</p>
183189
<h4 id="macos">MacOS</h4>

doc/testing.md

+16
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,22 @@ required on Ubuntu 18.04 by using `JAVA_OPTIONS`.
370370

371371
$ make run-test TEST="jtreg:test/hotspot/jtreg/containers/docker" JTREG="JAVA_OPTIONS=-Djdk.test.docker.image.name=ubuntu -Djdk.test.docker.image.version=latest"
372372

373+
### PKCS11 Tests
374+
375+
It is highly recommended to use the latest NSS version when running PKCS11 tests.
376+
Improper NSS version may lead to unexpected failures which are hard to diagnose.
377+
For example, sun/security/pkcs11/Secmod/AddTrustedCert.java may fail on Ubuntu
378+
18.04 with the default NSS version in the system.
379+
To run these tests correctly, the system property `jdk.test.lib.artifacts.<NAME>` is required on
380+
Ubuntu 18.04 to specify the alternative NSS lib directory. The `<NAME>`
381+
component should be replaced with the name element of the appropriate
382+
`@Artifact` class. (See `test/jdk/sun/security/pkcs11/PKCS11Test.java`)
383+
For example:
384+
385+
$ make test TEST="jtreg:sun/security/pkcs11/Secmod/AddTrustedCert.java" JTREG="JAVA_OPTIONS=-Djdk.test.lib.artifacts.nsslib-linux_aarch64=/path/to/NSS-libs"
386+
387+
For more notes about the PKCS11 tests, please refer to test/jdk/sun/security/pkcs11/README.
388+
373389
### Client UI Tests
374390

375391
Some Client UI tests use key sequences which may be reserved by the operating

test/jdk/ProblemList.txt

+1-6
Original file line numberDiff line numberDiff line change
@@ -634,12 +634,7 @@ sun/security/provider/PolicyFile/GrantAllPermToExtWhenNoPolicy.java 8039280 gene
634634
sun/security/provider/PolicyParser/ExtDirsChange.java 8039280 generic-all
635635
sun/security/provider/PolicyParser/PrincipalExpansionError.java 8039280 generic-all
636636

637-
sun/security/tools/keytool/NssTest.java 8295343,8204203 linux-all,windows-all
638-
sun/security/pkcs11/Signature/TestRSAKeyLength.java 8295343 linux-all
639-
sun/security/pkcs11/rsa/TestSignatures.java 8295343 linux-all
640-
sun/security/pkcs11/rsa/TestKeyPairGenerator.java 8295343 linux-all
641-
sun/security/pkcs11/rsa/TestKeyFactory.java 8295343 linux-all
642-
sun/security/pkcs11/KeyStore/Basic.java 8295343 linux-all
637+
sun/security/tools/keytool/NssTest.java 8204203 linux-all,windows-all
643638

644639
############################################################################
645640

test/jdk/sun/security/pkcs11/PKCS11Test.java

+9-92
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import java.security.spec.ECParameterSpec;
4949
import java.util.ArrayList;
5050
import java.util.Arrays;
51-
import java.util.HashMap;
5251
import java.util.Iterator;
5352
import java.util.List;
5453
import java.util.Map;
@@ -384,30 +383,19 @@ private static Path getNSSLibPath() throws Exception {
384383

385384
static Path getNSSLibPath(String library) throws Exception {
386385
String osid = getOsId();
387-
String[] nssLibDirs = getNssLibPaths(osid);
388-
if (nssLibDirs == null) {
389-
System.out.println("Warning: unsupported OS: " + osid
386+
String nssLibDir = fetchNssLib(osid);
387+
if (nssLibDir == null) {
388+
throw new SkippedException("Warning: unsupported OS: " + osid
390389
+ ", please initialize NSS library location, skipping test");
391-
return null;
392-
}
393-
if (nssLibDirs.length == 0) {
394-
System.out.println("Warning: NSS not supported on this platform, skipping test");
395-
return null;
396390
}
397391

398-
Path nssLibPath = null;
399-
for (String dir : nssLibDirs) {
400-
Path libPath = Paths.get(dir).resolve(System.mapLibraryName(library));
401-
if (Files.exists(libPath)) {
402-
nssLibPath = libPath;
403-
break;
404-
}
405-
}
406-
if (nssLibPath == null) {
407-
System.out.println("Warning: can't find NSS library on this machine, skipping test");
408-
return null;
392+
String libraryName = System.mapLibraryName(library);
393+
Path libPath = Paths.get(nssLibDir).resolve(libraryName);
394+
if (!Files.exists(libPath)) {
395+
throw new SkippedException("NSS library \"" + libraryName + "\" was not found in " + nssLibDir);
409396
}
410-
return nssLibPath;
397+
398+
return libPath;
411399
}
412400

413401
private static String getOsId() {
@@ -731,77 +719,6 @@ private static ECParameterSpec getECParameterSpec(Provider p, String name)
731719
return parameters.getParameterSpec(ECParameterSpec.class);
732720
}
733721

734-
// Location of the NSS libraries on each supported platform
735-
private static Map<String, String[]> getOsMap() {
736-
if (osMap != null) {
737-
return osMap;
738-
}
739-
740-
osMap = new HashMap<>();
741-
osMap.put("SunOS-sparc-32", new String[] { "/usr/lib/mps/" });
742-
osMap.put("SunOS-sparcv9-64", new String[] { "/usr/lib/mps/64/" });
743-
osMap.put("SunOS-x86-32", new String[] { "/usr/lib/mps/" });
744-
osMap.put("SunOS-amd64-64", new String[] { "/usr/lib/mps/64/" });
745-
osMap.put("Linux-i386-32", new String[]{
746-
"/usr/lib/i386-linux-gnu/",
747-
"/usr/lib32/",
748-
"/usr/lib/"});
749-
osMap.put("Linux-amd64-64", new String[]{
750-
"/usr/lib/x86_64-linux-gnu/",
751-
"/usr/lib/x86_64-linux-gnu/nss/",
752-
"/usr/lib64/"});
753-
osMap.put("Linux-ppc64-64", new String[]{"/usr/lib64/"});
754-
osMap.put("Linux-ppc64le-64", new String[]{"/usr/lib64/"});
755-
osMap.put("Linux-s390x-64", new String[]{"/usr/lib64/"});
756-
osMap.put("Windows-x86-32", new String[]{});
757-
osMap.put("Windows-amd64-64", new String[]{});
758-
osMap.put("MacOSX-x86_64-64", new String[]{});
759-
osMap.put("Linux-arm-32", new String[]{
760-
"/usr/lib/arm-linux-gnueabi/nss/",
761-
"/usr/lib/arm-linux-gnueabihf/nss/"});
762-
// Exclude linux-aarch64 at the moment until the following bug is fixed:
763-
// 8296631: NSS tests failing on OL9 linux-aarch64 hosts
764-
// osMap.put("Linux-aarch64-64", new String[] {
765-
// "/usr/lib/aarch64-linux-gnu/",
766-
// "/usr/lib/aarch64-linux-gnu/nss/",
767-
// "/usr/lib64/" });
768-
return osMap;
769-
}
770-
771-
private static String[] getNssLibPaths(String osId) {
772-
String[] preferablePaths = getPreferableNssLibPaths(osId);
773-
if (preferablePaths.length != 0) {
774-
return preferablePaths;
775-
} else {
776-
return getOsMap().get(osId);
777-
}
778-
}
779-
780-
private static String[] getPreferableNssLibPaths(String osId) {
781-
List<String> nssLibPaths = new ArrayList<>();
782-
783-
String customNssLibPaths = System.getProperty("test.nss.lib.paths");
784-
if (customNssLibPaths == null) {
785-
// If custom local NSS lib path is not provided,
786-
// try to download NSS libs from artifactory
787-
String path = fetchNssLib(osId);
788-
if (path != null) {
789-
nssLibPaths.add(path);
790-
}
791-
} else {
792-
String[] paths = customNssLibPaths.split(",");
793-
for (String path : paths) {
794-
if (!path.endsWith(File.separator)) {
795-
nssLibPaths.add(path + File.separator);
796-
} else {
797-
nssLibPaths.add(path);
798-
}
799-
}
800-
}
801-
802-
return nssLibPaths.toArray(new String[0]);
803-
}
804-
805722
private final static char[] hexDigits = "0123456789abcdef".toCharArray();
806723

807724
private static final String distro = distro();

test/jdk/sun/security/pkcs11/README

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ perform as a result of bugs or features in NSS or other pkcs11 libraries.
44
- How to get NSS libraries?
55
The libraries come from the following sources.
66

7-
1. Specified by system property test.nss.lib.paths
8-
System property test.nss.lib.paths can specify a set of absolute paths to
9-
the local NSS library directories. The paths are separated by comma.
7+
1. Specified by system property jdk.test.lib.artifacts.<NAME>
8+
The system property, jdk.test.lib.artifacts.<NAME>, can specify an absolute path
9+
to the local NSS library directory. The <NAME> component should be replaced with
10+
the name element of the appropriate @Artifact class.
11+
(See `test/jdk/sun/security/pkcs11/PKCS11Test.java`)
1012

1113
2. Pre-built NSS libraries from artifactory server
12-
If the value of system property test.nss.lib.paths is not set, the tests will try
13-
to download pre-built NSS libraries from artifactory server. Currently, the
14-
tests only looks for libraries for Windows and MacOSX platforms on artifactory.
14+
If the value of system property jdk.test.lib.artifacts.<NAME> is not set, the
15+
tests will try to download pre-built NSS libraries from artifactory server.
1516
Please note that JIB jar MUST be present in classpath when downloading the
1617
libraries.
1718

test/jdk/sun/security/tools/keytool/NssTest.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2023 Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -56,8 +56,9 @@ private static void copyFiles() throws IOException {
5656

5757
Path dbPath = srcPath.getParent().getParent()
5858
.resolve("pkcs11").resolve("nss").resolve("db");
59-
Files.copy(dbPath.resolve("cert8.db"), Paths.get("cert8.db"));
60-
Files.copy(dbPath.resolve("key3.db"), Paths.get("key3.db"));
61-
Files.copy(dbPath.resolve("secmod.db"), Paths.get("secmod.db"));
59+
Path destDir = Path.of( "tmpdb");
60+
Files.createDirectory(destDir);
61+
Files.copy(dbPath.resolve("cert9.db"), destDir.resolve("cert9.db"));
62+
Files.copy(dbPath.resolve("key4.db"), destDir.resolve("key4.db"));
6263
}
6364
}

test/jdk/sun/security/tools/keytool/p11-nss.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ slot = 2
66

77
library = ${nss.lib}
88

9-
nssArgs = "configdir='.' certPrefix='' keyPrefix='' secmod='secmod.db'"
9+
nssArgs = "configdir='sql:./tmpdb' certPrefix='' keyPrefix='' secmod='secmod.db'"
1010

1111
#forceLogin = true
1212

0 commit comments

Comments
 (0)