2019-10-31 13:31:07 -05:00
|
|
|
#!/usr/bin/env python3
|
2016-10-03 19:44:57 +02:00
|
|
|
|
2017-02-14 02:55:31 +01:00
|
|
|
from __future__ import print_function
|
|
|
|
import gc
|
2019-12-01 22:24:28 -05:00
|
|
|
import logging
|
Revert "VPP-1508 python3 tests: raw_input"
This reverts commit 72f0004ac5f6e201cbe042593d76df6f2491d743.
Reason for revert: Traceback (most recent call last):
File "/home/ksekera/vpp/test/test_ipsec_ah.py", line 36, in
setUpClass
super(TemplateIpsecAh, cls).setUpClass()
File "/home/ksekera/vpp/test/template_ipsec.py", line 105, in
setUpClass
super(TemplateIpsec, cls).setUpClass()
File "/home/ksekera/vpp/test/framework.py", line 459, in setUpClass
cls.quit()
File "/home/ksekera/vpp/test/framework.py", line 475, in quit
six.input("When done debugging, press ENTER to kill the "
AttributeError: 'module' object has no attribute 'input'
Change-Id: Idf0bbfea231730b37bae5dcb4557a0f82ab1b810
Signed-off-by: Ole Troan <ot@cisco.com>
2018-11-26 10:27:50 +00:00
|
|
|
import sys
|
2017-02-14 02:55:31 +01:00
|
|
|
import os
|
|
|
|
import select
|
2019-06-20 12:24:12 -04:00
|
|
|
import signal
|
2020-12-05 22:39:14 +00:00
|
|
|
import subprocess
|
Revert "VPP-1508 python3 tests: raw_input"
This reverts commit 72f0004ac5f6e201cbe042593d76df6f2491d743.
Reason for revert: Traceback (most recent call last):
File "/home/ksekera/vpp/test/test_ipsec_ah.py", line 36, in
setUpClass
super(TemplateIpsecAh, cls).setUpClass()
File "/home/ksekera/vpp/test/template_ipsec.py", line 105, in
setUpClass
super(TemplateIpsec, cls).setUpClass()
File "/home/ksekera/vpp/test/framework.py", line 459, in setUpClass
cls.quit()
File "/home/ksekera/vpp/test/framework.py", line 475, in quit
six.input("When done debugging, press ENTER to kill the "
AttributeError: 'module' object has no attribute 'input'
Change-Id: Idf0bbfea231730b37bae5dcb4557a0f82ab1b810
Signed-off-by: Ole Troan <ot@cisco.com>
2018-11-26 10:27:50 +00:00
|
|
|
import unittest
|
2016-10-11 11:47:09 +02:00
|
|
|
import tempfile
|
2016-10-28 13:20:27 +02:00
|
|
|
import time
|
Revert "VPP-1508 python3 tests: raw_input"
This reverts commit 72f0004ac5f6e201cbe042593d76df6f2491d743.
Reason for revert: Traceback (most recent call last):
File "/home/ksekera/vpp/test/test_ipsec_ah.py", line 36, in
setUpClass
super(TemplateIpsecAh, cls).setUpClass()
File "/home/ksekera/vpp/test/template_ipsec.py", line 105, in
setUpClass
super(TemplateIpsec, cls).setUpClass()
File "/home/ksekera/vpp/test/framework.py", line 459, in setUpClass
cls.quit()
File "/home/ksekera/vpp/test/framework.py", line 475, in quit
six.input("When done debugging, press ENTER to kill the "
AttributeError: 'module' object has no attribute 'input'
Change-Id: Idf0bbfea231730b37bae5dcb4557a0f82ab1b810
Signed-off-by: Ole Troan <ot@cisco.com>
2018-11-26 10:27:50 +00:00
|
|
|
import faulthandler
|
|
|
|
import random
|
|
|
|
import copy
|
|
|
|
import psutil
|
2018-11-29 09:37:08 +01:00
|
|
|
import platform
|
2016-12-08 10:16:41 +01:00
|
|
|
from collections import deque
|
2018-11-25 11:05:13 -08:00
|
|
|
from threading import Thread, Event
|
Revert "VPP-1508 python3 tests: raw_input"
This reverts commit 72f0004ac5f6e201cbe042593d76df6f2491d743.
Reason for revert: Traceback (most recent call last):
File "/home/ksekera/vpp/test/test_ipsec_ah.py", line 36, in
setUpClass
super(TemplateIpsecAh, cls).setUpClass()
File "/home/ksekera/vpp/test/template_ipsec.py", line 105, in
setUpClass
super(TemplateIpsec, cls).setUpClass()
File "/home/ksekera/vpp/test/framework.py", line 459, in setUpClass
cls.quit()
File "/home/ksekera/vpp/test/framework.py", line 475, in quit
six.input("When done debugging, press ENTER to kill the "
AttributeError: 'module' object has no attribute 'input'
Change-Id: Idf0bbfea231730b37bae5dcb4557a0f82ab1b810
Signed-off-by: Ole Troan <ot@cisco.com>
2018-11-26 10:27:50 +00:00
|
|
|
from inspect import getdoc, isclass
|
2018-11-25 11:05:13 -08:00
|
|
|
from traceback import format_exception
|
Revert "VPP-1508 python3 tests: raw_input"
This reverts commit 72f0004ac5f6e201cbe042593d76df6f2491d743.
Reason for revert: Traceback (most recent call last):
File "/home/ksekera/vpp/test/test_ipsec_ah.py", line 36, in
setUpClass
super(TemplateIpsecAh, cls).setUpClass()
File "/home/ksekera/vpp/test/template_ipsec.py", line 105, in
setUpClass
super(TemplateIpsec, cls).setUpClass()
File "/home/ksekera/vpp/test/framework.py", line 459, in setUpClass
cls.quit()
File "/home/ksekera/vpp/test/framework.py", line 475, in quit
six.input("When done debugging, press ENTER to kill the "
AttributeError: 'module' object has no attribute 'input'
Change-Id: Idf0bbfea231730b37bae5dcb4557a0f82ab1b810
Signed-off-by: Ole Troan <ot@cisco.com>
2018-11-26 10:27:50 +00:00
|
|
|
from logging import FileHandler, DEBUG, Formatter
|
2019-03-10 10:04:23 -07:00
|
|
|
|
|
|
|
import scapy.compat
|
2017-02-14 02:55:31 +01:00
|
|
|
from scapy.packet import Raw
|
2019-06-20 12:24:12 -04:00
|
|
|
import hook as hookmodule
|
2018-12-17 21:43:43 -08:00
|
|
|
from vpp_pg_interface import VppPGInterface
|
2018-12-21 16:04:22 +01:00
|
|
|
from vpp_sub_interface import VppSubInterface
|
Revert "VPP-1508 python3 tests: raw_input"
This reverts commit 72f0004ac5f6e201cbe042593d76df6f2491d743.
Reason for revert: Traceback (most recent call last):
File "/home/ksekera/vpp/test/test_ipsec_ah.py", line 36, in
setUpClass
super(TemplateIpsecAh, cls).setUpClass()
File "/home/ksekera/vpp/test/template_ipsec.py", line 105, in
setUpClass
super(TemplateIpsec, cls).setUpClass()
File "/home/ksekera/vpp/test/framework.py", line 459, in setUpClass
cls.quit()
File "/home/ksekera/vpp/test/framework.py", line 475, in quit
six.input("When done debugging, press ENTER to kill the "
AttributeError: 'module' object has no attribute 'input'
Change-Id: Idf0bbfea231730b37bae5dcb4557a0f82ab1b810
Signed-off-by: Ole Troan <ot@cisco.com>
2018-11-26 10:27:50 +00:00
|
|
|
from vpp_lo_interface import VppLoInterface
|
2019-03-15 02:16:20 -07:00
|
|
|
from vpp_bvi_interface import VppBviInterface
|
Revert "VPP-1508 python3 tests: raw_input"
This reverts commit 72f0004ac5f6e201cbe042593d76df6f2491d743.
Reason for revert: Traceback (most recent call last):
File "/home/ksekera/vpp/test/test_ipsec_ah.py", line 36, in
setUpClass
super(TemplateIpsecAh, cls).setUpClass()
File "/home/ksekera/vpp/test/template_ipsec.py", line 105, in
setUpClass
super(TemplateIpsec, cls).setUpClass()
File "/home/ksekera/vpp/test/framework.py", line 459, in setUpClass
cls.quit()
File "/home/ksekera/vpp/test/framework.py", line 475, in quit
six.input("When done debugging, press ENTER to kill the "
AttributeError: 'module' object has no attribute 'input'
Change-Id: Idf0bbfea231730b37bae5dcb4557a0f82ab1b810
Signed-off-by: Ole Troan <ot@cisco.com>
2018-11-26 10:27:50 +00:00
|
|
|
from vpp_papi_provider import VppPapiProvider
|
2019-12-02 21:42:28 -05:00
|
|
|
import vpp_papi
|
Revert "VPP-1508 python3 tests: raw_input"
This reverts commit 72f0004ac5f6e201cbe042593d76df6f2491d743.
Reason for revert: Traceback (most recent call last):
File "/home/ksekera/vpp/test/test_ipsec_ah.py", line 36, in
setUpClass
super(TemplateIpsecAh, cls).setUpClass()
File "/home/ksekera/vpp/test/template_ipsec.py", line 105, in
setUpClass
super(TemplateIpsec, cls).setUpClass()
File "/home/ksekera/vpp/test/framework.py", line 459, in setUpClass
cls.quit()
File "/home/ksekera/vpp/test/framework.py", line 475, in quit
six.input("When done debugging, press ENTER to kill the "
AttributeError: 'module' object has no attribute 'input'
Change-Id: Idf0bbfea231730b37bae5dcb4557a0f82ab1b810
Signed-off-by: Ole Troan <ot@cisco.com>
2018-11-26 10:27:50 +00:00
|
|
|
from vpp_papi.vpp_stats import VPPStats
|
tests: framework gracefully handle 'VppTransportShmemIOError'
Catches:
----
Traceback (most recent call last):
File "/vpp/test/framework.py", line 593, in tearDown
self.logger.info(self.vapi.ppcli("api trace save %s" % api_trace))
File "/vpp/test/vpp_papi_provider.py", line 413, in ppcli
return cli + "\n" + str(self.cli(cli))
File "/vpp/test/vpp_papi_provider.py", line 402, in cli
r = self.papi.cli_inband(cmd=cli)
File "/vpp/src/vpp-api/python/vpp_papi/vpp_papi.py", line 100, in __call__
return self._func(**kwargs)
File "/vpp/src/vpp-api/python/vpp_papi/vpp_papi.py", line 414, in f
return self._call_vpp(i, msg, multipart, **kwargs)
File "/vpp/src/vpp-api/python/vpp_papi/vpp_papi.py", line 634, in _call_vpp
msg = self.transport.read()
File "/vpp/src/vpp-api/python/vpp_papi/vpp_transport_shmem.py", line 120, in read
raise VppTransportShmemIOError(rv, 'vac_read failed')
VppTransportShmemIOError: [Errno -1] vac_read failed
----
Change-Id: I767e48c4d03081eb5df6a8aa67da7e192d25e4cc
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2019-03-15 09:39:19 -07:00
|
|
|
from vpp_papi.vpp_transport_shmem import VppTransportShmemIOError
|
2018-03-14 18:14:49 +01:00
|
|
|
from log import RED, GREEN, YELLOW, double_line_delim, single_line_delim, \
|
2018-11-09 11:58:54 +01:00
|
|
|
get_logger, colorize
|
2018-11-25 11:05:13 -08:00
|
|
|
from vpp_object import VppObjectRegistry
|
Revert "VPP-1508 python3 tests: raw_input"
This reverts commit 72f0004ac5f6e201cbe042593d76df6f2491d743.
Reason for revert: Traceback (most recent call last):
File "/home/ksekera/vpp/test/test_ipsec_ah.py", line 36, in
setUpClass
super(TemplateIpsecAh, cls).setUpClass()
File "/home/ksekera/vpp/test/template_ipsec.py", line 105, in
setUpClass
super(TemplateIpsec, cls).setUpClass()
File "/home/ksekera/vpp/test/framework.py", line 459, in setUpClass
cls.quit()
File "/home/ksekera/vpp/test/framework.py", line 475, in quit
six.input("When done debugging, press ENTER to kill the "
AttributeError: 'module' object has no attribute 'input'
Change-Id: Idf0bbfea231730b37bae5dcb4557a0f82ab1b810
Signed-off-by: Ole Troan <ot@cisco.com>
2018-11-26 10:27:50 +00:00
|
|
|
from util import ppp, is_core_present
|
|
|
|
from scapy.layers.inet import IPerror, TCPerror, UDPerror, ICMPerror
|
|
|
|
from scapy.layers.inet6 import ICMPv6DestUnreach, ICMPv6EchoRequest
|
|
|
|
from scapy.layers.inet6 import ICMPv6EchoReply
|
2018-12-09 15:37:04 -08:00
|
|
|
|
2019-12-01 22:24:28 -05:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
# Set up an empty logger for the testcase that can be overridden as necessary
|
|
|
|
null_logger = logging.getLogger('VppTestCase')
|
|
|
|
null_logger.addHandler(logging.NullHandler())
|
|
|
|
|
2018-09-19 15:01:47 +02:00
|
|
|
PASS = 0
|
|
|
|
FAIL = 1
|
|
|
|
ERROR = 2
|
|
|
|
SKIP = 3
|
|
|
|
TEST_RUN = 4
|
|
|
|
|
2019-07-03 08:38:38 -04:00
|
|
|
|
|
|
|
class BoolEnvironmentVariable(object):
|
|
|
|
|
|
|
|
def __init__(self, env_var_name, default='n', true_values=None):
|
|
|
|
self.name = env_var_name
|
|
|
|
self.default = default
|
|
|
|
self.true_values = true_values if true_values is not None else \
|
|
|
|
("y", "yes", "1")
|
|
|
|
|
|
|
|
def __bool__(self):
|
|
|
|
return os.getenv(self.name, self.default).lower() in self.true_values
|
|
|
|
|
|
|
|
if sys.version_info[0] == 2:
|
|
|
|
__nonzero__ = __bool__
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return 'BoolEnvironmentVariable(%r, default=%r, true_values=%r)' % \
|
|
|
|
(self.name, self.default, self.true_values)
|
|
|
|
|
|
|
|
|
|
|
|
debug_framework = BoolEnvironmentVariable('TEST_DEBUG')
|
|
|
|
if debug_framework:
|
2018-02-17 13:41:33 +01:00
|
|
|
import debug_internal
|
|
|
|
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
Test framework module.
|
|
|
|
|
|
|
|
The module provides a set of tools for constructing and running tests and
|
|
|
|
representing the results.
|
|
|
|
"""
|
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
|
2019-06-20 12:24:12 -04:00
|
|
|
class VppDiedError(Exception):
|
|
|
|
""" exception for reporting that the subprocess has died."""
|
|
|
|
|
|
|
|
signals_by_value = {v: k for k, v in signal.__dict__.items() if
|
|
|
|
k.startswith('SIG') and not k.startswith('SIG_')}
|
|
|
|
|
2019-06-19 10:29:24 -04:00
|
|
|
def __init__(self, rv=None, testcase=None, method_name=None):
|
2019-06-20 12:24:12 -04:00
|
|
|
self.rv = rv
|
|
|
|
self.signal_name = None
|
2019-06-19 10:29:24 -04:00
|
|
|
self.testcase = testcase
|
|
|
|
self.method_name = method_name
|
|
|
|
|
2019-06-20 12:24:12 -04:00
|
|
|
try:
|
|
|
|
self.signal_name = VppDiedError.signals_by_value[-rv]
|
2019-06-26 20:45:08 -04:00
|
|
|
except (KeyError, TypeError):
|
2019-06-20 12:24:12 -04:00
|
|
|
pass
|
|
|
|
|
2019-06-19 10:29:24 -04:00
|
|
|
if testcase is None and method_name is None:
|
|
|
|
in_msg = ''
|
|
|
|
else:
|
|
|
|
in_msg = 'running %s.%s ' % (testcase, method_name)
|
|
|
|
|
|
|
|
msg = "VPP subprocess died %sunexpectedly with return code: %d%s." % (
|
|
|
|
in_msg,
|
2019-06-20 12:24:12 -04:00
|
|
|
self.rv,
|
2019-07-13 09:35:38 -04:00
|
|
|
' [%s]' % (self.signal_name if
|
|
|
|
self.signal_name is not None else ''))
|
2019-06-20 12:24:12 -04:00
|
|
|
super(VppDiedError, self).__init__(msg)
|
|
|
|
|
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
class _PacketInfo(object):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""Private class to create packet info object.
|
|
|
|
|
|
|
|
Help process information about the next packet.
|
|
|
|
Set variables to default values.
|
|
|
|
"""
|
2016-11-11 11:38:55 +01:00
|
|
|
#: Store the index of the packet.
|
2016-10-03 19:44:57 +02:00
|
|
|
index = -1
|
2016-11-11 11:38:55 +01:00
|
|
|
#: Store the index of the source packet generator interface of the packet.
|
2016-10-03 19:44:57 +02:00
|
|
|
src = -1
|
2016-11-11 11:38:55 +01:00
|
|
|
#: Store the index of the destination packet generator interface
|
|
|
|
#: of the packet.
|
2016-10-03 19:44:57 +02:00
|
|
|
dst = -1
|
2017-03-02 15:22:47 +01:00
|
|
|
#: Store expected ip version
|
|
|
|
ip = -1
|
|
|
|
#: Store expected upper protocol
|
|
|
|
proto = -1
|
2016-11-11 11:38:55 +01:00
|
|
|
#: Store the copy of the former packet.
|
2016-10-03 19:44:57 +02:00
|
|
|
data = None
|
2016-10-11 11:47:09 +02:00
|
|
|
|
2016-12-07 15:09:13 +01:00
|
|
|
def __eq__(self, other):
|
|
|
|
index = self.index == other.index
|
|
|
|
src = self.src == other.src
|
|
|
|
dst = self.dst == other.dst
|
|
|
|
data = self.data == other.data
|
|
|
|
return index and src and dst and data
|
|
|
|
|
2016-10-11 11:47:09 +02:00
|
|
|
|
2017-02-14 02:55:31 +01:00
|
|
|
def pump_output(testclass):
|
|
|
|
""" pump output from vpp stdout/stderr to proper queues """
|
2017-11-09 09:16:39 +01:00
|
|
|
stdout_fragment = ""
|
|
|
|
stderr_fragment = ""
|
2018-07-23 05:35:56 -04:00
|
|
|
while not testclass.pump_thread_stop_flag.is_set():
|
2017-02-14 02:55:31 +01:00
|
|
|
readable = select.select([testclass.vpp.stdout.fileno(),
|
|
|
|
testclass.vpp.stderr.fileno(),
|
|
|
|
testclass.pump_thread_wakeup_pipe[0]],
|
|
|
|
[], [])[0]
|
|
|
|
if testclass.vpp.stdout.fileno() in readable:
|
2017-11-09 09:16:39 +01:00
|
|
|
read = os.read(testclass.vpp.stdout.fileno(), 102400)
|
|
|
|
if len(read) > 0:
|
2019-10-17 01:53:47 +02:00
|
|
|
split = read.decode('ascii',
|
|
|
|
errors='backslashreplace').splitlines(True)
|
2017-11-09 09:16:39 +01:00
|
|
|
if len(stdout_fragment) > 0:
|
|
|
|
split[0] = "%s%s" % (stdout_fragment, split[0])
|
|
|
|
if len(split) > 0 and split[-1].endswith("\n"):
|
|
|
|
limit = None
|
|
|
|
else:
|
|
|
|
limit = -1
|
|
|
|
stdout_fragment = split[-1]
|
|
|
|
testclass.vpp_stdout_deque.extend(split[:limit])
|
|
|
|
if not testclass.cache_vpp_output:
|
|
|
|
for line in split[:limit]:
|
2019-11-21 16:50:24 +01:00
|
|
|
testclass.logger.info(
|
2017-11-09 09:16:39 +01:00
|
|
|
"VPP STDOUT: %s" % line.rstrip("\n"))
|
2017-02-14 02:55:31 +01:00
|
|
|
if testclass.vpp.stderr.fileno() in readable:
|
2017-11-09 09:16:39 +01:00
|
|
|
read = os.read(testclass.vpp.stderr.fileno(), 102400)
|
|
|
|
if len(read) > 0:
|
2019-10-15 19:31:55 +02:00
|
|
|
split = read.decode('ascii',
|
|
|
|
errors='backslashreplace').splitlines(True)
|
2017-11-09 09:16:39 +01:00
|
|
|
if len(stderr_fragment) > 0:
|
|
|
|
split[0] = "%s%s" % (stderr_fragment, split[0])
|
2019-10-15 19:31:55 +02:00
|
|
|
if len(split) > 0 and split[-1].endswith("\n"):
|
2017-11-09 09:16:39 +01:00
|
|
|
limit = None
|
|
|
|
else:
|
|
|
|
limit = -1
|
|
|
|
stderr_fragment = split[-1]
|
2019-10-15 19:31:55 +02:00
|
|
|
|
2017-11-09 09:16:39 +01:00
|
|
|
testclass.vpp_stderr_deque.extend(split[:limit])
|
|
|
|
if not testclass.cache_vpp_output:
|
|
|
|
for line in split[:limit]:
|
2019-11-21 16:50:24 +01:00
|
|
|
testclass.logger.error(
|
2017-11-09 09:16:39 +01:00
|
|
|
"VPP STDERR: %s" % line.rstrip("\n"))
|
2018-12-09 15:37:04 -08:00
|
|
|
# ignoring the dummy pipe here intentionally - the
|
|
|
|
# flag will take care of properly terminating the loop
|
2016-10-28 13:20:27 +02:00
|
|
|
|
|
|
|
|
2018-12-06 07:46:13 -08:00
|
|
|
def _is_skip_aarch64_set():
|
2019-07-03 08:38:38 -04:00
|
|
|
return BoolEnvironmentVariable('SKIP_AARCH64')
|
2018-11-29 09:37:08 +01:00
|
|
|
|
2019-05-16 14:34:55 +02:00
|
|
|
|
2018-12-06 07:46:13 -08:00
|
|
|
is_skip_aarch64_set = _is_skip_aarch64_set()
|
2018-11-29 09:37:08 +01:00
|
|
|
|
2018-12-06 07:46:13 -08:00
|
|
|
|
|
|
|
def _is_platform_aarch64():
|
2018-11-29 09:37:08 +01:00
|
|
|
return platform.machine() == 'aarch64'
|
|
|
|
|
2019-05-16 14:34:55 +02:00
|
|
|
|
2018-12-06 07:46:13 -08:00
|
|
|
is_platform_aarch64 = _is_platform_aarch64()
|
|
|
|
|
2018-11-29 09:37:08 +01:00
|
|
|
|
2018-12-06 07:46:13 -08:00
|
|
|
def _running_extended_tests():
|
2019-07-03 08:38:38 -04:00
|
|
|
return BoolEnvironmentVariable("EXTENDED_TESTS")
|
2017-03-07 11:39:27 +01:00
|
|
|
|
2019-05-16 14:34:55 +02:00
|
|
|
|
2018-12-06 07:46:13 -08:00
|
|
|
running_extended_tests = _running_extended_tests()
|
2017-03-07 11:39:27 +01:00
|
|
|
|
2018-12-06 07:46:13 -08:00
|
|
|
|
2020-03-10 16:59:39 -04:00
|
|
|
def _running_gcov_tests():
|
|
|
|
return BoolEnvironmentVariable("GCOV_TESTS")
|
|
|
|
|
|
|
|
|
|
|
|
running_gcov_tests = _running_gcov_tests()
|
|
|
|
|
|
|
|
|
2017-08-08 04:33:53 +02:00
|
|
|
class KeepAliveReporter(object):
|
|
|
|
"""
|
|
|
|
Singleton object which reports test start to parent process
|
|
|
|
"""
|
|
|
|
_shared_state = {}
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.__dict__ = self._shared_state
|
VPP-1498: test/framework.py: AttributeError
Traceback if .send_keep_alive is called before pipe is configured.
Traceback (most recent call last):
File "/vpp/test/test_span.py", line 27, in setUpClass
super(TestSpan, cls).setUpClass()
File "/vpp/test/framework.py", line 411, in setUpClass
cls.reporter.send_keep_alive(cls, 'setUpClass')
File "/vpp/test/framework.py", line 172, in send_keep_alive
if self.pipe is None:
File "/vpp/test/framework.py", line 160, in pipe
return self._pipe
AttributeError: 'KeepAliveReporter' object has no attribute '_pipe'
Change-Id: I561d2748441702478a84fbb4580a4d2667d70ffd
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2018-11-18 08:17:34 -08:00
|
|
|
self._pipe = None
|
2017-08-08 04:33:53 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def pipe(self):
|
|
|
|
return self._pipe
|
|
|
|
|
|
|
|
@pipe.setter
|
|
|
|
def pipe(self, pipe):
|
VPP-1498: test/framework.py: AttributeError
Traceback if .send_keep_alive is called before pipe is configured.
Traceback (most recent call last):
File "/vpp/test/test_span.py", line 27, in setUpClass
super(TestSpan, cls).setUpClass()
File "/vpp/test/framework.py", line 411, in setUpClass
cls.reporter.send_keep_alive(cls, 'setUpClass')
File "/vpp/test/framework.py", line 172, in send_keep_alive
if self.pipe is None:
File "/vpp/test/framework.py", line 160, in pipe
return self._pipe
AttributeError: 'KeepAliveReporter' object has no attribute '_pipe'
Change-Id: I561d2748441702478a84fbb4580a4d2667d70ffd
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2018-11-18 08:17:34 -08:00
|
|
|
if self._pipe is not None:
|
2017-08-08 04:33:53 +02:00
|
|
|
raise Exception("Internal error - pipe should only be set once.")
|
|
|
|
self._pipe = pipe
|
|
|
|
|
2018-09-21 13:55:16 +02:00
|
|
|
def send_keep_alive(self, test, desc=None):
|
2017-08-08 04:33:53 +02:00
|
|
|
"""
|
|
|
|
Write current test tmpdir & desc to keep-alive pipe to signal liveness
|
|
|
|
"""
|
2017-08-11 06:56:05 +02:00
|
|
|
if self.pipe is None:
|
|
|
|
# if not running forked..
|
|
|
|
return
|
|
|
|
|
2017-08-08 04:33:53 +02:00
|
|
|
if isclass(test):
|
2018-09-21 13:55:16 +02:00
|
|
|
desc = '%s (%s)' % (desc, unittest.util.strclass(test))
|
2017-08-08 04:33:53 +02:00
|
|
|
else:
|
2018-09-21 13:55:16 +02:00
|
|
|
desc = test.id()
|
2017-08-08 04:33:53 +02:00
|
|
|
|
2017-09-30 22:04:21 -04:00
|
|
|
self.pipe.send((desc, test.vpp_bin, test.tempdir, test.vpp.pid))
|
2017-08-08 04:33:53 +02:00
|
|
|
|
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
class VppTestCase(unittest.TestCase):
|
2016-11-11 11:38:55 +01:00
|
|
|
"""This subclass is a base class for VPP test cases that are implemented as
|
|
|
|
classes. It provides methods to create and run test case.
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
|
2018-12-21 16:04:22 +01:00
|
|
|
extra_vpp_punt_config = []
|
|
|
|
extra_vpp_plugin_config = []
|
2019-12-01 22:24:28 -05:00
|
|
|
logger = null_logger
|
2019-10-26 22:25:49 -04:00
|
|
|
vapi_response_timeout = 5
|
2018-11-28 07:42:11 +01:00
|
|
|
|
2016-10-11 11:47:09 +02:00
|
|
|
@property
|
|
|
|
def packet_infos(self):
|
|
|
|
"""List of packet infos"""
|
|
|
|
return self._packet_infos
|
|
|
|
|
2016-12-21 08:50:14 +01:00
|
|
|
@classmethod
|
|
|
|
def get_packet_count_for_if_idx(cls, dst_if_index):
|
|
|
|
"""Get the number of packet info for specified destination if index"""
|
|
|
|
if dst_if_index in cls._packet_count_for_dst_if_idx:
|
|
|
|
return cls._packet_count_for_dst_if_idx[dst_if_index]
|
|
|
|
else:
|
|
|
|
return 0
|
2016-10-11 11:47:09 +02:00
|
|
|
|
2020-08-26 14:33:54 +00:00
|
|
|
@classmethod
|
|
|
|
def force_solo(cls):
|
|
|
|
""" if the test case class is timing-sensitive - return true """
|
|
|
|
return False
|
|
|
|
|
2016-10-11 11:47:09 +02:00
|
|
|
@classmethod
|
|
|
|
def instance(cls):
|
|
|
|
"""Return the instance of this testcase"""
|
|
|
|
return cls.test_instance
|
2016-10-03 19:44:57 +02:00
|
|
|
|
2016-10-28 13:20:27 +02:00
|
|
|
@classmethod
|
|
|
|
def set_debug_flags(cls, d):
|
2019-10-21 02:53:14 +00:00
|
|
|
cls.gdbserver_port = 7777
|
2016-10-28 13:20:27 +02:00
|
|
|
cls.debug_core = False
|
|
|
|
cls.debug_gdb = False
|
|
|
|
cls.debug_gdbserver = False
|
2019-10-21 02:53:14 +00:00
|
|
|
cls.debug_all = False
|
2016-10-28 13:20:27 +02:00
|
|
|
if d is None:
|
|
|
|
return
|
|
|
|
dl = d.lower()
|
|
|
|
if dl == "core":
|
|
|
|
cls.debug_core = True
|
2019-10-21 02:53:14 +00:00
|
|
|
elif dl == "gdb" or dl == "gdb-all":
|
2016-10-28 13:20:27 +02:00
|
|
|
cls.debug_gdb = True
|
2019-10-21 02:53:14 +00:00
|
|
|
elif dl == "gdbserver" or dl == "gdbserver-all":
|
2016-10-28 13:20:27 +02:00
|
|
|
cls.debug_gdbserver = True
|
|
|
|
else:
|
|
|
|
raise Exception("Unrecognized DEBUG option: '%s'" % d)
|
2019-10-21 02:53:14 +00:00
|
|
|
if dl == "gdb-all" or dl == "gdbserver-all":
|
|
|
|
cls.debug_all = True
|
2016-10-28 13:20:27 +02:00
|
|
|
|
2018-11-21 09:28:32 -08:00
|
|
|
@staticmethod
|
|
|
|
def get_least_used_cpu():
|
2018-07-16 14:22:01 +02:00
|
|
|
cpu_usage_list = [set(range(psutil.cpu_count()))]
|
|
|
|
vpp_processes = [p for p in psutil.process_iter(attrs=['pid', 'name'])
|
|
|
|
if 'vpp_main' == p.info['name']]
|
|
|
|
for vpp_process in vpp_processes:
|
|
|
|
for cpu_usage_set in cpu_usage_list:
|
|
|
|
try:
|
|
|
|
cpu_num = vpp_process.cpu_num()
|
|
|
|
if cpu_num in cpu_usage_set:
|
|
|
|
cpu_usage_set_index = cpu_usage_list.index(
|
|
|
|
cpu_usage_set)
|
|
|
|
if cpu_usage_set_index == len(cpu_usage_list) - 1:
|
|
|
|
cpu_usage_list.append({cpu_num})
|
|
|
|
else:
|
|
|
|
cpu_usage_list[cpu_usage_set_index + 1].add(
|
|
|
|
cpu_num)
|
|
|
|
cpu_usage_set.remove(cpu_num)
|
|
|
|
break
|
|
|
|
except psutil.NoSuchProcess:
|
|
|
|
pass
|
|
|
|
|
|
|
|
for cpu_usage_set in cpu_usage_list:
|
|
|
|
if len(cpu_usage_set) > 0:
|
|
|
|
min_usage_set = cpu_usage_set
|
|
|
|
break
|
|
|
|
|
|
|
|
return random.choice(tuple(min_usage_set))
|
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
@classmethod
|
|
|
|
def setUpConstants(cls):
|
2016-10-11 11:47:09 +02:00
|
|
|
""" Set-up the test case class based on environment variables """
|
2019-07-03 08:38:38 -04:00
|
|
|
cls.step = BoolEnvironmentVariable('STEP')
|
2018-03-21 12:35:51 +01:00
|
|
|
d = os.getenv("DEBUG", None)
|
2019-07-03 08:38:38 -04:00
|
|
|
# inverted case to handle '' == True
|
2018-03-21 12:35:51 +01:00
|
|
|
c = os.getenv("CACHE_OUTPUT", "1")
|
|
|
|
cls.cache_vpp_output = False if c.lower() in ("n", "no", "0") else True
|
2016-10-28 13:20:27 +02:00
|
|
|
cls.set_debug_flags(d)
|
2018-11-08 11:21:39 +01:00
|
|
|
cls.vpp_bin = os.getenv('VPP_BIN', "vpp")
|
|
|
|
cls.plugin_path = os.getenv('VPP_PLUGIN_PATH')
|
2019-05-08 19:18:18 -04:00
|
|
|
cls.test_plugin_path = os.getenv('VPP_TEST_PLUGIN_PATH')
|
2017-03-21 08:21:25 +01:00
|
|
|
cls.extern_plugin_path = os.getenv('EXTERN_PLUGINS')
|
|
|
|
plugin_path = None
|
|
|
|
if cls.plugin_path is not None:
|
|
|
|
if cls.extern_plugin_path is not None:
|
|
|
|
plugin_path = "%s:%s" % (
|
|
|
|
cls.plugin_path, cls.extern_plugin_path)
|
2017-03-24 05:47:15 +01:00
|
|
|
else:
|
|
|
|
plugin_path = cls.plugin_path
|
2017-03-21 08:21:25 +01:00
|
|
|
elif cls.extern_plugin_path is not None:
|
|
|
|
plugin_path = cls.extern_plugin_path
|
2018-12-21 16:04:22 +01:00
|
|
|
debug_cli = ""
|
2016-11-02 09:25:05 +01:00
|
|
|
if cls.step or cls.debug_gdb or cls.debug_gdbserver:
|
2018-12-21 16:04:22 +01:00
|
|
|
debug_cli = "cli-listen localhost:5002"
|
2017-03-02 11:27:11 +01:00
|
|
|
coredump_size = None
|
2018-03-21 12:35:51 +01:00
|
|
|
size = os.getenv("COREDUMP_SIZE")
|
2018-12-21 16:04:22 +01:00
|
|
|
if size is not None:
|
|
|
|
coredump_size = "coredump-size %s" % size
|
|
|
|
if coredump_size is None:
|
|
|
|
coredump_size = "coredump-size unlimited"
|
|
|
|
|
|
|
|
cpu_core_number = cls.get_least_used_cpu()
|
2019-07-19 09:14:19 +00:00
|
|
|
if not hasattr(cls, "worker_config"):
|
|
|
|
cls.worker_config = ""
|
2018-12-21 16:04:22 +01:00
|
|
|
|
2020-03-10 14:35:32 +00:00
|
|
|
default_variant = os.getenv("VARIANT")
|
|
|
|
if default_variant is not None:
|
|
|
|
default_variant = "defaults { %s 100 }" % default_variant
|
|
|
|
else:
|
|
|
|
default_variant = ""
|
|
|
|
|
2020-04-29 17:04:10 -04:00
|
|
|
api_fuzzing = os.getenv("API_FUZZ")
|
|
|
|
if api_fuzzing is None:
|
|
|
|
api_fuzzing = 'off'
|
|
|
|
|
2018-12-21 16:04:22 +01:00
|
|
|
cls.vpp_cmdline = [cls.vpp_bin, "unix",
|
|
|
|
"{", "nodaemon", debug_cli, "full-coredump",
|
|
|
|
coredump_size, "runtime-dir", cls.tempdir, "}",
|
|
|
|
"api-trace", "{", "on", "}", "api-segment", "{",
|
|
|
|
"prefix", cls.shm_prefix, "}", "cpu", "{",
|
2019-07-19 09:14:19 +00:00
|
|
|
"main-core", str(cpu_core_number),
|
|
|
|
cls.worker_config, "}",
|
2019-12-25 09:24:58 -05:00
|
|
|
"physmem", "{", "max-size", "32m", "}",
|
2019-04-15 11:27:22 +02:00
|
|
|
"statseg", "{", "socket-name", cls.stats_sock, "}",
|
|
|
|
"socksvr", "{", "socket-name", cls.api_sock, "}",
|
2020-03-10 14:35:32 +00:00
|
|
|
"node { ", default_variant, "}",
|
2020-04-29 17:04:10 -04:00
|
|
|
"api-fuzz {", api_fuzzing, "}",
|
2019-04-15 11:27:22 +02:00
|
|
|
"plugins",
|
2018-12-21 16:04:22 +01:00
|
|
|
"{", "plugin", "dpdk_plugin.so", "{", "disable",
|
2019-04-10 09:44:23 +02:00
|
|
|
"}", "plugin", "rdma_plugin.so", "{", "disable",
|
2020-09-21 08:17:51 +00:00
|
|
|
"}", "plugin", "lisp_unittest_plugin.so", "{",
|
|
|
|
"enable",
|
2018-12-21 16:04:22 +01:00
|
|
|
"}", "plugin", "unittest_plugin.so", "{", "enable",
|
|
|
|
"}"] + cls.extra_vpp_plugin_config + ["}", ]
|
2020-03-10 14:35:32 +00:00
|
|
|
|
2018-12-21 16:04:22 +01:00
|
|
|
if cls.extra_vpp_punt_config is not None:
|
|
|
|
cls.vpp_cmdline.extend(cls.extra_vpp_punt_config)
|
2017-03-21 08:21:25 +01:00
|
|
|
if plugin_path is not None:
|
2018-12-21 16:04:22 +01:00
|
|
|
cls.vpp_cmdline.extend(["plugin_path", plugin_path])
|
2019-05-08 19:18:18 -04:00
|
|
|
if cls.test_plugin_path is not None:
|
|
|
|
cls.vpp_cmdline.extend(["test_plugin_path", cls.test_plugin_path])
|
|
|
|
|
2018-11-08 11:24:34 +01:00
|
|
|
cls.logger.info("vpp_cmdline args: %s" % cls.vpp_cmdline)
|
|
|
|
cls.logger.info("vpp_cmdline: %s" % " ".join(cls.vpp_cmdline))
|
2016-10-28 13:20:27 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def wait_for_enter(cls):
|
|
|
|
if cls.debug_gdbserver:
|
|
|
|
print(double_line_delim)
|
|
|
|
print("Spawned GDB server with PID: %d" % cls.vpp.pid)
|
|
|
|
elif cls.debug_gdb:
|
|
|
|
print(double_line_delim)
|
|
|
|
print("Spawned VPP with PID: %d" % cls.vpp.pid)
|
|
|
|
else:
|
|
|
|
cls.logger.debug("Spawned VPP with PID: %d" % cls.vpp.pid)
|
|
|
|
return
|
|
|
|
print(single_line_delim)
|
2019-10-21 02:53:14 +00:00
|
|
|
print("You can debug VPP using:")
|
2016-10-28 13:20:27 +02:00
|
|
|
if cls.debug_gdbserver:
|
2019-06-18 22:59:55 -04:00
|
|
|
print("sudo gdb " + cls.vpp_bin +
|
2019-10-21 02:53:14 +00:00
|
|
|
" -ex 'target remote localhost:{port}'"
|
|
|
|
.format(port=cls.gdbserver_port))
|
|
|
|
print("Now is the time to attach gdb by running the above "
|
|
|
|
"command, set up breakpoints etc., then resume VPP from "
|
2016-10-28 13:20:27 +02:00
|
|
|
"within gdb by issuing the 'continue' command")
|
2019-10-21 02:53:14 +00:00
|
|
|
cls.gdbserver_port += 1
|
2016-10-28 13:20:27 +02:00
|
|
|
elif cls.debug_gdb:
|
2019-06-18 22:59:55 -04:00
|
|
|
print("sudo gdb " + cls.vpp_bin + " -ex 'attach %s'" % cls.vpp.pid)
|
2019-10-21 02:53:14 +00:00
|
|
|
print("Now is the time to attach gdb by running the above "
|
|
|
|
"command and set up breakpoints etc., then resume VPP from"
|
|
|
|
" within gdb by issuing the 'continue' command")
|
2016-10-28 13:20:27 +02:00
|
|
|
print(single_line_delim)
|
2018-12-15 10:16:35 -08:00
|
|
|
input("Press ENTER to continue running the testcase...")
|
2016-10-28 13:20:27 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def run_vpp(cls):
|
|
|
|
cmdline = cls.vpp_cmdline
|
|
|
|
|
|
|
|
if cls.debug_gdbserver:
|
2016-11-03 05:36:01 +01:00
|
|
|
gdbserver = '/usr/bin/gdbserver'
|
|
|
|
if not os.path.isfile(gdbserver) or \
|
|
|
|
not os.access(gdbserver, os.X_OK):
|
|
|
|
raise Exception("gdbserver binary '%s' does not exist or is "
|
|
|
|
"not executable" % gdbserver)
|
|
|
|
|
2019-10-21 02:53:14 +00:00
|
|
|
cmdline = [gdbserver, 'localhost:{port}'
|
|
|
|
.format(port=cls.gdbserver_port)] + cls.vpp_cmdline
|
2016-10-28 13:20:27 +02:00
|
|
|
cls.logger.info("Gdbserver cmdline is %s", " ".join(cmdline))
|
|
|
|
|
2016-11-03 05:36:01 +01:00
|
|
|
try:
|
|
|
|
cls.vpp = subprocess.Popen(cmdline,
|
|
|
|
stdout=subprocess.PIPE,
|
2020-02-04 13:28:13 +01:00
|
|
|
stderr=subprocess.PIPE)
|
2018-11-24 21:19:38 -08:00
|
|
|
except subprocess.CalledProcessError as e:
|
2018-11-28 11:34:21 -08:00
|
|
|
cls.logger.critical("Subprocess returned with non-0 return code: ("
|
|
|
|
"%s)", e.returncode)
|
|
|
|
raise
|
|
|
|
except OSError as e:
|
|
|
|
cls.logger.critical("Subprocess returned with OS error: "
|
|
|
|
"(%s) %s", e.errno, e.strerror)
|
|
|
|
raise
|
|
|
|
except Exception as e:
|
|
|
|
cls.logger.exception("Subprocess returned unexpected from "
|
|
|
|
"%s:", cmdline)
|
2016-11-03 05:36:01 +01:00
|
|
|
raise
|
|
|
|
|
2016-10-28 13:20:27 +02:00
|
|
|
cls.wait_for_enter()
|
2016-10-07 16:30:03 +01:00
|
|
|
|
2019-04-09 20:19:51 -04:00
|
|
|
@classmethod
|
2019-10-31 08:34:22 +00:00
|
|
|
def wait_for_coredump(cls):
|
|
|
|
corefile = cls.tempdir + "/core"
|
2019-04-09 20:19:51 -04:00
|
|
|
if os.path.isfile(corefile):
|
2019-10-31 08:34:22 +00:00
|
|
|
cls.logger.error("Waiting for coredump to complete: %s", corefile)
|
2019-04-09 20:19:51 -04:00
|
|
|
curr_size = os.path.getsize(corefile)
|
2019-10-31 08:34:22 +00:00
|
|
|
deadline = time.time() + 60
|
2019-04-09 20:19:51 -04:00
|
|
|
ok = False
|
|
|
|
while time.time() < deadline:
|
|
|
|
cls.sleep(1)
|
|
|
|
size = curr_size
|
|
|
|
curr_size = os.path.getsize(corefile)
|
|
|
|
if size == curr_size:
|
|
|
|
ok = True
|
|
|
|
break
|
|
|
|
if not ok:
|
|
|
|
cls.logger.error("Timed out waiting for coredump to complete:"
|
|
|
|
" %s", corefile)
|
|
|
|
else:
|
|
|
|
cls.logger.error("Coredump complete: %s, size %d",
|
|
|
|
corefile, curr_size)
|
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
Perform class setup before running the testcase
|
|
|
|
Remove shared memory files, start vpp and connect the vpp-api
|
|
|
|
"""
|
2019-01-25 14:05:48 -08:00
|
|
|
super(VppTestCase, cls).setUpClass()
|
2017-02-14 02:55:31 +01:00
|
|
|
gc.collect() # run garbage collection first
|
2018-11-09 11:58:54 +01:00
|
|
|
cls.logger = get_logger(cls.__name__)
|
2019-11-05 11:18:25 +00:00
|
|
|
seed = os.environ["RND_SEED"]
|
|
|
|
random.seed(seed)
|
2018-11-09 11:58:54 +01:00
|
|
|
if hasattr(cls, 'parallel_handler'):
|
|
|
|
cls.logger.addHandler(cls.parallel_handler)
|
2018-11-21 13:13:39 +01:00
|
|
|
cls.logger.propagate = False
|
2019-03-13 09:23:05 -07:00
|
|
|
|
2016-10-11 11:47:09 +02:00
|
|
|
cls.tempdir = tempfile.mkdtemp(
|
2017-08-15 07:09:02 +02:00
|
|
|
prefix='vpp-unittest-%s-' % cls.__name__)
|
2018-09-26 11:19:00 +02:00
|
|
|
cls.stats_sock = "%s/stats.sock" % cls.tempdir
|
2019-04-15 11:27:22 +02:00
|
|
|
cls.api_sock = "%s/api.sock" % cls.tempdir
|
2017-04-11 06:01:53 +02:00
|
|
|
cls.file_handler = FileHandler("%s/log.txt" % cls.tempdir)
|
|
|
|
cls.file_handler.setFormatter(
|
2017-02-14 02:55:31 +01:00
|
|
|
Formatter(fmt='%(asctime)s,%(msecs)03d %(message)s',
|
|
|
|
datefmt="%H:%M:%S"))
|
2017-04-11 06:01:53 +02:00
|
|
|
cls.file_handler.setLevel(DEBUG)
|
|
|
|
cls.logger.addHandler(cls.file_handler)
|
2019-03-13 09:23:05 -07:00
|
|
|
cls.logger.debug("--- setUpClass() for %s called ---" %
|
|
|
|
cls.__name__)
|
2018-07-16 14:22:01 +02:00
|
|
|
cls.shm_prefix = os.path.basename(cls.tempdir)
|
2016-10-11 11:47:09 +02:00
|
|
|
os.chdir(cls.tempdir)
|
2016-10-28 13:20:27 +02:00
|
|
|
cls.logger.info("Temporary dir is %s, shm prefix is %s",
|
|
|
|
cls.tempdir, cls.shm_prefix)
|
2019-11-05 11:18:25 +00:00
|
|
|
cls.logger.debug("Random seed is %s" % seed)
|
2016-10-03 19:44:57 +02:00
|
|
|
cls.setUpConstants()
|
2016-12-21 08:50:14 +01:00
|
|
|
cls.reset_packet_infos()
|
2016-12-12 08:36:58 +01:00
|
|
|
cls._captures = []
|
2016-10-11 11:47:09 +02:00
|
|
|
cls.verbose = 0
|
2016-11-24 01:59:16 +01:00
|
|
|
cls.vpp_dead = False
|
2017-01-11 08:16:53 +01:00
|
|
|
cls.registry = VppObjectRegistry()
|
2017-04-10 06:30:17 +02:00
|
|
|
cls.vpp_startup_failed = False
|
2017-08-08 04:33:53 +02:00
|
|
|
cls.reporter = KeepAliveReporter()
|
2016-10-11 11:47:09 +02:00
|
|
|
# need to catch exceptions here because if we raise, then the cleanup
|
|
|
|
# doesn't get called and we might end with a zombie vpp
|
|
|
|
try:
|
2016-10-28 13:20:27 +02:00
|
|
|
cls.run_vpp()
|
2018-09-21 13:55:16 +02:00
|
|
|
cls.reporter.send_keep_alive(cls, 'setUpClass')
|
|
|
|
VppTestResult.current_test_case_info = TestCaseInfo(
|
|
|
|
cls.logger, cls.tempdir, cls.vpp.pid, cls.vpp_bin)
|
2016-12-08 10:16:41 +01:00
|
|
|
cls.vpp_stdout_deque = deque()
|
|
|
|
cls.vpp_stderr_deque = deque()
|
2017-02-14 02:55:31 +01:00
|
|
|
cls.pump_thread_stop_flag = Event()
|
|
|
|
cls.pump_thread_wakeup_pipe = os.pipe()
|
|
|
|
cls.pump_thread = Thread(target=pump_output, args=(cls,))
|
2017-02-14 07:11:52 +01:00
|
|
|
cls.pump_thread.daemon = True
|
2017-02-14 02:55:31 +01:00
|
|
|
cls.pump_thread.start()
|
2018-09-26 11:19:00 +02:00
|
|
|
if cls.debug_gdb or cls.debug_gdbserver:
|
2019-10-26 22:25:49 -04:00
|
|
|
cls.vapi_response_timeout = 0
|
2018-09-26 11:19:00 +02:00
|
|
|
cls.vapi = VppPapiProvider(cls.shm_prefix, cls.shm_prefix, cls,
|
2019-10-26 22:25:49 -04:00
|
|
|
cls.vapi_response_timeout)
|
2016-10-28 13:20:27 +02:00
|
|
|
if cls.step:
|
2019-06-20 12:24:12 -04:00
|
|
|
hook = hookmodule.StepHook(cls)
|
2016-10-28 13:20:27 +02:00
|
|
|
else:
|
2019-06-20 12:24:12 -04:00
|
|
|
hook = hookmodule.PollHook(cls)
|
2016-11-24 01:59:16 +01:00
|
|
|
cls.vapi.register_hook(hook)
|
2018-09-26 11:19:00 +02:00
|
|
|
cls.statistics = VPPStats(socketname=cls.stats_sock)
|
2017-04-10 06:30:17 +02:00
|
|
|
try:
|
|
|
|
hook.poll_vpp()
|
2018-03-21 12:35:51 +01:00
|
|
|
except VppDiedError:
|
2017-04-10 06:30:17 +02:00
|
|
|
cls.vpp_startup_failed = True
|
|
|
|
cls.logger.critical(
|
|
|
|
"VPP died shortly after startup, check the"
|
|
|
|
" output to standard error for possible cause")
|
|
|
|
raise
|
2016-10-28 13:20:27 +02:00
|
|
|
try:
|
|
|
|
cls.vapi.connect()
|
2019-12-02 21:42:28 -05:00
|
|
|
except vpp_papi.VPPIOError as e:
|
|
|
|
cls.logger.debug("Exception connecting to vapi: %s" % e)
|
|
|
|
cls.vapi.disconnect()
|
|
|
|
|
2016-10-28 13:20:27 +02:00
|
|
|
if cls.debug_gdbserver:
|
|
|
|
print(colorize("You're running VPP inside gdbserver but "
|
|
|
|
"VPP-API connection failed, did you forget "
|
|
|
|
"to 'continue' VPP from within gdb?", RED))
|
|
|
|
raise
|
2020-04-28 00:27:38 -04:00
|
|
|
except vpp_papi.VPPRuntimeError as e:
|
|
|
|
cls.logger.debug("%s" % e)
|
|
|
|
cls.quit()
|
|
|
|
raise
|
2019-10-13 10:06:46 +00:00
|
|
|
except Exception as e:
|
|
|
|
cls.logger.debug("Exception connecting to VPP: %s" % e)
|
2019-06-20 12:24:12 -04:00
|
|
|
cls.quit()
|
2018-03-21 12:35:51 +01:00
|
|
|
raise
|
2016-10-11 11:47:09 +02:00
|
|
|
|
2019-12-19 16:09:43 -05:00
|
|
|
@classmethod
|
|
|
|
def _debug_quit(cls):
|
|
|
|
if (cls.debug_gdbserver or cls.debug_gdb):
|
|
|
|
try:
|
|
|
|
cls.vpp.poll()
|
|
|
|
|
|
|
|
if cls.vpp.returncode is None:
|
|
|
|
print()
|
|
|
|
print(double_line_delim)
|
|
|
|
print("VPP or GDB server is still running")
|
|
|
|
print(single_line_delim)
|
|
|
|
input("When done debugging, press ENTER to kill the "
|
|
|
|
"process and finish running the testcase...")
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
@classmethod
|
|
|
|
def quit(cls):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
Disconnect vpp-api, kill vpp and cleanup shared memory files
|
|
|
|
"""
|
2019-12-19 16:09:43 -05:00
|
|
|
cls._debug_quit()
|
2016-10-28 13:20:27 +02:00
|
|
|
|
2018-07-16 14:22:01 +02:00
|
|
|
# first signal that we want to stop the pump thread, then wake it up
|
|
|
|
if hasattr(cls, 'pump_thread_stop_flag'):
|
|
|
|
cls.pump_thread_stop_flag.set()
|
|
|
|
if hasattr(cls, 'pump_thread_wakeup_pipe'):
|
2018-12-06 17:35:12 +01:00
|
|
|
os.write(cls.pump_thread_wakeup_pipe[1], b'ding dong wake up')
|
2017-02-14 02:55:31 +01:00
|
|
|
if hasattr(cls, 'pump_thread'):
|
|
|
|
cls.logger.debug("Waiting for pump thread to stop")
|
|
|
|
cls.pump_thread.join()
|
|
|
|
if hasattr(cls, 'vpp_stderr_reader_thread'):
|
2019-12-19 16:09:43 -05:00
|
|
|
cls.logger.debug("Waiting for stderr pump to stop")
|
2017-02-14 02:55:31 +01:00
|
|
|
cls.vpp_stderr_reader_thread.join()
|
|
|
|
|
2016-10-11 11:47:09 +02:00
|
|
|
if hasattr(cls, 'vpp'):
|
2016-12-02 07:05:24 +01:00
|
|
|
if hasattr(cls, 'vapi'):
|
2019-11-27 23:12:48 +01:00
|
|
|
cls.logger.debug(cls.vapi.vpp.get_stats())
|
2019-03-10 10:04:23 -07:00
|
|
|
cls.logger.debug("Disconnecting class vapi client on %s",
|
|
|
|
cls.__name__)
|
2016-12-02 07:05:24 +01:00
|
|
|
cls.vapi.disconnect()
|
2019-03-10 10:04:23 -07:00
|
|
|
cls.logger.debug("Deleting class vapi attribute on %s",
|
|
|
|
cls.__name__)
|
2017-02-14 02:55:31 +01:00
|
|
|
del cls.vapi
|
2016-10-11 11:47:09 +02:00
|
|
|
cls.vpp.poll()
|
|
|
|
if cls.vpp.returncode is None:
|
2019-10-31 08:34:22 +00:00
|
|
|
cls.wait_for_coredump()
|
2017-02-14 02:55:31 +01:00
|
|
|
cls.logger.debug("Sending TERM to vpp")
|
2019-05-06 10:49:41 -04:00
|
|
|
cls.vpp.terminate()
|
2017-02-14 02:55:31 +01:00
|
|
|
cls.logger.debug("Waiting for vpp to die")
|
|
|
|
cls.vpp.communicate()
|
2019-03-10 10:04:23 -07:00
|
|
|
cls.logger.debug("Deleting class vpp attribute on %s",
|
|
|
|
cls.__name__)
|
2016-10-11 11:47:09 +02:00
|
|
|
del cls.vpp
|
|
|
|
|
2017-04-10 06:30:17 +02:00
|
|
|
if cls.vpp_startup_failed:
|
|
|
|
stdout_log = cls.logger.info
|
|
|
|
stderr_log = cls.logger.critical
|
|
|
|
else:
|
|
|
|
stdout_log = cls.logger.info
|
|
|
|
stderr_log = cls.logger.info
|
|
|
|
|
2016-12-08 10:16:41 +01:00
|
|
|
if hasattr(cls, 'vpp_stdout_deque'):
|
2017-04-10 06:30:17 +02:00
|
|
|
stdout_log(single_line_delim)
|
|
|
|
stdout_log('VPP output to stdout while running %s:', cls.__name__)
|
|
|
|
stdout_log(single_line_delim)
|
2016-12-08 10:16:41 +01:00
|
|
|
vpp_output = "".join(cls.vpp_stdout_deque)
|
2017-04-11 06:01:53 +02:00
|
|
|
with open(cls.tempdir + '/vpp_stdout.txt', 'w') as f:
|
|
|
|
f.write(vpp_output)
|
2017-04-10 06:30:17 +02:00
|
|
|
stdout_log('\n%s', vpp_output)
|
|
|
|
stdout_log(single_line_delim)
|
2016-10-28 13:20:27 +02:00
|
|
|
|
2016-12-08 10:16:41 +01:00
|
|
|
if hasattr(cls, 'vpp_stderr_deque'):
|
2017-04-10 06:30:17 +02:00
|
|
|
stderr_log(single_line_delim)
|
|
|
|
stderr_log('VPP output to stderr while running %s:', cls.__name__)
|
|
|
|
stderr_log(single_line_delim)
|
2019-01-29 11:49:09 +01:00
|
|
|
vpp_output = "".join(cls.vpp_stderr_deque)
|
2017-04-11 06:01:53 +02:00
|
|
|
with open(cls.tempdir + '/vpp_stderr.txt', 'w') as f:
|
|
|
|
f.write(vpp_output)
|
2017-04-10 06:30:17 +02:00
|
|
|
stderr_log('\n%s', vpp_output)
|
|
|
|
stderr_log(single_line_delim)
|
2016-10-28 13:20:27 +02:00
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
2016-10-11 11:47:09 +02:00
|
|
|
""" Perform final cleanup after running all tests in this test-case """
|
2019-03-13 09:23:05 -07:00
|
|
|
cls.logger.debug("--- tearDownClass() for %s called ---" %
|
|
|
|
cls.__name__)
|
2018-09-21 13:55:16 +02:00
|
|
|
cls.reporter.send_keep_alive(cls, 'tearDownClass')
|
2016-10-03 19:44:57 +02:00
|
|
|
cls.quit()
|
2017-04-11 06:01:53 +02:00
|
|
|
cls.file_handler.close()
|
2018-02-17 13:41:33 +01:00
|
|
|
cls.reset_packet_infos()
|
|
|
|
if debug_framework:
|
|
|
|
debug_internal.on_tear_down_class(cls)
|
2016-10-03 19:44:57 +02:00
|
|
|
|
2019-03-13 09:23:05 -07:00
|
|
|
def show_commands_at_teardown(self):
|
|
|
|
""" Allow subclass specific teardown logging additions."""
|
|
|
|
self.logger.info("--- No test specific show commands provided. ---")
|
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
def tearDown(self):
|
2016-10-11 11:47:09 +02:00
|
|
|
""" Show various debug prints after each test """
|
2017-02-09 06:04:36 +01:00
|
|
|
self.logger.debug("--- tearDown() for %s.%s(%s) called ---" %
|
|
|
|
(self.__class__.__name__, self._testMethodName,
|
|
|
|
self._testMethodDoc))
|
tests: framework gracefully handle 'VppTransportShmemIOError'
Catches:
----
Traceback (most recent call last):
File "/vpp/test/framework.py", line 593, in tearDown
self.logger.info(self.vapi.ppcli("api trace save %s" % api_trace))
File "/vpp/test/vpp_papi_provider.py", line 413, in ppcli
return cli + "\n" + str(self.cli(cli))
File "/vpp/test/vpp_papi_provider.py", line 402, in cli
r = self.papi.cli_inband(cmd=cli)
File "/vpp/src/vpp-api/python/vpp_papi/vpp_papi.py", line 100, in __call__
return self._func(**kwargs)
File "/vpp/src/vpp-api/python/vpp_papi/vpp_papi.py", line 414, in f
return self._call_vpp(i, msg, multipart, **kwargs)
File "/vpp/src/vpp-api/python/vpp_papi/vpp_papi.py", line 634, in _call_vpp
msg = self.transport.read()
File "/vpp/src/vpp-api/python/vpp_papi/vpp_transport_shmem.py", line 120, in read
raise VppTransportShmemIOError(rv, 'vac_read failed')
VppTransportShmemIOError: [Errno -1] vac_read failed
----
Change-Id: I767e48c4d03081eb5df6a8aa67da7e192d25e4cc
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2019-03-15 09:39:19 -07:00
|
|
|
|
|
|
|
try:
|
|
|
|
if not self.vpp_dead:
|
|
|
|
self.logger.debug(self.vapi.cli("show trace max 1000"))
|
|
|
|
self.logger.info(self.vapi.ppcli("show interface"))
|
|
|
|
self.logger.info(self.vapi.ppcli("show hardware"))
|
|
|
|
self.logger.info(self.statistics.set_errors_str())
|
|
|
|
self.logger.info(self.vapi.ppcli("show run"))
|
|
|
|
self.logger.info(self.vapi.ppcli("show log"))
|
2019-07-08 12:25:38 -04:00
|
|
|
self.logger.info(self.vapi.ppcli("show bihash"))
|
tests: framework gracefully handle 'VppTransportShmemIOError'
Catches:
----
Traceback (most recent call last):
File "/vpp/test/framework.py", line 593, in tearDown
self.logger.info(self.vapi.ppcli("api trace save %s" % api_trace))
File "/vpp/test/vpp_papi_provider.py", line 413, in ppcli
return cli + "\n" + str(self.cli(cli))
File "/vpp/test/vpp_papi_provider.py", line 402, in cli
r = self.papi.cli_inband(cmd=cli)
File "/vpp/src/vpp-api/python/vpp_papi/vpp_papi.py", line 100, in __call__
return self._func(**kwargs)
File "/vpp/src/vpp-api/python/vpp_papi/vpp_papi.py", line 414, in f
return self._call_vpp(i, msg, multipart, **kwargs)
File "/vpp/src/vpp-api/python/vpp_papi/vpp_papi.py", line 634, in _call_vpp
msg = self.transport.read()
File "/vpp/src/vpp-api/python/vpp_papi/vpp_transport_shmem.py", line 120, in read
raise VppTransportShmemIOError(rv, 'vac_read failed')
VppTransportShmemIOError: [Errno -1] vac_read failed
----
Change-Id: I767e48c4d03081eb5df6a8aa67da7e192d25e4cc
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2019-03-15 09:39:19 -07:00
|
|
|
self.logger.info("Logging testcase specific show commands.")
|
|
|
|
self.show_commands_at_teardown()
|
|
|
|
self.registry.remove_vpp_config(self.logger)
|
2017-02-16 11:25:26 -05:00
|
|
|
# Save/Dump VPP api trace log
|
2019-10-21 12:55:48 +00:00
|
|
|
m = self._testMethodName
|
|
|
|
api_trace = "vpp_api_trace.%s.%d.log" % (m, self.vpp.pid)
|
2017-02-16 11:25:26 -05:00
|
|
|
tmp_api_trace = "/tmp/%s" % api_trace
|
|
|
|
vpp_api_trace_log = "%s/%s" % (self.tempdir, api_trace)
|
|
|
|
self.logger.info(self.vapi.ppcli("api trace save %s" % api_trace))
|
|
|
|
self.logger.info("Moving %s to %s\n" % (tmp_api_trace,
|
|
|
|
vpp_api_trace_log))
|
|
|
|
os.rename(tmp_api_trace, vpp_api_trace_log)
|
2018-02-13 16:14:06 -05:00
|
|
|
self.logger.info(self.vapi.ppcli("api trace custom-dump %s" %
|
2017-02-16 11:25:26 -05:00
|
|
|
vpp_api_trace_log))
|
tests: framework gracefully handle 'VppTransportShmemIOError'
Catches:
----
Traceback (most recent call last):
File "/vpp/test/framework.py", line 593, in tearDown
self.logger.info(self.vapi.ppcli("api trace save %s" % api_trace))
File "/vpp/test/vpp_papi_provider.py", line 413, in ppcli
return cli + "\n" + str(self.cli(cli))
File "/vpp/test/vpp_papi_provider.py", line 402, in cli
r = self.papi.cli_inband(cmd=cli)
File "/vpp/src/vpp-api/python/vpp_papi/vpp_papi.py", line 100, in __call__
return self._func(**kwargs)
File "/vpp/src/vpp-api/python/vpp_papi/vpp_papi.py", line 414, in f
return self._call_vpp(i, msg, multipart, **kwargs)
File "/vpp/src/vpp-api/python/vpp_papi/vpp_papi.py", line 634, in _call_vpp
msg = self.transport.read()
File "/vpp/src/vpp-api/python/vpp_papi/vpp_transport_shmem.py", line 120, in read
raise VppTransportShmemIOError(rv, 'vac_read failed')
VppTransportShmemIOError: [Errno -1] vac_read failed
----
Change-Id: I767e48c4d03081eb5df6a8aa67da7e192d25e4cc
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2019-03-15 09:39:19 -07:00
|
|
|
except VppTransportShmemIOError:
|
|
|
|
self.logger.debug("VppTransportShmemIOError: Vpp dead. "
|
|
|
|
"Cannot log show commands.")
|
|
|
|
self.vpp_dead = True
|
2017-03-02 11:29:19 +01:00
|
|
|
else:
|
|
|
|
self.registry.unregister_all(self.logger)
|
2016-10-11 11:47:09 +02:00
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
def setUp(self):
|
2016-10-11 11:47:09 +02:00
|
|
|
""" Clear trace before running each test"""
|
2019-01-25 14:05:48 -08:00
|
|
|
super(VppTestCase, self).setUp()
|
2017-08-08 04:33:53 +02:00
|
|
|
self.reporter.send_keep_alive(self)
|
2016-12-08 05:03:32 +01:00
|
|
|
if self.vpp_dead:
|
2019-06-26 20:45:08 -04:00
|
|
|
|
|
|
|
raise VppDiedError(rv=None, testcase=self.__class__.__name__,
|
|
|
|
method_name=self._testMethodName)
|
2017-02-14 02:55:31 +01:00
|
|
|
self.sleep(.1, "during setUp")
|
2016-12-08 10:16:41 +01:00
|
|
|
self.vpp_stdout_deque.append(
|
|
|
|
"--- test setUp() for %s.%s(%s) starts here ---\n" %
|
|
|
|
(self.__class__.__name__, self._testMethodName,
|
|
|
|
self._testMethodDoc))
|
|
|
|
self.vpp_stderr_deque.append(
|
|
|
|
"--- test setUp() for %s.%s(%s) starts here ---\n" %
|
|
|
|
(self.__class__.__name__, self._testMethodName,
|
|
|
|
self._testMethodDoc))
|
2016-10-11 11:47:09 +02:00
|
|
|
self.vapi.cli("clear trace")
|
|
|
|
# store the test instance inside the test class - so that objects
|
|
|
|
# holding the class can access instance methods (like assertEqual)
|
|
|
|
type(self).test_instance = self
|
2016-10-03 19:44:57 +02:00
|
|
|
|
|
|
|
@classmethod
|
2017-09-20 08:26:30 +02:00
|
|
|
def pg_enable_capture(cls, interfaces=None):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
Enable capture on packet-generator interfaces
|
|
|
|
|
2017-09-20 08:26:30 +02:00
|
|
|
:param interfaces: iterable interface indexes (if None,
|
|
|
|
use self.pg_interfaces)
|
2016-10-11 11:47:09 +02:00
|
|
|
|
|
|
|
"""
|
2017-09-20 08:26:30 +02:00
|
|
|
if interfaces is None:
|
|
|
|
interfaces = cls.pg_interfaces
|
2016-10-11 11:47:09 +02:00
|
|
|
for i in interfaces:
|
|
|
|
i.enable_capture()
|
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
@classmethod
|
2016-12-12 08:36:58 +01:00
|
|
|
def register_capture(cls, cap_name):
|
|
|
|
""" Register a capture in the testclass """
|
|
|
|
# add to the list of captures with current timestamp
|
|
|
|
cls._captures.append((time.time(), cap_name))
|
|
|
|
|
2019-10-13 18:56:03 +00:00
|
|
|
@classmethod
|
|
|
|
def get_vpp_time(cls):
|
2020-03-11 10:31:36 -04:00
|
|
|
# processes e.g. "Time now 2.190522, Wed, 11 Mar 2020 17:29:54 GMT"
|
|
|
|
# returns float("2.190522")
|
|
|
|
timestr = cls.vapi.cli('show clock')
|
|
|
|
head, sep, tail = timestr.partition(',')
|
|
|
|
head, sep, tail = head.partition('Time now')
|
|
|
|
return float(tail)
|
2019-10-13 18:56:03 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def sleep_on_vpp_time(cls, sec):
|
|
|
|
""" Sleep according to time in VPP world """
|
|
|
|
# On a busy system with many processes
|
|
|
|
# we might end up with VPP time being slower than real world
|
|
|
|
# So take that into account when waiting for VPP to do something
|
|
|
|
start_time = cls.get_vpp_time()
|
|
|
|
while cls.get_vpp_time() - start_time < sec:
|
|
|
|
cls.sleep(0.1)
|
|
|
|
|
2016-12-12 08:36:58 +01:00
|
|
|
@classmethod
|
|
|
|
def pg_start(cls):
|
2019-10-13 10:09:50 +00:00
|
|
|
""" Enable the PG, wait till it is done, then clean up """
|
2019-01-15 13:25:09 +01:00
|
|
|
cls.vapi.cli("trace add pg-input 1000")
|
2016-10-11 11:47:09 +02:00
|
|
|
cls.vapi.cli('packet-generator enable')
|
2019-10-13 10:09:50 +00:00
|
|
|
# PG, when starts, runs to completion -
|
|
|
|
# so let's avoid a race condition,
|
|
|
|
# and wait a little till it's done.
|
|
|
|
# Then clean it up - and then be gone.
|
|
|
|
deadline = time.time() + 300
|
|
|
|
while cls.vapi.cli('show packet-generator').find("Yes") != -1:
|
|
|
|
cls.sleep(0.01) # yield
|
|
|
|
if time.time() > deadline:
|
|
|
|
cls.logger.error("Timeout waiting for pg to stop")
|
|
|
|
break
|
|
|
|
for stamp, cap_name in cls._captures:
|
|
|
|
cls.vapi.cli('packet-generator delete %s' % cap_name)
|
2016-12-12 08:36:58 +01:00
|
|
|
cls._captures = []
|
2016-10-03 19:44:57 +02:00
|
|
|
|
|
|
|
@classmethod
|
2019-07-23 11:54:48 +02:00
|
|
|
def create_pg_interfaces(cls, interfaces, gso=0, gso_size=0):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
2016-12-22 11:06:56 +01:00
|
|
|
Create packet-generator interfaces.
|
2016-10-11 11:47:09 +02:00
|
|
|
|
2016-12-22 11:06:56 +01:00
|
|
|
:param interfaces: iterable indexes of the interfaces.
|
|
|
|
:returns: List of created interfaces.
|
2016-10-11 11:47:09 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
result = []
|
|
|
|
for i in interfaces:
|
2019-07-23 11:54:48 +02:00
|
|
|
intf = VppPGInterface(cls, i, gso, gso_size)
|
2016-10-11 11:47:09 +02:00
|
|
|
setattr(cls, intf.name, intf)
|
|
|
|
result.append(intf)
|
|
|
|
cls.pg_interfaces = result
|
|
|
|
return result
|
|
|
|
|
2016-11-04 11:11:44 +01:00
|
|
|
@classmethod
|
2018-06-24 22:49:33 +02:00
|
|
|
def create_loopback_interfaces(cls, count):
|
2016-11-04 11:11:44 +01:00
|
|
|
"""
|
2016-12-22 11:06:56 +01:00
|
|
|
Create loopback interfaces.
|
2016-11-04 11:11:44 +01:00
|
|
|
|
2018-06-24 22:49:33 +02:00
|
|
|
:param count: number of interfaces created.
|
2016-12-22 11:06:56 +01:00
|
|
|
:returns: List of created interfaces.
|
2016-11-04 11:11:44 +01:00
|
|
|
"""
|
2018-06-24 22:49:33 +02:00
|
|
|
result = [VppLoInterface(cls) for i in range(count)]
|
|
|
|
for intf in result:
|
2016-11-04 11:11:44 +01:00
|
|
|
setattr(cls, intf.name, intf)
|
|
|
|
cls.lo_interfaces = result
|
|
|
|
return result
|
|
|
|
|
2019-03-15 02:16:20 -07:00
|
|
|
@classmethod
|
|
|
|
def create_bvi_interfaces(cls, count):
|
|
|
|
"""
|
|
|
|
Create BVI interfaces.
|
|
|
|
|
|
|
|
:param count: number of interfaces created.
|
|
|
|
:returns: List of created interfaces.
|
|
|
|
"""
|
|
|
|
result = [VppBviInterface(cls) for i in range(count)]
|
|
|
|
for intf in result:
|
|
|
|
setattr(cls, intf.name, intf)
|
|
|
|
cls.bvi_interfaces = result
|
|
|
|
return result
|
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
@staticmethod
|
2017-09-20 08:26:30 +02:00
|
|
|
def extend_packet(packet, size, padding=' '):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
2017-09-20 08:26:30 +02:00
|
|
|
Extend packet to given size by padding with spaces or custom padding
|
2016-10-11 11:47:09 +02:00
|
|
|
NOTE: Currently works only when Raw layer is present.
|
|
|
|
|
|
|
|
:param packet: packet
|
|
|
|
:param size: target size
|
2017-09-20 08:26:30 +02:00
|
|
|
:param padding: padding used to extend the payload
|
2016-10-11 11:47:09 +02:00
|
|
|
|
|
|
|
"""
|
2016-10-03 19:44:57 +02:00
|
|
|
packet_len = len(packet) + 4
|
|
|
|
extend = size - packet_len
|
|
|
|
if extend > 0:
|
2019-05-07 10:39:57 +02:00
|
|
|
num = (extend // len(padding)) + 1
|
|
|
|
packet[Raw].load += (padding * num)[:extend].encode("ascii")
|
2016-10-11 11:47:09 +02:00
|
|
|
|
2016-12-21 08:50:14 +01:00
|
|
|
@classmethod
|
|
|
|
def reset_packet_infos(cls):
|
|
|
|
""" Reset the list of packet info objects and packet counts to zero """
|
|
|
|
cls._packet_infos = {}
|
|
|
|
cls._packet_count_for_dst_if_idx = {}
|
2016-10-11 11:47:09 +02:00
|
|
|
|
2016-12-21 08:50:14 +01:00
|
|
|
@classmethod
|
|
|
|
def create_packet_info(cls, src_if, dst_if):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
Create packet info object containing the source and destination indexes
|
|
|
|
and add it to the testcase's packet info list
|
|
|
|
|
2016-12-21 08:50:14 +01:00
|
|
|
:param VppInterface src_if: source interface
|
|
|
|
:param VppInterface dst_if: destination interface
|
2016-10-11 11:47:09 +02:00
|
|
|
|
|
|
|
:returns: _PacketInfo object
|
|
|
|
|
|
|
|
"""
|
2016-10-03 19:44:57 +02:00
|
|
|
info = _PacketInfo()
|
2016-12-21 08:50:14 +01:00
|
|
|
info.index = len(cls._packet_infos)
|
|
|
|
info.src = src_if.sw_if_index
|
|
|
|
info.dst = dst_if.sw_if_index
|
|
|
|
if isinstance(dst_if, VppSubInterface):
|
|
|
|
dst_idx = dst_if.parent.sw_if_index
|
|
|
|
else:
|
|
|
|
dst_idx = dst_if.sw_if_index
|
|
|
|
if dst_idx in cls._packet_count_for_dst_if_idx:
|
|
|
|
cls._packet_count_for_dst_if_idx[dst_idx] += 1
|
|
|
|
else:
|
|
|
|
cls._packet_count_for_dst_if_idx[dst_idx] = 1
|
|
|
|
cls._packet_infos[info.index] = info
|
2016-10-03 19:44:57 +02:00
|
|
|
return info
|
2016-10-11 11:47:09 +02:00
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
@staticmethod
|
|
|
|
def info_to_payload(info):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
Convert _PacketInfo object to packet payload
|
|
|
|
|
|
|
|
:param info: _PacketInfo object
|
|
|
|
|
|
|
|
:returns: string containing serialized data from packet info
|
|
|
|
"""
|
2017-03-02 15:22:47 +01:00
|
|
|
return "%d %d %d %d %d" % (info.index, info.src, info.dst,
|
|
|
|
info.ip, info.proto)
|
2016-10-03 19:44:57 +02:00
|
|
|
|
|
|
|
@staticmethod
|
2019-03-06 11:58:06 -08:00
|
|
|
def payload_to_info(payload, payload_field='load'):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
Convert packet payload to _PacketInfo object
|
|
|
|
|
|
|
|
:param payload: packet payload
|
2019-03-12 20:04:56 -07:00
|
|
|
:type payload: <class 'scapy.packet.Raw'>
|
|
|
|
:param payload_field: packet fieldname of payload "load" for
|
2019-03-06 11:58:06 -08:00
|
|
|
<class 'scapy.packet.Raw'>
|
2019-03-12 20:04:56 -07:00
|
|
|
:type payload_field: str
|
2016-10-11 11:47:09 +02:00
|
|
|
:returns: _PacketInfo object containing de-serialized data from payload
|
|
|
|
|
|
|
|
"""
|
2019-03-06 11:58:06 -08:00
|
|
|
numbers = getattr(payload, payload_field).split()
|
2016-10-03 19:44:57 +02:00
|
|
|
info = _PacketInfo()
|
|
|
|
info.index = int(numbers[0])
|
|
|
|
info.src = int(numbers[1])
|
|
|
|
info.dst = int(numbers[2])
|
2017-03-02 15:22:47 +01:00
|
|
|
info.ip = int(numbers[3])
|
|
|
|
info.proto = int(numbers[4])
|
2016-10-03 19:44:57 +02:00
|
|
|
return info
|
2016-10-11 11:47:09 +02:00
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
def get_next_packet_info(self, info):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
Iterate over the packet info list stored in the testcase
|
|
|
|
Start iteration with first element if info is None
|
|
|
|
Continue based on index in info if info is specified
|
|
|
|
|
|
|
|
:param info: info or None
|
|
|
|
:returns: next info in list or None if no more infos
|
|
|
|
"""
|
2016-10-03 19:44:57 +02:00
|
|
|
if info is None:
|
|
|
|
next_index = 0
|
|
|
|
else:
|
|
|
|
next_index = info.index + 1
|
2016-12-21 08:50:14 +01:00
|
|
|
if next_index == len(self._packet_infos):
|
2016-10-03 19:44:57 +02:00
|
|
|
return None
|
|
|
|
else:
|
2016-12-21 08:50:14 +01:00
|
|
|
return self._packet_infos[next_index]
|
2016-10-11 11:47:09 +02:00
|
|
|
|
|
|
|
def get_next_packet_info_for_interface(self, src_index, info):
|
|
|
|
"""
|
|
|
|
Search the packet info list for the next packet info with same source
|
|
|
|
interface index
|
|
|
|
|
|
|
|
:param src_index: source interface index to search for
|
|
|
|
:param info: packet info - where to start the search
|
|
|
|
:returns: packet info or None
|
|
|
|
|
|
|
|
"""
|
2016-10-03 19:44:57 +02:00
|
|
|
while True:
|
|
|
|
info = self.get_next_packet_info(info)
|
|
|
|
if info is None:
|
|
|
|
return None
|
2016-10-11 11:47:09 +02:00
|
|
|
if info.src == src_index:
|
2016-10-03 19:44:57 +02:00
|
|
|
return info
|
2016-10-11 11:47:09 +02:00
|
|
|
|
|
|
|
def get_next_packet_info_for_interface2(self, src_index, dst_index, info):
|
|
|
|
"""
|
|
|
|
Search the packet info list for the next packet info with same source
|
|
|
|
and destination interface indexes
|
|
|
|
|
|
|
|
:param src_index: source interface index to search for
|
|
|
|
:param dst_index: destination interface index to search for
|
|
|
|
:param info: packet info - where to start the search
|
|
|
|
:returns: packet info or None
|
|
|
|
|
|
|
|
"""
|
2016-10-03 19:44:57 +02:00
|
|
|
while True:
|
2016-10-11 11:47:09 +02:00
|
|
|
info = self.get_next_packet_info_for_interface(src_index, info)
|
2016-10-03 19:44:57 +02:00
|
|
|
if info is None:
|
|
|
|
return None
|
2016-10-11 11:47:09 +02:00
|
|
|
if info.dst == dst_index:
|
2016-10-03 19:44:57 +02:00
|
|
|
return info
|
|
|
|
|
2016-09-29 14:43:44 +02:00
|
|
|
def assert_equal(self, real_value, expected_value, name_or_class=None):
|
|
|
|
if name_or_class is None:
|
2017-02-16 10:53:53 +01:00
|
|
|
self.assertEqual(real_value, expected_value)
|
2016-09-29 14:43:44 +02:00
|
|
|
return
|
|
|
|
try:
|
|
|
|
msg = "Invalid %s: %d('%s') does not match expected value %d('%s')"
|
|
|
|
msg = msg % (getdoc(name_or_class).strip(),
|
|
|
|
real_value, str(name_or_class(real_value)),
|
|
|
|
expected_value, str(name_or_class(expected_value)))
|
2018-03-21 12:35:51 +01:00
|
|
|
except Exception:
|
2016-09-29 14:43:44 +02:00
|
|
|
msg = "Invalid %s: %s does not match expected value %s" % (
|
|
|
|
name_or_class, real_value, expected_value)
|
|
|
|
|
|
|
|
self.assertEqual(real_value, expected_value, msg)
|
|
|
|
|
2017-01-09 07:43:48 +01:00
|
|
|
def assert_in_range(self,
|
|
|
|
real_value,
|
|
|
|
expected_min,
|
|
|
|
expected_max,
|
|
|
|
name=None):
|
2016-09-29 14:43:44 +02:00
|
|
|
if name is None:
|
|
|
|
msg = None
|
|
|
|
else:
|
|
|
|
msg = "Invalid %s: %s out of range <%s,%s>" % (
|
|
|
|
name, real_value, expected_min, expected_max)
|
|
|
|
self.assertTrue(expected_min <= real_value <= expected_max, msg)
|
|
|
|
|
2018-05-16 10:52:54 +02:00
|
|
|
def assert_packet_checksums_valid(self, packet,
|
|
|
|
ignore_zero_udp_checksums=True):
|
2019-03-10 10:04:23 -07:00
|
|
|
received = packet.__class__(scapy.compat.raw(packet))
|
2018-05-16 10:52:54 +02:00
|
|
|
udp_layers = ['UDP', 'UDPerror']
|
|
|
|
checksum_fields = ['cksum', 'chksum']
|
|
|
|
checksums = []
|
|
|
|
counter = 0
|
2019-03-10 10:04:23 -07:00
|
|
|
temp = received.__class__(scapy.compat.raw(received))
|
2018-05-16 10:52:54 +02:00
|
|
|
while True:
|
|
|
|
layer = temp.getlayer(counter)
|
|
|
|
if layer:
|
2019-12-05 13:13:21 +00:00
|
|
|
layer = layer.copy()
|
|
|
|
layer.remove_payload()
|
2018-05-16 10:52:54 +02:00
|
|
|
for cf in checksum_fields:
|
|
|
|
if hasattr(layer, cf):
|
|
|
|
if ignore_zero_udp_checksums and \
|
2019-05-16 14:34:55 +02:00
|
|
|
0 == getattr(layer, cf) and \
|
|
|
|
layer.name in udp_layers:
|
2018-05-16 10:52:54 +02:00
|
|
|
continue
|
2019-12-05 13:13:21 +00:00
|
|
|
delattr(temp.getlayer(counter), cf)
|
2018-05-16 10:52:54 +02:00
|
|
|
checksums.append((counter, cf))
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
counter = counter + 1
|
2018-06-24 22:49:55 +02:00
|
|
|
if 0 == len(checksums):
|
|
|
|
return
|
2019-03-10 10:04:23 -07:00
|
|
|
temp = temp.__class__(scapy.compat.raw(temp))
|
2018-05-16 10:52:54 +02:00
|
|
|
for layer, cf in checksums:
|
2018-06-24 22:49:55 +02:00
|
|
|
calc_sum = getattr(temp[layer], cf)
|
|
|
|
self.assert_equal(
|
|
|
|
getattr(received[layer], cf), calc_sum,
|
|
|
|
"packet checksum on layer #%d: %s" % (layer, temp[layer].name))
|
|
|
|
self.logger.debug(
|
|
|
|
"Checksum field `%s` on `%s` layer has correct value `%s`" %
|
|
|
|
(cf, temp[layer].name, calc_sum))
|
2018-05-16 10:52:54 +02:00
|
|
|
|
|
|
|
def assert_checksum_valid(self, received_packet, layer,
|
|
|
|
field_name='chksum',
|
|
|
|
ignore_zero_checksum=False):
|
|
|
|
""" Check checksum of received packet on given layer """
|
|
|
|
received_packet_checksum = getattr(received_packet[layer], field_name)
|
|
|
|
if ignore_zero_checksum and 0 == received_packet_checksum:
|
|
|
|
return
|
2019-03-10 10:04:23 -07:00
|
|
|
recalculated = received_packet.__class__(
|
|
|
|
scapy.compat.raw(received_packet))
|
2018-05-16 10:52:54 +02:00
|
|
|
delattr(recalculated[layer], field_name)
|
2019-03-10 10:04:23 -07:00
|
|
|
recalculated = recalculated.__class__(scapy.compat.raw(recalculated))
|
2018-05-16 10:52:54 +02:00
|
|
|
self.assert_equal(received_packet_checksum,
|
|
|
|
getattr(recalculated[layer], field_name),
|
|
|
|
"packet checksum on layer: %s" % layer)
|
|
|
|
|
|
|
|
def assert_ip_checksum_valid(self, received_packet,
|
|
|
|
ignore_zero_checksum=False):
|
|
|
|
self.assert_checksum_valid(received_packet, 'IP',
|
|
|
|
ignore_zero_checksum=ignore_zero_checksum)
|
|
|
|
|
|
|
|
def assert_tcp_checksum_valid(self, received_packet,
|
|
|
|
ignore_zero_checksum=False):
|
|
|
|
self.assert_checksum_valid(received_packet, 'TCP',
|
|
|
|
ignore_zero_checksum=ignore_zero_checksum)
|
|
|
|
|
|
|
|
def assert_udp_checksum_valid(self, received_packet,
|
|
|
|
ignore_zero_checksum=True):
|
|
|
|
self.assert_checksum_valid(received_packet, 'UDP',
|
|
|
|
ignore_zero_checksum=ignore_zero_checksum)
|
|
|
|
|
|
|
|
def assert_embedded_icmp_checksum_valid(self, received_packet):
|
|
|
|
if received_packet.haslayer(IPerror):
|
|
|
|
self.assert_checksum_valid(received_packet, 'IPerror')
|
|
|
|
if received_packet.haslayer(TCPerror):
|
|
|
|
self.assert_checksum_valid(received_packet, 'TCPerror')
|
|
|
|
if received_packet.haslayer(UDPerror):
|
|
|
|
self.assert_checksum_valid(received_packet, 'UDPerror',
|
|
|
|
ignore_zero_checksum=True)
|
|
|
|
if received_packet.haslayer(ICMPerror):
|
|
|
|
self.assert_checksum_valid(received_packet, 'ICMPerror')
|
|
|
|
|
|
|
|
def assert_icmp_checksum_valid(self, received_packet):
|
|
|
|
self.assert_checksum_valid(received_packet, 'ICMP')
|
|
|
|
self.assert_embedded_icmp_checksum_valid(received_packet)
|
|
|
|
|
|
|
|
def assert_icmpv6_checksum_valid(self, pkt):
|
|
|
|
if pkt.haslayer(ICMPv6DestUnreach):
|
|
|
|
self.assert_checksum_valid(pkt, 'ICMPv6DestUnreach', 'cksum')
|
|
|
|
self.assert_embedded_icmp_checksum_valid(pkt)
|
|
|
|
if pkt.haslayer(ICMPv6EchoRequest):
|
|
|
|
self.assert_checksum_valid(pkt, 'ICMPv6EchoRequest', 'cksum')
|
|
|
|
if pkt.haslayer(ICMPv6EchoReply):
|
|
|
|
self.assert_checksum_valid(pkt, 'ICMPv6EchoReply', 'cksum')
|
|
|
|
|
2019-05-16 14:35:46 +02:00
|
|
|
def get_packet_counter(self, counter):
|
|
|
|
if counter.startswith("/"):
|
|
|
|
counter_value = self.statistics.get_counter(counter)
|
|
|
|
else:
|
|
|
|
counters = self.vapi.cli("sh errors").split('\n')
|
2019-05-16 14:34:55 +02:00
|
|
|
counter_value = 0
|
2019-05-16 14:35:46 +02:00
|
|
|
for i in range(1, len(counters) - 1):
|
|
|
|
results = counters[i].split()
|
|
|
|
if results[1] == counter:
|
|
|
|
counter_value = int(results[0])
|
|
|
|
break
|
|
|
|
return counter_value
|
|
|
|
|
2018-11-08 11:24:34 +01:00
|
|
|
def assert_packet_counter_equal(self, counter, expected_value):
|
2019-05-16 14:34:55 +02:00
|
|
|
counter_value = self.get_packet_counter(counter)
|
|
|
|
self.assert_equal(counter_value, expected_value,
|
|
|
|
"packet counter `%s'" % counter)
|
2018-11-08 11:24:34 +01:00
|
|
|
|
2019-05-16 15:01:34 +02:00
|
|
|
def assert_error_counter_equal(self, counter, expected_value):
|
|
|
|
counter_value = self.statistics.get_err_counter(counter)
|
|
|
|
self.assert_equal(counter_value, expected_value,
|
|
|
|
"error counter `%s'" % counter)
|
|
|
|
|
2017-02-14 02:55:31 +01:00
|
|
|
@classmethod
|
|
|
|
def sleep(cls, timeout, remark=None):
|
2019-03-10 09:10:54 -07:00
|
|
|
|
|
|
|
# /* Allow sleep(0) to maintain win32 semantics, and as decreed
|
|
|
|
# * by Guido, only the main thread can be interrupted.
|
|
|
|
# */
|
|
|
|
# https://github.com/python/cpython/blob/6673decfa0fb078f60587f5cb5e98460eea137c2/Modules/timemodule.c#L1892 # noqa
|
|
|
|
if timeout == 0:
|
|
|
|
# yield quantum
|
|
|
|
if hasattr(os, 'sched_yield'):
|
|
|
|
os.sched_yield()
|
|
|
|
else:
|
|
|
|
time.sleep(0)
|
|
|
|
return
|
|
|
|
|
2019-12-01 22:24:28 -05:00
|
|
|
cls.logger.debug("Starting sleep for %es (%s)", timeout, remark)
|
2017-04-19 07:10:58 +00:00
|
|
|
before = time.time()
|
2017-02-02 06:58:07 +01:00
|
|
|
time.sleep(timeout)
|
2017-04-19 07:10:58 +00:00
|
|
|
after = time.time()
|
2019-12-01 22:24:28 -05:00
|
|
|
if after - before > 2 * timeout:
|
2019-03-10 09:10:54 -07:00
|
|
|
cls.logger.error("unexpected self.sleep() result - "
|
2018-12-09 15:37:04 -08:00
|
|
|
"slept for %es instead of ~%es!",
|
|
|
|
after - before, timeout)
|
2019-12-01 22:24:28 -05:00
|
|
|
|
|
|
|
cls.logger.debug(
|
2018-12-09 15:37:04 -08:00
|
|
|
"Finished sleep (%s) - slept %es (wanted %es)",
|
|
|
|
remark, after - before, timeout)
|
2017-02-02 06:58:07 +01:00
|
|
|
|
2019-12-23 04:10:25 +00:00
|
|
|
def pg_send(self, intf, pkts, worker=None):
|
2018-01-08 04:41:42 -08:00
|
|
|
self.vapi.cli("clear trace")
|
2019-12-23 04:10:25 +00:00
|
|
|
intf.add_stream(pkts, worker=worker)
|
2018-01-08 04:41:42 -08:00
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
2019-02-20 09:01:14 -08:00
|
|
|
|
|
|
|
def send_and_assert_no_replies(self, intf, pkts, remark="", timeout=None):
|
|
|
|
self.pg_send(intf, pkts)
|
2018-06-07 23:48:20 -07:00
|
|
|
if not timeout:
|
|
|
|
timeout = 1
|
2018-01-08 04:41:42 -08:00
|
|
|
for i in self.pg_interfaces:
|
|
|
|
i.get_capture(0, timeout=timeout)
|
|
|
|
i.assert_nothing_captured(remark=remark)
|
|
|
|
timeout = 0.1
|
|
|
|
|
2019-12-23 04:10:25 +00:00
|
|
|
def send_and_expect(self, intf, pkts, output, n_rx=None, worker=None):
|
2019-03-28 08:56:10 +00:00
|
|
|
if not n_rx:
|
|
|
|
n_rx = len(pkts)
|
2019-12-23 04:10:25 +00:00
|
|
|
self.pg_send(intf, pkts, worker=worker)
|
2019-03-28 08:56:10 +00:00
|
|
|
rx = output.get_capture(n_rx)
|
2018-10-10 07:22:51 -07:00
|
|
|
return rx
|
|
|
|
|
2019-02-20 09:01:14 -08:00
|
|
|
def send_and_expect_only(self, intf, pkts, output, timeout=None):
|
|
|
|
self.pg_send(intf, pkts)
|
2019-01-07 16:29:26 -08:00
|
|
|
rx = output.get_capture(len(pkts))
|
|
|
|
outputs = [output]
|
2018-10-10 07:22:51 -07:00
|
|
|
if not timeout:
|
|
|
|
timeout = 1
|
|
|
|
for i in self.pg_interfaces:
|
|
|
|
if i not in outputs:
|
|
|
|
i.get_capture(0, timeout=timeout)
|
|
|
|
i.assert_nothing_captured()
|
|
|
|
timeout = 0.1
|
|
|
|
|
2018-01-08 04:41:42 -08:00
|
|
|
return rx
|
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
|
2018-07-16 14:22:01 +02:00
|
|
|
def get_testcase_doc_name(test):
|
|
|
|
return getdoc(test.__class__).splitlines()[0]
|
|
|
|
|
|
|
|
|
2018-11-22 10:01:09 +00:00
|
|
|
def get_test_description(descriptions, test):
|
|
|
|
short_description = test.shortDescription()
|
|
|
|
if descriptions and short_description:
|
|
|
|
return short_description
|
|
|
|
else:
|
|
|
|
return str(test)
|
|
|
|
|
|
|
|
|
2018-09-21 13:55:16 +02:00
|
|
|
class TestCaseInfo(object):
|
|
|
|
def __init__(self, logger, tempdir, vpp_pid, vpp_bin_path):
|
|
|
|
self.logger = logger
|
|
|
|
self.tempdir = tempdir
|
|
|
|
self.vpp_pid = vpp_pid
|
|
|
|
self.vpp_bin_path = vpp_bin_path
|
|
|
|
self.core_crash_test = None
|
2017-03-07 11:39:27 +01:00
|
|
|
|
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
class VppTestResult(unittest.TestResult):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
@property result_string
|
|
|
|
String variable to store the test case result string.
|
|
|
|
@property errors
|
|
|
|
List variable containing 2-tuples of TestCase instances and strings
|
|
|
|
holding formatted tracebacks. Each tuple represents a test which
|
|
|
|
raised an unexpected exception.
|
|
|
|
@property failures
|
|
|
|
List variable containing 2-tuples of TestCase instances and strings
|
|
|
|
holding formatted tracebacks. Each tuple represents a test where
|
|
|
|
a failure was explicitly signalled using the TestCase.assert*()
|
|
|
|
methods.
|
|
|
|
"""
|
|
|
|
|
2018-09-21 13:55:16 +02:00
|
|
|
failed_test_cases_info = set()
|
|
|
|
core_crash_test_cases_info = set()
|
|
|
|
current_test_case_info = None
|
|
|
|
|
2019-01-16 11:12:50 -08:00
|
|
|
def __init__(self, stream=None, descriptions=None, verbosity=None,
|
|
|
|
runner=None):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
2017-01-04 12:58:53 +01:00
|
|
|
:param stream File descriptor to store where to report test results.
|
|
|
|
Set to the standard error stream by default.
|
|
|
|
:param descriptions Boolean variable to store information if to use
|
|
|
|
test case descriptions.
|
2016-10-11 11:47:09 +02:00
|
|
|
:param verbosity Integer variable to store required verbosity level.
|
|
|
|
"""
|
2019-01-13 16:09:10 -08:00
|
|
|
super(VppTestResult, self).__init__(stream, descriptions, verbosity)
|
2016-10-03 19:44:57 +02:00
|
|
|
self.stream = stream
|
|
|
|
self.descriptions = descriptions
|
|
|
|
self.verbosity = verbosity
|
|
|
|
self.result_string = None
|
2018-11-16 17:28:56 +01:00
|
|
|
self.runner = runner
|
2016-10-03 19:44:57 +02:00
|
|
|
|
|
|
|
def addSuccess(self, test):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
Record a test succeeded result
|
|
|
|
|
|
|
|
:param test:
|
|
|
|
|
|
|
|
"""
|
2018-09-21 13:55:16 +02:00
|
|
|
if self.current_test_case_info:
|
|
|
|
self.current_test_case_info.logger.debug(
|
|
|
|
"--- addSuccess() %s.%s(%s) called" % (test.__class__.__name__,
|
|
|
|
test._testMethodName,
|
|
|
|
test._testMethodDoc))
|
2016-10-03 19:44:57 +02:00
|
|
|
unittest.TestResult.addSuccess(self, test)
|
2016-10-28 13:20:27 +02:00
|
|
|
self.result_string = colorize("OK", GREEN)
|
2016-10-11 11:47:09 +02:00
|
|
|
|
2018-09-19 15:01:47 +02:00
|
|
|
self.send_result_through_pipe(test, PASS)
|
|
|
|
|
2016-10-11 11:47:09 +02:00
|
|
|
def addSkip(self, test, reason):
|
|
|
|
"""
|
|
|
|
Record a test skipped.
|
|
|
|
|
|
|
|
:param test:
|
|
|
|
:param reason:
|
|
|
|
|
|
|
|
"""
|
2018-09-21 13:55:16 +02:00
|
|
|
if self.current_test_case_info:
|
|
|
|
self.current_test_case_info.logger.debug(
|
|
|
|
"--- addSkip() %s.%s(%s) called, reason is %s" %
|
|
|
|
(test.__class__.__name__, test._testMethodName,
|
|
|
|
test._testMethodDoc, reason))
|
2016-10-11 11:47:09 +02:00
|
|
|
unittest.TestResult.addSkip(self, test, reason)
|
2016-10-28 13:20:27 +02:00
|
|
|
self.result_string = colorize("SKIP", YELLOW)
|
2016-10-11 11:47:09 +02:00
|
|
|
|
2018-09-19 15:01:47 +02:00
|
|
|
self.send_result_through_pipe(test, SKIP)
|
|
|
|
|
2018-09-21 13:55:16 +02:00
|
|
|
def symlink_failed(self):
|
|
|
|
if self.current_test_case_info:
|
2017-08-15 07:09:02 +02:00
|
|
|
try:
|
2018-11-08 11:21:39 +01:00
|
|
|
failed_dir = os.getenv('FAILED_DIR')
|
2018-09-21 13:55:16 +02:00
|
|
|
link_path = os.path.join(
|
|
|
|
failed_dir,
|
|
|
|
'%s-FAILED' %
|
|
|
|
os.path.basename(self.current_test_case_info.tempdir))
|
2019-12-01 22:24:28 -05:00
|
|
|
|
|
|
|
self.current_test_case_info.logger.debug(
|
2018-09-21 13:55:16 +02:00
|
|
|
"creating a link to the failed test")
|
2019-12-01 22:24:28 -05:00
|
|
|
self.current_test_case_info.logger.debug(
|
2018-09-21 13:55:16 +02:00
|
|
|
"os.symlink(%s, %s)" %
|
|
|
|
(self.current_test_case_info.tempdir, link_path))
|
2018-07-16 14:22:01 +02:00
|
|
|
if os.path.exists(link_path):
|
2019-12-01 22:24:28 -05:00
|
|
|
self.current_test_case_info.logger.debug(
|
2018-09-21 13:55:16 +02:00
|
|
|
'symlink already exists')
|
2018-07-16 14:22:01 +02:00
|
|
|
else:
|
2018-09-21 13:55:16 +02:00
|
|
|
os.symlink(self.current_test_case_info.tempdir, link_path)
|
2018-07-16 14:22:01 +02:00
|
|
|
|
2017-08-15 07:09:02 +02:00
|
|
|
except Exception as e:
|
2019-12-01 22:24:28 -05:00
|
|
|
self.current_test_case_info.logger.error(e)
|
2017-08-15 07:09:02 +02:00
|
|
|
|
2018-09-19 15:01:47 +02:00
|
|
|
def send_result_through_pipe(self, test, result):
|
|
|
|
if hasattr(self, 'test_framework_result_pipe'):
|
|
|
|
pipe = self.test_framework_result_pipe
|
2018-08-30 10:51:45 +02:00
|
|
|
if pipe:
|
2018-09-19 15:01:47 +02:00
|
|
|
pipe.send((test.id(), result))
|
2018-08-30 10:51:45 +02:00
|
|
|
|
2018-09-21 13:55:16 +02:00
|
|
|
def log_error(self, test, err, fn_name):
|
|
|
|
if self.current_test_case_info:
|
|
|
|
if isinstance(test, unittest.suite._ErrorHolder):
|
|
|
|
test_name = test.description
|
|
|
|
else:
|
|
|
|
test_name = '%s.%s(%s)' % (test.__class__.__name__,
|
|
|
|
test._testMethodName,
|
|
|
|
test._testMethodDoc)
|
|
|
|
self.current_test_case_info.logger.debug(
|
|
|
|
"--- %s() %s called, err is %s" %
|
|
|
|
(fn_name, test_name, err))
|
|
|
|
self.current_test_case_info.logger.debug(
|
|
|
|
"formatted exception is:\n%s" %
|
|
|
|
"".join(format_exception(*err)))
|
|
|
|
|
|
|
|
def add_error(self, test, err, unittest_fn, error_type):
|
|
|
|
if error_type == FAIL:
|
|
|
|
self.log_error(test, err, 'addFailure')
|
|
|
|
error_type_str = colorize("FAIL", RED)
|
|
|
|
elif error_type == ERROR:
|
|
|
|
self.log_error(test, err, 'addError')
|
|
|
|
error_type_str = colorize("ERROR", RED)
|
|
|
|
else:
|
|
|
|
raise Exception('Error type %s cannot be used to record an '
|
|
|
|
'error or a failure' % error_type)
|
|
|
|
|
|
|
|
unittest_fn(self, test, err)
|
|
|
|
if self.current_test_case_info:
|
|
|
|
self.result_string = "%s [ temp dir used by test case: %s ]" % \
|
|
|
|
(error_type_str,
|
|
|
|
self.current_test_case_info.tempdir)
|
|
|
|
self.symlink_failed()
|
|
|
|
self.failed_test_cases_info.add(self.current_test_case_info)
|
|
|
|
if is_core_present(self.current_test_case_info.tempdir):
|
|
|
|
if not self.current_test_case_info.core_crash_test:
|
|
|
|
if isinstance(test, unittest.suite._ErrorHolder):
|
|
|
|
test_name = str(test)
|
|
|
|
else:
|
2019-03-06 08:23:58 -08:00
|
|
|
test_name = "'{!s}' ({!s})".format(
|
2018-09-21 13:55:16 +02:00
|
|
|
get_testcase_doc_name(test), test.id())
|
|
|
|
self.current_test_case_info.core_crash_test = test_name
|
|
|
|
self.core_crash_test_cases_info.add(
|
|
|
|
self.current_test_case_info)
|
|
|
|
else:
|
|
|
|
self.result_string = '%s [no temp dir]' % error_type_str
|
|
|
|
|
|
|
|
self.send_result_through_pipe(test, error_type)
|
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
def addFailure(self, test, err):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
Record a test failed result
|
|
|
|
|
|
|
|
:param test:
|
|
|
|
:param err: error message
|
|
|
|
|
|
|
|
"""
|
2018-09-21 13:55:16 +02:00
|
|
|
self.add_error(test, err, unittest.TestResult.addFailure, FAIL)
|
2018-09-19 15:01:47 +02:00
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
def addError(self, test, err):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
Record a test error result
|
|
|
|
|
|
|
|
:param test:
|
|
|
|
:param err: error message
|
|
|
|
|
|
|
|
"""
|
2018-09-21 13:55:16 +02:00
|
|
|
self.add_error(test, err, unittest.TestResult.addError, ERROR)
|
2018-09-19 15:01:47 +02:00
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
def getDescription(self, test):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
Get test description
|
|
|
|
|
|
|
|
:param test:
|
|
|
|
:returns: test description
|
|
|
|
|
|
|
|
"""
|
2018-11-22 10:01:09 +00:00
|
|
|
return get_test_description(self.descriptions, test)
|
2016-10-11 11:47:09 +02:00
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
def startTest(self, test):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
Start a test
|
|
|
|
|
|
|
|
:param test:
|
|
|
|
|
|
|
|
"""
|
2019-01-13 16:09:10 -08:00
|
|
|
|
|
|
|
def print_header(test):
|
2020-08-26 14:33:54 +00:00
|
|
|
test_doc = getdoc(test)
|
|
|
|
if not test_doc:
|
|
|
|
raise Exception("No doc string for test '%s'" % test.id())
|
|
|
|
test_title = test_doc.splitlines()[0]
|
|
|
|
test_title_colored = colorize(test_title, GREEN)
|
|
|
|
if test.force_solo():
|
|
|
|
# long live PEP-8 and 80 char width limitation...
|
|
|
|
c = YELLOW
|
|
|
|
test_title_colored = colorize("SOLO RUN: " + test_title, c)
|
|
|
|
|
2019-01-13 16:09:10 -08:00
|
|
|
if not hasattr(test.__class__, '_header_printed'):
|
|
|
|
print(double_line_delim)
|
2020-08-26 14:33:54 +00:00
|
|
|
print(test_title_colored)
|
2019-01-13 16:09:10 -08:00
|
|
|
print(double_line_delim)
|
|
|
|
test.__class__._header_printed = True
|
|
|
|
|
|
|
|
print_header(test)
|
2019-11-28 14:48:44 +01:00
|
|
|
self.start_test = time.time()
|
2016-10-03 19:44:57 +02:00
|
|
|
unittest.TestResult.startTest(self, test)
|
|
|
|
if self.verbosity > 0:
|
2016-10-11 11:47:09 +02:00
|
|
|
self.stream.writeln(
|
|
|
|
"Starting " + self.getDescription(test) + " ...")
|
|
|
|
self.stream.writeln(single_line_delim)
|
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
def stopTest(self, test):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
2018-08-30 10:51:45 +02:00
|
|
|
Called when the given test has been run
|
2016-10-11 11:47:09 +02:00
|
|
|
|
|
|
|
:param test:
|
|
|
|
|
|
|
|
"""
|
2016-10-03 19:44:57 +02:00
|
|
|
unittest.TestResult.stopTest(self, test)
|
2019-11-28 14:48:44 +01:00
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
if self.verbosity > 0:
|
2016-10-11 11:47:09 +02:00
|
|
|
self.stream.writeln(single_line_delim)
|
2017-01-13 07:25:25 +01:00
|
|
|
self.stream.writeln("%-73s%s" % (self.getDescription(test),
|
2017-01-04 12:58:53 +01:00
|
|
|
self.result_string))
|
2016-10-11 11:47:09 +02:00
|
|
|
self.stream.writeln(single_line_delim)
|
2016-10-03 19:44:57 +02:00
|
|
|
else:
|
2019-11-28 14:48:44 +01:00
|
|
|
self.stream.writeln("%-68s %4.2f %s" %
|
|
|
|
(self.getDescription(test),
|
|
|
|
time.time() - self.start_test,
|
|
|
|
self.result_string))
|
2018-09-19 15:01:47 +02:00
|
|
|
|
|
|
|
self.send_result_through_pipe(test, TEST_RUN)
|
2016-10-03 19:44:57 +02:00
|
|
|
|
|
|
|
def printErrors(self):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
Print errors from running the test case
|
|
|
|
"""
|
2018-11-16 17:28:56 +01:00
|
|
|
if len(self.errors) > 0 or len(self.failures) > 0:
|
|
|
|
self.stream.writeln()
|
|
|
|
self.printErrorList('ERROR', self.errors)
|
|
|
|
self.printErrorList('FAIL', self.failures)
|
|
|
|
|
|
|
|
# ^^ that is the last output from unittest before summary
|
|
|
|
if not self.runner.print_summary:
|
|
|
|
devnull = unittest.runner._WritelnDecorator(open(os.devnull, 'w'))
|
|
|
|
self.stream = devnull
|
|
|
|
self.runner.stream = devnull
|
2016-10-11 11:47:09 +02:00
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
def printErrorList(self, flavour, errors):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
Print error list to the output stream together with error type
|
|
|
|
and test case description.
|
|
|
|
|
|
|
|
:param flavour: error type
|
|
|
|
:param errors: iterable errors
|
|
|
|
|
|
|
|
"""
|
2016-10-03 19:44:57 +02:00
|
|
|
for test, err in errors:
|
2016-10-11 11:47:09 +02:00
|
|
|
self.stream.writeln(double_line_delim)
|
|
|
|
self.stream.writeln("%s: %s" %
|
|
|
|
(flavour, self.getDescription(test)))
|
|
|
|
self.stream.writeln(single_line_delim)
|
2016-10-03 19:44:57 +02:00
|
|
|
self.stream.writeln("%s" % err)
|
|
|
|
|
|
|
|
|
|
|
|
class VppTestRunner(unittest.TextTestRunner):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
2017-02-03 07:29:43 +01:00
|
|
|
A basic test runner implementation which prints results to standard error.
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
2018-12-09 15:37:04 -08:00
|
|
|
|
2016-10-11 11:47:09 +02:00
|
|
|
@property
|
|
|
|
def resultclass(self):
|
|
|
|
"""Class maintaining the results of the tests"""
|
|
|
|
return VppTestResult
|
|
|
|
|
2018-07-16 14:22:01 +02:00
|
|
|
def __init__(self, keep_alive_pipe=None, descriptions=True, verbosity=1,
|
2018-09-19 15:01:47 +02:00
|
|
|
result_pipe=None, failfast=False, buffer=False,
|
2019-01-13 21:32:37 -08:00
|
|
|
resultclass=None, print_summary=True, **kwargs):
|
2017-01-17 13:42:48 +01:00
|
|
|
# ignore stream setting here, use hard-coded stdout to be in sync
|
|
|
|
# with prints from VppTestCase methods ...
|
|
|
|
super(VppTestRunner, self).__init__(sys.stdout, descriptions,
|
|
|
|
verbosity, failfast, buffer,
|
2019-01-13 21:32:37 -08:00
|
|
|
resultclass, **kwargs)
|
2018-11-21 13:20:43 +01:00
|
|
|
KeepAliveReporter.pipe = keep_alive_pipe
|
2017-02-03 07:29:43 +01:00
|
|
|
|
2018-11-16 17:28:56 +01:00
|
|
|
self.orig_stream = self.stream
|
|
|
|
self.resultclass.test_framework_result_pipe = result_pipe
|
|
|
|
|
|
|
|
self.print_summary = print_summary
|
|
|
|
|
|
|
|
def _makeResult(self):
|
|
|
|
return self.resultclass(self.stream,
|
|
|
|
self.descriptions,
|
|
|
|
self.verbosity,
|
|
|
|
self)
|
2018-08-30 10:51:45 +02:00
|
|
|
|
2016-10-03 19:44:57 +02:00
|
|
|
def run(self, test):
|
2016-10-11 11:47:09 +02:00
|
|
|
"""
|
|
|
|
Run the tests
|
|
|
|
|
|
|
|
:param test:
|
|
|
|
|
|
|
|
"""
|
2017-06-07 08:19:47 +02:00
|
|
|
faulthandler.enable() # emit stack trace to stderr if killed by signal
|
2018-07-16 14:22:01 +02:00
|
|
|
|
|
|
|
result = super(VppTestRunner, self).run(test)
|
2018-11-16 17:28:56 +01:00
|
|
|
if not self.print_summary:
|
|
|
|
self.stream = self.orig_stream
|
|
|
|
result.stream = self.orig_stream
|
2018-07-16 14:22:01 +02:00
|
|
|
return result
|
2017-10-16 04:20:13 -07:00
|
|
|
|
|
|
|
|
|
|
|
class Worker(Thread):
|
2019-12-04 19:43:53 -05:00
|
|
|
def __init__(self, executable_args, logger, env=None, *args, **kwargs):
|
|
|
|
super(Worker, self).__init__(*args, **kwargs)
|
2017-10-16 04:20:13 -07:00
|
|
|
self.logger = logger
|
2019-12-04 19:43:53 -05:00
|
|
|
self.args = executable_args
|
2019-10-21 02:53:14 +00:00
|
|
|
if hasattr(self, 'testcase') and self.testcase.debug_all:
|
|
|
|
if self.testcase.debug_gdbserver:
|
|
|
|
self.args = ['/usr/bin/gdbserver', 'localhost:{port}'
|
|
|
|
.format(port=self.testcase.gdbserver_port)] + args
|
|
|
|
elif self.testcase.debug_gdb and hasattr(self, 'wait_for_gdb'):
|
|
|
|
self.args.append(self.wait_for_gdb)
|
2019-12-04 19:43:53 -05:00
|
|
|
self.app_bin = executable_args[0]
|
2019-10-21 02:53:14 +00:00
|
|
|
self.app_name = os.path.basename(self.app_bin)
|
|
|
|
if hasattr(self, 'role'):
|
|
|
|
self.app_name += ' {role}'.format(role=self.role)
|
tests: Have worker return immediately on bad executable
No reason to waste CI cycles if we know the test will not run.
See:
17:55:11 ==============================================================================
17:55:11 VPP Object Model Test
17:55:11 ==============================================================================
17:55:11 Exception in thread Thread-4:
17:55:11 Traceback (most recent call last):
17:55:11 File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
17:55:11 self.run()
17:55:11 File "/w/workspace/vpp-beta-verify-master-ubuntu1804/test/framework.py", line 1475, in run
17:55:11 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
17:55:11 File "/w/workspace/vpp-beta-verify-master-ubuntu1804/test/run/venv/local/lib/python2.7/site-packages/subprocess32.py", line 617, in __init__
17:55:11 restore_signals, start_new_session)
17:55:11 File "/w/workspace/vpp-beta-verify-master-ubuntu1804/test/run/venv/local/lib/python2.7/site-packages/subprocess32.py", line 1415, in _execute_child
17:55:11 raise child_exception_type(errno_num, err_msg)
17:55:11 OSError: [Errno 2] No such file or directory: '/w/workspace/vpp-beta-verify-master-ubuntu1804/test/build/vom_test/vom_test'
17:55:11
17:55:11 17:55:11,328 Timeout! Worker did not finish in 120s
17:55:11 run C++ VOM tests ERROR [ temp dir used by test case: /tmp/vpp-unittest-VOMTestCase-vpMcWF ]
17:55:11
Type: fix
Change-Id: I3d8252807e98a09a8abd70de8a22517151f9d786
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2019-06-30 15:38:55 -04:00
|
|
|
self.process = None
|
2017-10-16 04:20:13 -07:00
|
|
|
self.result = None
|
tests: Have worker return immediately on bad executable
No reason to waste CI cycles if we know the test will not run.
See:
17:55:11 ==============================================================================
17:55:11 VPP Object Model Test
17:55:11 ==============================================================================
17:55:11 Exception in thread Thread-4:
17:55:11 Traceback (most recent call last):
17:55:11 File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
17:55:11 self.run()
17:55:11 File "/w/workspace/vpp-beta-verify-master-ubuntu1804/test/framework.py", line 1475, in run
17:55:11 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
17:55:11 File "/w/workspace/vpp-beta-verify-master-ubuntu1804/test/run/venv/local/lib/python2.7/site-packages/subprocess32.py", line 617, in __init__
17:55:11 restore_signals, start_new_session)
17:55:11 File "/w/workspace/vpp-beta-verify-master-ubuntu1804/test/run/venv/local/lib/python2.7/site-packages/subprocess32.py", line 1415, in _execute_child
17:55:11 raise child_exception_type(errno_num, err_msg)
17:55:11 OSError: [Errno 2] No such file or directory: '/w/workspace/vpp-beta-verify-master-ubuntu1804/test/build/vom_test/vom_test'
17:55:11
17:55:11 17:55:11,328 Timeout! Worker did not finish in 120s
17:55:11 run C++ VOM tests ERROR [ temp dir used by test case: /tmp/vpp-unittest-VOMTestCase-vpMcWF ]
17:55:11
Type: fix
Change-Id: I3d8252807e98a09a8abd70de8a22517151f9d786
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2019-06-30 15:38:55 -04:00
|
|
|
env = {} if env is None else env
|
2018-02-26 14:40:13 -05:00
|
|
|
self.env = copy.deepcopy(env)
|
2017-10-16 04:20:13 -07:00
|
|
|
|
2019-10-21 02:53:14 +00:00
|
|
|
def wait_for_enter(self):
|
|
|
|
if not hasattr(self, 'testcase'):
|
|
|
|
return
|
|
|
|
if self.testcase.debug_all and self.testcase.debug_gdbserver:
|
|
|
|
print()
|
|
|
|
print(double_line_delim)
|
|
|
|
print("Spawned GDB Server for '{app}' with PID: {pid}"
|
|
|
|
.format(app=self.app_name, pid=self.process.pid))
|
|
|
|
elif self.testcase.debug_all and self.testcase.debug_gdb:
|
|
|
|
print()
|
|
|
|
print(double_line_delim)
|
|
|
|
print("Spawned '{app}' with PID: {pid}"
|
|
|
|
.format(app=self.app_name, pid=self.process.pid))
|
|
|
|
else:
|
|
|
|
return
|
|
|
|
print(single_line_delim)
|
|
|
|
print("You can debug '{app}' using:".format(app=self.app_name))
|
|
|
|
if self.testcase.debug_gdbserver:
|
|
|
|
print("sudo gdb " + self.app_bin +
|
|
|
|
" -ex 'target remote localhost:{port}'"
|
|
|
|
.format(port=self.testcase.gdbserver_port))
|
|
|
|
print("Now is the time to attach gdb by running the above "
|
|
|
|
"command, set up breakpoints etc., then resume from "
|
|
|
|
"within gdb by issuing the 'continue' command")
|
|
|
|
self.testcase.gdbserver_port += 1
|
|
|
|
elif self.testcase.debug_gdb:
|
|
|
|
print("sudo gdb " + self.app_bin +
|
|
|
|
" -ex 'attach {pid}'".format(pid=self.process.pid))
|
|
|
|
print("Now is the time to attach gdb by running the above "
|
|
|
|
"command and set up breakpoints etc., then resume from"
|
|
|
|
" within gdb by issuing the 'continue' command")
|
|
|
|
print(single_line_delim)
|
|
|
|
input("Press ENTER to continue running the testcase...")
|
|
|
|
|
2017-10-16 04:20:13 -07:00
|
|
|
def run(self):
|
|
|
|
executable = self.args[0]
|
tests: Have worker return immediately on bad executable
No reason to waste CI cycles if we know the test will not run.
See:
17:55:11 ==============================================================================
17:55:11 VPP Object Model Test
17:55:11 ==============================================================================
17:55:11 Exception in thread Thread-4:
17:55:11 Traceback (most recent call last):
17:55:11 File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
17:55:11 self.run()
17:55:11 File "/w/workspace/vpp-beta-verify-master-ubuntu1804/test/framework.py", line 1475, in run
17:55:11 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
17:55:11 File "/w/workspace/vpp-beta-verify-master-ubuntu1804/test/run/venv/local/lib/python2.7/site-packages/subprocess32.py", line 617, in __init__
17:55:11 restore_signals, start_new_session)
17:55:11 File "/w/workspace/vpp-beta-verify-master-ubuntu1804/test/run/venv/local/lib/python2.7/site-packages/subprocess32.py", line 1415, in _execute_child
17:55:11 raise child_exception_type(errno_num, err_msg)
17:55:11 OSError: [Errno 2] No such file or directory: '/w/workspace/vpp-beta-verify-master-ubuntu1804/test/build/vom_test/vom_test'
17:55:11
17:55:11 17:55:11,328 Timeout! Worker did not finish in 120s
17:55:11 run C++ VOM tests ERROR [ temp dir used by test case: /tmp/vpp-unittest-VOMTestCase-vpMcWF ]
17:55:11
Type: fix
Change-Id: I3d8252807e98a09a8abd70de8a22517151f9d786
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2019-06-30 15:38:55 -04:00
|
|
|
if not os.path.exists(executable) or not os.access(
|
|
|
|
executable, os.F_OK | os.X_OK):
|
|
|
|
# Exit code that means some system file did not exist,
|
|
|
|
# could not be opened, or had some other kind of error.
|
|
|
|
self.result = os.EX_OSFILE
|
|
|
|
raise EnvironmentError(
|
|
|
|
"executable '%s' is not found or executable." % executable)
|
2019-10-21 02:53:14 +00:00
|
|
|
self.logger.debug("Running executable: '{app}'"
|
|
|
|
.format(app=' '.join(self.args)))
|
2017-10-16 04:20:13 -07:00
|
|
|
env = os.environ.copy()
|
2018-02-16 18:31:56 -05:00
|
|
|
env.update(self.env)
|
2017-10-16 04:20:13 -07:00
|
|
|
env["CK_LOG_FILE_NAME"] = "-"
|
|
|
|
self.process = subprocess.Popen(
|
|
|
|
self.args, shell=False, env=env, preexec_fn=os.setpgrp,
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
2019-10-21 02:53:14 +00:00
|
|
|
self.wait_for_enter()
|
2017-10-16 04:20:13 -07:00
|
|
|
out, err = self.process.communicate()
|
2019-10-21 02:53:14 +00:00
|
|
|
self.logger.debug("Finished running `{app}'".format(app=self.app_name))
|
2017-10-16 04:20:13 -07:00
|
|
|
self.logger.info("Return code is `%s'" % self.process.returncode)
|
|
|
|
self.logger.info(single_line_delim)
|
2019-10-21 02:53:14 +00:00
|
|
|
self.logger.info("Executable `{app}' wrote to stdout:"
|
|
|
|
.format(app=self.app_name))
|
2017-10-16 04:20:13 -07:00
|
|
|
self.logger.info(single_line_delim)
|
2019-10-29 19:12:03 -04:00
|
|
|
self.logger.info(out.decode('utf-8'))
|
2017-10-16 04:20:13 -07:00
|
|
|
self.logger.info(single_line_delim)
|
2019-10-21 02:53:14 +00:00
|
|
|
self.logger.info("Executable `{app}' wrote to stderr:"
|
|
|
|
.format(app=self.app_name))
|
2017-10-16 04:20:13 -07:00
|
|
|
self.logger.info(single_line_delim)
|
2019-10-29 19:12:03 -04:00
|
|
|
self.logger.info(err.decode('utf-8'))
|
2017-10-16 04:20:13 -07:00
|
|
|
self.logger.info(single_line_delim)
|
|
|
|
self.result = self.process.returncode
|
2019-01-13 16:09:10 -08:00
|
|
|
|
2019-05-16 14:34:55 +02:00
|
|
|
|
2019-01-13 16:09:10 -08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
pass
|