aboutsummaryrefslogtreecommitdiff
path: root/test/com
diff options
context:
space:
mode:
authorkvn <none@none>2014-02-19 20:10:55 -0800
committerkvn <none@none>2014-02-19 20:10:55 -0800
commit63c416c9d21e2da3e6ba459aeab85283be69810d (patch)
treeda2f131b9d41155851b00bf18c3e3481afea7f17 /test/com
parent2212d0b149f8e11b4bc77d1108e1fb196e07be10 (diff)
parent6bfb38f9adaf2188d2e3940e517ea136ceffeb22 (diff)
Merge
Diffstat (limited to 'test/com')
-rw-r--r--test/com/sun/jdi/BadHandshakeTest.java4
-rw-r--r--test/com/sun/jdi/ExclusiveBind.java90
2 files changed, 34 insertions, 60 deletions
diff --git a/test/com/sun/jdi/BadHandshakeTest.java b/test/com/sun/jdi/BadHandshakeTest.java
index 8e35442eb..35afb3356 100644
--- a/test/com/sun/jdi/BadHandshakeTest.java
+++ b/test/com/sun/jdi/BadHandshakeTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -85,7 +85,7 @@ public class BadHandshakeTest {
success.set(line.contains("Listening for transport dt_socket at address:"));
return true;
},
- 1500,
+ Integer.MAX_VALUE,
TimeUnit.MILLISECONDS
);
diff --git a/test/com/sun/jdi/ExclusiveBind.java b/test/com/sun/jdi/ExclusiveBind.java
index 3389ee220..d53efd8d5 100644
--- a/test/com/sun/jdi/ExclusiveBind.java
+++ b/test/com/sun/jdi/ExclusiveBind.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 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
@@ -25,57 +25,28 @@
* @bug 4531526
* @summary Test that more than one debuggee cannot bind to same port
* at the same time.
+ * @library /lib/testlibrary
*
+ * @build jdk.testlibrary.ProcessTools jdk.testlibrary.JDKToolLauncher jdk.testlibrary.Utils
* @build VMConnection ExclusiveBind HelloWorld
* @run main ExclusiveBind
*/
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.File;
import java.net.ServerSocket;
import com.sun.jdi.Bootstrap;
import com.sun.jdi.VirtualMachine;
import com.sun.jdi.connect.Connector;
import com.sun.jdi.connect.AttachingConnector;
+
+import java.util.ArrayList;
import java.util.Map;
import java.util.List;
import java.util.Iterator;
+import java.util.concurrent.TimeUnit;
-public class ExclusiveBind {
-
- /*
- * Helper class to direct process output to the parent
- * System.out
- */
- static class IOHandler implements Runnable {
- InputStream in;
-
- IOHandler(InputStream in) {
- this.in = in;
- }
-
- static void handle(InputStream in) {
- IOHandler handler = new IOHandler(in);
- Thread thr = new Thread(handler);
- thr.setDaemon(true);
- thr.start();
- }
-
- public void run() {
- try {
- byte b[] = new byte[100];
- for (;;) {
- int n = in.read(b);
- if (n < 0) return;
- for (int i=0; i<n; i++) {
- System.out.print((char)b[i]);
- }
- }
- } catch (IOException ioe) { }
- }
-
- }
+import jdk.testlibrary.ProcessTools;
+import jdk.testlibrary.Utils;
+public class ExclusiveBind {
/*
* Find a connector by name
*/
@@ -95,25 +66,23 @@ public class ExclusiveBind {
* Launch (in server mode) a debuggee with the given address and
* suspend mode.
*/
- private static Process launch(String address, boolean suspend, String class_name) throws IOException {
- String exe = System.getProperty("java.home") + File.separator + "bin" +
- File.separator + "java";
- String cmd = exe + " " + VMConnection.getDebuggeeVMOptions() +
- " -agentlib:jdwp=transport=dt_socket,server=y,suspend=";
+ 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) {
- cmd += "y";
+ lib += "y";
} else {
- cmd += "n";
+ lib += "n";
}
- cmd += ",address=" + address + " " + class_name;
+ lib += ",address=" + address;
- System.out.println("Starting: " + cmd);
+ args.add(lib);
+ args.add(class_name);
- Process p = Runtime.getRuntime().exec(cmd);
- IOHandler.handle(p.getInputStream());
- IOHandler.handle(p.getErrorStream());
-
- return p;
+ return ProcessTools.createJavaProcessBuilder(args.toArray(new String[args.size()]));
}
/*
@@ -132,16 +101,21 @@ public class ExclusiveBind {
String address = String.valueOf(port);
// launch the first debuggee
- Process process1 = launch(address, true, "HelloWorld");
-
- // give first debuggee time to suspend
- Thread.currentThread().sleep(5000);
+ ProcessBuilder process1 = prepareLauncher(address, true, "HelloWorld");
+ // start the debuggee and wait for the "ready" message
+ Process p = ProcessTools.startProcess(
+ "process1",
+ process1,
+ line -> line.equals("Listening for transport dt_socket at address: " + address),
+ Math.round(5000 * Utils.TIMEOUT_FACTOR),
+ TimeUnit.MILLISECONDS
+ );
// launch a second debuggee with the same address
- Process process2 = launch(address, false, "HelloWorld");
+ ProcessBuilder process2 = prepareLauncher(address, false, "HelloWorld");
// get exit status from second debuggee
- int exitCode = process2.waitFor();
+ int exitCode = ProcessTools.startProcess("process2", process2).waitFor();
// clean-up - attach to first debuggee and resume it
AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");