Java Code Examples for jdk.testlibrary.ProcessTools#executeProcess()

The following examples show how to use jdk.testlibrary.ProcessTools#executeProcess() . 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: JstatdTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Depending on test settings command line can look like:
 *
 * jstat -J-XX:+UsePerfData -J-Duser.language=en -gcutil pid@hostname 250 5
 * jstat -J-XX:+UsePerfData -J-Duser.language=en -gcutil pid@hostname:port 250 5
 * jstat -J-XX:+UsePerfData -J-Duser.language=en -gcutil pid@hostname/serverName 250 5
 * jstat -J-XX:+UsePerfData -J-Duser.language=en -gcutil pid@hostname:port/serverName 250 5
 */
private OutputAnalyzer runJstat() throws Exception {
    JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstat");
    launcher.addVMArg("-XX:+UsePerfData");
    launcher.addVMArg("-Duser.language=en");
    launcher.addToolArg("-gcutil");
    launcher.addToolArg(jstatdPid + "@" + getDestination());
    launcher.addToolArg(Integer.toString(JSTAT_GCUTIL_INTERVAL_MS));
    launcher.addToolArg(Integer.toString(JSTAT_GCUTIL_SAMPLES));

    String[] cmd = launcher.getCommand();
    log("Start jstat", cmd);

    ProcessBuilder processBuilder = new ProcessBuilder(cmd);
    OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
    System.out.println(output.getOutput());

    return output;
}
 
Example 2
Source File: ZeroArgPremainAgentTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] a) throws Exception {
    String testArgs = String.format(
            "-javaagent:ZeroArgPremainAgent.jar -classpath %s DummyMain",
            System.getProperty("test.classes", "."));

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
            Utils.addTestJavaOpts(testArgs.split("\\s+")));
    System.out.println("testjvm.cmd:" + Utils.getCommandLine(pb));

    OutputAnalyzer output = ProcessTools.executeProcess(pb);
    System.out.println("testjvm.stdout:" + output.getStdout());
    System.out.println("testjvm.stderr:" + output.getStderr());

    output.stderrShouldContain("java.lang.NoSuchMethodException");
    if (0 == output.getExitValue()) {
        throw new RuntimeException("Expected error but got exit value 0");
    }
}
 
Example 3
Source File: RunUtil.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs a test in a separate JVM.
 * command line like:
 * {test_jdk}/bin/java {defaultopts} -cp {test.class.path} {testopts} main
 *
 * {defaultopts} are the default java options set by the framework.
 * Default GC options in {defaultopts} may be removed.
 * This is used when the test specifies its own GC options.
 *
 * @param main Name of the main class.
 * @param clearGcOpts true if the default GC options should be removed.
 * @param testOpts java options specified by the test.
 */
private static void runTest(String main, boolean clearGcOpts, String... testOpts)
            throws Throwable {
    List<String> opts = new ArrayList<>();
    opts.add(JDKToolFinder.getJDKTool("java"));
    opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
    opts.add("-cp");
    opts.add(System.getProperty("test.class.path", "test.class.path"));
    opts.add("-XX:+PrintGCDetails");

    if (clearGcOpts) {
        opts = Utils.removeGcOpts(opts);
    }
    opts.addAll(Arrays.asList(testOpts));
    opts.add(main);

    OutputAnalyzer output = ProcessTools.executeProcess(opts.toArray(new String[0]));
    output.shouldHaveExitValue(0);
    if (output.getStdout().indexOf(successMessage) < 0) {
        throw new Exception("output missing '" + successMessage + "'");
    }
}
 
Example 4
Source File: RunUtil.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs a test in a separate JVM.
 * command line like:
 * {test_jdk}/bin/java {defaultopts} -cp {test.class.path} {testopts} main
 *
 * {defaultopts} are the default java options set by the framework.
 * Default GC options in {defaultopts} may be removed.
 * This is used when the test specifies its own GC options.
 *
 * @param main Name of the main class.
 * @param clearGcOpts true if the default GC options should be removed.
 * @param testOpts java options specified by the test.
 */
