Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/JdbTest.java
41161 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.share.jdb;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
29
import java.io.*;
30
import java.util.*;
31
32
public abstract class JdbTest {
33
public static final int PASSED = 0; // Exit code for passed test
34
public static final int FAILED = 2; // Exit code for failed test
35
public static final int JCK_STATUS_BASE = 95; // Standard JCK-compatible exit code bias
36
37
/* Flag if the test passes */
38
protected boolean success = true;
39
40
/* Flag if debuggee should fail in a test */
41
protected static boolean debuggeeShouldFail = false;
42
43
/* Handler of command line arguments. */
44
protected static JdbArgumentHandler argumentHandler = null;
45
46
/* Log class to print log messages. */
47
protected static Log log = null;
48
49
protected static Jdb jdb = null;
50
protected static Debuggee debuggee = null;
51
protected static Launcher launcher = null;
52
protected static String debuggeeClass = "";
53
protected static String firstBreak = "";
54
protected static String lastBreak = "";
55
protected static String compoundPromptIdent = null;
56
57
/* Constructors */
58
protected JdbTest (boolean debuggeeShouldFail) {
59
this.debuggeeShouldFail = debuggeeShouldFail;
60
}
61
62
protected JdbTest () {
63
this.debuggeeShouldFail = false;
64
}
65
66
abstract protected void runCases();
67
68
protected boolean shouldPass() {
69
return false;
70
}
71
72
protected void failure(String errMessage) {
73
success = false;
74
log.complain(errMessage);
75
}
76
77
protected void display(String message) {
78
log.display(message);
79
}
80
81
protected void launchJdbAndDebuggee(String debuggeeClass) throws Exception {
82
launcher = new Launcher(argumentHandler, log);
83
launcher.launchJdbAndDebuggee(debuggeeClass);
84
jdb = launcher.getJdb();
85
86
if (jdb == null) {
87
throw new Failure("jdb object points to null");
88
}
89
if (debuggeeClass != null) {
90
if (jdb.terminated()) {
91
throw new Failure("jdb exited before testing with code " + jdb.waitFor());
92
}
93
94
if (argumentHandler.isAttachingConnector() || argumentHandler.isListeningConnector()) {
95
debuggee = launcher.getDebuggee();
96
97
if (debuggee.terminated()) {
98
throw new Failure("Debuggee exited before testing");
99
}
100
}
101
}
102
}
103
104
protected void initJdb() {
105
String[] reply;
106
107
jdb.setCompoundPromptIdent(compoundPromptIdent);
108
109
// wait for prompts after connection established
110
if (argumentHandler.isAttachingConnector() || argumentHandler.isListeningConnector()) {
111
// wait for two prompts (after connection established and VM_INIT received)
112
jdb.waitForPrompt(0, false, 2);
113
} else if (argumentHandler.isLaunchingConnector()) {
114
// wait for one prompt (after connection established)
115
jdb.waitForPrompt(0, false);
116
} else {
117
throw new TestBug("Unexpected connector kind: " + argumentHandler.getConnectorType());
118
}
119
120
display("Setting first breakpoint");
121
jdb.setDeferredBreakpointInMethod(firstBreak);
122
123
display("Starting debuggee class");
124
jdb.startDebuggeeClass();
125
}
126
127
protected void afterJdbExit() {
128
}
129
130
protected int runTest(String argv[], PrintStream out) {
131
try {
132
argumentHandler = new JdbArgumentHandler(argv);
133
log = new Log(out, argumentHandler);
134
135
if (shouldPass()) {
136
log.println("TEST PASSED");
137
return PASSED;
138
}
139
140
try {
141
launchJdbAndDebuggee(debuggeeClass);
142
143
try {
144
initJdb();
145
146
/* START OF TEST CASES */
147
display("Test cases starts.");
148
149
runCases();
150
151
display("Test cases ends.");
152
/* END OF TEST CASES */
153
154
} catch (DebuggeeUncaughtException ex) {
155
jdb.quit();
156
throw new TestFailure(ex);
157
} catch (Exception e) {
158
failure("Caught unexpected exception while executing the test: " + e);
159
e.printStackTrace(log.getOutStream());
160
} finally {
161
display("Waiting for jdb exits");
162
int code = jdb.waitFor(argumentHandler.getWaitTime() * 60 * 1000);
163
if (code == PASSED) {
164
display("jdb normally exited");
165
afterJdbExit();
166
} else if (code == LocalProcess.PROCESS_IS_ALIVE) {
167
failure("jdb did not exit after timeout.");
168
if (!jdb.terminated()) {
169
display("Sending quit command to jdb.");
170
jdb.quit();
171
} else {
172
throw new TestBug("code PROCESS_IS_ALIVE is returned for terminated jdb");
173
}
174
} else {
175
failure("jdb abnormally exited with code: " + code);
176
}
177
jdb = null;
178
179
if (debuggee != null
180
&& (argumentHandler.isAttachingConnector()
181
|| argumentHandler.isListeningConnector())) {
182
display("Waiting for debuggee exits");
183
code = debuggee.waitForDebuggee();
184
if (debuggeeShouldFail) {
185
if (code == JCK_STATUS_BASE + PASSED) {
186
failure("Debuggee PASSED with exit code: " + code + " but should fail");
187
} else {
188
display("Debuggee FAILED as expected with exit code: " + code);
189
}
190
} else {
191
if (code == JCK_STATUS_BASE + PASSED) {
192
display("Debuggee PASSED with exit code: " + code);
193
} else {
194
failure("Debuggee FAILED with exit code: " + code);
195
}
196
}
197
// debuggee = null;
198
}
199
}
200
201
} catch (Exception e) {
202
failure("Caught unexpected exception: " + e);
203
e.printStackTrace(out);
204
205
if (jdb != null) {
206
try {
207
jdb.finalize();
208
} catch (Throwable ex) {
209
failure("Caught exception/error while finalization of jdb:\n\t" + ex);
210
ex.printStackTrace(log.getOutStream());
211
}
212
} else {
213
log.complain("jdb reference is null, cannot run jdb.finalize() method");
214
}
215
216
if (debuggee != null) {
217
debuggee.killDebuggee();
218
} else {
219
log.complain("debuggee reference is null, cannot run debuggee.finalize() method");
220
}
221
222
}
223
224
if (!success) {
225
log.complain("TEST FAILED");
226
return FAILED;
227
}
228
229
} catch (Exception e) {
230
out.println("Caught unexpected exception while starting the test: " + e);
231
e.printStackTrace(out);
232
out.println("TEST FAILED");
233
return FAILED;
234
}
235
out.println("TEST PASSED");
236
return PASSED;
237
}
238
}
239
240