test/lib/jdk/test/lib/cds/CDSTestUtils.java
changeset 51411 4699147a4f91
parent 49931 840e26123940
child 51491 187c84a5efe1
--- a/test/lib/jdk/test/lib/cds/CDSTestUtils.java	Wed Aug 15 14:35:33 2018 +0200
+++ b/test/lib/jdk/test/lib/cds/CDSTestUtils.java	Wed Aug 15 10:00:16 2018 -0700
@@ -32,7 +32,7 @@
 import jdk.test.lib.Utils;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.process.ProcessTools;
-
+import jtreg.SkippedException;
 
 // This class contains common test utilities for testing CDS
 public class CDSTestUtils {
@@ -114,17 +114,14 @@
     public static class Result {
         private final OutputAnalyzer output;
         private final CDSOptions options;
-        private final boolean hasMappingFailure;
-        private final boolean hasAbnormalExit;
         private final boolean hasNormalExit;
         private final String CDS_DISABLED = "warning: CDS is disabled when the";
 
         public Result(CDSOptions opts, OutputAnalyzer out) throws Exception {
-            options = opts;
-            output = out;
-            hasMappingFailure = CDSTestUtils.checkCommonExecExceptions(output);
-            hasAbnormalExit   = (!hasMappingFailure) && (output.getExitValue() != 0);
-            hasNormalExit     = (!hasMappingFailure) && (output.getExitValue() == 0);
+            checkMappingFailure(out);
+            this.options = opts;
+            this.output = out;
+            hasNormalExit = (output.getExitValue() == 0);
 
             if (hasNormalExit) {
                 if ("on".equals(options.xShareMode) &&
@@ -138,30 +135,22 @@
         }
 
         public Result assertNormalExit(Checker checker) throws Exception {
-            if (!hasMappingFailure) {
-                checker.check(output);
-                output.shouldHaveExitValue(0);
-            }
+            checker.check(output);
+            output.shouldHaveExitValue(0);
             return this;
         }
 
         public Result assertAbnormalExit(Checker checker) throws Exception {
-            if (!hasMappingFailure) {
-                checker.check(output);
-                output.shouldNotHaveExitValue(0);
-            }
+            checker.check(output);
+            output.shouldNotHaveExitValue(0);
             return this;
         }
 
         // When {--limit-modules, --patch-module, and/or --upgrade-module-path}
         // are specified, CDS is silently disabled for both -Xshare:auto and -Xshare:on.
         public Result assertSilentlyDisabledCDS(Checker checker) throws Exception {
-            if (hasMappingFailure) {
-                throw new RuntimeException("Unexpected mapping failure");
-            }
             // this comes from a JVM warning message.
             output.shouldContain(CDS_DISABLED);
-
             checker.check(output);
             return this;
         }
@@ -181,34 +170,27 @@
         }
 
         public Result ifAbnormalExit(Checker checker) throws Exception {
-            if (hasAbnormalExit) {
+            if (!hasNormalExit) {
                 checker.check(output);
             }
             return this;
         }
 
         public Result ifNoMappingFailure(Checker checker) throws Exception {
-            if (!hasMappingFailure) {
-                checker.check(output);
-            }
+            checker.check(output);
             return this;
         }
 
 
         public Result assertNormalExit(String... matches) throws Exception {
-            if (!hasMappingFailure) {
-                checkMatches(output, matches);
-                output.shouldHaveExitValue(0);
-            }
+            checkMatches(output, matches);
+            output.shouldHaveExitValue(0);
             return this;
         }
 
         public Result assertAbnormalExit(String... matches) throws Exception {
-            if (!hasMappingFailure) {
-                checkMatches(output, matches);
-                output.shouldNotHaveExitValue(0);
-            }
-
+            checkMatches(output, matches);
+            output.shouldNotHaveExitValue(0);
             return this;
         }
     }
@@ -223,7 +205,7 @@
     public static final String TestTimeoutFactor = System.getProperty("test.timeout.factor", "1.0");
 
     public static final String UnableToMapMsg =
-        "Unable to map shared archive: test did not complete; assumed PASS";
+        "Unable to map shared archive: test did not complete";
 
     // Create bootstrap CDS archive,
     // use extra JVM command line args as a prefix.
@@ -295,7 +277,7 @@
     // of exceptions and common errors.
     // Exception e argument - an exception to be re-thrown if none of the common
     // exceptions match. Pass null if you wish not to re-throw any exception.
-    public static boolean checkCommonExecExceptions(OutputAnalyzer output, Exception e)
+    public static void checkCommonExecExceptions(OutputAnalyzer output, Exception e)
         throws Exception {
         if (output.getStdout().contains("http://bugreport.java.com/bugreport/crash.jsp")) {
             throw new RuntimeException("Hotspot crashed");
@@ -303,9 +285,6 @@
         if (output.getStdout().contains("TEST FAILED")) {
             throw new RuntimeException("Test Failed");
         }
-        if (output.getOutput().contains("shared class paths mismatch")) {
-//            throw new RuntimeException("shared class paths mismatch");
-        }
         if (output.getOutput().contains("Unable to unmap shared space")) {
             throw new RuntimeException("Unable to unmap shared space");
         }
@@ -314,18 +293,16 @@
         // at given address. This behavior is platform-specific, machine config-specific
         // and can be random (see ASLR).
         if (isUnableToMap(output)) {
-            System.out.println(UnableToMapMsg);
-            return true;
+            throw new SkippedException(UnableToMapMsg);
         }
 
         if (e != null) {
             throw e;
         }
-        return false;
     }
 
-    public static boolean checkCommonExecExceptions(OutputAnalyzer output) throws Exception {
-        return checkCommonExecExceptions(output, null);
+    public static void checkCommonExecExceptions(OutputAnalyzer output) throws Exception {
+        checkCommonExecExceptions(output, null);
     }
 
 
@@ -358,6 +335,12 @@
         return false;
     }
 
+    public static void checkMappingFailure(OutputAnalyzer out) throws SkippedException {
+        if (isUnableToMap(out)) {
+            throw new SkippedException(UnableToMapMsg);
+        }
+    }
+
     public static Result run(String... cliPrefix) throws Exception {
         CDSOptions opts = new CDSOptions();
         opts.setArchiveName(getDefaultArchiveName());
@@ -446,8 +429,7 @@
                                              int expectedExitValue,
                                              String... extraMatches) throws Exception {
         if (isUnableToMap(output)) {
-            System.out.println(UnableToMapMsg);
-            return output;
+            throw new SkippedException(UnableToMapMsg);
         }
 
         output.shouldHaveExitValue(expectedExitValue);