blob: 5f53f55f1bb84fc908c0461edc2354ac0369c22b [file] [log] [blame]
Adrian Villin4677d922024-06-14 09:32:39 +02001package hst
Filip Tehlarc204c872022-12-21 08:59:16 +01002
Adrian Villincee15aa2024-03-14 11:42:55 -04003import (
4 "reflect"
5 "runtime"
6 "strings"
Adrian Villincee15aa2024-03-14 11:42:55 -04007
8 . "github.com/onsi/ginkgo/v2"
Maros Ondrejicka7550dd22023-02-07 20:40:27 +01009)
10
Adrian Villincee15aa2024-03-14 11:42:55 -040011const (
Adrian Villin4677d922024-06-14 09:32:39 +020012 SingleTopoContainerVpp = "vpp"
13 SingleTopoContainerNginx = "nginx"
14 TapInterfaceName = "htaphost"
Adrian Villincee15aa2024-03-14 11:42:55 -040015)
16
Adrian Villin681ff3a2024-06-07 06:45:48 -040017var noTopoTests = map[string][]func(s *NoTopoSuite){}
18var noTopoSoloTests = map[string][]func(s *NoTopoSuite){}
Adrian Villincee15aa2024-03-14 11:42:55 -040019
Filip Tehlarc204c872022-12-21 08:59:16 +010020type NoTopoSuite struct {
21 HstSuite
22}
23
Adrian Villin4677d922024-06-14 09:32:39 +020024func RegisterNoTopoTests(tests ...func(s *NoTopoSuite)) {
Adrian Villin681ff3a2024-06-07 06:45:48 -040025 noTopoTests[getTestFilename()] = tests
Adrian Villincee15aa2024-03-14 11:42:55 -040026}
Adrian Villin4677d922024-06-14 09:32:39 +020027func RegisterNoTopoSoloTests(tests ...func(s *NoTopoSuite)) {
Adrian Villin681ff3a2024-06-07 06:45:48 -040028 noTopoSoloTests[getTestFilename()] = tests
Adrian Villincee15aa2024-03-14 11:42:55 -040029}
30
Filip Tehlarc204c872022-12-21 08:59:16 +010031func (s *NoTopoSuite) SetupSuite() {
Filip Tehlar608d0062023-04-28 10:29:47 +020032 s.HstSuite.SetupSuite()
Adrian Villin4677d922024-06-14 09:32:39 +020033 s.LoadNetworkTopology("tap")
34 s.LoadContainerTopology("single")
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010035}
36
37func (s *NoTopoSuite) SetupTest() {
Filip Tehlar608d0062023-04-28 10:29:47 +020038 s.HstSuite.SetupTest()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010039
40 // Setup test conditions
Filip Tehlar608d0062023-04-28 10:29:47 +020041 var sessionConfig Stanza
42 sessionConfig.
Adrian Villin4677d922024-06-14 09:32:39 +020043 NewStanza("session").
44 Append("enable").
Adrian Villin1fde9992024-06-24 08:14:05 -040045 Append("use-app-socket-api")
46
47 if strings.Contains(CurrentSpecReport().LeafNodeText, "InterruptMode") {
48 sessionConfig.Append("use-private-rx-mqs").Close()
49 s.Log("**********************INTERRUPT MODE**********************")
50 } else {
51 sessionConfig.Close()
52 }
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010053
Adrian Villin4677d922024-06-14 09:32:39 +020054 container := s.GetContainerByName(SingleTopoContainerVpp)
55 vpp, _ := container.newVppInstance(container.AllocatedCpus, sessionConfig)
56 s.AssertNil(vpp.Start())
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010057
Adrian Villin4677d922024-06-14 09:32:39 +020058 tapInterface := s.GetInterfaceByName(TapInterfaceName)
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010059
Adrian Villin4677d922024-06-14 09:32:39 +020060 s.AssertNil(vpp.createTap(tapInterface), "failed to create tap interface")
Filip Tehlarc204c872022-12-21 08:59:16 +010061}
Adrian Villincee15aa2024-03-14 11:42:55 -040062
63var _ = Describe("NoTopoSuite", Ordered, ContinueOnFailure, func() {
64 var s NoTopoSuite
65 BeforeAll(func() {
66 s.SetupSuite()
67 })
68 BeforeEach(func() {
69 s.SetupTest()
70 })
71 AfterAll(func() {
72 s.TearDownSuite()
73 })
74 AfterEach(func() {
75 s.TearDownTest()
76 })
77
Adrian Villin681ff3a2024-06-07 06:45:48 -040078 for filename, tests := range noTopoTests {
79 for _, test := range tests {
80 test := test
81 pc := reflect.ValueOf(test).Pointer()
82 funcValue := runtime.FuncForPC(pc)
83 testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
84 It(testName, func(ctx SpecContext) {
Adrian Villin4677d922024-06-14 09:32:39 +020085 s.Log(testName + ": BEGIN")
Adrian Villin681ff3a2024-06-07 06:45:48 -040086 test(&s)
Adrian Villin4677d922024-06-14 09:32:39 +020087 }, SpecTimeout(SuiteTimeout))
Adrian Villin681ff3a2024-06-07 06:45:48 -040088 }
Adrian Villincee15aa2024-03-14 11:42:55 -040089 }
90})
91
92var _ = Describe("NoTopoSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
93 var s NoTopoSuite
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
Adrian Villin681ff3a2024-06-07 06:45:48 -0400107 for filename, tests := range noTopoSoloTests {
108 for _, test := range tests {
109 test := test
110 pc := reflect.ValueOf(test).Pointer()
111 funcValue := runtime.FuncForPC(pc)
112 testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
113 It(testName, Label("SOLO"), func(ctx SpecContext) {
Adrian Villin4677d922024-06-14 09:32:39 +0200114 s.Log(testName + ": BEGIN")
Adrian Villin681ff3a2024-06-07 06:45:48 -0400115 test(&s)
Adrian Villin4677d922024-06-14 09:32:39 +0200116 }, SpecTimeout(SuiteTimeout))
Adrian Villin681ff3a2024-06-07 06:45:48 -0400117 }
Adrian Villincee15aa2024-03-14 11:42:55 -0400118 }
119})