blob: b716af3920569a33afe483b41bb1baa0b0da63ca [file] [log] [blame]
Matej Perina6912a052017-09-25 10:54:47 +02001#!/usr/bin/env python
2
3import os
4import subprocess
Damjan Marioncc4a5e82018-07-30 16:10:14 +02005import unittest
Matej Perina6912a052017-09-25 10:54:47 +02006
Damjan Marioncc4a5e82018-07-30 16:10:14 +02007from framework import VppTestCase, running_extended_tests
Matej Perina6912a052017-09-25 10:54:47 +02008
9# Api files path
Damjan Marioncc4a5e82018-07-30 16:10:14 +020010API_FILES_PATH = "japi/java"
Matej Perina6912a052017-09-25 10:54:47 +020011
12# Registry jar file name prefix
13REGISTRY_JAR_PREFIX = "jvpp-registry"
Matej Perinad135c192017-07-18 13:59:41 +020014
15
Paul Vinciguerradefde0f2018-12-06 07:46:13 -080016@unittest.skipUnless(running_extended_tests, "part of extended tests")
Matej Perina6912a052017-09-25 10:54:47 +020017class TestJVpp(VppTestCase):
Matej Perinad135c192017-07-18 13:59:41 +020018 """ 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 Perina6912a052017-09-25 10:54:47 +020096
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 Sekerab8c72a42018-11-08 11:21:39 +0100102 install_dir = os.getenv('VPP_BUILD_DIR')
Matej Perina6912a052017-09-25 10:54:47 +0200103 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 Gradzki7064c332018-07-18 10:32:23 +0200111 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 Perina6912a052017-09-25 10:54:47 +0200115
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 Gradzki7064c332018-07-18 10:32:23 +0200118 if (not os.path.isfile(api_jar_path)):
119 raise Exception(
120 "Api jar has not been found: {0}".format(api_jar_path))
Matej Perina6912a052017-09-25 10:54:47 +0200121
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 Gradzkicefa41f2018-04-06 12:00:52 +0200136
137 if self.process.returncode != 0:
Paul Vinciguerra61e63bf2018-11-24 21:19:38 -0800138 raise subprocess.CalledProcessError(
Marek Gradzkicefa41f2018-04-06 12:00:52 +0200139 "Command {0} failed with return code: {1}.{2}"
140 "Process error output: {2}{3}"
141 .format(command, self.process.returncode, os.linesep, err))
Matej Perina6912a052017-09-25 10:54:47 +0200142
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()