blob: 490ed5ebcf839e86fad88b1b39fcb84642d8eb67 [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:
Chore464e1dc2019-06-25 14:21:26 +043031 return False
Dave Wallace47e77302019-06-05 10:40:07 -040032 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"""
Chore464e1dc2019-06-25 14:21:26 +0430105
Dave Wallace211b28a2019-05-08 20:46:33 -0400106 def setUp(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400107 super(QUICEchoInternalTestCase, self).setUp()
Chore464e1dc2019-06-25 14:21:26 +0430108 self.client_args = "uri %s fifo-size 64 test-bytes appns client" \
109 % self.uri
Dave Wallace47e77302019-06-05 10:40:07 -0400110 self.server_args = "uri %s fifo-size 64 appns server" % self.uri
Dave Wallace211b28a2019-05-08 20:46:33 -0400111
Dave Wallace47e77302019-06-05 10:40:07 -0400112 def server(self, *args):
Chore464e1dc2019-06-25 14:21:26 +0430113 error = self.vapi.cli(
114 "test echo server %s %s" %
115 (self.server_args, ' '.join(args)))
Dave Wallace47e77302019-06-05 10:40:07 -0400116 if error:
117 self.logger.critical(error)
118 self.assertNotIn("failed", error)
Dave Wallace211b28a2019-05-08 20:46:33 -0400119
Dave Wallace47e77302019-06-05 10:40:07 -0400120 def client(self, *args):
Chore464e1dc2019-06-25 14:21:26 +0430121 error = self.vapi.cli(
122 "test echo client %s %s" %
123 (self.client_args, ' '.join(args)))
Dave Wallace47e77302019-06-05 10:40:07 -0400124 if error:
125 self.logger.critical(error)
126 self.assertNotIn("failed", error)
Dave Wallaceb063ad02019-04-09 21:01:09 -0400127
Chore464e1dc2019-06-25 14:21:26 +0430128
Dave Wallace47e77302019-06-05 10:40:07 -0400129class QUICEchoInternalTransferTestCase(QUICEchoInternalTestCase):
130 """QUIC Echo Internal Transfer Test Case"""
Dave Wallaceb063ad02019-04-09 21:01:09 -0400131 @unittest.skipUnless(running_extended_tests, "part of extended tests")
Dave Wallace211b28a2019-05-08 20:46:33 -0400132 def test_quic_internal_transfer(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400133 self.server()
134 self.client("no-output", "mbytes", "10")
Dave Wallaceb063ad02019-04-09 21:01:09 -0400135
Chore464e1dc2019-06-25 14:21:26 +0430136
Dave Wallace47e77302019-06-05 10:40:07 -0400137class QUICEchoInternalSerialTestCase(QUICEchoInternalTestCase):
138 """QUIC Echo Internal Serial Transfer Test Case"""
Dave Wallace0d144c72019-05-15 21:41:23 -0400139 @unittest.skipUnless(running_extended_tests, "part of extended tests")
140 def test_quic_serial_internal_transfer(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400141 self.server()
142 self.client("no-output", "mbytes", "10")
143 self.client("no-output", "mbytes", "10")
144 self.client("no-output", "mbytes", "10")
145 self.client("no-output", "mbytes", "10")
146 self.client("no-output", "mbytes", "10")
Dave Wallace0d144c72019-05-15 21:41:23 -0400147
Chore464e1dc2019-06-25 14:21:26 +0430148
Dave Wallace47e77302019-06-05 10:40:07 -0400149class QUICEchoInternalMStreamTestCase(QUICEchoInternalTestCase):
150 """QUIC Echo Internal MultiStream Test Case"""
Dave Wallace211b28a2019-05-08 20:46:33 -0400151 @unittest.skipUnless(running_extended_tests, "part of extended tests")
152 def test_quic_internal_multistream_transfer(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400153 self.server()
154 self.client("nclients", "10", "mbytes", "1", "no-output")
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400155
156
Dave Wallace47e77302019-06-05 10:40:07 -0400157class QUICEchoExternalTestCase(QUICTestCase):
158 extra_vpp_punt_config = ["session", "{", "evt_qs_memfd_seg", "}"]
159 quic_setup = "default"
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400160
161 def setUp(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400162 super(QUICEchoExternalTestCase, self).setUp()
Chore464e1dc2019-06-25 14:21:26 +0430163 common_args = [
164 "uri",
165 self.uri,
166 "fifo-size",
167 "64",
168 "test-bytes:assert",
169 "socket-name",
170 self.api_sock]
171 self.server_echo_test_args = common_args + \
172 ["server", "appns", "server", "quic-setup", self.quic_setup]
173 self.client_echo_test_args = common_args + \
174 ["client", "appns", "client", "quic-setup", self.quic_setup]
Dave Wallace47e77302019-06-05 10:40:07 -0400175 self.event = Event()
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400176
Dave Wallace47e77302019-06-05 10:40:07 -0400177 def server(self, *args):
178 _args = self.server_echo_test_args + list(args)
Chore464e1dc2019-06-25 14:21:26 +0430179 self.worker_server = QUICAppWorker(
180 self.build_dir,
181 "quic_echo",
182 _args,
183 self.logger,
184 event=self.event)
Dave Wallace47e77302019-06-05 10:40:07 -0400185 self.worker_server.start()
186 self.sleep(self.pre_test_sleep)
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400187
Dave Wallace47e77302019-06-05 10:40:07 -0400188 def client(self, *args):
189 _args = self.client_echo_test_args + list(args)
190 # self.client_echo_test_args += "use-svm-api"
Chore464e1dc2019-06-25 14:21:26 +0430191 self.worker_client = QUICAppWorker(
192 self.build_dir,
193 "quic_echo",
194 _args,
195 self.logger,
196 event=self.event)
Dave Wallace47e77302019-06-05 10:40:07 -0400197 self.worker_client.start()
198 self.event.wait(self.timeout)
199 self.sleep(self.post_test_sleep)
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400200
Dave Wallace47e77302019-06-05 10:40:07 -0400201 def validate_external_test_results(self):
Chore464e1dc2019-06-25 14:21:26 +0430202 self.logger.info(
203 "Client worker result is `%s'" %
204 self.worker_client.result)
Dave Wallace47e77302019-06-05 10:40:07 -0400205 server_result = self.worker_server.result
206 client_result = self.worker_client.result
207 server_kill_error = False
208 if self.worker_server.result is None:
Chore464e1dc2019-06-25 14:21:26 +0430209 server_kill_error = self.worker_server.teardown(
210 self.logger, self.timeout)
Dave Wallace47e77302019-06-05 10:40:07 -0400211 if self.worker_client.result is None:
212 self.worker_client.teardown(self.logger, self.timeout)
213 self.assertIsNone(server_result, "Wrong server worker return code")
Chore464e1dc2019-06-25 14:21:26 +0430214 self.assertIsNotNone(
215 client_result,
216 "Timeout! Client worker did not finish in %ss" %
217 self.timeout)
Dave Wallace47e77302019-06-05 10:40:07 -0400218 self.assertEqual(client_result, 0, "Wrong client worker return code")
219 self.assertFalse(server_kill_error, "Server kill errored")
220
221
222class QUICEchoExternalTransferTestCase(QUICEchoExternalTestCase):
223 """QUIC Echo External Transfer Test Case"""
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400224 @unittest.skipUnless(running_extended_tests, "part of extended tests")
225 def test_quic_external_transfer(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400226 self.server()
227 self.client()
228 self.validate_external_test_results()
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400229
Chore464e1dc2019-06-25 14:21:26 +0430230
Dave Wallace47e77302019-06-05 10:40:07 -0400231class QUICEchoExternalServerStreamTestCase(QUICEchoExternalTestCase):
232 """QUIC Echo External Transfer Server Stream Test Case"""
233 quic_setup = "serverstream"
234
235 @unittest.skipUnless(running_extended_tests, "part of extended tests")
236 def test_quic_external_transfer_server_stream(self):
237 self.server("nclients", "1/1", "send", "1Kb", "recv", "0")
Chore464e1dc2019-06-25 14:21:26 +0430238 self.client("nclients", "1/1", "send", "0", "recv", "1Kb")
Dave Wallace47e77302019-06-05 10:40:07 -0400239 self.validate_external_test_results()
240
Chore464e1dc2019-06-25 14:21:26 +0430241
Dave Wallace47e77302019-06-05 10:40:07 -0400242class QUICEchoExternalServerStreamWorkersTestCase(QUICEchoExternalTestCase):
243 """QUIC Echo External Transfer Server Stream MultiWorker Test Case"""
244 quic_setup = "serverstream"
245
246 @unittest.skipUnless(running_extended_tests, "part of extended tests")
247 def test_quic_external_transfer_server_stream_multi_workers(self):
248 self.server("nclients", "4/4", "send", "1Kb", "recv", "0")
249 self.client("nclients", "4/4", "send", "0", "recv", "1Kb")
250 self.validate_external_test_results()
Dave Wallace211b28a2019-05-08 20:46:33 -0400251
Dave Wallaceb063ad02019-04-09 21:01:09 -0400252
253if __name__ == '__main__':
254 unittest.main(testRunner=VppTestRunner)