Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/Clear/clear001.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.Clear;
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.Clear.
34
*
35
* See clear001.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 clear001 {
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.Clear";
53
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "clear001";
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.Clear";
58
static final int JDWP_COMMAND_ID = JDWP.Command.EventRequest.Clear;
59
static final byte TESTED_EVENT_KIND = JDWP.EventKind.BREAKPOINT;
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 = clear001a.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 clear001().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 final 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(" event: " + TESTED_EVENT_KIND);
228
command.addByte(TESTED_EVENT_KIND);
229
log.display(" requestID: " + eventRequestID);
230
command.addInt(eventRequestID);
231
command.setLength();
232
log.display(" ... command packet created");
233
234
// send command packet to debugee
235
try {
236
log.display("Sending command packet:\n" + command);
237
transport.write(command);
238
log.display(" ... command packet sent");
239
} catch (IOException e) {
240
log.complain("Unable to send command packet:\n\t" + e);
241
success = false;
242
return;
243
}
244
log.display("");
245
246
// receive reply packet from debugee
247
ReplyPacket reply = new ReplyPacket();
248
try {
249
log.display("Waiting for reply packet");
250
transport.read(reply);
251
log.display(" ... reply packet received:\n" + reply);
252
} catch (IOException e) {
253
log.complain("Unable to read reply packet:\n\t" + e);
254
success = false;
255
return;
256
}
257
log.display("");
258
259
// check reply packet header
260
try{
261
log.display("Checking header of reply packet");
262
reply.checkHeader(command.getPacketID());
263
log.display(" ... packet header is correct");
264
} catch (BoundException e) {
265
log.complain("Wrong header of reply packet for tested command:\n\t"
266
+ e.getMessage());
267
success = false;
268
return;
269
}
270
271
// start parsing reply packet data
272
log.display("Parsing reply packet data:");
273
reply.resetPosition();
274
275
// no out data
276
log.display(" no out data");
277
278
log.display(" ... packet data is parsed");
279
280
// check for extra data in reply packet
281
if (!reply.isParsed()) {
282
log.complain("Extra trailing bytes found in reply packet at: "
283
+ reply.offsetString());
284
success = false;
285
}
286
}
287
288
/**
289
* Wait for VM_DEATH event.
290
*/
291
void waitForVMDeathEvent() {
292
293
EventPacket eventPacket = null;
294
295
// receive reply packet from debugee
296
try {
297
log.display("Waiting for event packet");
298
eventPacket = debugee.getEventPacket(timeout);
299
log.display(" ... event packet received:\n" + eventPacket);
300
} catch (IOException e) {
301
log.complain("Unable to read tested event packet:\n\t" + e);
302
success = false;
303
return;
304
}
305
log.display("");
306
307
// check reply packet header
308
try{
309
log.display("Checking header of event packet");
310
eventPacket.checkHeader();
311
log.display(" ... packet header is correct");
312
} catch (BoundException e) {
313
log.complain("Bad header of tested event packet:\n\t"
314
+ e.getMessage());
315
success = false;
316
return;
317
}
318
319
// start parsing reply packet data
320
log.display("Parsing event packet:");
321
eventPacket.resetPosition();
322
323
// get suspendPolicy value
324
byte suspendPolicy = 0;
325
try {
326
suspendPolicy = eventPacket.getByte();
327
log.display(" suspendPolicy: " + suspendPolicy);
328
} catch (BoundException e) {
329
log.complain("Unable to get suspendPolicy value from tested event packet:\n\t"
330
+ e.getMessage());
331
success = false;
332
return;
333
}
334
335
// get events count
336
int events = 0;
337
try {
338
events = eventPacket.getInt();
339
log.display(" events: " + events);
340
} catch (BoundException e) {
341
log.complain("Unable to get events count from tested event packet:\n\t"
342
+ e.getMessage());
343
success = false;
344
return;
345
}
346
347
// check events count
348
if (events < 0) {
349
log.complain("Negative value of events number in tested event packet: " +
350
events + " (expected: " + 1 + ")");
351
success = false;
352
} else if (events != 1) {
353
log.complain("Invalid number of events in tested event packet: " +
354
events + " (expected: " + 1 + ")");
355
success = false;
356
}
357
358
// extract each event
359
long eventThreadID = 0;
360
for (int i = 0; i < events; i++) {
361
log.display(" event #" + i + ":");
362
363
// get eventKind
364
byte eventKind = 0;
365
try {
366
eventKind = eventPacket.getByte();
367
log.display(" eventKind: " + eventKind);
368
} catch (BoundException e) {
369
log.complain("Unable to get eventKind of event #" + i + " from tested event packet:\n\t"
370
+ e.getMessage());
371
success = false;
372
return;
373
}
374
375
// check eventKind
376
if (eventKind == JDWP.EventKind.VM_DEATH) {
377
log.display("Expected VM_DEATH event received intead of BREAKPOINT event");
378
dead = true;
379
return;
380
} else if (eventKind == JDWP.EventKind.BREAKPOINT) {
381
log.complain("Unexpected BREAKPOINT event received in event packet: " +
382
eventKind + " (expected: " + JDWP.EventKind.VM_DEATH + ")");
383
success = false;
384
} else {
385
log.complain("Unexpected eventKind of event " + i + " in event packet: " +
386
eventKind + " (expected: " + JDWP.EventKind.VM_DEATH + ")");
387
success = false;
388
return;
389
}
390
391
// get requestID
392
int requestID = 0;
393
try {
394
requestID = eventPacket.getInt();
395
log.display(" requestID: " + requestID);
396
} catch (BoundException e) {
397
log.complain("Unable to get requestID of event #" + i + " from BREAKPOINT event packet:\n\t"
398
+ e.getMessage());
399
success = false;
400
return;
401
}
402
403
// check requestID
404
if (requestID != eventRequestID) {
405
log.complain("Unexpected requestID of event " + i + " in BREAKPOINT event packet: " +
406
requestID + " (expected: " + eventRequestID + ")");
407
success = false;
408
}
409
410
// get threadID
411
long threadID = 0;
412
try {
413
threadID = eventPacket.getObjectID();
414
log.display(" threadID: " + threadID);
415
} catch (BoundException e) {
416
log.complain("Unable to get threadID of event #" + i + " from BREAKPOINT event packet:\n\t"
417
+ e.getMessage());
418
success = false;
419
return;
420
}
421
422
// get location
423
JDWP.Location location = null;
424
try {
425
location = eventPacket.getLocation();
426
log.display(" location: " + location);
427
} catch (BoundException e) {
428
log.complain("Unable to get location of event #" + i + " from BREAKPOINT event packet:\n\t"
429
+ e.getMessage());
430
success = false;
431
return;
432
}
433
}
434
435
// check for extra data in event packet
436
if (!eventPacket.isParsed()) {
437
log.complain("Extra trailing bytes found in event packet at: "
438
+ eventPacket.offsetString());
439
success = false;
440
}
441
442
log.display(" ... event packet parsed");
443
}
444
445
446
/**
447
* Disconnect debuggee and wait for it exited.
448
*/
449
void quitDebugee() {
450
if (debugee == null)
451
return;
452
453
// disconnect debugee if not dead
454
if (!dead) {
455
try {
456
log.display("Disconnecting debuggee");
457
debugee.dispose();
458
log.display(" ... debuggee disconnected");
459
} catch (Failure e) {
460
log.display("Failed to finally disconnect debuggee:\n\t"
461
+ e.getMessage());
462
}
463
}
464
465
// wait for debugee exited
466
log.display("Waiting for debuggee exit");
467
int code = debugee.waitFor();
468
log.display(" ... debuggee exited with exit code: " + code);
469
470
// analize debugee exit status code
471
if (code != JCK_STATUS_BASE + PASSED) {
472
log.complain("Debuggee FAILED with exit code: " + code);
473
success = false;
474
}
475
}
476
477
}
478
479