Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/LocalVariable/equals/equals001.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.jdi.LocalVariable.equals;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdi.*;
29
30
import com.sun.jdi.*;
31
import java.util.*;
32
import java.io.*;
33
34
/**
35
* The test for the implementation of an object of the type <BR>
36
* LocalVariable. <BR>
37
* <BR>
38
* The test checks up that results of the method <BR>
39
* <code>com.sun.jdi.LocalVariable.equals()</code> <BR>
40
* complies with its spec. <BR>
41
* <BR>
42
* The cases for testing are as follows. <BR>
43
* <BR>
44
* When a gebuggee creates an object containing two <BR>
45
* methods with equal sets of variables and arguments, <BR>
46
* a debugger creates following LocalVariable objects: <BR>
47
* - two for the same variable in the debuggee; <BR>
48
* - for "the same type - different name" variable in <BR>
49
* the same method in the debuggee; <BR>
50
* - for "same name-type - different methods" variable; <BR>
51
* <BR>
52
* and applies the method LocalVariable.equals() <BR>
53
* to pairs of the above Localvariables to <BR>
54
* check up that the method returns the follwing values:<BR>
55
* - true if two LocalVariable mirror the same variable <BR>
56
* or argument in the same method in the debuggee; <BR>
57
* - false otherwise. <BR>
58
* <BR>
59
*/
60
61
public class equals001 {
62
63
//----------------------------------------------------- templete section
64
static final int PASSED = 0;
65
static final int FAILED = 2;
66
static final int PASS_BASE = 95;
67
68
//----------------------------------------------------- templete parameters
69
static final String
70
sHeader1 = "\n==> nsk/jdi/LocalVariable/equals/equals001 ",
71
sHeader2 = "--> equals001: ",
72
sHeader3 = "##> equals001: ";
73
74
//----------------------------------------------------- main method
75
76
public static void main (String argv[]) {
77
int result = run(argv, System.out);
78
System.exit(result + PASS_BASE);
79
}
80
81
public static int run (String argv[], PrintStream out) {
82
return new equals001().runThis(argv, out);
83
}
84
85
//-------------------------------------------------- log procedures
86
87
//private static boolean verbMode = false;
88
89
private static Log logHandler;
90
91
private static void log1(String message) {
92
logHandler.display(sHeader1 + message);
93
}
94
private static void log2(String message) {
95
logHandler.display(sHeader2 + message);
96
}
97
private static void log3(String message) {
98
logHandler.complain(sHeader3 + message);
99
}
100
101
// ************************************************ test parameters
102
103
private String debuggeeName =
104
"nsk.jdi.LocalVariable.equals.equals001a";
105
106
String mName = "nsk.jdi.LocalVariable.equals";
107
108
//====================================================== test program
109
110
static ArgumentHandler argsHandler;
111
static int testExitCode = PASSED;
112
113
//------------------------------------------------------ common section
114
115
private int runThis (String argv[], PrintStream out) {
116
117
Debugee debuggee;
118
119
argsHandler = new ArgumentHandler(argv);
120
logHandler = new Log(out, argsHandler);
121
Binder binder = new Binder(argsHandler, logHandler);
122
123
if (argsHandler.verbose()) {
124
debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp
125
} else {
126
debuggee = binder.bindToDebugee(debuggeeName); // *** tp
127
}
128
129
IOPipe pipe = new IOPipe(debuggee);
130
131
debuggee.redirectStderr(out);
132
log2("equals001a debuggee launched");
133
debuggee.resume();
134
135
String line = pipe.readln();
136
if ((line == null) || !line.equals("ready")) {
137
log3("signal received is not 'ready' but: " + line);
138
return FAILED;
139
} else {
140
log2("'ready' recieved");
141
}
142
143
VirtualMachine vm = debuggee.VM();
144
145
//------------------------------------------------------ testing section
146
log1(" TESTING BEGINS");
147
148
for (int i = 0; ; i++) {
149
pipe.println("newcheck");
150
line = pipe.readln();
151
152
if (line.equals("checkend")) {
153
log2(" : returned string is 'checkend'");
154
break ;
155
} else if (!line.equals("checkready")) {
156
log3("ERROR: returned string is not 'checkready'");
157
testExitCode = FAILED;
158
break ;
159
}
160
161
log1("new check: #" + i);
162
163
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
164
165
List listOfLoadedClasses = vm.classesByName(mName + ".TestClass");
166
167
if (listOfLoadedClasses.size() != 1) {
168
testExitCode = FAILED;
169
log3("ERROR: listOfLoadedClasses.size() != 1 " +
170
listOfLoadedClasses.size());
171
break ;
172
}
173
174
List methods1 =
175
((ReferenceType) listOfLoadedClasses.get(0)).
176
methodsByName("testmethod1");
177
List methods2 =
178
((ReferenceType) listOfLoadedClasses.get(0)).
179
methodsByName("testmethod2");
180
181
Method testMethod1 = (Method) methods1.get(0);
182
Method testMethod2 = (Method) methods2.get(0);
183
184
String names1[] = { "bl1", "bt1", "ch1", "db1",
185
"fl1", "in1", "ln1", "sh1",
186
"class2_1", "iface_1", "cfc_1", "param1" };
187
String names2[] = { "bl2", "bt2", "ch2", "db2",
188
"fl2", "in2", "ln2", "sh2",
189
"class2_2", "iface_2", "cfc_2", "param2" };
190
191
int i2;
192
193
for (i2 = 0; i2 < names1.length; i2++) {
194
195
log2("new check: #" + i2);
196
197
List lVars1 = null;
198
List lVars2 = null;
199
List lVars3 = null;
200
List lVars4 = null;
201
202
try {
203
lVars1 = testMethod1.variablesByName(names1[i2]);
204
lVars2 = testMethod1.variablesByName(names1[i2]);
205
lVars3 = testMethod1.variablesByName(names2[i2]);
206
lVars4 = testMethod2.variablesByName(names1[i2]);
207
} catch ( AbsentInformationException e ) {
208
log3("ERROR: AbsentInformationException for " +
209
"lVars = testMethod_i.variablesByName(names[i2])" );
210
testExitCode = FAILED;
211
continue;
212
}
213
if (lVars1.size() != 1 || lVars2.size() != 1 ||
214
lVars3.size() != 1 || lVars4.size() != 1 ) {
215
testExitCode = FAILED;
216
log3("ERROR: lVars-i.size() != 1 for i2= " + i2);
217
continue;
218
}
219
220
LocalVariable lVar1 = (LocalVariable) lVars1.get(0);
221
LocalVariable lVar2 = (LocalVariable) lVars2.get(0);
222
LocalVariable lVar3 = (LocalVariable) lVars3.get(0);
223
LocalVariable lVar4 = (LocalVariable) lVars4.get(0);
224
225
226
if (!lVar1.equals(lVar2)) {
227
testExitCode = FAILED;
228
log3("ERROR: !lVar1.equals(lvar2) for check# " + i2);
229
}
230
if (lVar1.equals(lVar3)) {
231
testExitCode = FAILED;
232
log3("ERROR: lVar1.equals(lvar3) for check# " + i2);
233
}
234
if (lVar1.equals(lVar4)) {
235
testExitCode = FAILED;
236
log3("ERROR: lVar1.equals(lvar4) for check# " + i2);
237
}
238
}
239
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
240
}
241
log1(" TESTING ENDS");
242
243
//-------------------------------------------------- test summary section
244
//------------------------------------------------- standard end section
245
246
pipe.println("quit");
247
log2("waiting for the debuggee to finish ...");
248
debuggee.waitFor();
249
250
int status = debuggee.getStatus();
251
if (status != PASSED + PASS_BASE) {
252
log3("debuggee returned UNEXPECTED exit status: " +
253
status + " != PASS_BASE");
254
testExitCode = FAILED;
255
} else {
256
log2("debuggee returned expected exit status: " +
257
status + " == PASS_BASE");
258
}
259
260
if (testExitCode != PASSED) {
261
logHandler.complain("TEST FAILED");
262
}
263
return testExitCode;
264
}
265
}
266
267