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"). |
Adrian Villin | 1fde999 | 2024-06-24 08:14:05 -0400 | [diff] [blame] | 48 | Append("event-queue-length 100000") |
| 49 | |
| 50 | if strings.Contains(CurrentSpecReport().LeafNodeText, "InterruptMode") { |
| 51 | sessionConfig.Append("use-private-rx-mqs").Close() |
| 52 | } else { |
| 53 | sessionConfig.Close() |
| 54 | } |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 55 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 56 | container := s.GetContainerByName("vpp") |
| 57 | vpp, _ := container.newVppInstance(container.AllocatedCpus, sessionConfig) |
| 58 | s.AssertNil(vpp.Start()) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 59 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 60 | idx, err := vpp.createAfPacket(s.GetInterfaceByName(ServerInterface)) |
| 61 | s.AssertNil(err, fmt.Sprint(err)) |
| 62 | s.AssertNotEqual(0, idx) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 63 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 64 | idx, err = vpp.createAfPacket(s.GetInterfaceByName(ClientInterface)) |
| 65 | s.AssertNil(err, fmt.Sprint(err)) |
| 66 | s.AssertNotEqual(0, idx) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 67 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 68 | container.Exec("chmod 777 -R %s", container.GetContainerWorkDir()) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 69 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 70 | |
| 71 | var _ = Describe("NsSuite", Ordered, ContinueOnFailure, func() { |
| 72 | var s NsSuite |
| 73 | BeforeAll(func() { |
| 74 | s.SetupSuite() |
| 75 | }) |
| 76 | BeforeEach(func() { |
| 77 | s.SetupTest() |
| 78 | }) |
| 79 | AfterAll(func() { |
| 80 | s.TearDownSuite() |
| 81 | }) |
| 82 | AfterEach(func() { |
| 83 | s.TearDownTest() |
| 84 | }) |
| 85 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 86 | for filename, tests := range nsTests { |
| 87 | for _, test := range tests { |
| 88 | test := test |
| 89 | pc := reflect.ValueOf(test).Pointer() |
| 90 | funcValue := runtime.FuncForPC(pc) |
| 91 | testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] |
| 92 | It(testName, func(ctx SpecContext) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 93 | s.Log(testName + ": BEGIN") |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 94 | test(&s) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 95 | }, SpecTimeout(SuiteTimeout)) |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 96 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 97 | } |
| 98 | }) |
| 99 | |
| 100 | var _ = Describe("NsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { |
| 101 | var s NsSuite |
| 102 | BeforeAll(func() { |
| 103 | s.SetupSuite() |
| 104 | }) |
| 105 | BeforeEach(func() { |
| 106 | s.SetupTest() |
| 107 | }) |
| 108 | AfterAll(func() { |
| 109 | s.TearDownSuite() |
| 110 | }) |
| 111 | AfterEach(func() { |
| 112 | s.TearDownTest() |
| 113 | }) |
| 114 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 115 | for filename, tests := range nsSoloTests { |
| 116 | for _, test := range tests { |
| 117 | test := test |
| 118 | pc := reflect.ValueOf(test).Pointer() |
| 119 | funcValue := runtime.FuncForPC(pc) |
| 120 | testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] |
| 121 | It(testName, Label("SOLO"), func(ctx SpecContext) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 122 | s.Log(testName + ": BEGIN") |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 123 | test(&s) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 124 | }, SpecTimeout(SuiteTimeout)) |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 125 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 126 | } |
| 127 | }) |