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

The following examples show how to use jdk.test.lib.process.OutputAnalyzer#stdoutShouldContain() . 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: SetVMFlagTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void setMutableFlagWithInvalidValue(CommandExecutor executor) {
    OutputAnalyzer out = getAllFlags(executor);
    String flagName = out.firstMatch(MANAGEABLE_PATTERN, 1);
    String flagVal = out.firstMatch(MANAGEABLE_PATTERN, 2);

    System.out.println("### Setting a mutable flag '" + flagName + "' to an invalid value");

    if (flagVal == null) {
        System.err.println(out.getOutput());
        throw new Error("Can not find a boolean manageable flag");
    }

    // a boolean flag accepts only 0/1 as its value
    out = executor.execute("VM.set_flag " + flagName + " unexpected_value");
    out.stderrShouldBeEmpty();
    out.stdoutShouldContain("flag value must be a boolean (1/0 or true/false)");

    out = getAllFlags(executor);

    String newFlagVal = out.firstMatch(MANAGEABLE_PATTERN.replace("(\\S+)", flagName), 1);

    assertEquals(newFlagVal, flagVal);
}
 
Example 2
Source File: SetVMFlagTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void setImmutableFlag(CommandExecutor executor) {
    OutputAnalyzer out = getAllFlags(executor);
    String flagName = out.firstMatch(IMMUTABLE_PATTERN, 1);
    String flagVal = out.firstMatch(IMMUTABLE_PATTERN, 2);

    System.out.println("### Setting an immutable flag '" + flagName + "'");

    if (flagVal == null) {
        System.err.println(out.getOutput());
        throw new Error("Can not find an immutable uintx flag");
    }

    Long numVal = Long.parseLong(flagVal);

    out = executor.execute("VM.set_flag " + flagName + " " + (numVal + 1));
    out.stderrShouldBeEmpty();
    out.stdoutShouldContain("only 'writeable' flags can be set");

    out = getAllFlags(executor);

    String newFlagVal = out.firstMatch(IMMUTABLE_PATTERN.replace("(\\S+)", flagName), 1);

    assertEquals(newFlagVal, flagVal);
}
 
Example 3
Source File: TestModularizedEvent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {
    compileModule(ANNO_MODULE);
    compileModule(SETTING_MODULE);
    compileModule(EVENT_MODULE, "--module-path", MODS_DIR.toString());
    compileModule(TEST_MODULE, "--module-path", MODS_DIR.toString());

    OutputAnalyzer oa = ProcessTools.executeTestJava("--module-path", "mods", "-m", "test.jfr.main/test.jfr.main.MainTest");
    oa.stdoutShouldContain("Test passed.");
}
 
Example 4
Source File: ClhsdbJstackXcompStress.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void runJstackInLoop(LingeredApp app) throws Exception {
    boolean anyMatchedCompiledFrame = false;
    for (int i = 0; i < MAX_ITERATIONS; i++) {
        JDKToolLauncher launcher = JDKToolLauncher
                .createUsingTestJDK("jhsdb");
        launcher.addToolArg("jstack");
        launcher.addToolArg("--pid");
        launcher.addToolArg(Long.toString(app.getPid()));

        ProcessBuilder pb = new ProcessBuilder();
        pb.command(launcher.getCommand());
        Process jhsdb = pb.start();
        OutputAnalyzer out = new OutputAnalyzer(jhsdb);

        jhsdb.waitFor();

        if (DEBUG) {
            System.out.println(out.getStdout());
            System.err.println(out.getStderr());
        }

        out.stderrShouldBeEmpty(); // NPE's are reported on the err stream
        out.stdoutShouldNotContain("Error occurred during stack walking:");
        out.stdoutShouldContain(LingeredAppWithRecComputation.THREAD_NAME);
        List<String> stdoutList = Arrays.asList(out.getStdout().split("\\R"));
        anyMatchedCompiledFrame = anyMatchedCompiledFrame || isMatchCompiledFrame(stdoutList);
    }
    if (!anyMatchedCompiledFrame) {
         throw new RuntimeException("Expected jstack output to contain 'Compiled frame'");
    }
    System.out.println("DEBUG: jhsdb jstack did not throw NPE, as expected.");
}
 
Example 5
Source File: TestModularizedEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {
    compileModule(ANNO_MODULE);
    compileModule(SETTING_MODULE);
    compileModule(EVENT_MODULE, "--module-path", MODS_DIR.toString());
    compileModule(TEST_MODULE, "--module-path", MODS_DIR.toString());

    OutputAnalyzer oa = ProcessTools.executeTestJava("--module-path", "mods", "-m", "test.jfr.main/test.jfr.main.MainTest");
    oa.stdoutShouldContain("Test passed.");
}
 
Example 6
Source File: GetObjectSizeOverflow.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 (!Platform.is64bit()) {
            System.out.println("Test needs a 4GB heap and can only be run as a 64bit process, skipping.");
            return;
        }

        PrintWriter pw = new PrintWriter("MANIFEST.MF");
        pw.println("Premain-Class: GetObjectSizeOverflowAgent");
        pw.close();

        ProcessBuilder pb = new ProcessBuilder();
        pb.command(new String[] { JDKToolFinder.getJDKTool("jar"), "cmf", "MANIFEST.MF", "agent.jar", "GetObjectSizeOverflowAgent.class"});
        pb.start().waitFor();

        ProcessBuilder pt = ProcessTools.createJavaProcessBuilder(true, "-Xmx4000m", "-javaagent:agent.jar",  "GetObjectSizeOverflowAgent");
        OutputAnalyzer output = new OutputAnalyzer(pt.start());

        if (output.getStdout().contains("Could not reserve enough space") || output.getStderr().contains("java.lang.OutOfMemoryError")) {
            System.out.println("stdout: " + output.getStdout());
            System.out.println("stderr: " + output.getStderr());
            System.out.println("Test could not reserve or allocate enough space, skipping");
            return;
        }

        output.stdoutShouldContain("GetObjectSizeOverflow passed");
    }
 
Example 7
Source File: GetObjectSizeClass.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  {
    PrintWriter pw = new PrintWriter("MANIFEST.MF");
    pw.println("Premain-Class: GetObjectSizeClassAgent");
    pw.close();

    ProcessBuilder pb = new ProcessBuilder();
    pb.command(new String[] { JDKToolFinder.getJDKTool("jar"), "cmf", "MANIFEST.MF", "agent.jar", "GetObjectSizeClassAgent.class"});
    pb.start().waitFor();

    ProcessBuilder pt = ProcessTools.createJavaProcessBuilder(true, "-javaagent:agent.jar",  "GetObjectSizeClassAgent");
    OutputAnalyzer output = new OutputAnalyzer(pt.start());

    output.stdoutShouldContain("GetObjectSizeClass passed");
}