From 91b626a4071bef211253a7f239e0e36605e24ce8 Mon Sep 17 00:00:00 2001 From: Matus Fabian Date: Wed, 18 Dec 2024 14:20:31 +0100 Subject: [PATCH] hs-test: fix readCpus return error otherwise hst might panic Type: test Change-Id: Ib3ec8a2113af4594f2c2fc54ae72e358bfadaef2 Signed-off-by: Matus Fabian --- extras/hs-test/infra/cpu.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/extras/hs-test/infra/cpu.go b/extras/hs-test/infra/cpu.go index 7a29eb4a9c3b..e871c60af80f 100644 --- a/extras/hs-test/infra/cpu.go +++ b/extras/hs-test/infra/cpu.go @@ -140,8 +140,11 @@ func (c *CpuAllocatorT) readCpus() error { // make c.cpus divisible by maxContainerCount * nCpus, so we don't have to check which numa will be used // and we can use offsets - count_to_remove := len(tmpCpus) % (c.maxContainerCount * *NConfiguredCpus) - c.cpus = append(c.cpus, tmpCpus[:len(tmpCpus)-count_to_remove]...) + countToRemove := len(tmpCpus) % (c.maxContainerCount * *NConfiguredCpus) + if countToRemove >= len(tmpCpus) { + return fmt.Errorf("requested too much CPUs per container (%d) should be no more than %d", *NConfiguredCpus, len(tmpCpus)/c.maxContainerCount) + } + c.cpus = append(c.cpus, tmpCpus[:len(tmpCpus)-countToRemove]...) tmpCpus = tmpCpus[:0] } } else {