/** * Used to log command line, stdout, stderr and exit code from an executed process. * * @param pb The executed process. * @param output The output from the process. */ public static String getProcessLog(ProcessBuilder pb, OutputAnalyzer output) { String stderr = output == null ? "null" : output.getStderr(); String stdout = output == null ? "null" : output.getStdout(); String exitValue = output == null ? "null" : Integer.toString(output.getExitValue()); StringBuilder logMsg = new StringBuilder(); final String nl = System.getProperty("line.separator"); logMsg.append("--- ProcessLog ---" + nl); logMsg.append("cmd: " + getCommandLine(pb) + nl); logMsg.append("exitvalue: " + exitValue + nl); logMsg.append("stderr: " + stderr + nl); logMsg.append("stdout: " + stdout + nl); return logMsg.toString(); }
public static void main(String args[]) throws Exception { if (!Platform.is64bit()) { System.out.println( "ReadFromNoaccessArea tests is useful only on 64bit architecture. Passing silently."); return; } ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( "-Xbootclasspath/a:.", "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", "-XX:+UseCompressedOops", "-XX:HeapBaseMinAddress=33G", "-XX:-CreateCoredumpOnCrash", "-Xmx32m", DummyClassWithMainTryingToReadFromNoaccessArea.class.getName()); OutputAnalyzer output = new OutputAnalyzer(pb.start()); System.out.println("******* Printing stdout for analysis in case of failure *******"); System.out.println(output.getStdout()); System.out.println("******* Printing stderr for analysis in case of failure *******"); System.out.println(output.getStderr()); System.out.println("***************************************************************"); if (output.getStdout() != null && output.getStdout().contains("WB_ReadFromNoaccessArea method is useless")) { // Test conditions broken. There is no protected page in ReservedHeapSpace in these // circumstances. Silently passing test. return; } if (Platform.isWindows()) { output.shouldContain("EXCEPTION_ACCESS_VIOLATION"); } else if (Platform.isOSX()) { output.shouldContain("SIGBUS"); } else { output.shouldContain("SIGSEGV"); } }