8137255: sun/security/provider/NSASuiteB/TestDSAGenParameterSpec.java timeouts intermittently
authorjjiang
Wed, 25 May 2016 02:20:02 +0100
changeset 38555 74f0c0bf9c21
parent 38554 6bb9dce6c3a9
child 38556 868af536ce12
8137255: sun/security/provider/NSASuiteB/TestDSAGenParameterSpec.java timeouts intermittently Summary: sun/security/provider/NSASuiteB/TestDSAGenParameterSpec.java timeouts intermittently due to large DSA key parameter generation. Reviewed-by: valeriep Contributed-by: John Jiang <sha.jiang@oracle.com>
jdk/test/ProblemList.txt
jdk/test/sun/security/provider/NSASuiteB/TestDSAGenParameterSpec.java
--- a/jdk/test/ProblemList.txt	Tue May 24 18:41:31 2016 -0700
+++ b/jdk/test/ProblemList.txt	Wed May 25 02:20:02 2016 +0100
@@ -288,8 +288,6 @@
 
 sun/security/tools/keytool/autotest.sh                          8130302 generic-all
 
-sun/security/provider/NSASuiteB/TestDSAGenParameterSpec.java    8137255 generic-all
-
 sun/security/x509/URICertStore/ExtensionsWithLDAP.java          8134577 generic-all
 
 sun/security/provider/SecureRandom/StrongSecureRandom.java      8157387 linux-all
--- a/jdk/test/sun/security/provider/NSASuiteB/TestDSAGenParameterSpec.java	Tue May 24 18:41:31 2016 -0700
+++ b/jdk/test/sun/security/provider/NSASuiteB/TestDSAGenParameterSpec.java	Wed May 25 02:20:02 2016 +0100
@@ -33,6 +33,7 @@
 import java.security.spec.InvalidParameterSpecException;
 import java.util.Arrays;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /*
  * @test
@@ -41,26 +42,15 @@
  * @summary Verify that DSAGenParameterSpec can and can only be used to generate
  *          DSA within some certain range of key sizes as described in the class
  *          specification (L, N) as (1024, 160), (2048, 224), (2048, 256) and
- *          (3072, 256) should be OK for DSAGenParameterSpec. But the real
- *          implementation SUN doesn't support (3072, 256).
- * @run main TestDSAGenParameterSpec
+ *          (3072, 256) should be OK for DSAGenParameterSpec.
+ * @run main TestDSAGenParameterSpec 2048,256,true 2048,224,true 1024,160,true 4096,256 3072,224 2048,160 1024,224 512,160
+ * @run main TestDSAGenParameterSpec 3072,256,true
  */
 public class TestDSAGenParameterSpec {
 
     private static final String ALGORITHM_NAME = "DSA";
     private static final String PROVIDER_NAME = "SUN";
 
-    private static final List<DataTuple> DATA = Arrays.asList(
-            new DataTuple(1024, 160, true, true),
-            new DataTuple(2048, 224, true, true),
-            new DataTuple(2048, 256, true, true),
-            new DataTuple(3072, 256, true, false),
-            new DataTuple(1024, 224),
-            new DataTuple(2048, 160),
-            new DataTuple(4096, 256),
-            new DataTuple(512, 160),
-            new DataTuple(3072, 224));
-
     private static void testDSAGenParameterSpec(DataTuple dataTuple)
             throws NoSuchAlgorithmException, NoSuchProviderException,
             InvalidParameterSpecException, InvalidAlgorithmParameterException {
@@ -84,14 +74,7 @@
             checkParam(param, genParamSpec);
             System.out.println("Test case passed");
         } catch (InvalidParameterException ipe) {
-            // The DSAGenParameterSpec API support this, but the real
-            // implementation in SUN doesn't
-            if (!dataTuple.isSunProviderSupported) {
-                System.out.println("Test case passed: expected "
-                        + "InvalidParameterException is caught");
-            } else {
-                throw new RuntimeException("Test case failed.", ipe);
-            }
+            throw new RuntimeException("Test case failed.", ipe);
         }
     }
 
@@ -127,11 +110,9 @@
             throw new RuntimeException("Wrong seed length");
         }
 
-        // use the parameters to generate real DSA keys
         KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM_NAME,
                 PROVIDER_NAME);
         keyGen.initialize(spec);
-        keyGen.generateKeyPair();
     }
 
     private static DSAGenParameterSpec createGenParameterSpec(
@@ -158,10 +139,21 @@
     }
 
     public static void main(String[] args) throws Exception {
-        for (DataTuple dataTuple : DATA) {
+        List<DataTuple> dataTuples = Arrays.stream(args)
+                .map(arg -> arg.split(",")).map(params -> {
+                    int primePLen = Integer.valueOf(params[0]);
+                    int subprimeQLen = Integer.valueOf(params[1]);
+                    boolean isDSASpecSupported = false;
+                    if (params.length == 3) {
+                        isDSASpecSupported = Boolean.valueOf(params[2]);
+                    }
+                    return new DataTuple(primePLen, subprimeQLen,
+                            isDSASpecSupported);
+                }).collect(Collectors.toList());
+
+        for (DataTuple dataTuple : dataTuples) {
             testDSAGenParameterSpec(dataTuple);
         }
-        System.out.println("All tests passed");
     }
 
     private static class DataTuple {
@@ -169,18 +161,13 @@
         private int primePLen;
         private int subprimeQLen;
         private boolean isDSASpecSupported;
-        private boolean isSunProviderSupported;
 
         private DataTuple(int primePLen, int subprimeQLen,
-                boolean isDSASpecSupported, boolean isSunProviderSupported) {
+                boolean isDSASpecSupported) {
             this.primePLen = primePLen;
             this.subprimeQLen = subprimeQLen;
             this.isDSASpecSupported = isDSASpecSupported;
-            this.isSunProviderSupported = isSunProviderSupported;
-        }
-
-        private DataTuple(int primePLen, int subprimeQLen) {
-            this(primePLen, subprimeQLen, false, false);
         }
     }
 }
+