Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/SetDefaultStratum/setdefstrat001.java
41161 views
1
/*
2
* Copyright (c) 2001, 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.jdwp.VirtualMachine.SetDefaultStratum;
25
26
import java.io.*;
27
28
import nsk.share.*;
29
import nsk.share.jpda.*;
30
import nsk.share.jdwp.*;
31
32
/**
33
* Test for JDWP command: VirtualMachine.SetDefaultStratum.
34
*
35
* See setdefstrat001.README for description of test execution.
36
*
37
* This class represents debugger part of the test.
38
* Test is executed by invoking method runIt().
39
* JDWP command is tested in the method testCommand().
40
*
41
* @see #runIt()
42
* @see #testCommand()
43
*/
44
public class setdefstrat001 {
45
46
// exit status constants
47
static final int JCK_STATUS_BASE = 95;
48
static final int PASSED = 0;
49
static final int FAILED = 2;
50
51
// communication signals constants
52
static final String READY = "ready";
53
static final String QUIT = "quit";
54
55
// package and classes names constants
56
static final String PACKAGE_NAME = "nsk.jdwp.VirtualMachine.SetDefaultStratum";
57
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "setdefstrat001";
58
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
59
60
// VM capability constatnts
61
static final int VM_CAPABILITY_NUMBER = JDWP.Capability.CAN_SET_DEFAULT_STRATUM;
62
static final String VM_CAPABILITY_NAME = "canSetDefaultStratum";
63
64
// tested JDWP command constants
65
static final String JDWP_COMMAND_NAME = "VirtualMachine.SetDefaultStratum";
66
static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.SetDefaultStratum;
67
68
// new value for default startum
69
static final String NEW_DEFAULT_STRATUM = "test";
70
71
// usual scaffold objects
72
ArgumentHandler argumentHandler = null;
73
Log log = null;
74
Binder binder = null;
75
Debugee debugee = null;
76
Transport transport = null;
77
IOPipe pipe = null;
78
79
// test passed or not
80
boolean success = true;
81
82
// -------------------------------------------------------------------
83
84
/**
85
* Start test from command line.
86
*/
87
public static void main (String argv[]) {
88
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
89
}
90
91
/**
92
* Start JCK-compilant test.
93
*/
94
public static int run(String argv[], PrintStream out) {
95
return new setdefstrat001().runIt(argv, out);
96
}
97
98
// -------------------------------------------------------------------
99
100
/**
101
* Perform test execution.
102
*/
103
public int runIt(String argv[], PrintStream out) {
104
105
// make log for debugger messages
106
argumentHandler = new ArgumentHandler(argv);
107
log = new Log(out, argumentHandler);
108
109
// execute test and display results
110
try {
111
log.display("\n>>> Preparing debugee for testing \n");
112
113
// launch debuggee
114
binder = new Binder(argumentHandler, log);
115
log.display("Launching debugee");
116
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
117
transport = debugee.getTransport();
118
pipe = debugee.createIOPipe();
119
120
// make debuggee ready for testing
121
prepareDebugee();
122
123
// work with prepared debuggee
124
try {
125
log.display("\n>>> Checking VM capability \n");
126
127
// check for VM capability
128
log.display("Checking VM capability: " + VM_CAPABILITY_NAME);
129
if (!debugee.getNewCapability(VM_CAPABILITY_NUMBER, VM_CAPABILITY_NAME)) {
130
out.println("TEST PASSED: unsupported VM capability: "
131
+ VM_CAPABILITY_NAME);
132
return PASSED;
133
}
134
135
// perform testing JDWP command
136
log.display("\n>>> Testing JDWP command \n");
137
testCommand();
138
139
} finally {
140
// quit debugee
141
log.display("\n>>> Finishing test \n");
142
quitDebugee();
143
}
144
145
} catch (Failure e) {
146
log.complain("TEST FAILED: " + e.getMessage());
147
success = false;
148
} catch (Exception e) {
149
e.printStackTrace(out);
150
log.complain("Caught unexpected exception while running the test:\n\t" + e);
151
success = false;
152
}
153
154
if (!success) {
155
log.complain("TEST FAILED");
156
return FAILED;
157
}
158
159
out.println("TEST PASSED");
160
return PASSED;
161
162
}
163
164
/**
165
* Prepare debugee for testing and waiting for ready signal.
166
*/
167
void prepareDebugee() {
168
// wait for VM_INIT event from debugee
169
log.display("Waiting for VM_INIT event");
170
debugee.waitForVMInit();
171
172
// query debugee for VM-dependent ID sizes
173
log.display("Querying for IDSizes");
174
debugee.queryForIDSizes();
175
176
// resume initially suspended debugee
177
log.display("Resuming debugee VM");
178
debugee.resume();
179
180
// wait for READY signal from debugee
181
log.display("Waiting for signal from debugee: " + READY);
182
String signal = pipe.readln();
183
log.display("Received signal from debugee: " + signal);
184
if (! signal.equals(READY)) {
185
throw new TestBug("Unexpected signal received from debugee: " + signal
186
+ " (expected: " + READY + ")");
187
}
188
}
189
190
/**
191
* Sending debugee signal to quit and waiting for it exits.
192
*/
193
void quitDebugee() {
194
// send debugee signal to quit
195
log.display("Sending signal to debugee: " + QUIT);
196
pipe.println(QUIT);
197
198
// wait for debugee exits
199
log.display("Waiting for debugee exits");
200
int code = debugee.waitFor();
201
202
// analize debugee exit status code
203
if (code == JCK_STATUS_BASE + PASSED) {
204
log.display("Debugee PASSED with exit code: " + code);
205
} else {
206
log.complain("Debugee FAILED with exit code: " + code);
207
success = false;
208
}
209
}
210
211
/**
212
* Perform testing JDWP command.
213
*/
214
void testCommand() {
215
// create command packet and fill requred out data
216
log.display("Create command packet:");
217
log.display("Command: " + JDWP_COMMAND_NAME);
218
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
219
log.display(" stratumID: " + NEW_DEFAULT_STRATUM);
220
command.addString(NEW_DEFAULT_STRATUM);
221
command.setLength();
222
223
// send command packet to debugee
224
try {
225
log.display("Sending command packet:\n" + command);
226
transport.write(command);
227
} catch (IOException e) {
228
log.complain("Unable to send command packet:\n\t" + e);
229
success = false;
230
return;
231
}
232
233
ReplyPacket reply = new ReplyPacket();
234
235
// receive reply packet from debugee
236
try {
237
log.display("Waiting for reply packet");
238
transport.read(reply);
239
log.display("Reply packet received:\n" + reply);
240
} catch (IOException e) {
241
log.complain("Unable to read reply packet:\n\t" + e);
242
success = false;
243
return;
244
}
245
246
// check reply packet header
247
try{
248
log.display("Checking reply packet header");
249
reply.checkHeader(command.getPacketID());
250
} catch (BoundException e) {
251
log.complain("Bad header of reply packet:\n\t" + e.getMessage());
252
success = false;
253
return;
254
}
255
256
// start parsing reply packet data
257
log.display("Parsing reply packet:");
258
reply.resetPosition();
259
260
// no data in reply packet
261
262
// check for extra data in reply packet
263
if (!reply.isParsed()) {
264
log.complain("Extra trailing bytes found in reply packet at: "
265
+ reply.offsetString());
266
success = false;
267
}
268
}
269
}
270
271