Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 1 | package hst |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 2 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 3 | import ( |
| 4 | "reflect" |
| 5 | "runtime" |
| 6 | "strings" |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 7 | |
| 8 | . "github.com/onsi/ginkgo/v2" |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 9 | ) |
| 10 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 11 | const ( |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 12 | SingleTopoContainerVpp = "vpp" |
| 13 | SingleTopoContainerNginx = "nginx" |
| 14 | TapInterfaceName = "htaphost" |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 15 | ) |
| 16 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 17 | var noTopoTests = map[string][]func(s *NoTopoSuite){} |
| 18 | var noTopoSoloTests = map[string][]func(s *NoTopoSuite){} |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 19 | |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 20 | type NoTopoSuite struct { |
| 21 | HstSuite |
| 22 | } |
| 23 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 24 | func RegisterNoTopoTests(tests ...func(s *NoTopoSuite)) { |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 25 | noTopoTests[getTestFilename()] = tests |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 26 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 27 | func RegisterNoTopoSoloTests(tests ...func(s *NoTopoSuite)) { |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 28 | noTopoSoloTests[getTestFilename()] = tests |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 29 | } |
| 30 | |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 31 | func (s *NoTopoSuite) SetupSuite() { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 32 | s.HstSuite.SetupSuite() |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 33 | s.LoadNetworkTopology("tap") |
| 34 | s.LoadContainerTopology("single") |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | func (s *NoTopoSuite) SetupTest() { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 38 | s.HstSuite.SetupTest() |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 39 | |
| 40 | // Setup test conditions |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 41 | var sessionConfig Stanza |
| 42 | sessionConfig. |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 43 | NewStanza("session"). |
| 44 | Append("enable"). |
Adrian Villin | 1fde999 | 2024-06-24 08:14:05 -0400 | [diff] [blame] | 45 | Append("use-app-socket-api") |
| 46 | |
| 47 | if strings.Contains(CurrentSpecReport().LeafNodeText, "InterruptMode") { |
| 48 | sessionConfig.Append("use-private-rx-mqs").Close() |
| 49 | s.Log("**********************INTERRUPT MODE**********************") |
| 50 | } else { |
| 51 | sessionConfig.Close() |
| 52 | } |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 53 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 54 | container := s.GetContainerByName(SingleTopoContainerVpp) |
| 55 | vpp, _ := container.newVppInstance(container.AllocatedCpus, sessionConfig) |
| 56 | s.AssertNil(vpp.Start()) |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 57 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 58 | tapInterface := s.GetInterfaceByName(TapInterfaceName) |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 59 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 60 | s.AssertNil(vpp.createTap(tapInterface), "failed to create tap interface") |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 61 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 62 | |
| 63 | var _ = Describe("NoTopoSuite", Ordered, ContinueOnFailure, func() { |
| 64 | var s NoTopoSuite |
| 65 | BeforeAll(func() { |
| 66 | s.SetupSuite() |
| 67 | }) |
| 68 | BeforeEach(func() { |
| 69 | s.SetupTest() |
| 70 | }) |
| 71 | AfterAll(func() { |
| 72 | s.TearDownSuite() |
| 73 | }) |
| 74 | AfterEach(func() { |
| 75 | s.TearDownTest() |
| 76 | }) |
| 77 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 78 | for filename, tests := range noTopoTests { |
| 79 | for _, test := range tests { |
| 80 | test := test |
| 81 | pc := reflect.ValueOf(test).Pointer() |
| 82 | funcValue := runtime.FuncForPC(pc) |
| 83 | testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] |
| 84 | It(testName, func(ctx SpecContext) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 85 | s.Log(testName + ": BEGIN") |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 86 | test(&s) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 87 | }, SpecTimeout(SuiteTimeout)) |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 88 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 89 | } |
| 90 | }) |
| 91 | |
| 92 | var _ = Describe("NoTopoSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { |
| 93 | var s NoTopoSuite |
| 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 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 107 | for filename, tests := range noTopoSoloTests { |
| 108 | for _, test := range tests { |
| 109 | test := test |
| 110 | pc := reflect.ValueOf(test).Pointer() |
| 111 | funcValue := runtime.FuncForPC(pc) |
| 112 | testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] |
| 113 | It(testName, Label("SOLO"), func(ctx SpecContext) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 114 | s.Log(testName + ": BEGIN") |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 115 | test(&s) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 116 | }, SpecTimeout(SuiteTimeout)) |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 117 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 118 | } |
| 119 | }) |