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