Navigation Menu

Skip to content


8287663: Add a regression test for JDK-8287073
Browse files Browse the repository at this point in the history
Reviewed-by: iklam
  • Loading branch information
jerboaa committed Jun 7, 2022
1 parent b647a12 commit 2d8c649
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Expand Up @@ -86,7 +86,10 @@ static CgroupMetrics create() {
} catch (IOException | UncheckedIOException e) {
return null;
return create(optResult);

public static CgroupMetrics create(Optional<CgroupTypeResult> optResult) {
if (optResult.isEmpty()) {
return null;
Expand Down
Expand Up @@ -25,6 +25,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static;

import java.nio.charset.StandardCharsets;
Expand All @@ -50,7 +51,7 @@

* @test
* @bug 8287107
* @bug 8287107 8287073
* @key cgroups
* @requires == "linux"
* @modules java.base/jdk.internal.platform
Expand All @@ -66,6 +67,7 @@ public class TestCgroupSubsystemFactory {
private Path cgroupv1CgInfoZeroHierarchy;
private Path cgroupv1MntInfoZeroHierarchy;
private Path cgroupv2CgInfoZeroHierarchy;
private Path cgroupv2CgInfoZeroMinimal;
private Path cgroupv2MntInfoZeroHierarchy;
private Path cgroupv1CgInfoNonZeroHierarchy;
private Path cgroupv1MntInfoNonZeroHierarchy;
Expand Down Expand Up @@ -127,6 +129,9 @@ public class TestCgroupSubsystemFactory {
"net_cls 0 1 1\n" +
"blkio 0 1 1\n" +
"perf_event 0 1 1 ";
private String cgroupsZeroHierarchyMinimal =
"#subsys_name hierarchy num_cgroups enabled\n" +
"cpu 0 1 1\n";
private String mntInfoHybrid =
"30 23 0:26 / /sys/fs/cgroup ro,nosuid,nodev,noexec shared:4 - tmpfs tmpfs ro,seclabel,mode=755\n" +
"31 30 0:27 / /sys/fs/cgroup/unified rw,nosuid,nodev,noexec,relatime shared:5 - cgroup2 none rw,seclabel,nsdelegate\n" +
Expand Down Expand Up @@ -306,6 +311,9 @@ public void setup() {
cgroupv1MountInfoCgroupsOnlyCPUCtrl = Paths.get(existingDirectory.toString(), "self_mountinfo_cpu_only_controller");
Files.writeString(cgroupv1MountInfoCgroupsOnlyCPUCtrl, mntInfoCpuOnly);

cgroupv2CgInfoZeroMinimal = Paths.get(existingDirectory.toString(), "cgv2_proc_cgroups_minimal");
Files.writeString(cgroupv2CgInfoZeroMinimal, cgroupsZeroHierarchyMinimal);

cgroupv2CgInfoNoZeroHierarchyOnlyFreezer = Paths.get(existingDirectory.toString(), "cgroups_cgv2_non_zero_only_freezer");
Files.writeString(cgroupv2CgInfoNoZeroHierarchyOnlyFreezer, cgroupsNonZeroHierarchyOnlyFreezer);

Expand Down Expand Up @@ -480,6 +488,30 @@ public void testZeroHierarchyCgroupsV2() throws IOException {
assertEquals("/sys/fs/cgroup", cpuInfo.getMountPoint());

* On some systems the memory controller might not show up in /proc/cgroups
* which may provoke a NPE on instantiation. See bug 8287073.
public void testZeroHierarchyCgroupsV2Minimal() throws IOException {
String cgroups = cgroupv2CgInfoZeroMinimal.toString();
String mountInfo = cgroupv2MntInfoZeroHierarchy.toString();
String selfCgroup = cgroupv2SelfCgroup.toString();
Optional<CgroupTypeResult> result = CgroupSubsystemFactory.determineType(mountInfo, cgroups, selfCgroup);

assertTrue("Expected non-empty cgroup result", result.isPresent());
CgroupTypeResult res = result.get();

assertTrue("zero hierarchy ids with mounted controllers expected cgroups v2", res.isCgroupV2());
assertNull("Only cpu controller present", res.getInfos().get("memory"));
try {
// pass
} catch (NullPointerException e) {
fail("Missing memory controller should not cause any NPE");

@Test(expected = IOException.class)
public void mountInfoFileNotFound() throws IOException {
String cgroups = cgroupv1CgInfoZeroHierarchy.toString(); // any existing file
Expand Down

3 comments on commit 2d8c649

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

Copy link

@openjdk openjdk bot commented on 2d8c649 Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jerboaa Could not automatically backport 2d8c6490 to openjdk/jdk11u-dev due to conflicts in the following files:

  • test/jdk/jdk/internal/platform/cgroup/

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk11u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b jerboaa-backport-2d8c6490

# Fetch the commit you want to backport
$ git fetch --no-tags 2d8c6490540e3ccea23b81129b2e4073915071e0

# Backport the commit
$ git cherry-pick --no-commit 2d8c6490540e3ccea23b81129b2e4073915071e0
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 2d8c6490540e3ccea23b81129b2e4073915071e0'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u-dev with the title Backport 2d8c6490540e3ccea23b81129b2e4073915071e0.

Please sign in to comment.