2015-05-14 06:42:16 +08:00
|
|
|
// +build linux
|
|
|
|
|
2015-02-27 11:00:17 +08:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCpusetSetCpus(t *testing.T) {
|
|
|
|
helper := NewCgroupTestUtil("cpuset", t)
|
|
|
|
defer helper.cleanup()
|
|
|
|
|
|
|
|
const (
|
|
|
|
cpusBefore = "0"
|
|
|
|
cpusAfter = "1-3"
|
|
|
|
)
|
|
|
|
|
|
|
|
helper.writeFileContents(map[string]string{
|
|
|
|
"cpuset.cpus": cpusBefore,
|
|
|
|
})
|
|
|
|
|
2015-12-15 08:26:29 +08:00
|
|
|
helper.CgroupData.config.Resources.CpusetCpus = cpusAfter
|
2015-02-27 11:00:17 +08:00
|
|
|
cpuset := &CpusetGroup{}
|
2015-11-05 18:52:14 +08:00
|
|
|
if err := cpuset.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
|
2015-02-27 11:00:17 +08:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
value, err := getCgroupParamString(helper.CgroupPath, "cpuset.cpus")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to parse cpuset.cpus - %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if value != cpusAfter {
|
|
|
|
t.Fatal("Got the wrong value, set cpuset.cpus failed.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCpusetSetMems(t *testing.T) {
|
|
|
|
helper := NewCgroupTestUtil("cpuset", t)
|
|
|
|
defer helper.cleanup()
|
|
|
|
|
|
|
|
const (
|
|
|
|
memsBefore = "0"
|
|
|
|
memsAfter = "1"
|
|
|
|
)
|
|
|
|
|
|
|
|
helper.writeFileContents(map[string]string{
|
|
|
|
"cpuset.mems": memsBefore,
|
|
|
|
})
|
|
|
|
|
2015-12-15 08:26:29 +08:00
|
|
|
helper.CgroupData.config.Resources.CpusetMems = memsAfter
|
2015-02-27 11:00:17 +08:00
|
|
|
cpuset := &CpusetGroup{}
|
2015-11-05 18:52:14 +08:00
|
|
|
if err := cpuset.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
|
2015-02-27 11:00:17 +08:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
value, err := getCgroupParamString(helper.CgroupPath, "cpuset.mems")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to parse cpuset.mems - %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if value != memsAfter {
|
|
|
|
t.Fatal("Got the wrong value, set cpuset.mems failed.")
|
|
|
|
}
|
|
|
|
}
|