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 |
| 11 | |
| 12 | |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 13 | class QUICAppWorker(Worker): |
| 14 | """ QUIC Test Application Worker """ |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 15 | process = None |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 16 | |
Nathan Skrzypczak | e82a7ad | 2019-05-22 18:41:50 +0200 | [diff] [blame] | 17 | def __init__(self, build_dir, appname, args, logger, env={}): |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 18 | app = "%s/vpp/bin/%s" % (build_dir, appname) |
| 19 | self.args = [app] + args |
| 20 | super(QUICAppWorker, self).__init__(self.args, logger, env) |
| 21 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 22 | def run(self): |
| 23 | super(QUICAppWorker, self).run() |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 24 | |
| 25 | def teardown(self, logger, timeout): |
| 26 | if self.process is None: |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame] | 27 | return False |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 28 | try: |
| 29 | logger.debug("Killing worker process (pid %d)" % self.process.pid) |
| 30 | os.killpg(os.getpgid(self.process.pid), signal.SIGKILL) |
| 31 | self.join(timeout) |
| 32 | except OSError as e: |
| 33 | logger.debug("Couldn't kill worker process") |
| 34 | return True |
| 35 | return False |
| 36 | |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 37 | |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 38 | class QUICTestCase(VppTestCase): |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 39 | """ QUIC Test Case """ |
| 40 | |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 41 | def setUp(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 42 | super(QUICTestCase, self).setUp() |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 43 | var = "VPP_BUILD_DIR" |
| 44 | self.build_dir = os.getenv(var, None) |
| 45 | if self.build_dir is None: |
| 46 | raise Exception("Environment variable `%s' not set" % var) |
| 47 | self.vppDebug = 'vpp_debug' in self.build_dir |
| 48 | self.timeout = 20 |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 49 | self.vapi.session_enable_disable(is_enabled=1) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 50 | self.pre_test_sleep = 0.3 |
| 51 | self.post_test_sleep = 0.2 |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 52 | |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 53 | self.create_loopback_interfaces(2) |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 54 | self.uri = "quic://%s/1234" % self.loop0.local_ip4 |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 55 | table_id = 1 |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 56 | for i in self.lo_interfaces: |
| 57 | i.admin_up() |
| 58 | |
| 59 | if table_id != 0: |
| 60 | tbl = VppIpTable(self, table_id) |
| 61 | tbl.add_vpp_config() |
| 62 | |
| 63 | i.set_table_ip4(table_id) |
| 64 | i.config_ip4() |
| 65 | table_id += 1 |
| 66 | |
| 67 | # Configure namespaces |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 68 | self.vapi.app_namespace_add_del(namespace_id=b"server", |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 69 | sw_if_index=self.loop0.sw_if_index) |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 70 | self.vapi.app_namespace_add_del(namespace_id=b"client", |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 71 | sw_if_index=self.loop1.sw_if_index) |
| 72 | |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 73 | # Add inter-table routes |
| 74 | self.ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32, |
| 75 | [VppRoutePath("0.0.0.0", |
| 76 | 0xffffffff, |
| 77 | nh_table_id=2)], table_id=1) |
| 78 | self.ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32, |
| 79 | [VppRoutePath("0.0.0.0", |
| 80 | 0xffffffff, |
| 81 | nh_table_id=1)], table_id=2) |
| 82 | self.ip_t01.add_vpp_config() |
| 83 | self.ip_t10.add_vpp_config() |
| 84 | self.logger.debug(self.vapi.cli("show ip fib")) |
| 85 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 86 | def tearDown(self): |
| 87 | self.vapi.session_enable_disable(is_enabled=0) |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 88 | # Delete inter-table routes |
| 89 | self.ip_t01.remove_vpp_config() |
| 90 | self.ip_t10.remove_vpp_config() |
| 91 | |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 92 | for i in self.lo_interfaces: |
| 93 | i.unconfig_ip4() |
| 94 | i.set_table_ip4(0) |
| 95 | i.admin_down() |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 96 | super(QUICTestCase, self).tearDown() |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 97 | |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 98 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 99 | class QUICEchoInternalTestCase(QUICTestCase): |
| 100 | """QUIC Echo Internal Test Case""" |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame] | 101 | |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 102 | def setUp(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 103 | super(QUICEchoInternalTestCase, self).setUp() |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame] | 104 | self.client_args = "uri %s fifo-size 64 test-bytes appns client" \ |
| 105 | % self.uri |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 106 | self.server_args = "uri %s fifo-size 64 appns server" % self.uri |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 107 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 108 | def server(self, *args): |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame] | 109 | error = self.vapi.cli( |
| 110 | "test echo server %s %s" % |
| 111 | (self.server_args, ' '.join(args))) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 112 | if error: |
| 113 | self.logger.critical(error) |
| 114 | self.assertNotIn("failed", error) |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 115 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 116 | def client(self, *args): |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame] | 117 | error = self.vapi.cli( |
| 118 | "test echo client %s %s" % |
| 119 | (self.client_args, ' '.join(args))) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 120 | if error: |
| 121 | self.logger.critical(error) |
| 122 | self.assertNotIn("failed", error) |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 123 | |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame] | 124 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 125 | class QUICEchoInternalTransferTestCase(QUICEchoInternalTestCase): |
| 126 | """QUIC Echo Internal Transfer Test Case""" |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 127 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 128 | def test_quic_internal_transfer(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 129 | self.server() |
Aloys Augustin | 706079c | 2019-06-27 16:10:23 +0200 | [diff] [blame] | 130 | self.client("no-output", "mbytes", "2") |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 131 | |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame] | 132 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 133 | class QUICEchoInternalSerialTestCase(QUICEchoInternalTestCase): |
| 134 | """QUIC Echo Internal Serial Transfer Test Case""" |
Dave Wallace | 0d144c7 | 2019-05-15 21:41:23 -0400 | [diff] [blame] | 135 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
| 136 | def test_quic_serial_internal_transfer(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 137 | self.server() |
Aloys Augustin | 706079c | 2019-06-27 16:10:23 +0200 | [diff] [blame] | 138 | self.client("no-output", "mbytes", "2") |
| 139 | self.client("no-output", "mbytes", "2") |
| 140 | self.client("no-output", "mbytes", "2") |
| 141 | self.client("no-output", "mbytes", "2") |
| 142 | self.client("no-output", "mbytes", "2") |
Dave Wallace | 0d144c7 | 2019-05-15 21:41:23 -0400 | [diff] [blame] | 143 | |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame] | 144 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 145 | class QUICEchoInternalMStreamTestCase(QUICEchoInternalTestCase): |
| 146 | """QUIC Echo Internal MultiStream Test Case""" |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 147 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
| 148 | def test_quic_internal_multistream_transfer(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 149 | self.server() |
| 150 | self.client("nclients", "10", "mbytes", "1", "no-output") |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 151 | |
| 152 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 153 | class QUICEchoExternalTestCase(QUICTestCase): |
| 154 | extra_vpp_punt_config = ["session", "{", "evt_qs_memfd_seg", "}"] |
| 155 | quic_setup = "default" |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 156 | |
| 157 | def setUp(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 158 | super(QUICEchoExternalTestCase, self).setUp() |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame] | 159 | common_args = [ |
| 160 | "uri", |
| 161 | self.uri, |
| 162 | "fifo-size", |
| 163 | "64", |
| 164 | "test-bytes:assert", |
| 165 | "socket-name", |
| 166 | self.api_sock] |
| 167 | self.server_echo_test_args = common_args + \ |
| 168 | ["server", "appns", "server", "quic-setup", self.quic_setup] |
| 169 | self.client_echo_test_args = common_args + \ |
| 170 | ["client", "appns", "client", "quic-setup", self.quic_setup] |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 171 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 172 | def server(self, *args): |
| 173 | _args = self.server_echo_test_args + list(args) |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame] | 174 | self.worker_server = QUICAppWorker( |
| 175 | self.build_dir, |
| 176 | "quic_echo", |
| 177 | _args, |
Nathan Skrzypczak | e82a7ad | 2019-05-22 18:41:50 +0200 | [diff] [blame] | 178 | self.logger) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 179 | self.worker_server.start() |
| 180 | self.sleep(self.pre_test_sleep) |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 181 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 182 | def client(self, *args): |
| 183 | _args = self.client_echo_test_args + list(args) |
| 184 | # self.client_echo_test_args += "use-svm-api" |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame] | 185 | self.worker_client = QUICAppWorker( |
| 186 | self.build_dir, |
| 187 | "quic_echo", |
| 188 | _args, |
Nathan Skrzypczak | e82a7ad | 2019-05-22 18:41:50 +0200 | [diff] [blame] | 189 | self.logger) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 190 | self.worker_client.start() |
Nathan Skrzypczak | 24cbf77 | 2019-07-09 14:36:31 +0200 | [diff] [blame] | 191 | self.worker_client.join(self.timeout) |
| 192 | self.worker_server.join(self.timeout) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 193 | self.sleep(self.post_test_sleep) |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 194 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 195 | def validate_external_test_results(self): |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame] | 196 | self.logger.info( |
| 197 | "Client worker result is `%s'" % |
| 198 | self.worker_client.result) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 199 | server_result = self.worker_server.result |
| 200 | client_result = self.worker_client.result |
| 201 | server_kill_error = False |
| 202 | if self.worker_server.result is None: |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame] | 203 | server_kill_error = self.worker_server.teardown( |
| 204 | self.logger, self.timeout) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 205 | if self.worker_client.result is None: |
| 206 | self.worker_client.teardown(self.logger, self.timeout) |
Nathan Skrzypczak | e82a7ad | 2019-05-22 18:41:50 +0200 | [diff] [blame] | 207 | self.assertEqual(server_result, 0, "Wrong server worker return code") |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame] | 208 | self.assertIsNotNone( |
| 209 | client_result, |
| 210 | "Timeout! Client worker did not finish in %ss" % |
| 211 | self.timeout) |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 212 | self.assertEqual(client_result, 0, "Wrong client worker return code") |
| 213 | self.assertFalse(server_kill_error, "Server kill errored") |
| 214 | |
| 215 | |
| 216 | class QUICEchoExternalTransferTestCase(QUICEchoExternalTestCase): |
| 217 | """QUIC Echo External Transfer Test Case""" |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 218 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
| 219 | def test_quic_external_transfer(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 220 | self.server() |
| 221 | self.client() |
| 222 | self.validate_external_test_results() |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 223 | |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame] | 224 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 225 | class QUICEchoExternalServerStreamTestCase(QUICEchoExternalTestCase): |
| 226 | """QUIC Echo External Transfer Server Stream Test Case""" |
| 227 | quic_setup = "serverstream" |
| 228 | |
| 229 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
| 230 | def test_quic_external_transfer_server_stream(self): |
Nathan Skrzypczak | e82a7ad | 2019-05-22 18:41:50 +0200 | [diff] [blame] | 231 | self.server("TX=1Kb", "RX=0") |
| 232 | self.client("TX=0", "RX=1Kb") |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 233 | self.validate_external_test_results() |
| 234 | |
Chore | 464e1dc | 2019-06-25 14:21:26 +0430 | [diff] [blame] | 235 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 236 | class QUICEchoExternalServerStreamWorkersTestCase(QUICEchoExternalTestCase): |
| 237 | """QUIC Echo External Transfer Server Stream MultiWorker Test Case""" |
| 238 | quic_setup = "serverstream" |
| 239 | |
| 240 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
| 241 | def test_quic_external_transfer_server_stream_multi_workers(self): |
Nathan Skrzypczak | e82a7ad | 2019-05-22 18:41:50 +0200 | [diff] [blame] | 242 | self.server("nclients", "4/4", "TX=1Kb", "RX=0") |
| 243 | self.client("nclients", "4/4", "TX=0", "RX=1Kb") |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame] | 244 | self.validate_external_test_results() |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 245 | |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 246 | |
| 247 | if __name__ == '__main__': |
| 248 | unittest.main(testRunner=VppTestRunner) |