Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequest/setEnabled/setenabled003.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.EventRequest.setEnabled;
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
* EventRequest. <BR>
40
* <BR>
41
* The test checks that results of the method <BR>
42
* <code>com.sun.jdi.EventRequest.setEnabled()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks up on the following assertion: <BR>
46
* - IllegalThreadStateException - <BR>
47
* if this is a StepRequest, val is true, and <BR>
48
* the thread named in the request has died. <BR>
49
* The cases to test include three states of <BR>
50
* the thread named in the request: not started, running, dead. <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 assertion, <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 check case 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 check case 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 setenabled003 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 setenabled003().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.EventRequest.setEnabled.setenabled003a";
104
105
private String testedClassName =
106
"nsk.jdi.EventRequest.setEnabled.Thread1setenabled003a";
107
108
//====================================================== test program
109
110
private int runThis (String argv[], PrintStream out) {
111
112
argsHandler = new ArgumentHandler(argv);
113
logHandler = new Log(out, argsHandler);
114
Binder binder = new Binder(argsHandler, logHandler);
115
116
waitTime = argsHandler.getWaitTime() * 60000;
117
118
try {
119
log2("launching a debuggee :");
120
log2(" " + debuggeeName);
121
if (argsHandler.verbose()) {
122
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
123
} else {
124
debuggee = binder.bindToDebugee(debuggeeName);
125
}
126
if (debuggee == null) {
127
log3("ERROR: no debuggee launched");
128
return FAILED;
129
}
130
log2("debuggee launched");
131
} catch ( Exception e ) {
132
log3("ERROR: Exception : " + e);
133
log2(" test cancelled");
134
return FAILED;
135
}
136
137
debuggee.redirectOutput(logHandler);
138
139
vm = debuggee.VM();
140
141
eventQueue = vm.eventQueue();
142
if (eventQueue == null) {
143
log3("ERROR: eventQueue == null : TEST ABORTED");
144
vm.exit(PASS_BASE);
145
return FAILED;
146
}
147
148
log2("invocation of the method runTest()");
149
switch (runTest()) {
150
151
case 0 : log2("test phase has finished normally");
152
log2(" waiting for the debuggee to finish ...");
153
debuggee.waitFor();
154
155
log2("......getting the debuggee's exit status");
156
int status = debuggee.getStatus();
157
if (status != PASS_BASE) {
158
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
159
status + " != PASS_BASE");
160
testExitCode = FAILED;
161
} else {
162
log2("......debuggee returned expected exit status: " +
163
status + " == PASS_BASE");
164
}
165
break;
166
167
default : log3("ERROR: runTest() returned unexpected value");
168
169
case 1 : log3("test phase has not finished normally: debuggee is still alive");
170
log2("......forcing: vm.exit();");
171
testExitCode = FAILED;
172
try {
173
vm.exit(PASS_BASE);
174
} catch ( Exception e ) {
175
log3("ERROR: Exception : " + e);
176
}
177
break;
178
179
case 2 : log3("test cancelled due to VMDisconnectedException");
180
log2("......trying: vm.process().destroy();");
181
testExitCode = FAILED;
182
try {
183
Process vmProcess = vm.process();
184
if (vmProcess != null) {
185
vmProcess.destroy();
186
}
187
} catch ( Exception e ) {
188
log3("ERROR: Exception : " + e);
189
}
190
break;
191
}
192
193
return testExitCode;
194
}
195
196
197
/*
198
* Return value: 0 - normal end of the test
199
* 1 - ubnormal end of the test
200
* 2 - VMDisconnectedException while test phase
201
*/
202
203
private int runTest() {
204
205
try {
206
testRun();
207
208
log2("waiting for VMDeathEvent");
209
getEventSet();
210
if (eventIterator.nextEvent() instanceof VMDeathEvent)
211
return 0;
212
213
log3("ERROR: last event is not the VMDeathEvent");
214
return 1;
215
} catch ( VMDisconnectedException e ) {
216
log3("ERROR: VMDisconnectedException : " + e);
217
return 2;
218
} catch ( Exception e ) {
219
log3("ERROR: Exception : " + e);
220
return 1;
221
}
222
223
}
224
225
private void testRun()
226
throws JDITestRuntimeException, Exception {
227
228
eventRManager = vm.eventRequestManager();
229
230
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
231
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
232
cpRequest.addClassFilter(debuggeeName);
233
234
cpRequest.enable();
235
vm.resume();
236
getEventSet();
237
cpRequest.disable();
238
239
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
240
debuggeeClass = event.referenceType();
241
242
if (!debuggeeClass.name().equals(debuggeeName))
243
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
244
245
log2(" received: ClassPrepareEvent for debuggeeClass");
246
247
String bPointMethod = "methodForCommunication";
248
String lineForComm = "lineForComm";
249
250
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
251
252
BreakpointRequest bpRequest = settingBreakpoint(mainThread,
253
debuggeeClass,
254
bPointMethod, lineForComm, "zero");
255
bpRequest.enable();
256
257
//------------------------------------------------------ testing section
258
259
260
EventRequest eventRequest1 = null;
261
262
ThreadReference thread1 = null;
263
String threadName1 = "thread1";
264
265
266
log1(" TESTING BEGINS");
267
268
for (int i = 0; ; i++) {
269
270
vm.resume();
271
breakpointForCommunication();
272
273
int instruction = ((IntegerValue)
274
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
275
276
if (instruction == 0) {
277
vm.resume();
278
break;
279
}
280
281
log1(":::::: case: # " + i);
282
283
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
284
285
vm.suspend();
286
switch (i) {
287
288
case 0:
289
thread1 = (ThreadReference)
290
debuggeeClass.getValue(debuggeeClass.fieldByName(threadName1));
291
292
log2("......setting up StepRequest");
293
eventRequest1 = eventRManager.createStepRequest
294
(thread1, StepRequest.STEP_MIN, StepRequest.STEP_INTO);
295
try {
296
log2("......eventRequest1.setEnabled(true); IllegalThreadStateException is expected");
297
eventRequest1.setEnabled(true);
298
log3("ERROR: case 0 : no IllegalThreadStateException");
299
testExitCode = FAILED;
300
} catch ( IllegalThreadStateException e ) {
301
log2(" not started thread");
302
log2(" : IllegalThreadStateException when setEnabled(true)");
303
}
304
try {
305
log2("......eventRequest1.setEnabled(false); IllegalThreadStateException is not expected");
306
eventRequest1.setEnabled(false);
307
log2(" no IllegalThreadStateException");
308
} catch ( IllegalThreadStateException e ) {
309
testExitCode = FAILED;
310
log3("ERROR: case 0 : not started thread");
311
log3(" : IllegalThreadStateException when setEnabled(false)");
312
}
313
break;
314
315
case 1:
316
try {
317
log2("......eventRequest1.setEnabled(true); IllegalThreadStateException is not expected");
318
eventRequest1.setEnabled(true);
319
log2(" no IllegalThreadStateException");
320
} catch ( IllegalThreadStateException e ) {
321
testExitCode = FAILED;
322
log3("ERROR: case 1 : running thread");
323
log3(" : IllegalThreadStateException when setEnabled(true)");
324
}
325
try {
326
log2("......eventRequest1.setEnabled(false); IllegalThreadStateException is not expected");
327
eventRequest1.setEnabled(false);
328
log2(" no IllegalThreadStateException");
329
} catch ( IllegalThreadStateException e ) {
330
testExitCode = FAILED;
331
log3("ERROR: case 1 : running thread");
332
log3(" : IllegalThreadStateException when setEnabled(false)");
333
}
334
break;
335
336
case 2:
337
try {
338
log2("......eventRequest1.setEnabled(true); IllegalThreadStateException is expected");
339
eventRequest1.setEnabled(true);
340
testExitCode = FAILED;
341
log3("ERROR: case 2 : dead thread");
342
log3(" : NO IllegalThreadStateException when setEnabled(true)");
343
} catch ( IllegalThreadStateException e ) {
344
log2(" IllegalThreadStateException");
345
}
346
try {
347
log2("......eventRequest1.setEnabled(false); IllegalThreadStateException is not expected");
348
eventRequest1.setEnabled(false);
349
log2(" no IllegalThreadStateException");
350
} catch ( IllegalThreadStateException e ) {
351
testExitCode = FAILED;
352
log3("ERROR: case 2 : dead thread");
353
log3(" : IllegalThreadStateException when setEnabled(false)");
354
}
355
break;
356
357
358
default:
359
throw new JDITestRuntimeException("** default case 2 **");
360
}
361
vm.resume();
362
363
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
364
}
365
log1(" TESTING ENDS");
366
return;
367
}
368
369
}
370
371