< prev index next >

test/testlibrary_tests/ctw/CtwTest.java

Print this page
rev 12487 : 8172149: CTW library should call System::exit
Reviewed-by:

*** 19,28 **** --- 19,29 ---- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ + import java.util.Arrays; import java.util.List; import java.util.Collections; import java.util.ArrayList; import java.io.File;
*** 36,47 **** --- 37,60 ---- import java.nio.file.StandardCopyOption; import java.nio.charset.Charset; import jdk.test.lib.JDKToolFinder; import jdk.test.lib.process.OutputAnalyzer; + import jdk.test.lib.process.ProcessTools; public abstract class CtwTest { + private static final String LOG_FILE = "ctw.log"; + private static final String[] CTW_COMMAND = { + "-Xbootclasspath/a:.", + "-XX:+UnlockDiagnosticVMOptions", + "-XX:+WhiteBoxAPI", + "-Dsun.hotspot.tools.ctw.logfile=" + LOG_FILE, + "--add-exports", "java.base/jdk.internal.jimage=ALL-UNNAMED", + "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED", + "--add-exports", "java.base/jdk.internal.reflect=ALL-UNNAMED", + sun.hotspot.tools.ctw.CompileTheWorld.class.getName(), + }; protected final String[] shouldContain; protected CtwTest(String[] shouldContain) { this.shouldContain = shouldContain; }
*** 52,84 **** switch (args[0]) { case "prepare": prepare(); break; case "check": ! check(args); break; default: throw new Error("unregonized action -- " + args[0]); } } protected void prepare() throws Exception { } ! protected void check(String[] args) throws Exception { ! if (args.length < 2) { ! throw new Error("logfile isn't specified"); ! } ! String logfile = args[1]; ! try (BufferedReader r = Files.newBufferedReader(Paths.get(logfile), Charset.defaultCharset())) { OutputAnalyzer output = readOutput(r); for (String test : shouldContain) { output.shouldContain(test); } } } private static OutputAnalyzer readOutput(BufferedReader reader) throws IOException { StringBuilder builder = new StringBuilder(); String eol = String.format("%n"); String line; --- 65,107 ---- switch (args[0]) { case "prepare": prepare(); break; case "check": ! check(); ! break; ! case "compile": ! compile(args); break; default: throw new Error("unregonized action -- " + args[0]); } } protected void prepare() throws Exception { } ! protected void check() throws Exception { ! try (BufferedReader r = Files.newBufferedReader(Paths.get(LOG_FILE), Charset.defaultCharset())) { OutputAnalyzer output = readOutput(r); for (String test : shouldContain) { output.shouldContain(test); } } } + protected void compile(String[] args) throws Exception { + // concat CTW_COMMAND and args w/o 0th element + String[] cmd = Arrays.copyOf(CTW_COMMAND, CTW_COMMAND.length + args.length - 1); + System.arraycopy(args, 1, cmd, CTW_COMMAND.length, args.length - 1); + + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmd); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + dump(output, "compile"); + output.shouldHaveExitValue(0); + } + private static OutputAnalyzer readOutput(BufferedReader reader) throws IOException { StringBuilder builder = new StringBuilder(); String eol = String.format("%n"); String line;
< prev index next >