diff options
Diffstat (limited to 'extras/hs-test/infra')
-rw-r--r-- | extras/hs-test/infra/container.go | 5 | ||||
-rw-r--r-- | extras/hs-test/infra/cpu.go | 55 | ||||
-rw-r--r-- | extras/hs-test/infra/hst_suite.go | 9 | ||||
-rw-r--r-- | extras/hs-test/infra/suite_h2.go | 90 | ||||
-rw-r--r-- | extras/hs-test/infra/vppinstance.go | 6 |
5 files changed, 106 insertions, 59 deletions
diff --git a/extras/hs-test/infra/container.go b/extras/hs-test/infra/container.go index 918c19e669e..efc317fa96d 100644 --- a/extras/hs-test/infra/container.go +++ b/extras/hs-test/infra/container.go @@ -460,7 +460,7 @@ func (c *Container) ExecServer(useEnvVars bool, command string, arguments ...any c.Suite.AssertNil(exechelper.Run(containerExecCommand)) } -func (c *Container) Exec(useEnvVars bool, command string, arguments ...any) string { +func (c *Container) Exec(useEnvVars bool, command string, arguments ...any) (string, error) { var envVars string serverCommand := fmt.Sprintf(command, arguments...) if useEnvVars { @@ -472,8 +472,7 @@ func (c *Container) Exec(useEnvVars bool, command string, arguments ...any) stri GinkgoHelper() c.Suite.Log(containerExecCommand) byteOutput, err := exechelper.CombinedOutput(containerExecCommand) - c.Suite.AssertNil(err, fmt.Sprint(err)) - return string(byteOutput) + return string(byteOutput), err } func (c *Container) saveLogs() { diff --git a/extras/hs-test/infra/cpu.go b/extras/hs-test/infra/cpu.go index 743a4eddc67..4afc96bcee4 100644 --- a/extras/hs-test/infra/cpu.go +++ b/extras/hs-test/infra/cpu.go @@ -6,7 +6,6 @@ import ( "fmt" "os" "os/exec" - "strconv" "strings" . "github.com/onsi/ginkgo/v2" @@ -21,8 +20,6 @@ type CpuContext struct { type CpuAllocatorT struct { cpus []int - runningInCi bool - buildNumber int maxContainerCount int } @@ -40,13 +37,8 @@ func (c *CpuAllocatorT) Allocate(containerCount int, nCpus int, offset int) (*Cp // 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"+ @@ -66,33 +58,9 @@ func (c *CpuAllocatorT) Allocate(containerCount int, nCpus int, offset int) (*Cp } 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 @@ -124,7 +92,7 @@ func (c *CpuAllocatorT) readCpus() error { 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 @@ -148,7 +116,8 @@ func (c *CpuAllocatorT) readCpus() error { // 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] @@ -200,16 +169,6 @@ func CpuAllocator() (*CpuAllocatorT, error) { 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 diff --git a/extras/hs-test/infra/hst_suite.go b/extras/hs-test/infra/hst_suite.go index 5ef4883ebdb..c2dfc592ebb 100644 --- a/extras/hs-test/infra/hst_suite.go +++ b/extras/hs-test/infra/hst_suite.go @@ -46,6 +46,7 @@ var ParallelTotal = flag.Lookup("ginkgo.parallel.total") 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 @@ -443,11 +444,7 @@ func (s *HstSuite) SkipIfNotEnoughAvailableCpus() { 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 "+ @@ -516,7 +513,7 @@ func (s *HstSuite) WaitForCoreDump() bool { 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) diff --git a/extras/hs-test/infra/suite_h2.go b/extras/hs-test/infra/suite_h2.go new file mode 100644 index 00000000000..54a373e315b --- /dev/null +++ b/extras/hs-test/infra/suite_h2.go @@ -0,0 +1,90 @@ +package hst + +import ( + "reflect" + "runtime" + "strings" + + . "github.com/onsi/ginkgo/v2" +) + +var h2Tests = map[string][]func(s *H2Suite){} + +type H2Suite struct { + HstSuite + Interfaces struct { + Tap *NetInterface + } + Containers struct { + Vpp *Container + Curl *Container + } +} + +func RegisterH2Tests(tests ...func(s *H2Suite)) { + h2Tests[getTestFilename()] = tests +} + +func (s *H2Suite) SetupSuite() { + s.HstSuite.SetupSuite() + s.LoadNetworkTopology("tap") + s.LoadContainerTopology("single") + s.Interfaces.Tap = s.GetInterfaceByName("htaphost") + s.Containers.Vpp = s.GetContainerByName("vpp") + s.Containers.Curl = s.GetContainerByName("curl") +} + +func (s *H2Suite) SetupTest() { + s.HstSuite.SetupTest() + + // Setup test conditions + var sessionConfig Stanza + sessionConfig.NewStanza("session").Append("enable").Append("use-app-socket-api") + + vpp, _ := s.Containers.Vpp.newVppInstance(s.Containers.Vpp.AllocatedCpus, sessionConfig) + + s.AssertNil(vpp.Start()) + s.AssertNil(vpp.CreateTap(s.Interfaces.Tap, 1, 1), "failed to create tap interface") + + if *DryRun { + s.LogStartedContainers() + s.Skip("Dry run mode = true") + } +} + +func (s *H2Suite) TearDownTest() { + s.HstSuite.TearDownTest() +} + +func (s *H2Suite) VppAddr() string { + return s.Interfaces.Tap.Peer.Ip4AddressString() +} + +var _ = PDescribe("Http2Suite", Ordered, ContinueOnFailure, func() { + var s H2Suite + BeforeAll(func() { + s.SetupSuite() + }) + BeforeEach(func() { + s.SetupTest() + }) + AfterAll(func() { + s.TearDownSuite() + }) + AfterEach(func() { + s.TearDownTest() + }) + + for filename, tests := range h2Tests { + for _, test := range tests { + test := test + pc := reflect.ValueOf(test).Pointer() + funcValue := runtime.FuncForPC(pc) + testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] + It(testName, func(ctx SpecContext) { + s.Log(testName + ": BEGIN") + test(&s) + }, SpecTimeout(TestTimeout)) + } + } +}) diff --git a/extras/hs-test/infra/vppinstance.go b/extras/hs-test/infra/vppinstance.go index 370d2be38d1..59d17de4d20 100644 --- a/extras/hs-test/infra/vppinstance.go +++ b/extras/hs-test/infra/vppinstance.go @@ -243,9 +243,11 @@ func (vpp *VppInstance) Start() error { } func (vpp *VppInstance) Stop() { - pid := strings.TrimSpace(vpp.Container.Exec(false, "pidof vpp")) + pid, err := vpp.Container.Exec(false, "pidof vpp") + pid = strings.TrimSpace(pid) // Stop VPP only if it's still running - if len(pid) > 0 { + if err == nil { + vpp.getSuite().Log("Stopping VPP") vpp.Container.Exec(false, "bash -c \"kill -15 "+pid+"\"") } } |