Matej Perina | 6912a05 | 2017-09-25 10:54:47 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import os |
| 4 | import subprocess |
Damjan Marion | cc4a5e8 | 2018-07-30 16:10:14 +0200 | [diff] [blame] | 5 | import unittest |
Matej Perina | 6912a05 | 2017-09-25 10:54:47 +0200 | [diff] [blame] | 6 | |
Damjan Marion | cc4a5e8 | 2018-07-30 16:10:14 +0200 | [diff] [blame] | 7 | from framework import VppTestCase, running_extended_tests |
Matej Perina | 6912a05 | 2017-09-25 10:54:47 +0200 | [diff] [blame] | 8 | |
| 9 | # Api files path |
Damjan Marion | cc4a5e8 | 2018-07-30 16:10:14 +0200 | [diff] [blame] | 10 | API_FILES_PATH = "japi/java" |
Matej Perina | 6912a05 | 2017-09-25 10:54:47 +0200 | [diff] [blame] | 11 | |
| 12 | # Registry jar file name prefix |
| 13 | REGISTRY_JAR_PREFIX = "jvpp-registry" |
Matej Perina | d135c19 | 2017-07-18 13:59:41 +0200 | [diff] [blame] | 14 | |
| 15 | |
Paul Vinciguerra | defde0f | 2018-12-06 07:46:13 -0800 | [diff] [blame] | 16 | @unittest.skipUnless(running_extended_tests, "part of extended tests") |
Matej Perina | 6912a05 | 2017-09-25 10:54:47 +0200 | [diff] [blame] | 17 | class TestJVpp(VppTestCase): |
Matej Perina | d135c19 | 2017-07-18 13:59:41 +0200 | [diff] [blame] | 18 | """ JVPP Core Test Case """ |
| 19 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 20 | @classmethod |
| 21 | def setUpClass(cls): |
| 22 | super(TestJVpp, cls).setUpClass() |
| 23 | |
| 24 | @classmethod |
| 25 | def tearDownClass(cls): |
| 26 | super(TestJVpp, cls).tearDownClass() |
| 27 | |
Matej Perina | d135c19 | 2017-07-18 13:59:41 +0200 | [diff] [blame] | 28 | def invoke_for_jvpp_core(self, api_jar_name, test_class_name): |
| 29 | self.jvpp_connection_test(api_jar_name=api_jar_name, |
| 30 | test_class_name=test_class_name, |
| 31 | timeout=10) |
| 32 | |
| 33 | def test_vpp_core_callback_api(self): |
| 34 | """ JVPP Core Callback Api Test Case """ |
| 35 | self.invoke_for_jvpp_core(api_jar_name="jvpp-core", |
| 36 | test_class_name="io.fd.vpp.jvpp.core.test." |
| 37 | "CallbackApiTest") |
| 38 | |
| 39 | def test_vpp_core_future_api(self): |
| 40 | """JVPP Core Future Api Test Case""" |
| 41 | self.invoke_for_jvpp_core(api_jar_name="jvpp-core", |
| 42 | test_class_name="io.fd.vpp.jvpp.core.test." |
| 43 | "FutureApiTest") |
| 44 | |
| 45 | def test_vpp_acl_callback_api(self): |
| 46 | """ JVPP Acl Callback Api Test Case """ |
| 47 | self.invoke_for_jvpp_core(api_jar_name="jvpp-acl", |
| 48 | test_class_name="io.fd.vpp.jvpp.acl.test." |
| 49 | "CallbackApiTest") |
| 50 | |
| 51 | def test_vpp_acl_future_api(self): |
| 52 | """JVPP Acl Future Api Test Case""" |
| 53 | self.invoke_for_jvpp_core(api_jar_name="jvpp-acl", |
| 54 | test_class_name="io.fd.vpp.jvpp.acl.test." |
| 55 | "FutureApiTest") |
| 56 | |
| 57 | def test_vpp_ioamexport_callback_api(self): |
| 58 | """ JVPP Ioamexport Callback Api Test Case """ |
| 59 | self.invoke_for_jvpp_core(api_jar_name="jvpp-ioamexport", |
| 60 | test_class_name="io.fd.vpp.jvpp.ioamexport." |
| 61 | "test.CallbackApiTest") |
| 62 | |
| 63 | def test_vpp_ioamexport_future_api(self): |
| 64 | """JVPP Ioamexport Future Api Test Case""" |
| 65 | self.invoke_for_jvpp_core(api_jar_name="jvpp-ioamexport", |
| 66 | test_class_name="io.fd.vpp.jvpp.ioamexport." |
| 67 | "test.FutureApiTest") |
| 68 | |
| 69 | def test_vpp_ioampot_callback_api(self): |
| 70 | """ JVPP Ioampot Callback Api Test Case """ |
| 71 | self.invoke_for_jvpp_core(api_jar_name="jvpp-ioampot", |
| 72 | test_class_name="io.fd.vpp.jvpp.ioampot." |
| 73 | "test.CallbackApiTest") |
| 74 | |
| 75 | def test_vpp_ioampot_future_api(self): |
| 76 | """JVPP Ioampot Future Api Test Case""" |
| 77 | self.invoke_for_jvpp_core(api_jar_name="jvpp-ioampot", |
| 78 | test_class_name="io.fd.vpp.jvpp.ioampot." |
| 79 | "test.FutureApiTest") |
| 80 | |
| 81 | def test_vpp_ioamtrace_callback_api(self): |
| 82 | """ JVPP Ioamtrace Callback Api Test Case """ |
| 83 | self.invoke_for_jvpp_core(api_jar_name="jvpp-ioamtrace", |
| 84 | test_class_name="io.fd.vpp.jvpp.ioamtrace." |
| 85 | "test.CallbackApiTest") |
| 86 | |
| 87 | def test_vpp_ioamtrace_future_api(self): |
| 88 | """JVPP Ioamtrace Future Api Test Case""" |
| 89 | self.invoke_for_jvpp_core(api_jar_name="jvpp-ioamtrace", |
| 90 | test_class_name="io.fd.vpp.jvpp.ioamtrace." |
| 91 | "test.FutureApiTest") |
| 92 | |
| 93 | def test_vpp_snat_callback_api(self): |
| 94 | """ JVPP Snat Callback Api Test Case """ |
| 95 | self.invoke_for_jvpp_core(api_jar_name="jvpp-nat", |
| 96 | test_class_name="io.fd.vpp.jvpp.nat.test." |
| 97 | "CallbackApiTest") |
| 98 | |
| 99 | def test_vpp_snat_future_api(self): |
| 100 | """JVPP Snat Future Api Test Case""" |
| 101 | self.invoke_for_jvpp_core(api_jar_name="jvpp-nat", |
| 102 | test_class_name="io.fd.vpp.jvpp.nat.test." |
| 103 | "FutureApiTest") |
Matej Perina | 6912a05 | 2017-09-25 10:54:47 +0200 | [diff] [blame] | 104 | |
| 105 | def full_jar_name(self, install_dir, jar_name, version): |
| 106 | return os.path.join(install_dir, API_FILES_PATH, |
| 107 | "{0}-{1}.jar".format(jar_name, version)) |
| 108 | |
| 109 | def jvpp_connection_test(self, api_jar_name, test_class_name, timeout): |
Klement Sekera | b8c72a4 | 2018-11-08 11:21:39 +0100 | [diff] [blame] | 110 | install_dir = os.getenv('VPP_BUILD_DIR') |
Matej Perina | 6912a05 | 2017-09-25 10:54:47 +0200 | [diff] [blame] | 111 | self.logger.info("Install directory : {0}".format(install_dir)) |
| 112 | |
| 113 | version_reply = self.vapi.show_version() |
| 114 | version = version_reply.version.split("-")[0] |
| 115 | registry_jar_path = self.full_jar_name(install_dir, |
| 116 | REGISTRY_JAR_PREFIX, version) |
| 117 | self.logger.info("JVpp Registry jar path : {0}" |
| 118 | .format(registry_jar_path)) |
Marek Gradzki | 7064c33 | 2018-07-18 10:32:23 +0200 | [diff] [blame] | 119 | if (not os.path.isfile(registry_jar_path)): |
| 120 | raise Exception( |
| 121 | "JVpp Registry jar has not been found: {0}" |
| 122 | .format(registry_jar_path)) |
Matej Perina | 6912a05 | 2017-09-25 10:54:47 +0200 | [diff] [blame] | 123 | |
| 124 | api_jar_path = self.full_jar_name(install_dir, api_jar_name, version) |
| 125 | self.logger.info("Api jar path : {0}".format(api_jar_path)) |
Marek Gradzki | 7064c33 | 2018-07-18 10:32:23 +0200 | [diff] [blame] | 126 | if (not os.path.isfile(api_jar_path)): |
| 127 | raise Exception( |
| 128 | "Api jar has not been found: {0}".format(api_jar_path)) |
Matej Perina | 6912a05 | 2017-09-25 10:54:47 +0200 | [diff] [blame] | 129 | |
| 130 | # passes shm prefix as parameter to create connection with same value |
| 131 | command = ["java", "-cp", |
| 132 | "{0}:{1}".format(registry_jar_path, api_jar_path), |
| 133 | test_class_name, "/{0}-vpe-api".format(self.shm_prefix)] |
| 134 | self.logger.info("Test Command : {0}, Timeout : {1}". |
| 135 | format(command, timeout)) |
| 136 | |
| 137 | self.process = subprocess.Popen(command, shell=False, |
| 138 | stdout=subprocess.PIPE, |
| 139 | stderr=subprocess.PIPE, bufsize=1, |
| 140 | universal_newlines=True) |
| 141 | |
| 142 | out, err = self.process.communicate() |
| 143 | self.logger.info("Process output : {0}{1}".format(os.linesep, out)) |
Marek Gradzki | cefa41f | 2018-04-06 12:00:52 +0200 | [diff] [blame] | 144 | |
| 145 | if self.process.returncode != 0: |
Paul Vinciguerra | 61e63bf | 2018-11-24 21:19:38 -0800 | [diff] [blame] | 146 | raise subprocess.CalledProcessError( |
Marek Gradzki | cefa41f | 2018-04-06 12:00:52 +0200 | [diff] [blame] | 147 | "Command {0} failed with return code: {1}.{2}" |
| 148 | "Process error output: {2}{3}" |
| 149 | .format(command, self.process.returncode, os.linesep, err)) |
Matej Perina | 6912a05 | 2017-09-25 10:54:47 +0200 | [diff] [blame] | 150 | |
| 151 | def tearDown(self): |
| 152 | self.logger.info("Tearing down jvpp test") |
| 153 | super(TestJVpp, self).tearDown() |
| 154 | if hasattr(self, 'process') and self.process.poll() is None: |
| 155 | self.process.kill() |