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: |
| 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 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""" |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 105 | def setUp(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame^] | 106 | 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 Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 109 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame^] | 110 | 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 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): |
| 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 Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 121 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame^] | 122 | class QUICEchoInternalTransferTestCase(QUICEchoInternalTestCase): |
| 123 | """QUIC Echo Internal Transfer Test Case""" |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 124 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 125 | def test_quic_internal_transfer(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame^] | 126 | self.server() |
| 127 | self.client("no-output", "mbytes", "10") |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 128 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame^] | 129 | class QUICEchoInternalSerialTestCase(QUICEchoInternalTestCase): |
| 130 | """QUIC Echo Internal Serial Transfer Test Case""" |
Dave Wallace | 0d144c7 | 2019-05-15 21:41:23 -0400 | [diff] [blame] | 131 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
| 132 | def test_quic_serial_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") |
| 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 Wallace | 0d144c7 | 2019-05-15 21:41:23 -0400 | [diff] [blame] | 139 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame^] | 140 | class QUICEchoInternalMStreamTestCase(QUICEchoInternalTestCase): |
| 141 | """QUIC Echo Internal MultiStream Test Case""" |
Dave Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 142 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
| 143 | def test_quic_internal_multistream_transfer(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame^] | 144 | self.server() |
| 145 | self.client("nclients", "10", "mbytes", "1", "no-output") |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 146 | |
| 147 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame^] | 148 | class QUICEchoExternalTestCase(QUICTestCase): |
| 149 | extra_vpp_punt_config = ["session", "{", "evt_qs_memfd_seg", "}"] |
| 150 | quic_setup = "default" |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 151 | |
| 152 | def setUp(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame^] | 153 | 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 Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 158 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame^] | 159 | 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 Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 165 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame^] | 166 | 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 Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 174 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame^] | 175 | 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 | |
| 190 | class QUICEchoExternalTransferTestCase(QUICEchoExternalTestCase): |
| 191 | """QUIC Echo External Transfer Test Case""" |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 192 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
| 193 | def test_quic_external_transfer(self): |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame^] | 194 | self.server() |
| 195 | self.client() |
| 196 | self.validate_external_test_results() |
Dave Wallace | 3bffd4b | 2019-05-13 15:51:52 -0400 | [diff] [blame] | 197 | |
Dave Wallace | 47e7730 | 2019-06-05 10:40:07 -0400 | [diff] [blame^] | 198 | class 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 | |
| 208 | class 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 Wallace | 211b28a | 2019-05-08 20:46:33 -0400 | [diff] [blame] | 217 | |
Dave Wallace | b063ad0 | 2019-04-09 21:01:09 -0400 | [diff] [blame] | 218 | |
| 219 | if __name__ == '__main__': |
| 220 | unittest.main(testRunner=VppTestRunner) |