blob: d88730b1c0bfbc5be292c3abcd159f9166d139ff [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").
48 Append("event-queue-length 100000").Close()
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010049
Adrian Villin4677d922024-06-14 09:32:39 +020050 container := s.GetContainerByName("vpp")
51 vpp, _ := container.newVppInstance(container.AllocatedCpus, sessionConfig)
52 s.AssertNil(vpp.Start())
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010053
Adrian Villin4677d922024-06-14 09:32:39 +020054 idx, err := vpp.createAfPacket(s.GetInterfaceByName(ServerInterface))
55 s.AssertNil(err, fmt.Sprint(err))
56 s.AssertNotEqual(0, idx)
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010057
Adrian Villin4677d922024-06-14 09:32:39 +020058 idx, err = vpp.createAfPacket(s.GetInterfaceByName(ClientInterface))
59 s.AssertNil(err, fmt.Sprint(err))
60 s.AssertNotEqual(0, idx)
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010061
Adrian Villin4677d922024-06-14 09:32:39 +020062 container.Exec("chmod 777 -R %s", container.GetContainerWorkDir())
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010063}
Adrian Villincee15aa2024-03-14 11:42:55 -040064
65var _ = Describe("NsSuite", Ordered, ContinueOnFailure, func() {
66 var s NsSuite
67 BeforeAll(func() {
68 s.SetupSuite()
69 })
70 BeforeEach(func() {
71 s.SetupTest()
72 })
73 AfterAll(func() {
74 s.TearDownSuite()
75 })
76 AfterEach(func() {
77 s.TearDownTest()
78 })
79
Adrian Villin681ff3a2024-06-07 06:45:48 -040080 for filename, tests := range nsTests {
81 for _, test := range tests {
82 test := test
83 pc := reflect.ValueOf(test).Pointer()
84 funcValue := runtime.FuncForPC(pc)
85 testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
86 It(testName, func(ctx SpecContext) {
Adrian Villin4677d922024-06-14 09:32:39 +020087 s.Log(testName + ": BEGIN")
Adrian Villin681ff3a2024-06-07 06:45:48 -040088 test(&s)
Adrian Villin4677d922024-06-14 09:32:39 +020089 }, SpecTimeout(SuiteTimeout))
Adrian Villin681ff3a2024-06-07 06:45:48 -040090 }
Adrian Villincee15aa2024-03-14 11:42:55 -040091 }
92})
93
94var _ = Describe("NsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
95 var s NsSuite
96 BeforeAll(func() {
97 s.SetupSuite()
98 })
99 BeforeEach(func() {
100 s.SetupTest()
101 })
102 AfterAll(func() {
103 s.TearDownSuite()
104 })
105 AfterEach(func() {
106 s.TearDownTest()
107 })
108
Adrian Villin681ff3a2024-06-07 06:45:48 -0400109 for filename, tests := range nsSoloTests {
110 for _, test := range tests {
111 test := test
112 pc := reflect.ValueOf(test).Pointer()
113 funcValue := runtime.FuncForPC(pc)
114 testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
115 It(testName, Label("SOLO"), func(ctx SpecContext) {
Adrian Villin4677d922024-06-14 09:32:39 +0200116 s.Log(testName + ": BEGIN")
Adrian Villin681ff3a2024-06-07 06:45:48 -0400117 test(&s)
Adrian Villin4677d922024-06-14 09:32:39 +0200118 }, SpecTimeout(SuiteTimeout))
Adrian Villin681ff3a2024-06-07 06:45:48 -0400119 }
Adrian Villincee15aa2024-03-14 11:42:55 -0400120 }
121})