private static void runTest(String main, boolean clearGcOpts, String... testOpts)
            throws Throwable {
    List<String> opts = new ArrayList<>();
    opts.add(JDKToolFinder.getJDKTool("java"));
    opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
    opts.add("-cp");
    opts.add(System.getProperty("test.class.path", "test.class.path"));
    opts.add("-XX:+PrintGCDetails");

    if (clearGcOpts) {
        opts = Utils.removeGcOpts(opts);
    }
    opts.addAll(Arrays.asList(testOpts));
    opts.add(main);

    OutputAnalyzer output = ProcessTools.executeProcess(opts.toArray(new String[0]));
    output.shouldHaveExitValue(0);
    if (output.getStdout().indexOf(successMessage) < 0) {
        throw new Exception("output missing '" + successMessage + "'");
    }
}
 
Example 5
Source File: RunUtil.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs a test in a separate JVM.
 * command line like:
 * {test_jdk}/bin/java {defaultopts} -cp {test.class.path} {testopts} main
 *
 * {defaultopts} are the default java options set by the framework.
 * Default GC options in {defaultopts} may be removed.
 * This is used when the test specifies its own GC options.
 *
 * @param main Name of the main class.
 * @param clearGcOpts true if the default GC options should be removed.
 * @param testOpts java options specified by the test.
 */
private static void runTest(String main, boolean clearGcOpts, String... testOpts)
            throws Throwable {
    List<String> opts = new ArrayList<>();
    opts.add(JDKToolFinder.getJDKTool("java"));
    opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
    opts.add("-cp");
    opts.add(System.getProperty("test.class.path", "test.class.path"));
    opts.add("-XX:+PrintGCDetails");

    if (clearGcOpts) {
        opts = Utils.removeGcOpts(opts);
    }
    opts.addAll(Arrays.asList(testOpts));
    opts.add(main);

    OutputAnalyzer output = ProcessTools.executeProcess(opts.toArray(new String[0]));
    output.shouldHaveExitValue(0);
    if (output.getStdout().indexOf(successMessage) < 0) {
        throw new Exception("output missing '" + successMessage + "'");
    }
}
 
Example 6
Source File: RunUtil.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs a test in a separate JVM.
 * command line like:
 * {test_jdk}/bin/java {defaultopts} -cp {test.class.path} {testopts} main
 *
 * {defaultopts} are the default java options set by the framework.
 * Default GC options in {defaultopts} may be removed.
 * This is used when the test specifies its own GC options.
 *
 * @param main Name of the main class.
 * @param clearGcOpts true if the default GC options should be removed.
 * @param testOpts java options specified by the test.
 */
private static void runTest(String main, boolean clearGcOpts, String... testOpts)
            throws Throwable {
    List<String> opts = new ArrayList<>();
    opts.add(JDKToolFinder.getJDKTool("java"));
    opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
    opts.add("-cp");
    opts.add(System.getProperty("test.class.path", "test.class.path"));
    opts.add("-XX:+PrintGCDetails");

    if (clearGcOpts) {
        opts = Utils.removeGcOpts(opts);
    }
    opts.addAll(Arrays.asList(testOpts));
    opts.add(main);

    OutputAnalyzer output = ProcessTools.executeProcess(opts.toArray(new String[0]));
    output.shouldHaveExitValue(0);
    if (output.getStdout().indexOf(successMessage) < 0) {
        throw new Exception("output missing '" + successMessage + "'");
    }
}
 
Example 7
Source File: RunUtil.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs a test in a separate JVM.
 * command line like:
 * {test_jdk}/bin/java {defaultopts} -cp {test.class.path} {testopts} main
 *
 * {defaultopts} are the default java options set by the framework.
 * Default GC options in {defaultopts} may be removed.
 * This is used when the test specifies its own GC options.
 *
 * @param main Name of the main class.
 * @param clearGcOpts true if the default GC options should be removed.
 * @param testOpts java options specified by the test.
 */
