changeset 17557:077a8cd3df68

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
author ssahoo
date Wed, 31 Aug 2016 08:44:12 -0700
parents b46447382c84
children 6f390eafc676 80f8d74959a0
files test/sun/security/provider/SecureRandom/AutoReseed.java
diffstat 1 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/test/sun/security/provider/SecureRandom/AutoReseed.java	Wed Aug 31 08:34:59 2016 -0700
+++ b/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");
         }
     }
 }