aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile2
-rw-r--r--test/framework.py28
-rw-r--r--test/test_ipsec_tun_if_esp.py4
-rw-r--r--test/vpp_papi_provider.py66
4 files changed, 49 insertions, 51 deletions
diff --git a/test/Makefile b/test/Makefile
index 514cb27fc14..084fc849897 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -401,8 +401,6 @@ help:
@echo ""
@echo " SKIP_AARCH64=1 - skip tests that are failing on the ARM platorm in FD.io CI"
@echo ""
- @echo " SOCKET=1 - Communicate with VPP over Unix domain socket instead of SHM"
- @echo ""
@echo " RND_SEED=seed - Seed RND with given seed"
@echo ""
@echo "Creating test documentation"
diff --git a/test/framework.py b/test/framework.py
index 4ccbc454b5b..4e0949bcf45 100644
--- a/test/framework.py
+++ b/test/framework.py
@@ -33,7 +33,7 @@ from vpp_bvi_interface import VppBviInterface
from vpp_papi_provider import VppPapiProvider
import vpp_papi
from vpp_papi.vpp_stats import VPPStats
-from vpp_papi.vpp_transport_shmem import VppTransportShmemIOError
+from vpp_papi.vpp_transport_socket import VppTransportSocketIOError
from log import RED, GREEN, YELLOW, double_line_delim, single_line_delim, \
get_logger, colorize
from vpp_object import VppObjectRegistry
@@ -564,10 +564,10 @@ class VppTestCase(unittest.TestCase):
cls.logger.addHandler(cls.file_handler)
cls.logger.debug("--- setUpClass() for %s called ---" %
cls.__name__)
- cls.shm_prefix = os.path.basename(cls.tempdir)
+ cls.shm_prefix = os.path.basename(cls.tempdir) # Only used for VAPI
os.chdir(cls.tempdir)
- cls.logger.info("Temporary dir is %s, shm prefix is %s",
- cls.tempdir, cls.shm_prefix)
+ cls.logger.info("Temporary dir is %s, api socket is %s",
+ cls.tempdir, cls.api_sock)
cls.logger.debug("Random seed is %s" % seed)
cls.setUpConstants()
cls.reset_packet_infos()
@@ -593,7 +593,7 @@ class VppTestCase(unittest.TestCase):
cls.pump_thread.start()
if cls.debug_gdb or cls.debug_gdbserver:
cls.vapi_response_timeout = 0
- cls.vapi = VppPapiProvider(cls.shm_prefix, cls.shm_prefix, cls,
+ cls.vapi = VppPapiProvider(cls.__name__, cls,
cls.vapi_response_timeout)
if cls.step:
hook = hookmodule.StepHook(cls)
@@ -611,7 +611,7 @@ class VppTestCase(unittest.TestCase):
raise
try:
cls.vapi.connect()
- except vpp_papi.VPPIOError as e:
+ except (vpp_papi.VPPIOError, Exception) as e:
cls.logger.debug("Exception connecting to vapi: %s" % e)
cls.vapi.disconnect()
@@ -619,15 +619,15 @@ class VppTestCase(unittest.TestCase):
print(colorize("You're running VPP inside gdbserver but "
"VPP-API connection failed, did you forget "
"to 'continue' VPP from within gdb?", RED))
- raise
+ raise e
except vpp_papi.VPPRuntimeError as e:
cls.logger.debug("%s" % e)
cls.quit()
- raise
+ raise e
except Exception as e:
cls.logger.debug("Exception connecting to VPP: %s" % e)
cls.quit()
- raise
+ raise e
@classmethod
def _debug_quit(cls):
@@ -679,7 +679,11 @@ class VppTestCase(unittest.TestCase):
cls.logger.debug("Sending TERM to vpp")
cls.vpp.terminate()
cls.logger.debug("Waiting for vpp to die")
- cls.vpp.communicate()
+ try:
+ outs, errs = cls.vpp.communicate(timeout=5)
+ except subprocess.TimeoutExpired:
+ cls.vpp.kill()
+ outs, errs = cls.vpp.communicate()
cls.logger.debug("Deleting class vpp attribute on %s",
cls.__name__)
cls.vpp.stdout.close()
@@ -758,8 +762,8 @@ class VppTestCase(unittest.TestCase):
os.rename(tmp_api_trace, vpp_api_trace_log)
self.logger.info(self.vapi.ppcli("api trace custom-dump %s" %
vpp_api_trace_log))
- except VppTransportShmemIOError:
- self.logger.debug("VppTransportShmemIOError: Vpp dead. "
+ except VppTransportSocketIOError:
+ self.logger.debug("VppTransportSocketIOError: Vpp dead. "
"Cannot log show commands.")
self.vpp_dead = True
else:
diff --git a/test/test_ipsec_tun_if_esp.py b/test/test_ipsec_tun_if_esp.py
index 158e911e0c7..b72d464c663 100644
--- a/test/test_ipsec_tun_if_esp.py
+++ b/test/test_ipsec_tun_if_esp.py
@@ -509,7 +509,7 @@ class TestIpsec6TunIfEspHandoff(TemplateIpsec6TunIfEsp,
stats0 = policer.get_stats(worker=0)
stats1 = policer.get_stats(worker=1)
- if pol_bind is 1:
+ if pol_bind == 1:
# First pass: Worker 1, should have done all the policing
self.assertEqual(stats, stats1)
@@ -581,7 +581,7 @@ class TestIpsec4TunIfEspHandoff(TemplateIpsec4TunIfEsp,
stats0 = policer.get_stats(worker=0)
stats1 = policer.get_stats(worker=1)
- if pol_bind is 1:
+ if pol_bind == 1:
# First pass: Worker 1, should have done all the policing
self.assertEqual(stats, stats1)
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index 81e25ecc621..da693c73e2a 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -8,13 +8,12 @@
import os
import time
from collections import deque
-
+import queue
from six import moves, iteritems
from vpp_papi import VPPApiClient, mac_pton
from hook import Hook
from vpp_ip_route import MPLS_IETF_MAX_LABEL, MPLS_LABEL_INVALID
-
#
# Dictionary keyed on message name to override default values for
# named parameters
@@ -131,10 +130,9 @@ class VppPapiProvider(object):
_zero, _negative = range(2)
- def __init__(self, name, shm_prefix, test_class, read_timeout):
+ def __init__(self, name, test_class, read_timeout):
self.hook = Hook(test_class)
self.name = name
- self.shm_prefix = shm_prefix
self.test_class = test_class
self._expect_api_retval = self._zero
self._expect_stack = []
@@ -143,18 +141,11 @@ class VppPapiProvider(object):
# calling the constructor.
VPPApiClient.apidir = os.getenv('VPP_INSTALL_PATH')
- use_socket = False
- try:
- if os.environ['SOCKET'] == '1':
- use_socket = True
- except KeyError:
- pass
-
self.vpp = VPPApiClient(logger=test_class.logger,
read_timeout=read_timeout,
- use_socket=use_socket,
+ use_socket=True,
server_address=test_class.api_sock)
- self._events = deque()
+ self._events = queue.Queue()
def __enter__(self):
return self
@@ -193,9 +184,14 @@ class VppPapiProvider(object):
def collect_events(self):
""" Collect all events from the internal queue and clear the queue. """
- e = self._events
- self._events = deque()
- return e
+ result = []
+ while True:
+ try:
+ e = self._events.get(block=False)
+ result.append(e)
+ except queue.Empty:
+ return result
+ return result
def wait_for_event(self, timeout, name=None):
""" Wait for and return next event. """
@@ -205,28 +201,21 @@ class VppPapiProvider(object):
else:
self.test_class.logger.debug("Expecting event within %ss",
timeout)
- if self._events:
- self.test_class.logger.debug("Not waiting, event already queued")
- limit = time.time() + timeout
- while time.time() < limit:
- if self._events:
- e = self._events.popleft()
- if name and type(e).__name__ != name:
- raise Exception(
- "Unexpected event received: %s, expected: %s" %
- (type(e).__name__, name))
- self.test_class.logger.debug("Returning event %s:%s" %
- (name, e))
- return e
- self.test_class.sleep(0) # yield
- raise Exception("Event did not occur within timeout")
+ try:
+ e = self._events.get(timeout=timeout)
+ except queue.Empty:
+ raise Exception("Event did not occur within timeout")
+ msgname = type(e).__name__
+ if name and msgname != name:
+ raise Exception("Unexpected event received: %s, expected: %s"
+ % msgname)
+ self.test_class.logger.debug("Returning event %s:%s" % (name, e))
+ return e
def __call__(self, name, event):
""" Enqueue event in the internal event queue. """
- # FIXME use the name instead of relying on type(e).__name__ ?
- # FIXME #2 if this throws, it is eaten silently, Ole?
self.test_class.logger.debug("New event: %s: %s" % (name, event))
- self._events.append(event)
+ self._events.put(event)
def factory(self, name, apifn):
def f(*a, **ka):
@@ -262,7 +251,14 @@ class VppPapiProvider(object):
def connect(self):
"""Connect the API to VPP"""
- self.vpp.connect(self.name, self.shm_prefix)
+ # This might be called before VPP is prepared to listen to the socket
+ retries = 0
+ while not os.path.exists(self.test_class.api_sock):
+ time.sleep(0.5)
+ retries += 1
+ if retries > 120:
+ break
+ self.vpp.connect(self.name[:63])
self.papi = self.vpp.api
self.vpp.register_event_callback(self)