Skip to content

add functional tests for cgroup v2 in gcs#2664

Open
jiechen0826 wants to merge 1 commit intomicrosoft:mainfrom
jiechen0826:cgroup-v2-public
Open

add functional tests for cgroup v2 in gcs#2664
jiechen0826 wants to merge 1 commit intomicrosoft:mainfrom
jiechen0826:cgroup-v2-public

Conversation

@jiechen0826
Copy link
Copy Markdown
Contributor

Summary

Adds functional end-to-end tests for cgroup operations in the GCS, covering both v1 and v2 hierarchies. These tests run inside the UVM as part of the GCS test binary and exercise the full cgroup stats pipeline regardless of which cgroup version the kernel provides.

Motivation

The GCS cgroup code path had no dedicated functional test coverage. As we migrate UVM images from cgroup v1 to v2 (e.g., Ubuntu 24.04), we need a regression gate that validates stats collection, resource limits, CPU throttling, and OOM monitoring work correctly on both cgroup versions.

Changes

New: test/gcs/cgroup_test.go (7 tests)

Test What it validates
TestCgroupVersionDetection IsCgroupV2() matches actual /sys/fs/cgroup filesystem layout
TestContainerStats_CgroupMetrics Full stats pipeline returns non-nil memory, CPU, and pids metrics
TestContainerStats_MemoryLimit OCI memory limit (128 MiB) round-trips correctly through cgroup
TestContainerExec_CgroupIsolation Exec'd process lands in the correct /containers/<id> cgroup path
TestMultipleContainers_IndependentStats Two containers with different memory limits (64 MiB / 128 MiB) report independent stats
TestContainerStats_CPUThrottling CFS quota (10%) produces non-zero throttling counters under CPU burn
TestOOMEventFD_ContainerKill 64 MiB container killed by 128 MiB allocation reports OomKill=1 and fires eventfd

Modified: internal/guest/cgroup/cgroup.go

  • Added LoadManager(cgroupPath string) (Manager, error) — loads an existing cgroup (created by the runtime) as a Manager, supporting both v1 and v2. Used by tests to inspect container cgroups.

Modified: test/gcs/main_test.go

  • Fixed setup() to handle both cgroup v1 and v2 when joining the root cgroup. Previously only used the v1 API (cgroups.Load), which fails on v2-only kernels.

Testing

All 7 tests pass in a Hyper-V LCOW UVM with cgroup v2 (Ubuntu 24.04 rootfs):
--- PASS: TestCgroupVersionDetection (0.00s)
--- PASS: TestContainerStats_CgroupMetrics (2.07s)
--- PASS: TestContainerStats_MemoryLimit (2.09s)
--- PASS: TestContainerExec_CgroupIsolation (2.17s)
--- PASS: TestMultipleContainers_IndependentStats (4.17s)
--- PASS: TestContainerStats_CPUThrottling (4.15s)
--- PASS: TestOOMEventFD_ContainerKill (2.83s)
PASS

Signed-off-by: Jie Chen <jiechen3@microsoft.com>
@jiechen0826 jiechen0826 requested a review from a team as a code owner April 7, 2026 18:03
@jiechen0826 jiechen0826 changed the title add functional tests for cgorup in gcs add functional tests for cgroup v2 in gcs Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants