Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Version/version002.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.Version;
25
26
import java.io.*;
27
import java.util.*;
28
29
import nsk.share.*;
30
import nsk.share.jpda.*;
31
import nsk.share.jdwp.*;
32
33
public class version002 {
34
static final int JCK_STATUS_BASE = 95;
35
static final int PASSED = 0;
36
static final int FAILED = 2;
37
static final String PACKAGE_NAME = "nsk.jdwp.VirtualMachine.Version";
38
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "version002";
39
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
40
41
static final String JDWP_COMMAND_NAME = "VirtualMachine.Version";
42
static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.Version;
43
44
public static void main (String argv[]) {
45
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
46
}
47
48
public static int run(String argv[], PrintStream out) {
49
return new version002().runIt(argv, out);
50
}
51
52
public int runIt(String argv[], PrintStream out) {
53
54
boolean success = true;
55
56
try {
57
ArgumentHandler argumentHandler = new ArgumentHandler(argv);
58
Log log = new Log(out, argumentHandler);
59
60
try {
61
62
Binder binder = new Binder(argumentHandler, log);
63
log.display("Start debugee VM");
64
Debugee debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
65
Transport transport = debugee.getTransport();
66
IOPipe pipe = debugee.createIOPipe();
67
68
log.display("Waiting for VM_INIT event");
69
debugee.waitForVMInit();
70
71
log.display("Querying for IDSizes");
72
debugee.queryForIDSizes();
73
74
log.display("Resume debugee VM");
75
debugee.resume();
76
77
log.display("Waiting for command: " + "ready");
78
String cmd = pipe.readln();
79
log.display("Received command: " + cmd);
80
81
// begin test of JDWP command
82
83
try {
84
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
85
// A properly formed CommandPacket has JDWP.Flag.NONE
86
// for the 'flags' field. Set the 'flags' field to '!'
87
// simulate a bad value in the printable ASCII range.
88
// '!' == 0x21 which means the bad value also does not
89
// have the JDWP.Flag.REPLY_PACKET (0x80) set.
90
command.setFlags((byte) '!');
91
92
log.display("Sending command packet:\n" + command);
93
transport.write(command);
94
95
log.display("Waiting for reply packet");
96
ReplyPacket reply = new ReplyPacket();
97
transport.read(reply);
98
99
if (true) {
100
// In this test (compared to version001), we
101
// should never reach here because the debuggee
102
// should have thrown an IOException and printed
103
// this error message:
104
// ERROR: Received jdwpPacket with flags != 0x0 (actual=0x21) when a jdwpCmdPacket was expected.
105
106
throw new Failure("Debuggee did not detect bad flags field.");
107
}
108
// The code below this point of the try-catch block is
109
// not reachable and could be deleted. It is left in
110
// place to ease porting of this test to earlier releases.
111
112
log.display("Reply packet received:\n" + reply);
113
114
log.display("Checking reply packet header");
115
reply.checkHeader(command.getPacketID());
116
117
log.display("Parsing reply packet:");
118
reply.resetPosition();
119
120
String description = reply.getString();
121
log.display(" description: " + description);
122
123
int jdwpMajor = reply.getInt();
124
log.display(" jdwpMajor: " + jdwpMajor);
125
126
int jdwpMinor = reply.getInt();
127
log.display(" jdwpMinor: " + jdwpMinor);
128
129
String vmVersion = reply.getString();
130
log.display(" vmVersion: " + vmVersion);
131
132
String vmName = reply.getString();
133
log.display(" vmName: " + vmName);
134
135
if (! reply.isParsed()) {
136
log.complain("Extra bytes in reply packet at: " + reply.currentPosition());
137
success = false;
138
}
139
140
} catch (IOException ie) {
141
// version001 expects to pass.
142
// This test expects to fail due to an IOException.
143
log.display("Expected IOException caught: " + ie);
144
success = true;
145
} catch (Exception e) {
146
log.complain("Exception catched: " + e);
147
success = false;
148
}
149
150
// end test of JDWP command
151
152
log.display("Sending command: " + "quit");
153
pipe.println("quit");
154
155
log.display("Waiting for debugee exits");
156
int code = debugee.waitFor();
157
if (code == JCK_STATUS_BASE + PASSED) {
158
log.display("Debugee PASSED: " + code);
159
} else {
160
log.complain("Debugee FAILED: " + code);
161
success = false;
162
}
163
164
} catch (Exception e) {
165
log.complain("Unexpected exception: " + e);
166
e.printStackTrace(out);
167
success = false;
168
}
169
170
if (!success) {
171
log.complain("TEST FAILED");
172
return FAILED;
173
}
174
175
} catch (Exception e) {
176
out.println("Unexpected exception: " + e);
177
e.printStackTrace(out);
178
out.println("TEST FAILED");
179
return FAILED;
180
}
181
182
out.println("TEST PASSED");
183
return PASSED;
184
185
}
186
187
}
188
189