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




 178 
 179         public Result ifNoMappingFailure(Checker checker) throws Exception {
 180             checker.check(output);
 181             return this;
 182         }
 183 
 184 
 185         public Result assertNormalExit(String... matches) throws Exception {
 186             checkMatches(output, matches);
 187             output.shouldHaveExitValue(0);
 188             return this;
 189         }
 190 
 191         public Result assertAbnormalExit(String... matches) throws Exception {
 192             checkMatches(output, matches);
 193             output.shouldNotHaveExitValue(0);
 194             return this;
 195         }
 196     }
 197 
 198     // Specify this property to copy sdandard output of the child test process to
 199     // the parent/main stdout of the test.
 200     // By default such output is logged into a file, and is copied into the main stdout.
 201     public static final boolean CopyChildStdoutToMainStdout =
 202         Boolean.valueOf(System.getProperty("test.cds.copy.child.stdout", "true"));








 203 
 204     // This property is passed to child test processes
 205     public static final String TestTimeoutFactor = System.getProperty("test.timeout.factor", "1.0");
 206 
 207     public static final String UnableToMapMsg =
 208         "Unable to map shared archive: test did not complete";
 209 
 210     // Create bootstrap CDS archive,
 211     // use extra JVM command line args as a prefix.
 212     // For CDS tests specifying prefix makes more sense than specifying suffix, since
 213     // normally there are no classes or arguments to classes, just "-version"
 214     // To specify suffix explicitly use CDSOptions.addSuffix()
 215     public static OutputAnalyzer createArchive(String... cliPrefix)
 216         throws Exception {
 217         return createArchive((new CDSOptions()).addPrefix(cliPrefix));
 218     }
 219 
 220     // Create bootstrap CDS archive
 221     public static OutputAnalyzer createArchive(CDSOptions opts)
 222         throws Exception {


 527         return new File(dir, getTestName() + "-" + name);
 528     }
 529 
 530 
 531     public static File getOutputSourceFile(String name) {
 532         File dir = new File(System.getProperty("test.classes", "."));
 533         return new File(dir, name);
 534     }
 535 
 536 
 537     public static File getSourceFile(String name) {
 538         File dir = new File(System.getProperty("test.src", "."));
 539         return new File(dir, name);
 540     }
 541 
 542 
 543     // ============================= Logging
 544     public static OutputAnalyzer executeAndLog(ProcessBuilder pb, String logName) throws Exception {
 545         long started = System.currentTimeMillis();
 546         OutputAnalyzer output = new OutputAnalyzer(pb.start());


 547 
 548         writeFile(getOutputFile(logName + ".stdout"), output.getStdout());
 549         writeFile(getOutputFile(logName + ".stderr"), output.getStderr());
 550         System.out.println("[ELAPSED: " + (System.currentTimeMillis() - started) + " ms]");


 551         System.out.println("[STDERR]\n" + output.getStderr());
 552 
 553         if (CopyChildStdoutToMainStdout)
 554             System.out.println("[STDOUT]\n" + output.getStdout());
 555 
 556         return output;
 557     }
 558 
 559 
 560     private static void writeFile(File file, String content) throws Exception {
 561         FileOutputStream fos = new FileOutputStream(file);
 562         PrintStream ps = new PrintStream(fos);
 563         ps.print(content);
 564         ps.close();
 565         fos.close();
 566     }
 567 }


 178 
 179         public Result ifNoMappingFailure(Checker checker) throws Exception {
 180             checker.check(output);
 181             return this;
 182         }
 183 
 184 
 185         public Result assertNormalExit(String... matches) throws Exception {
 186             checkMatches(output, matches);
 187             output.shouldHaveExitValue(0);
 188             return this;
 189         }
 190 
 191         public Result assertAbnormalExit(String... matches) throws Exception {
 192             checkMatches(output, matches);
 193             output.shouldNotHaveExitValue(0);
 194             return this;
 195         }
 196     }
 197 
 198     // A number to be included in the filename of the stdout and the stderr output file.
 199     static int count = 0;
 200 
 201     private static int getNextCount() {
 202         return count++;
 203     }
 204 
 205     // By default, stdout of child processes are logged in files such as
 206     // <testname>-0000-exec.stdout. If you want to also include the stdout
 207     // inside jtr files, you can override this in the jtreg command line like
 208     // "jtreg -Dtest.cds.copy.child.stdout=true ...."
 209     public static final boolean copyChildStdoutToMainStdout =
 210         Boolean.getBoolean("test.cds.copy.child.stdout");
 211 
 212     // This property is passed to child test processes
 213     public static final String TestTimeoutFactor = System.getProperty("test.timeout.factor", "1.0");
 214 
 215     public static final String UnableToMapMsg =
 216         "Unable to map shared archive: test did not complete";
 217 
 218     // Create bootstrap CDS archive,
 219     // use extra JVM command line args as a prefix.
 220     // For CDS tests specifying prefix makes more sense than specifying suffix, since
 221     // normally there are no classes or arguments to classes, just "-version"
 222     // To specify suffix explicitly use CDSOptions.addSuffix()
 223     public static OutputAnalyzer createArchive(String... cliPrefix)
 224         throws Exception {
 225         return createArchive((new CDSOptions()).addPrefix(cliPrefix));
 226     }
 227 
 228     // Create bootstrap CDS archive
 229     public static OutputAnalyzer createArchive(CDSOptions opts)
 230         throws Exception {


 535         return new File(dir, getTestName() + "-" + name);
 536     }
 537 
 538 
 539     public static File getOutputSourceFile(String name) {
 540         File dir = new File(System.getProperty("test.classes", "."));
 541         return new File(dir, name);
 542     }
 543 
 544 
 545     public static File getSourceFile(String name) {
 546         File dir = new File(System.getProperty("test.src", "."));
 547         return new File(dir, name);
 548     }
 549 
 550 
 551     // ============================= Logging
 552     public static OutputAnalyzer executeAndLog(ProcessBuilder pb, String logName) throws Exception {
 553         long started = System.currentTimeMillis();
 554         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 555         String outputFileNamePrefix =
 556             getTestName() + "-" + String.format("%04d", getNextCount()) + "-" + logName;
 557 
 558         writeFile(getOutputFile(outputFileNamePrefix + ".stdout"), output.getStdout());
 559         writeFile(getOutputFile(outputFileNamePrefix + ".stderr"), output.getStderr());
 560         System.out.println("[ELAPSED: " + (System.currentTimeMillis() - started) + " ms]");
 561         System.out.println("[logging stdout to " + outputFileNamePrefix + ".stdout]");
 562         System.out.println("[logging stderr to " + outputFileNamePrefix + ".stderr]");
 563         System.out.println("[STDERR]\n" + output.getStderr());
 564 
 565         if (copyChildStdoutToMainStdout)
 566             System.out.println("[STDOUT]\n" + output.getStdout());
 567 
 568         return output;
 569     }
 570 
 571 
 572     private static void writeFile(File file, String content) throws Exception {
 573         FileOutputStream fos = new FileOutputStream(file);
 574         PrintStream ps = new PrintStream(fos);
 575         ps.print(content);
 576         ps.close();
 577         fos.close();
 578     }
 579 }
test/lib/jdk/test/lib/cds/CDSTestUtils.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File