blob: bb48745c34c4f50ed0a204683bf862d93bf273c2 [file] [log] [blame]
Matej Perinad135c192017-07-18 13:59:41 +02001#!/usr/bin/env python
2import os
3import subprocess
4from vpp_papi_provider import VppPapiProvider
5from threading import Timer
6
7from framework import VppTestCase
8
9# Api files path
10API_FILES_PATH = "vpp/vpp-api/java"
11
12# Registry jar file name prefix
13REGISTRY_JAR_PREFIX = "jvpp-registry"
14
15
16class TestJVppConnection(VppTestCase):
17
18 def full_jar_name(self, install_dir, jar_name, version):
19 return os.path.join(install_dir, API_FILES_PATH,
20 "{0}-{1}.jar".format(jar_name, version))
21
22 def jvpp_connection_test(self, api_jar_name, test_class_name, timeout):
23 install_dir = os.getenv('VPP_TEST_BUILD_DIR')
24 print("Install directory : {0}".format(install_dir))
25
26 version_reply = self.vapi.show_version()
27 version = version_reply.version.split("-")[0]
28 registry_jar_path = self.full_jar_name(install_dir,
29 REGISTRY_JAR_PREFIX, version)
30 print("JVpp Registry jar path : {0}".format(registry_jar_path))
31
32 api_jar_path = self.full_jar_name(install_dir, api_jar_name, version)
33 print("Api jar path : {0}".format(api_jar_path))
34
35 # passes shm prefix as parameter to create connection with same value
36 command = ["java", "-cp",
37 "{0}:{1}".format(registry_jar_path, api_jar_path),
38 test_class_name, "/{0}-vpe-api".format(self.shm_prefix)]
39 print("Test Command : {0}, Timeout : {1}".format(command, timeout))
40
41 self.process = subprocess.Popen(command, shell=False,
42 stdout=subprocess.PIPE,
43 stderr=subprocess.PIPE, bufsize=1,
44 universal_newlines=True)
45
46 out, err = self.process.communicate()
47 print("Process output : {0}{1}".format(os.linesep, out))
48 print("Process error output : {0}{1}".format(os.linesep, err))
49 self.assert_equal(self.process.returncode, 0, "process return code")
50
51 def tearDown(self):
52 print("Tearing down jvpp test")
53 if self.process.poll() is None:
54 self.process.kill()