mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-12 09:46:25 +08:00
db3159c9d9
Add support for the pids cgroup controller to libcontainer, a recent feature that is available in Linux 4.3+. Unfortunately, due to the init process being written in Go, it can spawn an an unknown number of threads due to blocked syscalls. This results in the init process being unable to run properly, and thus small pids.max configs won't work properly. Signed-off-by: Aleksa Sarai <asarai@suse.com>
84 lines
1.8 KiB
Go
84 lines
1.8 KiB
Go
// +build linux
|
|
|
|
package fs
|
|
|
|
import (
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
|
)
|
|
|
|
const (
|
|
maxUnlimited = -1
|
|
maxLimited = 1024
|
|
)
|
|
|
|
func TestPidsSetMax(t *testing.T) {
|
|
helper := NewCgroupTestUtil("pids", t)
|
|
defer helper.cleanup()
|
|
|
|
helper.writeFileContents(map[string]string{
|
|
"pids.max": "max",
|
|
})
|
|
|
|
helper.CgroupData.config.Resources.PidsLimit = maxLimited
|
|
pids := &PidsGroup{}
|
|
if err := pids.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
value, err := getCgroupParamUint(helper.CgroupPath, "pids.max")
|
|
if err != nil {
|
|
t.Fatalf("Failed to parse pids.max - %s", err)
|
|
}
|
|
|
|
if value != maxLimited {
|
|
t.Fatalf("Expected %d, got %d for setting pids.max - limited", maxLimited, value)
|
|
}
|
|
}
|
|
|
|
func TestPidsSetUnlimited(t *testing.T) {
|
|
helper := NewCgroupTestUtil("pids", t)
|
|
defer helper.cleanup()
|
|
|
|
helper.writeFileContents(map[string]string{
|
|
"pids.max": strconv.Itoa(maxLimited),
|
|
})
|
|
|
|
helper.CgroupData.config.Resources.PidsLimit = maxUnlimited
|
|
pids := &PidsGroup{}
|
|
if err := pids.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
value, err := getCgroupParamString(helper.CgroupPath, "pids.max")
|
|
if err != nil {
|
|
t.Fatalf("Failed to parse pids.max - %s", err)
|
|
}
|
|
|
|
if value != "max" {
|
|
t.Fatalf("Expected %s, got %s for setting pids.max - unlimited", "max", value)
|
|
}
|
|
}
|
|
|
|
func TestPidsStats(t *testing.T) {
|
|
helper := NewCgroupTestUtil("pids", t)
|
|
defer helper.cleanup()
|
|
|
|
helper.writeFileContents(map[string]string{
|
|
"pids.current": strconv.Itoa(1337),
|
|
"pids.max": strconv.Itoa(maxLimited),
|
|
})
|
|
|
|
pids := &PidsGroup{}
|
|
stats := *cgroups.NewStats()
|
|
if err := pids.GetStats(helper.CgroupPath, &stats); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if stats.PidsStats.Current != 1337 {
|
|
t.Fatalf("Expected %d, got %d for pids.current", 1337, stats.PidsStats.Current)
|
|
}
|
|
}
|