Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 1 | package main |
| 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 ( |
adrianvillin | fbf5f2b | 2024-02-13 03:26:25 -0500 | [diff] [blame] | 14 | clientInterface = "hclnvpp" |
| 15 | serverInterface = "hsrvvpp" |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 16 | ) |
| 17 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 18 | var nsTests = []func(s *NsSuite){} |
| 19 | var nsSoloTests = []func(s *NsSuite){} |
| 20 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 21 | type NsSuite struct { |
| 22 | HstSuite |
| 23 | } |
| 24 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 25 | func registerNsTests(tests ...func(s *NsSuite)) { |
| 26 | nsTests = append(nsTests, tests...) |
| 27 | } |
| 28 | func registerNsSoloTests(tests ...func(s *NsSuite)) { |
| 29 | nsSoloTests = append(nsSoloTests, tests...) |
| 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() |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 34 | s.configureNetworkTopology("ns") |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 35 | s.loadContainerTopology("ns") |
| 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. |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [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 | |
| 50 | container := s.getContainerByName("vpp") |
Adrian Villin | b9464cd | 2024-05-27 09:52:59 -0400 | [diff] [blame] | 51 | vpp, _ := container.newVppInstance(container.allocatedCpus, sessionConfig) |
Filip Tehlar | 56e17cf | 2024-01-11 17:17:33 +0100 | [diff] [blame] | 52 | s.assertNil(vpp.start()) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 53 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 54 | idx, err := vpp.createAfPacket(s.getInterfaceByName(serverInterface)) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 55 | s.assertNil(err, fmt.Sprint(err)) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 56 | s.assertNotEqual(0, idx) |
| 57 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 58 | idx, err = vpp.createAfPacket(s.getInterfaceByName(clientInterface)) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 59 | s.assertNil(err, fmt.Sprint(err)) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 60 | s.assertNotEqual(0, idx) |
| 61 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [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 | |
| 80 | for _, test := range nsTests { |
| 81 | test := test |
| 82 | pc := reflect.ValueOf(test).Pointer() |
| 83 | funcValue := runtime.FuncForPC(pc) |
Adrian Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame] | 84 | testName := strings.Split(funcValue.Name(), ".")[2] |
| 85 | It(testName, func(ctx SpecContext) { |
| 86 | s.log(testName + ": BEGIN") |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 87 | test(&s) |
Adrian Villin | 93974e2 | 2024-05-30 06:10:59 -0400 | [diff] [blame] | 88 | }, SpecTimeout(suiteTimeout)) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 89 | } |
| 90 | }) |
| 91 | |
| 92 | var _ = Describe("NsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { |
| 93 | var s NsSuite |
| 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 | |
| 107 | for _, test := range nsSoloTests { |
| 108 | test := test |
| 109 | pc := reflect.ValueOf(test).Pointer() |
| 110 | funcValue := runtime.FuncForPC(pc) |
Adrian Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame] | 111 | testName := strings.Split(funcValue.Name(), ".")[2] |
| 112 | It(testName, Label("SOLO"), func(ctx SpecContext) { |
| 113 | s.log(testName + ": BEGIN") |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 114 | test(&s) |
Adrian Villin | 93974e2 | 2024-05-30 06:10:59 -0400 | [diff] [blame] | 115 | }, SpecTimeout(suiteTimeout)) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 116 | } |
| 117 | }) |