blob: 03636b11191f5adc170f95446d1261d523994aa7 [file] [log] [blame]
Filip Tehlar229f5fc2022-08-09 14:44:47 +00001package main
2
3import (
4 "fmt"
Adrian Villincee15aa2024-03-14 11:42:55 -04005
Adrian Villin4677d922024-06-14 09:32:39 +02006 . "fd.io/hs-test/infra"
Adrian Villincee15aa2024-03-14 11:42:55 -04007 . "github.com/onsi/ginkgo/v2"
Filip Tehlar229f5fc2022-08-09 14:44:47 +00008)
9
Adrian Villincee15aa2024-03-14 11:42:55 -040010func init() {
Adrian Villind01a63a2024-08-15 12:53:53 +020011 RegisterLdpTests(LDPreloadIperfVppTest, LDPreloadIperfVppInterruptModeTest, RedisBenchmarkTest)
Adrian Villin1fde9992024-06-24 08:14:05 -040012}
13
Adrian Villind01a63a2024-08-15 12:53:53 +020014func LDPreloadIperfVppInterruptModeTest(s *LdpSuite) {
Adrian Villin1fde9992024-06-24 08:14:05 -040015 LDPreloadIperfVppTest(s)
Adrian Villincee15aa2024-03-14 11:42:55 -040016}
17
Adrian Villind01a63a2024-08-15 12:53:53 +020018func LDPreloadIperfVppTest(s *LdpSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +020019 clientContainer := s.GetContainerByName("client-vpp")
Adrian Villind01a63a2024-08-15 12:53:53 +020020 serverContainer := s.GetContainerByName("server-vpp")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000021
22 stopServerCh := make(chan struct{}, 1)
23 srvCh := make(chan error, 1)
24 clnCh := make(chan error)
Adrian Villind01a63a2024-08-15 12:53:53 +020025 clnRes := make(chan string, 1)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000026
Adrian Villincee15aa2024-03-14 11:42:55 -040027 go func() {
28 defer GinkgoRecover()
Adrian Villind01a63a2024-08-15 12:53:53 +020029 cmd := "iperf3 -4 -s -p " + s.GetPortFromPpid()
30 s.StartServerApp(serverContainer, "iperf3", cmd, srvCh, stopServerCh)
Adrian Villincee15aa2024-03-14 11:42:55 -040031 }()
Filip Tehlar229f5fc2022-08-09 14:44:47 +000032
Adrian Villind01a63a2024-08-15 12:53:53 +020033 err := <-srvCh
Adrian Villin4677d922024-06-14 09:32:39 +020034 s.AssertNil(err, fmt.Sprint(err))
Filip Tehlar229f5fc2022-08-09 14:44:47 +000035
Adrian Villin4677d922024-06-14 09:32:39 +020036 serverVethAddress := s.GetInterfaceByName(ServerInterfaceName).Ip4AddressString()
Adrian Villincee15aa2024-03-14 11:42:55 -040037 go func() {
38 defer GinkgoRecover()
Adrian Villind01a63a2024-08-15 12:53:53 +020039 cmd := "iperf3 -c " + serverVethAddress + " -u -l 1460 -b 10g -p " + s.GetPortFromPpid()
40 s.StartClientApp(clientContainer, cmd, clnCh, clnRes)
Adrian Villincee15aa2024-03-14 11:42:55 -040041 }()
Adrian Villin4677d922024-06-14 09:32:39 +020042 s.Log(<-clnRes)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000043
44 // wait for client's result
45 err = <-clnCh
Adrian Villin4677d922024-06-14 09:32:39 +020046 s.AssertNil(err, fmt.Sprint(err))
Filip Tehlar229f5fc2022-08-09 14:44:47 +000047
48 // stop server
49 stopServerCh <- struct{}{}
50}
Adrian Villind01a63a2024-08-15 12:53:53 +020051
52func RedisBenchmarkTest(s *LdpSuite) {
53 s.SkipIfMultiWorker()
54
55 serverContainer := s.GetContainerByName("server-vpp")
56 clientContainer := s.GetContainerByName("client-vpp")
57
58 serverVethAddress := s.GetInterfaceByName(ServerInterfaceName).Ip4AddressString()
59 runningSrv := make(chan error)
60 doneSrv := make(chan struct{})
61 clnCh := make(chan error)
62 clnRes := make(chan string, 1)
63
64 go func() {
65 defer GinkgoRecover()
66 cmd := "redis-server --daemonize yes --protected-mode no --bind " + serverVethAddress
67 s.StartServerApp(serverContainer, "redis-server", cmd, runningSrv, doneSrv)
68 }()
69
70 err := <-runningSrv
71 s.AssertNil(err)
72
73 go func() {
74 defer GinkgoRecover()
75 var cmd string
76 if *NConfiguredCpus == 1 {
77 cmd = "redis-benchmark --threads 1 -h " + serverVethAddress
78 } else {
79 cmd = "redis-benchmark --threads " + fmt.Sprint(*NConfiguredCpus) + "-h " + serverVethAddress
80 }
81 s.StartClientApp(clientContainer, cmd, clnCh, clnRes)
82 }()
83
84 s.Log(<-clnRes)
85 // wait for client's result
86 err = <-clnCh
87 s.AssertNil(err, fmt.Sprint(err))
88 // stop server
89 doneSrv <- struct{}{}
90}