Java Code Examples for jdk.test.lib.process.OutputAnalyzer#getStdout()

The following examples show how to use jdk.test.lib.process.OutputAnalyzer#getStdout() . 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: TestG1HeapRegionSize.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void checkG1HeapRegionSize(String[] flags, int expectedValue, int exitValue) throws Exception {
  ArrayList<String> flagList = new ArrayList<String>();
  flagList.addAll(Arrays.asList(flags));
  flagList.add("-XX:+UseG1GC");
  flagList.add("-XX:+PrintFlagsFinal");
  flagList.add("-version");

  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flagList.toArray(new String[0]));
  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  output.shouldHaveExitValue(exitValue);

  if (exitValue == 0) {
    String stdout = output.getStdout();
    int flagValue = getFlagValue("G1HeapRegionSize", stdout);
    if (flagValue != expectedValue) {
      throw new RuntimeException("Wrong value for G1HeapRegionSize. Expected " + expectedValue + " but got " + flagValue);
    }
  }
}
 
Example 2
Source File: TestG1ConcMarkStepDurationMillis.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void runG1ConcMarkStepDurationMillisTest(String expectedValue, int expectedResult) throws Exception {
  List<String> vmOpts = new ArrayList<>();

  Collections.addAll(vmOpts, "-XX:+UseG1GC", "-XX:G1ConcMarkStepDurationMillis="+expectedValue, "-XX:+PrintFlagsFinal", "-version");

  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()]));
  OutputAnalyzer output = new OutputAnalyzer(pb.start());

  output.shouldHaveExitValue(expectedResult == PASS ? 0 : 1);
  String stdout = output.getStdout();
  if (expectedResult == PASS) {
    checkG1ConcMarkStepDurationMillisConsistency(stdout, expectedValue);
  } else if (expectedResult == FAIL_IMPROPER_VALUE) {
    output.shouldContain("Improperly specified VM option");
  } else if (expectedResult == FAIL_OUT_RANGE) {
    output.shouldContain("outside the allowed range");
  }
}
 
Example 3
Source File: TestMaxNewSize.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static String getMaxNewSize(String[] flags) throws Exception {
  ArrayList<String> finalargs = new ArrayList<String>();
  finalargs.addAll(Arrays.asList(flags));
  if (isRunningG1(flags)) {
    finalargs.add("-XX:G1HeapRegionSize=1M");
  }
  finalargs.add("-XX:+PrintFlagsFinal");
  finalargs.add("-version");

  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs.toArray(new String[0]));
  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  output.shouldHaveExitValue(0);
  String stdout = output.getStdout();
  //System.out.println(stdout);
  return getFlagValue("MaxNewSize", stdout);
}
 
Example 4
Source File: TestRemsetLoggingThreads.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void runTest(int refinementThreads, int workerThreads) throws Exception {
  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
                                                            "-XX:+UnlockDiagnosticVMOptions",
                                                            "-Xlog:gc+remset+exit=trace",
                                                            "-XX:G1ConcRefinementThreads=" + refinementThreads,
                                                            "-XX:ParallelGCThreads=" + workerThreads,
                                                            "-version");

  OutputAnalyzer output = new OutputAnalyzer(pb.start());

  // a zero in refinement thread numbers indicates that the value in ParallelGCThreads should be used.
  // Additionally use at least one thread.
  int expectedNumRefinementThreads = refinementThreads;

  String pattern = "Concurrent RS threads times \\(s\\)$";
  Matcher m = Pattern.compile(pattern, Pattern.MULTILINE).matcher(output.getStdout());

  if (!m.find()) {
    throw new Exception("Could not find correct output for concurrent RS threads times in stdout," +
      " should match the pattern \"" + pattern + "\", but stdout is \n" + output.getStdout());
  }
  output.shouldHaveExitValue(0);
}
 
Example 5
Source File: SpaceUtilizationCheck.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
       "-XX:+UnlockDiagnosticVMOptions",
       "-XX:SharedArchiveFile=./SpaceUtilizationCheck.jsa",
       "-Xshare:dump");

    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    String stdout = output.getStdout();
    ArrayList<String> utilization = findUtilization(stdout);

    if (utilization.size() != NUMBER_OF_CHECKED_SHARED_REGIONS )
        throw new RuntimeException("The output format of sharing summary has changed");

    for(String str : utilization) {
        int value = Integer.parseInt(str);
        if (value < MIN_UTILIZATION) {
            System.out.println(stdout);
            throw new RuntimeException("Utilization for one of the regions" +
                "is below a threshold of " + MIN_UTILIZATION + "%");
        }
    }
}
 
