Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/VirtualMachine07.java
41160 views
1
/*
2
* Copyright (c) 2008, 2020, 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
/*
25
* @test
26
*
27
* @summary converted from VM Testbase nsk/aod/VirtualMachine/VirtualMachine07.
28
* VM Testbase keywords: [feature_282, jdk]
29
* VM Testbase readme:
30
* Description :
31
* Test checks work of Attach API (com.sun.tools.attach).
32
* Test is based on the nsk.share.aod framework.
33
* This test checks methods VirtualMachine.loadAgentLibrary(String agent) and
34
* VirtualMachine.loadAgentLibrary(String agent, String options).
35
* Test checks following cases:
36
* - it is possible to pass options to agent using loadAgentLibrary(String agent, String options)
37
* - it is possible to specify null options (in this case zero-length is passed to the Agent_OnAttach)
38
* - if Agent_OnAttach returns error code loadAgentLibrary throws AgentInitializationException and
39
* AgentInitializationException.returnValue() returns this error code
40
*
41
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
42
* /test/lib
43
* @build nsk.share.aod.TargetApplicationWaitingAgents
44
* @run main/othervm/native
45
* -XX:+UsePerfData
46
* nsk.aod.VirtualMachine.VirtualMachine07.VirtualMachine07
47
* -jdk ${test.jdk}
48
* -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
49
* -target nsk.share.aod.TargetApplicationWaitingAgents
50
* -na VirtualMachine07agent00,VirtualMachine07agent01,VirtualMachine07agent02,VirtualMachine07agent03
51
* -testedMethod loadAgentLibrary
52
*/
53
54
package nsk.aod.VirtualMachine.VirtualMachine07;
55
56
import com.sun.tools.attach.AgentInitializationException;
57
import com.sun.tools.attach.VirtualMachine;
58
import nsk.share.TestBug;
59
import nsk.share.aod.AODRunnerArgParser;
60
import nsk.share.aod.AODTestRunner;
61
import nsk.share.aod.AgentInformation;
62
import nsk.share.test.TestUtils;
63
64
import java.util.List;
65
66
/*
67
* Test is written to test following methods:
68
* - VirtualMachine.loadAgentLibrary
69
* - VirtualMachine.loadAgentPath
70
*
71
*(method to test is specified via command line parameter 'testedMethod')
72
*/
73
public class VirtualMachine07 extends AODTestRunner {
74
private static class ArgParser extends AODRunnerArgParser {
75
private static final String TESTED_METHOD_OPT = "testedMethod";
76
77
ArgParser(String[] args) {
78
super(args);
79
}
80
81
protected boolean checkOption(String option, String value) {
82
if (super.checkOption(option, value))
83
return true;
84
85
if (option.equals(TESTED_METHOD_OPT)) {
86
if ("loadAgentLibrary".equals(value) || "loadAgentPath".equals(value)) {
87
return true;
88
} else {
89
throw new TestBug("Unexpected value of '" + TESTED_METHOD_OPT + "': " + value);
90
}
91
}
92
93
return false;
94
}
95
96
protected void checkOptions() {
97
super.checkOptions();
98
99
// if test loadAgentPath parameter arch is needed
100
if (!testLoadAgentLibrary()) {
101
if (!options.containsKey("arch")) {
102
throw new TestBug("Option 'arch' wasn't specified");
103
}
104
}
105
}
106
107
boolean testLoadAgentLibrary() {
108
return options.getProperty(TESTED_METHOD_OPT).equals("loadAgentLibrary");
109
}
110
}
111
112
public VirtualMachine07(String[] args) {
113
super(args);
114
}
115
116
/*
117
* When test method loadAgentPath platform specific agent name should be
118
* created (lib<agent>.so for unix, lib<agent>.dylib for macosx and
119
* <agent>.dll for windows)
120
*/
121
protected String expandAgentPath(String path) {
122
int index = path.lastIndexOf('/');
123
if (index < 0)
124
throw new TestBug("Unexpected agent library name format");
125
126
String dir = path.substring(0, index);
127
String libName = path.substring(index + 1);
128
129
if (argParser.getArch().startsWith("windows")) {
130
return dir + "/" + libName + ".dll";
131
} else if (argParser.getArch().startsWith("mac")) {
132
return dir + "/" + "lib" + libName + ".dylib";
133
} else {
134
return dir + "/" + "lib" + libName + ".so";
135
}
136
}
137
138
protected AODRunnerArgParser createArgParser(String[] args) {
139
return new ArgParser(args);
140
}
141
142
protected void loadAgent(VirtualMachine vm, String agent) throws Throwable {
143
boolean testLoadAgentLibrary = ((ArgParser) argParser).testLoadAgentLibrary();
144
145
if (testLoadAgentLibrary) {
146
log.display("Test method VirtualMachine.loadAgentLibrary");
147
} else {
148
log.display("Test method VirtualMachine.loadAgentPath");
149
}
150
151
if (testLoadAgentLibrary) {
152
log.display("Loading '" + agent + "'");
153
vm.loadAgentLibrary(agent);
154
} else {
155
String expandedName = (agent == null ? null : expandAgentPath(agent));
156
log.display("Loading '" + expandedName + "'");
157
vm.loadAgentPath(expandedName);
158
}
159
}
160
161
protected void loadAgent(VirtualMachine vm, String agent, String options) throws Throwable {
162
boolean testLoadAgentLibrary = ((ArgParser) argParser).testLoadAgentLibrary();
163
164
if (testLoadAgentLibrary) {
165
log.display("Test method VirtualMachine.loadAgentLibrary");
166
} else {
167
log.display("Test method VirtualMachine.loadAgentPath");
168
}
169
170
if (testLoadAgentLibrary) {
171
log.display("Loading '" + agent + "'");
172
vm.loadAgentLibrary(agent, options);
173
} else {
174
String expandedName = (agent == null ? null : expandAgentPath(agent));
175
log.display("Loading '" + expandedName + "'");
176
vm.loadAgentPath(expandedName, options);
177
}
178
}
179
180
public void doTestActions(String targetVMId) throws Throwable {
181
// check that all required parameters were passed to the test
182
List<AgentInformation> agents = argParser.getAgents();
183
if (agents.size() != 4) {
184
throw new TestBug("Test requires 4 agents, actually " + agents.size() + " were specified");
185
}
186
for (AgentInformation agent : agents) {
187
if (agent.jarAgent) {
188
throw new TestBug("Non native agent was specified");
189
}
190
}
191
192
VirtualMachine vm = VirtualMachine.attach(targetVMId);
193
194
try {
195
AgentInformation agent;
196
197
agent = agents.get(0);
198
loadAgent(vm, agent.pathToAgent);
199
200
agent = agents.get(1);
201
loadAgent(vm, agent.pathToAgent, null);
202
203
agent = agents.get(2);
204
loadAgent(vm, agent.pathToAgent, "VirtualMachine_TestOptions");
205
206
agent = agents.get(3);
207
log.display("Loading '" + agent.pathToAgent + "' (this agent fails to initialize)");
208
try {
209
loadAgent(vm, agent.pathToAgent);
210
211
TestUtils.testFailed("Expected AgentInitializationException wasn't thrown");
212
} catch (AgentInitializationException e) {
213
log.display("Expected AgentInitializationException was caught");
214
log.display("AgentInitializationException.returnValue(): " + e.returnValue());
215
TestUtils.assertEquals(e.returnValue(), 10,
216
"AgentInitializationException.returnValue() returns unexpected value: " + e.returnValue() + ", expected value is 10");
217
}
218
} finally {
219
vm.detach();
220
}
221
}
222
223
public static void main(String[] args) {
224
new VirtualMachine07(args).runTest();
225
}
226
}
227
228