Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8179249

Improve process output analysis in CDS tests

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P3 P3
    • 11
    • 10
    • hotspot
    • b03

      Many CDS tests have the following pattern for analyzing the output of a JVM process.

          OutputAnalyzer out = TestCommon.execCommon("-cp", cp, mainClass, ....);
          out.shouldMatch(".*pattern");
          out.shouldHaveExitValue(0);

      However, due to Address Space Layout Randomization (ASLR), intermittently the launched JVM process may fail to map the archive. In that case, it's possible for the output to not match the given pattern, and thus the test would report a spurious failure.

      Many of the existing tests used this pattern to avoid the spurious failures (see http://hg.openjdk.java.net/jdk/hs/file/f43576cfb273/test/hotspot/jtreg/runtime/appcds/ClassPathAttr.java#l77 )

            output = TestCommon.execCommon("-Xlog:class+path", "-cp", cp, "CpAttr1");
            if (!TestCommon.isUnableToMap(output)){
              output.shouldMatch("checking shared classpath entry: .*cpattr2.jar");
              output.shouldMatch("checking shared classpath entry: .*cpattr3.jar");
            }

      However, in many cases in the past, we have forgotten to put the isUnableToMap check, and subsequently would have to fix the test.

      A better design this:

            TestCommon.run("-Xlog:class+path", "-cp", cp, "CpAttr1")
              .assertNormalExit(output -> {
                  output.shouldMatch("checking shared classpath entry: .*cpattr2.jar");
                  output.shouldMatch("checking shared classpath entry: .*cpattr3.jar");
                });

      here, the output.shouldMatch() code is provided in a Lambda expression. The assertNormalExit() method would invoke the Lambda expression only if no 'unable to map" error has happened.

            iklam Ioi Lam
            iklam Ioi Lam
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: