Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine01/VirtualMachine01.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/VirtualMachine01.
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
* Test checks that methods of VirtualMachine throws expected exceptions
34
* in following cases:
35
* - VirtualMachine.attach(null) should throw NullPointerException
36
* - VirtualMachine.attach(<invalid vm id>) should throw AttachNotSupportedException
37
* - VirtualMachine.loadAgent(null), VirtualMachine.loadAgentLibrary(null),
38
* VirtualMachine.loadAgentPath(null) should throw NullPointerException
39
*
40
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
41
* /test/lib
42
* @build nsk.share.aod.DummyTargetApplication
43
* @run main/othervm
44
* -XX:+UsePerfData
45
* nsk.aod.VirtualMachine.VirtualMachine01.VirtualMachine01
46
* -jdk ${test.jdk}
47
* -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
48
* -target nsk.share.aod.DummyTargetApplication
49
*/
50
51
package nsk.aod.VirtualMachine.VirtualMachine01;
52
53
import com.sun.tools.attach.AttachNotSupportedException;
54
import com.sun.tools.attach.VirtualMachine;
55
import com.sun.tools.attach.VirtualMachineDescriptor;
56
import com.sun.tools.attach.spi.AttachProvider;
57
import nsk.share.aod.AODTestRunner;
58
import nsk.share.test.TestUtils;
59
60
/*
61
* Test provokes exception which should be thrown by VirtualMachine methods:
62
* - VirtualMachine.attach(null) should throw NullPointerException
63
* - VirtualMachine.attach(<invalid vm id>) should throw AttachNotSupportedException
64
* - VirtualMachine.loadAgent(null), VirtualMachine.loadAgentLibrary(null),
65
* VirtualMachine.loadAgentPath(null) should throw NullPointerException
66
*/
67
public class VirtualMachine01 extends AODTestRunner {
68
69
VirtualMachine01(String[] args) {
70
super(args);
71
}
72
73
public void doTestActions(String targetVMId) throws Throwable {
74
try {
75
log.display("VirtualMachine.attach((String)null)");
76
VirtualMachine.attach((String) null);
77
TestUtils.testFailed("NullPointerException wasn't thrown");
78
} catch (NullPointerException e) {
79
log.display("Expected exception: " + e);
80
}
81
82
try {
83
log.display("VirtualMachine.attach((VirtualMachineDescriptor)null)");
84
VirtualMachine.attach((VirtualMachineDescriptor) null);
85
TestUtils.testFailed("NullPointerException wasn't thrown");
86
} catch (NullPointerException e) {
87
log.display("Expected exception: " + e);
88
}
89
90
final String invalidVMId = "InvalidID";
91
92
try {
93
log.display("VirtualMachine.attach(" + invalidVMId + ")");
94
VirtualMachine.attach(invalidVMId);
95
TestUtils.testFailed("AttachNotSupportedException wasn't thrown");
96
} catch (AttachNotSupportedException e) {
97
log.display("Expected exception: " + e);
98
}
99
100
try {
101
TestUtils.assertTrue(AttachProvider.providers().size() > 0, "AttachProvider.providers() returns empty list");
102
log.display("Create VirtualMachineDescriptor using provider '" + AttachProvider.providers().get(0) + "'");
103
VirtualMachineDescriptor vmd = new VirtualMachineDescriptor(AttachProvider.providers().get(0), invalidVMId);
104
log.display("VirtualMachine.attach(new VirtualMachineDescriptor(provider, " + invalidVMId + "))");
105
VirtualMachine.attach(vmd);
106
TestUtils.testFailed("AttachNotSupportedException wasn't thrown");
107
} catch (AttachNotSupportedException e) {
108
log.display("Expected exception: " + e);
109
}
110
111
// create VirtualMachine object VM to check non-static methods
112
113
VirtualMachine vm = VirtualMachine.attach(targetVMId);
114
try {
115
try {
116
log.display("VirtualMachine.loadAgent(null)");
117
vm.loadAgent(null);
118
TestUtils.testFailed("NullPointerException wasn't thrown");
119
} catch (NullPointerException e) {
120
log.display("Expected exception: " + e);
121
}
122
123
try {
124
log.display("VirtualMachine.loadAgent(null, null)");
125
vm.loadAgent(null, null);
126
TestUtils.testFailed("NullPointerException wasn't thrown");
127
} catch (NullPointerException e) {
128
log.display("Expected exception: " + e);
129
}
130
131
try {
132
log.display("VirtualMachine.loadAgentLibrary(null)");
133
vm.loadAgentLibrary(null);
134
TestUtils.testFailed("NullPointerException wasn't thrown");
135
} catch (NullPointerException e) {
136
log.display("Expected exception: " + e);
137
}
138
139
try {
140
log.display("VirtualMachine.loadAgentLibrary(null, null)");
141
vm.loadAgentLibrary(null, null);
142
TestUtils.testFailed("NullPointerException wasn't thrown");
143
} catch (NullPointerException e) {
144
log.display("Expected exception: " + e);
145
}
146
147
try {
148
log.display("VirtualMachine.loadAgentPath(null)");
149
vm.loadAgentPath(null);
150
TestUtils.testFailed("NullPointerException wasn't thrown");
151
} catch (NullPointerException e) {
152
log.display("Expected exception: " + e);
153
}
154
155
try {
156
log.display("VirtualMachine.loadAgentPath(null, null)");
157
vm.loadAgentPath(null, null);
158
TestUtils.testFailed("NullPointerException wasn't thrown");
159
} catch (NullPointerException e) {
160
log.display("Expected exception: " + e);
161
}
162
163
} finally {
164
vm.detach();
165
}
166
}
167
168
public static void main(String[] args) {
169
new VirtualMachine01(args).runTest();
170
}
171
172
}
173
174