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