blob: 601ec22a8a96818731858381ce219517ae01b894 [file] [log] [blame]
Adrian Villin4677d922024-06-14 09:32:39 +02001package hst
Maros Ondrejickadb823ed2022-12-14 16:30:04 +01002
Adrian Villincee15aa2024-03-14 11:42:55 -04003import (
4 "fmt"
5 "reflect"
6 "runtime"
7 "strings"
Adrian Villincee15aa2024-03-14 11:42:55 -04008
9 . "github.com/onsi/ginkgo/v2"
10)
11
adrianvillin28bd8f02024-02-13 06:00:02 -050012// These correspond to names used in yaml config
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010013const (
Adrian Villin4677d922024-06-14 09:32:39 +020014 ClientInterface = "hclnvpp"
15 ServerInterface = "hsrvvpp"
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010016)
17
Adrian Villin681ff3a2024-06-07 06:45:48 -040018var nsTests = map[string][]func(s *NsSuite){}
19var nsSoloTests = map[string][]func(s *NsSuite){}
Adrian Villincee15aa2024-03-14 11:42:55 -040020
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010021type NsSuite struct {
22 HstSuite
23}
24
Adrian Villin4677d922024-06-14 09:32:39 +020025func RegisterNsTests(tests ...func(s *NsSuite)) {
Adrian Villin681ff3a2024-06-07 06:45:48 -040026 nsTests[getTestFilename()] = tests
Adrian Villincee15aa2024-03-14 11:42:55 -040027}
Adrian Villin4677d922024-06-14 09:32:39 +020028func RegisterNsSoloTests(tests ...func(s *NsSuite)) {
Adrian Villin681ff3a2024-06-07 06:45:48 -040029 nsSoloTests[getTestFilename()] = tests
Adrian Villincee15aa2024-03-14 11:42:55 -040030}
31
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010032func (s *NsSuite) SetupSuite() {
Filip Tehlar608d0062023-04-28 10:29:47 +020033 s.HstSuite.SetupSuite()
Adrian Villin4677d922024-06-14 09:32:39 +020034 s.ConfigureNetworkTopology("ns")
35 s.LoadContainerTopology("ns")
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010036}
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010037
38func (s *NsSuite) SetupTest() {
Filip Tehlar608d0062023-04-28 10:29:47 +020039 s.HstSuite.SetupTest()
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010040
41 // Setup test conditions
Filip Tehlar608d0062023-04-28 10:29:47 +020042 var sessionConfig Stanza
43 sessionConfig.
Adrian Villin4677d922024-06-14 09:32:39 +020044 NewStanza("session").
45 Append("enable").
46 Append("use-app-socket-api").
47 Append("evt_qs_memfd_seg").
Adrian Villin1fde9992024-06-24 08:14:05 -040048 Append("event-queue-length 100000")
49
50 if strings.Contains(CurrentSpecReport().LeafNodeText, "InterruptMode") {
51 sessionConfig.Append("use-private-rx-mqs").Close()
52 } else {
53 sessionConfig.Close()
54 }
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010055
Adrian Villin4677d922024-06-14 09:32:39 +020056 container := s.GetContainerByName("vpp")
57 vpp, _ := container.newVppInstance(container.AllocatedCpus, sessionConfig)
58 s.AssertNil(vpp.Start())
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010059
Adrian Villin4677d922024-06-14 09:32:39 +020060 idx, err := vpp.createAfPacket(s.GetInterfaceByName(ServerInterface))
61 s.AssertNil(err, fmt.Sprint(err))
62 s.AssertNotEqual(0, idx)
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010063
Adrian Villin4677d922024-06-14 09:32:39 +020064 idx, err = vpp.createAfPacket(s.GetInterfaceByName(ClientInterface))
65 s.AssertNil(err, fmt.Sprint(err))
66 s.AssertNotEqual(0, idx)
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010067
Adrian Villin4677d922024-06-14 09:32:39 +020068 container.Exec("chmod 777 -R %s", container.GetContainerWorkDir())
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010069}
Adrian Villincee15aa2024-03-14 11:42:55 -040070
71var _ = Describe("NsSuite", Ordered, ContinueOnFailure, func() {
72 var s NsSuite
73 BeforeAll(func() {
74 s.SetupSuite()
75 })
76 BeforeEach(func() {
77 s.SetupTest()
78 })
79 AfterAll(func() {
80 s.TearDownSuite()
81 })
82 AfterEach(func() {
83 s.TearDownTest()
84 })
85
Adrian Villin681ff3a2024-06-07 06:45:48 -040086 for filename, tests := range nsTests {
87 for _, test := range tests {
88 test := test
89 pc := reflect.ValueOf(test).Pointer()
90 funcValue := runtime.FuncForPC(pc)
91 testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
92 It(testName, func(ctx SpecContext) {
Adrian Villin4677d922024-06-14 09:32:39 +020093 s.Log(testName + ": BEGIN")
Adrian Villin681ff3a2024-06-07 06:45:48 -040094 test(&s)
Adrian Villin4677d922024-06-14 09:32:39 +020095 }, SpecTimeout(SuiteTimeout))
Adrian Villin681ff3a2024-06-07 06:45:48 -040096 }
Adrian Villincee15aa2024-03-14 11:42:55 -040097 }
98})
99
100var _ = Describe("NsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
101 var s NsSuite
102 BeforeAll(func() {
103 s.SetupSuite()
104 })
105 BeforeEach(func() {
106 s.SetupTest()
107 })
108 AfterAll(func() {
109 s.TearDownSuite()
110 })
111 AfterEach(func() {
112 s.TearDownTest()
113 })
114
Adrian Villin681ff3a2024-06-07 06:45:48 -0400115 for filename, tests := range nsSoloTests {
116 for _, test := range tests {
117 test := test
118 pc := reflect.ValueOf(test).Pointer()
119 funcValue := runtime.FuncForPC(pc)
120 testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
121 It(testName, Label("SOLO"), func(ctx SpecContext) {
Adrian Villin4677d922024-06-14 09:32:39 +0200122 s.Log(testName + ": BEGIN")
Adrian Villin681ff3a2024-06-07 06:45:48 -0400123 test(&s)
Adrian Villin4677d922024-06-14 09:32:39 +0200124 }, SpecTimeout(SuiteTimeout))
Adrian Villin681ff3a2024-06-07 06:45:48 -0400125 }
Adrian Villincee15aa2024-03-14 11:42:55 -0400126 }
127})