test/testlibrary/jdk/test/lib/ProcessTools.java
Print this page
@@ -37,11 +37,11 @@
}
/**
* Pumps stdout and stderr from running the process into a String.
*
- * @param processHandler ProcessHandler to run.
+ * @param processBuilder ProcessBuilder to run.
* @return Output from process.
* @throws IOException If an I/O error occurs.
*/
public static OutputBuffer getOutput(ProcessBuilder processBuilder) throws IOException {
return getOutput(processBuilder.start());
@@ -107,10 +107,21 @@
return result.toString();
}
/**
+ * Gets the array of strings containing input arguments passed to the VM
+ *
+ * @return arguments
+ */
+ public static String[] getVmInputArgs() {
+ RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
+ List<String> args = runtime.getInputArguments();
+ return args.toArray(new String[args.size()]);
+ }
+
+ /**
* Get platform specific VM arguments (e.g. -d64 on 64bit Solaris)
*
* @return String[] with platform specific arguments, empty if there are none
*/
public static String[] getPlatformSpecificVMArgs() {
@@ -171,10 +182,30 @@
ProcessBuilder pb = createJavaProcessBuilder(Utils.addTestJavaOpts(cmds));
return executeProcess(pb);
}
/**
+ * Executes a test jvm process, waits for it to finish and returns the process output.
+ * The default jvm options from the test, jtreg, test.vm.opts and test.java.opts, are added.
+ * The java from the test.jdk is used to execute the command.
+ *
+ * The command line will be like:
+ * {test.jdk}/bin/java {test.vm.opts} {test.java.opts} cmds
+ *
+ * @param cmds User specifed arguments.
+ * @return The output from the process.
+ */
+ public static OutputAnalyzer executeTestJvmAllArgs(String... cmds) throws Throwable {
+ List<String> argsList = new ArrayList<>();
+ String[] testArgs = getVmInputArgs();
+ Collections.addAll(argsList, testArgs);
+ Collections.addAll(argsList, Utils.addTestJavaOpts(cmds));
+ ProcessBuilder pb = createJavaProcessBuilder(argsList.toArray(new String[argsList.size()]));
+ return executeProcess(pb);
+ }
+
+ /**
* Executes a process, waits for it to finish and returns the process output.
* The process will have exited before this method returns.
* @param pb The ProcessBuilder to execute.
* @return The {@linkplain OutputAnalyzer} instance wrapping the process.
*/