Hadi Rayan Al-Sandid | e0e8513 | 2024-06-24 10:28:58 +0200 | [diff] [blame^] | 1 | package hst |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | . "github.com/onsi/ginkgo/v2" |
| 6 | "reflect" |
| 7 | "runtime" |
| 8 | "strings" |
| 9 | ) |
| 10 | |
| 11 | var cpuPinningTests = map[string][]func(s *CpuPinningSuite){} |
| 12 | var cpuPinningSoloTests = map[string][]func(s *CpuPinningSuite){} |
| 13 | |
| 14 | type CpuPinningSuite struct { |
| 15 | HstSuite |
| 16 | } |
| 17 | |
| 18 | func RegisterCpuPinningTests(tests ...func(s *CpuPinningSuite)) { |
| 19 | cpuPinningTests[getTestFilename()] = tests |
| 20 | } |
| 21 | |
| 22 | func RegisterCpuPinningSoloTests(tests ...func(s *CpuPinningSuite)) { |
| 23 | cpuPinningSoloTests[getTestFilename()] = tests |
| 24 | } |
| 25 | |
| 26 | func (s *CpuPinningSuite) SetupSuite() { |
| 27 | s.HstSuite.SetupSuite() |
| 28 | s.LoadNetworkTopology("tap") |
| 29 | s.LoadContainerTopology("singleCpuPinning") |
| 30 | } |
| 31 | |
| 32 | func (s *CpuPinningSuite) SetupTest() { |
| 33 | // Skip if we cannot allocate 3 CPUs for test container |
| 34 | s.SkipIfNotEnoughAvailableCpus(1, 3) |
| 35 | s.CpuPerVpp = 3 |
| 36 | s.HstSuite.SetupTest() |
| 37 | container := s.GetContainerByName(SingleTopoContainerVpp) |
| 38 | vpp, err := container.newVppInstance(container.AllocatedCpus) |
| 39 | s.AssertNotNil(vpp, fmt.Sprint(err)) |
| 40 | |
| 41 | } |
| 42 | |
| 43 | var _ = Describe("CpuPinningSuite", Ordered, ContinueOnFailure, func() { |
| 44 | var s CpuPinningSuite |
| 45 | BeforeAll(func() { |
| 46 | s.SetupSuite() |
| 47 | }) |
| 48 | BeforeEach(func() { |
| 49 | s.SetupTest() |
| 50 | }) |
| 51 | AfterAll(func() { |
| 52 | s.TearDownSuite() |
| 53 | |
| 54 | }) |
| 55 | AfterEach(func() { |
| 56 | s.TearDownTest() |
| 57 | }) |
| 58 | |
| 59 | // https://onsi.github.io/ginkgo/#dynamically-generating-specs |
| 60 | for filename, tests := range cpuPinningTests { |
| 61 | for _, test := range tests { |
| 62 | test := test |
| 63 | pc := reflect.ValueOf(test).Pointer() |
| 64 | funcValue := runtime.FuncForPC(pc) |
| 65 | testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] |
| 66 | It(testName, func(ctx SpecContext) { |
| 67 | s.Log(testName + ": BEGIN") |
| 68 | test(&s) |
| 69 | }, SpecTimeout(SuiteTimeout)) |
| 70 | } |
| 71 | } |
| 72 | }) |
| 73 | |
| 74 | var _ = Describe("CpuPinningSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { |
| 75 | var s CpuPinningSuite |
| 76 | BeforeAll(func() { |
| 77 | s.SetupSuite() |
| 78 | }) |
| 79 | BeforeEach(func() { |
| 80 | s.SetupTest() |
| 81 | }) |
| 82 | AfterAll(func() { |
| 83 | s.TearDownSuite() |
| 84 | }) |
| 85 | AfterEach(func() { |
| 86 | s.TearDownTest() |
| 87 | }) |
| 88 | |
| 89 | for filename, tests := range cpuPinningSoloTests { |
| 90 | for _, test := range tests { |
| 91 | test := test |
| 92 | pc := reflect.ValueOf(test).Pointer() |
| 93 | funcValue := runtime.FuncForPC(pc) |
| 94 | testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] |
| 95 | It(testName, Label("SOLO"), func(ctx SpecContext) { |
| 96 | s.Log(testName + ": BEGIN") |
| 97 | test(&s) |
| 98 | }, SpecTimeout(SuiteTimeout)) |
| 99 | } |
| 100 | } |
| 101 | }) |