return container, nil
}
-func (c *Container) run() error {
- if c.name == "" {
- return fmt.Errorf("create volume failed: container name is blank")
- }
-
- exechelper.Run(fmt.Sprintf("mkdir -p /tmp/%s/sync", c.name))
+func (c *Container) getRunCommand() string {
syncPath := fmt.Sprintf(" -v %s:/tmp/sync", c.getSyncPath())
cmd := "docker run --cap-add=all -d --privileged --network host --rm"
cmd += syncPath
cmd += c.getVolumesAsCliOption()
cmd += c.getEnvVarsAsCliOption()
cmd += " --name " + c.name + " " + c.image
- fmt.Println(cmd)
+ return cmd
+}
+
+func (c *Container) run() error {
+ if c.name == "" {
+ return fmt.Errorf("run container failed: name is blank")
+ }
+
+ exechelper.Run(fmt.Sprintf("mkdir -p /tmp/%s/sync", c.name))
+ cmd := c.getRunCommand()
err := exechelper.Run(cmd)
if err != nil {
return fmt.Errorf("container run failed: %s", err)
package main
-import (
- "fmt"
-)
-
func (s *VethsSuite) TestEchoBuiltin() {
serverContainer := s.getContainerByName("server-vpp")
_, err := serverContainer.execAction("Configure2Veths srv")
o, err := clientContainer.execAction("RunEchoClnInternal nclients 10000 bytes 1 syn-timeout 100 test-timeout 100 no-return private-segment-size 1g fifo-size 4")
s.assertNil(err)
- fmt.Println(o)
+ s.log(o)
}
package main
import (
- "fmt"
"testing"
"io/ioutil"
+ "os"
"github.com/edwarnicke/exechelper"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)
+func IsPersistent() bool {
+ if os.Getenv("HST_PERSIST") == "1" {
+ return true
+ }
+ return false
+}
+
+func IsVerbose() bool {
+ if os.Getenv("HST_VERBOSE") == "1" {
+ return true
+ }
+ return false
+}
+
type HstSuite struct {
suite.Suite
teardownSuite func()
}
func (s *HstSuite) TearDownTest() {
+ if IsPersistent() {
+ return
+ }
s.ResetContainers()
s.RemoveVolumes()
}
func (s *HstSuite) SetupTest() {
for _, volume := range s.volumes {
cmd := "docker volume create --name=" + volume
- fmt.Println(cmd)
+ s.log(cmd)
exechelper.Run(cmd)
}
for _, container := range s.containers {
}
}
-func (s *HstSuite) ResetContainers() {
- for _, container := range s.containers {
- container.stop()
+func (s *HstSuite) log(args ...any) {
+ if IsVerbose() {
+ s.T().Log(args...)
}
}
-func (s *HstSuite) NewVolume(name string) error {
- err := exechelper.Run(fmt.Sprintf("docker volume create --name=%s", name))
- if err != nil {
- return err
- }
+func (s *HstSuite) skip(args ...any) {
+ s.log(args...)
+ s.T().SkipNow()
+}
- s.volumes = append(s.volumes, name)
- return nil
+func (s *HstSuite) ResetContainers() {
+ for _, container := range s.containers {
+ container.stop()
+ }
}
func (s *HstSuite) RemoveVolumes() {
if err != nil {
s.T().Fatalf("config error: %v", err)
}
+ s.log(newContainer.getRunCommand())
s.containers[newContainer.name] = newContainer
}
}
t.Fatalf("failed to configure %s: %v", topologyName, err)
}
- t.Logf("topo %s loaded", topologyName)
return func() {
+ if IsPersistent() {
+ return
+ }
topology.Unconfigure()
}
}
package main
func (s *NsSuite) TestHttpTps() {
- t := s.T()
finished := make(chan error, 1)
server_ip := "10.0.0.2"
port := "8080"
container := s.getContainerByName("vpp")
- t.Log("starting vpp..")
+ s.log("starting vpp..")
// start & configure vpp in the container
_, err := container.execAction("ConfigureHttpTps")
}
func (s *VethsSuite) TestHttpCli() {
- t := s.T()
-
serverContainer := s.getContainerByName("server-vpp")
clientContainer := s.getContainerByName("client-vpp")
_, err = clientContainer.execAction("Configure2Veths cln")
s.assertNil(err)
- t.Log("configured IPs...")
+ s.log("configured IPs...")
_, err = serverContainer.execAction("RunHttpCliSrv")
s.assertNil(err)
- t.Log("configured http server")
+ s.log("configured http server")
o, err := clientContainer.execAction("RunHttpCliCln /show/version")
s.assertNil(err)
srvCh := make(chan error, 1)
clnCh := make(chan error)
- fmt.Println("starting VPPs")
+ s.log("starting VPPs")
originalWorkDir := serverContainer.workDir
serverContainer.workDir = serverVolume.containerDir
SaveToFile(srvVcl)
s.assertNil(err)
- fmt.Printf("attaching server to vpp")
+ s.log("attaching server to vpp")
// FIXME
time.Sleep(5 * time.Second)
err = <-srvCh
s.assertNil(err)
- fmt.Println("attaching client to vpp")
+ s.log("attaching client to vpp")
+ var clnRes = make(chan string, 1)
clnEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+clnVcl)
- go StartClientApp(clnEnv, clnCh)
+ go StartClientApp(clnEnv, clnCh, clnRes)
+ s.log(<- clnRes)
// wait for client's result
err = <-clnCh
package main
func (s *TapSuite) TestLinuxIperf() {
- t := s.T()
clnCh := make(chan error)
stopServerCh := make(chan struct{})
srvCh := make(chan error, 1)
+ clnRes := make(chan string, 1)
defer func() {
stopServerCh <- struct{}{}
}()
go StartServerApp(srvCh, stopServerCh, nil)
err := <-srvCh
s.assertNil(err)
- t.Log("server running")
- go StartClientApp(nil, clnCh)
- t.Log("client running")
+ s.log("server running")
+ go StartClientApp(nil, clnCh, clnRes)
+ s.log("client running")
+ s.log(<- clnRes)
err = <-clnCh
s.assertNil(err)
- t.Log("Test completed")
+ s.log("Test completed")
}
s.assertNil(err, "failed to run truncate command")
defer func() { os.Remove(srcFile) }()
- fmt.Println("Test file created...")
+ s.log("Test file created...")
go startHttpServer(serverRunning, stopServer, ":666", "server")
// TODO better error handling and recovery
stopServer <- struct{}{}
}(stopServer)
- fmt.Println("http server started...")
+ s.log("http server started...")
c := fmt.Sprintf("ip netns exec client wget --retry-connrefused --retry-on-http-error=503 --tries=10 -O %s 10.0.0.2:555/%s", outputFile, srcFile)
_, err = exechelper.CombinedOutput(c)
testVppProxy.setVppProxy()
err := testVppProxy.start()
s.assertNil(err, "failed to start and configure VPP")
- fmt.Println("VPP running and configured...")
+ s.log("VPP running and configured...")
output, err := testVppProxy.vppctl("test proxy server server-uri tcp://10.0.0.2/555 client-uri tcp://10.0.1.1/666")
- fmt.Println("Proxy configured...", string(output))
+ s.log("Proxy configured...", string(output))
return nil
}
envoyContainer := s.getContainerByName("envoy")
envoyContainer.run()
- fmt.Println("VPP running and configured...")
+ s.log("VPP running and configured...")
return nil
}
#!/usr/bin/env bash
source vars
-sudo -E go test -buildvcs=false -v $@
+
+for ARG in "$@"
+do
+ if [[ "$ARG" = "-p" ]]
+ then
+ export HST_PERSIST=1
+ shift
+ elif [[ "$ARG" = "-v" ]]
+ then
+ export HST_VERBOSE=1
+ shift
+ fi
+done
+
+sudo -E go test -buildvcs=false -v $@
cmd.Process.Kill()
}
-func StartClientApp(env []string, clnCh chan error) {
+func StartClientApp(env []string, clnCh chan error, clnRes chan string) {
defer func() {
clnCh <- nil
}()
nTries++
continue
} else {
- fmt.Printf("Client output: %s", o)
+ clnRes <- fmt.Sprintf("Client output: %s", o)
}
break
}
netNs)
o, err := cmd.CombinedOutput()
if err != nil {
- fmt.Printf("wget error: '%s'.\n%s", err, o)
+ finished <- errors.New(fmt.Sprintf("wget error: '%s'.\n%s", err, o))
return
}
- fmt.Printf("Client output: %s", o)
finished <- nil
}
package main
import (
- "fmt"
"time"
)
func (s *VethsSuite) TestVclEchoQuic() {
- s.T().Skip("quic test skipping..")
+ s.skip("quic test skipping..")
s.testVclEcho("quic")
}
func (s *VethsSuite) TestVclEchoUdp() {
- s.T().Skip("udp echo currently broken in vpp, skipping..")
+ s.skip("udp echo currently broken in vpp, skipping..")
s.testVclEcho("udp")
}
o, err := echoClnContainer.execAction("RunEchoClient "+proto)
s.assertNil(err)
- fmt.Println(o)
+ s.log(o)
}
func (s *VethsSuite) TestVclRetryAttach() {
- s.T().Skip()
+ s.skip()
s.testRetryAttach("tcp")
}
_, err = echoSrvContainer.execAction("RunVclEchoServer "+proto)
s.assertNil(err)
- fmt.Println("This whole test case can take around 3 minutes to run. Please be patient.")
- fmt.Println("... Running first echo client test, before disconnect.")
+ s.log("This whole test case can take around 3 minutes to run. Please be patient.")
+ s.log("... Running first echo client test, before disconnect.")
echoClnContainer := s.getContainerByName("client-application")
_, err = echoClnContainer.execAction("RunVclEchoClient "+proto)
s.assertNil(err)
- fmt.Println("... First test ended. Stopping VPP server now.")
+ s.log("... First test ended. Stopping VPP server now.")
// Stop server-vpp-instance, start it again and then run vcl-test-client once more
stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
_, err = srvVppContainer.execAction("Configure2Veths srv-with-preset-hw-addr")
s.assertNil(err)
- fmt.Println("... VPP server is starting again, so waiting for a bit.")
+ s.log("... VPP server is starting again, so waiting for a bit.")
time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
- fmt.Println("... Running second echo client test, after disconnect and re-attachment.")
+ s.log("... Running second echo client test, after disconnect and re-attachment.")
_, err = echoClnContainer.execAction("RunVclEchoClient "+proto)
s.assertNil(err)
- fmt.Println("Done.")
+ s.log("Done.")
}
func (s *VethsSuite) TestTcpWithLoss() {
s.assertNil(err)
s.assertEqual(true, len(output) != 0)
s.assertNotContains(output, "failed: timeout")
- fmt.Println(output)
+ s.log(output)
}