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/tc03x001.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: <br>
40
* Suite 2 - Breakpoints (multiple threads) <br>
41
* Test case: TC2 <br>
42
* Description: Class breakpoint <br>
43
* Steps: 1.Add class breakpoint: singlethread.Class1 <br>
44
* 2.Debug Main <br>
45
* X. Stops on line 13 in Class1.java <br>
46
*
47
* When the test is starting debugee, debugger creates <code>MethodEntryRequest</code>.
48
* After <code>MethodEntryEvent</code> arrived, debugger checks line number of one's
49
* location. It should be 73th line, that is constructor of <code>tc03x001aClass1</code>
50
* class. Every thread must generate <code>MethodEntryEvent</code>.
51
*
52
* In case, when at least one event doesn't arrive during waittime
53
* interval or line number of event is wrong, test fails.
54
*/
55
56
public class tc03x001 {
57
58
public final static String SGL_READY = "ready";
59
public final static String SGL_PERFORM = "perform";
60
public final static String SGL_QUIT = "quit";
61
62
private final static String prefix = "nsk.jdi.BScenarios.singlethrd.";
63
private final static String debuggerName = prefix + "tc03x001";
64
private final static String debugeeName = debuggerName + "a";
65
private final static String testedClassName = debugeeName + "Class1";
66
67
private static int exitStatus;
68
private static Log log;
69
private static Debugee debugee;
70
private static long waitTime;
71
private final static int expectedEventCount = 1;
72
private static int eventCount = 0;
73
74
private ClassType debugeeClass;
75
76
private static void display(String msg) {
77
log.display(msg);
78
}
79
80
private static void complain(String msg) {
81
log.complain("debugger FAILURE> " + msg + "\n");
82
}
83
84
public static void main(String argv[]) {
85
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
86
}
87
88
public static int run(String argv[], PrintStream out) {
89
90
exitStatus = Consts.TEST_PASSED;
91
92
tc03x001 thisTest = new tc03x001();
93
94
ArgumentHandler argHandler = new ArgumentHandler(argv);
95
log = new Log(out, argHandler);
96
97
waitTime = argHandler.getWaitTime() * 60000;
98
99
debugee = Debugee.prepareDebugee(argHandler, log, debugeeName);
100
101
try {
102
thisTest.execTest();
103
} catch (Throwable e) {
104
complain("Unexpected " + e);
105
exitStatus = Consts.TEST_FAILED;
106
e.printStackTrace();
107
} finally {
108
debugee.resume();
109
debugee.quit();
110
}
111
display("Test finished. exitStatus = " + exitStatus);
112
113
return exitStatus;
114
}
115
116
private void execTest() throws Failure {
117
118
debugeeClass = (ClassType)debugee.classByName(debugeeName);
119
display("Tested class\t:" + debugeeClass.name());
120
121
display("\nTEST BEGINS");
122
display("===========");
123
124
EventSet eventSet = null;
125
EventIterator eventIterator = null;
126
Event event;
127
long totalTime = waitTime;
128
long tmp, begin = System.currentTimeMillis(),
129
delta = 0;
130
boolean exit = false;
131
132
EventRequestManager evm = debugee.getEventRequestManager();
133
MethodEntryRequest mthdReq = evm.createMethodEntryRequest();
134
mthdReq.addClassFilter(testedClassName);
135
mthdReq.enable();
136
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 MethodEntryEvent) {
159
display(" event ===>>> " + event);
160
hitClassBreakpoint((MethodEntryEvent )event);
161
debugee.resume();
162
exit = true;
163
164
} else if (event instanceof VMDeathEvent) {
165
exit = true;
166
break;
167
} else if (event instanceof VMDisconnectEvent) {
168
exit = true;
169
break;
170
} // if
171
} // while
172
} // if
173
tmp = System.currentTimeMillis();
174
delta = tmp - begin;
175
totalTime -= delta;
176
begin = tmp;
177
}
178
179
if (eventCount < expectedEventCount) {
180
if (totalTime <= 0) {
181
complain("out of wait time...");
182
}
183
complain("expecting " + expectedEventCount
184
+ " breakpoint events, but "
185
+ eventCount + " events arrived.");
186
exitStatus = Consts.TEST_FAILED;
187
}
188
189
display("=============");
190
display("TEST FINISHES\n");
191
}
192
193
private void hitClassBreakpoint(MethodEntryEvent event) {
194
ThreadReference thrd = event.thread();
195
196
display("event info:");
197
display("\tthread\t- " + event.thread().name());
198
try {
199
display("\tsource\t- " + event.location().sourceName());
200
} catch (AbsentInformationException e) {
201
}
202
display("\tmethod\t- " + event.location().method().name());
203
display("\tline\t- " + event.location().lineNumber());
204
205
if (event.location().lineNumber() == tc03x001a.checkLastLine) {
206
display("ClassBreakpoint stops on the expected line "
207
+ event.location().lineNumber() + " in method "
208
+ event.method().name());
209
} else {
210
complain("ClassBreakpoint stops on line " + event.location().lineNumber()
211
+ " in method " + event.method().name()
212
+ ", expected line number is "
213
+ tc03x001a.checkLastLine);
214
exitStatus = Consts.TEST_FAILED;
215
}
216
217
eventCount++;
218
219
display("");
220
221
}
222
}
223
224