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

The following examples show how to use jdk.testlibrary.ProcessTools#createJavaProcessBuilder() . 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: RunToExit.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static Process launch(String address, String class_name) throws Exception {
    String args[] = new String[]{
        "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address="
            + address,
        class_name
    };
    args = VMConnection.insertDebuggeeVMOptions(args);

    ProcessBuilder launcher = ProcessTools.createJavaProcessBuilder(args);

    System.out.println(launcher.command().stream().collect(Collectors.joining(" ", "Starting: ", "")));

    Process p = ProcessTools.startProcess(
        class_name,
        launcher,
        RunToExit::checkForError,
        RunToExit::isTransportListening,
        0,
        TimeUnit.NANOSECONDS
    );

    return p;
}
 
Example 2
Source File: BadHandshakeTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static Process launch(String address, String class_name) throws Exception {
    String[] args = VMConnection.insertDebuggeeVMOptions(new String[] {
        "-agentlib:jdwp=transport=dt_socket" +
        ",server=y" + ",suspend=y" + ",address=" + address,
        class_name
    });

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);

    final AtomicBoolean success = new AtomicBoolean();
    Process p = ProcessTools.startProcess(
        class_name,
        pb,
        (line) -> {
            // The first thing that will get read is
            //    Listening for transport dt_socket at address: xxxxx
            // which shows the debuggee is ready to accept connections.
            success.set(line.contains("Listening for transport dt_socket at address:"));
            return true;
        },
        1500,
        TimeUnit.MILLISECONDS
    );

    return success.get() ? p : null;
}
 
Example 3
Source File: ExclusiveBind.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static ProcessBuilder prepareLauncher(String address, boolean suspend, String class_name) throws Exception {
    List<String> args = new ArrayList<>();
    for(String dbgOption : VMConnection.getDebuggeeVMOptions().split(" ")) {
        if (!dbgOption.trim().isEmpty()) {
            args.add(dbgOption);
        }
    }
    String lib = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=";
    if (suspend) {
        lib += "y";
    } else {
        lib += "n";
    }
    lib += ",address=" + address;

    args.add(lib);
    args.add(class_name);

    return ProcessTools.createJavaProcessBuilder(args.toArray(new String[args.size()]));
}
 
Example 4
Source File: ExclusiveBind.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static ProcessBuilder prepareLauncher(String address, boolean suspend, String class_name) throws Exception {
    List<String> args = new ArrayList<>();
    for(String dbgOption : VMConnection.getDebuggeeVMOptions().split(" ")) {
        args.add(dbgOption);
    }
    String lib = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=";
    if (suspend) {
        lib += "y";
    } else {
        lib += "n";
    }
    lib += ",address=" + address;

    args.add(lib);
    args.add(class_name);

    return ProcessTools.createJavaProcessBuilder(args.toArray(new String[args.size()]));
}
 
Example 5
Source File: TestJpsJar.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    String testJdk = System.getProperty("test.jdk", "?");
    String testSrc = System.getProperty("test.src", "?");
    File jar = JpsHelper.buildJar("JpsBase");

    List<String> cmd = new ArrayList<>();
    cmd.addAll(JpsHelper.getVmArgs());
    cmd.add("-Dtest.jdk=" + testJdk);
    cmd.add("-Dtest.src=" + testSrc);
    cmd.add("-jar");
    cmd.add(jar.getAbsolutePath());
    cmd.add("monkey");

    ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(cmd.toArray(new String[cmd.size()]));
    OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
    System.out.println(output.getOutput());
    output.shouldHaveExitValue(0);
}
 
Example 6
Source File: BadHandshakeTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static Process launch(String address, String class_name) throws Exception {
    String[] args = VMConnection.insertDebuggeeVMOptions(new String[] {
        "-agentlib:jdwp=transport=dt_socket" +
        ",server=y" + ",suspend=y" + ",address=" + address,
        class_name
    });

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);

    final AtomicBoolean success = new AtomicBoolean();
    Process p = ProcessTools.startProcess(
        class_name,
        pb,
        (line) -> {
            // The first thing that will get read is
            //    Listening for transport dt_socket at address: xxxxx
            // which shows the debuggee is ready to accept connections.
            success.set(line.contains("Listening for transport dt_socket at address:"));
            return true;
        },
        Integer.MAX_VALUE,
        TimeUnit.MILLISECONDS
    );

    return success.get() ? p : null;
}
 
Example 7
Source File: PremainClassTest.java    From TencentKona-8 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:%s/Agent.jar -classpath %s DummyMain",
            System.getProperty("test.src"),
            System.getProperty("test.classes", "."));

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

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

    output.shouldHaveExitValue(0);
    output.stdoutShouldContain("premain running");
    output.stdoutShouldContain("Hello from DummyMain!");
}
 
Example 8
Source File: ZeroArgPremainAgentTest.java    From openjdk-8 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 = new OutputAnalyzer(pb.start());
    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 9
Source File: ZeroArgPremainAgentTest.java    From jdk8u-jdk 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 = new OutputAnalyzer(pb.start());
    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 10
Source File: NoPremainAgentTest.java    From openjdk-8 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:NoPremainAgent.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 = new OutputAnalyzer(pb.start());
    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 11
