Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/multithrd/tc01x001.java
41160 views
1
/*
2
* Copyright (c) 2002, 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.jdi.BScenarios.multithrd;
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.request.*;
32
import com.sun.jdi.event.*;
33
34
import java.util.*;
35
import java.io.*;
36
37
/**
38
* This test is from the group of so-called Borland's scenarios and
39
* implements the following test case: <br>
40
* Suite 2 - Breakpoints (multiple threads) <br>
41
* TC1 <br>
42
* Description: Line breakpoint & step <br>
43
* Steps: 1.Set breakpoint on line 32 <br>
44
* 2.Debug Main <br>
45
* X. Stops on line 32 <br>
46
* 3.Run | Step over <br>
47
* X. Steps to line 33 <br>
48
*
49
* When the test is starting debugee, debugger sets breakpoint at the 69th
50
* line (method "foo"). After the breakpoint is reached, debugger creates
51
* "step over" request and resumes debugee. For every hit event debugger
52
* checks line number of one's location. It should be 69th line for Breakpoint
53
* or 70th line for Step.
54
*
55
* In case, when at least one event doesn't arrive during waittime
56
* interval or line number of event is wrong, test fails.
57
*/
58
59
public class tc01x001 {
60
61
public final static String SGL_READY = "ready";
62
public final static String SGL_PERFORM = "perform";
63
public final static String SGL_QUIT = "quit";
64
65
private final static String prefix = "nsk.jdi.BScenarios.multithrd.";
66
private final static String debuggerName = prefix + "tc01x001";
67
private final static String debugeeName = debuggerName + "a";
68
69
private static int exitStatus;
70
private static Log log;
71
private static Debugee debugee;
72
private static long waitTime;
73
private static int brkpEventCount = 0;
74
private static int stepEventCount = 0;
75
76
private ClassType debugeeClass;
77
78
private static void display(String msg) {
79
log.display(msg);
80
}
81
82
private static void complain(String msg) {
83
log.complain("debugger FAILURE> " + msg + "\n");
84
}
85
86
public static void main(String argv[]) {
87
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
88
}
89
90
public static int run(String argv[], PrintStream out) {
91
92
exitStatus = Consts.TEST_PASSED;
93
94
tc01x001 thisTest = new tc01x001();
95
96
ArgumentHandler argHandler = new ArgumentHandler(argv);
97
log = new Log(out, argHandler);
98
99
waitTime = argHandler.getWaitTime() * 60000;
100
101
debugee = Debugee.prepareDebugee(argHandler, log, debugeeName);
102
103
try {
104
thisTest.execTest();
105
} catch (Throwable e) {
106
exitStatus = Consts.TEST_FAILED;
107
e.printStackTrace();
108
} finally {
109
debugee.resume();
110
debugee.quit();
111
}
112
display("Test finished. exitStatus = " + exitStatus);
113
114
return exitStatus;
115
}
116
117
private void execTest() throws Failure {
118
119
debugeeClass = (ClassType)debugee.classByName(debugeeName);
120
121
display("\nTEST BEGINS");
122
display("===========");
123
124
display("Tested class\t:" + debugeeClass.name());
125
126
EventSet eventSet = null;
127
EventIterator eventIterator = null;
128
Event event;
129
long totalTime = waitTime;
130
long tmp, begin = System.currentTimeMillis(),
131
delta = 0;
132
boolean exit = false;
133
134
debugee.setBreakpoint(debugeeClass,
135
tc01x001a.brkpMethodName,
136
tc01x001a.brkpLineNumber);
137
debugee.resume();
138
debugee.sendSignal(SGL_PERFORM);
139
140
while (totalTime > 0 && !exit) {
141
if (eventIterator == null || !eventIterator.hasNext()) {
142
try {
143
eventSet = debugee.VM().eventQueue().remove(totalTime);
144
} catch (InterruptedException e) {
145
new Failure(e);
146
}
147
if (eventSet != null) {
148
eventIterator = eventSet.eventIterator();
149
} else {
150
eventIterator = null;
151
}
152
}
153
if (eventIterator != null) {
154
while (eventIterator.hasNext()) {
155
event = eventIterator.nextEvent();
156
// display(" event ===>>> " + event);
157
158
if (event instanceof BreakpointEvent) {
159
display(" event ===>>> " + event);
160
hitBreakpoint((BreakpointEvent )event);
161
debugee.resume();
162
163
} else if (event instanceof StepEvent) {
164
display(" event ===>>> " + event);
165
hitStepOver((StepEvent )event);
166
debugee.resume();
167
168
} else if (event instanceof VMDeathEvent) {
169
exit = true;
170
break;
171
} else if (event instanceof VMDisconnectEvent) {
172
exit = true;
173
break;
174
} // if
175
} // while
176
} // if
177
exit = exit || (brkpEventCount == tc01x001a.threadCount &&
178
stepEventCount == tc01x001a.threadCount);
179
tmp = System.currentTimeMillis();
180
delta = tmp - begin;
181
totalTime -= delta;
182
begin = tmp;
183
}
184
185
if (brkpEventCount < tc01x001a.threadCount) {
186
if (totalTime <= 0) {
187
complain("out of wait time...");
188
}
189
complain("expecting " + tc01x001a.threadCount
190
+ " MethodBreakpoint events, but "
191
+ brkpEventCount + " events arrived.");
192
exitStatus = Consts.TEST_FAILED;
193
}
194
195
display("=============");
196
display("TEST FINISHES\n");
197
}
198
199
private void hitBreakpoint(BreakpointEvent event) {
200
EventRequestManager evm = debugee.getEventRequestManager();
201
ThreadReference thrd = event.thread();
202
203
display("event info:");
204
display("\tthread\t- " + event.thread().name());
205
try {
206
display("\tsource\t- " + event.location().sourceName());
207
} catch (AbsentInformationException e) {
208
}
209
display("\tmethod\t- " + event.location().method().name());
210
display("\tline\t- " + event.location().lineNumber());
211
212
if (event.location().lineNumber() != tc01x001a.checkBrkpLine) {
213
complain("BreakpointEvent stops on line " + event.location().lineNumber()
214
+ ", expected line number is " + tc01x001a.checkBrkpLine);
215
exitStatus = Consts.TEST_FAILED;
216
} else {
217
display("BreakpointEvent stops on the expected line "
218
+ event.location().lineNumber());
219
}
220
221
display("");
222
StepRequest step = evm.createStepRequest(thrd, StepRequest.STEP_LINE,
223
StepRequest.STEP_OVER);
224
brkpEventCount++;
225
step.enable();
226
}
227
228
private void hitStepOver(StepEvent event) {
229
EventRequestManager evm = debugee.getEventRequestManager();
230
231
display("event info:");
232
display("\tthread\t- " + event.thread().name());
233
try {
234
display("\tsource\t- " + event.location().sourceName());
235
} catch (AbsentInformationException e) {
236
}
237
display("\tmethod\t- " + event.location().method().name());
238
display("\tline\t- " + event.location().lineNumber());
239
240
if (event.location().lineNumber() != tc01x001a.checkStepLine) {
241
complain("StepEvent steps to line " + event.location().lineNumber()
242
+ ", expected line number is " + tc01x001a.checkStepLine);
243
exitStatus = Consts.TEST_FAILED;
244
} else {
245
display("StepEvent steps to the expected line "
246
+ event.location().lineNumber());
247
}
248
display("");
249
250
evm.deleteEventRequest(event.request());
251
stepEventCount++;
252
}
253
}
254
255