diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 5e35d6e360..7be8c862c3 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -5272,6 +5272,7 @@ RUN [ "/hello" ]`, map[string]string{}) } func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) { + testRequires(c, CpuCfsQuota) name := "testbuildresourceconstraints" ctx, err := fakeContext(` diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 20e8c6ee4c..6cdb18cde0 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -88,15 +88,13 @@ func (s *DockerSuite) TestRunEchoStdoutWithCPUAndMemoryLimit(c *check.C) { // "test" should be printed func (s *DockerSuite) TestRunEchoStdoutWithCPUQuota(c *check.C) { + testRequires(c, CpuCfsQuota) runCmd := exec.Command(dockerBinary, "run", "--cpu-quota", "8000", "--name", "test", "busybox", "echo", "test") out, _, _, err := runCommandWithStdoutStderr(runCmd) if err != nil { c.Fatalf("failed to run container: %v, output: %q", err, out) } out = strings.TrimSpace(out) - if strings.Contains(out, "Your kernel does not support CPU cfs quota") { - c.Skip("Your kernel does not support CPU cfs quota, skip this test") - } if out != "test" { c.Errorf("container should've printed 'test'") } @@ -105,7 +103,7 @@ func (s *DockerSuite) TestRunEchoStdoutWithCPUQuota(c *check.C) { c.Assert(err, check.IsNil) if out != "8000" { - c.Errorf("setting the CPU CFS quota failed") + c.Fatalf("setting the CPU CFS quota failed") } } @@ -1116,20 +1114,16 @@ func (s *DockerSuite) TestRunProcWritableInPrivilegedContainers(c *check.C) { } func (s *DockerSuite) TestRunWithCpuPeriod(c *check.C) { + testRequires(c, CpuCfsPeriod) runCmd := exec.Command(dockerBinary, "run", "--cpu-period", "50000", "--name", "test", "busybox", "true") - out, _, _, err := runCommandWithStdoutStderr(runCmd) - if err != nil { - c.Fatalf("failed to run container: %v, output: %q", err, out) - } - out = strings.TrimSpace(out) - if strings.Contains(out, "Your kernel does not support CPU cfs period") { - c.Skip("Your kernel does not support CPU cfs period, skip this test") + if _, err := runCommand(runCmd); err != nil { + c.Fatalf("failed to run container: %v", err) } - out, err = inspectField("test", "HostConfig.CpuPeriod") + out, err := inspectField("test", "HostConfig.CpuPeriod") c.Assert(err, check.IsNil) if out != "50000" { - c.Errorf("setting the CPU CFS period failed") + c.Fatalf("setting the CPU CFS period failed") } } diff --git a/integration-cli/requirements.go b/integration-cli/requirements.go index fc4f5ee955..62a0acc0f1 100644 --- a/integration-cli/requirements.go +++ b/integration-cli/requirements.go @@ -7,8 +7,10 @@ import ( "log" "net/http" "os/exec" + "path" "strings" + "github.com/docker/libcontainer/cgroups" "github.com/go-check/check" ) @@ -96,6 +98,32 @@ var ( }, "Test requires underlying root filesystem not be backed by overlay.", } + CpuCfsPeriod = TestRequirement{ + func() bool { + cgroupCpuMountpoint, err := cgroups.FindCgroupMountpoint("cpu") + if err != nil { + return false + } + if _, err := ioutil.ReadFile(path.Join(cgroupCpuMountpoint, "cpu.cfs_period_us")); err != nil { + return false + } + return true + }, + "Test requires an environment that supports cgroup cfs period.", + } + CpuCfsQuota = TestRequirement{ + func() bool { + cgroupCpuMountpoint, err := cgroups.FindCgroupMountpoint("cpu") + if err != nil { + return false + } + if _, err := ioutil.ReadFile(path.Join(cgroupCpuMountpoint, "cpu.cfs_quota_us")); err != nil { + return false + } + return true + }, + "Test requires an environment that supports cgroup cfs quota.", + } ) // testRequires checks if the environment satisfies the requirements