blob: c3b93576f71230bdae56112f6d910bfb8b51d9d5 [file] [log] [blame]
Matej Perina6912a052017-09-25 10:54:47 +02001#!/usr/bin/env python
2
3import os
4import subprocess
5
6from framework import VppTestCase
7
8# Api files path
9API_FILES_PATH = "vpp/vpp-api/java"
10
11# Registry jar file name prefix
12REGISTRY_JAR_PREFIX = "jvpp-registry"
Matej Perinad135c192017-07-18 13:59:41 +020013
14
Matej Perina6912a052017-09-25 10:54:47 +020015class TestJVpp(VppTestCase):
Matej Perinad135c192017-07-18 13:59:41 +020016 """ JVPP Core Test Case """
17
18 def invoke_for_jvpp_core(self, api_jar_name, test_class_name):
19 self.jvpp_connection_test(api_jar_name=api_jar_name,
20 test_class_name=test_class_name,
21 timeout=10)
22
23 def test_vpp_core_callback_api(self):
24 """ JVPP Core Callback Api Test Case """
25 self.invoke_for_jvpp_core(api_jar_name="jvpp-core",
26 test_class_name="io.fd.vpp.jvpp.core.test."
27 "CallbackApiTest")
28
29 def test_vpp_core_future_api(self):
30 """JVPP Core Future Api Test Case"""
31 self.invoke_for_jvpp_core(api_jar_name="jvpp-core",
32 test_class_name="io.fd.vpp.jvpp.core.test."
33 "FutureApiTest")
34
35 def test_vpp_acl_callback_api(self):
36 """ JVPP Acl Callback Api Test Case """
37 self.invoke_for_jvpp_core(api_jar_name="jvpp-acl",
38 test_class_name="io.fd.vpp.jvpp.acl.test."
39 "CallbackApiTest")
40
41 def test_vpp_acl_future_api(self):
42 """JVPP Acl Future Api Test Case"""
43 self.invoke_for_jvpp_core(api_jar_name="jvpp-acl",
44 test_class_name="io.fd.vpp.jvpp.acl.test."
45 "FutureApiTest")
46
47 def test_vpp_ioamexport_callback_api(self):
48 """ JVPP Ioamexport Callback Api Test Case """
49 self.invoke_for_jvpp_core(api_jar_name="jvpp-ioamexport",
50 test_class_name="io.fd.vpp.jvpp.ioamexport."
51 "test.CallbackApiTest")
52
53 def test_vpp_ioamexport_future_api(self):
54 """JVPP Ioamexport Future Api Test Case"""
55 self.invoke_for_jvpp_core(api_jar_name="jvpp-ioamexport",
56 test_class_name="io.fd.vpp.jvpp.ioamexport."
57 "test.FutureApiTest")
58
59 def test_vpp_ioampot_callback_api(self):
60 """ JVPP Ioampot Callback Api Test Case """
61 self.invoke_for_jvpp_core(api_jar_name="jvpp-ioampot",
62 test_class_name="io.fd.vpp.jvpp.ioampot."
63 "test.CallbackApiTest")
64
65 def test_vpp_ioampot_future_api(self):
66 """JVPP Ioampot Future Api Test Case"""
67 self.invoke_for_jvpp_core(api_jar_name="jvpp-ioampot",
68 test_class_name="io.fd.vpp.jvpp.ioampot."
69 "test.FutureApiTest")
70
71 def test_vpp_ioamtrace_callback_api(self):
72 """ JVPP Ioamtrace Callback Api Test Case """
73 self.invoke_for_jvpp_core(api_jar_name="jvpp-ioamtrace",
74 test_class_name="io.fd.vpp.jvpp.ioamtrace."
75 "test.CallbackApiTest")
76
77 def test_vpp_ioamtrace_future_api(self):
78 """JVPP Ioamtrace Future Api Test Case"""
79 self.invoke_for_jvpp_core(api_jar_name="jvpp-ioamtrace",
80 test_class_name="io.fd.vpp.jvpp.ioamtrace."
81 "test.FutureApiTest")
82
83 def test_vpp_snat_callback_api(self):
84 """ JVPP Snat Callback Api Test Case """
85 self.invoke_for_jvpp_core(api_jar_name="jvpp-nat",
86 test_class_name="io.fd.vpp.jvpp.nat.test."
87 "CallbackApiTest")
88
89 def test_vpp_snat_future_api(self):
90 """JVPP Snat Future Api Test Case"""
91 self.invoke_for_jvpp_core(api_jar_name="jvpp-nat",
92 test_class_name="io.fd.vpp.jvpp.nat.test."
93 "FutureApiTest")
Matej Perina6912a052017-09-25 10:54:47 +020094
95 def full_jar_name(self, install_dir, jar_name, version):
96 return os.path.join(install_dir, API_FILES_PATH,
97 "{0}-{1}.jar".format(jar_name, version))
98
99 def jvpp_connection_test(self, api_jar_name, test_class_name, timeout):
100 install_dir = os.getenv('VPP_TEST_BUILD_DIR')
101 self.logger.info("Install directory : {0}".format(install_dir))
102
103 version_reply = self.vapi.show_version()
104 version = version_reply.version.split("-")[0]
105 registry_jar_path = self.full_jar_name(install_dir,
106 REGISTRY_JAR_PREFIX, version)
107 self.logger.info("JVpp Registry jar path : {0}"
108 .format(registry_jar_path))
109
110 api_jar_path = self.full_jar_name(install_dir, api_jar_name, version)
111 self.logger.info("Api jar path : {0}".format(api_jar_path))
112
113 # passes shm prefix as parameter to create connection with same value
114 command = ["java", "-cp",
115 "{0}:{1}".format(registry_jar_path, api_jar_path),
116 test_class_name, "/{0}-vpe-api".format(self.shm_prefix)]
117 self.logger.info("Test Command : {0}, Timeout : {1}".
118 format(command, timeout))
119
120 self.process = subprocess.Popen(command, shell=False,
121 stdout=subprocess.PIPE,
122 stderr=subprocess.PIPE, bufsize=1,
123 universal_newlines=True)
124
125 out, err = self.process.communicate()
126 self.logger.info("Process output : {0}{1}".format(os.linesep, out))
Marek Gradzkicefa41f2018-04-06 12:00:52 +0200127
128 if self.process.returncode != 0:
129 raise Exception(
130 "Command {0} failed with return code: {1}.{2}"
131 "Process error output: {2}{3}"
132 .format(command, self.process.returncode, os.linesep, err))
Matej Perina6912a052017-09-25 10:54:47 +0200133
134 def tearDown(self):
135 self.logger.info("Tearing down jvpp test")
136 super(TestJVpp, self).tearDown()
137 if hasattr(self, 'process') and self.process.poll() is None:
138 self.process.kill()