private static void runTest(String main, boolean clearGcOpts, String... testOpts)
            throws Throwable {
    List<String> opts = new ArrayList<>();
    opts.add(JDKToolFinder.getJDKTool("java"));
    opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
    opts.add("-cp");
    opts.add(System.getProperty("test.class.path", "test.class.path"));
    opts.add("-XX:+PrintGCDetails");

    if (clearGcOpts) {
        opts = Utils.removeGcOpts(opts);
    }
    opts.addAll(Arrays.asList(testOpts));
    opts.add(main);

    OutputAnalyzer output = ProcessTools.executeProcess(opts.toArray(new String[0]));
    output.shouldHaveExitValue(0);
    if (output.getStdout().indexOf(successMessage) < 0) {
        throw new Exception("output missing '" + successMessage + "'");
    }
}
 
Example 8
Source File: TestGCYoungGenerationConfigurationEventWithMinAndMaxSize.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    String[] jvm_args = {"-XX:+EnableJFR",
                         "-XX:+UnlockExperimentalVMOptions",
                         "-XX:-UseFastUnorderedTimeStamps",
                         "-XX:NewSize=12m",
                         "-cp",
                         System.getProperty("java.class.path"),
                         "-XX:MaxNewSize=16m",
                         "-Xms32m",
                         "-Xmx64m",
                         Tester.class.getName()};
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(jvm_args);
    try {
        OutputAnalyzer analyzer = ProcessTools.executeProcess(pb);
        analyzer.shouldHaveExitValue(0);
    } catch (Throwable t) {
        throw new Exception(t);
    }
}
 
Example 9
Source File: TestStartName.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void testName(String recordingName, boolean validName) throws Exception {
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
        "-XX:StartFlightRecording=name=" + recordingName, TestName.class.getName(), recordingName);
    OutputAnalyzer out = null;
    try {
        out = ProcessTools.executeProcess(pb);
    } catch (Throwable t) {
        throw new Exception(t);
    }

    if (validName) {
        out.shouldHaveExitValue(0);
    } else {
        out.shouldHaveExitValue(1);
        out.shouldContain("Name of recording can't be numeric");
    }
}
 
Example 10
Source File: TestNative.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String lib = System.getProperty("test.nativepath");
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-Djava.library.path=" + lib, "jdk.jfr.event.sampling.TestNative$Test");

    OutputAnalyzer output = ProcessTools.executeProcess(pb);
    output.shouldHaveExitValue(0);
    output.stdoutShouldNotContain("No native samples found");
}
 
Example 11
Source File: BasicLauncherTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void launchJStack() throws IOException {

        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;
        }

        System.out.println("Starting LingeredApp");
        try {
            theApp = LingeredApp.startApp(Arrays.asList("-Xmx256m"));

            System.out.println("Starting jstack against " + theApp.getPid());
            JDKToolLauncher launcher = createSALauncher();

            launcher.addToolArg("jstack");
            launcher.addToolArg("--pid=" + Long.toString(theApp.getPid()));

            ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
            OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);;
            output.shouldContain("No deadlocks found");
            output.shouldNotContain("illegal bci");
            output.shouldNotContain("AssertionFailure");
            output.shouldHaveExitValue(0);

        } catch (Exception ex) {
            throw new RuntimeException("Test ERROR " + ex, ex);
        } finally {
            LingeredApp.stopApp(theApp);
        }
    }
 
Example 12
Source File: NativeErrors.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static String executeCmd(String... toolArgs) throws Throwable {
    JDKToolLauncher cmd = JDKToolLauncher.createUsingTestJDK("native2ascii");
    for (String s : toolArgs) {
        cmd.addToolArg(s);
    }
    OutputAnalyzer output = ProcessTools.executeProcess(cmd.getCommand());
    if (output == null || output.getStdout() == null) {
        throw new Exception("Output was null. Process did not finish correctly.");
    }
    if (output.getExitValue() == 0) {
        throw new Exception("Process exit code was 0, but error was expected.");
    }
    return output.getStdout();
}
 
Example 13
Source File: NativeErrors.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static String executeCmd(String... toolArgs) throws Throwable {
    JDKToolLauncher cmd = JDKToolLauncher.createUsingTestJDK("native2ascii");
    for (String s : toolArgs) {
        cmd.addToolArg(s);
    }
    OutputAnalyzer output = ProcessTools.executeProcess(cmd.getCommand());
    if (output == null || output.getStdout() == null) {
        throw new Exception("Output was null. Process did not finish correctly.");
    }
    if (output.getExitValue() == 0) {
        throw new Exception("Process exit code was 0, but error was expected.");
    }
    return output.getStdout();
}
 
