use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.
the class DynamicLauncher method run.
protected void run() throws Exception {
OutputAnalyzer out;
int retries = 1;
boolean tryAgain;
do {
tryAgain = false;
jmxPort = Utils.getFreePort();
out = runVM();
try {
out.shouldNotContain("Port already in use");
} catch (RuntimeException e) {
if (retries < 3) {
retries++;
tryAgain = true;
}
}
} while (tryAgain);
}
use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.
the class NativeErrors method executeCmd.
private static String executeCmd(String... toolArgs) throws Throwable {
JDKToolLauncher cmd = JDKToolLauncher.createUsingTestJDK("native2ascii");
for (String s : toolArgs) {
cmd.addToolArg(s);
}
OutputAnalyzer output = ProcessTools.executeProcess(cmd.getCommand());
if (output == null || output.getStdout() == null) {
throw new Exception("Output was null. Process did not finish correctly.");
}
if (output.getExitValue() == 0) {
throw new Exception("Process exit code was 0, but error was expected.");
}
return output.getStdout();
}
use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.
the class JpsBase method main.
public static void main(String[] args) throws Exception {
int pid = ProcessTools.getProcessId();
List<List<JpsHelper.JpsArg>> combinations = JpsHelper.JpsArg.generateCombinations();
for (List<JpsHelper.JpsArg> combination : combinations) {
OutputAnalyzer output = JpsHelper.jps(JpsHelper.JpsArg.asCmdArray(combination));
output.shouldHaveExitValue(0);
boolean isQuiet = false;
boolean isFull = false;
String pattern;
for (JpsHelper.JpsArg jpsArg : combination) {
switch(jpsArg) {
case q:
// If '-q' is specified output should contain only a list of local VM identifiers:
// 30673
isQuiet = true;
JpsHelper.verifyJpsOutput(output, "^\\d+$");
output.shouldContain(Integer.toString(pid));
break;
case l:
// If '-l' is specified output should contain the full package name for the application's main class
// or the full path name to the application's JAR file:
// 30673 /tmp/jtreg/jtreg-workdir/scratch/JpsBase.jar ...
isFull = true;
pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*";
output.shouldMatch(pattern);
break;
case m:
// 30673 JpsBase monkey ...
for (String arg : args) {
pattern = "^" + pid + ".*" + replaceSpecialChars(arg) + ".*";
output.shouldMatch(pattern);
}
break;
case v:
// 30673 JpsBase -Xmx512m -XX:+UseParallelGC -XX:Flags=/tmp/jtreg/jtreg-workdir/scratch/vmflags ...
for (String vmArg : JpsHelper.getVmArgs()) {
pattern = "^" + pid + ".*" + replaceSpecialChars(vmArg) + ".*";
output.shouldMatch(pattern);
}
break;
case V:
// If '-V' is specified output should contain VM flags:
// 30673 JpsBase +DisableExplicitGC ...
pattern = "^" + pid + ".*" + replaceSpecialChars(JpsHelper.VM_FLAG) + ".*";
output.shouldMatch(pattern);
break;
}
if (isQuiet) {
break;
}
}
if (!isQuiet) {
// Verify output line by line.
// Output should only contain lines with pids after the first line with pid.
JpsHelper.verifyJpsOutput(output, "^\\d+\\s+.*");
if (!isFull) {
pattern = "^" + pid + "\\s+" + replaceSpecialChars(shortProcessName);
if (combination.isEmpty()) {
// If no arguments are specified output should only contain
// pid and process name
pattern += "$";
} else {
pattern += ".*";
}
output.shouldMatch(pattern);
}
}
}
}
use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.
the class JpsHelper method jps.
/**
* Start jps utility with VM args and tool arguments
*/
public static OutputAnalyzer jps(List<String> vmArgs, List<String> toolArgs) throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jps");
if (vmArgs != null) {
for (String vmArg : vmArgs) {
launcher.addVMArg(vmArg);
}
}
if (toolArgs != null) {
for (String toolArg : toolArgs) {
launcher.addToolArg(toolArg);
}
}
ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
System.out.println(output.getOutput());
return output;
}
use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.
the class JstatdTest method runJps.
/**
* Depending on test settings command line can look like:
*
* jps -J-XX:+UsePerfData hostname
* jps -J-XX:+UsePerfData hostname:port
* jps -J-XX:+UsePerfData hostname/serverName
* jps -J-XX:+UsePerfData hostname:port/serverName
*/
private OutputAnalyzer runJps() throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jps");
launcher.addVMArg("-XX:+UsePerfData");
// Run jps with -v flag to obtain -Dparent.pid.<pid>
launcher.addToolArg("-v");
launcher.addToolArg(getDestination());
String[] cmd = launcher.getCommand();
log("Start jps", cmd);
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
System.out.println(output.getOutput());
return output;
}
Aggregations