test/lib/jdk/test/lib/cds/CDSTestUtils.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File open Sdiff test/lib/jdk/test/lib/cds

test/lib/jdk/test/lib/cds/CDSTestUtils.java

Print this page
rev 49650 : [mq]: module_path


 100      *      CCDSTestUtils.run(args)
 101      *         .assertNormalExit(output -> output.shouldNotContain("this should not be printed")
 102      *         .assertNormalExit("should have this", "should have that");
 103      *
 104      * 4. [Rare use case] if a test sometimes exit normally, and sometimes abnormally:
 105      *
 106      *      CCDSTestUtils.run(args)
 107      *         .ifNormalExit("ths string is printed when exiting with 0")
 108      *         .ifAbNormalExit("ths string is printed when exiting with 1");
 109      *
 110      *    NOTE: you usually don't want to write your test case like this -- it should always
 111      *    exit with the same exit code. (But I kept this API because some existing test cases
 112      *    behave this way -- need to revisit).
 113      */
 114     public static class Result {
 115         private final OutputAnalyzer output;
 116         private final CDSOptions options;
 117         private final boolean hasMappingFailure;
 118         private final boolean hasAbnormalExit;
 119         private final boolean hasNormalExit;

 120 
 121         public Result(CDSOptions opts, OutputAnalyzer out) throws Exception {
 122             options = opts;
 123             output = out;
 124             hasMappingFailure = CDSTestUtils.checkCommonExecExceptions(output);
 125             hasAbnormalExit   = (!hasMappingFailure) && (output.getExitValue() != 0);
 126             hasNormalExit     = (!hasMappingFailure) && (output.getExitValue() == 0);
 127 
 128             if (hasNormalExit) {
 129                 if ("on".equals(options.xShareMode) && output.getStderr().contains("java version")) {


 130                     // "-showversion" is always passed in the command-line by the execXXX methods.
 131                     // During normal exit, we require that the VM to show that sharing was enabled.
 132                     output.shouldContain("sharing");
 133                 }
 134             }
 135         }
 136 
 137         public Result assertNormalExit(Checker checker) throws Exception {
 138             if (!hasMappingFailure) {
 139                 checker.check(output);
 140                 output.shouldHaveExitValue(0);
 141             }
 142             return this;
 143         }
 144 
 145         public Result assertAbnormalExit(Checker checker) throws Exception {
 146             if (!hasMappingFailure) {
 147                 checker.check(output);
 148                 output.shouldNotHaveExitValue(0);
 149             }
 150             return this;
 151         }




















 152 
 153         public Result ifNormalExit(Checker checker) throws Exception {
 154             if (hasNormalExit) {
 155                 checker.check(output);
 156             }
 157             return this;
 158         }
 159 
 160         public Result ifAbnormalExit(Checker checker) throws Exception {
 161             if (hasAbnormalExit) {
 162                 checker.check(output);
 163             }
 164             return this;
 165         }
 166 
 167         public Result ifNoMappingFailure(Checker checker) throws Exception {
 168             if (!hasMappingFailure) {
 169                 checker.check(output);
 170             }
 171             return this;




 100      *      CCDSTestUtils.run(args)
 101      *         .assertNormalExit(output -> output.shouldNotContain("this should not be printed")
 102      *         .assertNormalExit("should have this", "should have that");
 103      *
 104      * 4. [Rare use case] if a test sometimes exit normally, and sometimes abnormally:
 105      *
 106      *      CCDSTestUtils.run(args)
 107      *         .ifNormalExit("ths string is printed when exiting with 0")
 108      *         .ifAbNormalExit("ths string is printed when exiting with 1");
 109      *
 110      *    NOTE: you usually don't want to write your test case like this -- it should always
 111      *    exit with the same exit code. (But I kept this API because some existing test cases
 112      *    behave this way -- need to revisit).
 113      */
 114     public static class Result {
 115         private final OutputAnalyzer output;
 116         private final CDSOptions options;
 117         private final boolean hasMappingFailure;
 118         private final boolean hasAbnormalExit;
 119         private final boolean hasNormalExit;
 120         private final String CDS_DISABLED = "warning: CDS is disabled when the";
 121 
 122         public Result(CDSOptions opts, OutputAnalyzer out) throws Exception {
 123             options = opts;
 124             output = out;
 125             hasMappingFailure = CDSTestUtils.checkCommonExecExceptions(output);
 126             hasAbnormalExit   = (!hasMappingFailure) && (output.getExitValue() != 0);
 127             hasNormalExit     = (!hasMappingFailure) && (output.getExitValue() == 0);
 128 
 129             if (hasNormalExit) {
 130                 if ("on".equals(options.xShareMode) &&
 131                     output.getStderr().contains("java version") &&
 132                     !output.getStderr().contains(CDS_DISABLED)) {
 133                     // "-showversion" is always passed in the command-line by the execXXX methods.
 134                     // During normal exit, we require that the VM to show that sharing was enabled.
 135                     output.shouldContain("sharing");
 136                 }
 137             }
 138         }
 139 
 140         public Result assertNormalExit(Checker checker) throws Exception {
 141             if (!hasMappingFailure) {
 142                 checker.check(output);
 143                 output.shouldHaveExitValue(0);
 144             }
 145             return this;
 146         }
 147 
 148         public Result assertAbnormalExit(Checker checker) throws Exception {
 149             if (!hasMappingFailure) {
 150                 checker.check(output);
 151                 output.shouldNotHaveExitValue(0);
 152             }
 153             return this;
 154         }
 155 
 156         // When {--limit-modules, --patch-module, and/or --upgrade-module-path}
 157         // are specified, CDS is silently disabled for both -Xshare:auto and -Xshare:on.
 158         public Result assertSilentlyDisabledCDS(Checker checker) throws Exception {
 159             if (hasMappingFailure) {
 160                 throw new RuntimeException("Unexpected mapping failure");
 161             }
 162             // this comes from a JVM warning message.
 163             output.shouldContain(CDS_DISABLED);
 164 
 165             checker.check(output);
 166             return this;
 167         }
 168 
 169         public Result assertSilentlyDisabledCDS(int exitCode, String... matches) throws Exception {
 170             return assertSilentlyDisabledCDS((out) -> {
 171                 out.shouldHaveExitValue(exitCode);
 172                 checkMatches(out, matches);
 173                    });
 174         } 
 175 
 176         public Result ifNormalExit(Checker checker) throws Exception {
 177             if (hasNormalExit) {
 178                 checker.check(output);
 179             }
 180             return this;
 181         }
 182 
 183         public Result ifAbnormalExit(Checker checker) throws Exception {
 184             if (hasAbnormalExit) {
 185                 checker.check(output);
 186             }
 187             return this;
 188         }
 189 
 190         public Result ifNoMappingFailure(Checker checker) throws Exception {
 191             if (!hasMappingFailure) {
 192                 checker.check(output);
 193             }
 194             return this;


test/lib/jdk/test/lib/cds/CDSTestUtils.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File