Example 14
Source File: NativeErrors.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static String executeCmd(String... toolArgs) throws Throwable {
    JDKToolLauncher cmd = JDKToolLauncher.createUsingTestJDK("native2ascii");
    for (String s : toolArgs) {
        cmd.addToolArg(s);
    }
    OutputAnalyzer output = ProcessTools.executeProcess(cmd.getCommand());
    if (output == null || output.getStdout() == null) {
        throw new Exception("Output was null. Process did not finish correctly.");
    }
    if (output.getExitValue() == 0) {
        throw new Exception("Process exit code was 0, but error was expected.");
    }
    return output.getStdout();
}
 
Example 15
Source File: NativeErrors.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static String executeCmd(String... toolArgs) throws Throwable {
    JDKToolLauncher cmd = JDKToolLauncher.createUsingTestJDK("native2ascii");
    for (String s : toolArgs) {
        cmd.addToolArg(s);
    }
    OutputAnalyzer output = ProcessTools.executeProcess(cmd.getCommand());
    if (output == null || output.getStdout() == null) {
        throw new Exception("Output was null. Process did not finish correctly.");
    }
    if (output.getExitValue() == 0) {
        throw new Exception("Process exit code was 0, but error was expected.");
    }
    return output.getStdout();
}
 
Example 16
Source File: NativeErrors.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static String executeCmd(String... toolArgs) throws Throwable {
    JDKToolLauncher cmd = JDKToolLauncher.createUsingTestJDK("native2ascii");
    for (String s : toolArgs) {
        cmd.addToolArg(s);
    }
    OutputAnalyzer output = ProcessTools.executeProcess(cmd.getCommand());
    if (output == null || output.getStdout() == null) {
        throw new Exception("Output was null. Process did not finish correctly.");
    }
    if (output.getExitValue() == 0) {
        throw new Exception("Process exit code was 0, but error was expected.");
    }
    return output.getStdout();
}
 
Example 17
Source File: LeadingGarbage.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void createNormalZip() throws Throwable {
    createFiles();
    String[] cmd = { jar, "c0Mf", "normal.zip", "a", "b" };
    ProcessBuilder pb = new ProcessBuilder(cmd);
    OutputAnalyzer a = ProcessTools.executeProcess(pb);
    a.shouldHaveExitValue(0);
    a.stdoutShouldMatch("\\A\\Z");
    a.stderrShouldMatch("\\A\\Z");
    deleteFiles();
}
 
Example 18
Source File: BasicTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void execute(Path image, String scriptName) throws Throwable {
    String cmd = image.resolve("bin").resolve(scriptName).toString();
    OutputAnalyzer analyzer;
    if (System.getProperty("os.name").startsWith("Windows")) {
        analyzer = ProcessTools.executeProcess("sh.exe", cmd, "1", "2", "3");
    } else {
        analyzer = ProcessTools.executeProcess(cmd, "1", "2", "3");
    }
    if (analyzer.getExitValue() != 0) {
        throw new AssertionError("Image invocation failed: rc=" + analyzer.getExitValue());
    }
}
 
Example 19
Source File: LeadingGarbage.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void assertCanExtract(String zipFileName) throws Throwable {
    String[] cmd = { jar, "xf", zipFileName };
    ProcessBuilder pb = new ProcessBuilder(cmd);
    OutputAnalyzer a = ProcessTools.executeProcess(pb);
    a.shouldHaveExitValue(0);
    a.stdoutShouldMatch("\\A\\Z");
    a.stderrShouldMatch("\\A\\Z");
    assertFilesExist();
}
 
Example 20
Source File: DynamicLauncher.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected OutputAnalyzer runVM() throws Exception {
    String[] options = this.options();
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(options);
    OutputAnalyzer out = ProcessTools.executeProcess(pb);
    System.out.println(out.getStdout());
    System.err.println(out.getStderr());
    return out;
}