aboutsummaryrefslogtreecommitdiffstats
path: root/extras/hs-test
diff options
context:
space:
mode:
authorFilip Tehlar <ftehlar@cisco.com>2022-11-22 12:49:22 +0100
committerFlorin Coras <florin.coras@gmail.com>2022-11-25 00:37:20 +0000
commit1a9dc75fe8099fdde9b1dd248a8fca35b001f9fc (patch)
tree729ad4b6b531ca3905434e1cbb4a950fff18dad6 /extras/hs-test
parentb79d09bbfa93f0f752f7249ad27a08eae0863a6b (diff)
hs-test: auto register test actions
Type: improvement Signed-off-by: Filip Tehlar <ftehlar@cisco.com> Change-Id: Icb5db6f69eda93181aba69b1f8676a73c0a4561b
Diffstat (limited to 'extras/hs-test')
-rwxr-xr-xextras/hs-test/actions.go49
-rwxr-xr-xextras/hs-test/echo_test.go8
-rwxr-xr-xextras/hs-test/framework_test.go1
-rwxr-xr-xextras/hs-test/http_test.go10
-rwxr-xr-xextras/hs-test/ldp_test.go8
-rwxr-xr-xextras/hs-test/main.go28
-rwxr-xr-xextras/hs-test/proxy_test.go8
-rwxr-xr-xextras/hs-test/vcl_test.go28
8 files changed, 62 insertions, 78 deletions
diff --git a/extras/hs-test/actions.go b/extras/hs-test/actions.go
index 1f35ee7df15..9885f87b87d 100755
--- a/extras/hs-test/actions.go
+++ b/extras/hs-test/actions.go
@@ -19,20 +19,9 @@ import (
"github.com/edwarnicke/vpphelper"
)
-func RegisterActions() {
- cfgTable = make(map[string]func([]string) *ActionResult)
- reg("echo-srv-internal", Configure2Veths)
- reg("echo-cln-internal", Configure2Veths)
- reg("echo-client", RunEchoClient)
- reg("echo-server", RunEchoServer)
- reg("vpp-proxy", ConfigureVppProxy)
- reg("vpp-envoy", ConfigureEnvoyProxy)
- reg("http-tps", ConfigureHttpTps)
- reg("2veths", Configure2Veths)
- reg("vcl-test-server", RunVclEchoServer)
- reg("vcl-test-client", RunVclEchoClient)
- reg("http-cli-srv", RunHttpCliSrv)
- reg("http-cli-cln", RunHttpCliCln)
+type ConfFn func(context.Context, api.Connection) error
+
+type Actions struct {
}
func configureProxyTcp(ifName0, ipAddr0, ifName1, ipAddr1 string) ConfFn {
@@ -53,18 +42,18 @@ func configureProxyTcp(ifName0, ipAddr0, ifName1, ipAddr1 string) ConfFn {
}
}
-func RunHttpCliSrv(args []string) *ActionResult {
+func (a *Actions) RunHttpCliSrv(args []string) *ActionResult {
cmd := fmt.Sprintf("http cli server")
- return ApiCliInband("/tmp/2veths", cmd)
+ return ApiCliInband("/tmp/Configure2Veths", cmd)
}
-func RunHttpCliCln(args []string) *ActionResult {
+func (a *Actions) RunHttpCliCln(args []string) *ActionResult {
cmd := fmt.Sprintf("http cli client uri http://10.10.10.1/80 query %s", getArgs())
fmt.Println(cmd)
- return ApiCliInband("/tmp/2veths", cmd)
+ return ApiCliInband("/tmp/Configure2Veths", cmd)
}
-func ConfigureVppProxy(args []string) *ActionResult {
+func (a *Actions) ConfigureVppProxy(args []string) *ActionResult {
ctx, cancel := newVppContext()
defer cancel()
@@ -81,7 +70,7 @@ func ConfigureVppProxy(args []string) *ActionResult {
return nil
}
-func ConfigureEnvoyProxy(args []string) *ActionResult {
+func (a *Actions) ConfigureEnvoyProxy(args []string) *ActionResult {
var startup Stanza
startup.
NewStanza("session").
@@ -127,7 +116,7 @@ func ApiCliInband(root, cmd string) *ActionResult {
return NewActionResult(err, ActionResultWithStdout(cliInbandReply.Reply))
}
-func RunEchoClient(args []string) *ActionResult {
+func (a *Actions) RunEchoClient(args []string) *ActionResult {
outBuff := bytes.NewBuffer([]byte{})
errBuff := bytes.NewBuffer([]byte{})
@@ -140,7 +129,7 @@ func RunEchoClient(args []string) *ActionResult {
ActionResultWithStderr(string(errBuff.String())))
}
-func RunEchoServer(args []string) *ActionResult {
+func (a *Actions) RunEchoServer(args []string) *ActionResult {
cmd := fmt.Sprintf("vpp_echo server TX=RX socket-name /tmp/echo-srv/var/run/app_ns_sockets/1 use-app-socket-api uri %s://10.10.10.1/12344", args[2])
errCh := exechelper.Start(cmd)
select {
@@ -152,17 +141,17 @@ func RunEchoServer(args []string) *ActionResult {
return nil
}
-func RunEchoSrvInternal() *ActionResult {
+func (a *Actions) RunEchoSrvInternal(args []string) *ActionResult {
cmd := fmt.Sprintf("test echo server %s uri tcp://10.10.10.1/1234", getArgs())
- return ApiCliInband("/tmp/2veths", cmd)
+ return ApiCliInband("/tmp/Configure2Veths", cmd)
}
-func RunEchoClnInternal() *ActionResult {
+func (a *Actions) RunEchoClnInternal(args []string) *ActionResult {
cmd := fmt.Sprintf("test echo client %s uri tcp://10.10.10.1/1234", getArgs())
- return ApiCliInband("/tmp/2veths", cmd)
+ return ApiCliInband("/tmp/Configure2Veths", cmd)
}
-func RunVclEchoServer(args []string) *ActionResult {
+func (a *Actions) RunVclEchoServer(args []string) *ActionResult {
f, err := os.Create("vcl_1.conf")
if err != nil {
return NewActionResult(err, ActionResultWithStderr(("create vcl config: ")))
@@ -182,7 +171,7 @@ func RunVclEchoServer(args []string) *ActionResult {
return nil
}
-func RunVclEchoClient(args []string) *ActionResult {
+func (a *Actions) RunVclEchoClient(args []string) *ActionResult {
outBuff := bytes.NewBuffer([]byte{})
errBuff := bytes.NewBuffer([]byte{})
@@ -238,7 +227,7 @@ func configure2vethsTopo(ifName, interfaceAddress, namespaceId string, secret ui
}
}
-func Configure2Veths(args []string) *ActionResult {
+func (a *Actions) Configure2Veths(args []string) *ActionResult {
var startup Stanza
startup.
NewStanza("session").
@@ -317,7 +306,7 @@ func configureAfPacket(ctx context.Context, vppCon api.Connection,
return afPacketCreateRsp.SwIfIndex, nil
}
-func ConfigureHttpTps(args []string) *ActionResult {
+func (a *Actions) ConfigureHttpTps(args []string) *ActionResult {
ctx, cancel := newVppContext()
defer cancel()
con, vppErrCh := vpphelper.StartAndDialContext(ctx,
diff --git a/extras/hs-test/echo_test.go b/extras/hs-test/echo_test.go
index 55f75007590..74ff4cb0d6e 100755
--- a/extras/hs-test/echo_test.go
+++ b/extras/hs-test/echo_test.go
@@ -24,25 +24,25 @@ func (s *Veths2Suite) TestEchoBuiltin() {
}
defer func() { exechelper.Run("docker stop " + clnInstance) }()
- _, err = hstExec("2veths srv", srvInstance)
+ _, err = hstExec("Configure2Veths srv", srvInstance)
if err != nil {
t.Errorf("%v", err)
return
}
- _, err = hstExec("2veths cln", clnInstance)
+ _, err = hstExec("Configure2Veths cln", clnInstance)
if err != nil {
t.Errorf("%v", err)
return
}
- _, err = hstExec("echo-srv-internal private-segment-size 1g fifo-size 4 no-echo", srvInstance)
+ _, err = hstExec("RunEchoSrvInternal private-segment-size 1g fifo-size 4 no-echo", srvInstance)
if err != nil {
t.Errorf("%v", err)
return
}
- o, err := hstExec("echo-cln-internal nclients 10000 bytes 1 syn-timeout 100 test-timeout 100 no-return private-segment-size 1g fifo-size 4", clnInstance)
+ o, err := hstExec("RunEchoClnInternal nclients 10000 bytes 1 syn-timeout 100 test-timeout 100 no-return private-segment-size 1g fifo-size 4", clnInstance)
if err != nil {
t.Errorf("%v", err)
return
diff --git a/extras/hs-test/framework_test.go b/extras/hs-test/framework_test.go
index 78a289265be..38003925f2f 100755
--- a/extras/hs-test/framework_test.go
+++ b/extras/hs-test/framework_test.go
@@ -78,5 +78,4 @@ func TestNs(t *testing.T) {
func TestVeths2(t *testing.T) {
var m Veths2Suite
suite.Run(t, &m)
-
}
diff --git a/extras/hs-test/http_test.go b/extras/hs-test/http_test.go
index fbbd64aa31e..bd93736376d 100755
--- a/extras/hs-test/http_test.go
+++ b/extras/hs-test/http_test.go
@@ -23,7 +23,7 @@ func (s *NsSuite) TestHttpTps() {
defer func() { exechelper.Run("docker stop " + dockerInstance) }()
// start & configure vpp in the container
- _, err = hstExec(dockerInstance, dockerInstance)
+ _, err = hstExec("ConfigureHttpTps", dockerInstance)
if err != nil {
t.Errorf("%v", err)
return
@@ -56,13 +56,13 @@ func (s *Veths2Suite) TestHttpCli() {
}
defer func() { exechelper.Run("docker stop " + clnInstance) }()
- _, err = hstExec("2veths srv", srvInstance)
+ _, err = hstExec("Configure2Veths srv", srvInstance)
if err != nil {
t.Errorf("%v", err)
return
}
- _, err = hstExec("2veths cln", clnInstance)
+ _, err = hstExec("Configure2Veths cln", clnInstance)
if err != nil {
t.Errorf("%v", err)
return
@@ -70,7 +70,7 @@ func (s *Veths2Suite) TestHttpCli() {
t.Log("configured IPs...")
- _, err = hstExec("http-cli-srv", srvInstance)
+ _, err = hstExec("RunHttpCliSrv", srvInstance)
if err != nil {
t.Errorf("%v", err)
return
@@ -78,7 +78,7 @@ func (s *Veths2Suite) TestHttpCli() {
t.Log("configured http server")
- o, err := hstExec("http-cli-cln /show/version", clnInstance)
+ o, err := hstExec("RunHttpCliCln /show/version", clnInstance)
if err != nil {
t.Errorf("%v", err)
return
diff --git a/extras/hs-test/ldp_test.go b/extras/hs-test/ldp_test.go
index 0783b189522..13c102e0633 100755
--- a/extras/hs-test/ldp_test.go
+++ b/extras/hs-test/ldp_test.go
@@ -47,13 +47,13 @@ func (s *Veths2Suite) TestLDPreloadIperfVpp() {
}
defer func() { exechelper.Run("docker stop " + clnInstance) }()
- _, err = hstExec("2veths srv", srvInstance)
+ _, err = hstExec("Configure2Veths srv", srvInstance)
if err != nil {
t.Errorf("%v", err)
return
}
- _, err = hstExec("2veths cln", clnInstance)
+ _, err = hstExec("Configure2Veths cln", clnInstance)
if err != nil {
t.Errorf("%v", err)
return
@@ -66,7 +66,7 @@ func (s *Veths2Suite) TestLDPreloadIperfVpp() {
Append("app-scope-local").
Append("app-scope-global").
Append("use-mq-eventfd").
- Append(fmt.Sprintf("app-socket-api /tmp/%s/2veths/var/run/app_ns_sockets/2", clnInstance)).Close().
+ Append(fmt.Sprintf("app-socket-api /tmp/%s/Configure2Veths/var/run/app_ns_sockets/2", clnInstance)).Close().
SaveToFile(clnVcl)
if err != nil {
t.Errorf("%v", err)
@@ -80,7 +80,7 @@ func (s *Veths2Suite) TestLDPreloadIperfVpp() {
Append("app-scope-local").
Append("app-scope-global").
Append("use-mq-eventfd").
- Append(fmt.Sprintf("app-socket-api /tmp/%s/2veths/var/run/app_ns_sockets/1", srvInstance)).Close().
+ Append(fmt.Sprintf("app-socket-api /tmp/%s/Configure2Veths/var/run/app_ns_sockets/1", srvInstance)).Close().
SaveToFile(srvVcl)
if err != nil {
t.Errorf("%v", err)
diff --git a/extras/hs-test/main.go b/extras/hs-test/main.go
index f54b6c4d910..9de0d314cb2 100755
--- a/extras/hs-test/main.go
+++ b/extras/hs-test/main.go
@@ -7,15 +7,10 @@ import (
"os"
"os/exec"
"os/signal"
-
- "git.fd.io/govpp.git/api"
+ "reflect"
)
-type CfgTable map[string]func([]string) *ActionResult
-
-var cfgTable CfgTable
-
-type ConfFn func(context.Context, api.Connection) error
+var actions Actions
func newVppContext() (context.Context, context.CancelFunc) {
ctx, cancel := signal.NotifyContext(
@@ -116,15 +111,18 @@ func OkResult() *ActionResult {
return NewActionResult(nil)
}
-func reg(key string, fn func([]string) *ActionResult) {
- cfgTable[key] = fn
-}
-
func processArgs() *ActionResult {
- fn := cfgTable[os.Args[1]]
- if fn == nil {
- return NewActionResult(fmt.Errorf("internal: no config found for %s", os.Args[1]))
+ nArgs := len(os.Args) - 1 // skip program name
+ if nArgs < 1 {
+ return NewActionResult(fmt.Errorf("internal: no action specified!"))
+ }
+ action := os.Args[1]
+ methodValue := reflect.ValueOf(&actions).MethodByName(action)
+ if !methodValue.IsValid() {
+ return NewActionResult(fmt.Errorf("internal unknown action %s!", action))
}
+ methodIface := methodValue.Interface()
+ fn := methodIface.(func([]string) *ActionResult)
return fn(os.Args)
}
@@ -144,8 +142,6 @@ func main() {
os.Exit(0)
}
- RegisterActions()
-
var err error
res := processArgs()
err = writeSyncFile(res)
diff --git a/extras/hs-test/proxy_test.go b/extras/hs-test/proxy_test.go
index 797de5255fa..d426b61a33f 100755
--- a/extras/hs-test/proxy_test.go
+++ b/extras/hs-test/proxy_test.go
@@ -9,7 +9,7 @@ import (
"github.com/edwarnicke/exechelper"
)
-func testProxyHttpTcp(t *testing.T, dockerInstance string, proxySetup func() error) error {
+func testProxyHttpTcp(t *testing.T, dockerInstance, action string, proxySetup func() error) error {
const outputFile = "test.data"
const srcFile = "10M"
stopServer := make(chan struct{}, 1)
@@ -23,7 +23,7 @@ func testProxyHttpTcp(t *testing.T, dockerInstance string, proxySetup func() err
defer func() { exechelper.Run("docker stop " + dockerInstance) }()
// start & configure vpp in the container
- _, err = hstExec(dockerInstance, dockerInstance)
+ _, err = hstExec(action, dockerInstance)
if err != nil {
return fmt.Errorf("error starting vpp in container: %v", err)
}
@@ -72,7 +72,7 @@ func testProxyHttpTcp(t *testing.T, dockerInstance string, proxySetup func() err
func (s *NsSuite) TestVppProxyHttpTcp() {
t := s.T()
dockerInstance := "vpp-proxy"
- err := testProxyHttpTcp(t, dockerInstance, configureVppProxy)
+ err := testProxyHttpTcp(t, dockerInstance, "ConfigureVppProxy", configureVppProxy)
if err != nil {
t.Errorf("%v", err)
}
@@ -88,7 +88,7 @@ func (s *NsSuite) TestEnvoyProxyHttpTcp() {
ctx, cancel := context.WithCancel(context.Background())
dockerInstance := "vpp-envoy"
- err := testProxyHttpTcp(t, dockerInstance, func() error {
+ err := testProxyHttpTcp(t, dockerInstance, "ConfigureEnvoyProxy", func() error {
return setupEnvoy(t, ctx, dockerInstance)
})
if err != nil {
diff --git a/extras/hs-test/vcl_test.go b/extras/hs-test/vcl_test.go
index fddd70d49d8..f699a65295c 100755
--- a/extras/hs-test/vcl_test.go
+++ b/extras/hs-test/vcl_test.go
@@ -32,14 +32,14 @@ func (s *Veths2Suite) testVclEcho(proto string) {
echoSrv := "echo-srv"
echoCln := "echo-cln"
- err := dockerRun(srvInstance, "-v echo-srv-vol:/tmp/2veths")
+ err := dockerRun(srvInstance, "-v echo-srv-vol:/tmp/Configure2Veths")
if err != nil {
t.Errorf("%v", err)
return
}
defer func() { exechelper.Run("docker stop " + srvInstance) }()
- err = dockerRun(clnInstance, "-v echo-cln-vol:/tmp/2veths")
+ err = dockerRun(clnInstance, "-v echo-cln-vol:/tmp/Configure2Veths")
if err != nil {
t.Errorf("%v", err)
return
@@ -60,26 +60,26 @@ func (s *Veths2Suite) testVclEcho(proto string) {
}
defer func() { exechelper.Run("docker stop " + echoCln) }()
- _, err = hstExec("2veths srv", srvInstance)
+ _, err = hstExec("Configure2Veths srv", srvInstance)
if err != nil {
t.Errorf("%v", err)
return
}
- _, err = hstExec("2veths cln", clnInstance)
+ _, err = hstExec("Configure2Veths cln", clnInstance)
if err != nil {
t.Errorf("%v", err)
return
}
// run server app
- _, err = hstExec("echo-server "+proto, echoSrv)
+ _, err = hstExec("RunEchoServer "+proto, echoSrv)
if err != nil {
t.Errorf("echo server: %v", err)
return
}
- o, err := hstExec("echo-client "+proto, echoCln)
+ o, err := hstExec("RunEchoClient "+proto, echoCln)
if err != nil {
t.Errorf("echo client: %v", err)
}
@@ -102,14 +102,14 @@ func (s *Veths2Suite) testRetryAttach(proto string) {
echoSrv := "echo-srv"
echoCln := "echo-cln"
- err := dockerRun(srvInstance, "-v echo-srv-vol:/tmp/2veths")
+ err := dockerRun(srvInstance, "-v echo-srv-vol:/tmp/Configure2Veths")
if err != nil {
t.Errorf("%v", err)
return
}
defer func() { exechelper.Run("docker stop " + srvInstance) }()
- err = dockerRun(clnInstance, "-v echo-cln-vol:/tmp/2veths")
+ err = dockerRun(clnInstance, "-v echo-cln-vol:/tmp/Configure2Veths")
if err != nil {
t.Errorf("%v", err)
return
@@ -130,19 +130,19 @@ func (s *Veths2Suite) testRetryAttach(proto string) {
}
defer func() { exechelper.Run("docker stop " + echoCln) }()
- _, err = hstExec("2veths srv-with-preset-hw-addr", srvInstance)
+ _, err = hstExec("Configure2Veths srv-with-preset-hw-addr", srvInstance)
if err != nil {
t.Errorf("%v", err)
return
}
- _, err = hstExec("2veths cln", clnInstance)
+ _, err = hstExec("Configure2Veths cln", clnInstance)
if err != nil {
t.Errorf("%v", err)
return
}
- _, err = hstExec("vcl-test-server "+proto, echoSrv)
+ _, err = hstExec("RunVclEchoServer "+proto, echoSrv)
if err != nil {
t.Errorf("vcl test server: %v", err)
return
@@ -150,7 +150,7 @@ func (s *Veths2Suite) testRetryAttach(proto string) {
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.")
- _, err = hstExec("vcl-test-client "+proto, echoCln)
+ _, err = hstExec("RunVclEchoClient "+proto, echoCln)
if err != nil {
t.Errorf("vcl test client: %v", err)
return
@@ -171,7 +171,7 @@ func (s *Veths2Suite) testRetryAttach(proto string) {
t.Errorf("error while stopping hs-test: %v", err)
return
}
- _, err = hstExec("2veths srv-with-preset-hw-addr", srvInstance)
+ _, err = hstExec("Configure2Veths srv-with-preset-hw-addr", srvInstance)
if err != nil {
t.Errorf("%v", err)
return
@@ -181,7 +181,7 @@ func (s *Veths2Suite) testRetryAttach(proto string) {
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.")
- _, err = hstExec("vcl-test-client "+proto, echoCln)
+ _, err = hstExec("RunVclEchoClient "+proto, echoCln)
if err != nil {
t.Errorf("vcl test client: %v", err)
}