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 | 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 | cee15aa | 2024-03-14 11:42:55 -0400 | [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 | } |
| 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() |
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 | |
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) { |
| 87 | s.log(testName + ": BEGIN") |
| 88 | test(&s) |
| 89 | }, SpecTimeout(suiteTimeout)) |
| 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) { |
| 116 | s.log(testName + ": BEGIN") |
| 117 | test(&s) |
| 118 | }, SpecTimeout(suiteTimeout)) |
| 119 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 120 | } |
| 121 | }) |