Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 2 | """ Vpp QUIC tests """ |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 3 | |
| 4 | import unittest |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 5 | import os |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 6 | import subprocess |
| 7 | import signal |
| 8 | from framework import VppTestCase, VppTestRunner, running_extended_tests, \ |
| 9 | Worker |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 10 | from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 11 | from threading import Event |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 12 | |
| 13 | |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 14 | class QUICAppWorker(Worker): |
| 15 | """ QUIC Test Application Worker """ |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 16 | process = None |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 17 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 18 | def __init__(self, build_dir, appname, args, logger, env={}, event=None): |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 19 | app = "%s/vpp/bin/%s" % (build_dir, appname) |
| 20 | self.args = [app] + args |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 21 | self.event = event |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 22 | super(QUICAppWorker, self).__init__(self.args, logger, env) |
| 23 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 24 | 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: |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 31 | return False |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 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 Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 41 | |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 42 | class QUICTestCase(VppTestCase): |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 43 | """ QUIC Test Case """ |
| 44 | |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 45 | def setUp(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 46 | super(QUICTestCase, self).setUp() |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 47 | 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 Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 53 | self.vapi.session_enable_disable(is_enabled=1) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 54 | self.pre_test_sleep = 0.3 |
| 55 | self.post_test_sleep = 0.2 |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 56 | |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 57 | self.create_loopback_interfaces(2) |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 58 | self.uri = "quic://%s/1234" % self.loop0.local_ip4 |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 59 | table_id = 1 |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 60 | 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 Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 72 | self.vapi.app_namespace_add_del(namespace_id=b"server", |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 73 | sw_if_index=self.loop0.sw_if_index) |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 74 | self.vapi.app_namespace_add_del(namespace_id=b"client", |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 75 | sw_if_index=self.loop1.sw_if_index) |
| 76 | |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 77 | # 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 Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 90 | def tearDown(self): |
| 91 | self.vapi.session_enable_disable(is_enabled=0) |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 92 | # Delete inter-table routes |
| 93 | self.ip_t01.remove_vpp_config() |
| 94 | self.ip_t10.remove_vpp_config() |
| 95 | |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 96 | for i in self.lo_interfaces: |
| 97 | i.unconfig_ip4() |
| 98 | i.set_table_ip4(0) |
| 99 | i.admin_down() |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 100 | super(QUICTestCase, self).tearDown() |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 101 | |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 102 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 103 | class QUICEchoInternalTestCase(QUICTestCase): |
| 104 | """QUIC Echo Internal Test Case""" |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 105 | |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 106 | def setUp(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 107 | super(QUICEchoInternalTestCase, self).setUp() |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 108 | self.client_args = "uri %s fifo-size 64 test-bytes appns client" \ |
| 109 | % self.uri |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 110 | self.server_args = "uri %s fifo-size 64 appns server" % self.uri |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 111 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 112 | def server(self, *args): |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 113 | error = self.vapi.cli( |
| 114 | "test echo server %s %s" % |
| 115 | (self.server_args, ' '.join(args))) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 116 | if error: |
| 117 | self.logger.critical(error) |
| 118 | self.assertNotIn("failed", error) |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 119 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 120 | def client(self, *args): |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 121 | error = self.vapi.cli( |
| 122 | "test echo client %s %s" % |
| 123 | (self.client_args, ' '.join(args))) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 124 | if error: |
| 125 | self.logger.critical(error) |
| 126 | self.assertNotIn("failed", error) |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 127 | |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 128 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 129 | class QUICEchoInternalTransferTestCase(QUICEchoInternalTestCase): |
| 130 | """QUIC Echo Internal Transfer Test Case""" |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 131 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 132 | def test_quic_internal_transfer(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 133 | self.server() |
| 134 | self.client("no-output", "mbytes", "10") |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 135 | |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 136 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 137 | class QUICEchoInternalSerialTestCase(QUICEchoInternalTestCase): |
| 138 | """QUIC Echo Internal Serial Transfer Test Case""" |
Dave Wallace | 0d144c7 | 2019-05-15 21:41:23 -0400 | [diff] [blame] | 139 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
| 140 | def test_quic_serial_internal_transfer(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 141 | 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 Wallace | 0d144c7 | 2019-05-15 21:41:23 -0400 | [diff] [blame] | 147 | |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 148 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 149 | class QUICEchoInternalMStreamTestCase(QUICEchoInternalTestCase): |
| 150 | """QUIC Echo Internal MultiStream Test Case""" |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 151 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
| 152 | def test_quic_internal_multistream_transfer(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 153 | self.server() |
| 154 | self.client("nclients", "10", "mbytes", "1", "no-output") |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 155 | |
| 156 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 157 | class QUICEchoExternalTestCase(QUICTestCase): |
| 158 | extra_vpp_punt_config = ["session", "{", "evt_qs_memfd_seg", "}"] |
| 159 | quic_setup = "default" |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 160 | |
| 161 | def setUp(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 162 | super(QUICEchoExternalTestCase, self).setUp() |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 163 | 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 Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 175 | self.event = Event() |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 176 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 177 | def server(self, *args): |
| 178 | _args = self.server_echo_test_args + list(args) |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 179 | self.worker_server = QUICAppWorker( |
| 180 | self.build_dir, |
| 181 | "quic_echo", |
| 182 | _args, |
| 183 | self.logger, |
| 184 | event=self.event) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 185 | self.worker_server.start() |
| 186 | self.sleep(self.pre_test_sleep) |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 187 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 188 | def client(self, *args): |
| 189 | _args = self.client_echo_test_args + list(args) |
| 190 | # self.client_echo_test_args += "use-svm-api" |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 191 | self.worker_client = QUICAppWorker( |
| 192 | self.build_dir, |
| 193 | "quic_echo", |
| 194 | _args, |
| 195 | self.logger, |
| 196 | event=self.event) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 197 | self.worker_client.start() |
| 198 | self.event.wait(self.timeout) |
| 199 | self.sleep(self.post_test_sleep) |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 200 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 201 | def validate_external_test_results(self): |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 202 | self.logger.info( |
| 203 | "Client worker result is `%s'" % |
| 204 | self.worker_client.result) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 205 | 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: |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 209 | server_kill_error = self.worker_server.teardown( |
| 210 | self.logger, self.timeout) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 211 | 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") |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 214 | self.assertIsNotNone( |
| 215 | client_result, |
| 216 | "Timeout! Client worker did not finish in %ss" % |
| 217 | self.timeout) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 218 | self.assertEqual(client_result, 0, "Wrong client worker return code") |
| 219 | self.assertFalse(server_kill_error, "Server kill errored") |
| 220 | |
| 221 | |
| 222 | class QUICEchoExternalTransferTestCase(QUICEchoExternalTestCase): |
| 223 | """QUIC Echo External Transfer Test Case""" |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 224 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
| 225 | def test_quic_external_transfer(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 226 | self.server() |
| 227 | self.client() |
| 228 | self.validate_external_test_results() |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 229 | |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 230 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 231 | class 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") |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 238 | self.client("nclients", "1/1", "send", "0", "recv", "1Kb") |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 239 | self.validate_external_test_results() |
| 240 | |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame^] | 241 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 242 | class 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 Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 251 | |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 252 | |
| 253 | if __name__ == '__main__': |
| 254 | unittest.main(testRunner=VppTestRunner) |