Java Code Examples for jdk.test.lib.process.OutputAnalyzer#asLines()
The following examples show how to use
jdk.test.lib.process.OutputAnalyzer#asLines() .
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: PrintDirectivesProcessor.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private List<String> getDirectives(OutputAnalyzer outputAnalyzer) { List<String> directives = new ArrayList<>(); List<String> inputStrings = outputAnalyzer.asLines(); Iterator<String> iterator = inputStrings.iterator(); while (iterator.hasNext()) { String input = iterator.next(); if (input.equals("Directive:")) { Asserts.assertTrue(iterator.hasNext(), "inconsistent directive" + "printed into the output"); String matchString = iterator.next(); Matcher matcher = MATCH_PATTERN.matcher(matchString); Asserts.assertTrue(matcher.matches(), "Incorrect matching " + "string in directive"); directives.add(matcher.group(1)); } } return directives; }
Example 2
Source File: TestInstanceKlassSizeForInterface.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static String getJcmdInstanceKlassSize(OutputAnalyzer output, String instanceKlassName) { for (String s : output.asLines()) { if (s.contains(instanceKlassName)) { String tokens[]; System.out.println(s); tokens = s.split("\\s+"); return tokens[3]; } } return null; }
Example 3
Source File: TestInstanceKlassSize.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static String getJcmdInstanceKlassSize(OutputAnalyzer output, String instanceKlassName) { for (String s : output.asLines()) { if (s.contains(instanceKlassName)) { String tokens[]; System.out.println(s); tokens = s.split("\\s+"); return tokens[3]; } } return null; }
Example 4
Source File: TestDriver.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private List<String> executeApplication() throws Throwable { OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvmAllArgs( "-Xbatch", "-XX:-TieredCompilation", "-XX:+PrintCompilation", "-XX:+TraceNewVectors", TestIntVect.class.getName()); outputAnalyzer.shouldHaveExitValue(0); return outputAnalyzer.asLines(); }
Example 5
Source File: PrintProcessor.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public void accept(OutputAnalyzer outputAnalyzer) { boolean wizardMode = false; try { wizardMode = Boolean.parseBoolean(ManagementFactory .getPlatformMXBean(HotSpotDiagnosticMXBean.class) .getVMOption("WizardMode").getValue()); } catch (IllegalArgumentException e) { // ignore exception because WizardMode exists in debug only builds } if (wizardMode) { System.out.println("SKIP: WizardMode's output are not supported"); return; } for (String line : outputAnalyzer.asLines()) { Matcher matcher = COMPILED_METHOD.matcher(line); if (matcher.matches()) { String method = normalize(matcher.group("name")); if (!printMethods.contains(normalize(method)) && testMethods.contains(method)) { System.out.println(outputAnalyzer.getOutput()); throw new AssertionError("FAILED: wrong method " + "was printed: " + method + " LINE: " + line); } } } }
Example 6
Source File: TestInstanceKlassSizeForInterface.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static void createAnotherToAttach( String[] instanceKlassNames, int lingeredAppPid) throws Exception { String[] toolArgs = { "--add-modules=jdk.hotspot.agent", "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED", "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED", "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED", "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.debugger=ALL-UNNAMED", "TestInstanceKlassSizeForInterface", Integer.toString(lingeredAppPid) }; // Start a new process to attach to the LingeredApp process ProcessBuilder processBuilder = ProcessTools .createJavaProcessBuilder(toolArgs); OutputAnalyzer SAOutput = ProcessTools.executeProcess(processBuilder); SAOutput.shouldHaveExitValue(0); System.out.println(SAOutput.getOutput()); // Run jcmd on the LingeredApp process ProcessBuilder pb = new ProcessBuilder(); pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), Long.toString(lingeredAppPid), "GC.class_stats", "VTab,ITab,OopMap,KlassBytes" } ); OutputAnalyzer jcmdOutput = new OutputAnalyzer(pb.start()); System.out.println(jcmdOutput.getOutput()); // Match the sizes from both the output streams for (String instanceKlassName : instanceKlassNames) { System.out.println ("Trying to match for " + instanceKlassName); String jcmdInstanceKlassSize = getJcmdInstanceKlassSize( jcmdOutput, instanceKlassName); Asserts.assertNotNull(jcmdInstanceKlassSize, "Could not get the instance klass size from the jcmd output"); for (String s : SAOutput.asLines()) { if (s.contains(instanceKlassName)) { Asserts.assertTrue( s.contains(jcmdInstanceKlassSize), "The size computed by SA for " + instanceKlassName + " does not match."); } } } }
Example 7
Source File: TestInstanceKlassSize.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static void startMeWithArgs() throws Exception { LingeredApp app = null; OutputAnalyzer output = null; try { List<String> vmArgs = new ArrayList<String>(); vmArgs.add("-XX:+UsePerfData"); vmArgs.addAll(Utils.getVmOptions()); app = LingeredApp.startApp(vmArgs); System.out.println ("Started LingeredApp with pid " + app.getPid()); } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex); } try { String[] instanceKlassNames = new String[] { " java.lang.Object", " java.util.Vector", " sun.util.PreHashedMap", " java.lang.String", " java.lang.Thread", " java.lang.Byte", }; String[] toolArgs = { "--add-modules=jdk.hotspot.agent", "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED", "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED", "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED", "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.debugger=ALL-UNNAMED", "TestInstanceKlassSize", Long.toString(app.getPid()) }; OutputAnalyzer jcmdOutput = jcmd( app.getPid(), "GC.class_stats", "VTab,ITab,OopMap,KlassBytes"); ProcessBuilder processBuilder = ProcessTools .createJavaProcessBuilder(toolArgs); output = ProcessTools.executeProcess(processBuilder); System.out.println(output.getOutput()); output.shouldHaveExitValue(0); // Check whether the size matches that which jcmd outputs for (String instanceKlassName : instanceKlassNames) { System.out.println ("Trying to match for" + instanceKlassName); String jcmdInstanceKlassSize = getJcmdInstanceKlassSize( jcmdOutput, instanceKlassName); Asserts.assertNotNull(jcmdInstanceKlassSize, "Could not get the instance klass size from the jcmd output"); for (String s : output.asLines()) { if (s.contains(instanceKlassName)) { Asserts.assertTrue( s.contains(jcmdInstanceKlassSize), "The size computed by SA for" + instanceKlassName + " does not match."); } } } } finally { LingeredApp.stopApp(app); } }
Example 8
Source File: TestCheckedJniExceptionCheck.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
static void checkOuputForCorrectWarnings(OutputAnalyzer oa) throws RuntimeException { List<String> lines = oa.asLines(); int expectedWarnings = 0; int warningCount = 0; int lineNo = 0; boolean testStartLine = false; for (String line : lines) { lineNo++; if (!testStartLine) { // Skip any warning before the actual test itself testStartLine = line.startsWith(TEST_START); continue; } if (line.startsWith(JNI_CHECK_EXCEPTION)) { if (expectedWarnings == 0) { oa.reportDiagnosticSummary(); throw new RuntimeException("Unexpected warning at line " + lineNo); } warningCount++; if (warningCount > expectedWarnings) { oa.reportDiagnosticSummary(); throw new RuntimeException("Unexpected warning at line " + lineNo); } } else if (line.startsWith(EXPECT_WARNING_START)) { String countStr = line.substring(EXPECT_WARNING_START.length() + 1); expectedWarnings = Integer.parseInt(countStr); } else if (line.startsWith(EXPECT_WARNING_END)) { if (warningCount != expectedWarnings) { oa.reportDiagnosticSummary(); throw new RuntimeException("Missing warning at line " + lineNo); } warningCount = 0; expectedWarnings = 0; } } /* System.out.println("Output looks good..."); oa.reportDiagnosticSummary(); */ }