Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 1 | package main |
| 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 ( |
adrianvillin | fbf5f2b | 2024-02-13 03:26:25 -0500 | [diff] [blame] | 15 | serverInterfaceName = "srv" |
| 16 | clientInterfaceName = "cln" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 17 | ) |
| 18 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 19 | var vethTests = []func(s *VethsSuite){} |
| 20 | var vethSoloTests = []func(s *VethsSuite){} |
| 21 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 22 | type VethsSuite struct { |
| 23 | HstSuite |
| 24 | } |
| 25 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 26 | func registerVethTests(tests ...func(s *VethsSuite)) { |
| 27 | vethTests = append(vethTests, tests...) |
| 28 | } |
| 29 | func registerSoloVethTests(tests ...func(s *VethsSuite)) { |
| 30 | vethSoloTests = append(vethSoloTests, tests...) |
| 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() |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 36 | s.configureNetworkTopology("2peerVeth") |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 37 | s.loadContainerTopology("2peerVeth") |
| 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. |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [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 |
| 51 | serverContainer := s.getContainerByName("server-vpp") |
| 52 | |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 53 | cpus := s.AllocateCpus() |
adrianvillin | 7c67547 | 2024-02-12 02:44:53 -0500 | [diff] [blame] | 54 | serverVpp, err := serverContainer.newVppInstance(cpus, sessionConfig) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 55 | s.assertNotNil(serverVpp, fmt.Sprint(err)) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 56 | |
| 57 | s.setupServerVpp() |
| 58 | |
| 59 | // ... For client |
| 60 | clientContainer := s.getContainerByName("client-vpp") |
| 61 | |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 62 | cpus = s.AllocateCpus() |
adrianvillin | 7c67547 | 2024-02-12 02:44:53 -0500 | [diff] [blame] | 63 | clientVpp, err := clientContainer.newVppInstance(cpus, sessionConfig) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 64 | s.assertNotNil(clientVpp, fmt.Sprint(err)) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 65 | |
| 66 | s.setupClientVpp() |
| 67 | } |
| 68 | |
| 69 | func (s *VethsSuite) setupServerVpp() { |
| 70 | serverVpp := s.getContainerByName("server-vpp").vppInstance |
Filip Tehlar | 56e17cf | 2024-01-11 17:17:33 +0100 | [diff] [blame] | 71 | s.assertNil(serverVpp.start()) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 72 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 73 | serverVeth := s.getInterfaceByName(serverInterfaceName) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 74 | idx, err := serverVpp.createAfPacket(serverVeth) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 75 | s.assertNil(err, fmt.Sprint(err)) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 76 | s.assertNotEqual(0, idx) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | func (s *VethsSuite) setupClientVpp() { |
| 80 | clientVpp := s.getContainerByName("client-vpp").vppInstance |
Filip Tehlar | 56e17cf | 2024-01-11 17:17:33 +0100 | [diff] [blame] | 81 | s.assertNil(clientVpp.start()) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 82 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 83 | clientVeth := s.getInterfaceByName(clientInterfaceName) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 84 | idx, err := clientVpp.createAfPacket(clientVeth) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 85 | s.assertNil(err, fmt.Sprint(err)) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 86 | s.assertNotEqual(0, idx) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 87 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 88 | |
| 89 | var _ = Describe("VethsSuite", Ordered, ContinueOnFailure, func() { |
| 90 | var s VethsSuite |
| 91 | BeforeAll(func() { |
| 92 | s.SetupSuite() |
| 93 | }) |
| 94 | BeforeEach(func() { |
| 95 | s.SetupTest() |
| 96 | }) |
| 97 | AfterAll(func() { |
| 98 | s.TearDownSuite() |
| 99 | |
| 100 | }) |
| 101 | AfterEach(func() { |
| 102 | s.TearDownTest() |
| 103 | }) |
| 104 | |
| 105 | // https://onsi.github.io/ginkgo/#dynamically-generating-specs |
| 106 | for _, test := range vethTests { |
| 107 | test := test |
| 108 | pc := reflect.ValueOf(test).Pointer() |
| 109 | funcValue := runtime.FuncForPC(pc) |
| 110 | It(strings.Split(funcValue.Name(), ".")[2], func(ctx SpecContext) { |
| 111 | test(&s) |
| 112 | }, SpecTimeout(time.Minute*5)) |
| 113 | } |
| 114 | }) |
| 115 | |
| 116 | var _ = Describe("VethsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { |
| 117 | var s VethsSuite |
| 118 | BeforeAll(func() { |
| 119 | s.SetupSuite() |
| 120 | }) |
| 121 | BeforeEach(func() { |
| 122 | s.SetupTest() |
| 123 | }) |
| 124 | AfterAll(func() { |
| 125 | s.TearDownSuite() |
| 126 | |
| 127 | }) |
| 128 | AfterEach(func() { |
| 129 | s.TearDownTest() |
| 130 | }) |
| 131 | |
| 132 | // https://onsi.github.io/ginkgo/#dynamically-generating-specs |
| 133 | for _, test := range vethSoloTests { |
| 134 | test := test |
| 135 | pc := reflect.ValueOf(test).Pointer() |
| 136 | funcValue := runtime.FuncForPC(pc) |
| 137 | It(strings.Split(funcValue.Name(), ".")[2], Label("SOLO"), func(ctx SpecContext) { |
| 138 | test(&s) |
| 139 | }, SpecTimeout(time.Minute*5)) |
| 140 | } |
| 141 | }) |