8194831: [TESTBUG] Test runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java misleading error message
authorgziemski
Wed, 17 Jan 2018 13:39:07 -0600
changeset 48789 7c8f208580cb
parent 48788 a766aa4a1f07
child 48790 423faefc77df
8194831: [TESTBUG] Test runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java misleading error message Summary: Only show the actual GC used in the error message. Show exit status in hex as well as decimal. Reviewed-by: dholmes
test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOption.java
--- a/test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOption.java	Wed Jan 17 09:43:14 2018 -0800
+++ b/test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOption.java	Wed Jan 17 13:39:07 2018 -0600
@@ -373,11 +373,12 @@
      * @throws Exception if java process can not be started
      */
     private boolean runJavaWithParam(String optionValue, boolean valid) throws Exception {
-        int exitCode;
+        int exitCode = 0;
         boolean result = true;
         String errorMessage = null;
+        String explicitGC = null;
         List<String> runJava = new ArrayList<>();
-        OutputAnalyzer out;
+        OutputAnalyzer out = null;
 
         if (VMType != null) {
             runJava.add(VMType);
@@ -388,7 +389,11 @@
               prepend.contains("-XX:+UseSerialGC") ||
               prepend.contains("-XX:+UseParallelGC") ||
               prepend.contains("-XX:+UseG1GC"))) {
-            runJava.add(GCType);
+            explicitGC = GCType;
+        }
+
+        if (explicitGC != null) {
+            runJava.add(explicitGC);
         }
 
         runJava.addAll(prepend);
@@ -398,15 +403,19 @@
         out = new OutputAnalyzer(ProcessTools.createJavaProcessBuilder(runJava.toArray(new String[0])).start());
 
         exitCode = out.getExitValue();
+        String exitCodeString = null;
+        if (exitCode != 0) {
+            exitCodeString = exitCode + " [0x" + Integer.toHexString(exitCode).toUpperCase() + "]";
+        }
 
         if (out.getOutput().contains("A fatal error has been detected by the Java Runtime Environment")) {
             /* Always consider "fatal error" in output as fail */
-            errorMessage = "JVM output reports a fatal error. JVM exited with code " + exitCode + "!";
+            errorMessage = "JVM output reports a fatal error. JVM exited with code " + exitCodeString + "!";
         } else if (valid == true) {
             if (!allowedExitCodes.contains(exitCode)) {
-                errorMessage = "JVM exited with unexpected error code = " + exitCode;
+                errorMessage = "JVM exited with unexpected error code = " + exitCodeString;
             } else if ((exitCode != 0) && (out.getOutput().isEmpty() == true)) {
-                errorMessage = "JVM exited with error(exitcode == " + exitCode + "), but with empty stdout and stderr. " +
+                errorMessage = "JVM exited with error(exitcode == " + exitCodeString + "), but with empty stdout and stderr. " +
                        "Description of error is needed!";
             } else if (out.getOutput().contains("is outside the allowed range")) {
                 errorMessage = "JVM output contains \"is outside the allowed range\"";
@@ -418,7 +427,7 @@
             if (exitCode == 0) {
                 errorMessage = "JVM successfully exit";
             } else if (exitCode != 1) {
-                errorMessage = "JVM exited with code " + exitCode + " which not equal to 1";
+                errorMessage = "JVM exited with code " + exitCodeString + " which does not equal to 1";
             } else if (!out.getOutput().contains(errorMessageCommandLineValue)) {
                 errorMessage = "JVM output does not contain expected output \"" + errorMessageCommandLineValue + "\"";
             }
@@ -426,7 +435,7 @@
 
         if (errorMessage != null) {
             String fullOptionString = String.format("%s %s %s %s",
-                    VMType == null ? "" : VMType, GCType == null ? "" : GCType, prependString.toString(), optionValue).trim().replaceAll("  +", " ");
+                    VMType == null ? "" : VMType, explicitGC == null ? "" : explicitGC, prependString.toString(), optionValue).trim().replaceAll("  +", " ");
             failedMessage(name, fullOptionString, valid, errorMessage);
             printOutputContent(out);
             result = false;