Dave Wallace | cfcf2f4 | 2018-02-16 18:31:56 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | """ Vpp VCL tests """ |
| 3 | |
| 4 | import unittest |
| 5 | import os |
| 6 | import signal |
Dave Wallace | 42996c0 | 2018-02-26 14:40:13 -0500 | [diff] [blame^] | 7 | from framework import VppTestCase, VppTestRunner, Worker |
Dave Wallace | a67a03e | 2018-02-20 12:39:37 -0500 | [diff] [blame] | 8 | from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath |
Dave Wallace | cfcf2f4 | 2018-02-16 18:31:56 -0500 | [diff] [blame] | 9 | |
| 10 | |
Dave Wallace | 42996c0 | 2018-02-26 14:40:13 -0500 | [diff] [blame^] | 11 | class VclAppWorker(Worker): |
| 12 | """ VCL Test Application Worker """ |
| 13 | |
| 14 | def __init__(self, appname, args, logger, env={}): |
| 15 | var = "VPP_TEST_BUILD_DIR" |
| 16 | build_dir = os.getenv(var, None) |
| 17 | if build_dir is None: |
| 18 | raise Exception("Environment variable `%s' not set" % var) |
| 19 | vcl_app_dir = "%s/vpp/.libs" % build_dir |
| 20 | self.args = ["%s/%s" % (vcl_app_dir, appname)] + args |
| 21 | super(VclAppWorker, self).__init__(self.args, logger, env) |
| 22 | |
| 23 | |
| 24 | class VclTestCase(VppTestCase): |
| 25 | """ VCL Test Class """ |
| 26 | |
| 27 | def validateResults(self, worker_client, worker_server, timeout): |
| 28 | self.logger.info("Client worker result is `%s'" % worker_client.result) |
| 29 | error = False |
| 30 | if worker_client.result is None: |
| 31 | try: |
| 32 | error = True |
| 33 | self.logger.error( |
| 34 | "Timeout! Client worker did not finish in %ss" % timeout) |
| 35 | os.killpg(os.getpgid(worker_client.process.pid), |
| 36 | signal.SIGTERM) |
| 37 | worker_client.join() |
| 38 | except: |
| 39 | self.logger.debug( |
| 40 | "Couldn't kill client worker-spawned process") |
| 41 | raise |
| 42 | if error: |
| 43 | os.killpg(os.getpgid(worker_server.process.pid), signal.SIGTERM) |
| 44 | worker_server.join() |
| 45 | raise Exception( |
| 46 | "Timeout! Client worker did not finish in %ss" % timeout) |
| 47 | self.assert_equal(worker_client.result, 0, "Binary test return code") |
| 48 | |
| 49 | |
| 50 | class VCLCUTTHRUTestCase(VclTestCase): |
| 51 | """ VPP Communications Library Test """ |
Dave Wallace | cfcf2f4 | 2018-02-16 18:31:56 -0500 | [diff] [blame] | 52 | |
| 53 | server_addr = "127.0.0.1" |
| 54 | server_port = "22000" |
Dave Wallace | 42996c0 | 2018-02-26 14:40:13 -0500 | [diff] [blame^] | 55 | timeout = 3 |
| 56 | echo_phrase = "Hello, world! Jenny is a friend of mine" |
Dave Wallace | cfcf2f4 | 2018-02-16 18:31:56 -0500 | [diff] [blame] | 57 | |
| 58 | def setUp(self): |
Dave Wallace | a67a03e | 2018-02-20 12:39:37 -0500 | [diff] [blame] | 59 | super(VCLCUTTHRUTestCase, self).setUp() |
| 60 | |
| 61 | self.vapi.session_enable_disable(is_enabled=1) |
| 62 | |
| 63 | def tearDown(self): |
| 64 | self.vapi.session_enable_disable(is_enabled=0) |
| 65 | |
| 66 | super(VCLCUTTHRUTestCase, self).tearDown() |
Dave Wallace | cfcf2f4 | 2018-02-16 18:31:56 -0500 | [diff] [blame] | 67 | |
| 68 | def test_vcl_cutthru(self): |
| 69 | """ run VCL cut-thru test """ |
Dave Wallace | 42996c0 | 2018-02-26 14:40:13 -0500 | [diff] [blame^] | 70 | self.env = {'VCL_API_PREFIX': self.shm_prefix, |
| 71 | 'VCL_APP_SCOPE_LOCAL': "true"} |
| 72 | |
| 73 | worker_server = VclAppWorker("vcl_test_server", |
| 74 | [self.server_port], |
| 75 | self.logger, self.env) |
Dave Wallace | cfcf2f4 | 2018-02-16 18:31:56 -0500 | [diff] [blame] | 76 | worker_server.start() |
Dave Wallace | 42996c0 | 2018-02-26 14:40:13 -0500 | [diff] [blame^] | 77 | self.sleep(0.2) |
| 78 | worker_client = VclAppWorker("vcl_test_client", |
| 79 | [self.server_addr, self.server_port, |
| 80 | "-E", self.echo_phrase, "-X"], |
| 81 | self.logger, self.env) |
Dave Wallace | cfcf2f4 | 2018-02-16 18:31:56 -0500 | [diff] [blame] | 82 | worker_client.start() |
Dave Wallace | 42996c0 | 2018-02-26 14:40:13 -0500 | [diff] [blame^] | 83 | worker_client.join(self.timeout) |
| 84 | self.validateResults(worker_client, worker_server, self.timeout) |
Dave Wallace | cfcf2f4 | 2018-02-16 18:31:56 -0500 | [diff] [blame] | 85 | |
| 86 | |
Dave Wallace | 42996c0 | 2018-02-26 14:40:13 -0500 | [diff] [blame^] | 87 | class VCLTHRUHSTestcase(VclTestCase): |
Dave Wallace | a67a03e | 2018-02-20 12:39:37 -0500 | [diff] [blame] | 88 | """ VCL Thru Hoststack Test """ |
| 89 | |
| 90 | server_port = "22000" |
Dave Wallace | 42996c0 | 2018-02-26 14:40:13 -0500 | [diff] [blame^] | 91 | timeout = 3 |
| 92 | echo_phrase = "Hello, world! Jenny is a friend of mine" |
Dave Wallace | a67a03e | 2018-02-20 12:39:37 -0500 | [diff] [blame] | 93 | |
| 94 | def setUp(self): |
| 95 | super(VCLTHRUHSTestcase, self).setUp() |
| 96 | |
| 97 | self.vapi.session_enable_disable(is_enabled=1) |
| 98 | self.create_loopback_interfaces(range(2)) |
| 99 | |
| 100 | table_id = 0 |
| 101 | |
| 102 | for i in self.lo_interfaces: |
| 103 | i.admin_up() |
| 104 | |
| 105 | if table_id != 0: |
| 106 | tbl = VppIpTable(self, table_id) |
| 107 | tbl.add_vpp_config() |
| 108 | |
| 109 | i.set_table_ip4(table_id) |
| 110 | i.config_ip4() |
| 111 | table_id += 1 |
| 112 | |
| 113 | # Configure namespaces |
Dave Wallace | 42996c0 | 2018-02-26 14:40:13 -0500 | [diff] [blame^] | 114 | self.vapi.app_namespace_add(namespace_id="0", secret=1234, |
Dave Wallace | a67a03e | 2018-02-20 12:39:37 -0500 | [diff] [blame] | 115 | sw_if_index=self.loop0.sw_if_index) |
Dave Wallace | 42996c0 | 2018-02-26 14:40:13 -0500 | [diff] [blame^] | 116 | self.vapi.app_namespace_add(namespace_id="1", secret=5678, |
Dave Wallace | a67a03e | 2018-02-20 12:39:37 -0500 | [diff] [blame] | 117 | sw_if_index=self.loop1.sw_if_index) |
| 118 | |
| 119 | def tearDown(self): |
| 120 | for i in self.lo_interfaces: |
| 121 | i.unconfig_ip4() |
| 122 | i.set_table_ip4(0) |
| 123 | i.admin_down() |
| 124 | |
| 125 | self.vapi.session_enable_disable(is_enabled=0) |
| 126 | super(VCLTHRUHSTestcase, self).tearDown() |
| 127 | |
| 128 | def test_vcl_thru_hoststack(self): |
| 129 | """ run VCL thru hoststack test """ |
Dave Wallace | 42996c0 | 2018-02-26 14:40:13 -0500 | [diff] [blame^] | 130 | self.env = {'VCL_API_PREFIX': self.shm_prefix, |
| 131 | 'VCL_APP_SCOPE_GLOBAL': "true"} |
| 132 | |
Dave Wallace | a67a03e | 2018-02-20 12:39:37 -0500 | [diff] [blame] | 133 | # Add inter-table routes |
| 134 | ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32, |
| 135 | [VppRoutePath("0.0.0.0", |
| 136 | 0xffffffff, |
| 137 | nh_table_id=1)]) |
| 138 | ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32, |
| 139 | [VppRoutePath("0.0.0.0", |
| 140 | 0xffffffff, |
| 141 | nh_table_id=0)], table_id=1) |
| 142 | ip_t01.add_vpp_config() |
| 143 | ip_t10.add_vpp_config() |
| 144 | |
Dave Wallace | 42996c0 | 2018-02-26 14:40:13 -0500 | [diff] [blame^] | 145 | self.env.update({'VCL_APP_NAMESPACE_ID': "0", |
| 146 | 'VCL_APP_NAMESPACE_SECRET': "1234"}) |
| 147 | worker_server = VclAppWorker("vcl_test_server", |
| 148 | [self.server_port], |
| 149 | self.logger, self.env) |
Dave Wallace | a67a03e | 2018-02-20 12:39:37 -0500 | [diff] [blame] | 150 | worker_server.start() |
Dave Wallace | 42996c0 | 2018-02-26 14:40:13 -0500 | [diff] [blame^] | 151 | self.sleep(0.2) |
| 152 | |
| 153 | self.env.update({'VCL_APP_NAMESPACE_ID': "1", |
| 154 | 'VCL_APP_NAMESPACE_SECRET': "5678"}) |
| 155 | worker_client = VclAppWorker("vcl_test_client", |
| 156 | [self.loop0.local_ip4, self.server_port, |
| 157 | "-E", self.echo_phrase, "-X"], |
| 158 | self.logger, self.env) |
Dave Wallace | a67a03e | 2018-02-20 12:39:37 -0500 | [diff] [blame] | 159 | worker_client.start() |
Dave Wallace | 42996c0 | 2018-02-26 14:40:13 -0500 | [diff] [blame^] | 160 | worker_client.join(self.timeout) |
| 161 | |
| 162 | self.validateResults(worker_client, worker_server, self.timeout) |
Dave Wallace | a67a03e | 2018-02-20 12:39:37 -0500 | [diff] [blame] | 163 | |
Dave Wallace | cfcf2f4 | 2018-02-16 18:31:56 -0500 | [diff] [blame] | 164 | if __name__ == '__main__': |
| 165 | unittest.main(testRunner=VppTestRunner) |