Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp003.java
41161 views
1
/*
2
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
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
*
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.
22
*/
23
24
package nsk.jdwp.EventRequest.ClearAllBreakpoints;
25
26
import java.io.*;
27
28
import nsk.share.*;
29
import nsk.share.jpda.*;
30
import nsk.share.jdwp.*;
31
32
/**
33
* Test for JDWP command: EventRequest.ClearAllBreakpoints.
34
*
35
* See clrallbreakp003.README for description of test execution.
36
*
37
* This class represents debugger part of the test.
38
* Test is executed by invoking method runIt().
39
* JDWP command is tested in the method testCommand().
40
*
41
* @see #runIt()
42
* @see #waitForTestedEvent()
43
*/
44
public class clrallbreakp003 {
45
46
// exit status constants
47
static final int JCK_STATUS_BASE = 95;
48
static final int PASSED = 0;
49
static final int FAILED = 2;
50
51
// package and classes names constants
52
static final String PACKAGE_NAME = "nsk.jdwp.EventRequest.ClearAllBreakpoints";
53
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "clrallbreakp003";
54
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
55
56
// tested JDWP command constants
57
static final String JDWP_COMMAND_NAME = "EventRequest.ClearAllBreakpoints";
58
static final int JDWP_COMMAND_ID = JDWP.Command.EventRequest.ClearAllBreakpoints;
59
static final byte TESTED_EVENT_KIND = JDWP.EventKind.VM_START;
60
static final byte TESTED_EVENT_SUSPEND_POLICY = JDWP.SuspendPolicy.ALL;
61
62
// name and signature of the tested class
63
static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";
64
static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";
65
66
// name of field and method of tested class
67
static final String TESTED_METHOD_NAME = "run";
68
static final int BREAKPOINT_LINE = clrallbreakp003a.BREAKPOINT_LINE;
69
70
// usual scaffold objects
71
ArgumentHandler argumentHandler = null;
72
Log log = null;
73
Binder binder = null;
74
Debugee debugee = null;
75
Transport transport = null;
76
int waitTime = 0; // minutes
77
long timeout = 0; // milliseconds
78
boolean dead = false;
79
boolean success = true;
80
81
// obtained data
82
long testedClassID = 0;
83
long testedMethodID = 0;
84
int eventRequestID = 0;
85
86
// -------------------------------------------------------------------
87
88
/**
89
* Start test from command line.
90
*/
91
public static void main(String argv[]) {
92
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
93
}
94
95
/**
96
* Start test from JCK-compilant environment.
97
*/
98
public static int run(String argv[], PrintStream out) {
99
return new clrallbreakp003().runIt(argv, out);
100
}
101
102
// -------------------------------------------------------------------
103
104
/**
105
* Perform test execution.
106
*/
107
public int runIt(String argv[], PrintStream out) {
108
109
// make log for debugger messages
110
argumentHandler = new ArgumentHandler(argv);
111
log = new Log(out, argumentHandler);
112
waitTime = argumentHandler.getWaitTime();
113
timeout = waitTime * 60 * 1000;
114
115
// execute test and display results
116
try {
117
log.display("\n>>> Starting debugee \n");
118
119
// launch debuggee
120
binder = new Binder(argumentHandler, log);
121
log.display("Launching debugee");
122
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
123
transport = debugee.getTransport();
124
log.display(" ... debugee launched");
125
log.display("");
126
127
// set timeout for debuggee responces
128
log.display("Setting timeout for debuggee responces: " + waitTime + " minute(s)");
129
transport.setReadTimeout(timeout);
130
log.display(" ... timeout set");
131
132
// wait for debuggee started
133
log.display("Waiting for VM_INIT event");
134
debugee.waitForVMInit();
135
log.display(" ... VM_INIT event received");
136
137
// query debugee for VM-dependent ID sizes
138
log.display("Querying for IDSizes");
139
debugee.queryForIDSizes();
140
log.display(" ... size of VM-dependent types adjusted");
141
142
// get debuggee prepared for testing
143
log.display("\n>>> Get debuggee prepared for testing \n");
144
prepareForTest();
145
146
// test JDWP command
147
log.display("\n>>> Testing JDWP command \n");
148
testCommand();
149
150
log.display("\n>>> Finishing debuggee \n");
151
152
// resume debuggee
153
log.display("Resuming debuggee");
154
debugee.resume();
155
log.display(" ... debuggee resumed");
156
157
// wait for debuggee exited
158
log.display("Waiting for fianl VM_DEATH event");
159
debugee.waitForVMDeath();
160
dead = true;
161
log.display(" ... VM_DEATH event received");
162
163
} catch (Failure e) {
164
log.complain("TEST FAILED: " + e.getMessage());
165
success = false;
166
} catch (Exception e) {
167
e.printStackTrace(out);
168
log.complain("Caught unexpected exception while running the test:\n\t" + e);
169
success = false;
170
} finally {
171
// quit debugee
172
log.display("\n>>> Finishing test \n");
173
quitDebugee();
174
}
175
176
// check test results
177
if (!success) {
178
log.complain("TEST FAILED");
179
return FAILED;
180
}
181
182
out.println("TEST PASSED");
183
return PASSED;
184
185
}
186
187
void prepareForTest() {
188
// wait for tested class loaded
189
log.display("Waiting for tested class loaded");
190
testedClassID = debugee.waitForClassLoaded(TESTED_CLASS_NAME, JDWP.SuspendPolicy.ALL);
191
log.display(" ... got classID: " + testedClassID);
192
log.display("");
193
194
// get methodID for tested method
195
log.display("Getting tested methodID by name: " + TESTED_METHOD_NAME);
196
testedMethodID = debugee.getMethodID(testedClassID, TESTED_METHOD_NAME, true);
197
log.display(" ... got methodID: " + testedMethodID);
198
199
// make request for BREAKPOINT event
200
log.display("Making request for BREAKPOINT event at: "
201
+ TESTED_METHOD_NAME + ":" + BREAKPOINT_LINE);
202
eventRequestID = debugee.requestBreakpointEvent(JDWP.TypeTag.CLASS, testedClassID,
203
testedMethodID, BREAKPOINT_LINE,
204
JDWP.SuspendPolicy.ALL);
205
log.display(" ... got requestID: " + eventRequestID);
206
207
// clear request for BREAKPOINT event
208
log.display("Clearing BREAKPOINT event requestID: " + eventRequestID);
209
debugee.clearEventRequest(JDWP.EventKind.BREAKPOINT, eventRequestID);
210
log.display(" ... request removed");
211
}
212
213
214
/**
215
* Test JDWP command.
216
*/
217
void testCommand() {
218
// create command packet and fill requred out data
219
log.display("Create command packet: " + JDWP_COMMAND_NAME);
220
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
221
log.display(" no out data");
222
command.setLength();
223
log.display(" ... command packet created");
224
225
// send command packet to debugee
226
try {
227
log.display("Sending command packet:\n" + command);
228
transport.write(command);
229
log.display(" ... command packet sent");
230
} catch (IOException e) {
231
log.complain("Unable to send command packet:\n\t" + e);
232
success = false;
233
return;
234
}
235
log.display("");
236
237
// receive reply packet from debugee
238
ReplyPacket reply = new ReplyPacket();
239
try {
240
log.display("Waiting for reply packet");
241
transport.read(reply);
242
log.display(" ... reply packet received:\n" + reply);
243
} catch (IOException e) {
244
log.complain("Unable to read reply packet:\n\t" + e);
245
success = false;
246
return;
247
}
248
log.display("");
249
250
// check reply packet header
251
try{
252
log.display("Checking header of reply packet");
253
reply.checkHeader(command.getPacketID());
254
log.display(" ... packet header is correct");
255
} catch (BoundException e) {
256
log.complain("Wrong header of reply packet for tested command:\n\t"
257
+ e.getMessage());
258
success = false;
259
return;
260
}
261
262
// start parsing reply packet data
263
log.display("Parsing reply packet data:");
264
reply.resetPosition();
265
266
// no out data
267
log.display(" no out data");
268
269
log.display(" ... packet data is parsed");
270
271
// check for extra data in reply packet
272
if (!reply.isParsed()) {
273
log.complain("Extra trailing bytes found in reply packet at: "
274
+ reply.offsetString());
275
success = false;
276
}
277
}
278
279
/**
280
* Disconnect debuggee and wait for it exited.
281
*/
282
void quitDebugee() {
283
if (debugee == null)
284
return;
285
286
// disconnect debugee if not dead
287
if (!dead) {
288
try {
289
log.display("Disconnecting debuggee");
290
debugee.dispose();
291
log.display(" ... debuggee disconnected");
292
} catch (Failure e) {
293
log.display("Failed to finally disconnect debuggee:\n\t"
294
+ e.getMessage());
295
}
296
}
297
298
// wait for debugee exited
299
log.display("Waiting for debuggee exit");
300
int code = debugee.waitFor();
301
log.display(" ... debuggee exited with exit code: " + code);
302
303
// analize debugee exit status code
304
if (code != JCK_STATUS_BASE + PASSED) {
305
log.complain("Debuggee FAILED with exit code: " + code);
306
success = false;
307
}
308
}
309
310
}
311
312