Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/aod/AttachProvider/AttachProvider02/AttachProvider02.java
41161 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/AttachProvider/AttachProvider02.
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 tries to attach to the VM started by this test using 2 methods:
34
* - AttachProvider.attachVirtualMachine(String id)
35
* - AttachProvider.attachVirtualMachine(VirtualMachineDescriptor vmd)
36
* After attaching test tries to use created VirtualMachine object (tries to call VirtualMachine.getSystemProperties()).
37
*
38
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
39
* /test/lib
40
* @build nsk.share.aod.DummyTargetApplication
41
* @run main/othervm
42
* -Djdk.attach.allowAttachSelf
43
* -XX:+UsePerfData
44
* nsk.aod.AttachProvider.AttachProvider02.AttachProvider02
45
* -jdk ${test.jdk}
46
* -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
47
* -target nsk.share.aod.DummyTargetApplication
48
*/
49
50
package nsk.aod.AttachProvider.AttachProvider02;
51
52
import com.sun.tools.attach.VirtualMachine;
53
import com.sun.tools.attach.VirtualMachineDescriptor;
54
import com.sun.tools.attach.spi.AttachProvider;
55
import nsk.share.aod.AODTestRunner;
56
import nsk.share.test.TestUtils;
57
58
import java.util.Properties;
59
60
/*
61
* Test checks following methods:
62
* - AttachProvider.attachVirtualMachine(String id)
63
* - AttachProvider.attachVirtualMachine(VirtualMachineDescriptor vmd)
64
*/
65
public class AttachProvider02 extends AODTestRunner {
66
67
public AttachProvider02(String[] args) {
68
super(args);
69
}
70
71
public void doTestActions(String targetVMId) throws Throwable {
72
TestUtils.assertTrue(AttachProvider.providers().size() > 0, "Method AttachProvider.providers() returns empty collection");
73
74
String currentVMId = getCurrentVMId();
75
76
for (AttachProvider provider : AttachProvider.providers()) {
77
log.display("Provider: " + provider);
78
log.display("Provider.name(): " + provider.name());
79
log.display("Provider.type(): " + provider.type());
80
81
TestUtils.assertNotNull(provider.name(), "Provider.name() returns null");
82
TestUtils.assertNotNull(provider.type(), "Provider.type() returns null");
83
84
tryAttach(provider, currentVMId, false);
85
tryAttach(provider, currentVMId, true);
86
87
tryAttach(provider, targetVMId, false);
88
tryAttach(provider, targetVMId, true);
89
}
90
}
91
92
void tryAttach(AttachProvider provider, String vmId, boolean useVMDescriptor) throws Throwable {
93
log.display("Attaching to vm " + vmId + " using " +
94
(useVMDescriptor ? "VirtualMachineDescriptor " : "VM id"));
95
96
VirtualMachine vm;
97
98
if (useVMDescriptor) {
99
vm = provider.attachVirtualMachine(new VirtualMachineDescriptor(provider, vmId));
100
} else {
101
vm = provider.attachVirtualMachine(vmId);
102
}
103
104
try {
105
log.display("Attached to vm: " + vm);
106
TestUtils.assertEquals(vm.id(), vmId, "VirtualMachine.id() returns unexpected value for attached vm: " + vm.id());
107
108
// try to use created VirtualMachine
109
log.display("Trying to call VirtualMachine.getSystemProperties()");
110
Properties properties = vm.getSystemProperties();
111
TestUtils.assertNotNull(properties, "VirtualMachine.getSystemProperties() returns null");
112
113
TestUtils.assertTrue(properties.size() > 0, "VirtualMachine.getSystemProperties() returns empty collection");
114
} finally {
115
vm.detach();
116
}
117
}
118
119
public static void main(String[] args) {
120
new AttachProvider02(args).runTest();
121
}
122
}
123
124