Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/containers/docker/TestCPUSets.java
40942 views
1
/*
2
* Copyright (c) 2017, 2021, 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
/*
26
* @test
27
* @key cgroups
28
* @summary Test JVM's awareness of cpu sets (cpus and mems)
29
* @requires docker.support
30
* @requires (os.arch != "s390x")
31
* @library /test/lib
32
* @modules java.base/jdk.internal.misc
33
* java.management
34
* jdk.jartool/sun.tools.jar
35
* @build AttemptOOM sun.hotspot.WhiteBox PrintContainerInfo
36
* @run driver jdk.test.lib.helpers.ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox
37
* @run driver TestCPUSets
38
*/
39
import java.util.List;
40
import jdk.test.lib.containers.docker.Common;
41
import jdk.test.lib.containers.docker.DockerRunOptions;
42
import jdk.test.lib.containers.docker.DockerTestUtils;
43
import jdk.test.lib.containers.cgroup.CPUSetsReader;
44
import jdk.test.lib.Asserts;
45
import jdk.test.lib.Platform;
46
import jdk.test.lib.Utils;
47
import jdk.test.lib.process.OutputAnalyzer;
48
import jtreg.SkippedException;
49
50
public class TestCPUSets {
51
private static final String imageName = Common.imageName("cpusets");
52
53
public static void main(String[] args) throws Exception {
54
if (!DockerTestUtils.canTestDocker()) {
55
return;
56
}
57
58
59
Common.prepareWhiteBox();
60
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
61
62
try {
63
// Sanity test the cpu sets reader and parser
64
CPUSetsReader.test();
65
testTheSet("Cpus_allowed_list");
66
testTheSet("Mems_allowed_list");
67
} finally {
68
DockerTestUtils.removeDockerImage(imageName);
69
}
70
}
71
72
73
private static void testTheSet(String setType) throws Exception {
74
String cpuSetStr = CPUSetsReader.readFromProcStatus(setType);
75
76
if (cpuSetStr == null) {
77
String msg = String.format("The %s test is skipped: cpuSetStr is null %n", setType);
78
throw new SkippedException(msg);
79
}
80
81
List<Integer> cpuSet = CPUSetsReader.parseCpuSet(cpuSetStr);
82
int availableProcessors = Runtime.getRuntime().availableProcessors();
83
84
// print diagnostic info
85
printSet(setType, cpuSet);
86
log("getNumCpus(): " + CPUSetsReader.getNumCpus());
87
log("Runtime.getRuntime().availableProcessors(): " + availableProcessors);
88
89
int maxSetSize = Math.min(cpuSet.size(), availableProcessors);
90
log("maxSetSize = " + maxSetSize);
91
92
// Test subset of one, full set, and half of the set
93
testCpuSet(CPUSetsReader.listToString(cpuSet, 1));
94
if (maxSetSize >= 2) {
95
String cpuSetParam = CPUSetsReader.listToString(cpuSet, maxSetSize);
96
log("Testing with cpuSetParam = " + cpuSetParam);
97
testCpuSet(cpuSetParam);
98
}
99
if (maxSetSize >= 4) {
100
String cpuSetParam = CPUSetsReader.listToString(cpuSet, maxSetSize/2);
101
log("Testing with cpuSetParam = " + cpuSetParam);
102
testCpuSet(cpuSetParam);
103
}
104
}
105
106
107
private static void printSet(String setType, List<Integer> set) {
108
System.out.print("printSet(): " + setType + ": ");
109
set.forEach( i -> System.out.print(i + ", "));
110
System.out.println("");
111
}
112
113
114
private static void log(String msg) {
115
System.out.println(msg);
116
}
117
118
119
private static DockerRunOptions commonOpts() {
120
DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java",
121
"PrintContainerInfo");
122
opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/");
123
opts.addJavaOpts("-Xlog:os+container=trace", "-cp", "/test-classes/");
124
Common.addWhiteBoxOpts(opts);
125
return opts;
126
}
127
128
129
private static void checkResult(List<String> lines, String lineMarker, String value) {
130
boolean lineMarkerFound = false;
131
132
for (String line : lines) {
133
if (line.contains(lineMarker)) {
134
lineMarkerFound = true;
135
String[] parts = line.split(":");
136
System.out.println("DEBUG: line = " + line);
137
System.out.println("DEBUG: parts.length = " + parts.length);
138
139
Asserts.assertEquals(parts.length, 2);
140
String set = parts[1].replaceAll("\\s","");
141
String actual = CPUSetsReader.listToString(CPUSetsReader.parseCpuSet(set));
142
Asserts.assertEquals(actual, value);
143
break;
144
}
145
}
146
Asserts.assertTrue(lineMarkerFound);
147
}
148
149
150
private static void testCpuSet(String value) throws Exception {
151
Common.logNewTestCase("cpusets.cpus, value = " + value);
152
153
DockerRunOptions opts = commonOpts();
154
opts.addDockerOpts("--cpuset-cpus=" + value);
155
156
List<String> lines = Common.run(opts).asLines();
157
checkResult(lines, "cpuset.cpus is:", value);
158
}
159
160
private static void testMemSet(String value) throws Exception {
161
Common.logNewTestCase("cpusets.mems, value = " + value);
162
163
DockerRunOptions opts = commonOpts();
164
opts.addDockerOpts("--cpuset-mems=" + value);
165
166
List<String> lines = Common.run(opts).asLines();
167
checkResult(lines, "cpuset.mems is:", value);
168
}
169
170
}
171
172