hsa: unify echo test setup
[vpp.git] / extras / hs-test / vcl_test.go
1 package main
2
3 import (
4         "fmt"
5         "time"
6 )
7
8 const vclTemplate = `vcl {
9   app-socket-api %[1]s/var/run/app_ns_sockets/%[2]s
10   app-scope-global
11   app-scope-local
12   namespace-id %[2]s
13   namespace-secret %[2]s
14   use-mq-eventfd
15 }
16 `
17
18 func (s *VethsSuite) TestXEchoVclClientUdp() {
19         s.testXEchoVclClient("udp")
20 }
21
22 func (s *VethsSuite) TestXEchoVclClientTcp() {
23         s.testXEchoVclClient("tcp")
24 }
25
26 func (s *VethsSuite) testXEchoVclClient(proto string) {
27         port := "12345"
28         serverVpp := s.getContainerByName("server-vpp").vppInstance
29
30         serverVeth := s.netInterfaces[serverInterfaceName]
31         serverVpp.vppctl("test echo server uri %s://%s/%s fifo-size 64k", proto, serverVeth.ip4AddressString(), port)
32
33         echoClnContainer := s.getTransientContainerByName("client-app")
34         clientVclConfContent := fmt.Sprintf(vclTemplate, echoClnContainer.getContainerWorkDir(), "2")
35         echoClnContainer.createFile("/vcl.conf", clientVclConfContent)
36
37         testClientCommand := "vcl_test_client -N 100 -p " + proto + " " + serverVeth.ip4AddressString() + " " + port
38         s.log(testClientCommand)
39         echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
40         o := echoClnContainer.exec(testClientCommand)
41         s.log(o)
42         s.assertContains(o, "CLIENT RESULTS")
43 }
44
45 func (s *VethsSuite) TestXEchoVclServerUdp() {
46         s.testXEchoVclServer("udp")
47 }
48
49 func (s *VethsSuite) TestXEchoVclServerTcp() {
50         s.testXEchoVclServer("tcp")
51 }
52
53 func (s *VethsSuite) testXEchoVclServer(proto string) {
54         port := "12345"
55         srvVppCont := s.getContainerByName("server-vpp")
56         srvAppCont := s.getContainerByName("server-app")
57
58         serverVclConfContent := fmt.Sprintf(vclTemplate, srvVppCont.getContainerWorkDir(), "1")
59         srvAppCont.createFile("/vcl.conf", serverVclConfContent)
60         srvAppCont.addEnvVar("VCL_CONFIG", "/vcl.conf")
61         vclSrvCmd := fmt.Sprintf("vcl_test_server -p %s %s", proto, port)
62         srvAppCont.execServer(vclSrvCmd)
63
64         serverVeth := s.netInterfaces[serverInterfaceName]
65         serverVethAddress := serverVeth.ip4AddressString()
66
67         clientVpp := s.getContainerByName("client-vpp").vppInstance
68         o := clientVpp.vppctl("test echo client uri %s://%s/%s fifo-size 64k verbose mbytes 2", proto, serverVethAddress, port)
69         s.log(o)
70         s.assertContains(o, "Test finished at")
71 }
72
73 func (s *VethsSuite) testVclEcho(proto string) {
74         port := "12345"
75         srvVppCont := s.getContainerByName("server-vpp")
76         srvAppCont := s.getContainerByName("server-app")
77
78         serverVclConfContent := fmt.Sprintf(vclTemplate, srvVppCont.getContainerWorkDir(), "1")
79         srvAppCont.createFile("/vcl.conf", serverVclConfContent)
80         srvAppCont.addEnvVar("VCL_CONFIG", "/vcl.conf")
81         srvAppCont.execServer("vcl_test_server " + port)
82
83         serverVeth := s.netInterfaces[serverInterfaceName]
84         serverVethAddress := serverVeth.ip4AddressString()
85
86         echoClnContainer := s.getTransientContainerByName("client-app")
87         clientVclConfContent := fmt.Sprintf(vclTemplate, echoClnContainer.getContainerWorkDir(), "2")
88         echoClnContainer.createFile("/vcl.conf", clientVclConfContent)
89
90         testClientCommand := "vcl_test_client -p " + proto + " " + serverVethAddress + " " + port
91         echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
92         o := echoClnContainer.exec(testClientCommand)
93         s.log(o)
94 }
95
96 func (s *VethsSuite) TestVclEchoTcp() {
97         s.testVclEcho("tcp")
98 }
99
100 func (s *VethsSuite) TestVclEchoUdp() {
101         s.testVclEcho("udp")
102 }
103
104 func (s *VethsSuite) TestVclRetryAttach() {
105         s.skip("this test takes too long, for now it's being skipped")
106         s.testRetryAttach("tcp")
107 }
108
109 func (s *VethsSuite) testRetryAttach(proto string) {
110         srvVppContainer := s.getTransientContainerByName("server-vpp")
111
112         echoSrvContainer := s.getContainerByName("server-app")
113
114         serverVclConfContent := fmt.Sprintf(vclTemplate, echoSrvContainer.getContainerWorkDir(), "1")
115         echoSrvContainer.createFile("/vcl.conf", serverVclConfContent)
116
117         echoSrvContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
118         echoSrvContainer.execServer("vcl_test_server -p " + proto + " 12346")
119
120         s.log("This whole test case can take around 3 minutes to run. Please be patient.")
121         s.log("... Running first echo client test, before disconnect.")
122
123         serverVeth := s.netInterfaces[serverInterfaceName]
124         serverVethAddress := serverVeth.ip4AddressString()
125
126         echoClnContainer := s.getTransientContainerByName("client-app")
127         clientVclConfContent := fmt.Sprintf(vclTemplate, echoClnContainer.getContainerWorkDir(), "2")
128         echoClnContainer.createFile("/vcl.conf", clientVclConfContent)
129
130         testClientCommand := "vcl_test_client -U -p " + proto + " " + serverVethAddress + " 12346"
131         echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
132         o := echoClnContainer.exec(testClientCommand)
133         s.log(o)
134         s.log("... First test ended. Stopping VPP server now.")
135
136         // Stop server-vpp-instance, start it again and then run vcl-test-client once more
137         srvVppContainer.vppInstance.disconnect()
138         stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
139         srvVppContainer.exec(stopVppCommand)
140
141         s.setupServerVpp()
142
143         s.log("... VPP server is starting again, so waiting for a bit.")
144         time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
145
146         s.log("... Running second echo client test, after disconnect and re-attachment.")
147         o = echoClnContainer.exec(testClientCommand)
148         s.log(o)
149         s.log("Done.")
150 }