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/tc02x001.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: TC2
42
* Description: Line breakpoint & step over
43
* Steps: 1.Set breakpoint on line 19
44
* 2.Debug Main
45
* X. Stops on line 19
46
* 3.Run | Step over three times
47
* X. Stops on line 22 in Main.java
48
*
49
* When the test is starting debugee, debugger sets breakpoint at
50
* the 49th line (method "performTest").
51
* After the breakpoint is reached, debugger creates "step over" request
52
* and resumes debugee. For the third <code>StepEvent</code> debugger checks line
53
* number of one's location. It should be 52th line.
54
*
55
* In case, when line number of event is wrong, test fails.
56
*/
57
58
public class tc02x001 {
59
60
public final static String SGL_READY = "ready";
61
public final static String SGL_PERFORM = "perform";
62
public final static String SGL_QUIT = "quit";
63
64
private final static String prefix = "nsk.jdi.BScenarios.singlethrd.";
65
private final static String debuggerName = prefix + "tc02x001";
66
private final static String debugeeName = debuggerName + "a";
67
68
private static int exitStatus;
69
private static Log log;
70
private static Debugee debugee;
71
private static long waitTime;
72
private final static int expectedStepEventCount = 3;
73
private static int stepEventCount = 0;
74
75
private ClassType debugeeClass;
76
77
private static void display(String msg) {
78
log.display(msg);
79
}
80
81
private static void complain(String msg) {
82
log.complain("debugger FAILURE> " + msg + "\n");
83
}
84
85
public static void main(String argv[]) {
86
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
87
}
88
89
public static int run(String argv[], PrintStream out) {
90
91
exitStatus = Consts.TEST_PASSED;
92
93
tc02x001 thisTest = new tc02x001();
94
95
ArgumentHandler argHandler = new ArgumentHandler(argv);
96
log = new Log(out, argHandler);
97
98
waitTime = argHandler.getWaitTime() * 60000;
99
100
debugee = Debugee.prepareDebugee(argHandler, log, debugeeName);
101
102
try {
103
thisTest.execTest();
104
} catch (Throwable e) {
105
complain("Unexpected " + 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
EventRequestManager evm = debugee.getEventRequestManager();
134
StepRequest step = null;
135
136
debugee.setBreakpoint(debugeeClass,
137
tc02x001a.brkpMethodName,
138
tc02x001a.brkpLineNumber);
139
debugee.resume();
140
debugee.sendSignal(SGL_PERFORM);
141
142
while (totalTime > 0 && !exit) {
143
if (eventIterator == null || !eventIterator.hasNext()) {
144
try {
145
eventSet = debugee.VM().eventQueue().remove(totalTime);
146
} catch (InterruptedException e) {
147
new Failure(e);
148
}
149
if (eventSet != null) {
150
eventIterator = eventSet.eventIterator();
151
} else {
152
eventIterator = null;
153
}
154
}
155
if (eventIterator != null) {
156
while (eventIterator.hasNext()) {
157
event = eventIterator.nextEvent();
158
// display(" event ===>>> " + event);
159
160
if (event instanceof BreakpointEvent) {
161
display(" event ===>>> " + event);
162
hitBreakpoint((BreakpointEvent )event);
163
step = evm.createStepRequest(((BreakpointEvent )event).thread(),
164
StepRequest.STEP_LINE,
165
StepRequest.STEP_OVER);
166
step.enable();
167
debugee.resume();
168
169
} else if (event instanceof StepEvent) {
170
display(" event ===>>> " + event);
171
hitStepOver((StepEvent )event);
172
if (stepEventCount >= expectedStepEventCount) {
173
evm.deleteEventRequest(step);
174
}
175
debugee.resume();
176
177
} else if (event instanceof VMDeathEvent) {
178
exit = true;
179
break;
180
} else if (event instanceof VMDisconnectEvent) {
181
exit = true;
182
break;
183
} // if
184
} // while
185
} // if
186
exit = exit || (stepEventCount == expectedStepEventCount);
187
tmp = System.currentTimeMillis();
188
delta = tmp - begin;
189
totalTime -= delta;
190
begin = tmp;
191
}
192
193
if (stepEventCount < expectedStepEventCount) {
194
if (totalTime <= 0) {
195
complain("out of wait time...");
196
}
197
complain("expecting " + expectedStepEventCount
198
+ " step events, but "
199
+ stepEventCount + " events arrived.");
200
exitStatus = Consts.TEST_FAILED;
201
}
202
203
display("=============");
204
display("TEST FINISHES\n");
205
}
206
207
private void hitBreakpoint(BreakpointEvent event) {
208
display("BreakpointEvent arrived. Location - "
209
+ event.location().lineNumber() + " line");
210
display("");
211
}
212
213
private void hitStepOver(StepEvent event) {
214
stepEventCount++;
215
216
display("event info:");
217
display("\tthread\t- " + event.thread().name());
218
try {
219
display("\tsource\t- " + event.location().sourceName());
220
} catch (AbsentInformationException e) {
221
}
222
display("\tmethod\t- " + event.location().method().name());
223
display("\tline\t- " + event.location().lineNumber());
224
225
if (stepEventCount == expectedStepEventCount) {
226
if (event.location().lineNumber() != tc02x001a.checkLastLine) {
227
complain("StepEvent steps to line " + event.location().lineNumber()
228
+ ", expected line number is "
229
+ tc02x001a.checkLastLine);
230
exitStatus = Consts.TEST_FAILED;
231
} else {
232
display("StepEvent steps to the expected line "
233
+ event.location().lineNumber());
234
}
235
}
236
display("");
237
}
238
}
239
240