diff --git a/jdk/test/com/sun/jdi/DoubleAgentTest.java b/jdk/test/com/sun/jdi/DoubleAgentTest.java index 3568f436ac1..0a0b5e8dcae 100644 --- a/jdk/test/com/sun/jdi/DoubleAgentTest.java +++ b/jdk/test/com/sun/jdi/DoubleAgentTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -21,136 +21,39 @@ * questions. */ +import jdk.testlibrary.OutputAnalyzer; +import jdk.testlibrary.ProcessTools; +import jdk.testlibrary.Utils; + /* @test * @bug 6354345 - * @summary Check that a double agent request fails + * @summary Check that multiple -agentlib statements in command line fails * - * @build VMConnection DoubleAgentTest Exit0 + * @library /lib/testlibrary + * @build jdk.testlibarary.* + * @build DoubleAgentTest Exit0 * @run driver DoubleAgentTest - * */ -import java.io.InputStream; -import java.io.IOException; -import java.io.File; -import java.net.ServerSocket; public class DoubleAgentTest { - static Object locker = new Object(); - static String outputText = ""; + private static final String TEST_CLASSES = System.getProperty( + "test.classes", "."); - /* - * Helper class to redirect process output/error - */ - static class IOHandler implements Runnable { - InputStream in; + public static void main(String[] args) throws Throwable { + int port = Utils.getFreePort(); - IOHandler(InputStream in) { - this.in = in; - } - - static Thread handle(InputStream in) { - IOHandler handler = new IOHandler(in); - Thread thr = new Thread(handler); - thr.setDaemon(true); - thr.start(); - return thr; - } - - public void run() { - try { - byte b[] = new byte[100]; - for (;;) { - int n = in.read(b, 0, 100); - // 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. - synchronized(locker) { - locker.notify(); - } - if (n < 0) { - break; - } - String s = new String(b, 0, n, "UTF-8"); - System.out.print(s); - synchronized(outputText) { - outputText += s; - } - } - } catch (IOException ioe) { - ioe.printStackTrace(); - } - } - - } - - /* - * Launch a server debuggee with the given address - */ - private static Process launch(String address, String class_name) throws IOException { - String exe = System.getProperty("java.home") - + File.separator + "bin" + File.separator + "java"; String jdwpOption = "-agentlib:jdwp=transport=dt_socket" - + ",server=y" + ",suspend=y" + ",address=" + address; - String cmd = exe + " " + VMConnection.getDebuggeeVMOptions() - + " " + jdwpOption - + " " + jdwpOption - + " " + class_name; + + ",server=y" + ",suspend=n" + ",address=*:" + String.valueOf(port); - System.out.println("Starting: " + cmd); - - Process p = Runtime.getRuntime().exec(cmd); - - return p; - } - - /* - * - pick a TCP port - * - Launch a server debuggee that should fail - * - verify we saw error - */ - public static void main(String args[]) throws Exception { - // find a free port - ServerSocket ss = new ServerSocket(0); - int port = ss.getLocalPort(); - ss.close(); - - String address = String.valueOf(port); - - // launch the server debuggee - Process process = launch(address, "Exit0"); - Thread t1 = IOHandler.handle(process.getInputStream()); - Thread t2 = IOHandler.handle(process.getErrorStream()); - - // wait for the debugge to be ready - synchronized(locker) { - locker.wait(); - } - - int exitCode = process.waitFor(); - try { - t1.join(); - t2.join(); - } catch ( InterruptedException e ) { - e.printStackTrace(); - throw new Exception("Debuggee failed InterruptedException"); - } - - if ( outputText.contains("capabilities") ) { - throw new Exception( - "Debuggee failed with ERROR about capabilities: " + outputText); - } - - if ( !outputText.contains("ERROR") ) { - throw new Exception( - "Debuggee does not have ERROR in the output: " + outputText); - } - - if ( exitCode == 0 ) { - throw new Exception( - "Debuggee should have failed with an non-zero exit code"); - } + OutputAnalyzer output = ProcessTools.executeTestJvm("-classpath", + TEST_CLASSES, + jdwpOption, // Notice jdwpOption specified twice + jdwpOption, + "Exit0"); + output.shouldContain("Cannot load this JVM TI agent twice"); + output.shouldHaveExitValue(1); } }