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/clrallbreakp002.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 clrallbreakp002.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 clrallbreakp002 {
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 + "." + "clrallbreakp002";
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
// usual scaffold objects
67
ArgumentHandler argumentHandler = null;
68
Log log = null;
69
Binder binder = null;
70
Debugee debugee = null;
71
Transport transport = null;
72
int waitTime = 0; // minutes
73
long timeout = 0; // milliseconds
74
boolean dead = false;
75
boolean success = true;
76
77
// obtained data
78
long testedClassID = 0;
79
80
// -------------------------------------------------------------------
81
82
/**
83
* Start test from command line.
84
*/
85
public static void main(String argv[]) {
86
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
87
}
88
89
/**
90
* Start test from JCK-compilant environment.
91
*/
92
public static int run(String argv[], PrintStream out) {
93
return new clrallbreakp002().runIt(argv, out);
94
}
95
96
// -------------------------------------------------------------------
97
98
/**
99
* Perform test execution.
100
*/
101
public int runIt(String argv[], PrintStream out) {
102
103
// make log for debugger messages
104
argumentHandler = new ArgumentHandler(argv);
105
log = new Log(out, argumentHandler);
106
waitTime = argumentHandler.getWaitTime();
107
timeout = waitTime * 60 * 1000;
108
109
// execute test and display results
110
try {
111
log.display("\n>>> Starting debugee \n");
112
113
// launch debuggee
114
binder = new Binder(argumentHandler, log);
115
log.display("Launching debugee");
116
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
117
transport = debugee.getTransport();
118
log.display(" ... debugee launched");
119
log.display("");
120
121
// set timeout for debuggee responces
122
log.display("Setting timeout for debuggee responces: " + waitTime + " minute(s)");
123
transport.setReadTimeout(timeout);
124
log.display(" ... timeout set");
125
126
// wait for debuggee started
127
log.display("Waiting for VM_INIT event");
128
debugee.waitForVMInit();
129
log.display(" ... VM_INIT event received");
130
131
// query debugee for VM-dependent ID sizes
132
log.display("Querying for IDSizes");
133
debugee.queryForIDSizes();
134
log.display(" ... size of VM-dependent types adjusted");
135
136
// get debuggee prepared for testing
137
log.display("\n>>> Getting prepared for testing \n");
138
prepareForTest();
139
140
// test JDWP command
141
log.display("\n>>> Testing JDWP command \n");
142
testCommand();
143
144
log.display("\n>>> Finishing debuggee \n");
145
146
// resume debuggee
147
log.display("Resuming debuggee");
148
debugee.resume();
149
log.display(" ... debuggee resumed");
150
151
// wait for debuggee exited
152
log.display("Waiting for VM_DEATH event");
153
debugee.waitForVMDeath();
154
dead = true;
155
log.display(" ... VM_DEATH event received");
156
157
} catch (Failure e) {
158
log.complain("TEST FAILED: " + e.getMessage());
159
success = false;
160
} catch (Exception e) {
161
e.printStackTrace(out);
162
log.complain("Caught unexpected exception while running the test:\n\t" + e);
163
success = false;
164
} finally {
165
// quit debugee
166
log.display("\n>>> Finishing test \n");
167
quitDebugee();
168
}
169
170
// check test results
171
if (!success) {
172
log.complain("TEST FAILED");
173
return FAILED;
174
}
175
176
out.println("TEST PASSED");
177
return PASSED;
178
179
}
180
181
/**
182
* Get debuggee prepared for testing and obtain required data.
183
*/
184
void prepareForTest() {
185
// wait for tested class loaded
186
log.display("Waiting for tested class loaded");
187
testedClassID = debugee.waitForClassLoaded(TESTED_CLASS_NAME, JDWP.SuspendPolicy.ALL);
188
log.display(" ... got classID: " + testedClassID);
189
log.display("");
190
}
191
192
/**
193
* Test JDWP command.
194
*/
195
void testCommand() {
196
// create command packet and fill requred out data
197
log.display("Create command packet: " + JDWP_COMMAND_NAME);
198
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
199
log.display(" no out data");
200
command.setLength();
201
log.display(" ... command packet created");
202
203
// send command packet to debugee
204
try {
205
log.display("Sending command packet:\n" + command);
206
transport.write(command);
207
log.display(" ... command packet sent");
208
} catch (IOException e) {
209
log.complain("Unable to send command packet:\n\t" + e);
210
success = false;
211
return;
212
}
213
log.display("");
214
215
// receive reply packet from debugee
216
ReplyPacket reply = new ReplyPacket();
217
try {
218
log.display("Waiting for reply packet");
219
transport.read(reply);
220
log.display(" ... reply packet received:\n" + reply);
221
} catch (IOException e) {
222
log.complain("Unable to read reply packet:\n\t" + e);
223
success = false;
224
return;
225
}
226
log.display("");
227
228
// check reply packet header
229
try{
230
log.display("Checking header of reply packet");
231
reply.checkHeader(command.getPacketID());
232
log.display(" ... packet header is correct");
233
} catch (BoundException e) {
234
log.complain("Wrong header of reply packet for tested command:\n\t"
235
+ e.getMessage());
236
success = false;
237
return;
238
}
239
240
// start parsing reply packet data
241
log.display("Parsing reply packet data:");
242
reply.resetPosition();
243
244
// no out data
245
log.display(" no out data");
246
247
log.display(" ... packet data is parsed");
248
249
// check for extra data in reply packet
250
if (!reply.isParsed()) {
251
log.complain("Extra trailing bytes found in reply packet at: "
252
+ reply.offsetString());
253
success = false;
254
}
255
}
256
257
/**
258
* Disconnect debuggee and wait for it exited.
259
*/
260
void quitDebugee() {
261
if (debugee == null)
262
return;
263
264
// disconnect debugee if not dead
265
if (!dead) {
266
try {
267
log.display("Disconnecting debuggee");
268
debugee.dispose();
269
log.display(" ... debuggee disconnected");
270
} catch (Failure e) {
271
log.display("Failed to finally disconnect debuggee:\n\t"
272
+ e.getMessage());
273
}
274
}
275
276
// wait for debugee exited
277
log.display("Waiting for debuggee exit");
278
int code = debugee.waitFor();
279
log.display(" ... debuggee exited with exit code: " + code);
280
281
// analize debugee exit status code
282
if (code != JCK_STATUS_BASE + PASSED) {
283
log.complain("Debuggee FAILED with exit code: " + code);
284
success = false;
285
}
286
}
287
288
}
289
290