author | iignatyev |
Fri, 14 Sep 2018 14:02:57 -0700 | |
changeset 51754 | 594919232b8f |
parent 51675 | b487c1e914d0 |
child 53929 | ca23d3475af0 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
51675 | 2 |
* Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
25 |
* @bug 4997445 |
|
26 |
* @summary Test that with server=y, when VM runs to System.exit() no error happens |
|
51675 | 27 |
* @library /test/lib |
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
29496
diff
changeset
|
28 |
* @modules java.management |
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
29496
diff
changeset
|
29 |
* jdk.jdi |
51675 | 30 |
* @build VMConnection RunToExit Exit0 |
24973
8c4bc3fa4c4e
6622468: TEST_BUG: Time to retire the @debuggeeVMOptions mechanism used in the com.sun.jdi infrastructure
sla
parents:
24514
diff
changeset
|
31 |
* @run driver RunToExit |
2 | 32 |
*/ |
33 |
import java.net.ServerSocket; |
|
34 |
import com.sun.jdi.Bootstrap; |
|
35 |
import com.sun.jdi.VirtualMachine; |
|
36 |
import com.sun.jdi.event.*; |
|
37 |
import com.sun.jdi.connect.Connector; |
|
38 |
import com.sun.jdi.connect.AttachingConnector; |
|
29496
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
39 |
import java.net.ConnectException; |
2 | 40 |
import java.util.Map; |
41 |
import java.util.List; |
|
42 |
import java.util.Iterator; |
|
29496
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
43 |
import java.util.concurrent.TimeUnit; |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
44 |
import java.util.stream.Collectors; |
51675 | 45 |
import jdk.test.lib.process.ProcessTools; |
2 | 46 |
|
47 |
public class RunToExit { |
|
48 |
||
49 |
/* Increment this when ERROR: seen */ |
|
29496
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
50 |
static volatile int error_seen = 0; |
2 | 51 |
static volatile boolean ready = false; |
52 |
||
53 |
/* |
|
54 |
* Find a connector by name |
|
55 |
*/ |
|
56 |
private static Connector findConnector(String name) { |
|
57 |
List connectors = Bootstrap.virtualMachineManager().allConnectors(); |
|
58 |
Iterator iter = connectors.iterator(); |
|
59 |
while (iter.hasNext()) { |
|
60 |
Connector connector = (Connector)iter.next(); |
|
61 |
if (connector.name().equals(name)) { |
|
62 |
return connector; |
|
63 |
} |
|
64 |
} |
|
65 |
return null; |
|
66 |
} |
|
67 |
||
68 |
/* |
|
69 |
* Launch a server debuggee with the given address |
|
70 |
*/ |
|
29496
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
71 |
private static Process launch(String address, String class_name) throws Exception { |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
72 |
String args[] = new String[]{ |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
73 |
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=" |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
74 |
+ address, |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
75 |
class_name |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
76 |
}; |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
77 |
args = VMConnection.insertDebuggeeVMOptions(args); |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
78 |
|
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
79 |
ProcessBuilder launcher = ProcessTools.createJavaProcessBuilder(args); |
2 | 80 |
|
29496
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
81 |
System.out.println(launcher.command().stream().collect(Collectors.joining(" ", "Starting: ", ""))); |
2 | 82 |
|
29496
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
83 |
Process p = ProcessTools.startProcess( |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
84 |
class_name, |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
85 |
launcher, |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
86 |
RunToExit::checkForError, |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
87 |
RunToExit::isTransportListening, |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
88 |
0, |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
89 |
TimeUnit.NANOSECONDS |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
90 |
); |
2 | 91 |
|
92 |
return p; |
|
93 |
} |
|
94 |
||
29496
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
95 |
private static boolean isTransportListening(String line) { |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
96 |
return line.startsWith("Listening for transport dt_socket"); |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
97 |
} |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
98 |
|
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
99 |
private static void checkForError(String line) { |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
100 |
if (line.contains("ERROR:")) { |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
101 |
error_seen++; |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
102 |
} |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
103 |
} |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
104 |
|
2 | 105 |
/* |
106 |
* - pick a TCP port |
|
107 |
* - Launch a server debuggee: server=y,suspend=y,address=${port} |
|
108 |
* - run it to VM death |
|
109 |
* - verify we saw no error |
|
110 |
*/ |
|
111 |
public static void main(String args[]) throws Exception { |
|
112 |
// find a free port |
|
113 |
ServerSocket ss = new ServerSocket(0); |
|
114 |
int port = ss.getLocalPort(); |
|
115 |
ss.close(); |
|
116 |
||
117 |
String address = String.valueOf(port); |
|
118 |
||
119 |
// launch the server debuggee |
|
120 |
Process process = launch(address, "Exit0"); |
|
121 |
||
122 |
// attach to server debuggee and resume it so it can exit |
|
123 |
AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach"); |
|
124 |
Map conn_args = conn.defaultArguments(); |
|
125 |
Connector.IntegerArgument port_arg = |
|
126 |
(Connector.IntegerArgument)conn_args.get("port"); |
|
127 |
port_arg.setValue(port); |
|
24514
2440b44952d7
8043716: JDI test com/sun/jdi/ProcessAttachTest.sh and other 3 jdi tests failed in nightly
dsamersoff
parents:
20201
diff
changeset
|
128 |
|
2440b44952d7
8043716: JDI test com/sun/jdi/ProcessAttachTest.sh and other 3 jdi tests failed in nightly
dsamersoff
parents:
20201
diff
changeset
|
129 |
System.out.println("Connection arguments: " + conn_args); |
2440b44952d7
8043716: JDI test com/sun/jdi/ProcessAttachTest.sh and other 3 jdi tests failed in nightly
dsamersoff
parents:
20201
diff
changeset
|
130 |
|
29496
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
131 |
VirtualMachine vm = null; |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
132 |
while (vm == null) { |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
133 |
try { |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
134 |
vm = conn.attach(conn_args); |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
135 |
} catch (ConnectException e) { |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
136 |
e.printStackTrace(System.out); |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
137 |
System.out.println("--- Debugee not ready. Retrying in 500ms. ---"); |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
138 |
Thread.sleep(500); |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
139 |
} |
728ed9492e63
8049696: com/sun/jdi/RunToExit fails with "ConnectException: Connection refused"
jbachorik
parents:
26963
diff
changeset
|
140 |
} |
2 | 141 |
|
142 |
// The first event is always a VMStartEvent, and it is always in |
|
143 |
// an EventSet by itself. Wait for it. |
|
144 |
EventSet evtSet = vm.eventQueue().remove(); |
|
145 |
for (Event event: evtSet) { |
|
146 |
if (event instanceof VMStartEvent) { |
|
147 |
break; |
|
148 |
} |
|
149 |
throw new RuntimeException("Test failed - debuggee did not start properly"); |
|
150 |
} |
|
151 |
vm.eventRequestManager().deleteAllBreakpoints(); |
|
152 |
vm.resume(); |
|
153 |
||
154 |
int exitCode = process.waitFor(); |
|
155 |
||
156 |
// if the server debuggee ran cleanly, we assume we were clean |
|
157 |
if (exitCode == 0 && error_seen == 0) { |
|
158 |
System.out.println("Test passed - server debuggee cleanly terminated"); |
|
159 |
} else { |
|
26963
a2a52f380463
8059105: Add better failure reporting to com/sun/jdi/RunToExit.java test
farvidsson
parents:
24973
diff
changeset
|
160 |
throw new RuntimeException("Test failed - server debuggee generated an error when it terminated, " + |
a2a52f380463
8059105: Add better failure reporting to com/sun/jdi/RunToExit.java test
farvidsson
parents:
24973
diff
changeset
|
161 |
"exit code was " + exitCode + ", " + error_seen + " error(s) seen in debugee output."); |
2 | 162 |
} |
163 |
} |
|
164 |
} |