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

The following examples show how to use jdk.testlibrary.ProcessTools#executeTestJvm() . 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: BasicTests.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the actual tests in nested class TestMain.
 * The reason for running the tests in a separate process
 * is that we need to modify the class path.
 */
private static void runTests(int pid) throws Throwable {
    final String sep = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";
    String testClassDir = System.getProperty("test.classes", "") + sep;

    // Argumenta : -classpath cp BasicTests$TestMain pid agent badagent redefineagent
    String[] args = {
        "-classpath",
        classpath,
        "BasicTests$TestMain",
        Integer.toString(pid),
        testClassDir + "Agent.jar",
        testClassDir + "BadAgent.jar",
        testClassDir + "RedefineAgent.jar" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 2
Source File: BasicTests.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the actual tests in nested class TestMain.
 * The reason for running the tests in a separate process
 * is that we need to modify the class path.
 */
private static void runTests(int pid) throws Throwable {
    final String sep = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";
    String testClassDir = System.getProperty("test.classes", "") + sep;

    // Argumenta : -classpath cp BasicTests$TestMain pid agent badagent redefineagent
    String[] args = {
        "-classpath",
        classpath,
        "BasicTests$TestMain",
        Integer.toString(pid),
        testClassDir + "Agent.jar",
        testClassDir + "BadAgent.jar",
        testClassDir + "RedefineAgent.jar" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 3
Source File: RunnerUtil.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Will stop the running Application.
 * First tries to shutdown nicely by connecting to the shut down port.
 * If that fails, the process will be killed hard with stopProcess().
 *
 * If the nice shutdown fails, then an Exception is thrown and the test should fail.
 *
 * @param port The shut down port.
 * @param processThread The process to stop.
 */
public static void stopApplication(int port, ProcessThread processThread) throws Throwable {
    if (processThread == null) {
        System.out.println("RunnerUtil.stopApplication ignored since proc is null");
        return;
    }
    try {
        System.out.println("RunnerUtil.stopApplication waiting to for shutdown");
        OutputAnalyzer output = ProcessTools.executeTestJvm(
                "-classpath",
                System.getProperty("test.class.path", "."),
                "Shutdown",
                Integer.toString(port));
        // Verify that both the Shutdown command and the Application finished ok.
        output.shouldHaveExitValue(0);
        processThread.joinAndThrow();
        processThread.getOutput().shouldHaveExitValue(0);
    } catch (Throwable t) {
        System.out.println("RunnerUtil.stopApplication failed. Will kill it hard: " + t);
        processThread.stopProcess();
        throw t;
    }
}
 
Example 4
Source File: ProviderTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the actual tests in the nested class TestMain.
 * We need to run the tests in a separate process,
 * because we need to add to the classpath.
 */
private static void runTests() throws Throwable {
    final String sep = File.separator;
    String testClassPath = System.getProperty("test.class.path", "");
    String testClasses = System.getProperty("test.classes", "") + sep;
    String jdkLib = System.getProperty("test.jdk", ".") + sep + "lib" + sep;

    // Need to add SimpleProvider.jar and tools.jar to classpath.
    String classpath =
            testClassPath + File.pathSeparator +
            testClasses + "SimpleProvider.jar" + File.pathSeparator +
            jdkLib + "tools.jar";

    String[] args = {
            "-classpath",
            classpath,
            "ProviderTest$TestMain" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 5
Source File: ProviderTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the actual tests in the nested class TestMain.
 * We need to run the tests in a separate process,
 * because we need to add to the classpath.
 */
private static void runTests() throws Throwable {
    final String sep = File.separator;
    String testClassPath = System.getProperty("test.class.path", "");
    String testClasses = System.getProperty("test.classes", "") + sep;
    String jdkLib = System.getProperty("test.jdk", ".") + sep + "lib" + sep;

    // Need to add SimpleProvider.jar and tools.jar to classpath.
    String classpath =
            testClassPath + File.pathSeparator +
            testClasses + "SimpleProvider.jar" + File.pathSeparator +
            jdkLib + "tools.jar";

    String[] args = {
            "-classpath",
            classpath,
            "ProviderTest$TestMain" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 6
Source File: RunnerUtil.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Will stop the running Application.
 * First tries to shutdown nicely by connecting to the shut down port.
 * If that fails, the process will be killed hard with stopProcess().
 *
 * If the nice shutdown fails, then an Exception is thrown and the test should fail.
 *
 * @param port The shut down port.
 * @param processThread The process to stop.
 */
public static void stopApplication(int port, ProcessThread processThread) throws Throwable {
    if (processThread == null) {
        System.out.println("RunnerUtil.stopApplication ignored since proc is null");
        return;
    }
    try {
        System.out.println("RunnerUtil.stopApplication waiting to for shutdown");
        OutputAnalyzer output = ProcessTools.executeTestJvm(
                "-classpath",
                System.getProperty("test.class.path", "."),
                "Shutdown",
                Integer.toString(port));
        // Verify that both the Shutdown command and the Application finished ok.
        output.shouldHaveExitValue(0);
        processThread.joinAndThrow();
        processThread.getOutput().shouldHaveExitValue(0);
    } catch (Throwable t) {
        System.out.println("RunnerUtil.stopApplication failed. Will kill it hard: " + t);
        processThread.stopProcess();
        throw t;
    }
}
 
Example 7
Source File: RunnerUtil.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Will stop the running Application.
 * First tries to shutdown nicely by connecting to the shut down port.
 * If that fails, the process will be killed hard with stopProcess().
 *
 * If the nice shutdown fails, then an Exception is thrown and the test should fail.
 *
 * @param port The shut down port.
 * @param processThread The process to stop.
 */
public static void stopApplication(int port, ProcessThread processThread) throws Throwable {
    if (processThread == null) {
        System.out.println("RunnerUtil.stopApplication ignored since proc is null");
        return;
    }
    try {
        System.out.println("RunnerUtil.stopApplication waiting to for shutdown");
        OutputAnalyzer output = ProcessTools.executeTestJvm(
                "-classpath",
                System.getProperty("test.class.path", "."),
                "Shutdown",
                Integer.toString(port));
        // Verify that both the Shutdown command and the Application finished ok.
        output.shouldHaveExitValue(0);
        processThread.joinAndThrow();
        processThread.getOutput().shouldHaveExitValue(0);
    } catch (Throwable t) {
        System.out.println("RunnerUtil.stopApplication failed. Will kill it hard: " + t);
        processThread.stopProcess();
        throw t;
    }
}
 
Example 8
Source File: BasicTests.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the actual tests in nested class TestMain.
 * The reason for running the tests in a separate process
 * is that we need to modify the class path.
 */
private static void runTests(int pid) throws Throwable {
    final String sep = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";
    String testClassDir = System.getProperty("test.classes", "") + sep;

    // Argumenta : -classpath cp BasicTests$TestMain pid agent badagent redefineagent
    String[] args = {
        "-classpath",
        classpath,
        "BasicTests$TestMain",
        Integer.toString(pid),
        testClassDir + "Agent.jar",
        testClassDir + "BadAgent.jar",
        testClassDir + "RedefineAgent.jar" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 9
Source File: ProviderTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the actual tests in the nested class TestMain.
 * We need to run the tests in a separate process,
 * because we need to add to the classpath.
 */
private static void runTests() throws Throwable {
    final String sep = File.separator;
    String testClassPath = System.getProperty("test.class.path", "");
    String testClasses = System.getProperty("test.classes", "") + sep;
    String jdkLib = System.getProperty("test.jdk", ".") + sep + "lib" + sep;

    // Need to add SimpleProvider.jar to classpath.
    String classpath =
            testClassPath + File.pathSeparator +
            testClasses + "SimpleProvider.jar";

    String[] args = {
            "-classpath",
            classpath,
            "ProviderTest$TestMain" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 10
Source File: ProviderTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the actual tests in the nested class TestMain.
 * We need to run the tests in a separate process,
 * because we need to add to the classpath.
 */
private static void runTests() throws Throwable {
    final String sep = File.separator;
    String testClassPath = System.getProperty("test.class.path", "");
    String testClasses = System.getProperty("test.classes", "") + sep;
    String jdkLib = System.getProperty("test.jdk", ".") + sep + "lib" + sep;

    // Need to add SimpleProvider.jar and tools.jar to classpath.
    String classpath =
            testClassPath + File.pathSeparator +
            testClasses + "SimpleProvider.jar" + File.pathSeparator +
            jdkLib + "tools.jar";

    String[] args = {
            "-classpath",
            classpath,
            "ProviderTest$TestMain" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 11
Source File: TempDirTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the actual tests in nested class TestMain.
 * The reason for running the tests in a separate process
 * is that we need to modify the class path and
 * the -Djava.io.tmpdir property.
 */
private static void launchTests(int pid, Path clientTmpDir) throws Throwable {
    final String sep = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";

    String[] tmpDirArg = null;
    if (clientTmpDir != null) {
        tmpDirArg = new String [] {"-Djava.io.tmpdir=" + clientTmpDir};
    }

    // Arguments : [-Djava.io.tmpdir=] -classpath cp TempDirTest$TestMain pid
    String[] args = RunnerUtil.concat(
            tmpDirArg,
            new String[] {
                "-classpath",
                classpath,
                "TempDirTest$TestMain",
                Integer.toString(pid) });
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 12
Source File: BasicTests.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the actual tests in nested class TestMain.
 * The reason for running the tests in a separate process
 * is that we need to modify the class path.
 */
private static void runTests(int pid) throws Throwable {
    final String sep = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";
    String testClassDir = System.getProperty("test.classes", "") + sep;

    // Argumenta : -classpath cp BasicTests$TestMain pid agent badagent redefineagent
    String[] args = {
        "-classpath",
        classpath,
        "BasicTests$TestMain",
        Integer.toString(pid),
        testClassDir + "Agent.jar",
        testClassDir + "BadAgent.jar",
        testClassDir + "RedefineAgent.jar" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 13
Source File: TempDirTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the actual tests in nested class TestMain.
 * The reason for running the tests in a separate process
 * is that we need to modify the class path and
 * the -Djava.io.tmpdir property.
 */
private static void launchTests(int pid, Path clientTmpDir) throws Throwable {
    final String sep = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";

    String[] tmpDirArg = null;
    if (clientTmpDir != null) {
        tmpDirArg = new String [] {"-Djava.io.tmpdir=" + clientTmpDir};
    }

    // Arguments : [-Djava.io.tmpdir=] -classpath cp TempDirTest$TestMain pid
    String[] args = RunnerUtil.concat(
            tmpDirArg,
            new String[] {
                "-classpath",
                classpath,
                "TempDirTest$TestMain",
                Integer.toString(pid) });
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 14
Source File: BasicTests.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the actual tests in nested class TestMain.
 * The reason for running the tests in a separate process
 * is that we need to modify the class path.
 */
private static void runTests(int pid) throws Throwable {
    final String sep = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";
    String testClassDir = System.getProperty("test.classes", "") + sep;

    // Argumenta : -classpath cp BasicTests$TestMain pid agent badagent redefineagent
    String[] args = {
        "-classpath",
        classpath,
        "BasicTests$TestMain",
        Integer.toString(pid),
        testClassDir + "Agent.jar",
        testClassDir + "BadAgent.jar",
        testClassDir + "RedefineAgent.jar" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 15
Source File: TempDirTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the actual tests in nested class TestMain.
 * The reason for running the tests in a separate process
 * is that we need to modify the class path and
 * the -Djava.io.tmpdir property.
 */
private static void launchTests(int pid, Path clientTmpDir) throws Throwable {
    final String sep = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";

    String[] tmpDirArg = null;
    if (clientTmpDir != null) {
        tmpDirArg = new String [] {"-Djava.io.tmpdir=" + clientTmpDir};
    }

    // Arguments : [-Djava.io.tmpdir=] -classpath cp TempDirTest$TestMain pid
    String[] args = RunnerUtil.concat(
            tmpDirArg,
            new String[] {
                "-classpath",
                classpath,
                "TempDirTest$TestMain",
                Integer.toString(pid) });
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 16
Source File: TempDirTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the actual tests in nested class TestMain.
 * The reason for running the tests in a separate process
 * is that we need to modify the class path and
 * the -Djava.io.tmpdir property.
 */
private static void launchTests(int pid, Path clientTmpDir) throws Throwable {
    final String sep = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";

    String[] tmpDirArg = null;
    if (clientTmpDir != null) {
        tmpDirArg = new String [] {"-Djava.io.tmpdir=" + clientTmpDir};
    }

    // Arguments : [-Djava.io.tmpdir=] -classpath cp TempDirTest$TestMain pid
    String[] args = RunnerUtil.concat(
            tmpDirArg,
            new String[] {
                "-classpath",
                classpath,
                "TempDirTest$TestMain",
                Integer.toString(pid) });
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 17
Source File: PermissionTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Runs the actual test the nested class TestMain.
 * The test is run in a separate process because we need to add to the classpath.
 */
private static void runTests(int pid) throws Throwable {
    final String sep = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";
    String testSrc = System.getProperty("test.src", "") + sep;

    // Use a policy that will NOT allow attach. Test will verify exception.
    String[] args = {
        "-classpath",
        classpath,
        "-Djava.security.manager",
        String.format("-Djava.security.policy=%sjava.policy.deny", testSrc),
        "PermissionTest$TestMain",
        Integer.toString(pid),
        "true" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);

    // Use a policy that will allow attach.
    args = new String[] {
        "-classpath",
        classpath,
        "-Djava.security.manager",
        String.format("-Djava.security.policy=%sjava.policy.allow", testSrc),
        "PermissionTest$TestMain",
        Integer.toString(pid),
        "false" };
    output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 18
Source File: PermissionTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Runs the actual test the nested class TestMain.
 * The test is run in a separate process because we need to add to the classpath.
 */
private static void runTests(int pid) throws Throwable {
    final String sep = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";
    String testSrc = System.getProperty("test.src", "") + sep;

    // Use a policy that will NOT allow attach. Test will verify exception.
    String[] args = {
        "-classpath",
        classpath,
        "-Djava.security.manager",
        String.format("-Djava.security.policy=%sjava.policy.deny", testSrc),
        "PermissionTest$TestMain",
        Integer.toString(pid),
        "true" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);

    // Use a policy that will allow attach.
    args = new String[] {
        "-classpath",
        classpath,
        "-Djava.security.manager",
        String.format("-Djava.security.policy=%sjava.policy.allow", testSrc),
        "PermissionTest$TestMain",
        Integer.toString(pid),
        "false" };
    output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 19
Source File: PermissionTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Runs the actual test the nested class TestMain.
 * The test is run in a separate process because we need to add to the classpath.
 */
private static void runTests(int pid) throws Throwable {
    final String sep = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";
    String testSrc = System.getProperty("test.src", "") + sep;

    // Use a policy that will NOT allow attach. Test will verify exception.
    String[] args = {
        "-classpath",
        classpath,
        "-Djava.security.manager",
        String.format("-Djava.security.policy=%sjava.policy.deny", testSrc),
        "PermissionTest$TestMain",
        Integer.toString(pid),
        "true" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);

    // Use a policy that will allow attach.
    args = new String[] {
        "-classpath",
        classpath,
        "-Djava.security.manager",
        String.format("-Djava.security.policy=%sjava.policy.allow", testSrc),
        "PermissionTest$TestMain",
        Integer.toString(pid),
        "false" };
    output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 20
Source File: PermissionTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Runs the actual test the nested class TestMain.
 * The test is run in a separate process because we need to add to the classpath.
 */
private static void runTests(int pid) throws Throwable {
    final String sep = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";
    String testSrc = System.getProperty("test.src", "") + sep;

    // Use a policy that will NOT allow attach. Test will verify exception.
    String[] args = {
        "-classpath",
        classpath,
        "-Djava.security.manager",
        String.format("-Djava.security.policy=%sjava.policy.deny", testSrc),
        "PermissionTest$TestMain",
        Integer.toString(pid),
        "true" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);

    // Use a policy that will allow attach.
    args = new String[] {
        "-classpath",
        classpath,
        "-Djava.security.manager",
        String.format("-Djava.security.policy=%sjava.policy.allow", testSrc),
        "PermissionTest$TestMain",
        Integer.toString(pid),
        "false" };
    output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}