Skip to content

Commit

Permalink
integration/docker: fix CPU hotplug test
Browse files Browse the repository at this point in the history
ensure `nproc` is executed until the last vCPU has been connected

fixes kata-containers#250

Signed-off-by: Julio Montes <[email protected]>
  • Loading branch information
Julio Montes committed Apr 20, 2018
1 parent 71a9af5 commit 521e441
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions integration/docker/cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,18 @@ var _ = Describe("Hot plug CPUs", func() {
id string
vCPUs int
defaultVCPUs = getDefaultVCPUs()
cpuSysPath string
waitTime int
maxTries int
checkCpusCmd string
)

BeforeEach(func() {
id = RandID(30)
cpuSysPath = "/sys/devices/system/cpu"
checkCpusCmd = `c=0; while [[ "$(cat %s/cpu%d/online 2> /dev/null)" != "1" ]] && [[ $c < %d ]]; do sleep %d; ((c++)); done; nproc --all`
waitTime = 5
maxTries = 5
args = []string{"--rm", "--name", id}
Expect(defaultVCPUs).To(BeNumerically(">", 0))
})
Expand All @@ -79,16 +87,17 @@ var _ = Describe("Hot plug CPUs", func() {

DescribeTable("container with CPU period and quota",
func(quota, period int, fail bool) {
vCPUs = ((quota + period - 1) / period) + defaultVCPUs
args = append(args, "--cpu-quota", fmt.Sprintf("%d", quota),
"--cpu-period", fmt.Sprintf("%d", period), Image, "sh", "-c", "sleep 5; nproc")
vCPUs = (quota + period - 1) / period
"--cpu-period", fmt.Sprintf("%d", period), Image, "sh", "-c",
fmt.Sprintf(checkCpusCmd, cpuSysPath, vCPUs-1, maxTries, waitTime))
stdout, _, exitCode := dockerRun(args...)
if fail {
Expect(exitCode).ToNot(BeZero())
return
}
Expect(exitCode).To(BeZero())
Expect(fmt.Sprintf("%d", vCPUs+defaultVCPUs)).To(Equal(strings.Trim(stdout, "\n\t ")))
Expect(fmt.Sprintf("%d", vCPUs)).To(Equal(strings.Trim(stdout, "\n\t ")))
},
withCPUPeriodAndQuota(30000, 20000, defaultVCPUs, false),
withCPUPeriodAndQuota(30000, 10000, defaultVCPUs, false),
Expand All @@ -98,7 +107,8 @@ var _ = Describe("Hot plug CPUs", func() {

DescribeTable("container with CPU constraint",
func(cpus int, fail bool) {
args = append(args, "--cpus", fmt.Sprintf("%d", cpus), Image, "sh", "-c", "sleep 5; nproc")
args = append(args, "--cpus", fmt.Sprintf("%d", cpus), Image, "sh", "-c",
fmt.Sprintf(checkCpusCmd, cpuSysPath, vCPUs-1, maxTries, waitTime))
stdout, _, exitCode := dockerRun(args...)
if fail {
Expect(exitCode).ToNot(BeZero())
Expand Down

0 comments on commit 521e441

Please sign in to comment.