Skip to content

Commit c64eb7f

Browse files
tests: add integration test for cgroups hybrid
Check that runc run and runc exec put the process on the same cgroups v2 when using hybrid mode. Signed-off-by: Mauricio Vásquez <[email protected]>
1 parent e628462 commit c64eb7f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

tests/integration/cgroups.bats

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,26 @@ function setup() {
270270

271271
check_cpu_weight 42
272272
}
273+
274+
@test "runc exec (cgroup v2 hybrid joins correct cgroup)" {
275+
requires root cgroups_hybrid
276+
277+
set_cgroups_path "$BUSYBOX_BUNDLE"
278+
set_cgroup_mount_writable "$BUSYBOX_BUNDLE"
279+
280+
runc run --pid-file pid.txt -d --console-socket "$CONSOLE_SOCKET" test_cgroups_group
281+
[ "$status" -eq 0 ]
282+
283+
pid=$(cat pid.txt)
284+
run_cgroup=$(tail -1 </proc/"$pid"/cgroup)
285+
[[ $run_cgroup == *"runc-cgroups-integration-test"* ]]
286+
287+
runc exec test_cgroups_group cat /proc/self/cgroup
288+
[ "$status" -eq 0 ]
289+
290+
exec_cgroup=${lines[-1]}
291+
[[ $exec_cgroup == *"runc-cgroups-integration-test"* ]]
292+
293+
# check that the cgroups v2 path is the same for both processes
294+
[[ "$run_cgroup" == "$exec_cgroup" ]]
295+
}

tests/integration/helpers.bash

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ function init_cgroup_paths() {
151151
CGROUP_SUBSYSTEMS+=" freezer"
152152
fi
153153
else
154+
if stat -f -c %t /sys/fs/cgroup/unified | grep -qFw 63677270; then
155+
CGROUP_HYBRID=yes
156+
fi
154157
CGROUP_UNIFIED=no
155158
CGROUP_SUBSYSTEMS=$(awk '!/^#/ {print $1}' /proc/cgroups)
156159
for g in ${CGROUP_SUBSYSTEMS}; do
@@ -352,6 +355,12 @@ function requires() {
352355
skip_me=1
353356
fi
354357
;;
358+
cgroups_hybrid)
359+
init_cgroup_paths
360+
if [ "$CGROUP_HYBRID" != "yes" ]; then
361+
skip_me=1
362+
fi
363+
;;
355364
smp)
356365
local cpu_count=$(grep -c '^processor' /proc/cpuinfo)
357366
if [ "$cpu_count" -lt 2 ]; then

0 commit comments

Comments
 (0)