Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine02/VirtualMachine02.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/VirtualMachine02.
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 following methods:
34
* - VirtualMachine.attach(String id) (test tries to attach to the VM running test
35
* and to the another VM started by this test)
36
* - VirtualMachine.attach(VirtualMachineDescriptor vmd) (test tries to attach to the VM running test
37
* and to the another VM started by this test)
38
* - VirtualMachine.detach() (test checks that after detaching operations on VirtualMachine throw IOException)
39
*
40
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
41
* /test/lib
42
* @build nsk.share.aod.DummyTargetApplication
43
* @run main/othervm
44
* -Djdk.attach.allowAttachSelf
45
* -XX:+UsePerfData
46
* nsk.aod.VirtualMachine.VirtualMachine02.VirtualMachine02
47
* -jdk ${test.jdk}
48
* -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
49
* -target nsk.share.aod.DummyTargetApplication
50
*/
51
52
package nsk.aod.VirtualMachine.VirtualMachine02;
53
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
import java.io.IOException;
61
62
/*
63
* Test checks following methods:
64
* - VirtualMachine.attach(String) (test tries to attach to current and to another VM)
65
* - VirtualMachine.attach(VirtualMachineDescriptor) (test tries to attach to current and to another VM)
66
* - VirtualMachine.detach() (test checks that after detaching operations on VirtualMachine
67
* throw IOException)
68
*/
69
public class VirtualMachine02 extends AODTestRunner {
70
71
public VirtualMachine02(String[] args) {
72
super(args);
73
}
74
75
public void doTestActions(String targetVMId) throws Throwable {
76
log.display("Executing test for current VM");
77
String currentVMId = getCurrentVMId();
78
doTest(currentVMId);
79
log.display("");
80
81
log.display("Executing test for another VM (id = " + targetVMId + ")");
82
doTest(targetVMId);
83
}
84
85
void doTest(String targetVMId) throws Throwable {
86
VirtualMachine vm;
87
88
log.display("Trying to attach using VirtualMachine(\"" + targetVMId + "\")");
89
vm = VirtualMachine.attach(targetVMId);
90
log.display("Attached: " + vm);
91
checkDetach(vm);
92
93
log.display("Trying to attach using VirtualMachine(VirtualMachineDescriptor)");
94
AttachProvider provider;
95
TestUtils.assertTrue(AttachProvider.providers().size() > 0, "AttachProvider.providers() returns empty list");
96
provider = AttachProvider.providers().get(0);
97
log.display("Create VirtualMachineDescriptor using provider '" + provider + "'");
98
VirtualMachineDescriptor vmDescriptor = new VirtualMachineDescriptor(provider, targetVMId);
99
vm = VirtualMachine.attach(vmDescriptor);
100
log.display("Attached: " + vm);
101
TestUtils.assertEquals(vm.provider(), provider, "vm.provider() returns unexpected value: " + vm.provider());
102
checkDetach(vm);
103
}
104
105
void checkDetach(VirtualMachine vm) throws Throwable {
106
log.display("Detaching from " + vm);
107
vm.detach();
108
109
try {
110
vm.getSystemProperties();
111
TestUtils.testFailed("Expected IOException wasn't thrown");
112
} catch (IOException e) {
113
// expected exception
114
}
115
try {
116
vm.getAgentProperties();
117
TestUtils.testFailed("Expected IOException wasn't thrown");
118
} catch (IOException e) {
119
// expected exception
120
}
121
try {
122
vm.loadAgent("agent");
123
TestUtils.testFailed("Expected IOException wasn't thrown");
124
} catch (IOException e) {
125
// expected exception
126
}
127
try {
128
vm.loadAgentLibrary("agent");
129
TestUtils.testFailed("Expected IOException wasn't thrown");
130
} catch (IOException e) {
131
// expected exception
132
}
133
try {
134
vm.loadAgentPath("agent");
135
TestUtils.testFailed("Expected IOException wasn't thrown");
136
} catch (IOException e) {
137
// expected exception
138
}
139
140
// shouldn't throw exception
141
log.display("Trying to call detach one more time for " + vm);
142
vm.detach();
143
}
144
145
public static void main(String[] args) {
146
new VirtualMachine02(args).runTest();
147
}
148
}
149
150