jdk.testlibrary.Utils Java Examples

The following examples show how to use jdk.testlibrary.Utils. 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: 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 #2
Source File: ClipboardInterVMTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void runTest(String main, String... args)  {

        try {
            List<String> opts = new ArrayList<>();
            opts.add(getJavaExe());
            opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
            opts.add("-cp");
            opts.add(System.getProperty("test.class.path", System.getProperty("java.class.path")));

            opts.add(main);
            opts.addAll(Arrays.asList(args));

            ProcessBuilder pb = new ProcessBuilder(opts.toArray(new String[0]));
            process = pb.start();
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }
 
Example #3
Source File: DynamicLauncher.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void run() throws Exception {
    OutputAnalyzer out;
    int retries = 1;
    boolean tryAgain;

    do {
        tryAgain = false;
        jmxPort = Utils.getFreePort();
        out = runVM();
        try {
            out.shouldNotContain("Port already in use");
        } catch (RuntimeException e) {
            if (retries < 3) {
                retries++;
                tryAgain = true;
            }
        }
    } while (tryAgain);
}
 
Example #4
Source File: DynamicLauncher.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void run() throws Exception {
    OutputAnalyzer out;
    int retries = 1;
    boolean tryAgain;

    do {
        tryAgain = false;
        jmxPort = Utils.getFreePort();
        out = runVM();
        try {
            out.shouldNotContain("Port already in use");
        } catch (RuntimeException e) {
            if (retries < 3) {
                retries++;
                tryAgain = true;
            }
        }
    } while (tryAgain);
}
 
Example #5
Source File: PremainClassTest.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:%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 #6
Source File: NoPremainAgentTest.java    From openjdk-8-source 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 #7
Source File: JstatdTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies output form jps contains pids and programs' name information.
 * The function will discard any lines that come before the first line with pid.
 * This can happen if the JVM outputs a warning message for some reason
 * before running jps.
 *
 * The output can look like:
 * 35536 Jstatd
 * 35417 Main
 * 31103 org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
 */
private void verifyJpsOutput(OutputAnalyzer output) throws Exception {
    output.shouldHaveExitValue(0);
    assertFalse(output.getOutput().isEmpty(), "Output should not be empty");

    boolean foundFirstLineWithPid = false;
    String[] lines = output.getOutput().split(Utils.NEW_LINE);
    for (String line : lines) {
        if (!foundFirstLineWithPid) {
            foundFirstLineWithPid = line.matches(JPS_OUTPUT_REGEX);
            continue;
        }
        assertTrue(line.matches(JPS_OUTPUT_REGEX),
                "Output does not match the pattern" + Utils.NEW_LINE + line);
    }
    assertTrue(foundFirstLineWithPid, "Invalid output");
}
 
Example #8
Source File: RunUtil.java    From hottub 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 #9
Source File: JstatdTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse pid from jps output
 */
private String parsePid(String tool, OutputAnalyzer output) throws Exception {
    String[] lines = output.getOutput().split(Utils.NEW_LINE);
    String pid = null;
    int count = 0;
    String processName = tool;
    if (tool == "rmiregistry") {
        processName = "registryimpl";
    }

    Pattern toolInJpsPattern =
            Pattern.compile("^\\d+\\s{1}" + processName + "\\s{1}.*-dparent\\.pid\\." + ProcessTools.getProcessId() + ".*");
    for (String line : lines) {
        if (toolInJpsPattern.matcher(line.toLowerCase()).matches()) {
            pid = line.split(" ")[0];
            count++;
        }
    }
    if (count > 1) {
        throw new Exception("Expected one " + tool
                + " process, got " + count + ". Test will be canceled.");
    }

    return pid;
}
 
Example #10
Source File: JMXStartStopTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void testConnect(int port, int rmiPort) throws Exception {
    EOFException lastException = null;
    // factor adjusted timeout (5 seconds) for the RMI to become available
    long timeout = System.currentTimeMillis() + Utils.adjustTimeout(5000);
    do {
        try {
            doTestConnect(port, rmiPort);
            lastException = null;
        } catch (EOFException e) {
            lastException = e;
            System.out.println("Error establishing RMI connection. Retrying in 500ms.");
            Thread.sleep(500);
        }
    } while (lastException != null && System.currentTimeMillis() < timeout);

    if (lastException != null) {
        // didn't manage to get the RMI running in time
        // rethrow the exception
        throw lastException;
    }
}
 
Example #11
Source File: MethodResultTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static JMXConnector connect(JMXServiceURL addr) {
    final long timeout = Utils.adjustTimeout(100);

    JMXConnector connector = null;
    while (connector == null) {
        try {
            connector = JMXConnectorFactory.connect(addr);
        } catch (IOException e) {
            System.out.println("Connection error. Retrying after delay...");
            delay(timeout);
        } catch (Exception otherException) {
            System.out.println("Unexpected exception while connecting " + otherException);
            throw new RuntimeException(otherException);
        }
    }
    return connector;
}
 
Example #12
Source File: ClipboardInterVMTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static void runTest(String main, String... args)  {

        try {
            List<String> opts = new ArrayList<>();
            opts.add(getJavaExe());
            opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
            opts.add("-cp");
            opts.add(System.getProperty("test.class.path", System.getProperty("java.class.path")));

            opts.add(main);
            opts.addAll(Arrays.asList(args));

            ProcessBuilder pb = new ProcessBuilder(opts.toArray(new String[0]));
            process = pb.start();
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }
 
Example #13
Source File: ClipboardInterVMTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void runTest(String main, String... args)  {

        try {
            List<String> opts = new ArrayList<>();
            opts.add(getJavaExe());
            opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
            opts.add("-cp");
            opts.add(System.getProperty("test.class.path", System.getProperty("java.class.path")));

            opts.add(main);
            opts.addAll(Arrays.asList(args));

            ProcessBuilder pb = new ProcessBuilder(opts.toArray(new String[0]));
            process = pb.start();
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }
 
Example #14
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 #15
Source File: DynamicLauncher.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected void run() throws Exception {
    OutputAnalyzer out;
    int retries = 1;
    boolean tryAgain;

    do {
        tryAgain = false;
        jmxPort = Utils.getFreePort();
        out = runVM();
        try {
            out.shouldNotContain("Port already in use");
        } catch (RuntimeException e) {
            if (retries < 3) {
                retries++;
                tryAgain = true;
            }
        }
    } while (tryAgain);
}
 
Example #16
Source File: DynamicLauncher.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void run() throws Exception {
    OutputAnalyzer out;
    int retries = 1;
    boolean tryAgain;

    do {
        tryAgain = false;
        jmxPort = Utils.getFreePort();
        out = runVM();
        try {
            out.shouldNotContain("Port already in use");
        } catch (RuntimeException e) {
            if (retries < 3) {
                retries++;
                tryAgain = true;
            }
        }
    } while (tryAgain);
}
 
Example #17
Source File: JstatdTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies output form jps contains pids and programs' name information.
 * The function will discard any lines that come before the first line with pid.
 * This can happen if the JVM outputs a warning message for some reason
 * before running jps.
 *
 * The output can look like:
 * 35536 Jstatd
 * 35417 Main
 * 31103 org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
 */
private void verifyJpsOutput(OutputAnalyzer output) throws Exception {
    output.shouldHaveExitValue(0);
    assertFalse(output.getOutput().isEmpty(), "Output should not be empty");

    boolean foundFirstLineWithPid = false;
    String[] lines = output.getOutput().split(Utils.NEW_LINE);
    for (String line : lines) {
        if (!foundFirstLineWithPid) {
            foundFirstLineWithPid = line.matches(JPS_OUTPUT_REGEX);
            continue;
        }
        assertTrue(line.matches(JPS_OUTPUT_REGEX),
                "Output does not match the pattern" + Utils.NEW_LINE + line);
    }
    assertTrue(foundFirstLineWithPid, "Invalid output");
}
 
Example #18
Source File: JstatdTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies output form jps contains pids and programs' name information.
 * The function will discard any lines that come before the first line with pid.
 * This can happen if the JVM outputs a warning message for some reason
 * before running jps.
 *
 * The output can look like:
 * 35536 Jstatd
 * 35417 Main
 * 31103 org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
 */
private void verifyJpsOutput(OutputAnalyzer output) throws Exception {
    output.shouldHaveExitValue(0);
    assertFalse(output.getOutput().isEmpty(), "Output should not be empty");

    boolean foundFirstLineWithPid = false;
    String[] lines = output.getOutput().split(Utils.NEW_LINE);
    for (String line : lines) {
        if (!foundFirstLineWithPid) {
            foundFirstLineWithPid = line.matches(JPS_OUTPUT_REGEX);
            continue;
        }
        assertTrue(line.matches(JPS_OUTPUT_REGEX),
                "Output does not match the pattern" + Utils.NEW_LINE + line);
    }
    assertTrue(foundFirstLineWithPid, "Invalid output");
}
 
Example #19
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 #20
Source File: NoPremainAgentTest.java    From jdk8u60 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 #21
Source File: PremainClassTest.java    From jdk8u60 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 #22
Source File: JstatdTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies output form jps contains pids and programs' name information.
 * The function will discard any lines that come before the first line with pid.
 * This can happen if the JVM outputs a warning message for some reason
 * before running jps.
 *
 * The output can look like:
 * 35536 Jstatd
 * 35417 Main
 * 31103 org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
 */
private void verifyJpsOutput(OutputAnalyzer output) throws Exception {
    output.shouldHaveExitValue(0);
    assertFalse(output.getOutput().isEmpty(), "Output should not be empty");

    boolean foundFirstLineWithPid = false;
    String[] lines = output.getOutput().split(Utils.NEW_LINE);
    for (String line : lines) {
        if (!foundFirstLineWithPid) {
            foundFirstLineWithPid = line.matches(JPS_OUTPUT_REGEX);
            continue;
        }
        assertTrue(line.matches(JPS_OUTPUT_REGEX),
                "Output does not match the pattern" + Utils.NEW_LINE + line);
    }
    assertTrue(foundFirstLineWithPid, "Invalid output");
}
 
Example #23
Source File: RunUtil.java    From jdk8u60 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 #24
Source File: DynamicLauncher.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected void run() throws Exception {
    OutputAnalyzer out;
    int retries = 1;
    boolean tryAgain;

    do {
        tryAgain = false;
        jmxPort = Utils.getFreePort();
        out = runVM();
        try {
            out.shouldNotContain("Port already in use");
        } catch (RuntimeException e) {
            if (retries < 3) {
                retries++;
                tryAgain = true;
            }
        }
    } while (tryAgain);
}
 
Example #25
Source File: ClipboardInterVMTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void runTest(String main, String... args)  {

        try {
            List<String> opts = new ArrayList<>();
            opts.add(getJavaExe());
            opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
            opts.add("-cp");
            opts.add(System.getProperty("test.class.path", System.getProperty("java.class.path")));

            opts.add(main);
            opts.addAll(Arrays.asList(args));

            ProcessBuilder pb = new ProcessBuilder(opts.toArray(new String[0]));
            process = pb.start();
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }
 
Example #26
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 #27
Source File: PremainClassTest.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:%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 #28
Source File: ZeroArgPremainAgentTest.java    From openjdk-jdk8u 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 #29
Source File: RunUtil.java    From jdk8u-dev-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 #30
Source File: PortAlreadyInUseTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected void go() throws Exception {
    jmxPort = Utils.getFreePort();
    occupyPort();

    log.info("Attempting to start a VM using the same port.");
    OutputAnalyzer out = this.runVM();
    out.shouldContain("Port already in use");
    log.info("Failed as expected.");

    log.info("Trying again using retries.");
    this.run();
}