"fmt"
"os"
"os/exec"
- "strconv"
"strings"
. "github.com/onsi/ginkgo/v2"
type CpuAllocatorT struct {
cpus []int
- runningInCi bool
- buildNumber int
maxContainerCount int
}
// indexes, not actual cores
var minCpu, maxCpu int
- if c.runningInCi {
- minCpu = ((c.buildNumber) * c.maxContainerCount * nCpus) + offset
- maxCpu = ((c.buildNumber + 1) * c.maxContainerCount * nCpus) - 1 + offset
- } else {
- minCpu = ((GinkgoParallelProcess() - 1) * c.maxContainerCount * nCpus) + offset
- maxCpu = (GinkgoParallelProcess() * c.maxContainerCount * nCpus) - 1 + offset
- }
+ minCpu = ((GinkgoParallelProcess() - 1) * c.maxContainerCount * nCpus) + offset
+ maxCpu = (GinkgoParallelProcess() * c.maxContainerCount * nCpus) - 1 + offset
if len(c.cpus)-1 < maxCpu {
err := fmt.Errorf("could not allocate %d CPUs; available count: %d; attempted to allocate cores with index %d-%d; max index: %d;\n"+
}
func (c *CpuAllocatorT) readCpus() error {
- var first, second, third, fourth int
- var file *os.File
- var err error
-
- if c.runningInCi {
- // non-debug build runs on node0, debug on node1
- if *IsDebugBuild {
- file, err = os.Open("/sys/devices/system/node/node1/cpulist")
- } else {
- file, err = os.Open("/sys/devices/system/node/node0/cpulist")
- }
- if err != nil {
- return err
- }
- defer file.Close()
-
- sc := bufio.NewScanner(file)
- sc.Scan()
- line := sc.Text()
- _, err = fmt.Sscanf(line, "%d-%d,%d-%d", &first, &second, &third, &fourth)
- if err != nil {
- return err
- }
+ var first, second int
- c.cpus = iterateAndAppend(first, second, c.cpus)
- c.cpus = iterateAndAppend(third, fourth, c.cpus)
- } else if NumaAwareCpuAlloc {
+ if NumaAwareCpuAlloc {
var range1, range2 int
var tmpCpus []int
line := sc.Text()
for _, coreRange := range strings.Split(line, ",") {
- if strings.IndexRune(coreRange, '-') != -1 {
+ if strings.ContainsRune(coreRange, '-') {
_, err = fmt.Sscanf(coreRange, "%d-%d", &range1, &range2)
if err != nil {
return err
// and we can use offsets
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)
+ return fmt.Errorf("requested too many 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]
var err error
cpuAllocator = new(CpuAllocatorT)
cpuAllocator.maxContainerCount = 4
- buildNumberStr := os.Getenv("BUILD_NUMBER")
-
- if buildNumberStr != "" {
- cpuAllocator.runningInCi = true
- // get last digit of build number
- cpuAllocator.buildNumber, err = strconv.Atoi(buildNumberStr[len(buildNumberStr)-1:])
- if err != nil {
- return nil, err
- }
- }
err = cpuAllocator.readCpus()
if err != nil {
return nil, err
var DryRun = flag.Bool("dryrun", false, "set up containers but don't run tests")
var NumaAwareCpuAlloc bool
var TestTimeout time.Duration
+var RunningInCi bool
type HstSuite struct {
AllContainers map[string]*Container
availableCpus++
}
- if s.CpuAllocator.runningInCi {
- maxRequestedCpu = ((s.CpuAllocator.buildNumber + 1) * s.CpuAllocator.maxContainerCount * s.CpuCount)
- } else {
- maxRequestedCpu = (GinkgoParallelProcess() * s.CpuAllocator.maxContainerCount * s.CpuCount)
- }
+ maxRequestedCpu = (GinkgoParallelProcess() * s.CpuAllocator.maxContainerCount * s.CpuCount)
if availableCpus < maxRequestedCpu {
s.Skip(fmt.Sprintf("Test case cannot allocate requested cpus "+
output, _ := exechelper.Output(cmd)
AddReportEntry("VPP Backtrace", StringerStruct{Label: string(output)})
os.WriteFile(s.getLogDirPath()+"backtrace.log", output, os.FileMode(0644))
- if s.CpuAllocator.runningInCi {
+ if RunningInCi {
err = os.Remove(corePath)
if err == nil {
s.Log("removed " + corePath)