8180631: [TESTBUG] CDS tests should use CDSTestUtils.executeAndLog whenever spawning sub processes
authormseledtsov
Tue, 23 May 2017 20:14:52 -0700
changeset 46491 e43953993af3
parent 46490 d530e842c512
child 46492 5848b57c9dc5
8180631: [TESTBUG] CDS tests should use CDSTestUtils.executeAndLog whenever spawning sub processes Summary: Updated all relevant call sites to use executeAndLog() Reviewed-by: iklam, ccheung
hotspot/test/runtime/SharedArchiveFile/DumpSymbolAndStringTable.java
hotspot/test/runtime/SharedArchiveFile/LargeSharedSpace.java
hotspot/test/runtime/SharedArchiveFile/LimitSharedSizes.java
hotspot/test/runtime/SharedArchiveFile/MaxMetaspaceSize.java
hotspot/test/runtime/SharedArchiveFile/SASymbolTableTest.java
--- a/hotspot/test/runtime/SharedArchiveFile/DumpSymbolAndStringTable.java	Tue May 23 18:42:08 2017 +0000
+++ b/hotspot/test/runtime/SharedArchiveFile/DumpSymbolAndStringTable.java	Tue May 23 20:14:52 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,7 +30,7 @@
  *          java.management
  * @run main/othervm -XX:+UnlockDiagnosticVMOptions DumpSymbolAndStringTable
  */
-
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.JDKToolFinder;
@@ -42,7 +42,7 @@
 
         ProcessBuilder pb = new ProcessBuilder();
         pb.command(new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.symboltable", "-verbose"});
-        OutputAnalyzer output = new OutputAnalyzer(pb.start());
+        OutputAnalyzer output = CDSTestUtils.executeAndLog(pb, "jcmd-symboltable");
         try {
             output.shouldContain("24 2: DumpSymbolAndStringTable\n");
         } catch (RuntimeException e) {
@@ -50,7 +50,7 @@
         }
 
         pb.command(new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.stringtable", "-verbose"});
-        output = new OutputAnalyzer(pb.start());
+        output = CDSTestUtils.executeAndLog(pb, "jcmd-stringtable");
         try {
             output.shouldContain("16: java.lang.String\n");
         } catch (RuntimeException e) {
--- a/hotspot/test/runtime/SharedArchiveFile/LargeSharedSpace.java	Tue May 23 18:42:08 2017 +0000
+++ b/hotspot/test/runtime/SharedArchiveFile/LargeSharedSpace.java	Tue May 23 20:14:52 2017 -0700
@@ -40,7 +40,6 @@
 
 public class LargeSharedSpace {
     public static void main(String[] args) throws Exception {
-       ProcessBuilder pb;
        OutputAnalyzer output;
 
        // Test case 1: -XX:SharedMiscCodeSize=1066924031
--- a/hotspot/test/runtime/SharedArchiveFile/LimitSharedSizes.java	Tue May 23 18:42:08 2017 +0000
+++ b/hotspot/test/runtime/SharedArchiveFile/LimitSharedSizes.java	Tue May 23 20:14:52 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,6 +31,7 @@
  * @run main LimitSharedSizes
  */
 
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.Platform;
@@ -150,7 +151,7 @@
                option,
                "-Xshare:dump");
 
-            OutputAnalyzer output = new OutputAnalyzer(pb.start());
+            OutputAnalyzer output = CDSTestUtils.executeAndLog(pb, "dump" + counter);
 
             switch (td.getResult()) {
                 case VALID:
@@ -167,22 +168,14 @@
                          "-XX:+PrintSharedArchiveAndExit",
                          "-version");
 
-                      try {
-                          output = new OutputAnalyzer(pb.start());
-                          output.shouldContain("archive is valid");
-                      } catch (RuntimeException e) {
-                          // if sharing failed due to ASLR or similar reasons,
-                          // check whether sharing was attempted at all (UseSharedSpaces)
-                          if ((output.getOutput().contains("Unable to use shared archive") ||
-                               output.getOutput().contains("Unable to map ReadOnly shared space at required address.") ||
-                               output.getOutput().contains("Unable to map ReadWrite shared space at required address.") ||
-                               output.getOutput().contains("Unable to reserve shared space at required address")) &&
-                               output.getExitValue() == 1) {
-                               System.out.println("Unable to use shared archive: test not executed; assumed passed");
-                               continue;
-                          }
+                      output = CDSTestUtils.executeAndLog(pb, "use" + counter);
+                      if(CDSTestUtils.isUnableToMap(output)) {
+                          System.out.println("Unable to use shared archive: " +
+                                             "test not executed; assumed passed");
+                          continue;
+                      } else {
+                          output.shouldHaveExitValue(0);
                       }
-                      output.shouldHaveExitValue(0);
                   }
                 }
                 break;
--- a/hotspot/test/runtime/SharedArchiveFile/MaxMetaspaceSize.java	Tue May 23 18:42:08 2017 +0000
+++ b/hotspot/test/runtime/SharedArchiveFile/MaxMetaspaceSize.java	Tue May 23 20:14:52 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,15 +30,16 @@
  *          java.management
  */
 
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.ProcessTools;
-import jdk.test.lib.process.OutputAnalyzer;
 
 public class MaxMetaspaceSize {
   public static void main(String[] args) throws Exception {
+      String msg = "is not large enough.\n" +
+          "Either don't specify the -XX:MaxMetaspaceSize=<size>\n" +
+          "or increase the size to at least";
     ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
         "-XX:MaxMetaspaceSize=10m", "-Xshare:dump");
-    OutputAnalyzer output = new OutputAnalyzer(pb.start());
-      output.shouldContain("is not large enough.\nEither don't specify the -XX:MaxMetaspaceSize=<size>\nor increase the size to at least");
-      output.shouldHaveExitValue(2);
+    CDSTestUtils.executeAndLog(pb, "dump").shouldContain(msg).shouldHaveExitValue(2);
   }
 }
--- a/hotspot/test/runtime/SharedArchiveFile/SASymbolTableTest.java	Tue May 23 18:42:08 2017 +0000
+++ b/hotspot/test/runtime/SharedArchiveFile/SASymbolTableTest.java	Tue May 23 20:14:52 2017 -0700
@@ -95,17 +95,11 @@
                     "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.tools=ALL-UNNAMED",
                     "SASymbolTableTestAgent",
                     Long.toString(pid));
-            OutputAnalyzer output = ProcessTools.executeProcess(tool);
-            System.out.println("STDOUT[");
-            System.out.println(output.getOutput());
+            OutputAnalyzer output = CDSTestUtils.executeAndLog(tool, "tool");
             if (output.getStdout().contains("connected too early")) {
                 System.out.println("SymbolTable not created by VM - test skipped");
                 return;
             }
-            System.out.println("]");
-            System.out.println("STDERR[");
-            System.out.print(output.getStderr());
-            System.out.println("]");
             output.shouldHaveExitValue(0);
         } catch (Exception ex) {
             throw new RuntimeException("Test ERROR " + ex, ex);