Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 1 | package hst |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 2 | |
| 3 | import ( |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 4 | "fmt" |
| 5 | "reflect" |
| 6 | "runtime" |
| 7 | "strings" |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 8 | "time" |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 9 | |
| 10 | . "github.com/onsi/ginkgo/v2" |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 11 | ) |
| 12 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 13 | // These correspond to names used in yaml config |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 14 | const ( |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 15 | ServerInterfaceName = "srv" |
| 16 | ClientInterfaceName = "cln" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 17 | ) |
| 18 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 19 | var vethTests = map[string][]func(s *VethsSuite){} |
| 20 | var vethSoloTests = map[string][]func(s *VethsSuite){} |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 21 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 22 | type VethsSuite struct { |
| 23 | HstSuite |
| 24 | } |
| 25 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 26 | func RegisterVethTests(tests ...func(s *VethsSuite)) { |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 27 | vethTests[getTestFilename()] = tests |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 28 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 29 | func RegisterSoloVethTests(tests ...func(s *VethsSuite)) { |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 30 | vethSoloTests[getTestFilename()] = tests |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 31 | } |
| 32 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 33 | func (s *VethsSuite) SetupSuite() { |
| 34 | time.Sleep(1 * time.Second) |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 35 | s.HstSuite.SetupSuite() |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 36 | s.ConfigureNetworkTopology("2peerVeth") |
| 37 | s.LoadContainerTopology("2peerVeth") |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 38 | } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 39 | |
| 40 | func (s *VethsSuite) SetupTest() { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 41 | s.HstSuite.SetupTest() |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 42 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 43 | // Setup test conditions |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 44 | var sessionConfig Stanza |
| 45 | sessionConfig. |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 46 | NewStanza("session"). |
| 47 | Append("enable"). |
| 48 | Append("use-app-socket-api").Close() |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 49 | |
| 50 | // ... For server |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 51 | serverContainer := s.GetContainerByName("server-vpp") |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 52 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 53 | serverVpp, err := serverContainer.newVppInstance(serverContainer.AllocatedCpus, sessionConfig) |
| 54 | s.AssertNotNil(serverVpp, fmt.Sprint(err)) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 55 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 56 | s.SetupServerVpp() |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 57 | |
| 58 | // ... For client |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 59 | clientContainer := s.GetContainerByName("client-vpp") |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 60 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 61 | clientVpp, err := clientContainer.newVppInstance(clientContainer.AllocatedCpus, sessionConfig) |
| 62 | s.AssertNotNil(clientVpp, fmt.Sprint(err)) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 63 | |
| 64 | s.setupClientVpp() |
| 65 | } |
| 66 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 67 | func (s *VethsSuite) SetupServerVpp() { |
| 68 | serverVpp := s.GetContainerByName("server-vpp").VppInstance |
| 69 | s.AssertNil(serverVpp.Start()) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 70 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 71 | serverVeth := s.GetInterfaceByName(ServerInterfaceName) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 72 | idx, err := serverVpp.createAfPacket(serverVeth) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 73 | s.AssertNil(err, fmt.Sprint(err)) |
| 74 | s.AssertNotEqual(0, idx) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | func (s *VethsSuite) setupClientVpp() { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 78 | clientVpp := s.GetContainerByName("client-vpp").VppInstance |
| 79 | s.AssertNil(clientVpp.Start()) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 80 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 81 | clientVeth := s.GetInterfaceByName(ClientInterfaceName) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 82 | idx, err := clientVpp.createAfPacket(clientVeth) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 83 | s.AssertNil(err, fmt.Sprint(err)) |
| 84 | s.AssertNotEqual(0, idx) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 85 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 86 | |
| 87 | var _ = Describe("VethsSuite", Ordered, ContinueOnFailure, func() { |
| 88 | var s VethsSuite |
| 89 | BeforeAll(func() { |
| 90 | s.SetupSuite() |
| 91 | }) |
| 92 | BeforeEach(func() { |
| 93 | s.SetupTest() |
| 94 | }) |
| 95 | AfterAll(func() { |
| 96 | s.TearDownSuite() |
| 97 | |
| 98 | }) |
| 99 | AfterEach(func() { |
| 100 | s.TearDownTest() |
| 101 | }) |
| 102 | |
| 103 | // https://onsi.github.io/ginkgo/#dynamically-generating-specs |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 104 | for filename, tests := range vethTests { |
| 105 | for _, test := range tests { |
| 106 | test := test |
| 107 | pc := reflect.ValueOf(test).Pointer() |
| 108 | funcValue := runtime.FuncForPC(pc) |
| 109 | testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] |
| 110 | It(testName, func(ctx SpecContext) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 111 | s.Log(testName + ": BEGIN") |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 112 | test(&s) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 113 | }, SpecTimeout(SuiteTimeout)) |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 114 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 115 | } |
| 116 | }) |
| 117 | |
| 118 | var _ = Describe("VethsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { |
| 119 | var s VethsSuite |
| 120 | BeforeAll(func() { |
| 121 | s.SetupSuite() |
| 122 | }) |
| 123 | BeforeEach(func() { |
| 124 | s.SetupTest() |
| 125 | }) |
| 126 | AfterAll(func() { |
| 127 | s.TearDownSuite() |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 128 | }) |
| 129 | AfterEach(func() { |
| 130 | s.TearDownTest() |
| 131 | }) |
| 132 | |
| 133 | // https://onsi.github.io/ginkgo/#dynamically-generating-specs |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 134 | for filename, tests := range vethSoloTests { |
| 135 | for _, test := range tests { |
| 136 | test := test |
| 137 | pc := reflect.ValueOf(test).Pointer() |
| 138 | funcValue := runtime.FuncForPC(pc) |
| 139 | testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] |
| 140 | It(testName, Label("SOLO"), func(ctx SpecContext) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 141 | s.Log(testName + ": BEGIN") |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 142 | test(&s) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 143 | }, SpecTimeout(SuiteTimeout)) |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 144 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 145 | } |
| 146 | }) |