author | katleman |
Thu, 05 Jan 2012 08:42:37 -0800 | |
changeset 11376 | 075fe3928b7f |
parent 5506 | 202f599c92aa |
child 20184 | a2c4b7079eb6 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2000, 2006, 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 |
/** |
|
25 |
* @test |
|
26 |
* @bug 4334008 |
|
27 |
* @author Robert Field |
|
28 |
* |
|
29 |
* @run compile -g RepStepTarg.java |
|
30 |
* @run build VMConnection RepStep |
|
31 |
* |
|
4335
365eb4449319
6904183: Fix jdk/test/com/sun/jdi tests to run with -samevm
ohair
parents:
2
diff
changeset
|
32 |
* @run main/othervm RepStep |
2 | 33 |
* |
34 |
* @summary RepStep detects missed step events due to lack of |
|
35 |
* frame pop events (in back-end). |
|
36 |
*/ |
|
37 |
import com.sun.jdi.*; |
|
38 |
import com.sun.jdi.event.*; |
|
39 |
import com.sun.jdi.request.*; |
|
40 |
import com.sun.jdi.connect.*; |
|
41 |
||
42 |
import java.util.*; |
|
43 |
||
44 |
public class RepStep { |
|
45 |
static final String TARGET = "RepStepTarg"; |
|
46 |
static final int GRANULARITY = StepRequest.STEP_LINE; |
|
47 |
static final int DEPTH = StepRequest.STEP_INTO; |
|
48 |
static final int SUCCESS_COUNT = 30; |
|
49 |
||
50 |
VirtualMachine vm; |
|
51 |
final EventRequestManager requestManager; |
|
52 |
int stepNum = 0; |
|
53 |
boolean passed = false; |
|
54 |
||
55 |
public static void main(String args[]) throws Exception { |
|
56 |
new RepStep(args); |
|
57 |
} |
|
58 |
||
59 |
RepStep(String args[]) throws Exception { |
|
60 |
if (args.length > 0) { |
|
61 |
attachTarget(args[0]); |
|
62 |
} else { |
|
63 |
launchTarget(); |
|
64 |
} |
|
65 |
// vm.setDebugTraceMode(VirtualMachine.TRACE_ALL); |
|
66 |
requestManager = vm.eventRequestManager(); |
|
67 |
runTests(); |
|
68 |
dieNice(); |
|
69 |
} |
|
70 |
||
71 |
private void createStep(ThreadReference thread) { |
|
72 |
final StepRequest sr = |
|
73 |
requestManager.createStepRequest(thread, |
|
74 |
GRANULARITY, |
|
75 |
DEPTH); |
|
76 |
||
77 |
sr.addClassExclusionFilter("java.*"); |
|
78 |
sr.addClassExclusionFilter("sun.*"); |
|
79 |
sr.addClassExclusionFilter("com.sun.*"); |
|
80 |
sr.enable(); |
|
81 |
} |
|
82 |
||
83 |
private void runTests() throws Exception { |
|
84 |
ThreadReference thread = null; |
|
85 |
EventQueue queue = vm.eventQueue(); |
|
86 |
while (true) { |
|
87 |
EventSet set = queue.remove(); |
|
88 |
for (EventIterator it = set.eventIterator(); it.hasNext(); ) { |
|
89 |
Event event = it.nextEvent(); |
|
90 |
if (event instanceof VMStartEvent) { |
|
91 |
// get thread for setting step later |
|
92 |
thread = ((VMStartEvent)event).thread(); |
|
93 |
ClassPrepareRequest cpReq |
|
94 |
= requestManager.createClassPrepareRequest(); |
|
95 |
cpReq.addClassFilter(TARGET); |
|
96 |
cpReq.enable(); |
|
97 |
} else if (event instanceof ClassPrepareEvent) { |
|
98 |
createStep(thread); |
|
99 |
event.request().disable(); |
|
100 |
} else if (event instanceof StepEvent) { |
|
101 |
// StepEvent stepEvent = (StepEvent)event; |
|
102 |
// System.out.println(stepEvent); |
|
103 |
System.out.println(++stepNum); |
|
104 |
if (stepNum >= SUCCESS_COUNT) { |
|
105 |
// would have failed by now (> 4) |
|
106 |
System.out.println("RepStep passed"); |
|
107 |
event.request().disable(); |
|
108 |
set.resume(); |
|
109 |
return; // Success exit |
|
110 |
} |
|
111 |
} else if (event instanceof VMDeathEvent) { |
|
112 |
throw new Exception("RepStep failed: steps missed"); |
|
113 |
} else { |
|
114 |
throw new Exception("Unexpected event: " + event); |
|
115 |
} |
|
116 |
} |
|
117 |
set.resume(); |
|
118 |
} |
|
119 |
} |
|
120 |
||
121 |
private void dieNice() throws Exception { |
|
122 |
EventQueue queue = vm.eventQueue(); |
|
123 |
while (true) { |
|
124 |
EventSet set = queue.remove(); |
|
125 |
for (EventIterator it = set.eventIterator(); it.hasNext(); ) { |
|
126 |
Event event = it.nextEvent(); |
|
127 |
if (event instanceof VMDeathEvent) { |
|
128 |
// ignore |
|
129 |
} else if (event instanceof VMDisconnectEvent) { |
|
130 |
set.resume(); |
|
131 |
return; // Success exit |
|
132 |
} else { |
|
133 |
throw new Exception("Unexpected event: " + event); |
|
134 |
} |
|
135 |
} |
|
136 |
set.resume(); |
|
137 |
} |
|
138 |
} |
|
139 |
||
140 |
private Connector findConnector(String name) throws Exception { |
|
141 |
List connectors = Bootstrap.virtualMachineManager().allConnectors(); |
|
142 |
Iterator iter = connectors.iterator(); |
|
143 |
while (iter.hasNext()) { |
|
144 |
Connector connector = (Connector)iter.next(); |
|
145 |
if (connector.name().equals(name)) { |
|
146 |
return connector; |
|
147 |
} |
|
148 |
} |
|
149 |
throw new Exception("No connector: " + name); |
|
150 |
} |
|
151 |
||
152 |
/* launch child target vm */ |
|
153 |
private void launchTarget() throws Exception { |
|
154 |
LaunchingConnector launcher = |
|
155 |
(LaunchingConnector)findConnector("com.sun.jdi.CommandLineLaunch"); |
|
156 |
Map connectorArgs = launcher.defaultArguments(); |
|
157 |
Connector.Argument mainArg = |
|
158 |
(Connector.Argument)connectorArgs.get("main"); |
|
159 |
mainArg.setValue(TARGET); |
|
160 |
Connector.Argument optionsArg = |
|
161 |
(Connector.Argument)connectorArgs.get("options"); |
|
162 |
optionsArg.setValue(VMConnection.getDebuggeeVMOptions()); |
|
163 |
||
164 |
vm = launcher.launch(connectorArgs); |
|
165 |
System.out.println("launched: " + TARGET); |
|
166 |
} |
|
167 |
||
168 |
private void attachTarget(String portNum) throws Exception { |
|
169 |
AttachingConnector conn = |
|
170 |
(AttachingConnector)findConnector("com.sun.jdi.SocketAttach"); |
|
171 |
Map connectorArgs = conn.defaultArguments(); |
|
172 |
Connector.Argument portArg = |
|
173 |
(Connector.Argument)connectorArgs.get("port"); |
|
174 |
portArg.setValue(portNum); |
|
175 |
vm = conn.attach(connectorArgs); |
|
176 |
System.out.println("attached to: " + portNum); |
|
177 |
} |
|
178 |
||
179 |
} |