Example 6
Source File: TestPrintRegionRememberedSetInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static String runTest(String arg) throws Exception {
    ArrayList<String> finalargs = new ArrayList<String>();
    String[] defaultArgs = new String[] {
        "-XX:+UseG1GC",
        "-Xmx10m",
        "-XX:+ExplicitGCInvokesConcurrent",
        "-XX:+UnlockDiagnosticVMOptions",
        "-XX:G1HeapRegionSize=1M",
        "-XX:InitiatingHeapOccupancyPercent=0",
    };

    finalargs.addAll(Arrays.asList(defaultArgs));
    finalargs.add(arg);

    finalargs.add(RunAndWaitForMarking.class.getName());

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        finalargs.toArray(new String[0]));
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    output.shouldHaveExitValue(0);

    String result = output.getStdout();
    return result;
}
 
Example 7
Source File: TestNumWorkerOutput.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void runTest(String gcArg) throws Exception {
    final String[] arguments = {
        "-Xbootclasspath/a:.",
        "-XX:+UnlockExperimentalVMOptions",
        "-XX:+UnlockDiagnosticVMOptions",
        "-XX:+WhiteBoxAPI",
        "-XX:+" + gcArg,
        "-Xmx10M",
        "-XX:+PrintGCDetails",
        GCTest.class.getName()
        };

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(arguments);
    OutputAnalyzer output = new OutputAnalyzer(pb.start());

    output.shouldHaveExitValue(0);

    System.out.println(output.getStdout());

    String stdout = output.getStdout();

    checkPatternOnce(".*[info.*].*[gc,task.*].*GC\\(0\\) .*Using \\d+ workers of \\d+ for evacuation.*", stdout);
}
 
Example 8
Source File: TestObjectTenuringFlags.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void runTenuringFlagsConsistencyTest(String[] tenuringFlags,
        boolean shouldFail,
        ExpectedTenuringFlags expectedFlags) throws Exception {
  List<String> vmOpts = new ArrayList<>();
  if (tenuringFlags.length > 0) {
    Collections.addAll(vmOpts, tenuringFlags);
  }
  Collections.addAll(vmOpts, "-XX:+UseParallelGC", "-XX:+PrintFlagsFinal", "-version");

  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()]));
  OutputAnalyzer output = new OutputAnalyzer(pb.start());

  if (shouldFail) {
    output.shouldHaveExitValue(1);
  } else {
    output.shouldHaveExitValue(0);
    String stdout = output.getStdout();
    checkTenuringFlagsConsistency(stdout, expectedFlags);
  }
}
 
Example 9
Source File: TestAgeOutput.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void runTest(String gcArg) throws Exception {
    final String[] arguments = {
        "-Xbootclasspath/a:.",
        "-XX:+UnlockExperimentalVMOptions",
        "-XX:+UnlockDiagnosticVMOptions",
        "-XX:+WhiteBoxAPI",
        "-XX:+" + gcArg,
        "-Xmx10M",
        "-Xlog:gc+age=trace",
        GCTest.class.getName()
        };

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(arguments);
    OutputAnalyzer output = new OutputAnalyzer(pb.start());

    output.shouldHaveExitValue(0);

    System.out.println(output.getStdout());

    String stdout = output.getStdout();

    checkPattern(".*GC\\(0\\) .*Desired survivor size.*", stdout);
    checkPattern(".*GC\\(0\\) .*Age table with threshold.*", stdout);
    checkPattern(".*GC\\(0\\) .*- age   1:.*", stdout);
}
 
Example 10
Source File: HeapChangeLogging.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xmx128m", "-Xmn100m", "-XX:+UseSerialGC", "-Xlog:gc", "HeapFiller");
  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  String stdout = output.getStdout();
  System.out.println(stdout);
  Matcher stdoutMatcher = Pattern.compile(".*\\(Allocation Failure\\) [0-9]+[KMG]->[0-9]+[KMG]\\([0-9]+[KMG]\\)", Pattern.MULTILINE).matcher(stdout);
  if (!stdoutMatcher.find()) {
    throw new RuntimeException("No proper GC log line found");
  }
  output.shouldHaveExitValue(0);
}
 
