blob: b4fa77180415f26eba5ed71877274cc53da32e49 [file] [log] [blame]
Maros Ondrejickadb823ed2022-12-14 16:30:04 +01001package main
2
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 (
adrianvillinfbf5f2b2024-02-13 03:26:25 -050014 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 Villincee15aa2024-03-14 11:42:55 -040025func registerNsTests(tests ...func(s *NsSuite)) {
Adrian Villin681ff3a2024-06-07 06:45:48 -040026 nsTests[getTestFilename()] = tests
Adrian Villincee15aa2024-03-14 11:42:55 -040027}
28func 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()
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010034 s.configureNetworkTopology("ns")
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010035 s.loadContainerTopology("ns")
36}
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.
Maros Ondrejickae7625d02023-02-28 16:55:01 +010044 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
50 container := s.getContainerByName("vpp")
Adrian Villinb9464cd2024-05-27 09:52:59 -040051 vpp, _ := container.newVppInstance(container.allocatedCpus, sessionConfig)
Filip Tehlar56e17cf2024-01-11 17:17:33 +010052 s.assertNil(vpp.start())
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010053
adrianvillin28bd8f02024-02-13 06:00:02 -050054 idx, err := vpp.createAfPacket(s.getInterfaceByName(serverInterface))
Adrian Villincee15aa2024-03-14 11:42:55 -040055 s.assertNil(err, fmt.Sprint(err))
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010056 s.assertNotEqual(0, idx)
57
adrianvillin28bd8f02024-02-13 06:00:02 -050058 idx, err = vpp.createAfPacket(s.getInterfaceByName(clientInterface))
Adrian Villincee15aa2024-03-14 11:42:55 -040059 s.assertNil(err, fmt.Sprint(err))
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010060 s.assertNotEqual(0, idx)
61
Maros Ondrejickae7625d02023-02-28 16:55:01 +010062 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) {
87 s.log(testName + ": BEGIN")
88 test(&s)
89 }, SpecTimeout(suiteTimeout))
90 }
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) {
116 s.log(testName + ": BEGIN")
117 test(&s)
118 }, SpecTimeout(suiteTimeout))
119 }
Adrian Villincee15aa2024-03-14 11:42:55 -0400120 }
121})