Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/Set/set001.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.Set;
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.Set.
34
*
35
* See set001.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 set001 {
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.Set";
53
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "set001";
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.Set";
58
static final int JDWP_COMMAND_ID = JDWP.Command.EventRequest.Set;
59
static final byte TESTED_EVENT_KIND = JDWP.EventKind.BREAKPOINT;
60
static final byte TESTED_EVENT_SUSPEND_POLICY = JDWP.SuspendPolicy.ALL;
61
static final byte TESTED_EVENT_MODIFIER = JDWP.EventModifierKind.LOCATION_ONLY;
62
63
// name and signature of the tested class
64
static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";
65
static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";
66
67
// name of field and method of tested class
68
static final String TESTED_METHOD_NAME = "run";
69
static final int BREAKPOINT_LINE = set001a.BREAKPOINT_LINE;
70
71
// usual scaffold objects
72
ArgumentHandler argumentHandler = null;
73
Log log = null;
74
Binder binder = null;
75
Debugee debugee = null;
76
Transport transport = null;
77
int waitTime = 0; // minutes
78
long timeout = 0; // milliseconds
79
boolean dead = false;
80
boolean success = true;
81
82
// obtained data
83
long testedClassID = 0;
84
long testedMethodID = 0;
85
int eventRequestID = 0;
86
JDWP.Location breakpointLocation = null;
87
88
// -------------------------------------------------------------------
89
90
/**
91
* Start test from command line.
92
*/
93
public static void main(String argv[]) {
94
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
95
}
96
97
/**
98
* Start test from JCK-compilant environment.
99
*/
100
public static int run(String argv[], PrintStream out) {
101
return new set001().runIt(argv, out);
102
}
103
104
// -------------------------------------------------------------------
105
106
/**
107
* Perform test execution.
108
*/
109
public int runIt(String argv[], PrintStream out) {
110
111
// make log for debugger messages
112
argumentHandler = new ArgumentHandler(argv);
113
log = new Log(out, argumentHandler);
114
waitTime = argumentHandler.getWaitTime();
115
timeout = waitTime * 60 * 1000;
116
117
// execute test and display results
118
try {
119
log.display("\n>>> Starting debugee \n");
120
121
// launch debuggee
122
binder = new Binder(argumentHandler, log);
123
log.display("Launching debugee");
124
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
125
transport = debugee.getTransport();
126
log.display(" ... debugee launched");
127
log.display("");
128
129
// set timeout for debuggee responces
130
log.display("Setting timeout for debuggee responces: " + waitTime + " minute(s)");
131
transport.setReadTimeout(timeout);
132
log.display(" ... timeout set");
133
134
// wait for debuggee started
135
log.display("Waiting for VM_INIT event");
136
debugee.waitForVMInit();
137
log.display(" ... VM_INIT event received");
138
139
// query debugee for VM-dependent ID sizes
140
log.display("Querying for IDSizes");
141
debugee.queryForIDSizes();
142
log.display(" ... size of VM-dependent types adjusted");
143
144
// get debuggee prepared for testing
145
log.display("\n>>> Get debuggee prepared for testing \n");
146
prepareForTest();
147
148
// test JDWP command
149
log.display("\n>>> Testing JDWP command \n");
150
testCommand();
151
152
if (success) {
153
log.display("\n>>> Checking request result \n");
154
155
// resume debuggee
156
log.display("Resuming debuggee");
157
debugee.resume();
158
log.display(" ... debuggee resumed");
159
160
// wait for BREAKPOINT event
161
log.display("Waiting for BREAKPOINT event");
162
long threadID = debugee.waitForBreakpointEvent(eventRequestID);
163
log.display(" ... BREAKPOINT event received with threadID: " + threadID);
164
}
165
166
log.display("\n>>> Finishing debuggee \n");
167
168
// resume debuggee
169
log.display("Resuming debuggee");
170
debugee.resume();
171
log.display(" ... debuggee resumed");
172
173
// wait for debuggee exited
174
log.display("Waiting for VM_DEATH event");
175
debugee.waitForVMDeath();
176
dead = true;
177
log.display(" ... VM_DEATH event received");
178
179
} catch (Failure e) {
180
log.complain("TEST FAILED: " + e.getMessage());
181
success = false;
182
} catch (Exception e) {
183
e.printStackTrace(out);
184
log.complain("Caught unexpected exception while running the test:\n\t" + e);
185
success = false;
186
} finally {
187
// quit debugee
188
log.display("\n>>> Finishing test \n");
189
quitDebugee();
190
}
191
192
// check test results
193
if (!success) {
194
log.complain("TEST FAILED");
195
return FAILED;
196
}
197
198
out.println("TEST PASSED");
199
return PASSED;
200
201
}
202
203
/**
204
* Prepare debuggee for testing.
205
*/
206
void prepareForTest() {
207
// wait for tested class loaded
208
log.display("Waiting for tested class loaded");
209
testedClassID = debugee.waitForClassLoaded(TESTED_CLASS_NAME, JDWP.SuspendPolicy.ALL);
210
log.display(" ... got classID: " + testedClassID);
211
log.display("");
212
213
// get methodID for breakpoint method
214
log.display("Getting breakpoint methodID by name: " + TESTED_METHOD_NAME);
215
testedMethodID = debugee.getMethodID(testedClassID, TESTED_METHOD_NAME, true);
216
log.display(" ... got methodID: " + testedMethodID);
217
218
// get codeIndex for breakpoint line
219
log.display("Getting code index for breakpoint line: " + BREAKPOINT_LINE);
220
long codeIndex = debugee.getCodeIndex(testedClassID, testedMethodID, BREAKPOINT_LINE);
221
log.display(" ... got breakpoint codeIndex: " + codeIndex);
222
223
// create breakpoint location
224
log.display("Creating location for breakpoint at: "
225
+ TESTED_METHOD_NAME + ":" + BREAKPOINT_LINE);
226
breakpointLocation = new JDWP.Location(JDWP.TypeTag.CLASS, testedClassID,
227
testedMethodID, codeIndex);
228
log.display(" ... got breakpoint location: " + breakpointLocation);
229
}
230
231
/**
232
* Test JDWP command.
233
*/
234
void testCommand() {
235
// create command packet and fill requred out data
236
log.display("Create command packet: " + JDWP_COMMAND_NAME);
237
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
238
log.display(" event: " + TESTED_EVENT_KIND);
239
command.addByte(TESTED_EVENT_KIND);
240
log.display(" suspendPolicy: " + TESTED_EVENT_SUSPEND_POLICY);
241
command.addByte(TESTED_EVENT_SUSPEND_POLICY);
242
log.display(" modifiers: " + 1);
243
command.addInt(1);
244
log.display(" modKind: " + TESTED_EVENT_MODIFIER);
245
command.addByte(TESTED_EVENT_MODIFIER);
246
log.display(" location: " + breakpointLocation);
247
command.addLocation(breakpointLocation);
248
command.setLength();
249
log.display(" ... command packet created");
250
251
// send command packet to debugee
252
try {
253
log.display("Sending command packet:\n" + command);
254
transport.write(command);
255
log.display(" ... command packet sent");
256
} catch (IOException e) {
257
log.complain("Unable to send command packet:\n\t" + e);
258
success = false;
259
return;
260
}
261
log.display("");
262
263
// receive reply packet from debugee
264
ReplyPacket reply = new ReplyPacket();
265
try {
266
log.display("Waiting for reply packet");
267
transport.read(reply);
268
log.display(" ... reply packet received:\n" + reply);
269
} catch (IOException e) {
270
log.complain("Unable to read reply packet:\n\t" + e);
271
success = false;
272
return;
273
}
274
log.display("");
275
276
// check reply packet header
277
try{
278
log.display("Checking header of reply packet");
279
reply.checkHeader(command.getPacketID());
280
log.display(" ... packet header is correct");
281
} catch (BoundException e) {
282
log.complain("Wrong header of reply packet for tested command:\n\t"
283
+ e.getMessage());
284
success = false;
285
return;
286
}
287
288
// start parsing reply packet data
289
log.display("Parsing reply packet data:");
290
reply.resetPosition();
291
292
// extract requestID
293
int requestID = 0;
294
try {
295
requestID = reply.getInt();
296
log.display(" requestID: " + requestID);
297
} catch (BoundException e) {
298
log.complain("Unable to extract requestID from request reply packet:\n\t"
299
+ e.getMessage());
300
success = false;
301
}
302
303
// check requestID
304
if (requestID == 0) {
305
log.complain("Unexpected null requestID returned: " + requestID);
306
success = false;
307
}
308
eventRequestID = requestID;
309
310
log.display(" ... packet data is parsed");
311
312
// check for extra data in reply packet
313
if (!reply.isParsed()) {
314
log.complain("Extra trailing bytes found in reply packet at: "
315
+ reply.offsetString());
316
success = false;
317
}
318
}
319
320
/**
321
* Wait for VM_DEATH event.
322
*/
323
void waitForVMDeathEvent() {
324
325
EventPacket eventPacket = null;
326
327
// receive reply packet from debugee
328
try {
329
log.display("Waiting for event packet");
330
eventPacket = debugee.getEventPacket(timeout);
331
log.display(" ... event packet received:\n" + eventPacket);
332
} catch (IOException e) {
333
log.complain("Unable to read tested event packet:\n\t" + e);
334
success = false;
335
return;
336
}
337
log.display("");
338
339
// check reply packet header
340
try{
341
log.display("Checking header of event packet");
342
eventPacket.checkHeader();
343
log.display(" ... packet header is correct");
344
} catch (BoundException e) {
345
log.complain("Bad header of tested event packet:\n\t"
346
+ e.getMessage());
347
success = false;
348
return;
349
}
350
351
// start parsing reply packet data
352
log.display("Parsing event packet:");
353
eventPacket.resetPosition();
354
355
// get suspendPolicy value
356
byte suspendPolicy = 0;
357
try {
358
suspendPolicy = eventPacket.getByte();
359
log.display(" suspendPolicy: " + suspendPolicy);
360
} catch (BoundException e) {
361
log.complain("Unable to get suspendPolicy value from tested event packet:\n\t"
362
+ e.getMessage());
363
success = false;
364
return;
365
}
366
367
// get events count
368
int events = 0;
369
try {
370
events = eventPacket.getInt();
371
log.display(" events: " + events);
372
} catch (BoundException e) {
373
log.complain("Unable to get events count from tested event packet:\n\t"
374
+ e.getMessage());
375
success = false;
376
return;
377
}
378
379
// check events count
380
if (events < 0) {
381
log.complain("Negative value of events number in tested event packet: " +
382
events + " (expected: " + 1 + ")");
383
success = false;
384
} else if (events != 1) {
385
log.complain("Invalid number of events in tested event packet: " +
386
events + " (expected: " + 1 + ")");
387
success = false;
388
}
389
390
// extract each event
391
long eventThreadID = 0;
392
for (int i = 0; i < events; i++) {
393
log.display(" event #" + i + ":");
394
395
// get eventKind
396
byte eventKind = 0;
397
try {
398
eventKind = eventPacket.getByte();
399
log.display(" eventKind: " + eventKind);
400
} catch (BoundException e) {
401
log.complain("Unable to get eventKind of event #" + i + " from tested event packet:\n\t"
402
+ e.getMessage());
403
success = false;
404
return;
405
}
406
407
// check eventKind
408
if (eventKind == JDWP.EventKind.VM_DEATH) {
409
log.display("Expected VM_DEATH event received intead of BREAKPOINT event");
410
dead = true;
411
return;
412
} else if (eventKind == JDWP.EventKind.BREAKPOINT) {
413
log.complain("Unexpected BREAKPOINT event received in event packet: " +
414
eventKind + " (expected: " + JDWP.EventKind.VM_DEATH + ")");
415
success = false;
416
} else {
417
log.complain("Unexpected eventKind of event " + i + " in event packet: " +
418
eventKind + " (expected: " + JDWP.EventKind.VM_DEATH + ")");
419
success = false;
420
return;
421
}
422
423
// get requestID
424
int requestID = 0;
425
try {
426
requestID = eventPacket.getInt();
427
log.display(" requestID: " + requestID);
428
} catch (BoundException e) {
429
log.complain("Unable to get requestID of event #" + i + " from BREAKPOINT event packet:\n\t"
430
+ e.getMessage());
431
success = false;
432
return;
433
}
434
435
// check requestID
436
if (requestID != eventRequestID) {
437
log.complain("Unexpected requestID of event " + i + " in BREAKPOINT event packet: " +
438
requestID + " (expected: " + eventRequestID + ")");
439
success = false;
440
}
441
442
// get threadID
443
long threadID = 0;
444
try {
445
threadID = eventPacket.getObjectID();
446
log.display(" threadID: " + threadID);
447
} catch (BoundException e) {
448
log.complain("Unable to get threadID of event #" + i + " from BREAKPOINT event packet:\n\t"
449
+ e.getMessage());
450
success = false;
451
return;
452
}
453
454
// get location
455
JDWP.Location location = null;
456
try {
457
location = eventPacket.getLocation();
458
log.display(" location: " + location);
459
} catch (BoundException e) {
460
log.complain("Unable to get location of event #" + i + " from BREAKPOINT event packet:\n\t"
461
+ e.getMessage());
462
success = false;
463
return;
464
}
465
}
466
467
// check for extra data in event packet
468
if (!eventPacket.isParsed()) {
469
log.complain("Extra trailing bytes found in event packet at: "
470
+ eventPacket.offsetString());
471
success = false;
472
}
473
474
log.display(" ... event packet parsed");
475
}
476
477
478
/**
479
* Disconnect debuggee and wait for it exited.
480
*/
481
void quitDebugee() {
482
if (debugee == null)
483
return;
484
485
// disconnect debugee if not dead
486
if (!dead) {
487
try {
488
log.display("Disconnecting debuggee");
489
debugee.dispose();
490
log.display(" ... debuggee disconnected");
491
} catch (Failure e) {
492
log.display("Failed to finally disconnect debuggee:\n\t"
493
+ e.getMessage());
494
}
495
}
496
497
// wait for debugee exited
498
log.display("Waiting for debuggee exit");
499
int code = debugee.waitFor();
500
log.display(" ... debuggee exited with exit code: " + code);
501
502
// analize debugee exit status code
503
if (code != JCK_STATUS_BASE + PASSED) {
504
log.complain("Debuggee FAILED with exit code: " + code);
505
success = false;
506
}
507
}
508
509
}
510
511