7 from framework import VppTestCase, running_extended_tests
10 API_FILES_PATH = "japi/java"
12 # Registry jar file name prefix
13 REGISTRY_JAR_PREFIX = "jvpp-registry"
16 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
17 class TestJVpp(VppTestCase):
18 """ JVPP Core Test Case """
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,
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."
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."
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."
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."
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")
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."
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")
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."
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")
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."
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."
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."
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))
101 def jvpp_connection_test(self, api_jar_name, test_class_name, timeout):
102 install_dir = os.getenv('VPP_TEST_BUILD_DIR')
103 self.logger.info("Install directory : {0}".format(install_dir))
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))
111 if (not os.path.isfile(registry_jar_path)):
113 "JVpp Registry jar has not been found: {0}"
114 .format(registry_jar_path))
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))
118 if (not os.path.isfile(api_jar_path)):
120 "Api jar has not been found: {0}".format(api_jar_path))
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))
129 self.process = subprocess.Popen(command, shell=False,
130 stdout=subprocess.PIPE,
131 stderr=subprocess.PIPE, bufsize=1,
132 universal_newlines=True)
134 out, err = self.process.communicate()
135 self.logger.info("Process output : {0}{1}".format(os.linesep, out))
137 if self.process.returncode != 0:
139 "Command {0} failed with return code: {1}.{2}"
140 "Process error output: {2}{3}"
141 .format(command, self.process.returncode, os.linesep, err))
144 self.logger.info("Tearing down jvpp test")
145 super(TestJVpp, self).tearDown()
146 if hasattr(self, 'process') and self.process.poll() is None: