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" |
| 8 | "time" |
| 9 | |
| 10 | . "github.com/onsi/ginkgo/v2" |
| 11 | ) |
| 12 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 13 | // These correspond to names used in yaml config |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 14 | const ( |
adrianvillin | fbf5f2b | 2024-02-13 03:26:25 -0500 | [diff] [blame] | 15 | clientInterface = "hclnvpp" |
| 16 | serverInterface = "hsrvvpp" |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 17 | ) |
| 18 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 19 | var nsTests = []func(s *NsSuite){} |
| 20 | var nsSoloTests = []func(s *NsSuite){} |
| 21 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 22 | type NsSuite struct { |
| 23 | HstSuite |
| 24 | } |
| 25 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 26 | func registerNsTests(tests ...func(s *NsSuite)) { |
| 27 | nsTests = append(nsTests, tests...) |
| 28 | } |
| 29 | func registerNsSoloTests(tests ...func(s *NsSuite)) { |
| 30 | nsSoloTests = append(nsSoloTests, tests...) |
| 31 | } |
| 32 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 33 | func (s *NsSuite) SetupSuite() { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 34 | s.HstSuite.SetupSuite() |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 35 | s.configureNetworkTopology("ns") |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 36 | s.loadContainerTopology("ns") |
| 37 | } |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 38 | |
| 39 | func (s *NsSuite) SetupTest() { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 40 | s.HstSuite.SetupTest() |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 41 | |
| 42 | // Setup test conditions |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 43 | var sessionConfig Stanza |
| 44 | sessionConfig. |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 45 | newStanza("session"). |
| 46 | append("enable"). |
| 47 | append("use-app-socket-api"). |
| 48 | append("evt_qs_memfd_seg"). |
| 49 | append("event-queue-length 100000").close() |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 50 | |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 51 | cpus := s.AllocateCpus() |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 52 | container := s.getContainerByName("vpp") |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 53 | vpp, _ := container.newVppInstance(cpus, sessionConfig) |
Filip Tehlar | 56e17cf | 2024-01-11 17:17:33 +0100 | [diff] [blame] | 54 | s.assertNil(vpp.start()) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 55 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 56 | idx, err := vpp.createAfPacket(s.getInterfaceByName(serverInterface)) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 57 | s.assertNil(err, fmt.Sprint(err)) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 58 | s.assertNotEqual(0, idx) |
| 59 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 60 | idx, err = vpp.createAfPacket(s.getInterfaceByName(clientInterface)) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 61 | s.assertNil(err, fmt.Sprint(err)) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 62 | s.assertNotEqual(0, idx) |
| 63 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 64 | container.exec("chmod 777 -R %s", container.getContainerWorkDir()) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 65 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 66 | |
| 67 | var _ = Describe("NsSuite", Ordered, ContinueOnFailure, func() { |
| 68 | var s NsSuite |
| 69 | BeforeAll(func() { |
| 70 | s.SetupSuite() |
| 71 | }) |
| 72 | BeforeEach(func() { |
| 73 | s.SetupTest() |
| 74 | }) |
| 75 | AfterAll(func() { |
| 76 | s.TearDownSuite() |
| 77 | }) |
| 78 | AfterEach(func() { |
| 79 | s.TearDownTest() |
| 80 | }) |
| 81 | |
| 82 | for _, test := range nsTests { |
| 83 | test := test |
| 84 | pc := reflect.ValueOf(test).Pointer() |
| 85 | funcValue := runtime.FuncForPC(pc) |
Adrian Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame^] | 86 | testName := strings.Split(funcValue.Name(), ".")[2] |
| 87 | It(testName, func(ctx SpecContext) { |
| 88 | s.log(testName + ": BEGIN") |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 89 | test(&s) |
| 90 | }, SpecTimeout(time.Minute*5)) |
| 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 | |
| 109 | for _, test := range nsSoloTests { |
| 110 | test := test |
| 111 | pc := reflect.ValueOf(test).Pointer() |
| 112 | funcValue := runtime.FuncForPC(pc) |
Adrian Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame^] | 113 | testName := strings.Split(funcValue.Name(), ".")[2] |
| 114 | It(testName, Label("SOLO"), func(ctx SpecContext) { |
| 115 | s.log(testName + ": BEGIN") |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 116 | test(&s) |
| 117 | }, SpecTimeout(time.Minute*5)) |
| 118 | } |
| 119 | }) |