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/clrallbreakp001.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 clrallbreakp001.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 clrallbreakp001 {
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 + "." + "clrallbreakp001";
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 = clrallbreakp001a.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 clrallbreakp001().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 VM_DEATH event instead of BREAKPOINT event");
159
waitForVMDeathEvent();
160
161
if (!dead) {
162
// resume debuggee after BREAKPOINT event
163
log.display("Resuming debuggee");
164
debugee.resume();
165
log.display(" ... debuggee resumed");
166
167
// wait for debuggee exited
168
log.display("Waiting for fianl VM_DEATH event");
169
debugee.waitForVMDeath();
170
dead = true;
171
log.display(" ... VM_DEATH event received");
172
}
173
174
} catch (Failure e) {
175
log.complain("TEST FAILED: " + e.getMessage());
176
success = false;
177
} catch (Exception e) {
178
e.printStackTrace(out);
179
log.complain("Caught unexpected exception while running the test:\n\t" + e);
180
success = false;
181
} finally {
182
// quit debugee
183
log.display("\n>>> Finishing test \n");
184
quitDebugee();
185
}
186
187
// check test results
188
if (!success) {
189
log.complain("TEST FAILED");
190
return FAILED;
191
}
192
193
out.println("TEST PASSED");
194
return PASSED;
195
196
}
197
198
void prepareForTest() {
199
// wait for tested class loaded
200
log.display("Waiting for tested class loaded");
201
testedClassID = debugee.waitForClassLoaded(TESTED_CLASS_NAME, JDWP.SuspendPolicy.ALL);
202
log.display(" ... got classID: " + testedClassID);
203
log.display("");
204
205
// get methodID for tested method
206
log.display("Getting tested methodID by name: " + TESTED_METHOD_NAME);
207
testedMethodID = debugee.getMethodID(testedClassID, TESTED_METHOD_NAME, true);
208
log.display(" ... got methodID: " + testedMethodID);
209
210
// make request for BREAKPOINT event
211
log.display("Making request for BREAKPOINT event at: "
212
+ TESTED_METHOD_NAME + ":" + BREAKPOINT_LINE);
213
eventRequestID = debugee.requestBreakpointEvent(JDWP.TypeTag.CLASS, testedClassID,
214
testedMethodID, BREAKPOINT_LINE,
215
JDWP.SuspendPolicy.ALL);
216
log.display(" ... got requestID: " + eventRequestID);
217
}
218
219
220
/**
221
* Test JDWP command.
222
*/
223
void testCommand() {
224
// create command packet and fill requred out data
225
log.display("Create command packet: " + JDWP_COMMAND_NAME);
226
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
227
log.display(" no out data");
228
command.setLength();
229
log.display(" ... command packet created");
230
231
// send command packet to debugee
232
try {
233
log.display("Sending command packet:\n" + command);
234
transport.write(command);
235
log.display(" ... command packet sent");
236
} catch (IOException e) {
237
log.complain("Unable to send command packet:\n\t" + e);
238
success = false;
239
return;
240
}
241
log.display("");
242
243
// receive reply packet from debugee
244
ReplyPacket reply = new ReplyPacket();
245
try {
246
log.display("Waiting for reply packet");
247
transport.read(reply);
248
log.display(" ... reply packet received:\n" + reply);
249
} catch (IOException e) {
250
log.complain("Unable to read reply packet:\n\t" + e);
251
success = false;
252
return;
253
}
254
log.display("");
255
256
// check reply packet header
257
try{
258
log.display("Checking header of reply packet");
259
reply.checkHeader(command.getPacketID());
260
log.display(" ... packet header is correct");
261
} catch (BoundException e) {
262
log.complain("Wrong header of reply packet for tested command:\n\t"
263
+ e.getMessage());
264
success = false;
265
return;
266
}
267
268
// start parsing reply packet data
269
log.display("Parsing reply packet data:");
270
reply.resetPosition();
271
272
// no out data
273
log.display(" no out data");
274
275
log.display(" ... packet data is parsed");
276
277
// check for extra data in reply packet
278
if (!reply.isParsed()) {
279
log.complain("Extra trailing bytes found in reply packet at: "
280
+ reply.offsetString());
281
success = false;
282
}
283
}
284
285
/**
286
* Wait for VM_DEATH event.
287
*/
288
void waitForVMDeathEvent() {
289
290
EventPacket eventPacket = null;
291
292
// receive reply packet from debugee
293
try {
294
log.display("Waiting for event packet");
295
eventPacket = debugee.getEventPacket(timeout);
296
log.display(" ... event packet received:\n" + eventPacket);
297
} catch (IOException e) {
298
log.complain("Unable to read tested event packet:\n\t" + e);
299
success = false;
300
return;
301
}
302
log.display("");
303
304
// check reply packet header
305
try{
306
log.display("Checking header of event packet");
307
eventPacket.checkHeader();
308
log.display(" ... packet header is correct");
309
} catch (BoundException e) {
310
log.complain("Bad header of tested event packet:\n\t"
311
+ e.getMessage());
312
success = false;
313
return;
314
}
315
316
// start parsing reply packet data
317
log.display("Parsing event packet:");
318
eventPacket.resetPosition();
319
320
// get suspendPolicy value
321
byte suspendPolicy = 0;
322
try {
323
suspendPolicy = eventPacket.getByte();
324
log.display(" suspendPolicy: " + suspendPolicy);
325
} catch (BoundException e) {
326
log.complain("Unable to get suspendPolicy value from tested event packet:\n\t"
327
+ e.getMessage());
328
success = false;
329
return;
330
}
331
332
// get events count
333
int events = 0;
334
try {
335
events = eventPacket.getInt();
336
log.display(" events: " + events);
337
} catch (BoundException e) {
338
log.complain("Unable to get events count from tested event packet:\n\t"
339
+ e.getMessage());
340
success = false;
341
return;
342
}
343
344
// check events count
345
if (events < 0) {
346
log.complain("Negative value of events number in tested event packet: " +
347
events + " (expected: " + 1 + ")");
348
success = false;
349
} else if (events != 1) {
350
log.complain("Invalid number of events in tested event packet: " +
351
events + " (expected: " + 1 + ")");
352
success = false;
353
}
354
355
// extract each event
356
long eventThreadID = 0;
357
for (int i = 0; i < events; i++) {
358
log.display(" event #" + i + ":");
359
360
// get eventKind
361
byte eventKind = 0;
362
try {
363
eventKind = eventPacket.getByte();
364
log.display(" eventKind: " + eventKind);
365
} catch (BoundException e) {
366
log.complain("Unable to get eventKind of event #" + i + " from tested event packet:\n\t"
367
+ e.getMessage());
368
success = false;
369
return;
370
}
371
372
// check eventKind
373
if (eventKind == JDWP.EventKind.VM_DEATH) {
374
log.display("Expected VM_DEATH event received intead of BREAKPOINT event");
375
dead = true;
376
return;
377
} else if (eventKind == JDWP.EventKind.BREAKPOINT) {
378
log.complain("Unexpected BREAKPOINT event received in event packet: " +
379
eventKind + " (expected: " + JDWP.EventKind.VM_DEATH + ")");
380
success = false;
381
} else {
382
log.complain("Unexpected eventKind of event " + i + " in event packet: " +
383
eventKind + " (expected: " + JDWP.EventKind.VM_DEATH + ")");
384
success = false;
385
return;
386
}
387
388
// get requestID
389
int requestID = 0;
390
try {
391
requestID = eventPacket.getInt();
392
log.display(" requestID: " + requestID);
393
} catch (BoundException e) {
394
log.complain("Unable to get requestID of event #" + i + " from BREAKPOINT event packet:\n\t"
395
+ e.getMessage());
396
success = false;
397
return;
398
}
399
400
// check requestID
401
if (requestID != eventRequestID) {
402
log.complain("Unexpected requestID of event " + i + " in BREAKPOINT event packet: " +
403
requestID + " (expected: " + eventRequestID + ")");
404
success = false;
405
}
406
407
// get threadID
408
long threadID = 0;
409
try {
410
threadID = eventPacket.getObjectID();
411
log.display(" threadID: " + threadID);
412
} catch (BoundException e) {
413
log.complain("Unable to get threadID of event #" + i + " from BREAKPOINT event packet:\n\t"
414
+ e.getMessage());
415
success = false;
416
return;
417
}
418
419
// get location
420
JDWP.Location location = null;
421
try {
422
location = eventPacket.getLocation();
423
log.display(" location: " + location);
424
} catch (BoundException e) {
425
log.complain("Unable to get location of event #" + i + " from BREAKPOINT event packet:\n\t"
426
+ e.getMessage());
427
success = false;
428
return;
429
}
430
}
431
432
// check for extra data in event packet
433
if (!eventPacket.isParsed()) {
434
log.complain("Extra trailing bytes found in event packet at: "
435
+ eventPacket.offsetString());
436
success = false;
437
}
438
439
log.display(" ... event packet parsed");
440
}
441
442
443
/**
444
* Disconnect debuggee and wait for it exited.
445
*/
446
void quitDebugee() {
447
if (debugee == null)
448
return;
449
450
// disconnect debugee if not dead
451
if (!dead) {
452
try {
453
log.display("Disconnecting debuggee");
454
debugee.dispose();
455
log.display(" ... debuggee disconnected");
456
} catch (Failure e) {
457
log.display("Failed to finally disconnect debuggee:\n\t"
458
+ e.getMessage());
459
}
460
}
461
462
// wait for debugee exited
463
log.display("Waiting for debuggee exit");
464
int code = debugee.waitFor();
465
log.display(" ... debuggee exited with exit code: " + code);
466
467
// analize debugee exit status code
468
if (code != JCK_STATUS_BASE + PASSED) {
469
log.complain("Debuggee FAILED with exit code: " + code);
470
success = false;
471
}
472
}
473
474
}
475
476