From 34aeb33dddb1959441e0b963ad1a70ca3fba04a3 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 8 Oct 2026 12:43:17 -0700 Subject: [PATCH 1/2] fs: skip hugetlb tests if no huge pages available When the system has no huge page sizes available (e.g. /sys/kernel/mm/hugepages is absent in a build environment), cgroups.HugePageSizes returns an empty list, and HugetlbGroup's Set and GetStats are no-ops. As a result, the tests which expect GetStats to fail are failing, and the rest are passing vacuously. Skip all hugetlb tests in such case. Reported in https://github.com/opencontainers/runc/issues/1822. Signed-off-by: Kir Kolyshkin --- fs/hugetlb_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/fs/hugetlb_test.go b/fs/hugetlb_test.go index c37e3ec..cbc94c5 100644 --- a/fs/hugetlb_test.go +++ b/fs/hugetlb_test.go @@ -28,6 +28,8 @@ const ( ) func TestHugetlbSetHugetlb(t *testing.T) { + skipNoHugePages(t) + path := tempDir(t, "hugetlb") const ( @@ -70,6 +72,8 @@ func TestHugetlbSetHugetlb(t *testing.T) { } func TestHugetlbStats(t *testing.T) { + skipNoHugePages(t) + path := tempDir(t, "hugetlb") for _, pageSize := range cgroups.HugePageSizes() { writeFileContents(t, path, map[string]string{ @@ -92,6 +96,8 @@ func TestHugetlbStats(t *testing.T) { } func TestHugetlbRStatsRsvd(t *testing.T) { + skipNoHugePages(t) + path := tempDir(t, "hugetlb") for _, pageSize := range cgroups.HugePageSizes() { writeFileContents(t, path, map[string]string{ @@ -114,6 +120,8 @@ func TestHugetlbRStatsRsvd(t *testing.T) { } func TestHugetlbStatsNoUsageFile(t *testing.T) { + skipNoHugePages(t) + path := tempDir(t, "hugetlb") writeFileContents(t, path, map[string]string{ maxUsage: hugetlbMaxUsageContents, @@ -128,6 +136,8 @@ func TestHugetlbStatsNoUsageFile(t *testing.T) { } func TestHugetlbStatsNoMaxUsageFile(t *testing.T) { + skipNoHugePages(t) + path := tempDir(t, "hugetlb") for _, pageSize := range cgroups.HugePageSizes() { writeFileContents(t, path, map[string]string{ @@ -144,6 +154,8 @@ func TestHugetlbStatsNoMaxUsageFile(t *testing.T) { } func TestHugetlbStatsBadUsageFile(t *testing.T) { + skipNoHugePages(t) + path := tempDir(t, "hugetlb") for _, pageSize := range cgroups.HugePageSizes() { writeFileContents(t, path, map[string]string{ @@ -161,6 +173,8 @@ func TestHugetlbStatsBadUsageFile(t *testing.T) { } func TestHugetlbStatsBadMaxUsageFile(t *testing.T) { + skipNoHugePages(t) + path := tempDir(t, "hugetlb") writeFileContents(t, path, map[string]string{ usage: hugetlbUsageContents, @@ -174,3 +188,12 @@ func TestHugetlbStatsBadMaxUsageFile(t *testing.T) { t.Fatal("Expected failure") } } + +// skipNoHugePages skips the test if the system has no huge page sizes +// available, as in this case [HugetlbGroup] methods are no-ops. +func skipNoHugePages(t *testing.T) { + t.Helper() + if len(cgroups.HugePageSizes()) == 0 { + t.Skip("no huge page sizes available") + } +} From f1243f0ba0de078e0663adab591e8e939cd6dd3c Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 8 Oct 2026 12:43:43 -0700 Subject: [PATCH 2/2] fs: fix file names in hugetlb failure tests Some hugetlb tests use file name templates such as "hugetlb.%s.max_usage_in_bytes" as is, without substituting the page size. As a result, TestHugetlbStatsBadMaxUsageFile fails because the usage file is not found, rather than because the max usage file contents can't be parsed, and so it does not test what it is supposed to test. Fix this (and similar issues in other tests) by using proper file names for every available huge page size. Signed-off-by: Kir Kolyshkin --- fs/hugetlb_test.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/fs/hugetlb_test.go b/fs/hugetlb_test.go index cbc94c5..b46c533 100644 --- a/fs/hugetlb_test.go +++ b/fs/hugetlb_test.go @@ -123,9 +123,11 @@ func TestHugetlbStatsNoUsageFile(t *testing.T) { skipNoHugePages(t) path := tempDir(t, "hugetlb") - writeFileContents(t, path, map[string]string{ - maxUsage: hugetlbMaxUsageContents, - }) + for _, pageSize := range cgroups.HugePageSizes() { + writeFileContents(t, path, map[string]string{ + fmt.Sprintf(maxUsage, pageSize): hugetlbMaxUsageContents, + }) + } hugetlb := &HugetlbGroup{} actualStats := *cgroups.NewStats() @@ -159,8 +161,8 @@ func TestHugetlbStatsBadUsageFile(t *testing.T) { path := tempDir(t, "hugetlb") for _, pageSize := range cgroups.HugePageSizes() { writeFileContents(t, path, map[string]string{ - fmt.Sprintf(usage, pageSize): "bad", - maxUsage: hugetlbMaxUsageContents, + fmt.Sprintf(usage, pageSize): "bad", + fmt.Sprintf(maxUsage, pageSize): hugetlbMaxUsageContents, }) } @@ -176,10 +178,12 @@ func TestHugetlbStatsBadMaxUsageFile(t *testing.T) { skipNoHugePages(t) path := tempDir(t, "hugetlb") - writeFileContents(t, path, map[string]string{ - usage: hugetlbUsageContents, - maxUsage: "bad", - }) + for _, pageSize := range cgroups.HugePageSizes() { + writeFileContents(t, path, map[string]string{ + fmt.Sprintf(usage, pageSize): hugetlbUsageContents, + fmt.Sprintf(maxUsage, pageSize): "bad", + }) + } hugetlb := &HugetlbGroup{} actualStats := *cgroups.NewStats()