Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine04/VirtualMachine04.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/VirtualMachine04.
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.getSystemProperties() (test checks that returned properties contains
35
* expected property and tested method returns properties whose key and value is a String)
36
* - VirtualMachine.getAgentProperties() (test checks that method returns properties whose
37
* key and value is a String)
38
*
39
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
40
* /test/lib
41
* @build nsk.aod.VirtualMachine.VirtualMachine04.VM04Target
42
* @run main/othervm
43
* -XX:+UsePerfData
44
* nsk.aod.VirtualMachine.VirtualMachine04.VirtualMachine04
45
* -jdk ${test.jdk}
46
* -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
47
* -target nsk.aod.VirtualMachine.VirtualMachine04.VM04Target
48
*/
49
50
package nsk.aod.VirtualMachine.VirtualMachine04;
51
52
import com.sun.tools.attach.VirtualMachine;
53
import nsk.share.TestBug;
54
import nsk.share.aod.AODTestRunner;
55
import nsk.share.test.TestUtils;
56
57
import java.util.Properties;
58
59
/*
60
* Test checks following methods:
61
* - VirtualMachine.getSystemProperties()
62
* - VirtualMachine.getAgentProperties()
63
*/
64
public class VirtualMachine04 extends AODTestRunner {
65
static final String SIGNAL_CHANGE_PROPERTY = "change_property";
66
static final String SIGNAL_PROPERTY_CHANGED = "property_changed";
67
68
public VirtualMachine04(String[] args) {
69
super(args);
70
}
71
72
public void doTestActions(String targetVMId) throws Throwable {
73
VirtualMachine vm = VirtualMachine.attach(targetVMId);
74
75
try {
76
checkSystemProperties(vm, VM04Target.TEST_PROPERTY_KEY, VM04Target.TEST_PROPERTY_VALUE);
77
78
log.display("Sending signal " + SIGNAL_CHANGE_PROPERTY);
79
pipe.println(SIGNAL_CHANGE_PROPERTY);
80
String signal = pipe.readln();
81
log.display("Received signal " + signal);
82
if (!signal.equals(SIGNAL_PROPERTY_CHANGED)) {
83
throw new TestBug("Unexpected signal received: " + signal);
84
}
85
checkSystemProperties(vm, VM04Target.TEST_PROPERTY_KEY, VM04Target.CHANGED_TEST_PROPERTY_VALUE);
86
87
Properties properties = vm.getAgentProperties();
88
System.out.println("VirtualMachine.getAgentProperties(): " + properties);
89
checkProperties(properties);
90
} finally {
91
vm.detach();
92
}
93
}
94
95
void checkSystemProperties(VirtualMachine vm,
96
String propertyToCheck,
97
String expectedPropertyValue) throws Throwable {
98
99
Properties properties = vm.getSystemProperties();
100
System.out.println("VirtualMachine.getSystemProperties(): " + properties);
101
checkProperties(properties);
102
103
String checkedPropertyValue = properties.getProperty(propertyToCheck);
104
TestUtils.assertNotNull(checkedPropertyValue, "Properties doesn't contain property '" + propertyToCheck + "'");
105
TestUtils.assertEquals(checkedPropertyValue, expectedPropertyValue,
106
"Unexpected value of the property '" + propertyToCheck + "': " + checkedPropertyValue + ", expected value is '" + expectedPropertyValue + "'");
107
}
108
109
/*
110
* Check following spec clause: VirtualMachine.getSystemProperties() and
111
* VirtualMachine.getAgentProperties() return the properties whose key and value is a String
112
*/
113
void checkProperties(Properties properties) {
114
TestUtils.assertNotNull(properties, "Method returns null Properties");
115
116
for (Object key : properties.keySet()) {
117
Object value = properties.get(key);
118
log.display("Value of '" + key + "' = " + value);
119
120
TestUtils.assertTrue(key instanceof String, "Property key isn't String: " + key.getClass().getName());
121
TestUtils.assertTrue(value instanceof String, "Property value isn't String: " + value.getClass().getName());
122
}
123
}
124
125
public static void main(String[] args) {
126
new VirtualMachine04(args).runTest();
127
}
128
}
129
130