Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Exit/exit001.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.Exit;
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 exit001 {
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.Exit";
38
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "exit001";
39
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
40
41
static final String JDWP_COMMAND_NAME = "VirtualMachine.Exit";
42
static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.Exit;
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 exit001().runIt(argv, out);
50
}
51
52
public int runIt(String argv[], PrintStream out) {
53
54
boolean success = true;
55
56
try {
57
final ArgumentHandler argumentHandler = new ArgumentHandler(argv);
58
final Log log = new Log(out, argumentHandler);
59
60
try {
61
62
Binder binder = new Binder(argumentHandler, log);
63
log.display("Start debugee VM");
64
final 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
82
// Linux returns only 8 least significant bits of exit status - see #4459019 bug.
83
int expectedExitCode = 0x0F;
84
85
// begin test of JDWP command
86
87
try {
88
log.display("Creating command packet for " + JDWP_COMMAND_NAME
89
+ " with exit code: " + expectedExitCode);
90
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
91
command.addInt(expectedExitCode);
92
command.setLength();
93
94
log.display("Sending command packet:\n" + command);
95
transport.write(command);
96
97
log.display("Waiting for reply packet");
98
ReplyPacket reply = new ReplyPacket();
99
transport.read(reply);
100
log.display("Reply packet received:\n" + reply);
101
102
log.display("Checking reply packet header");
103
reply.checkHeader(command.getPacketID());
104
105
log.display("Parsing reply packet:");
106
reply.resetPosition();
107
108
if (! reply.isParsed()) {
109
log.complain("Extra bytes in reply packet at: " + reply.currentPosition());
110
success = false;
111
}
112
} catch (Exception e) {
113
log.complain("Exception catched: " + e);
114
success = false;
115
}
116
117
// check if debugee has been actually terminated
118
119
if (success) {
120
int waittime = argumentHandler.getWaitTime() * 60; // seconds
121
int pause = 1; // seconds
122
int tries = waittime / pause;
123
success = false;
124
125
for (int i = 0; i < tries; i++) {
126
if (debugee.terminated()) {
127
log.display("Debugee has been terminated successfully");
128
success = true;
129
break;
130
}
131
try {
132
Thread.currentThread().sleep(pause * 1000);
133
} catch (InterruptedException e) {
134
log.complain("Interrupted exception catched: " + e);
135
}
136
}
137
if (! success) {
138
log.complain("Debugee has not been terminated by request");
139
}
140
}
141
142
// check if debugee exit code is as expected
143
144
if (success) {
145
int exitCode = debugee.getStatus();
146
log.display("Debugee exit code is: " + exitCode);
147
if (exitCode != expectedExitCode) {
148
log.complain("Debugee exit code is not equal to expected: " + expectedExitCode);
149
success = false;
150
}
151
}
152
153
// end test of JDWP command
154
155
} catch (Exception e) {
156
log.complain("Unexpected exception: " + e);
157
e.printStackTrace(out);
158
success = false;
159
}
160
161
if (!success) {
162
log.complain("TEST FAILED");
163
return FAILED;
164
}
165
166
} catch (Exception e) {
167
out.println("Unexpected exception: " + e);
168
e.printStackTrace(out);
169
out.println("TEST FAILED");
170
return FAILED;
171
}
172
173
out.println("TEST PASSED");
174
return PASSED;
175
176
}
177
178
}
179
180