blob: 7bdb90b42aee342bdd07fe1de661462787e04e10 [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 Villincee15aa2024-03-14 11:42:55 -040018var nsTests = []func(s *NsSuite){}
19var nsSoloTests = []func(s *NsSuite){}
20
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)) {
26 nsTests = append(nsTests, tests...)
27}
28func registerNsSoloTests(tests ...func(s *NsSuite)) {
29 nsSoloTests = append(nsSoloTests, tests...)
30}
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
80 for _, test := range nsTests {
81 test := test
82 pc := reflect.ValueOf(test).Pointer()
83 funcValue := runtime.FuncForPC(pc)
Adrian Villin637edda2024-05-06 06:55:34 -040084 testName := strings.Split(funcValue.Name(), ".")[2]
85 It(testName, func(ctx SpecContext) {
86 s.log(testName + ": BEGIN")
Adrian Villincee15aa2024-03-14 11:42:55 -040087 test(&s)
Adrian Villin93974e22024-05-30 06:10:59 -040088 }, SpecTimeout(suiteTimeout))
Adrian Villincee15aa2024-03-14 11:42:55 -040089 }
90})
91
92var _ = Describe("NsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
93 var s NsSuite
94 BeforeAll(func() {
95 s.SetupSuite()
96 })
97 BeforeEach(func() {
98 s.SetupTest()
99 })
100 AfterAll(func() {
101 s.TearDownSuite()
102 })
103 AfterEach(func() {
104 s.TearDownTest()
105 })
106
107 for _, test := range nsSoloTests {
108 test := test
109 pc := reflect.ValueOf(test).Pointer()
110 funcValue := runtime.FuncForPC(pc)
Adrian Villin637edda2024-05-06 06:55:34 -0400111 testName := strings.Split(funcValue.Name(), ".")[2]
112 It(testName, Label("SOLO"), func(ctx SpecContext) {
113 s.log(testName + ": BEGIN")
Adrian Villincee15aa2024-03-14 11:42:55 -0400114 test(&s)
Adrian Villin93974e22024-05-30 06:10:59 -0400115 }, SpecTimeout(suiteTimeout))
Adrian Villincee15aa2024-03-14 11:42:55 -0400116 }
117})