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