From 3ecd6840af4f890a11d26628ac34d31786b16758 Mon Sep 17 00:00:00 2001 From: Adrian Villin Date: Wed, 26 Jun 2024 09:47:10 +0200 Subject: hs-test: containerize iperf tests Type: test Change-Id: I2c0bb76d96ccadd5ecfd6a04565420855043699e Signed-off-by: Adrian Villin --- extras/hs-test/infra/suite_iperf_linux.go | 96 +++++++++++++++++++++++++ extras/hs-test/infra/suite_tap.go | 88 ----------------------- extras/hs-test/iperf_linux_test.go | 48 +++++++++++++ extras/hs-test/linux_iperf_test.go | 40 ----------- extras/hs-test/topo-containers/2containers.yaml | 4 ++ 5 files changed, 148 insertions(+), 128 deletions(-) create mode 100644 extras/hs-test/infra/suite_iperf_linux.go delete mode 100644 extras/hs-test/infra/suite_tap.go create mode 100644 extras/hs-test/iperf_linux_test.go delete mode 100644 extras/hs-test/linux_iperf_test.go create mode 100644 extras/hs-test/topo-containers/2containers.yaml diff --git a/extras/hs-test/infra/suite_iperf_linux.go b/extras/hs-test/infra/suite_iperf_linux.go new file mode 100644 index 00000000000..728429b505f --- /dev/null +++ b/extras/hs-test/infra/suite_iperf_linux.go @@ -0,0 +1,96 @@ +package hst + +import ( + "reflect" + "runtime" + "strings" + "time" + + . "github.com/onsi/ginkgo/v2" +) + +type IperfSuite struct { + HstSuite +} + +const ( + ServerIperfContainerName string = "server" + ServerIperfInterfaceName string = "hstsrv" + ClientIperfContainerName string = "client" + ClientIperfInterfaceName string = "hstcln" +) + +var iperfTests = map[string][]func(s *IperfSuite){} +var iperfSoloTests = map[string][]func(s *IperfSuite){} + +func RegisterIperfTests(tests ...func(s *IperfSuite)) { + iperfTests[getTestFilename()] = tests +} +func RegisterIperfSoloTests(tests ...func(s *IperfSuite)) { + iperfSoloTests[getTestFilename()] = tests +} + +func (s *IperfSuite) SetupSuite() { + time.Sleep(1 * time.Second) + s.HstSuite.SetupSuite() + s.ConfigureNetworkTopology("2taps") + s.LoadContainerTopology("2containers") +} + +var _ = Describe("IperfSuite", Ordered, ContinueOnFailure, func() { + var s IperfSuite + BeforeAll(func() { + s.SetupSuite() + }) + BeforeEach(func() { + s.SetupTest() + }) + AfterAll(func() { + s.TearDownSuite() + }) + AfterEach(func() { + s.TearDownTest() + }) + + for filename, tests := range iperfTests { + for _, test := range tests { + test := test + pc := reflect.ValueOf(test).Pointer() + funcValue := runtime.FuncForPC(pc) + testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] + It(testName, func(ctx SpecContext) { + s.Log(testName + ": BEGIN") + test(&s) + }, SpecTimeout(SuiteTimeout)) + } + } +}) + +var _ = Describe("IperfSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { + var s IperfSuite + BeforeAll(func() { + s.SetupSuite() + }) + BeforeEach(func() { + s.SetupTest() + }) + AfterAll(func() { + s.TearDownSuite() + }) + AfterEach(func() { + s.TearDownTest() + }) + + for filename, tests := range iperfSoloTests { + for _, test := range tests { + test := test + pc := reflect.ValueOf(test).Pointer() + funcValue := runtime.FuncForPC(pc) + testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] + It(testName, Label("SOLO"), func(ctx SpecContext) { + s.Log(testName + ": BEGIN") + test(&s) + }, SpecTimeout(SuiteTimeout)) + } + } +}) diff --git a/extras/hs-test/infra/suite_tap.go b/extras/hs-test/infra/suite_tap.go deleted file mode 100644 index c02ab8e8535..00000000000 --- a/extras/hs-test/infra/suite_tap.go +++ /dev/null @@ -1,88 +0,0 @@ -package hst - -import ( - "reflect" - "runtime" - "strings" - "time" - - . "github.com/onsi/ginkgo/v2" -) - -type TapSuite struct { - HstSuite -} - -var tapTests = map[string][]func(s *TapSuite){} -var tapSoloTests = map[string][]func(s *TapSuite){} - -func RegisterTapTests(tests ...func(s *TapSuite)) { - tapTests[getTestFilename()] = tests -} -func RegisterTapSoloTests(tests ...func(s *TapSuite)) { - tapSoloTests[getTestFilename()] = tests -} - -func (s *TapSuite) SetupSuite() { - time.Sleep(1 * time.Second) - s.HstSuite.SetupSuite() - s.ConfigureNetworkTopology("tap") -} - -var _ = Describe("TapSuite", Ordered, ContinueOnFailure, func() { - var s TapSuite - BeforeAll(func() { - s.SetupSuite() - }) - BeforeEach(func() { - s.SetupTest() - }) - AfterAll(func() { - s.TearDownSuite() - }) - AfterEach(func() { - s.TearDownTest() - }) - - for filename, tests := range tapTests { - for _, test := range tests { - test := test - pc := reflect.ValueOf(test).Pointer() - funcValue := runtime.FuncForPC(pc) - testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] - It(testName, func(ctx SpecContext) { - s.Log(testName + ": BEGIN") - test(&s) - }, SpecTimeout(SuiteTimeout)) - } - } -}) - -var _ = Describe("TapSuiteSolo", Ordered, ContinueOnFailure, Serial, func() { - var s TapSuite - BeforeAll(func() { - s.SetupSuite() - }) - BeforeEach(func() { - s.SetupTest() - }) - AfterAll(func() { - s.TearDownSuite() - }) - AfterEach(func() { - s.TearDownTest() - }) - - for filename, tests := range tapSoloTests { - for _, test := range tests { - test := test - pc := reflect.ValueOf(test).Pointer() - funcValue := runtime.FuncForPC(pc) - testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] - It(testName, Label("SOLO"), func(ctx SpecContext) { - s.Log(testName + ": BEGIN") - test(&s) - }, SpecTimeout(SuiteTimeout)) - } - } -}) diff --git a/extras/hs-test/iperf_linux_test.go b/extras/hs-test/iperf_linux_test.go new file mode 100644 index 00000000000..14422fe5efa --- /dev/null +++ b/extras/hs-test/iperf_linux_test.go @@ -0,0 +1,48 @@ +package main + +import ( + "fmt" + + . "fd.io/hs-test/infra" + . "github.com/onsi/ginkgo/v2" +) + +func init() { + RegisterIperfTests(IperfLinuxTest) +} + +func IperfLinuxTest(s *IperfSuite) { + serverContainer := s.GetContainerByName(ServerIperfContainerName) + serverIpAddress := s.GetInterfaceByName(ServerIperfInterfaceName).Ip4AddressString() + clientContainer := s.GetContainerByName(ClientIperfContainerName) + clientIpAddress := s.GetInterfaceByName(ClientIperfInterfaceName).Ip4AddressString() + + clnCh := make(chan error) + stopServerCh := make(chan struct{}) + srvCh := make(chan error, 1) + clnRes := make(chan string, 1) + + defer func() { + stopServerCh <- struct{}{} + }() + + go func() { + defer GinkgoRecover() + cmd := "iperf3 -4 -s -B " + serverIpAddress + " -p " + s.GetPortFromPpid() + s.StartServerApp(serverContainer, "iperf3", cmd, srvCh, stopServerCh) + }() + err := <-srvCh + s.AssertNil(err, fmt.Sprint(err)) + s.Log("server running") + + go func() { + defer GinkgoRecover() + cmd := "iperf3 -c " + serverIpAddress + " -B " + clientIpAddress + + " -u -l 1460 -b 10g -p " + s.GetPortFromPpid() + s.StartClientApp(clientContainer, cmd, clnCh, clnRes) + }() + + s.Log(<-clnRes) + err = <-clnCh + s.AssertNil(err, "err: '%s'", err) +} diff --git a/extras/hs-test/linux_iperf_test.go b/extras/hs-test/linux_iperf_test.go deleted file mode 100644 index 9342e862f04..00000000000 --- a/extras/hs-test/linux_iperf_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package main - -import ( - . "fd.io/hs-test/infra" - "fmt" - . "github.com/onsi/ginkgo/v2" -) - -func init() { - RegisterTapTests(LinuxIperfTest) -} - -func LinuxIperfTest(s *TapSuite) { - clnCh := make(chan error) - stopServerCh := make(chan struct{}) - srvCh := make(chan error, 1) - clnRes := make(chan string, 1) - defer func() { - stopServerCh <- struct{}{} - }() - - go func() { - defer GinkgoRecover() - s.StartIperfServerApp(srvCh, stopServerCh, nil) - }() - err := <-srvCh - s.AssertNil(err, fmt.Sprint(err)) - s.Log("server running") - - ipAddress := s.GetInterfaceByName(TapInterfaceName).Ip4AddressString() - go func() { - defer GinkgoRecover() - s.StartIperfClientApp(ipAddress, nil, clnCh, clnRes) - }() - s.Log("client running") - s.Log(<-clnRes) - err = <-clnCh - s.AssertNil(err, "err: '%s', ip: '%s'", err, ipAddress) - s.Log("Test completed") -} diff --git a/extras/hs-test/topo-containers/2containers.yaml b/extras/hs-test/topo-containers/2containers.yaml new file mode 100644 index 00000000000..1217c27d3ed --- /dev/null +++ b/extras/hs-test/topo-containers/2containers.yaml @@ -0,0 +1,4 @@ +--- +containers: + - name: "server" + - name: "client" \ No newline at end of file -- cgit 1.2.3-korg