diff options
author | Michal Cmarada <mcmarada@cisco.com> | 2019-02-08 12:28:09 +0100 |
---|---|---|
committer | Michal Cmarada <mcmarada@cisco.com> | 2019-03-11 12:12:37 +0100 |
commit | dc0453b3a97feb02e66e4888e8d071e8116aa806 (patch) | |
tree | 91ee70acc176c09ad394883d848d596aaa56c108 /tests/test_jvpp.py | |
parent | 2388db4347cf0c4a1032cb945db2fdb1011d74d7 (diff) |
add test and checkstyle support
All tests are in "tests" directory.
To run tests use:
make test
For verbose output use:
export V=2;make test ARGS="-V"
Test log file is generated in:
Testing/Temporary/LastTest.log
To run checkstyle for the current commit use:
./scripts/checkstyle.sh
To run full check on all files use:
./scripts/checkstyle.sh --full
Change-Id: Ic83b3dbd44d2a264d27935f4e65cf9e737cfc0a0
Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
Diffstat (limited to 'tests/test_jvpp.py')
-rw-r--r-- | tests/test_jvpp.py | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/tests/test_jvpp.py b/tests/test_jvpp.py new file mode 100644 index 0000000..862b285 --- /dev/null +++ b/tests/test_jvpp.py @@ -0,0 +1,160 @@ +#!/usr/bin/env python + +# Copyright (c) 2019 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import subprocess +import unittest +from log import get_logger + +API_FILES_PATH = "java/" + +# Registry jar file name prefix +REGISTRY_JAR_PREFIX = "jvpp-registry" + + +class TestJVpp(unittest.TestCase): + """ JVPP Core Test Case """ + + def invoke_for_jvpp_core(self, api_jar_name, test_class_name): + self.jvpp_connection_test(api_jar_name=api_jar_name, + test_class_name=test_class_name) + + def test_vpp_core_callback_api(self): + """ JVPP Core Callback Api Test Case """ + self.invoke_for_jvpp_core(api_jar_name="jvpp-core", + test_class_name="io.fd.jvpp.core.test." + "CallbackApiTest") + + def test_vpp_registry_callback_api(self): + """ JVPP Core Callback Api Test Case """ + self.invoke_for_jvpp_core(api_jar_name="jvpp-registry", + test_class_name="io.fd.jvpp.test." + "ConnectionTest") + + def test_vpp_core_future_api(self): + """JVPP Core Future Api Test Case""" + self.invoke_for_jvpp_core(api_jar_name="jvpp-core", + test_class_name="io.fd.jvpp.core.test." + "FutureApiTest") + + def test_vpp_acl_callback_api(self): + """ JVPP Acl Callback Api Test Case """ + self.invoke_for_jvpp_core(api_jar_name="jvpp-acl", + test_class_name="io.fd.jvpp.acl.test." + "CallbackApiTest") + + def test_vpp_acl_future_api(self): + """JVPP Acl Future Api Test Case""" + self.invoke_for_jvpp_core(api_jar_name="jvpp-acl", + test_class_name="io.fd.jvpp.acl.test." + "FutureApiTest") + + def test_vpp_ioamexport_callback_api(self): + """ JVPP Ioamexport Callback Api Test Case """ + self.invoke_for_jvpp_core(api_jar_name="jvpp-ioamexport", + test_class_name="io.fd.jvpp.ioamexport." + "test.CallbackApiTest") + + def test_vpp_ioamexport_future_api(self): + """JVPP Ioamexport Future Api Test Case""" + self.invoke_for_jvpp_core(api_jar_name="jvpp-ioamexport", + test_class_name="io.fd.jvpp.ioamexport." + "test.FutureApiTest") + + def test_vpp_ioampot_callback_api(self): + """ JVPP Ioampot Callback Api Test Case """ + self.invoke_for_jvpp_core(api_jar_name="jvpp-ioampot", + test_class_name="io.fd.jvpp.ioampot." + "test.CallbackApiTest") + + def test_vpp_ioampot_future_api(self): + """JVPP Ioampot Future Api Test Case""" + self.invoke_for_jvpp_core(api_jar_name="jvpp-ioampot", + test_class_name="io.fd.jvpp.ioampot." + "test.FutureApiTest") + + def test_vpp_ioamtrace_callback_api(self): + """ JVPP Ioamtrace Callback Api Test Case """ + self.invoke_for_jvpp_core(api_jar_name="jvpp-ioamtrace", + test_class_name="io.fd.jvpp.ioamtrace." + "test.CallbackApiTest") + + def test_vpp_ioamtrace_future_api(self): + """JVPP Ioamtrace Future Api Test Case""" + self.invoke_for_jvpp_core(api_jar_name="jvpp-ioamtrace", + test_class_name="io.fd.jvpp.ioamtrace." + "test.FutureApiTest") + + def test_vpp_snat_callback_api(self): + """ JVPP Snat Callback Api Test Case """ + self.invoke_for_jvpp_core(api_jar_name="jvpp-nat", + test_class_name="io.fd.jvpp.nat.test." + "CallbackApiTest") + + def test_vpp_snat_future_api(self): + """JVPP Snat Future Api Test Case""" + self.invoke_for_jvpp_core(api_jar_name="jvpp-nat", + test_class_name="io.fd.jvpp.nat.test." + "FutureApiTest") + + @staticmethod + def full_jar_name(install_dir, jar_name, version): + return os.path.join(install_dir, API_FILES_PATH, + "{0}-{1}.jar".format(jar_name, version)) + + def jvpp_connection_test(self, api_jar_name, test_class_name): + self.logger = get_logger(api_jar_name) + install_dir = os.path.abspath('..') + self.logger.info("Install directory : {0}".format(install_dir)) + self.shm_prefix = "honeycomb" + proc = subprocess.Popen(['../version'], stdout=subprocess.PIPE) + version = proc.stdout.read().split("-")[0] + registry_jar_path = self.full_jar_name(install_dir, REGISTRY_JAR_PREFIX, version) + self.logger.info("JVpp Registry jar path : {0}".format(registry_jar_path)) + if not os.path.isfile(registry_jar_path): + raise Exception( + "JVpp Registry jar has not been found: {0}" + .format(registry_jar_path)) + + api_jar_path = self.full_jar_name(install_dir, api_jar_name, version) + self.logger.info("Api jar path : {0}".format(api_jar_path)) + if not os.path.isfile(api_jar_path): + raise Exception( + "Api jar has not been found: {0}".format(api_jar_path)) + + # passes shm prefix as parameter to create connection with same value + command = ["sudo", "java", "-cp", + "{0}:{1}".format(registry_jar_path, api_jar_path), + test_class_name, "/vpe-api"] + + self.process = subprocess.Popen(command, shell=False, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, bufsize=1, + universal_newlines=True) + + out, err = self.process.communicate() + self.logger.info("Process output : {0}{1}".format(os.linesep, out)) + + if self.process.returncode != 0: + raise subprocess.CalledProcessError(self.process.returncode, command, + "Command {0} failed with return code: {1}.{2}" + "Process error output: {2}{3}" + .format(command, self.process.returncode, os.linesep, err)) + + def tearDown(self): + self.logger.info("Tearing down jvpp test") + super(TestJVpp, self).tearDown() + if hasattr(self, 'process') and self.process.poll() is None: + self.process.kill() |