blob: 86d9b78a0107081e555273a3e6cdc6f667843c5d [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"
8 "time"
9
10 . "github.com/onsi/ginkgo/v2"
11)
12
adrianvillin28bd8f02024-02-13 06:00:02 -050013// These correspond to names used in yaml config
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010014const (
adrianvillinfbf5f2b2024-02-13 03:26:25 -050015 clientInterface = "hclnvpp"
16 serverInterface = "hsrvvpp"
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010017)
18
Adrian Villincee15aa2024-03-14 11:42:55 -040019var nsTests = []func(s *NsSuite){}
20var nsSoloTests = []func(s *NsSuite){}
21
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010022type NsSuite struct {
23 HstSuite
24}
25
Adrian Villincee15aa2024-03-14 11:42:55 -040026func registerNsTests(tests ...func(s *NsSuite)) {
27 nsTests = append(nsTests, tests...)
28}
29func registerNsSoloTests(tests ...func(s *NsSuite)) {
30 nsSoloTests = append(nsSoloTests, tests...)
31}
32
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010033func (s *NsSuite) SetupSuite() {
Filip Tehlar608d0062023-04-28 10:29:47 +020034 s.HstSuite.SetupSuite()
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010035 s.configureNetworkTopology("ns")
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010036 s.loadContainerTopology("ns")
37}
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010038
39func (s *NsSuite) SetupTest() {
Filip Tehlar608d0062023-04-28 10:29:47 +020040 s.HstSuite.SetupTest()
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010041
42 // Setup test conditions
Filip Tehlar608d0062023-04-28 10:29:47 +020043 var sessionConfig Stanza
44 sessionConfig.
Maros Ondrejickae7625d02023-02-28 16:55:01 +010045 newStanza("session").
46 append("enable").
47 append("use-app-socket-api").
48 append("evt_qs_memfd_seg").
49 append("event-queue-length 100000").close()
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010050
Filip Tehlar608d0062023-04-28 10:29:47 +020051 cpus := s.AllocateCpus()
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010052 container := s.getContainerByName("vpp")
Filip Tehlar608d0062023-04-28 10:29:47 +020053 vpp, _ := container.newVppInstance(cpus, sessionConfig)
Filip Tehlar56e17cf2024-01-11 17:17:33 +010054 s.assertNil(vpp.start())
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010055
adrianvillin28bd8f02024-02-13 06:00:02 -050056 idx, err := vpp.createAfPacket(s.getInterfaceByName(serverInterface))
Adrian Villincee15aa2024-03-14 11:42:55 -040057 s.assertNil(err, fmt.Sprint(err))
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010058 s.assertNotEqual(0, idx)
59
adrianvillin28bd8f02024-02-13 06:00:02 -050060 idx, err = vpp.createAfPacket(s.getInterfaceByName(clientInterface))
Adrian Villincee15aa2024-03-14 11:42:55 -040061 s.assertNil(err, fmt.Sprint(err))
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010062 s.assertNotEqual(0, idx)
63
Maros Ondrejickae7625d02023-02-28 16:55:01 +010064 container.exec("chmod 777 -R %s", container.getContainerWorkDir())
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010065}
Adrian Villincee15aa2024-03-14 11:42:55 -040066
67var _ = Describe("NsSuite", Ordered, ContinueOnFailure, func() {
68 var s NsSuite
69 BeforeAll(func() {
70 s.SetupSuite()
71 })
72 BeforeEach(func() {
73 s.SetupTest()
74 })
75 AfterAll(func() {
76 s.TearDownSuite()
77 })
78 AfterEach(func() {
79 s.TearDownTest()
80 })
81
82 for _, test := range nsTests {
83 test := test
84 pc := reflect.ValueOf(test).Pointer()
85 funcValue := runtime.FuncForPC(pc)
86 It(strings.Split(funcValue.Name(), ".")[2], func(ctx SpecContext) {
87 test(&s)
88 }, SpecTimeout(time.Minute*5))
89 }
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)
111 It(strings.Split(funcValue.Name(), ".")[2], Label("SOLO"), func(ctx SpecContext) {
112 test(&s)
113 }, SpecTimeout(time.Minute*5))
114 }
115})