Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/singlethrd/tc01x002.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.singlethrd;
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:
40
* Suite 1 - Breakpoints (single threads)
41
* Test case: TC1
42
* Description: Line breakpoint & step into
43
* Steps: 1.Set breakpoint on line 19
44
* 2.Debug Main
45
* X. Stops on line 19
46
* 3.Run | Step into three times
47
* X. Steps into Class1 constructor
48
*
49
* When the test is starting debugee, debugger sets breakpoint at
50
* the 49th line (method <code>performTest</code>).
51
* After the breakpoint is reached, debugger creates "step into" request
52
* and resumes debugee. <code>StepRequest</code> is created with specified
53
* <code>addClassExclusionFilter</code>. For the third <code>StepEvent</code>
54
* debugger checks line number of one's location. It should be 56th line.
55
*
56
* In case, when line number of event is wrong, test fails.
57
*/
58
59
public class tc01x002 {
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.singlethrd.";
66
private final static String debuggerName = prefix + "tc01x002";
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 final static int expectedStepEventCount = 3;
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
tc01x002 thisTest = new tc01x002();
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
complain("Unexpected " + e);
107
exitStatus = Consts.TEST_FAILED;
108
e.printStackTrace();
109
} finally {
110
debugee.resume();
111
debugee.quit();
112
}
113
display("Test finished. exitStatus = " + exitStatus);
114
115
return exitStatus;
116
}
117
118
private void execTest() throws Failure {
119
120
debugeeClass = (ClassType)debugee.classByName(debugeeName);
121
122
display("\nTEST BEGINS");
123
display("===========");
124
125
display("Tested class\t:" + debugeeClass.name());
126
127
EventSet eventSet = null;
128
EventIterator eventIterator = null;
129
Event event;
130
long totalTime = waitTime;
131
long tmp, begin = System.currentTimeMillis(),
132
delta = 0;
133
boolean exit = false;
134
EventRequestManager evm = debugee.getEventRequestManager();
135
StepRequest step = null;
136
137
debugee.setBreakpoint(debugeeClass,
138
tc01x002a.brkpMethodName,
139
tc01x002a.brkpLineNumber);
140
debugee.resume();
141
debugee.sendSignal(SGL_PERFORM);
142
143
while (totalTime > 0 && !exit) {
144
if (eventIterator == null || !eventIterator.hasNext()) {
145
try {
146
eventSet = debugee.VM().eventQueue().remove(totalTime);
147
} catch (InterruptedException e) {
148
new Failure(e);
149
}
150
if (eventSet != null) {
151
eventIterator = eventSet.eventIterator();
152
} else {
153
eventIterator = null;
154
}
155
}
156
if (eventIterator != null) {
157
while (eventIterator.hasNext()) {
158
event = eventIterator.nextEvent();
159
// display(" event ===>>> " + event);
160
161
if (event instanceof BreakpointEvent) {
162
display(" event ===>>> " + event);
163
hitBreakpoint((BreakpointEvent )event);
164
step = evm.createStepRequest(((BreakpointEvent )event).thread(),
165
StepRequest.STEP_LINE,
166
StepRequest.STEP_INTO);
167
step.addClassExclusionFilter("nsk.share.*");
168
step.addClassExclusionFilter("java.*");
169
step.addClassExclusionFilter("sun.*");
170
step.addClassExclusionFilter("oracle.*");
171
step.addClassExclusionFilter("jdk.jfr.*");
172
step.addClassExclusionFilter("com.oracle.*");
173
step.addClassExclusionFilter("jdk.internal.*");
174
step.enable();
175
debugee.resume();
176
177
} else if (event instanceof StepEvent) {
178
display(" event ===>>> " + event);
179
hitStepInto((StepEvent )event);
180
if (stepEventCount >= expectedStepEventCount) {
181
evm.deleteEventRequest(step);
182
}
183
debugee.resume();
184
185
} else if (event instanceof VMDeathEvent) {
186
exit = true;
187
break;
188
} else if (event instanceof VMDisconnectEvent) {
189
exit = true;
190
break;
191
} // if
192
} // while
193
} // if
194
exit = exit || (stepEventCount == expectedStepEventCount);
195
tmp = System.currentTimeMillis();
196
delta = tmp - begin;
197
totalTime -= delta;
198
begin = tmp;
199
}
200
201
if (stepEventCount < expectedStepEventCount) {
202
if (totalTime <= 0) {
203
complain("out of wait time...");
204
}
205
complain("expecting " + expectedStepEventCount
206
+ " step events, but "
207
+ stepEventCount + " events arrived.");
208
exitStatus = Consts.TEST_FAILED;
209
}
210
211
display("=============");
212
display("TEST FINISHES\n");
213
}
214
215
private void hitBreakpoint(BreakpointEvent event) {
216
display("BreakpointEvent arrived. Location - "
217
+ event.location().lineNumber() + " line");
218
display("");
219
}
220
221
private void hitStepInto(StepEvent event) {
222
stepEventCount++;
223
224
display("event info:");
225
display("\tthread\t- " + event.thread().name());
226
try {
227
display("\tsource\t- " + event.location().sourceName());
228
} catch (AbsentInformationException e) {
229
}
230
display("\tmethod\t- " + event.location().method().name());
231
display("\tline\t- " + event.location().lineNumber());
232
233
if (stepEventCount == expectedStepEventCount) {
234
if (event.location().lineNumber() != tc01x002a.checkLastLine) {
235
complain("StepEvent steps to line " + event.location().lineNumber()
236
+ ", expected line number is "
237
+ tc01x002a.checkLastLine);
238
exitStatus = Consts.TEST_FAILED;
239
} else {
240
display("StepEvent steps to the expected line "
241
+ event.location().lineNumber());
242
}
243
}
244
display("");
245
}
246
}
247
248