Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/containers/cgroup/CgroupSubsystemFactory.java
66644 views
1
/*
2
* Copyright (c) 2020, 2022, Red Hat Inc.
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 CgroupSubsystemFactory
26
* @bug 8287107
27
* @key cgroups
28
* @requires os.family == "linux"
29
* @library /testlibrary /test/lib
30
* @build sun.hotspot.WhiteBox
31
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
32
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI CgroupSubsystemFactory
33
*/
34
35
import java.io.IOException;
36
import java.nio.charset.StandardCharsets;
37
import java.nio.file.Files;
38
import java.nio.file.Path;
39
import java.nio.file.Paths;
40
41
import jdk.test.lib.Asserts;
42
import jdk.test.lib.Utils;
43
import jdk.test.lib.util.FileUtils;
44
import sun.hotspot.WhiteBox;
45
46
/*
47
* Verify hotspot's detection heuristics of CgroupSubsystemFactory::create()
48
*/
49
public class CgroupSubsystemFactory {
50
51
// Mirrored from src/hotspot/os/linux/cgroupSubsystem_linux.hpp
52
private static final int CGROUPS_V1 = 1;
53
private static final int CGROUPS_V2 = 2;
54
private static final int INVALID_CGROUPS_V2 = 3;
55
private static final int INVALID_CGROUPS_V1 = 4;
56
private static final int INVALID_CGROUPS_NO_MOUNT = 5;
57
private Path existingDirectory;
58
private Path cgroupv1CgroupsJoinControllers;
59
private Path cgroupv1SelfCgroupsJoinControllers;
60
private Path cgroupv1MountInfoJoinControllers;
61
private Path cgroupv1CgInfoZeroHierarchy;
62
private Path cgroupv1MntInfoZeroHierarchy;
63
private Path cgroupv2CgInfoZeroHierarchy;
64
private Path cgroupv2MntInfoZeroHierarchy;
65
private Path cgroupv1CgInfoNonZeroHierarchy;
66
private Path cgroupv1MntInfoNonZeroHierarchyOtherOrder;
67
private Path cgroupv1MntInfoNonZeroHierarchy;
68
private Path cgroupv1MntInfoDoubleCpuset;
69
private Path cgroupv1MntInfoDoubleCpuset2;
70
private Path cgroupv1MntInfoSystemdOnly;
71
private String mntInfoEmpty = "";
72
private Path cgroupV1SelfCgroup;
73
private Path cgroupV2SelfCgroup;
74
private Path cgroupV2MntInfoMissingCgroupv2;
75
private Path cgroupv1MntInfoMissingMemoryController;
76
private Path cgroupv2CgInfoNoZeroHierarchyOnlyFreezer;
77
private Path cgroupv2MntInfoNoZeroHierarchyOnlyFreezer;
78
private Path cgroupv2SelfNoZeroHierarchyOnlyFreezer;
79
private String procSelfCgroupHybridContent = "11:hugetlb:/\n" +
80
"10:devices:/user.slice\n" +
81
"9:pids:/user.slice/user-15263.slice/[email protected]\n" +
82
"8:cpu,cpuacct:/\n" +
83
"7:perf_event:/\n" +
84
"6:freezer:/\n" +
85
"5:blkio:/\n" +
86
"4:net_cls,net_prio:/\n" +
87
"3:cpuset:/\n" +
88
"2:memory:/user.slice/user-15263.slice/[email protected]\n" +
89
"1:name=systemd:/user.slice/user-15263.slice/[email protected]/gnome-terminal-server.service\n" +
90
"0::/user.slice/user-15263.slice/[email protected]/gnome-terminal-server.service";
91
private String procSelfCgroupV2UnifiedContent = "0::/user.slice/user-1000.slice/session-3.scope";
92
private String procSelfCgroupV1JoinControllers =
93
"9:freezer:/\n" +
94
"8:rdma:/\n" +
95
"7:blkio:/user.slice\n" +
96
"6:devices:/user.slice\n" +
97
"5:pids:/user.slice/user-1000.slice/session-2.scope\n" +
98
"4:cpu,cpuacct,memory,net_cls,net_prio,hugetlb:/user.slice/user-1000.slice/session-2.scope\n" +
99
"3:cpuset:/\n" +
100
"2:perf_event:/\n" +
101
"1:name=systemd:/user.slice/user-1000.slice/session-2.scope\n" +
102
"0::/user.slice/user-1000.slice/session-2.scope\n";
103
private String cgroupsZeroHierarchy =
104
"#subsys_name hierarchy num_cgroups enabled\n" +
105
"cpuset 0 1 1\n" +
106
"cpu 0 1 1\n" +
107
"cpuacct 0 1 1\n" +
108
"memory 0 1 1\n" +
109
"devices 0 1 1\n" +
110
"freezer 0 1 1\n" +
111
"net_cls 0 1 1\n" +
112
"pids 0 1 1\n" +
113
"blkio 0 1 1\n" +
114
"perf_event 0 1 1 ";
115
private String cgroupsNonZeroJoinControllers =
116
"#subsys_name hierarchy num_cgroups enabled\n" +
117
"cpuset\t3\t1\t1\n" +
118
"cpu\t4\t153\t1\n" +
119
"cpuacct\t4\t153\t1\n" +
120
"blkio\t7\t87\t1\n" +
121
"memory\t4\t153\t1\n" +
122
"devices\t6\t87\t1\n" +
123
"freezer\t9\t1\t1\n" +
124
"net_cls\t4\t153\t1\n" +
125
"perf_event\t2\t1\t1\n" +
126
"net_prio\t4\t153\t1\n" +
127
"hugetlb\t4\t153\t1\n" +
128
"pids\t5\t95\t1\n" +
129
"rdma\t8\t1\t1\n";
130
private String cgroupV2LineHybrid = "31 30 0:27 / /sys/fs/cgroup/unified rw,nosuid,nodev,noexec,relatime shared:5 - cgroup2 none rw,seclabel,nsdelegate\n";
131
private String cgroupv1MountInfoLineMemory = "35 30 0:31 / /sys/fs/cgroup/memory rw,nosuid,nodev,noexec,relatime shared:7 - cgroup none rw,seclabel,memory\n";
132
private String mntInfoHybridStub =
133
"30 23 0:26 / /sys/fs/cgroup ro,nosuid,nodev,noexec shared:4 - tmpfs tmpfs ro,seclabel,mode=755\n" +
134
"32 30 0:28 / /sys/fs/cgroup/systemd rw,nosuid,nodev,noexec,relatime shared:6 - cgroup none rw,seclabel,xattr,name=systemd\n" +
135
"36 30 0:32 / /sys/fs/cgroup/pids rw,nosuid,nodev,noexec,relatime shared:8 - cgroup none rw,seclabel,pids\n" +
136
"37 30 0:33 / /sys/fs/cgroup/perf_event rw,nosuid,nodev,noexec,relatime shared:9 - cgroup none rw,seclabel,perf_event\n" +
137
"38 30 0:34 / /sys/fs/cgroup/net_cls,net_prio rw,nosuid,nodev,noexec,relatime shared:10 - cgroup none rw,seclabel,net_cls,net_prio\n" +
138
"39 30 0:35 / /sys/fs/cgroup/hugetlb rw,nosuid,nodev,noexec,relatime shared:11 - cgroup none rw,seclabel,hugetlb\n" +
139
"40 30 0:36 / /sys/fs/cgroup/cpu,cpuacct rw,nosuid,nodev,noexec,relatime shared:12 - cgroup none rw,seclabel,cpu,cpuacct\n" +
140
"41 30 0:37 / /sys/fs/cgroup/devices rw,nosuid,nodev,noexec,relatime shared:13 - cgroup none rw,seclabel,devices\n" +
141
"42 30 0:38 / /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime shared:14 - cgroup none rw,seclabel,cpuset\n" +
142
"43 30 0:39 / /sys/fs/cgroup/blkio rw,nosuid,nodev,noexec,relatime shared:15 - cgroup none rw,seclabel,blkio\n" +
143
"44 30 0:40 / /sys/fs/cgroup/freezer rw,nosuid,nodev,noexec,relatime shared:16 - cgroup none rw,seclabel,freezer\n";
144
private String mntInfoHybridRest = cgroupv1MountInfoLineMemory + mntInfoHybridStub;
145
private String mntInfoHybridMissingMemory = mntInfoHybridStub;
146
private String mntInfoHybrid = cgroupV2LineHybrid + mntInfoHybridRest;
147
private String mntInfoHybridFlippedOrder = mntInfoHybridRest + cgroupV2LineHybrid;
148
private String mntInfoCgroupv1JoinControllers =
149
"31 22 0:26 / /sys/fs/cgroup ro,nosuid,nodev,noexec shared:9 - tmpfs tmpfs ro,mode=755\n" +
150
"32 31 0:27 / /sys/fs/cgroup/unified rw,nosuid,nodev,noexec,relatime shared:10 - cgroup2 cgroup2 rw,nsdelegate\n" +
151
"33 31 0:28 / /sys/fs/cgroup/systemd rw,nosuid,nodev,noexec,relatime shared:11 - cgroup cgroup rw,xattr,name=systemd\n" +
152
"36 31 0:31 / /sys/fs/cgroup/perf_event rw,nosuid,nodev,noexec,relatime shared:15 - cgroup cgroup rw,perf_event\n" +
153
"37 31 0:32 / /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime shared:16 - cgroup cgroup rw,cpuset\n" +
154
"38 31 0:33 / /sys/fs/cgroup/cpu,cpuacct,net_cls,net_prio,hugetlb,memory rw,nosuid,nodev,noexec,relatime shared:17 - cgroup cgroup rw,cpu,cpuacct,memory,net_cls,net_prio,hugetlb\n" +
155
"39 31 0:34 / /sys/fs/cgroup/pids rw,nosuid,nodev,noexec,relatime shared:18 - cgroup cgroup rw,pids\n" +
156
"40 31 0:35 / /sys/fs/cgroup/devices rw,nosuid,nodev,noexec,relatime shared:19 - cgroup cgroup rw,devices\n" +
157
"41 31 0:36 / /sys/fs/cgroup/blkio rw,nosuid,nodev,noexec,relatime shared:20 - cgroup cgroup rw,blkio\n" +
158
"42 31 0:37 / /sys/fs/cgroup/rdma rw,nosuid,nodev,noexec,relatime shared:21 - cgroup cgroup rw,rdma\n" +
159
"43 31 0:38 / /sys/fs/cgroup/freezer rw,nosuid,nodev,noexec,relatime shared:22 - cgroup cgroup rw,freezer\n";
160
private String mntInfoCgroupv1MoreCpusetLine = "121 32 0:37 / /cpusets rw,relatime shared:69 - cgroup none rw,cpuset\n";
161
private String mntInfoCgroupv1DoubleCpuset = mntInfoCgroupv1MoreCpusetLine + mntInfoHybrid;
162
private String mntInfoCgroupv1DoubleCpuset2 = mntInfoHybrid + mntInfoCgroupv1MoreCpusetLine;
163
private String cgroupsNonZeroHierarchy =
164
"#subsys_name hierarchy num_cgroups enabled\n" +
165
"cpuset 3 1 1\n" +
166
"cpu 8 1 1\n" +
167
"cpuacct 8 1 1\n" +
168
"blkio 10 1 1\n" +
169
"memory 2 90 1\n" +
170
"devices 8 74 1\n" +
171
"freezer 11 1 1\n" +
172
"net_cls 5 1 1\n" +
173
"perf_event 4 1 1\n" +
174
"net_prio 5 1 1\n" +
175
"hugetlb 6 1 1\n" +
176
"pids 9 80 1"; // hierarchy has to match procSelfCgroupHybridContent
177
private String mntInfoCgroupsV2Only =
178
"28 21 0:25 / /sys/fs/cgroup rw,nosuid,nodev,noexec,relatime shared:4 - cgroup2 none rw,seclabel,nsdelegate";
179
private String mntInfoCgroupsV1SystemdOnly =
180
"35 26 0:26 / /sys/fs/cgroup/systemd rw,nosuid,nodev,noexec,relatime - cgroup systemd rw,name=systemd\n" +
181
"26 18 0:19 / /sys/fs/cgroup rw,relatime - tmpfs none rw,size=4k,mode=755\n";
182
183
// We have a mix of V1 and V2 controllers, but none of the V1 controllers
184
// are used by Java, so the JDK should start in V2 mode.
185
private String cgroupsNonZeroHierarchyOnlyFreezer =
186
"#subsys_name hierarchy num_cgroups enabled\n" +
187
"cpuset 0 171 1\n" +
188
"cpu 0 171 1\n" +
189
"cpuacct 0 171 1\n" +
190
"blkio 0 171 1\n" +
191
"memory 0 171 1\n" +
192
"devices 0 171 1\n" +
193
"freezer 1 1 1\n" +
194
"net_cls 0 171 1\n" +
195
"perf_event 0 171 1\n" +
196
"net_prio 0 171 1\n" +
197
"hugetlb 0 171 1\n" +
198
"pids 0 171 1\n" +
199
"rdma 0 171 1\n" +
200
"misc 0 171 1\n";
201
private String cgroupv1SelfOnlyFreezerContent = "1:freezer:/\n" +
202
"0::/user.slice/user-1000.slice/session-2.scope";
203
private String mntInfoOnlyFreezerInV1 =
204
"32 23 0:27 / /sys/fs/cgroup rw,nosuid,nodev,noexec,relatime shared:9 - cgroup2 cgroup2 rw,nsdelegate,memory_recursiveprot\n" +
205
"911 32 0:47 / /sys/fs/cgroup/freezer rw,relatime shared:476 - cgroup freezer rw,freezer\n";
206
207
private void setup() {
208
try {
209
existingDirectory = Utils.createTempDirectory(CgroupSubsystemFactory.class.getSimpleName());
210
Path cgroupsZero = Paths.get(existingDirectory.toString(), "cgroups_zero");
211
Files.writeString(cgroupsZero, cgroupsZeroHierarchy, StandardCharsets.UTF_8);
212
cgroupv1CgInfoZeroHierarchy = cgroupsZero;
213
cgroupv2CgInfoZeroHierarchy = cgroupsZero;
214
cgroupv1MntInfoZeroHierarchy = Paths.get(existingDirectory.toString(), "mountinfo_empty");
215
Files.writeString(cgroupv1MntInfoZeroHierarchy, mntInfoEmpty);
216
217
cgroupv2MntInfoZeroHierarchy = Paths.get(existingDirectory.toString(), "mountinfo_cgroupv2");
218
Files.writeString(cgroupv2MntInfoZeroHierarchy, mntInfoCgroupsV2Only);
219
220
cgroupv1CgInfoNonZeroHierarchy = Paths.get(existingDirectory.toString(), "cgroups_non_zero");
221
Files.writeString(cgroupv1CgInfoNonZeroHierarchy, cgroupsNonZeroHierarchy);
222
223
cgroupv1MntInfoNonZeroHierarchy = Paths.get(existingDirectory.toString(), "mountinfo_non_zero");
224
Files.writeString(cgroupv1MntInfoNonZeroHierarchy, mntInfoHybrid);
225
226
cgroupv1MntInfoNonZeroHierarchyOtherOrder = Paths.get(existingDirectory.toString(), "mountinfo_non_zero_cgroupv2_last");
227
Files.writeString(cgroupv1MntInfoNonZeroHierarchyOtherOrder, mntInfoHybridFlippedOrder);
228
229
cgroupV1SelfCgroup = Paths.get(existingDirectory.toString(), "cgroup_self_hybrid");
230
Files.writeString(cgroupV1SelfCgroup, procSelfCgroupHybridContent);
231
232
cgroupV2SelfCgroup = Paths.get(existingDirectory.toString(), "cgroup_self_v2");
233
Files.writeString(cgroupV2SelfCgroup, procSelfCgroupV2UnifiedContent);
234
235
cgroupv1MntInfoMissingMemoryController = Paths.get(existingDirectory.toString(), "mnt_info_missing_memory");
236
Files.writeString(cgroupv1MntInfoMissingMemoryController, mntInfoHybridMissingMemory);
237
238
cgroupV2MntInfoMissingCgroupv2 = Paths.get(existingDirectory.toString(), "mnt_info_missing_cgroup2");
239
Files.writeString(cgroupV2MntInfoMissingCgroupv2, mntInfoHybridStub);
240
241
cgroupv1MntInfoDoubleCpuset = Paths.get(existingDirectory.toString(), "mnt_info_cgroupv1_double_cpuset");
242
Files.writeString(cgroupv1MntInfoDoubleCpuset, mntInfoCgroupv1DoubleCpuset);
243
244
cgroupv1MntInfoDoubleCpuset2 = Paths.get(existingDirectory.toString(), "mnt_info_cgroupv1_double_cpuset2");
245
Files.writeString(cgroupv1MntInfoDoubleCpuset2, mntInfoCgroupv1DoubleCpuset2);
246
247
cgroupv1MntInfoSystemdOnly = Paths.get(existingDirectory.toString(), "mnt_info_cgroupv1_systemd_only");
248
Files.writeString(cgroupv1MntInfoSystemdOnly, mntInfoCgroupsV1SystemdOnly);
249
250
cgroupv1CgroupsJoinControllers = Paths.get(existingDirectory.toString(), "cgroups_cgv1_join_controllers");
251
Files.writeString(cgroupv1CgroupsJoinControllers, cgroupsNonZeroJoinControllers);
252
253
cgroupv1SelfCgroupsJoinControllers = Paths.get(existingDirectory.toString(), "self_cgroup_cgv1_join_controllers");
254
Files.writeString(cgroupv1SelfCgroupsJoinControllers, procSelfCgroupV1JoinControllers);
255
256
cgroupv1MountInfoJoinControllers = Paths.get(existingDirectory.toString(), "mntinfo_cgv1_join_controllers");
257
Files.writeString(cgroupv1MountInfoJoinControllers, mntInfoCgroupv1JoinControllers);
258
259
cgroupv2CgInfoNoZeroHierarchyOnlyFreezer = Paths.get(existingDirectory.toString(), "cgroups_cgv2_non_zero_only_freezer");
260
Files.writeString(cgroupv2CgInfoNoZeroHierarchyOnlyFreezer, cgroupsNonZeroHierarchyOnlyFreezer);
261
262
cgroupv2SelfNoZeroHierarchyOnlyFreezer = Paths.get(existingDirectory.toString(), "self_cgroup_non_zero_only_freezer");
263
Files.writeString(cgroupv2SelfNoZeroHierarchyOnlyFreezer, cgroupv1SelfOnlyFreezerContent);
264
265
cgroupv2MntInfoNoZeroHierarchyOnlyFreezer = Paths.get(existingDirectory.toString(), "self_mountinfo_cgv2_non_zero_only_freezer");
266
Files.writeString(cgroupv2MntInfoNoZeroHierarchyOnlyFreezer, mntInfoOnlyFreezerInV1);
267
} catch (IOException e) {
268
throw new RuntimeException(e);
269
}
270
}
271
272
private void teardown() {
273
try {
274
FileUtils.deleteFileTreeWithRetry(existingDirectory);
275
} catch (IOException e) {
276
System.err.println("Teardown failed. " + e.getMessage());
277
}
278
}
279
280
private boolean isValidCgroup(int value) {
281
return value == CGROUPS_V1 || value == CGROUPS_V2;
282
}
283
284
public void testCgroupv1JoinControllerCombo(WhiteBox wb) {
285
String procCgroups = cgroupv1CgroupsJoinControllers.toString();
286
String procSelfCgroup = cgroupv1SelfCgroupsJoinControllers.toString();
287
String procSelfMountinfo = cgroupv1MountInfoJoinControllers.toString();
288
int retval = wb.validateCgroup(procCgroups, procSelfCgroup, procSelfMountinfo);
289
Asserts.assertEQ(CGROUPS_V1, retval, "Join controllers should be properly detected");
290
Asserts.assertTrue(isValidCgroup(retval));
291
System.out.println("testCgroupv1JoinControllerMounts PASSED!");
292
}
293
294
public void testCgroupv1MultipleCpusetMounts(WhiteBox wb, Path mountInfo) {
295
String procCgroups = cgroupv1CgInfoNonZeroHierarchy.toString();
296
String procSelfCgroup = cgroupV1SelfCgroup.toString();
297
String procSelfMountinfo = mountInfo.toString();
298
int retval = wb.validateCgroup(procCgroups, procSelfCgroup, procSelfMountinfo);
299
Asserts.assertEQ(CGROUPS_V1, retval, "Multiple cpuset controllers, but only one in /sys/fs/cgroup");
300
Asserts.assertTrue(isValidCgroup(retval));
301
System.out.println("testCgroupv1MultipleCpusetMounts PASSED!");
302
}
303
304
public void testCgroupv1SystemdOnly(WhiteBox wb) {
305
String procCgroups = cgroupv1CgInfoZeroHierarchy.toString();
306
String procSelfCgroup = cgroupV1SelfCgroup.toString();
307
String procSelfMountinfo = cgroupv1MntInfoSystemdOnly.toString();
308
int retval = wb.validateCgroup(procCgroups, procSelfCgroup, procSelfMountinfo);
309
Asserts.assertEQ(INVALID_CGROUPS_NO_MOUNT, retval, "Only systemd mounted. Invalid");
310
Asserts.assertFalse(isValidCgroup(retval));
311
System.out.println("testCgroupv1SystemdOnly PASSED!");
312
}
313
314
public void testCgroupv1NoMounts(WhiteBox wb) {
315
String procCgroups = cgroupv1CgInfoZeroHierarchy.toString();
316
String procSelfCgroup = cgroupV1SelfCgroup.toString();
317
String procSelfMountinfo = cgroupv1MntInfoZeroHierarchy.toString();
318
int retval = wb.validateCgroup(procCgroups, procSelfCgroup, procSelfMountinfo);
319
Asserts.assertEQ(INVALID_CGROUPS_NO_MOUNT, retval, "No cgroups mounted in /proc/self/mountinfo. Invalid.");
320
Asserts.assertFalse(isValidCgroup(retval));
321
System.out.println("testCgroupv1NoMounts PASSED!");
322
}
323
324
public void testCgroupv2NoCgroup2Fs(WhiteBox wb) {
325
String procCgroups = cgroupv2CgInfoZeroHierarchy.toString();
326
String procSelfCgroup = cgroupV2SelfCgroup.toString();
327
String procSelfMountinfo = cgroupV2MntInfoMissingCgroupv2.toString();
328
int retval = wb.validateCgroup(procCgroups, procSelfCgroup, procSelfMountinfo);
329
Asserts.assertEQ(INVALID_CGROUPS_V2, retval, "No cgroup2 filesystem in /proc/self/mountinfo. Invalid.");
330
Asserts.assertFalse(isValidCgroup(retval));
331
System.out.println("testCgroupv2NoCgroup2Fs PASSED!");
332
}
333
334
public void testCgroupv1MissingMemoryController(WhiteBox wb) {
335
String procCgroups = cgroupv1CgInfoNonZeroHierarchy.toString();
336
String procSelfCgroup = cgroupV1SelfCgroup.toString();
337
String procSelfMountinfo = cgroupv1MntInfoMissingMemoryController.toString();
338
int retval = wb.validateCgroup(procCgroups, procSelfCgroup, procSelfMountinfo);
339
Asserts.assertEQ(INVALID_CGROUPS_V1, retval, "Required memory controller path missing in mountinfo. Invalid.");
340
Asserts.assertFalse(isValidCgroup(retval));
341
System.out.println("testCgroupv1MissingMemoryController PASSED!");
342
}
343
344
public void testCgroupv2(WhiteBox wb) {
345
String procCgroups = cgroupv2CgInfoZeroHierarchy.toString();
346
String procSelfCgroup = cgroupV2SelfCgroup.toString();
347
String procSelfMountinfo = cgroupv2MntInfoZeroHierarchy.toString();
348
int retval = wb.validateCgroup(procCgroups, procSelfCgroup, procSelfMountinfo);
349
Asserts.assertEQ(CGROUPS_V2, retval, "Expected");
350
Asserts.assertTrue(isValidCgroup(retval));
351
System.out.println("testCgroupv2 PASSED!");
352
}
353
354
public void testCgroupV1Hybrid(WhiteBox wb) {
355
String procCgroups = cgroupv1CgInfoNonZeroHierarchy.toString();
356
String procSelfCgroup = cgroupV1SelfCgroup.toString();
357
String procSelfMountinfo = cgroupv1MntInfoNonZeroHierarchy.toString();
358
int retval = wb.validateCgroup(procCgroups, procSelfCgroup, procSelfMountinfo);
359
Asserts.assertEQ(CGROUPS_V1, retval, "Hybrid cgroups expected as cgroups v1");
360
Asserts.assertTrue(isValidCgroup(retval));
361
System.out.println("testCgroupv1Hybrid PASSED!");
362
}
363
364
public void testCgroupV1HybridMntInfoOrder(WhiteBox wb) {
365
String procCgroups = cgroupv1CgInfoNonZeroHierarchy.toString();
366
String procSelfCgroup = cgroupV1SelfCgroup.toString();
367
String procSelfMountinfo = cgroupv1MntInfoNonZeroHierarchyOtherOrder.toString();
368
int retval = wb.validateCgroup(procCgroups, procSelfCgroup, procSelfMountinfo);
369
Asserts.assertEQ(CGROUPS_V1, retval, "Hybrid cgroups expected as cgroups v1");
370
Asserts.assertTrue(isValidCgroup(retval));
371
System.out.println("testCgroupv1HybridMntInfoOrder PASSED!");
372
}
373
374
public void testNonZeroHierarchyOnlyFreezer(WhiteBox wb) {
375
String cgroups = cgroupv2CgInfoNoZeroHierarchyOnlyFreezer.toString();
376
String mountInfo = cgroupv2MntInfoNoZeroHierarchyOnlyFreezer.toString();
377
String selfCgroup = cgroupv2SelfNoZeroHierarchyOnlyFreezer.toString();
378
int retval = wb.validateCgroup(cgroups, selfCgroup, mountInfo);
379
Asserts.assertEQ(CGROUPS_V2, retval, "All V1 controllers are ignored");
380
Asserts.assertTrue(isValidCgroup(retval));
381
System.out.println("testNonZeroHierarchyOnlyFreezer PASSED!");
382
}
383
384
public static void main(String[] args) throws Exception {
385
WhiteBox wb = WhiteBox.getWhiteBox();
386
CgroupSubsystemFactory test = new CgroupSubsystemFactory();
387
test.setup();
388
try {
389
test.testCgroupv1SystemdOnly(wb);
390
test.testCgroupv1NoMounts(wb);
391
test.testCgroupv2(wb);
392
test.testCgroupV1Hybrid(wb);
393
test.testCgroupV1HybridMntInfoOrder(wb);
394
test.testCgroupv1MissingMemoryController(wb);
395
test.testCgroupv2NoCgroup2Fs(wb);
396
test.testCgroupv1MultipleCpusetMounts(wb, test.cgroupv1MntInfoDoubleCpuset);
397
test.testCgroupv1MultipleCpusetMounts(wb, test.cgroupv1MntInfoDoubleCpuset2);
398
test.testCgroupv1JoinControllerCombo(wb);
399
test.testNonZeroHierarchyOnlyFreezer(wb);
400
} finally {
401
test.teardown();
402
}
403
}
404
}
405
406