Java Code Examples for jdk.test.lib.process.OutputAnalyzer#getOutput()
The following examples show how to use
jdk.test.lib.process.OutputAnalyzer#getOutput() .
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: 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 2
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 3
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 4
Source File: IhopUtils.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Checks that GC log contains expected ergonomic messages * @param outputAnalyzer OutputAnalyer with GC log for checking * @throws RuntimeException If no IHOP ergo messages were not found */ public static void checkErgoMessagesExist(OutputAnalyzer outputAnalyzer) { String output = outputAnalyzer.getOutput(); if (!(output.contains(CYCLE_INITIATION_MESSAGE) | output.contains(CYCLE_INITIATION_MESSAGE_FALSE))) { throw new RuntimeException("Cannot find expected IHOP ergonomics messages"); } }
Example 5
Source File: TestTargetSurvivorRatioFlag.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Verify that actual survivor space usage ratio conforms specified TargetSurvivorRatio * * @param ratio value of TargetSurvivorRatio * @param options additional VM options */ public static void positiveTest(int ratio, LinkedList<String> options) throws Exception { LinkedList<String> vmOptions = new LinkedList<>(options); Collections.addAll(vmOptions, "-Xbootclasspath/a:.", "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED", "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", "-XX:+UseAdaptiveSizePolicy", "-Xlog:gc+age=trace", "-XX:MaxTenuringThreshold=" + MAX_TENURING_THRESHOLD, "-XX:NewSize=" + MAX_NEW_SIZE, "-XX:MaxNewSize=" + MAX_NEW_SIZE, "-XX:InitialHeapSize=" + 2 * MAX_NEW_SIZE, "-XX:MaxHeapSize=" + 2 * MAX_NEW_SIZE, "-XX:SurvivorRatio=" + SURVIVOR_RATIO, "-XX:TargetSurvivorRatio=" + ratio, // For reducing variance of survivor size. "-XX:TargetPLABWastePct=" + 1, TargetSurvivorRatioVerifier.class.getName(), Integer.toString(ratio) ); ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[vmOptions.size()])); OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start()); analyzer.shouldHaveExitValue(0); String output = analyzer.getOutput(); // Test avoids verification for parallel GC if (!output.contains(UNSUPPORTED_GC)) { // Two tests should be done - when actual ratio is lower than TargetSurvivorRatio // and when it is higher. We chech that output contains results for exactly two tests. List<Double> ratios = parseTestOutput(output); if (ratios.size() != 2) { System.out.println(output); throw new RuntimeException("Expected number of ratios extraced for output is 2," + " but " + ratios.size() + " ratios were extracted"); } // At the end of the first test survivor space usage ratio should lies between // TargetSurvivorRatio and TargetSurvivorRatio - 2*DELTA if (ratio < ratios.get(0) || ratio - ratios.get(0) > VARIANCE) { System.out.println(output); throw new RuntimeException("Survivor space usage ratio expected to be close to " + ratio + ", but observed ratio is: " + ratios.get(0)); } // After second test survivor space should be almost empty. if (ratios.get(1) > VARIANCE) { System.out.println(output); throw new RuntimeException("Survivor space expected to be empty due to " + "TargetSurvivorRatio overlimit, however observed " + "survivor space usage ratio is: " + ratios.get(1)); } } else { System.out.println("Selected GC does not support TargetSurvivorRatio option."); } }
Example 6
Source File: SummarySanityCheck.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String args[]) throws Exception { // Grab my own PID String pid = Long.toString(ProcessTools.getProcessId()); ProcessBuilder pb = new ProcessBuilder(); // Run 'jcmd <pid> VM.native_memory summary scale=KB' pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary", "scale=KB"}); OutputAnalyzer output = new OutputAnalyzer(pb.start()); jcmdout = output.getOutput(); // Split by '-' to get the 'groups' String[] lines = jcmdout.split("\n"); if (lines.length == 0) { throwTestException("Failed to parse jcmd output"); } int totalCommitted = 0, totalReserved = 0; int totalCommittedSum = 0, totalReservedSum = 0; // Match '- <mtType> (reserved=<reserved>KB, committed=<committed>KB) Pattern mtTypePattern = Pattern.compile("-\\s+(?<typename>[\\w\\s]+)\\(reserved=(?<reserved>\\d+)KB,\\scommitted=(?<committed>\\d+)KB\\)"); // Match 'Total: reserved=<reserved>KB, committed=<committed>KB' Pattern totalMemoryPattern = Pattern.compile("Total\\:\\sreserved=(?<reserved>\\d+)KB,\\scommitted=(?<committed>\\d+)KB"); for (int i = 0; i < lines.length; i++) { if (lines[i].startsWith("Total")) { Matcher totalMemoryMatcher = totalMemoryPattern.matcher(lines[i]); if (totalMemoryMatcher.matches()) { totalCommitted = Integer.parseInt(totalMemoryMatcher.group("committed")); totalReserved = Integer.parseInt(totalMemoryMatcher.group("reserved")); } else { throwTestException("Failed to match the expected groups in 'Total' memory part"); } } else if (lines[i].startsWith("-")) { Matcher typeMatcher = mtTypePattern.matcher(lines[i]); if (typeMatcher.matches()) { int typeCommitted = Integer.parseInt(typeMatcher.group("committed")); int typeReserved = Integer.parseInt(typeMatcher.group("reserved")); // Make sure reserved is always less or equals if (typeCommitted > typeReserved) { throwTestException("Committed (" + typeCommitted + ") was more than Reserved (" + typeReserved + ") for mtType: " + typeMatcher.group("typename")); } // Add to total and compare them in the end totalCommittedSum += typeCommitted; totalReservedSum += typeReserved; } else { throwTestException("Failed to match the group on line " + i); } } } // See if they add up correctly, rounding is a problem so make sure we're within +/- 8KB int committedDiff = totalCommitted - totalCommittedSum; if (committedDiff > 8 || committedDiff < -8) { throwTestException("Total committed (" + totalCommitted + ") did not match the summarized committed (" + totalCommittedSum + ")" ); } int reservedDiff = totalReserved - totalReservedSum; if (reservedDiff > 8 || reservedDiff < -8) { throwTestException("Total reserved (" + totalReserved + ") did not match the summarized reserved (" + totalReservedSum + ")" ); } }
Example 7
Source File: CiReplayBase.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public boolean generateReplay(boolean needCoreDump, String... vmopts) { OutputAnalyzer crashOut; String crashOutputString; try { List<String> options = new ArrayList<>(); options.addAll(Arrays.asList(REPLAY_GENERATION_OPTIONS)); options.addAll(Arrays.asList(vmopts)); options.add(needCoreDump ? ENABLE_COREDUMP_ON_CRASH : DISABLE_COREDUMP_ON_CRASH); options.add(VERSION_OPTION); if (needCoreDump) { crashOut = ProcessTools.executeProcess(getTestJavaCommandlineWithPrefix( RUN_SHELL_NO_LIMIT, options.toArray(new String[0]))); } else { crashOut = ProcessTools.executeProcess(ProcessTools.createJavaProcessBuilder(true, options.toArray(new String[0]))); } crashOutputString = crashOut.getOutput(); Asserts.assertNotEquals(crashOut.getExitValue(), 0, "Crash JVM exits gracefully"); Files.write(Paths.get("crash.out"), crashOutputString.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); } catch (Throwable t) { throw new Error("Can't create replay: " + t, t); } if (needCoreDump) { String coreFileLocation = getCoreFileLocation(crashOutputString); if (coreFileLocation == null) { if (Platform.isOSX()) { File coresDir = new File("/cores"); if (!coresDir.isDirectory() || !coresDir.canWrite()) { return false; } } throw new Error("Couldn't find core file location in: '" + crashOutputString + "'"); } try { Asserts.assertGT(new File(coreFileLocation).length(), 0L, "Unexpected core size"); Files.move(Paths.get(coreFileLocation), Paths.get(TEST_CORE_FILE_NAME)); } catch (IOException ioe) { throw new Error("Can't move core file: " + ioe, ioe); } } removeFromCurrentDirectoryStartingWith(HS_ERR_NAME); return true; }
Example 8
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 9
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."); } } }