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/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.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 48th 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>addClassFilter</code>. For the third <code>StepEvent</code> debugger
54
* 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 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.singlethrd.";
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 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
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
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
tc01x001a.brkpMethodName,
139
tc01x001a.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.addClassFilter(prefix + "*");
168
step.enable();
169
debugee.resume();
170
171
} else if (event instanceof StepEvent) {
172
display(" event ===>>> " + event);
173
hitStepInto((StepEvent )event);
174
if (stepEventCount >= expectedStepEventCount) {
175
evm.deleteEventRequest(step);
176
}
177
debugee.resume();
178
179
} else if (event instanceof VMDeathEvent) {
180
exit = true;
181
break;
182
} else if (event instanceof VMDisconnectEvent) {
183
exit = true;
184
break;
185
} // if
186
} // while
187
} // if
188
exit = exit || (stepEventCount == expectedStepEventCount);
189
tmp = System.currentTimeMillis();
190
delta = tmp - begin;
191
totalTime -= delta;
192
begin = tmp;
193
}
194
195
if (stepEventCount < expectedStepEventCount) {
196
if (totalTime <= 0) {
197
complain("out of wait time...");
198
}
199
complain("expecting " + expectedStepEventCount
200
+ " step events, but "
201
+ stepEventCount + " events arrived.");
202
exitStatus = Consts.TEST_FAILED;
203
}
204
205
display("=============");
206
display("TEST FINISHES\n");
207
}
208
209
private void hitBreakpoint(BreakpointEvent event) {
210
display("BreakpointEvent arrived. Location - "
211
+ event.location().lineNumber() + " line");
212
display("");
213
}
214
215
private void hitStepInto(StepEvent event) {
216
stepEventCount++;
217
218
display("event info:");
219
display("\tthread\t- " + event.thread().name());
220
try {
221
display("\tsource\t- " + event.location().sourceName());
222
} catch (AbsentInformationException e) {
223
}
224
display("\tmethod\t- " + event.location().method().name());
225
display("\tline\t- " + event.location().lineNumber());
226
227
if (stepEventCount == expectedStepEventCount) {
228
if (event.location().lineNumber() != tc01x001a.checkLastLine) {
229
complain("StepEvent steps to line " + event.location().lineNumber()
230
+ ", expected line number is "
231
+ tc01x001a.checkLastLine);
232
exitStatus = Consts.TEST_FAILED;
233
} else {
234
display("StepEvent steps to the expected line "
235
+ event.location().lineNumber());
236
}
237
}
238
display("");
239
}
240
}
241
242