Source File: BadHandshakeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static Process launch(String address, String class_name) throws Exception {
    String[] args = VMConnection.insertDebuggeeVMOptions(new String[] {
        "-agentlib:jdwp=transport=dt_socket" +
        ",server=y" + ",suspend=y" + ",address=" + address,
        class_name
    });

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);

    final AtomicBoolean success = new AtomicBoolean();
    Process p = ProcessTools.startProcess(
        class_name,
        pb,
        (line) -> {
            // The first thing that will get read is
            //    Listening for transport dt_socket at address: xxxxx
            // which shows the debuggee is ready to accept connections.
            success.set(line.contains("Listening for transport dt_socket at address:"));
            return true;
        },
        Integer.MAX_VALUE,
        TimeUnit.MILLISECONDS
    );

    return success.get() ? p : null;
}
 
Example 12
Source File: ZeroArgPremainAgentTest.java    From TencentKona-8 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 = new OutputAnalyzer(pb.start());
    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 13
Source File: MonitorVmStartTerminate.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void executeJava() throws Exception, IOException {
    String className = JavaProcess.class.getName();
    String classPath = System.getProperty("test.classes");
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        "-Dtest.timeout.factor=" + System.getProperty("test.timeout.factor", "1.0"),
        "-cp", classPath, className, mainArgsIdentifier);
    OutputBuffer ob = ProcessTools.getOutput(pb.start());
    System.out.println("Java Process " + getMainArgsIdentifier() + " stderr:"
            + ob.getStderr());
    System.err.println("Java Process " + getMainArgsIdentifier() + " stdout:"
            + ob.getStdout());
}
 
Example 14
Source File: DynamicLauncher.java    From jdk8u_jdk 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 = new OutputAnalyzer(pb.start());
    System.out.println(out.getStdout());
    System.err.println(out.getStderr());
    return out;
}
 
Example 15
Source File: TestDaemonThreadLauncher.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 {
    for(int i=0; i<50; i++) {
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-javaagent:DummyAgent.jar", "TestDaemonThread", ".");
        OutputAnalyzer analyzer = ProcessTools.executeProcess(pb);
        analyzer.shouldNotContain("ASSERTION FAILED");
        analyzer.shouldHaveExitValue(0);
    }
}
 
Example 16
Source File: DynamicLauncher.java    From jdk8u-jdk 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 = new OutputAnalyzer(pb.start());
    System.out.println(out.getStdout());
    System.err.println(out.getStderr());
    return out;
}
 
Example 17
Source File: DynamicLauncher.java    From jdk8u60 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 = new OutputAnalyzer(pb.start());
    System.out.println(out.getStdout());
    System.err.println(out.getStderr());
    return out;
}
 
Example 18
Source File: TestDaemonThreadLauncher.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 {
    for(int i=0; i<50; i++) {
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-javaagent:DummyAgent.jar", "TestDaemonThread", ".");
        OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
        analyzer.shouldNotContain("ASSERTION FAILED");
    }
}
 
Example 19
Source File: JMXInterfaceBindingTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private TestProcessThread runJMXBindingTest(String address, boolean useSSL) {
    List<String> args = new ArrayList<>();
    args.add("-classpath");
    args.add(TEST_CLASSPATH);
    args.add("-Dcom.sun.management.jmxremote.host=" + address);
    args.add("-Dcom.sun.management.jmxremote.port=" + JMX_PORT);
    args.add("-Dcom.sun.management.jmxremote.rmi.port=" + RMI_PORT);
    args.add("-Dcom.sun.management.jmxremote.authenticate=false");
    args.add("-Dcom.sun.management.jmxremote.ssl=" + Boolean.toString(useSSL));
    if (useSSL) {
        args.add("-Dcom.sun.management.jmxremote.registry.ssl=true");
        args.add("-Djavax.net.ssl.keyStore=" + KEYSTORE_LOC);
        args.add("-Djavax.net.ssl.trustStore=" + TRUSTSTORE_LOC);
        args.add("-Djavax.net.ssl.keyStorePassword=password");
        args.add("-Djavax.net.ssl.trustStorePassword=trustword");
    }
    args.add(TEST_CLASS);
    args.add(address);
    args.add(Integer.toString(JMX_PORT));
    args.add(Integer.toString(RMI_PORT));
    args.add(Boolean.toString(useSSL));
    try {
        ProcessBuilder builder = ProcessTools.createJavaProcessBuilder(args.toArray(new String[] {}));
        System.out.println(ProcessTools.getCommandLine(builder));
        TestProcessThread jvm = new TestProcessThread("JMX-Tester-" + address, JMXInterfaceBindingTest::isJMXAgentResponseAvailable, builder);
        return jvm;
    } catch (Exception e) {
        throw new RuntimeException("Test failed", e);
    }

}
 
Example 20
Source File: RunnerUtil.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * The Application process must be run concurrently with our tests since
 * the tests will attach to the Application.
 * We will run the Application process in a separate thread.
 *
 * The Application must be started with flag "-Xshare:off" for the Retransform
 * test in TestBasics to pass on all platforms.
 *
 * The Application will write its pid and shutdownPort in the given outFile.
 */
public static ProcessThread startApplication(String outFile) throws Throwable {
    String classpath = System.getProperty("test.class.path", ".");
    String[] args = Utils.addTestJavaOpts(
        "-Dattach.test=true", "-classpath", classpath, "Application", outFile);
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);
    ProcessThread pt = new ProcessThread("runApplication", pb);
    pt.start();
    return pt;
}