Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createStepRequest/crstepreq002.java
41161 views
1
/*
2
* Copyright (c) 2001, 2020, 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.jdi.EventRequestManager.createStepRequest;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdi.*;
29
30
import com.sun.jdi.*;
31
import com.sun.jdi.event.*;
32
import com.sun.jdi.request.*;
33
34
import java.util.*;
35
import java.io.*;
36
37
/**
38
* The test for the implementation of an object of the type <BR>
39
* EventRequestManager. <BR>
40
* <BR>
41
* The test checks that results of the method <BR>
42
* <code>com.sun.jdi.EventRequestManager.createStepRequest()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks up on the following assertion: <BR>
46
* - Creates a new disabled StepRequest. <BR>
47
* - STEP_MIN, STEP_LINE, STEP_INTO, STEP_OVER, STEP_OUT are valid <BR>
48
* arguments, that is, they don't throw IllegalArgumentException. <BR>
49
* - Values larger and lesser corresponding above are invalid arguments,<BR>
50
* that is, they do throw IllegalArgumentException. <BR>
51
* <BR>
52
* The test has three phases and works as follows. <BR>
53
* <BR>
54
* In first phase, <BR>
55
* upon launching debuggee's VM which will be suspended, <BR>
56
* a debugger waits for the VMStartEvent within a predefined <BR>
57
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
58
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
59
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
60
* and waits for the event within the predefined time interval. <BR>
61
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
62
* Upon getting the ClassPrepareEvent, <BR>
63
* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>
64
* within debuggee's special methodForCommunication(). <BR>
65
* <BR>
66
* In second phase to check the assertions, <BR>
67
* the debugger and the debuggee perform the following. <BR>
68
* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
69
* - The debuggee prepares new testcase and invokes <BR>
70
* the methodForCommunication to be suspended and <BR>
71
* to inform the debugger with the event. <BR>
72
* - Upon getting the BreakpointEvent, <BR>
73
* the debugger performs the checks required. <BR>
74
* <BR>
75
* In third phase, at the end of the test, the debuggee changes <BR>
76
* the value of the "instruction" which the debugger and debuggee <BR>
77
* use to inform each other of needed actions, and both end. <BR>
78
* <BR>
79
*/
80
81
public class crstepreq002 extends JDIBase {
82
83
public static void main (String argv[]) {
84
85
int result = run(argv, System.out);
86
87
System.exit(result + PASS_BASE);
88
}
89
90
public static int run (String argv[], PrintStream out) {
91
92
int exitCode = new crstepreq002().runThis(argv, out);
93
94
if (exitCode != PASSED) {
95
System.out.println("TEST FAILED");
96
}
97
return testExitCode;
98
}
99
100
// ************************************************ test parameters
101
102
private String debuggeeName =
103
"nsk.jdi.EventRequestManager.createStepRequest.crstepreq002a";
104
105
//====================================================== test program
106
107
private int runThis (String argv[], PrintStream out) {
108
109
argsHandler = new ArgumentHandler(argv);
110
logHandler = new Log(out, argsHandler);
111
Binder binder = new Binder(argsHandler, logHandler);
112
113
waitTime = argsHandler.getWaitTime() * 60000;
114
115
try {
116
log2("launching a debuggee :");
117
log2(" " + debuggeeName);
118
if (argsHandler.verbose()) {
119
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
120
} else {
121
debuggee = binder.bindToDebugee(debuggeeName);
122
}
123
if (debuggee == null) {
124
log3("ERROR: no debuggee launched");
125
return FAILED;
126
}
127
log2("debuggee launched");
128
} catch ( Exception e ) {
129
log3("ERROR: Exception : " + e);
130
log2(" test cancelled");
131
return FAILED;
132
}
133
134
debuggee.redirectOutput(logHandler);
135
136
vm = debuggee.VM();
137
138
eventQueue = vm.eventQueue();
139
if (eventQueue == null) {
140
log3("ERROR: eventQueue == null : TEST ABORTED");
141
vm.exit(PASS_BASE);
142
return FAILED;
143
}
144
145
log2("invocation of the method runTest()");
146
switch (runTest()) {
147
148
case 0 : log2("test phase has finished normally");
149
log2(" waiting for the debuggee to finish ...");
150
debuggee.waitFor();
151
152
log2("......getting the debuggee's exit status");
153
int status = debuggee.getStatus();
154
if (status != PASS_BASE) {
155
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
156
status + " != PASS_BASE");
157
testExitCode = FAILED;
158
} else {
159
log2("......debuggee returned expected exit status: " +
160
status + " == PASS_BASE");
161
}
162
break;
163
164
default : log3("ERROR: runTest() returned unexpected value");
165
166
case 1 : log3("test phase has not finished normally: debuggee is still alive");
167
log2("......forcing: vm.exit();");
168
testExitCode = FAILED;
169
try {
170
vm.exit(PASS_BASE);
171
} catch ( Exception e ) {
172
log3("ERROR: Exception : " + e);
173
}
174
break;
175
176
case 2 : log3("test cancelled due to VMDisconnectedException");
177
log2("......trying: vm.process().destroy();");
178
testExitCode = FAILED;
179
try {
180
Process vmProcess = vm.process();
181
if (vmProcess != null) {
182
vmProcess.destroy();
183
}
184
} catch ( Exception e ) {
185
log3("ERROR: Exception : " + e);
186
}
187
break;
188
}
189
190
return testExitCode;
191
}
192
193
194
/*
195
* Return value: 0 - normal end of the test
196
* 1 - ubnormal end of the test
197
* 2 - VMDisconnectedException while test phase
198
*/
199
200
private int runTest() {
201
202
try {
203
testRun();
204
205
log2("waiting for VMDeathEvent");
206
getEventSet();
207
if (eventIterator.nextEvent() instanceof VMDeathEvent)
208
return 0;
209
210
log3("ERROR: last event is not the VMDeathEvent");
211
return 1;
212
} catch ( VMDisconnectedException e ) {
213
log3("ERROR: VMDisconnectedException : " + e);
214
return 2;
215
} catch ( Exception e ) {
216
log3("ERROR: Exception : " + e);
217
return 1;
218
}
219
220
}
221
222
private void testRun()
223
throws JDITestRuntimeException, Exception {
224
225
eventRManager = vm.eventRequestManager();
226
227
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
228
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
229
cpRequest.addClassFilter(debuggeeName);
230
231
cpRequest.enable();
232
vm.resume();
233
getEventSet();
234
cpRequest.disable();
235
236
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
237
debuggeeClass = event.referenceType();
238
239
if (!debuggeeClass.name().equals(debuggeeName))
240
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
241
242
log2(" received: ClassPrepareEvent for debuggeeClass");
243
244
String bPointMethod = "methodForCommunication";
245
String lineForComm = "lineForComm";
246
247
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
248
249
BreakpointRequest bpRequest = settingBreakpoint(mainThread,
250
debuggeeClass,
251
bPointMethod, lineForComm, "zero");
252
bpRequest.enable();
253
254
//------------------------------------------------------ testing section
255
256
ThreadReference thread = null;
257
String threadName = "thread1";
258
259
StepRequest stRequest = null;
260
261
int minDepth, maxDepth;
262
int minSize, maxSize;
263
264
265
log1(" TESTING BEGINS");
266
267
for (int i = 0; ; i++) {
268
269
vm.resume();
270
breakpointForCommunication();
271
272
int instruction = ((IntegerValue)
273
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
274
275
if (instruction == 0) {
276
vm.resume();
277
break;
278
}
279
280
log1(":::::: case: # " + i);
281
282
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
283
284
thread = debuggee.threadByNameOrThrow(threadName);
285
286
if (StepRequest.STEP_MIN > StepRequest.STEP_LINE) {
287
maxSize = StepRequest.STEP_MIN;
288
minSize = StepRequest.STEP_LINE;
289
} else {
290
minSize = StepRequest.STEP_MIN;
291
maxSize = StepRequest.STEP_LINE;
292
}
293
294
if ( (StepRequest.STEP_INTO > StepRequest.STEP_OVER) &&
295
(StepRequest.STEP_INTO > StepRequest.STEP_OUT) )
296
maxDepth = StepRequest.STEP_INTO;
297
298
if ( (StepRequest.STEP_OVER > StepRequest.STEP_INTO) &&
299
(StepRequest.STEP_OVER > StepRequest.STEP_OUT) )
300
maxDepth = StepRequest.STEP_OVER;
301
302
if ( (StepRequest.STEP_OUT > StepRequest.STEP_OVER) &&
303
(StepRequest.STEP_OUT > StepRequest.STEP_INTO) )
304
maxDepth = StepRequest.STEP_OUT;
305
306
if ( (StepRequest.STEP_INTO < StepRequest.STEP_OVER) &&
307
(StepRequest.STEP_INTO < StepRequest.STEP_OUT) )
308
minDepth = StepRequest.STEP_INTO;
309
310
if ( (StepRequest.STEP_OVER < StepRequest.STEP_INTO) &&
311
(StepRequest.STEP_OVER < StepRequest.STEP_OUT) )
312
minDepth = StepRequest.STEP_OVER;
313
314
if ( (StepRequest.STEP_OUT < StepRequest.STEP_OVER) &&
315
(StepRequest.STEP_OUT < StepRequest.STEP_INTO) )
316
minDepth = StepRequest.STEP_OUT;
317
318
try {
319
log2("......creating: eventRManager.createStepRequest(thread, StepRequest.STEP_MIN, StepRequest.STEP_INTO);");
320
stRequest = eventRManager.createStepRequest(thread, StepRequest.STEP_MIN, StepRequest.STEP_INTO);
321
log2(" checking up on if request is disabled");
322
if (stRequest.isEnabled()) {
323
testExitCode = FAILED;
324
log3("ERROR: request is enabled");
325
}
326
} catch ( IllegalArgumentException e ) {
327
testExitCode = FAILED;
328
log3("ERROR: IllegalArgumentException for STEP_MIN - STEP_INTO");
329
}
330
eventRManager.deleteEventRequest(stRequest);
331
try {
332
log2("......creating: eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, StepRequest.STEP_OVER);");
333
stRequest = eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, StepRequest.STEP_OVER);
334
log2(" checking up on if request is disabled");
335
if (stRequest.isEnabled()) {
336
testExitCode = FAILED;
337
log3("ERROR: request is enabled");
338
}
339
} catch ( IllegalArgumentException e ) {
340
testExitCode = FAILED;
341
log3("ERROR: IllegalArgumentException for STEP_LINE - STEP_OVER");
342
}
343
eventRManager.deleteEventRequest(stRequest);
344
try {
345
log2("......creating: eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, StepRequest.STEP_OUT);");
346
stRequest = eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, StepRequest.STEP_OUT);
347
log2(" checking up on if request is disabled");
348
if (stRequest.isEnabled()) {
349
testExitCode = FAILED;
350
log3("ERROR: request is enabled");
351
}
352
} catch ( IllegalArgumentException e ) {
353
testExitCode = FAILED;
354
log3("ERROR: IllegalArgumentException for STEP_LINE - STEP_OUT");
355
}
356
eventRManager.deleteEventRequest(stRequest);
357
log2("......creating: eventRManager.createStepRequest(thread, minSize -1, StepRequest.STEP_OUT);");
358
log2(" IllegalArgumentException is expected");
359
try {
360
stRequest = eventRManager.createStepRequest(thread, minSize -1, StepRequest.STEP_OUT);
361
testExitCode = FAILED;
362
log3("ERROR: no IllegalArgumentException thrown");
363
} catch ( IllegalArgumentException e ) {
364
}
365
eventRManager.deleteEventRequest(stRequest);
366
log2("......creating: eventRManager.createStepRequest(thread, maxSize +1, StepRequest.STEP_OUT);");
367
log2(" IllegalArgumentException is expected");
368
try {
369
stRequest = eventRManager.createStepRequest(thread, maxSize +1, StepRequest.STEP_OUT);
370
testExitCode = FAILED;
371
log3("ERROR: no IllegalArgumentException thrown");
372
} catch ( IllegalArgumentException e ) {
373
}
374
eventRManager.deleteEventRequest(stRequest);
375
log2("......creating: eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, minDepth -1);");
376
log2(" IllegalArgumentException is expected");
377
try {
378
stRequest = eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, minDepth -1);
379
testExitCode = FAILED;
380
log3("ERROR: no IllegalArgumentException thrown");
381
} catch ( IllegalArgumentException e ) {
382
}
383
eventRManager.deleteEventRequest(stRequest);
384
log2("......creating: eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, maxDepth +1);");
385
log2(" IllegalArgumentException is expected");
386
try {
387
stRequest = eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, maxDepth +1);
388
testExitCode = FAILED;
389
log3("ERROR: no IllegalArgumentException thrown");
390
} catch ( IllegalArgumentException e ) {
391
}
392
393
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
394
}
395
log1(" TESTING ENDS");
396
return;
397
}
398
399
}
400
401