1
0
mirror of https://github.com/moby/moby.git synced 2025-12-06 07:41:18 +03:00

Add some missing cgroup test require and refactor the require check.

Signed-off-by: Lei Jitang <leijitang@huawei.com>
This commit is contained in:
Lei Jitang
2015-08-24 11:37:11 +08:00
parent 7ead74d903
commit c340ca4f5d
3 changed files with 133 additions and 114 deletions

View File

@@ -293,6 +293,60 @@ func (s *DockerSuite) TestRunWithKernelMemory(c *check.C) {
}
}
// "test" should be printed
func (s *DockerSuite) TestRunEchoStdoutWitCPUShares(c *check.C) {
testRequires(c, cpuShare)
out, _ := dockerCmd(c, "run", "-c", "1000", "busybox", "echo", "test")
if out != "test\n" {
c.Errorf("container should've printed 'test'")
}
}
// "test" should be printed
func (s *DockerSuite) TestRunEchoStdoutWithCPUSharesAndMemoryLimit(c *check.C) {
testRequires(c, cpuShare)
testRequires(c, memoryLimitSupport)
out, _, _ := dockerCmdWithStdoutStderr(c, "run", "-c", "1000", "-m", "16m", "busybox", "echo", "test")
if out != "test\n" {
c.Errorf("container should've printed 'test', got %q instead", out)
}
}
func (s *DockerSuite) TestRunWithCpuset(c *check.C) {
testRequires(c, cgroupCpuset)
if _, code := dockerCmd(c, "run", "--cpuset", "0", "busybox", "true"); code != 0 {
c.Fatalf("container should run successfully with cpuset of 0")
}
}
func (s *DockerSuite) TestRunWithCpusetCpus(c *check.C) {
testRequires(c, cgroupCpuset)
if _, code := dockerCmd(c, "run", "--cpuset-cpus", "0", "busybox", "true"); code != 0 {
c.Fatalf("container should run successfully with cpuset-cpus of 0")
}
}
func (s *DockerSuite) TestRunWithCpusetMems(c *check.C) {
testRequires(c, cgroupCpuset)
if _, code := dockerCmd(c, "run", "--cpuset-mems", "0", "busybox", "true"); code != 0 {
c.Fatalf("container should run successfully with cpuset-mems of 0")
}
}
func (s *DockerSuite) TestRunWithBlkioWeight(c *check.C) {
testRequires(c, blkioWeight)
if _, code := dockerCmd(c, "run", "--blkio-weight", "300", "busybox", "true"); code != 0 {
c.Fatalf("container should run successfully with blkio-weight of 300")
}
}
func (s *DockerSuite) TestRunWithBlkioInvalidWeight(c *check.C) {
testRequires(c, blkioWeight)
if _, _, err := dockerCmdWithError("run", "--blkio-weight", "5", "busybox", "true"); err == nil {
c.Fatalf("run with invalid blkio-weight should failed")
}
}
func (s *DockerSuite) TestRunOOMExitCode(c *check.C) {
testRequires(c, oomControl)
errChan := make(chan error)
@@ -424,3 +478,35 @@ func (s *DockerSuite) TestTwoContainersInNetHost(c *check.C) {
dockerCmd(c, "stop", "first")
dockerCmd(c, "stop", "second")
}
// "test" should be printed
func (s *DockerSuite) TestRunEchoStdoutWithMemoryLimit(c *check.C) {
testRequires(c, memoryLimitSupport)
out, _, _ := dockerCmdWithStdoutStderr(c, "run", "-m", "16m", "busybox", "echo", "test")
out = strings.Trim(out, "\r\n")
if expected := "test"; out != expected {
c.Fatalf("container should've printed %q but printed %q", expected, out)
}
}
// should run without memory swap
func (s *DockerSuite) TestRunWithoutMemoryswapLimit(c *check.C) {
testRequires(c, NativeExecDriver)
testRequires(c, memoryLimitSupport)
testRequires(c, swapMemorySupport)
dockerCmd(c, "run", "-m", "16m", "--memory-swap", "-1", "busybox", "true")
}
func (s *DockerSuite) TestRunWithSwappiness(c *check.C) {
testRequires(c, memorySwappinessSupport)
dockerCmd(c, "run", "--memory-swappiness", "0", "busybox", "true")
}
func (s *DockerSuite) TestRunWithSwappinessInvalid(c *check.C) {
testRequires(c, memorySwappinessSupport)
out, _, err := dockerCmdWithError("run", "--memory-swappiness", "101", "busybox", "true")
if err == nil {
c.Fatalf("failed. test was able to set invalid value, output: %q", out)
}
}