Example 11
Source File: TestMaxHeapSizeTools.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void getNewOldSize(String gcflag, long[] values) throws Exception {
  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(gcflag,
    "-XX:+PrintFlagsFinal", "-version");
  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  output.shouldHaveExitValue(0);

  String stdout = output.getStdout();
  values[0] = getFlagValue(" NewSize", stdout);
  values[1] = getFlagValue(" OldSize", stdout);
}
 
Example 12
Source File: TestParallelGCThreads.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static long getParallelGCThreadCount(String flags[]) throws Exception {
  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flags);
  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  output.shouldHaveExitValue(0);
  String stdout = output.getStdout();
  return FlagsValue.getFlagLongValue("ParallelGCThreads", stdout);
}
 
Example 13
Source File: TestRemsetLoggingTools.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static String runTest(String[] additionalArgs, int numGCs) throws Exception {
    ArrayList<String> finalargs = new ArrayList<String>();
    String[] defaultArgs = new String[] {
        "-Xbootclasspath/a:.",
        "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
        "-cp", System.getProperty("java.class.path"),
        "-XX:+UseG1GC",
        "-Xmn4m",
        "-Xint", // -Xint makes the test run faster
        "-Xms20m",
        "-Xmx20m",
        "-XX:ParallelGCThreads=1",
        "-XX:InitiatingHeapOccupancyPercent=100", // we don't want the additional GCs due to initial marking
        "-XX:+UnlockDiagnosticVMOptions",
        "-XX:G1HeapRegionSize=1M",
    };

    finalargs.addAll(Arrays.asList(defaultArgs));

    if (additionalArgs != null) {
        finalargs.addAll(Arrays.asList(additionalArgs));
    }

    finalargs.add(VerifySummaryOutput.class.getName());
    finalargs.add(String.valueOf(numGCs));

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        finalargs.toArray(new String[0]));
    OutputAnalyzer output = new OutputAnalyzer(pb.start());

    output.shouldHaveExitValue(0);

    String result = output.getStdout();
    return result;
}
 
Example 14
Source File: TestJcmdStartStopDefault.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static String parseRecordingName(OutputAnalyzer output) {
    // Expected output:
    // Started recording recording-1. No limit (duration/maxsize/maxage) in use.
    // Use JFR.dump name=recording-1 filename=FILEPATH to copy recording data to file.

    String stdout = output.getStdout();
    Pattern p = Pattern.compile(".*Use jcmd \\d+ JFR.dump name=(\\S+).*", Pattern.DOTALL);
    Matcher m = p.matcher(stdout);
    Asserts.assertTrue(m.matches(), "Could not parse recording name");
    String name = m.group(1);
    System.out.println("Recording name=" + name);
    return name;
}
 
Example 15
Source File: ExitOnThrow.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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 16
Source File: TestJcmdStartStopDefault.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static String parseRecordingName(OutputAnalyzer output) {
    // Expected output:
    // Started recording recording-1. No limit (duration/maxsize/maxage) in use.
    // Use JFR.dump name=recording-1 filename=FILEPATH to copy recording data to file.

    String stdout = output.getStdout();
    Pattern p = Pattern.compile(".*Use jcmd \\d+ JFR.dump name=(\\S+).*", Pattern.DOTALL);
    Matcher m = p.matcher(stdout);
    Asserts.assertTrue(m.matches(), "Could not parse recording name");
    String name = m.group(1);
    System.out.println("Recording name=" + name);
    return name;
}
 
