blob: e9e8bba92745dc38cadeab09e9b9f42632d5f37a [file] [log] [blame]
Filip Tehlar229f5fc2022-08-09 14:44:47 +00001package main
2
3import (
4 "fmt"
5 "os"
Adrian Villincee15aa2024-03-14 11:42:55 -04006
Adrian Villin4677d922024-06-14 09:32:39 +02007 . "fd.io/hs-test/infra"
Adrian Villincee15aa2024-03-14 11:42:55 -04008 . "github.com/onsi/ginkgo/v2"
Filip Tehlar229f5fc2022-08-09 14:44:47 +00009)
10
Adrian Villincee15aa2024-03-14 11:42:55 -040011func init() {
Adrian Villin1fde9992024-06-24 08:14:05 -040012 RegisterVethTests(LDPreloadIperfVppTest, LDPreloadIperfVppInterruptModeTest)
13}
14
15func LDPreloadIperfVppInterruptModeTest(s *VethsSuite) {
16 LDPreloadIperfVppTest(s)
Adrian Villincee15aa2024-03-14 11:42:55 -040017}
18
19func LDPreloadIperfVppTest(s *VethsSuite) {
Filip Tehlar229f5fc2022-08-09 14:44:47 +000020 var clnVclConf, srvVclConf Stanza
Adrian Villinb4516bb2024-06-19 06:20:00 -040021 var ldpreload string
Filip Tehlar229f5fc2022-08-09 14:44:47 +000022
Adrian Villin4677d922024-06-14 09:32:39 +020023 serverContainer := s.GetContainerByName("server-vpp")
24 serverVclFileName := serverContainer.GetHostWorkDir() + "/vcl_srv.conf"
Filip Tehlar229f5fc2022-08-09 14:44:47 +000025
Adrian Villin4677d922024-06-14 09:32:39 +020026 clientContainer := s.GetContainerByName("client-vpp")
27 clientVclFileName := clientContainer.GetHostWorkDir() + "/vcl_cln.conf"
Filip Tehlar229f5fc2022-08-09 14:44:47 +000028
Adrian Villinb4516bb2024-06-19 06:20:00 -040029 if *IsDebugBuild {
30 ldpreload = "LD_PRELOAD=../../build-root/build-vpp_debug-native/vpp/lib/x86_64-linux-gnu/libvcl_ldpreload.so"
31 } else {
32 ldpreload = "LD_PRELOAD=../../build-root/build-vpp-native/vpp/lib/x86_64-linux-gnu/libvcl_ldpreload.so"
33 }
Filip Tehlar229f5fc2022-08-09 14:44:47 +000034
35 stopServerCh := make(chan struct{}, 1)
36 srvCh := make(chan error, 1)
37 clnCh := make(chan error)
38
Adrian Villin4677d922024-06-14 09:32:39 +020039 s.Log("starting VPPs")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000040
Filip Tehlar5ebdd512023-12-14 13:06:54 +010041 clientAppSocketApi := fmt.Sprintf("app-socket-api %s/var/run/app_ns_sockets/default",
Adrian Villin4677d922024-06-14 09:32:39 +020042 clientContainer.GetHostWorkDir())
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010043 err := clnVclConf.
Adrian Villin4677d922024-06-14 09:32:39 +020044 NewStanza("vcl").
45 Append("rx-fifo-size 4000000").
46 Append("tx-fifo-size 4000000").
47 Append("app-scope-local").
48 Append("app-scope-global").
49 Append("use-mq-eventfd").
50 Append(clientAppSocketApi).Close().
51 SaveToFile(clientVclFileName)
52 s.AssertNil(err, fmt.Sprint(err))
Filip Tehlar229f5fc2022-08-09 14:44:47 +000053
Filip Tehlar5ebdd512023-12-14 13:06:54 +010054 serverAppSocketApi := fmt.Sprintf("app-socket-api %s/var/run/app_ns_sockets/default",
Adrian Villin4677d922024-06-14 09:32:39 +020055 serverContainer.GetHostWorkDir())
Filip Tehlar229f5fc2022-08-09 14:44:47 +000056 err = srvVclConf.
Adrian Villin4677d922024-06-14 09:32:39 +020057 NewStanza("vcl").
58 Append("rx-fifo-size 4000000").
59 Append("tx-fifo-size 4000000").
60 Append("app-scope-local").
61 Append("app-scope-global").
62 Append("use-mq-eventfd").
63 Append(serverAppSocketApi).Close().
64 SaveToFile(serverVclFileName)
65 s.AssertNil(err, fmt.Sprint(err))
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010066
Adrian Villin4677d922024-06-14 09:32:39 +020067 s.Log("attaching server to vpp")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000068
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010069 srvEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+serverVclFileName)
Adrian Villincee15aa2024-03-14 11:42:55 -040070 go func() {
71 defer GinkgoRecover()
Adrian Villin4677d922024-06-14 09:32:39 +020072 s.StartServerApp(srvCh, stopServerCh, srvEnv)
Adrian Villincee15aa2024-03-14 11:42:55 -040073 }()
Filip Tehlar229f5fc2022-08-09 14:44:47 +000074
75 err = <-srvCh
Adrian Villin4677d922024-06-14 09:32:39 +020076 s.AssertNil(err, fmt.Sprint(err))
Filip Tehlar229f5fc2022-08-09 14:44:47 +000077
Adrian Villin4677d922024-06-14 09:32:39 +020078 s.Log("attaching client to vpp")
Maros Ondrejicka87531802022-12-19 20:35:27 +010079 var clnRes = make(chan string, 1)
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010080 clnEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+clientVclFileName)
Adrian Villin4677d922024-06-14 09:32:39 +020081 serverVethAddress := s.GetInterfaceByName(ServerInterfaceName).Ip4AddressString()
Adrian Villincee15aa2024-03-14 11:42:55 -040082 go func() {
83 defer GinkgoRecover()
Adrian Villin4677d922024-06-14 09:32:39 +020084 s.StartClientApp(serverVethAddress, clnEnv, clnCh, clnRes)
Adrian Villincee15aa2024-03-14 11:42:55 -040085 }()
Adrian Villin4677d922024-06-14 09:32:39 +020086 s.Log(<-clnRes)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000087
88 // wait for client's result
89 err = <-clnCh
Adrian Villin4677d922024-06-14 09:32:39 +020090 s.AssertNil(err, fmt.Sprint(err))
Filip Tehlar229f5fc2022-08-09 14:44:47 +000091
92 // stop server
93 stopServerCh <- struct{}{}
94}