8164922: sun/security/provider/SecureRandom/AutoReseed.java failed with timeout in Ubuntu Linux.
authorssahoo
Wed, 31 Aug 2016 08:44:12 -0700
changeset 40683 c74de0698d08
parent 40682 b08455408de7
child 40684 2e37c119dc2a
child 40693 364c71c3a981
8164922: sun/security/provider/SecureRandom/AutoReseed.java failed with timeout in Ubuntu Linux. Summary: The test timeout waiting to get seed in an exhausted Linux platform. Reviewed-by: weijun
jdk/test/sun/security/provider/SecureRandom/AutoReseed.java
--- a/jdk/test/sun/security/provider/SecureRandom/AutoReseed.java	Wed Aug 31 08:34:59 2016 -0700
+++ b/jdk/test/sun/security/provider/SecureRandom/AutoReseed.java	Wed Aug 31 08:44:12 2016 -0700
@@ -20,6 +20,7 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
 import java.security.SecureRandom;
 import java.security.Security;
 
@@ -27,15 +28,15 @@
  * @test
  * @bug 8051408
  * @summary make sure nextBytes etc can be called before setSeed
+ * @run main/othervm -Djava.security.egd=file:/dev/urandom AutoReseed
  */
 public class AutoReseed {
 
     public static void main(String[] args) throws Exception {
         SecureRandom sr;
-        String old = Security.getProperty("securerandom.drbg.config");
-        try {
-            for (String mech :
-                    new String[]{"Hash_DRBG", "HMAC_DRBG", "CTR_DRBG"}) {
+        boolean pass = true;
+        for (String mech : new String[]{"Hash_DRBG", "HMAC_DRBG", "CTR_DRBG"}) {
+            try {
                 System.out.println("Testing " + mech + "...");
                 Security.setProperty("securerandom.drbg.config", mech);
 
@@ -46,9 +47,13 @@
                 sr.reseed();
                 sr = SecureRandom.getInstance("DRBG");
                 sr.generateSeed(10);
+            } catch (Exception e) {
+                pass = false;
+                e.printStackTrace(System.out);
             }
-        } finally {
-            Security.setProperty("securerandom.drbg.config", old);
+        }
+        if (!pass) {
+            throw new RuntimeException("At least one test case failed");
         }
     }
 }