Example 17
Source File: TestPrintJSON.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws Throwable {

        Path recordingFile = ExecuteHelper.createProfilingRecording().toAbsolutePath();

        OutputAnalyzer output = ExecuteHelper.jfr("print", "--json", "--stack-depth", "999", recordingFile.toString());
        String json = output.getStdout();

        // Parse JSON using Nashorn
        String statement = "var jsonObject = " + json;
        ScriptEngineManager factory = new ScriptEngineManager();
        ScriptEngine engine = factory.getEngineByName("nashorn");
        engine.eval(statement);
        JSObject o = (JSObject) engine.get("jsonObject");
        JSObject recording = (JSObject) o.getMember("recording");
        JSObject jsonEvents = (JSObject) recording.getMember("events");

        List<RecordedEvent> events = RecordingFile.readAllEvents(recordingFile);
        Collections.sort(events, (e1, e2) -> e1.getEndTime().compareTo(e2.getEndTime()));
        // Verify events are equal
        Iterator<RecordedEvent> it = events.iterator();

        for (Object jsonEvent : jsonEvents.values()) {
            RecordedEvent recordedEvent = it.next();
            String typeName = recordedEvent.getEventType().getName();
            Asserts.assertEquals(typeName, ((JSObject) jsonEvent).getMember("type").toString());
            assertEquals(jsonEvent, recordedEvent);
        }
        Asserts.assertFalse(events.size() != jsonEvents.values().size(), "Incorrect number of events");
    }
 
Example 18
Source File: TestPrintXML.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String... args) throws Throwable {

        Path recordingFile = ExecuteHelper.createProfilingRecording().toAbsolutePath();

        OutputAnalyzer output = ExecuteHelper.jfr("print", "--xml", "--stack-depth", "9999", recordingFile.toString());
        System.out.println(recordingFile);
        String xml = output.getStdout();

        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(new File(System.getProperty("test.src"), "jfr.xsd"));

        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setSchema(schema);
        factory.setNamespaceAware(true);

        SAXParser sp = factory.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        RecordingHandler handler = new RecordingHandler();
        xr.setContentHandler(handler);
        xr.setErrorHandler(handler);
        xr.parse(new InputSource(new StringReader(xml)));

        // Verify that all data was written correctly
        List<RecordedEvent> events = RecordingFile.readAllEvents(recordingFile);
        Collections.sort(events, (e1, e2) -> e1.getEndTime().compareTo(e2.getEndTime()));
        Iterator<RecordedEvent> it = events.iterator();
        for (XMLEvent xmlEvent : handler.events) {
            RecordedEvent re = it.next();
            if (!compare(re, xmlEvent.values)) {
                System.out.println("Expected:");
                System.out.println("----------------------");
                System.out.println(re);
                System.out.println();
                System.out.println("Was (XML)");
                System.out.println("----------------------");
                System.out.println(xmlEvent);
                System.out.println();
                throw new Exception("Event doesn't match");
            }
        }

    }
 
Example 19
Source File: TestPrintXML.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String... args) throws Throwable {

        Path recordingFile = ExecuteHelper.createProfilingRecording().toAbsolutePath();

        OutputAnalyzer output = ExecuteHelper.jfr("print", "--xml", "--stack-depth", "9999", recordingFile.toString());
        System.out.println(recordingFile);
        String xml = output.getStdout();

        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(new File(System.getProperty("test.src"), "jfr.xsd"));

        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setSchema(schema);
        factory.setNamespaceAware(true);

        SAXParser sp = factory.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        RecordingHandler handler = new RecordingHandler();
        xr.setContentHandler(handler);
        xr.setErrorHandler(handler);
        xr.parse(new InputSource(new StringReader(xml)));

        // Verify that all data was written correctly
        List<RecordedEvent> events = RecordingFile.readAllEvents(recordingFile);
        Collections.sort(events, (e1, e2) -> e1.getEndTime().compareTo(e2.getEndTime()));
        Iterator<RecordedEvent> it = events.iterator();
        for (XMLEvent xmlEvent : handler.events) {
            RecordedEvent re = it.next();
            if (!compare(re, xmlEvent.values)) {
                System.out.println("Expected:");
                System.out.println("----------------------");
                System.out.println(re);
                System.out.println();
                System.out.println("Was (XML)");
                System.out.println("----------------------");
                System.out.println(xmlEvent);
                System.out.println();
                throw new Exception("Event doesn't match");
            }
        }

    }
 
Example 20
Source File: TestUseCompressedOopsErgoTools.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static String expect(String[] flags, boolean hasWarning, boolean hasError, int errorcode) throws Exception {
  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flags);
  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  output.shouldHaveExitValue(errorcode);
  return output.getStdout();
}