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 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 3 | import ( |
| 4 | "fmt" |
| 5 | "reflect" |
| 6 | "runtime" |
| 7 | "strings" |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 8 | |
| 9 | . "github.com/onsi/ginkgo/v2" |
| 10 | ) |
| 11 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 12 | // These correspond to names used in yaml config |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 13 | const ( |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 14 | ClientInterface = "hclnvpp" |
| 15 | ServerInterface = "hsrvvpp" |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 16 | ) |
| 17 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 18 | var nsTests = map[string][]func(s *NsSuite){} |
| 19 | var nsSoloTests = map[string][]func(s *NsSuite){} |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 20 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 21 | type NsSuite struct { |
| 22 | HstSuite |
| 23 | } |
| 24 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 25 | func RegisterNsTests(tests ...func(s *NsSuite)) { |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 26 | nsTests[getTestFilename()] = tests |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 27 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 28 | func RegisterNsSoloTests(tests ...func(s *NsSuite)) { |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 29 | nsSoloTests[getTestFilename()] = tests |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 30 | } |
| 31 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 32 | func (s *NsSuite) SetupSuite() { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 33 | s.HstSuite.SetupSuite() |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 34 | s.ConfigureNetworkTopology("ns") |
| 35 | s.LoadContainerTopology("ns") |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 36 | } |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 37 | |
| 38 | func (s *NsSuite) SetupTest() { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 39 | s.HstSuite.SetupTest() |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 40 | |
| 41 | // Setup test conditions |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 42 | var sessionConfig Stanza |
| 43 | sessionConfig. |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 44 | 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 Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 49 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 50 | container := s.GetContainerByName("vpp") |
| 51 | vpp, _ := container.newVppInstance(container.AllocatedCpus, sessionConfig) |
| 52 | s.AssertNil(vpp.Start()) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 53 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 54 | idx, err := vpp.createAfPacket(s.GetInterfaceByName(ServerInterface)) |
| 55 | s.AssertNil(err, fmt.Sprint(err)) |
| 56 | s.AssertNotEqual(0, idx) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 57 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 58 | idx, err = vpp.createAfPacket(s.GetInterfaceByName(ClientInterface)) |
| 59 | s.AssertNil(err, fmt.Sprint(err)) |
| 60 | s.AssertNotEqual(0, idx) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 61 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 62 | container.Exec("chmod 777 -R %s", container.GetContainerWorkDir()) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 63 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 64 | |
| 65 | var _ = 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 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 80 | for filename, tests := range nsTests { |
| 81 | for _, test := range tests { |
| 82 | test := test |
| 83 | pc := reflect.ValueOf(test).Pointer() |
| 84 | funcValue := runtime.FuncForPC(pc) |
| 85 | testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] |
| 86 | It(testName, func(ctx SpecContext) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 87 | s.Log(testName + ": BEGIN") |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 88 | test(&s) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 89 | }, SpecTimeout(SuiteTimeout)) |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 90 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 91 | } |
| 92 | }) |
| 93 | |
| 94 | var _ = Describe("NsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { |
| 95 | var s NsSuite |
| 96 | BeforeAll(func() { |
| 97 | s.SetupSuite() |
| 98 | }) |
| 99 | BeforeEach(func() { |
| 100 | s.SetupTest() |
| 101 | }) |
| 102 | AfterAll(func() { |
| 103 | s.TearDownSuite() |
| 104 | }) |
| 105 | AfterEach(func() { |
| 106 | s.TearDownTest() |
| 107 | }) |
| 108 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 109 | for filename, tests := range nsSoloTests { |
| 110 | for _, test := range tests { |
| 111 | test := test |
| 112 | pc := reflect.ValueOf(test).Pointer() |
| 113 | funcValue := runtime.FuncForPC(pc) |
| 114 | testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] |
| 115 | It(testName, Label("SOLO"), func(ctx SpecContext) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 116 | s.Log(testName + ": BEGIN") |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 117 | test(&s) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame^] | 118 | }, SpecTimeout(SuiteTimeout)) |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 119 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 120 | } |
| 121 | }) |