blob: 2bcbcf3387e6229b4beea042415d8716b80b35ae [file] [log] [blame]
Dave Wallaceb063ad02019-04-09 21:01:09 -04001#!/usr/bin/env python
Dave Wallace3bffd4b2019-05-13 15:51:52 -04002""" Vpp QUIC tests """
Dave Wallaceb063ad02019-04-09 21:01:09 -04003
4import unittest
Dave Wallace211b28a2019-05-08 20:46:33 -04005import os
Dave Wallace3bffd4b2019-05-13 15:51:52 -04006import subprocess
7import signal
8from framework import VppTestCase, VppTestRunner, running_extended_tests, \
9 Worker
Dave Wallaceb063ad02019-04-09 21:01:09 -040010from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
Dave Wallace47e77302019-06-05 10:40:07 -040011from threading import Event
Dave Wallaceb063ad02019-04-09 21:01:09 -040012
13
Dave Wallace3bffd4b2019-05-13 15:51:52 -040014class QUICAppWorker(Worker):
15 """ QUIC Test Application Worker """
Dave Wallace47e77302019-06-05 10:40:07 -040016 process = None
Dave Wallace3bffd4b2019-05-13 15:51:52 -040017
Dave Wallace47e77302019-06-05 10:40:07 -040018 def __init__(self, build_dir, appname, args, logger, env={}, event=None):
Dave Wallace3bffd4b2019-05-13 15:51:52 -040019 app = "%s/vpp/bin/%s" % (build_dir, appname)
20 self.args = [app] + args
Dave Wallace47e77302019-06-05 10:40:07 -040021 self.event = event
Dave Wallace3bffd4b2019-05-13 15:51:52 -040022 super(QUICAppWorker, self).__init__(self.args, logger, env)
23
Dave Wallace47e77302019-06-05 10:40:07 -040024 def run(self):
25 super(QUICAppWorker, self).run()
26 if self.event:
27 self.event.set()
28
29 def teardown(self, logger, timeout):
30 if self.process is None:
31 return False
32 try:
33 logger.debug("Killing worker process (pid %d)" % self.process.pid)
34 os.killpg(os.getpgid(self.process.pid), signal.SIGKILL)
35 self.join(timeout)
36 except OSError as e:
37 logger.debug("Couldn't kill worker process")
38 return True
39 return False
40
Dave Wallace3bffd4b2019-05-13 15:51:52 -040041
Dave Wallace211b28a2019-05-08 20:46:33 -040042class QUICTestCase(VppTestCase):
Dave Wallaceb063ad02019-04-09 21:01:09 -040043 """ QUIC Test Case """
44
Dave Wallaceb063ad02019-04-09 21:01:09 -040045 def setUp(self):
Dave Wallace47e77302019-06-05 10:40:07 -040046 super(QUICTestCase, self).setUp()
Dave Wallace211b28a2019-05-08 20:46:33 -040047 var = "VPP_BUILD_DIR"
48 self.build_dir = os.getenv(var, None)
49 if self.build_dir is None:
50 raise Exception("Environment variable `%s' not set" % var)
51 self.vppDebug = 'vpp_debug' in self.build_dir
52 self.timeout = 20
Dave Wallaceb063ad02019-04-09 21:01:09 -040053 self.vapi.session_enable_disable(is_enabled=1)
Dave Wallace47e77302019-06-05 10:40:07 -040054 self.pre_test_sleep = 0.3
55 self.post_test_sleep = 0.2
Dave Wallace211b28a2019-05-08 20:46:33 -040056
Dave Wallaceb063ad02019-04-09 21:01:09 -040057 self.create_loopback_interfaces(2)
Dave Wallace211b28a2019-05-08 20:46:33 -040058 self.uri = "quic://%s/1234" % self.loop0.local_ip4
Dave Wallaceb063ad02019-04-09 21:01:09 -040059 table_id = 1
Dave Wallaceb063ad02019-04-09 21:01:09 -040060 for i in self.lo_interfaces:
61 i.admin_up()
62
63 if table_id != 0:
64 tbl = VppIpTable(self, table_id)
65 tbl.add_vpp_config()
66
67 i.set_table_ip4(table_id)
68 i.config_ip4()
69 table_id += 1
70
71 # Configure namespaces
Dave Wallace211b28a2019-05-08 20:46:33 -040072 self.vapi.app_namespace_add_del(namespace_id=b"server",
Dave Wallaceb063ad02019-04-09 21:01:09 -040073 sw_if_index=self.loop0.sw_if_index)
Dave Wallace211b28a2019-05-08 20:46:33 -040074 self.vapi.app_namespace_add_del(namespace_id=b"client",
Dave Wallaceb063ad02019-04-09 21:01:09 -040075 sw_if_index=self.loop1.sw_if_index)
76
Dave Wallace211b28a2019-05-08 20:46:33 -040077 # Add inter-table routes
78 self.ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32,
79 [VppRoutePath("0.0.0.0",
80 0xffffffff,
81 nh_table_id=2)], table_id=1)
82 self.ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32,
83 [VppRoutePath("0.0.0.0",
84 0xffffffff,
85 nh_table_id=1)], table_id=2)
86 self.ip_t01.add_vpp_config()
87 self.ip_t10.add_vpp_config()
88 self.logger.debug(self.vapi.cli("show ip fib"))
89
Dave Wallace47e77302019-06-05 10:40:07 -040090 def tearDown(self):
91 self.vapi.session_enable_disable(is_enabled=0)
Dave Wallace211b28a2019-05-08 20:46:33 -040092 # Delete inter-table routes
93 self.ip_t01.remove_vpp_config()
94 self.ip_t10.remove_vpp_config()
95
Dave Wallaceb063ad02019-04-09 21:01:09 -040096 for i in self.lo_interfaces:
97 i.unconfig_ip4()
98 i.set_table_ip4(0)
99 i.admin_down()
Dave Wallace47e77302019-06-05 10:40:07 -0400100 super(QUICTestCase, self).tearDown()
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400101
Dave Wallace211b28a2019-05-08 20:46:33 -0400102
Dave Wallace47e77302019-06-05 10:40:07 -0400103class QUICEchoInternalTestCase(QUICTestCase):
104 """QUIC Echo Internal Test Case"""
Dave Wallace211b28a2019-05-08 20:46:33 -0400105 def setUp(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400106 super(QUICEchoInternalTestCase, self).setUp()
107 self.client_args = "uri %s fifo-size 64 test-bytes appns client" % self.uri
108 self.server_args = "uri %s fifo-size 64 appns server" % self.uri
Dave Wallace211b28a2019-05-08 20:46:33 -0400109
Dave Wallace47e77302019-06-05 10:40:07 -0400110 def server(self, *args):
111 error = self.vapi.cli("test echo server %s %s" % (self.server_args, ' '.join(args)))
112 if error:
113 self.logger.critical(error)
114 self.assertNotIn("failed", error)
Dave Wallace211b28a2019-05-08 20:46:33 -0400115
Dave Wallace47e77302019-06-05 10:40:07 -0400116 def client(self, *args):
117 error = self.vapi.cli("test echo client %s %s" % (self.client_args, ' '.join(args)))
118 if error:
119 self.logger.critical(error)
120 self.assertNotIn("failed", error)
Dave Wallaceb063ad02019-04-09 21:01:09 -0400121
Dave Wallace47e77302019-06-05 10:40:07 -0400122class QUICEchoInternalTransferTestCase(QUICEchoInternalTestCase):
123 """QUIC Echo Internal Transfer Test Case"""
Dave Wallaceb063ad02019-04-09 21:01:09 -0400124 @unittest.skipUnless(running_extended_tests, "part of extended tests")
Dave Wallace211b28a2019-05-08 20:46:33 -0400125 def test_quic_internal_transfer(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400126 self.server()
127 self.client("no-output", "mbytes", "10")
Dave Wallaceb063ad02019-04-09 21:01:09 -0400128
Dave Wallace47e77302019-06-05 10:40:07 -0400129class QUICEchoInternalSerialTestCase(QUICEchoInternalTestCase):
130 """QUIC Echo Internal Serial Transfer Test Case"""
Dave Wallace0d144c72019-05-15 21:41:23 -0400131 @unittest.skipUnless(running_extended_tests, "part of extended tests")
132 def test_quic_serial_internal_transfer(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400133 self.server()
134 self.client("no-output", "mbytes", "10")
135 self.client("no-output", "mbytes", "10")
136 self.client("no-output", "mbytes", "10")
137 self.client("no-output", "mbytes", "10")
138 self.client("no-output", "mbytes", "10")
Dave Wallace0d144c72019-05-15 21:41:23 -0400139
Dave Wallace47e77302019-06-05 10:40:07 -0400140class QUICEchoInternalMStreamTestCase(QUICEchoInternalTestCase):
141 """QUIC Echo Internal MultiStream Test Case"""
Dave Wallace211b28a2019-05-08 20:46:33 -0400142 @unittest.skipUnless(running_extended_tests, "part of extended tests")
143 def test_quic_internal_multistream_transfer(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400144 self.server()
145 self.client("nclients", "10", "mbytes", "1", "no-output")
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400146
147
Dave Wallace47e77302019-06-05 10:40:07 -0400148class QUICEchoExternalTestCase(QUICTestCase):
149 extra_vpp_punt_config = ["session", "{", "evt_qs_memfd_seg", "}"]
150 quic_setup = "default"
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400151
152 def setUp(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400153 super(QUICEchoExternalTestCase, self).setUp()
154 common_args = ["uri", self.uri, "fifo-size", "64", "test-bytes:assert", "socket-name", self.api_sock]
155 self.server_echo_test_args = common_args + ["server", "appns", "server", "quic-setup", self.quic_setup]
156 self.client_echo_test_args = common_args + ["client", "appns", "client", "quic-setup", self.quic_setup]
157 self.event = Event()
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400158
Dave Wallace47e77302019-06-05 10:40:07 -0400159 def server(self, *args):
160 _args = self.server_echo_test_args + list(args)
161 self.worker_server = QUICAppWorker(self.build_dir, "quic_echo",
162 _args, self.logger, event=self.event)
163 self.worker_server.start()
164 self.sleep(self.pre_test_sleep)
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400165
Dave Wallace47e77302019-06-05 10:40:07 -0400166 def client(self, *args):
167 _args = self.client_echo_test_args + list(args)
168 # self.client_echo_test_args += "use-svm-api"
169 self.worker_client = QUICAppWorker(self.build_dir, "quic_echo",
170 _args, self.logger, event=self.event)
171 self.worker_client.start()
172 self.event.wait(self.timeout)
173 self.sleep(self.post_test_sleep)
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400174
Dave Wallace47e77302019-06-05 10:40:07 -0400175 def validate_external_test_results(self):
176 self.logger.info("Client worker result is `%s'" % self.worker_client.result)
177 server_result = self.worker_server.result
178 client_result = self.worker_client.result
179 server_kill_error = False
180 if self.worker_server.result is None:
181 server_kill_error = self.worker_server.teardown(self.logger, self.timeout)
182 if self.worker_client.result is None:
183 self.worker_client.teardown(self.logger, self.timeout)
184 self.assertIsNone(server_result, "Wrong server worker return code")
185 self.assertIsNotNone(client_result, "Timeout! Client worker did not finish in %ss" % self.timeout)
186 self.assertEqual(client_result, 0, "Wrong client worker return code")
187 self.assertFalse(server_kill_error, "Server kill errored")
188
189
190class QUICEchoExternalTransferTestCase(QUICEchoExternalTestCase):
191 """QUIC Echo External Transfer Test Case"""
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400192 @unittest.skipUnless(running_extended_tests, "part of extended tests")
193 def test_quic_external_transfer(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400194 self.server()
195 self.client()
196 self.validate_external_test_results()
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400197
Dave Wallace47e77302019-06-05 10:40:07 -0400198class QUICEchoExternalServerStreamTestCase(QUICEchoExternalTestCase):
199 """QUIC Echo External Transfer Server Stream Test Case"""
200 quic_setup = "serverstream"
201
202 @unittest.skipUnless(running_extended_tests, "part of extended tests")
203 def test_quic_external_transfer_server_stream(self):
204 self.server("nclients", "1/1", "send", "1Kb", "recv", "0")
205 self.client("nclients" ,"1/1", "send", "0", "recv", "1Kb")
206 self.validate_external_test_results()
207
208class QUICEchoExternalServerStreamWorkersTestCase(QUICEchoExternalTestCase):
209 """QUIC Echo External Transfer Server Stream MultiWorker Test Case"""
210 quic_setup = "serverstream"
211
212 @unittest.skipUnless(running_extended_tests, "part of extended tests")
213 def test_quic_external_transfer_server_stream_multi_workers(self):
214 self.server("nclients", "4/4", "send", "1Kb", "recv", "0")
215 self.client("nclients", "4/4", "send", "0", "recv", "1Kb")
216 self.validate_external_test_results()
Dave Wallace211b28a2019-05-08 20:46:33 -0400217
Dave Wallaceb063ad02019-04-09 21:01:09 -0400218
219if __name__ == '__main__':
220 unittest.main(testRunner=VppTestRunner)