Java Code Examples for jdk.test.lib.process.OutputAnalyzer#getExitValue()
The following examples show how to use
jdk.test.lib.process.OutputAnalyzer#getExitValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DtraceRunner.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static boolean dtraceAvailable() { String path = getDtracePath(); if (path == null) { return false; } // now we'll launch dtrace to trace itself just to be sure it works // and have all additional previleges set ProcessBuilder pbuilder = new ProcessBuilder(path, path); try { OutputAnalyzer oa = new OutputAnalyzer(pbuilder.start()); if (oa.getExitValue() != 0) { return false; } } catch (IOException e) { throw new Error("Couldn't launch dtrace", e); } return true; }
Example 2
Source File: CDSTestUtils.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static boolean isUnableToMap(OutputAnalyzer output) { String outStr = output.getOutput(); if ((output.getExitValue() == 1) && ( outStr.contains("Unable to reserve shared space at required address") || outStr.contains("Unable to map ReadOnly shared space at required address") || outStr.contains("Unable to map ReadWrite shared space at required address") || outStr.contains("Unable to map MiscData shared space at required address") || outStr.contains("Unable to map MiscCode shared space at required address") || outStr.contains("Unable to map OptionalData shared space at required address") || outStr.contains("Could not allocate metaspace at a compatible address") || outStr.contains("UseSharedSpaces: Unable to allocate region, range is not within java heap") )) { return true; } return false; }
Example 3
Source File: ExecuteOOMApp.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Executes OOM application with JFR recording and returns true if OOM error happened in the * test thread. Adds -XX:-UseGCOverheadLimit option to avoid "java.lang.OutOfMemoryError: GC overhead limit exceeded". * * @param settings JFR settings file * @param jfrFilename JFR resulting recording filename * @param additionalVmFlags additional VM flags passed to the java * @param bytesToAllocate number of bytes to allocate in new object every cycle in OOM application * @return true - OOM application is finished as expected,i.e. OOM happened in the test thead * false - OOM application is finished with OOM error which happened in the non test thread */ public static boolean execute(String settings, String jfrFilename, String[] additionalVmFlags, int bytesToAllocate) throws Exception { List<String> additionalVmFlagsList = new ArrayList<>(Arrays.asList(additionalVmFlags)); additionalVmFlagsList.add("-XX:-UseGCOverheadLimit"); OutputAnalyzer out = AppExecutorHelper.executeAndRecord(settings, jfrFilename, additionalVmFlagsList.toArray(new String[0]), OOMApp.class.getName(), String.valueOf(bytesToAllocate)); if ((out.getExitValue() == 1 && out.getOutput().contains("Exception: java.lang.OutOfMemoryError"))) { return false; } out.shouldHaveExitValue(0); System.out.println(out.getOutput()); return true; }
Example 4
Source File: CDSTestUtils.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static boolean isUnableToMap(OutputAnalyzer output) { String outStr = output.getOutput(); if ((output.getExitValue() == 1) && ( outStr.contains("Unable to reserve shared space at required address") || outStr.contains("Unable to map ReadOnly shared space at required address") || outStr.contains("Unable to map ReadWrite shared space at required address") || outStr.contains("Unable to map MiscData shared space at required address") || outStr.contains("Unable to map MiscCode shared space at required address") || outStr.contains("Unable to map OptionalData shared space at required address") || outStr.contains("Could not allocate metaspace at a compatible address") || outStr.contains("UseSharedSpaces: Unable to allocate region, range is not within java heap") )) { return true; } return false; }
Example 5
Source File: CDSTestUtils.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static boolean isUnableToMap(OutputAnalyzer output) { String outStr = output.getOutput(); if ((output.getExitValue() == 1) && ( outStr.contains("Unable to reserve shared space at required address") || outStr.contains("Unable to map ReadOnly shared space at required address") || outStr.contains("Unable to map ReadWrite shared space at required address") || outStr.contains("Unable to map MiscData shared space at required address") || outStr.contains("Unable to map MiscCode shared space at required address") || outStr.contains("Unable to map shared string space at required address") || outStr.contains("Could not allocate metaspace at a compatible address") || outStr.contains("Unable to allocate shared string space: range is not within java heap") )) { return true; } return false; }
Example 6
Source File: ExecuteOOMApp.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Executes OOM application with JFR recording and returns true if OOM error happened in the * test thread. Adds -XX:-UseGCOverheadLimit option to avoid "java.lang.OutOfMemoryError: GC overhead limit exceeded". * * @param settings JFR settings file * @param jfrFilename JFR resulting recording filename * @param additionalVmFlags additional VM flags passed to the java * @param bytesToAllocate number of bytes to allocate in new object every cycle in OOM application * @return true - OOM application is finished as expected,i.e. OOM happened in the test thead * false - OOM application is finished with OOM error which happened in the non test thread */ public static boolean execute(String settings, String jfrFilename, String[] additionalVmFlags, int bytesToAllocate) throws Exception { List<String> additionalVmFlagsList = new ArrayList<>(Arrays.asList(additionalVmFlags)); additionalVmFlagsList.add("-XX:-UseGCOverheadLimit"); OutputAnalyzer out = AppExecutorHelper.executeAndRecord(settings, jfrFilename, additionalVmFlagsList.toArray(new String[0]), OOMApp.class.getName(), String.valueOf(bytesToAllocate)); if ((out.getExitValue() == 1 && out.getOutput().contains("Exception: java.lang.OutOfMemoryError"))) { return false; } out.shouldHaveExitValue(0); System.out.println(out.getOutput()); return true; }
Example 7
Source File: PLABUtils.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Common check for test PLAB application's results. * @param out OutputAnalyzer for checking * @throws RuntimeException */ public static void commonCheck(OutputAnalyzer out) throws RuntimeException { if (out.getExitValue() != 0) { System.out.println(out.getOutput()); throw new RuntimeException("Exit code is not 0"); } // Test expects only WhiteBox initiated GC. out.shouldNotContain("Pause Young (G1 Evacuation Pause)"); }
Example 8
Source File: ListOptionNotExistingTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { OutputAnalyzer oa = JaotcTestHelper.compileLibrary("--compile-commands", "./notExisting.list", "--class-name", COMPILE_ITEM); int exitCode = oa.getExitValue(); Asserts.assertNE(exitCode, 0, "Unexpected compilation exit code"); File compiledLibrary = new File(JaotcTestHelper.DEFAULT_LIB_PATH); Asserts.assertFalse(compiledLibrary.exists(), "Compiler library unexpectedly exists"); }
Example 9
Source File: CiReplayBase.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public int startTest(String... additionalVmOpts) { try { List<String> allAdditionalOpts = new ArrayList<>(); allAdditionalOpts.addAll(Arrays.asList(REPLAY_OPTIONS)); allAdditionalOpts.addAll(Arrays.asList(additionalVmOpts)); OutputAnalyzer oa = ProcessTools.executeProcess(getTestJavaCommandlineWithPrefix( RUN_SHELL_ZERO_LIMIT, allAdditionalOpts.toArray(new String[0]))); return oa.getExitValue(); } catch (Throwable t) { throw new Error("Can't run replay process: " + t, t); } }
Example 10
Source File: ExitOnThrow.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { if (args.length == 0) { String[] cmd = JDKToolLauncher.createUsingTestJDK("java") .addToolArg("-cp") .addToolArg(cp) .addToolArg("ExitOnThrow") .addToolArg("-executeCleaner") .getCommand(); ProcessBuilder pb = new ProcessBuilder(cmd); OutputAnalyzer out = ProcessTools.executeProcess(pb); System.out.println("======================"); System.out.println(Arrays.toString(cmd)); String msg = " stdout: [" + out.getStdout() + "]\n" + " stderr: [" + out.getStderr() + "]\n" + " exitValue = " + out.getExitValue() + "\n"; System.out.println(msg); if (out.getExitValue() != 1) throw new RuntimeException("Unexpected exit code: " + out.getExitValue()); } else { Cleaner.create(new Object(), () -> { throw new RuntimeException("Foo!"); } ); while (true) { System.gc(); Thread.sleep(100); } } }
Example 11
Source File: ToolRunner.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Starts the process, waits for the process completion and returns the * results * * @return process results * @throws Exception if anything goes wrong */ ToolResults runToCompletion() throws Exception { ProcessBuilder pb = new ProcessBuilder(cmdArgs); OutputAnalyzer oa = ProcessTools.executeProcess(pb); return new ToolResults(oa.getExitValue(), stringToList(oa.getStdout()), stringToList(oa.getStderr())); }
Example 12
Source File: TestIHOPErgo.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static OutputAnalyzer executeTest(List<String> options) throws Throwable, RuntimeException { OutputAnalyzer out; out = ProcessTools.executeTestJvm(options.toArray(new String[options.size()])); if (out.getExitValue() != 0) { System.out.println(out.getOutput()); throw new RuntimeException("AppIHOP failed with exit code" + out.getExitValue()); } return out; }
Example 13
Source File: TestG1LoggingFailure.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void startVM(List<String> options) throws Throwable, RuntimeException { OutputAnalyzer out = ProcessTools.executeTestJvm(options.toArray(new String[options.size()])); out.shouldNotContain("pure virtual method called"); if (out.getExitValue() == 0) { System.out.println(out.getOutput()); throw new RuntimeException("Expects Alloc failure."); } }
Example 14
Source File: TestShutdownEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void runSubtest(int subTestIndex) throws Exception { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-XX:+LogJFR", "-XX:-CreateMinidumpOnCrash", "-XX:StartFlightRecording=filename=./dumped.jfr,dumponexit=true,settings=default", "jdk.jfr.event.runtime.TestShutdownEvent$TestMain", String.valueOf(subTestIndex)); OutputAnalyzer output = ProcessTools.executeProcess(pb); System.out.println(output.getOutput()); int exitCode = output.getExitValue(); System.out.println("Exit code: " + exitCode); String recordingName = output.firstMatch("emergency jfr file: (.*.jfr)", 1); if (recordingName == null) { recordingName = "./dumped.jfr"; } List<RecordedEvent> events = RecordingFile.readAllEvents(Paths.get(recordingName)); List<RecordedEvent> filteredEvents = events.stream() .filter(e -> e.getEventType().getName().equals(EventNames.Shutdown)) .sorted(Comparator.comparing(RecordedEvent::getStartTime)) .collect(Collectors.toList()); Asserts.assertEquals(filteredEvents.size(), 1); RecordedEvent event = filteredEvents.get(0); subTests[subTestIndex].verifyEvents(event, exitCode); }
Example 15
Source File: TestShutdownEvent.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void runSubtest(int subTestIndex) throws Exception { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-XX:+LogJFR", "-XX:-CreateMinidumpOnCrash", "-XX:StartFlightRecording=filename=./dumped.jfr,dumponexit=true,settings=default", "jdk.jfr.event.runtime.TestShutdownEvent$TestMain", String.valueOf(subTestIndex)); OutputAnalyzer output = ProcessTools.executeProcess(pb); System.out.println(output.getOutput()); int exitCode = output.getExitValue(); System.out.println("Exit code: " + exitCode); String recordingName = output.firstMatch("emergency jfr file: (.*.jfr)", 1); if (recordingName == null) { recordingName = "./dumped.jfr"; } List<RecordedEvent> events = RecordingFile.readAllEvents(Paths.get(recordingName)); List<RecordedEvent> filteredEvents = events.stream() .filter(e -> e.getEventType().getName().equals(EventNames.Shutdown)) .sorted(Comparator.comparing(RecordedEvent::getStartTime)) .collect(Collectors.toList()); Asserts.assertEquals(filteredEvents.size(), 1); RecordedEvent event = filteredEvents.get(0); subTests[subTestIndex].verifyEvents(event, exitCode); }
Example 16
Source File: TLSRestrictions.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
static void testConstraint(String[] trustNames, String[] certNames, String serverConstraint, String clientConstraint, boolean needClientAuth, boolean pass) throws Exception { String trustNameStr = trustNames == null ? "" : String.join(DELIMITER, trustNames); String certNameStr = certNames == null ? "" : String.join(DELIMITER, certNames); System.out.printf("Case:%n" + " trustNames=%s; certNames=%s%n" + " serverConstraint=%s; clientConstraint=%s%n" + " needClientAuth=%s%n" + " pass=%s%n%n", trustNameStr, certNameStr, serverConstraint, clientConstraint, needClientAuth, pass); JSSEServer server = new JSSEServer( createSSLContext(trustNames, certNames), serverConstraint, needClientAuth); int port = server.getPort(); server.start(); // Run client on another JVM so that its properties cannot be in conflict // with server's. OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm( "-Dcert.dir=" + CERT_DIR, "-Djava.security.debug=certpath", "-classpath", TEST_CLASSES, "JSSEClient", port + "", trustNameStr, certNameStr, clientConstraint); int exitValue = outputAnalyzer.getExitValue(); String clientOut = outputAnalyzer.getOutput(); Exception serverException = server.getException(); if (serverException != null) { System.out.println("Server: failed"); } System.out.println("---------- Client output start ----------"); System.out.println(clientOut); System.out.println("---------- Client output end ----------"); if (serverException instanceof SocketTimeoutException || clientOut.contains("SocketTimeoutException")) { System.out.println("The communication gets timeout and skips the test."); return; } if (pass) { if (serverException != null || exitValue != 0) { throw new RuntimeException( "Unexpected failure. Operation was blocked."); } } else { if (serverException == null && exitValue == 0) { throw new RuntimeException( "Unexpected pass. Operation was allowed."); } // The test may encounter non-SSL issues, like network problem. if (!(serverException instanceof SSLHandshakeException || clientOut.contains("SSLHandshakeException"))) { throw new RuntimeException("Failure with unexpected exception."); } } }
Example 17
Source File: AcceptCauseFileDescriptorLeak.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { if (args.length != 0) { OutputAnalyzer analyzer = execCmd("ulimit -n -H"); String output = analyzer.getOutput(); if (output == null || output.length() == 0) { throw new RuntimeException("\"ulimit -n -H\" output nothing" + " and its exit code is " + analyzer.getExitValue()); } else { output = output.trim(); // Set max open file descriptors to 1024 // if it is unlimited or greater than 1024, // otherwise just do test directly if ("unlimited".equals(output) || Integer.valueOf(output) > THRESHOLD) { analyzer = execCmd("ulimit -n " + THRESHOLD + "; " + composeJavaTestStr()); System.out.println("Output: [" + analyzer.getOutput() + "]"); int rc = analyzer.getExitValue(); if (rc != 0) { throw new RuntimeException( "Unexpected exit code: " + rc); } return; } } } final ServerSocket ss = new ServerSocket(0) { public Socket accept() throws IOException { Socket s = new Socket() { }; s.setSoTimeout(10000); implAccept(s); return s; } }; Thread t = new Thread(new Runnable() { public void run() { try { for (int i = 0; i < REPS; i++) { (new Socket("localhost", ss.getLocalPort())).close(); } } catch (IOException e) { e.printStackTrace(); } } }); t.start(); try { for (int i = 0; i < REPS; i++) { ss.accept().close(); } } finally { ss.close(); } t.join(); }
Example 18
Source File: TooSmallStackSize.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
static String checkStack(String stackOption, String optionMesg, String stackSize) throws Exception { String min_stack_allowed; System.out.println("*** Testing " + stackOption + stackSize); ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( stackOption + stackSize, // Uncomment the following to get log output // that shows actual thread creation sizes. // "-Xlog:os+thread", "-version"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); if (verbose) { System.out.println("stdout: " + output.getStdout()); } if (output.getExitValue() == 0) { // checkMinStackAllowed() is called with stackSize values // that should be the minimum that works. This method, // checkStack(), is called with stackSize values that // should be too small and result in error messages. // However, some platforms fix up a stackSize value that is // too small into something that works so we have to allow // for checkStack() calls that work. System.out.println("PASSED: got exit_code == 0 with " + stackOption + stackSize); min_stack_allowed = stackSize; } else { String expect = "The " + optionMesg + " specified is too small"; if (verbose) { System.out.println("Expect='" + expect + "'"); } output.shouldContain(expect); min_stack_allowed = getMinStackAllowed(output.getStdout()); System.out.println("PASSED: got expected error message with " + stackOption + stackSize); } return min_stack_allowed; }
Example 19
Source File: TestCrashOnOutOfMemoryError.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { if (args.length == 1) { // This should guarantee to throw: // java.lang.OutOfMemoryError: Requested array size exceeds VM limit try { Object[] oa = new Object[Integer.MAX_VALUE]; throw new Error("OOME not triggered"); } catch (OutOfMemoryError err) { throw new Error("OOME didn't abort JVM!"); } } // else this is the main test ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+CrashOnOutOfMemoryError", "-XX:-CreateCoredumpOnCrash", "-Xmx64m", TestCrashOnOutOfMemoryError.class.getName(),"throwOOME"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); int exitValue = output.getExitValue(); if (0 == exitValue) { //expecting a non zero value throw new Error("Expected to get non zero exit value"); } /* Output should look something like this. The actual text will depend on the OS and its core dump processing. Aborting due to java.lang.OutOfMemoryError: Requested array size exceeds VM limit # To suppress the following error report, specify this argument # after -XX: or in .hotspotrc: SuppressErrorAt=/debug.cpp:303 # # A fatal error has been detected by the Java Runtime Environment: # # Internal Error (/home/cheleswer/Desktop/jdk9/dev/hotspot/src/share/vm/utilities/debug.cpp:303), pid=6212, tid=6213 # fatal error: OutOfMemory encountered: Requested array size exceeds VM limit # # JRE version: OpenJDK Runtime Environment (9.0) (build 1.9.0-internal-debug-cheleswer_2015_10_20_14_32-b00) # Java VM: OpenJDK 64-Bit Server VM (1.9.0-internal-debug-cheleswer_2015_10_20_14_32-b00, mixed mode, tiered, compressed oops, serial gc, linux-amd64) # Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %P" (or dumping to /home/cheleswer/Desktop/core.6212) # # An error report file with more information is saved as: # /home/cheleswer/Desktop/hs_err_pid6212.log # # If you would like to submit a bug report, please visit: # http://bugreport.java.com/bugreport/crash.jsp # Current thread is 6213 Dumping core ... Aborted (core dumped) */ output.shouldContain("Aborting due to java.lang.OutOfMemoryError: Requested array size exceeds VM limit"); // extract hs-err file String hs_err_file = output.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1); if (hs_err_file == null) { throw new Error("Did not find hs-err file in output.\n"); } /* * Check if hs_err files exist or not */ File f = new File(hs_err_file); if (!f.exists()) { throw new Error("hs-err file missing at "+ f.getAbsolutePath() + ".\n"); } /* * Checking the completness of hs_err file. If last line of hs_err file is "END" * then it proves that file is complete. */ try (FileInputStream fis = new FileInputStream(f); BufferedReader br = new BufferedReader(new InputStreamReader(fis))) { String line = null; String lastLine = null; while ((line = br.readLine()) != null) { lastLine = line; } if (!lastLine.equals("END.")) { throw new Error("hs-err file incomplete (missing END marker.)"); } else { System.out.println("End marker found."); } } System.out.println("PASSED"); }
Example 20
Source File: DeadlockDetectionTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { System.out.println("Starting DeadlockDetectionTest"); if (!Platform.shouldSAAttach()) { // Silently skip the test if we don't have enough permissions to attach // Not all conditions checked by function is relevant to SA but it's worth // to check System.err.println("Error! Insufficient permissions to attach."); return; } if (Platform.isOSX()) { // Coredump stackwalking is not implemented for Darwin System.out.println("This test is not expected to work on OS X. Skipping"); return; } if (!LingeredApp.isLastModifiedWorking()) { // Exact behaviour of the test depends on operating system and the test nature, // so just print the warning and continue System.err.println("Warning! Last modified time doesn't work."); } try { List<String> vmArgs = new ArrayList<String>(); vmArgs.add("-XX:+UsePerfData"); vmArgs.addAll(Utils.getVmOptions()); theApp = new LingeredAppWithDeadlock(); LingeredApp.startApp(vmArgs, theApp); OutputAnalyzer output = jstack("--pid", Long.toString(theApp.getPid())); System.out.println(output.getOutput()); if (output.getExitValue() == 3) { System.out.println("Test can't run for some reason. Skipping"); } else { output.shouldHaveExitValue(0); output.shouldContain("Found a total of 1 deadlock."); } } finally { LingeredApp.stopApp(theApp); } }