hs-test: containerize iperf tests 96/41196/13
authorAdrian Villin <[email protected]>
Wed, 26 Jun 2024 07:47:10 +0000 (09:47 +0200)
committerFlorin Coras <[email protected]>
Wed, 18 Sep 2024 18:09:44 +0000 (18:09 +0000)
Type: test

Change-Id: I2c0bb76d96ccadd5ecfd6a04565420855043699e
Signed-off-by: Adrian Villin <[email protected]>
extras/hs-test/infra/suite_iperf_linux.go [moved from extras/hs-test/infra/suite_tap.go with 56% similarity]
extras/hs-test/iperf_linux_test.go [new file with mode: 0644]
extras/hs-test/linux_iperf_test.go [deleted file]
extras/hs-test/topo-containers/2containers.yaml [new file with mode: 0644]

similarity index 56%
rename from extras/hs-test/infra/suite_tap.go
rename to extras/hs-test/infra/suite_iperf_linux.go
index c02ab8e..728429b 100644 (file)
@@ -9,28 +9,36 @@ import (
        . "github.com/onsi/ginkgo/v2"
 )
 
-type TapSuite struct {
+type IperfSuite struct {
        HstSuite
 }
 
-var tapTests = map[string][]func(s *TapSuite){}
-var tapSoloTests = map[string][]func(s *TapSuite){}
+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 RegisterTapTests(tests ...func(s *TapSuite)) {
-       tapTests[getTestFilename()] = tests
+func RegisterIperfTests(tests ...func(s *IperfSuite)) {
+       iperfTests[getTestFilename()] = tests
 }
-func RegisterTapSoloTests(tests ...func(s *TapSuite)) {
-       tapSoloTests[getTestFilename()] = tests
+func RegisterIperfSoloTests(tests ...func(s *IperfSuite)) {
+       iperfSoloTests[getTestFilename()] = tests
 }
 
-func (s *TapSuite) SetupSuite() {
+func (s *IperfSuite) SetupSuite() {
        time.Sleep(1 * time.Second)
        s.HstSuite.SetupSuite()
-       s.ConfigureNetworkTopology("tap")
+       s.ConfigureNetworkTopology("2taps")
+       s.LoadContainerTopology("2containers")
 }
 
-var _ = Describe("TapSuite", Ordered, ContinueOnFailure, func() {
-       var s TapSuite
+var _ = Describe("IperfSuite", Ordered, ContinueOnFailure, func() {
+       var s IperfSuite
        BeforeAll(func() {
                s.SetupSuite()
        })
@@ -44,7 +52,7 @@ var _ = Describe("TapSuite", Ordered, ContinueOnFailure, func() {
                s.TearDownTest()
        })
 
-       for filename, tests := range tapTests {
+       for filename, tests := range iperfTests {
                for _, test := range tests {
                        test := test
                        pc := reflect.ValueOf(test).Pointer()
@@ -58,8 +66,8 @@ var _ = Describe("TapSuite", Ordered, ContinueOnFailure, func() {
        }
 })
 
-var _ = Describe("TapSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
-       var s TapSuite
+var _ = Describe("IperfSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
+       var s IperfSuite
        BeforeAll(func() {
                s.SetupSuite()
        })
@@ -73,7 +81,7 @@ var _ = Describe("TapSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
                s.TearDownTest()
        })
 
-       for filename, tests := range tapSoloTests {
+       for filename, tests := range iperfSoloTests {
                for _, test := range tests {
                        test := test
                        pc := reflect.ValueOf(test).Pointer()
diff --git a/extras/hs-test/iperf_linux_test.go b/extras/hs-test/iperf_linux_test.go
new file mode 100644 (file)
index 0000000..14422fe
--- /dev/null
@@ -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 (file)
index 9342e86..0000000
+++ /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 (file)
index 0000000..1217c27
--- /dev/null
@@ -0,0 +1,4 @@
+---
+containers:
+  - name: "server"
+  - name: "client"
\ No newline at end of file