blob: 629d2dac3edfbf67006d4ce67e1d3f9b6a613093 [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
16}
17
18func RegisterCpuPinningTests(tests ...func(s *CpuPinningSuite)) {
19 cpuPinningTests[getTestFilename()] = tests
20}
21
22func RegisterCpuPinningSoloTests(tests ...func(s *CpuPinningSuite)) {
23 cpuPinningSoloTests[getTestFilename()] = tests
24}
25
26func (s *CpuPinningSuite) SetupSuite() {
27 s.HstSuite.SetupSuite()
28 s.LoadNetworkTopology("tap")
29 s.LoadContainerTopology("singleCpuPinning")
30}
31
32func (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
43var _ = 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
74var _ = 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})