8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
authoriklam
Fri, 22 Nov 2019 15:32:00 -0800
changeset 59236 e2ee246e44e3
parent 59235 0f41ac6bb9dd
child 59237 2601fc0874be
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds Reviewed-by: mseledtsov
test/hotspot/jtreg/runtime/cds/appcds/TestCommon.java
test/hotspot/jtreg/runtime/cds/appcds/cacheObject/ArchivedModuleCompareTest.java
--- a/test/hotspot/jtreg/runtime/cds/appcds/TestCommon.java	Fri Nov 22 15:31:52 2019 -0800
+++ b/test/hotspot/jtreg/runtime/cds/appcds/TestCommon.java	Fri Nov 22 15:32:00 2019 -0800
@@ -662,4 +662,24 @@
          }
          return linkedJar;
     }
+
+    // Remove all UL log messages from a JVM's STDOUT (such as those printed by -Xlog:cds)
+    static Pattern logPattern = Pattern.compile("^\\[[0-9. ]*s\\].*");
+    public static String filterOutLogs(String stdout) {
+        StringBuilder sb = new StringBuilder();
+        String prefix = "";
+        for (String line : stdout.split("\n")) {
+            if (logPattern.matcher(line).matches()) {
+                continue;
+            }
+            sb.append(prefix);
+            sb.append(line);
+            prefix = "\n";
+        }
+        if (stdout.endsWith("\n")) {
+            // String.split("A\n") returns {"A"}, not {"A", ""}.
+            sb.append("\n");
+        }
+        return sb.toString();
+    }
 }
--- a/test/hotspot/jtreg/runtime/cds/appcds/cacheObject/ArchivedModuleCompareTest.java	Fri Nov 22 15:31:52 2019 -0800
+++ b/test/hotspot/jtreg/runtime/cds/appcds/cacheObject/ArchivedModuleCompareTest.java	Fri Nov 22 15:32:00 2019 -0800
@@ -49,12 +49,12 @@
 
         output = TestCommon.execOff("-cp", appJar, "PrintSystemModulesApp");
         output.shouldHaveExitValue(0);
-        String bootModules1 = output.getStdout();
+        String bootModules1 = TestCommon.filterOutLogs(output.getStdout());
 
         output = TestCommon.exec(appJar, "PrintSystemModulesApp");
         TestCommon.checkExec(output);
         if (output.getStderr().contains("sharing")) {
-            String bootModules2 = output.getStdout();
+            String bootModules2 = TestCommon.filterOutLogs(output.getStdout());
             TestCommon.checkOutputStrings(bootModules1, bootModules2, ", ");
         }
 
@@ -66,14 +66,14 @@
                                     "--show-module-resolution",
                                     "-version");
         output.shouldHaveExitValue(0);
-        String moduleResolutionOut1 = output.getStdout();
+        String moduleResolutionOut1 = TestCommon.filterOutLogs(output.getStdout());
 
         output = TestCommon.exec(appJar,
                                  "--show-module-resolution",
                                  "-version");
         TestCommon.checkExec(output);
         if (output.getStderr().contains("sharing")) {
-            String moduleResolutionOut2 = output.getStdout();
+            String moduleResolutionOut2 = TestCommon.filterOutLogs(output.getStdout());
             TestCommon.checkOutputStrings(
                 moduleResolutionOut1, moduleResolutionOut2, "\n");
         }