Skip to content

Commit 046755a

Browse files
committed
tests: add pids.limit tests
Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 63b5b4f commit 046755a

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

tests/integration/cgroups.bats

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,36 @@ convert_hugetlb_size() {
324324
done
325325
}
326326

327+
# https://github.com/opencontainers/runc/issues/4014.
328+
@test "runc run (pids.limit=0 is 0)" {
329+
[ $EUID -ne 0 ] && requires rootless_cgroup
330+
requires cgroups_pids
331+
332+
set_cgroups_path
333+
update_config '.linux.resources.pids.limit = 0'
334+
335+
runc run -d --console-socket "$CONSOLE_SOCKET" test_pids
336+
[ "$status" -eq 0 ]
337+
# systemd doesn't support TasksMax=0 so runc will silently remap it to 1.
338+
check_cgroup_value "pids.max" "1"
339+
check_systemd_value "TasksMax" "1"
340+
}
341+
342+
# https://github.com/opencontainers/runc/issues/4014.
343+
@test "runc run (pids.limit=-1 means unlimited)" {
344+
[ $EUID -ne 0 ] && requires rootless_cgroup
345+
requires cgroups_pids
346+
347+
set_cgroups_path
348+
update_config '.linux.resources.pids.limit = -1'
349+
350+
runc run -d --console-socket "$CONSOLE_SOCKET" test_pids
351+
[ "$status" -eq 0 ]
352+
check_cgroup_value "pids.max" "max"
353+
# systemd < v227 shows UINT64_MAX instead of "infinity".
354+
check_systemd_value "TasksMax" "infinity" "18446744073709551615"
355+
}
356+
327357
@test "runc run (cgroup v2 resources.unified only)" {
328358
requires root cgroups_v2
329359

@@ -390,6 +420,7 @@ convert_hugetlb_size() {
390420
set_cgroups_path
391421
# CPU shares of 3333 corresponds to CPU weight of 128.
392422
update_config ' .linux.resources.memory |= {"limit": 33554432}
423+
| .linux.resources.pids.limit = 100
393424
| .linux.resources.cpu |= {
394425
"shares": 3333,
395426
"quota": 40000,

tests/integration/update.bats

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,37 @@ EOF
327327
check_cpu_shares 100
328328
}
329329

330+
@test "update pids.limit" {
331+
[ $EUID -ne 0 ] && requires rootless_cgroup
332+
requires cgroups_pids
333+
334+
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
335+
[ "$status" -eq 0 ]
336+
337+
check_cgroup_value "pids.max" 20
338+
check_systemd_value "TasksMax" 20
339+
340+
runc update test_update --pids-limit 12345
341+
[ "$status" -eq 0 ]
342+
343+
check_cgroup_value "pids.max" "12345"
344+
check_systemd_value "TasksMax" "12345"
345+
346+
runc update test_update --pids-limit -1
347+
[ "$status" -eq 0 ]
348+
349+
check_cgroup_value "pids.max" "max"
350+
# systemd < v227 shows UINT64_MAX instead of "infinity".
351+
check_systemd_value "TasksMax" "infinity" "18446744073709551615"
352+
353+
runc update test_update --pids-limit 0
354+
[ "$status" -eq 0 ]
355+
356+
# systemd doesn't support TasksMax=0 so runc will silently remap it to 1.
357+
check_cgroup_value "pids.max" "1"
358+
check_systemd_value "TasksMax" "1"
359+
}
360+
330361
@test "cpu burst" {
331362
[ $EUID -ne 0 ] && requires rootless_cgroup
332363
requires cgroups_cpu_burst

0 commit comments

Comments
 (0)