Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8054066: com/sun/jdi/DoubleAgentTest.java fails with timeout #143

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 22 additions & 120 deletions jdk/test/com/sun/jdi/DoubleAgentTest.java
Original file line number Diff line number Diff line change
@@ -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,137 +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
*
* @build VMConnection DoubleAgentTest Exit0
* @run main DoubleAgentTest
* @summary Check that multiple -agentlib statements in command line fails
*
* @library /lib/testlibrary
* @build jdk.testlibrary.*
* @build DoubleAgentTest Exit0
* @run driver DoubleAgentTest
*/
import java.io.InputStream;
import java.io.IOException;
import java.io.File;
import java.net.ServerSocket;
import java.net.Socket;

public class DoubleAgentTest {

static Object locker = new Object();
static String outputText = "";

/*
* Helper class to redirect process output/error
*/
static class IOHandler implements Runnable {
InputStream in;

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;
}
private static final String TEST_CLASSES = System.getProperty(
"test.classes", ".");

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();
}
}
public static void main(String[] args) throws Throwable {
int port = Utils.getFreePort();

}

/*
* 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;

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);
}
+ ",server=y" + ",suspend=n" + ",address=*:" + String.valueOf(port);

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

}