diff options
author | Filip Tehlar <ftehlar@cisco.com> | 2023-09-02 08:54:21 +0200 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2023-09-04 20:56:14 +0000 |
commit | 4b3598e39a5b522a55b4b86fa06a323416108a6b (patch) | |
tree | 8266892eee1ef16a5702fccbc00a0be467e96ad1 | |
parent | a6b1a7d809e746325fe712b9de9ff086e55772dd (diff) |
hs-test: log external apps
Type: test
Change-Id: Id2b0d408bd46f20b81422506f9db4eb655feddac
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
-rw-r--r-- | extras/hs-test/hst_suite.go | 80 | ||||
-rw-r--r-- | extras/hs-test/http_test.go | 4 | ||||
-rw-r--r-- | extras/hs-test/ldp_test.go | 4 | ||||
-rw-r--r-- | extras/hs-test/linux_iperf_test.go | 4 | ||||
-rw-r--r-- | extras/hs-test/proxy_test.go | 2 | ||||
-rw-r--r-- | extras/hs-test/utils.go | 87 | ||||
-rw-r--r-- | extras/hs-test/vcl_test.go | 10 |
7 files changed, 97 insertions, 94 deletions
diff --git a/extras/hs-test/hst_suite.go b/extras/hs-test/hst_suite.go index 093bca0b56f..d74934ae62c 100644 --- a/extras/hs-test/hst_suite.go +++ b/extras/hs-test/hst_suite.go @@ -1,7 +1,9 @@ package main import ( + "errors" "flag" + "fmt" "io/ioutil" "os" "os/exec" @@ -313,3 +315,81 @@ func (s *HstSuite) getTestId() string { return s.testIds[testName] } + +func (s *HstSuite) startServerApp(running chan error, done chan struct{}, env []string) { + cmd := exec.Command("iperf3", "-4", "-s") + if env != nil { + cmd.Env = env + } + s.log(cmd) + err := cmd.Start() + if err != nil { + msg := fmt.Errorf("failed to start iperf server: %v", err) + running <- msg + return + } + running <- nil + <-done + cmd.Process.Kill() +} + +func (s *HstSuite) startClientApp(ipAddress string, env []string, clnCh chan error, clnRes chan string) { + defer func() { + clnCh <- nil + }() + + nTries := 0 + + for { + cmd := exec.Command("iperf3", "-c", ipAddress, "-u", "-l", "1460", "-b", "10g") + if env != nil { + cmd.Env = env + } + s.log(cmd) + o, err := cmd.CombinedOutput() + if err != nil { + if nTries > 5 { + clnCh <- fmt.Errorf("failed to start client app '%s'.\n%s", err, o) + return + } + time.Sleep(1 * time.Second) + nTries++ + continue + } else { + clnRes <- fmt.Sprintf("Client output: %s", o) + } + break + } +} + +func (s *HstSuite) startHttpServer(running chan struct{}, done chan struct{}, addressPort, netNs string) { + cmd := newCommand([]string{"./http_server", addressPort}, netNs) + err := cmd.Start() + s.log(cmd) + if err != nil { + fmt.Println("Failed to start http server") + return + } + running <- struct{}{} + <-done + cmd.Process.Kill() +} + +func (s *HstSuite) startWget(finished chan error, server_ip, port, query, netNs string) { + defer func() { + finished <- errors.New("wget error") + }() + + cmd := newCommand([]string{"wget", "--timeout=10", "--no-proxy", "--tries=5", "-O", "/dev/null", server_ip + ":" + port + "/" + query}, + netNs) + s.log(cmd) + o, err := cmd.CombinedOutput() + if err != nil { + finished <- fmt.Errorf("wget error: '%v\n\n%s'", err, o) + return + } else if !strings.Contains(string(o), "200 OK") { + finished <- fmt.Errorf("wget error: response not 200 OK") + return + } + finished <- nil +} diff --git a/extras/hs-test/http_test.go b/extras/hs-test/http_test.go index 503f42a47c7..4aab55335d2 100644 --- a/extras/hs-test/http_test.go +++ b/extras/hs-test/http_test.go @@ -17,7 +17,7 @@ func (s *NsSuite) TestHttpTps() { // configure vpp in the container container.vppInstance.vppctl("http tps uri tcp://0.0.0.0/8080") - go startWget(finished, client_ip, port, "test_file_10M", "client") + go s.startWget(finished, client_ip, port, "test_file_10M", "client") // wait for client err := <-finished s.assertNil(err) @@ -73,7 +73,7 @@ func (s *NoTopoSuite) TestNginxAsServer() { serverAddress := s.netInterfaces[tapInterfaceName].peer.ip4AddressString() defer func() { os.Remove(query) }() - go startWget(finished, serverAddress, "80", query, "") + go s.startWget(finished, serverAddress, "80", query, "") s.assertNil(<-finished) } diff --git a/extras/hs-test/ldp_test.go b/extras/hs-test/ldp_test.go index c2d6f33b714..1906d6b4121 100644 --- a/extras/hs-test/ldp_test.go +++ b/extras/hs-test/ldp_test.go @@ -54,7 +54,7 @@ func (s *VethsSuite) TestLDPreloadIperfVpp() { s.log("attaching server to vpp") srvEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+serverVclFileName) - go startServerApp(srvCh, stopServerCh, srvEnv) + go s.startServerApp(srvCh, stopServerCh, srvEnv) err = <-srvCh s.assertNil(err) @@ -63,7 +63,7 @@ func (s *VethsSuite) TestLDPreloadIperfVpp() { var clnRes = make(chan string, 1) clnEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+clientVclFileName) serverVethAddress := s.netInterfaces[serverInterfaceName].ip4AddressString() - go startClientApp(serverVethAddress, clnEnv, clnCh, clnRes) + go s.startClientApp(serverVethAddress, clnEnv, clnCh, clnRes) s.log(<-clnRes) // wait for client's result diff --git a/extras/hs-test/linux_iperf_test.go b/extras/hs-test/linux_iperf_test.go index 04556a8fe45..c03403c9e26 100644 --- a/extras/hs-test/linux_iperf_test.go +++ b/extras/hs-test/linux_iperf_test.go @@ -9,13 +9,13 @@ func (s *TapSuite) TestLinuxIperf() { stopServerCh <- struct{}{} }() - go startServerApp(srvCh, stopServerCh, nil) + go s.startServerApp(srvCh, stopServerCh, nil) err := <-srvCh s.assertNil(err) s.log("server running") ipAddress := s.netInterfaces[tapInterfaceName].ip4AddressString() - go startClientApp(ipAddress, nil, clnCh, clnRes) + go s.startClientApp(ipAddress, nil, clnCh, clnRes) s.log("client running") s.log(<-clnRes) err = <-clnCh diff --git a/extras/hs-test/proxy_test.go b/extras/hs-test/proxy_test.go index a7a6509144b..9e7230317fb 100644 --- a/extras/hs-test/proxy_test.go +++ b/extras/hs-test/proxy_test.go @@ -20,7 +20,7 @@ func testProxyHttpTcp(s *NsSuite) error { s.log("test file created...") - go startHttpServer(serverRunning, stopServer, ":666", "server") + go s.startHttpServer(serverRunning, stopServer, ":666", "server") // TODO better error handling and recovery <-serverRunning diff --git a/extras/hs-test/utils.go b/extras/hs-test/utils.go index 4261f4dc2d1..304dd4c241b 100644 --- a/extras/hs-test/utils.go +++ b/extras/hs-test/utils.go @@ -1,25 +1,12 @@ package main import ( - "errors" "fmt" "io" "os" - "os/exec" "strings" - "time" ) -const vclTemplate = `vcl { - app-socket-api %[1]s/var/run/app_ns_sockets/%[2]s - app-scope-global - app-scope-local - namespace-id %[2]s - namespace-secret %[2]s - use-mq-eventfd -} -` - const networkTopologyDir string = "topo-network/" const containerTopologyDir string = "topo-containers/" @@ -42,50 +29,6 @@ type JsonResult struct { StdOutput string } -func startServerApp(running chan error, done chan struct{}, env []string) { - cmd := exec.Command("iperf3", "-4", "-s") - if env != nil { - cmd.Env = env - } - err := cmd.Start() - if err != nil { - msg := fmt.Errorf("failed to start iperf server: %v", err) - running <- msg - return - } - running <- nil - <-done - cmd.Process.Kill() -} - -func startClientApp(ipAddress string, env []string, clnCh chan error, clnRes chan string) { - defer func() { - clnCh <- nil - }() - - nTries := 0 - - for { - cmd := exec.Command("iperf3", "-c", ipAddress, "-u", "-l", "1460", "-b", "10g") - if env != nil { - cmd.Env = env - } - o, err := cmd.CombinedOutput() - if err != nil { - if nTries > 5 { - clnCh <- fmt.Errorf("failed to start client app '%s'.\n%s", err, o) - return - } - time.Sleep(1 * time.Second) - nTries++ - continue - } else { - clnRes <- fmt.Sprintf("Client output: %s", o) - } - break - } -} - func assertFileSize(f1, f2 string) error { fi1, err := os.Stat(f1) if err != nil { @@ -103,36 +46,6 @@ func assertFileSize(f1, f2 string) error { return nil } -func startHttpServer(running chan struct{}, done chan struct{}, addressPort, netNs string) { - cmd := newCommand([]string{"./http_server", addressPort}, netNs) - err := cmd.Start() - if err != nil { - fmt.Println("Failed to start http server") - return - } - running <- struct{}{} - <-done - cmd.Process.Kill() -} - -func startWget(finished chan error, server_ip, port, query, netNs string) { - defer func() { - finished <- errors.New("wget error") - }() - - cmd := newCommand([]string{"wget", "--timeout=10", "--no-proxy", "--tries=5", "-O", "/dev/null", server_ip + ":" + port + "/" + query}, - netNs) - o, err := cmd.CombinedOutput() - if err != nil { - finished <- fmt.Errorf("wget error: '%v\n\n%s'", err, o) - return - } else if !strings.Contains(string(o), "200 OK") { - finished <- fmt.Errorf("wget error: response not 200 OK") - return - } - finished <- nil -} - func (c *Stanza) newStanza(name string) *Stanza { c.append("\n" + name + " {") c.pad += 2 diff --git a/extras/hs-test/vcl_test.go b/extras/hs-test/vcl_test.go index 109b242ee79..cf4c32ed020 100644 --- a/extras/hs-test/vcl_test.go +++ b/extras/hs-test/vcl_test.go @@ -5,6 +5,16 @@ import ( "time" ) +const vclTemplate = `vcl { + app-socket-api %[1]s/var/run/app_ns_sockets/%[2]s + app-scope-global + app-scope-local + namespace-id %[2]s + namespace-secret %[2]s + use-mq-eventfd +} +` + func (s *VethsSuite) testVclEcho(proto string) { port := "12345" srvVppCont := s.getContainerByName("server-vpp") |