changeset 30137:effb5513d392

8076344: serviceability/dcmd/vm/SetVMFlagTest.java test fails with "java.lang.Error: 'MaxHeapSize' flag is not available or immutable" Reviewed-by: sla
author jbachorik
date Thu, 02 Apr 2015 12:14:43 +0200
parents bbb14e0a0c79
children 35599707b3f7
files hotspot/test/serviceability/dcmd/vm/SetVMFlagTest.java hotspot/test/testlibrary/com/oracle/java/testlibrary/dcmd/CommandExecutor.java
diffstat 2 files changed, 54 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/test/serviceability/dcmd/vm/SetVMFlagTest.java	Thu Apr 02 07:44:55 2015 +0000
+++ b/hotspot/test/serviceability/dcmd/vm/SetVMFlagTest.java	Thu Apr 02 12:14:43 2015 +0200
@@ -38,13 +38,10 @@
  */
 
 public class SetVMFlagTest {
-    private static final String PRINTGC_NAME = "PrintGC";
-    private static final String XMX_NAME = "MaxHeapSize";
-
-    private static final String PRINTGC_PATTERN = "\\s*bool " + PRINTGC_NAME +
-                                                  "\\s+[\\:]?=\\s+(.*?)\\s+\\{manageable\\}";
-    private static final String XMX_PATTERN = "\\s*uintx " + XMX_NAME +
-                                                  "\\s+[\\:]?=\\s+(.*?)\\s+\\{product\\}";
+    private static final String MANAGEABLE_PATTERN = "\\s*bool\\s+(\\S+)\\s+[\\:]?=\\s+" +
+                                                     "(.*?)\\s+\\{manageable\\}";
+    private static final String IMMUTABLE_PATTERN = "\\s*uintx\\s+(\\S+)\\s+[\\:]?=\\s+" +
+                                                    "(.*?)\\s+\\{product\\}";
 
     public void run(CommandExecutor executor) {
         setMutableFlag(executor);
@@ -60,76 +57,86 @@
 
     private void setMutableFlag(CommandExecutor executor) {
         OutputAnalyzer out = getAllFlags(executor);
-        String flagVal = out.firstMatch(PRINTGC_PATTERN, 1);
+        String flagName = out.firstMatch(MANAGEABLE_PATTERN, 1);
+        String flagVal = out.firstMatch(MANAGEABLE_PATTERN, 2);
+
+        System.out.println("### Setting a mutable flag '" + flagName + "'");
 
         if (flagVal == null) {
             System.err.println(out.getOutput());
-            throw new Error("'" + PRINTGC_NAME + "' flag is either not available or manageable");
+            throw new Error("Can not find a boolean manageable flag");
         }
 
         Boolean blnVal = Boolean.parseBoolean(flagVal);
 
-        out = executor.execute("VM.set_flag " + PRINTGC_NAME + " " + (blnVal ? 0 : 1));
+        out = executor.execute("VM.set_flag " + flagName + " " + (blnVal ? 0 : 1));
         out.stderrShouldBeEmpty();
 
         out = getAllFlags(executor);
 
-        String newFlagVal = out.firstMatch(PRINTGC_PATTERN, 1);
+        String newFlagVal = out.firstMatch(MANAGEABLE_PATTERN.replace("(\\S+)", flagName), 1);
 
         assertNotEquals(newFlagVal, flagVal);
     }
 
     private void setMutableFlagWithInvalidValue(CommandExecutor executor) {
         OutputAnalyzer out = getAllFlags(executor);
-        String flagVal = out.firstMatch(PRINTGC_PATTERN, 1);
+        String flagName = out.firstMatch(MANAGEABLE_PATTERN, 1);
+        String flagVal = out.firstMatch(MANAGEABLE_PATTERN, 2);
+
+        System.out.println("### Setting a mutable flag '" + flagName + "' to an invalid value");
 
         if (flagVal == null) {
             System.err.println(out.getOutput());
-            throw new Error("'" + PRINTGC_NAME + "' flag is either not available or manageable");
+            throw new Error("Can not find a boolean manageable flag");
         }
 
-        // PrintGC is a boolean flag and accepts only 0/1 as its value
-        out = executor.execute("VM.set_flag " + PRINTGC_NAME + " unexpected_value");
+        // a boolean flag accepts only 0/1 as its value
+        out = executor.execute("VM.set_flag " + flagName + " unexpected_value");
         out.stderrShouldBeEmpty();
         out.stdoutShouldContain("flag value must be a boolean (1 or 0)");
 
         out = getAllFlags(executor);
 
-        String newFlagVal = out.firstMatch(PRINTGC_PATTERN, 1);
+        String newFlagVal = out.firstMatch(MANAGEABLE_PATTERN.replace("(\\S+)", flagName), 1);
 
         assertEquals(newFlagVal, flagVal);
     }
 
     private void setImmutableFlag(CommandExecutor executor) {
         OutputAnalyzer out = getAllFlags(executor);
-        String flagVal = out.firstMatch(XMX_PATTERN, 1);
+        String flagName = out.firstMatch(IMMUTABLE_PATTERN, 1);
+        String flagVal = out.firstMatch(IMMUTABLE_PATTERN, 2);
+
+        System.out.println("### Setting an immutable flag '" + flagName + "'");
 
         if (flagVal == null) {
             System.err.println(out.getOutput());
-            throw new Error("'" + XMX_NAME + "' flag is not available or immutable");
+            throw new Error("Can not find an immutable uintx flag");
         }
 
         Long numVal = Long.parseLong(flagVal);
 
-        out = executor.execute("VM.set_flag " + XMX_NAME + " " + (numVal + 1));
+        out = executor.execute("VM.set_flag " + flagName + " " + (numVal + 1));
         out.stderrShouldBeEmpty();
         out.stdoutShouldContain("only 'writeable' flags can be set");
 
         out = getAllFlags(executor);
 
-        String newFlagVal = out.firstMatch(XMX_PATTERN, 1);
+        String newFlagVal = out.firstMatch(IMMUTABLE_PATTERN.replace("(\\S+)", flagName), 1);
 
         assertEquals(newFlagVal, flagVal);
     }
 
     private void setNonExistingFlag(CommandExecutor executor) {
         String unknownFlag = "ThisIsUnknownFlag";
+        System.out.println("### Setting a non-existing flag '" + unknownFlag + "'");
         OutputAnalyzer out = executor.execute("VM.set_flag " + unknownFlag + " 1");
         out.stderrShouldBeEmpty();
         out.stdoutShouldContain("flag " + unknownFlag + " does not exist");
     }
 
     private OutputAnalyzer getAllFlags(CommandExecutor executor) {
-        return executor.execute("VM.flags -all");
+        return executor.execute("VM.flags -all", true);
     }
 }
\ No newline at end of file
--- a/hotspot/test/testlibrary/com/oracle/java/testlibrary/dcmd/CommandExecutor.java	Thu Apr 02 07:44:55 2015 +0000
+++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/dcmd/CommandExecutor.java	Thu Apr 02 12:14:43 2015 +0200
@@ -40,16 +40,34 @@
      *          stderr, regardless of the specific executor used.
      */
     public final OutputAnalyzer execute(String cmd) throws CommandExecutorException {
-        System.out.printf("Running DCMD '%s' through '%s'%n", cmd, this.getClass().getSimpleName());
+        return execute(cmd, false);
+    }
+
+    /**
+     * Execute a diagnostic command
+     *
+     * @param cmd The diagnostic command to execute
+     * @param silent Do not print the command output
+     * @return an {@link jdk.testlibrary.OutputAnalyzer} encapsulating the output of the command
+     * @throws CommandExecutorException if there is an exception on the "calling side" while trying to execute the
+     *          Diagnostic Command. Exceptions thrown on the remote side are available as textual representations in
+     *          stderr, regardless of the specific executor used.
+     */
+    public final OutputAnalyzer execute(String cmd, boolean silent) throws CommandExecutorException {
+        if (!silent) {
+            System.out.printf("Running DCMD '%s' through '%s'%n", cmd, this.getClass().getSimpleName());
+        }
+
         OutputAnalyzer oa = executeImpl(cmd);
 
-        System.out.println("---------------- stdout ----------------");
-        System.out.println(oa.getStdout());
-        System.out.println("---------------- stderr ----------------");
-        System.out.println(oa.getStderr());
-        System.out.println("----------------------------------------");
-        System.out.println();
-
+        if (!silent) {
+            System.out.println("---------------- stdout ----------------");
+            System.out.println(oa.getStdout());
+            System.out.println("---------------- stderr ----------------");
+            System.out.println(oa.getStderr());
+            System.out.println("----------------------------------------");
+            System.out.println();
+        }
         return oa;
     }