When sanity test is not done, API files are not loaded until the
first test case is run. Hence, it is not possible to use enums, etc.
outside of a test class.
By preloading API files before running any tests, it prevents its
issue.
Type: fix
Change-Id: I8730150374e6c5f8d6933ec037811372ac2a8da0
Signed-off-by: Maxime Peim <mpeim@cisco.com>
class TestVppPapiVPPApiClient(unittest.TestCase):
def test_getcontext(self):
class TestVppPapiVPPApiClient(unittest.TestCase):
def test_getcontext(self):
- vpp_papi.VPPApiClient.apidir = "."
- c = vpp_papi.VPPApiClient(testmode=True, use_socket=True)
+ c = vpp_papi.VPPApiClient(apidir=".", testmode=True, use_socket=True)
# reset initialization at module load time.
c.get_context.context = mp.Value(ctypes.c_uint, 0)
# reset initialization at module load time.
c.get_context.context = mp.Value(ctypes.c_uint, 0)
# run_tests.py (eg. make test TEST_JOBS=10)
def test_get_context_mp(self):
# run_tests.py (eg. make test TEST_JOBS=10)
def test_get_context_mp(self):
- vpp_papi.VPPApiClient.apidir = "."
- c = vpp_papi.VPPApiClient(testmode=True, use_socket=True)
+ c = vpp_papi.VPPApiClient(apidir=".", testmode=True, use_socket=True)
# reset initialization at module load time.
c.get_context.context = mp.Value(ctypes.c_uint, 0)
# reset initialization at module load time.
c.get_context.context = mp.Value(ctypes.c_uint, 0)
@classmethod
def process_json_file(self, apidef_file):
@classmethod
def process_json_file(self, apidef_file):
- api = json.load(apidef_file)
- return self._process_json(api)
+ return self._process_json(apidef_file.read())
@classmethod
def process_json_str(self, json_str):
@classmethod
def process_json_str(self, json_str):
- api = json.loads(json_str)
- return self._process_json(api)
+ return self._process_json(json_str)
- def _process_json(api): # -> Tuple[Dict, Dict]
+ def _process_json(json_str): # -> Tuple[Dict, Dict]
+ api = json.loads(json_str)
types = {}
services = {}
messages = {}
types = {}
services = {}
messages = {}
pass
return messages, services
pass
return messages, services
+ @staticmethod
+ def load_api(apifiles=None, apidir=None):
+ messages = {}
+ services = {}
+ if not apifiles:
+ # Pick up API definitions from default directory
+ try:
+ if isinstance(apidir, list):
+ apifiles = []
+ for d in apidir:
+ apifiles += VPPApiJSONFiles.find_api_files(d)
+ else:
+ apifiles = VPPApiJSONFiles.find_api_files(apidir)
+ except (RuntimeError, VPPApiError):
+ raise VPPRuntimeError
+
+ for file in apifiles:
+ with open(file) as apidef_file:
+ m, s = VPPApiJSONFiles.process_json_file(apidef_file)
+ messages.update(m)
+ services.update(s)
+
+ return apifiles, messages, services
+
class VPPApiClient:
"""VPP interface.
class VPPApiClient:
"""VPP interface.
these messages in a background thread.
"""
these messages in a background thread.
"""
VPPApiError = VPPApiError
VPPRuntimeError = VPPRuntimeError
VPPValueError = VPPValueError
VPPApiError = VPPApiError
VPPRuntimeError = VPPRuntimeError
VPPValueError = VPPValueError
testmode=False,
async_thread=True,
logger=None,
testmode=False,
async_thread=True,
logger=None,
self.id_msgdef = []
self.header = VPPType("header", [["u16", "msgid"], ["u32", "client_index"]])
self.apifiles = []
self.id_msgdef = []
self.header = VPPType("header", [["u16", "msgid"], ["u32", "client_index"]])
self.apifiles = []
self.event_callback = None
self.message_queue = queue.Queue()
self.read_timeout = read_timeout
self.event_callback = None
self.message_queue = queue.Queue()
self.read_timeout = read_timeout
self._apifiles = apifiles
self.stats = {}
self._apifiles = apifiles
self.stats = {}
- if not apifiles:
- # Pick up API definitions from default directory
- try:
- if isinstance(self.apidir, list):
- apifiles = []
- for d in self.apidir:
- apifiles += VPPApiJSONFiles.find_api_files(d)
- else:
- apifiles = VPPApiJSONFiles.find_api_files(self.apidir)
- except (RuntimeError, VPPApiError):
- # In test mode we don't care that we can't find the API files
- if testmode:
- apifiles = []
- else:
- raise VPPRuntimeError
-
- for file in apifiles:
- with open(file) as apidef_file:
- m, s = VPPApiJSONFiles.process_json_file(apidef_file)
- self.messages.update(m)
- self.services.update(s)
-
- self.apifiles = apifiles
+ try:
+ self.apifiles, self.messages, self.services = VPPApiJSONFiles.load_api(
+ apifiles, apidir
+ )
+ except VPPRuntimeError as e:
+ if testmode:
+ self.apifiles = []
+ else:
+ raise e
# Basic sanity check
if len(self.messages) == 0 and not testmode:
# Basic sanity check
if len(self.messages) == 0 and not testmode:
ARG18=--decode-pcaps
endif
ARG18=--decode-pcaps
endif
+ifneq ($(findstring $(API_PRELOAD),1 y yes),)
+ARG19=--api-preload
+else
+ARG19=
+endif
+
EXC_PLUGINS_ARG=
ifneq ($(VPP_EXCLUDED_PLUGINS),)
# convert the comma-separated list into N invocations of the argument to exclude a plugin
EXC_PLUGINS_ARG=
ifneq ($(VPP_EXCLUDED_PLUGINS),)
# convert the comma-separated list into N invocations of the argument to exclude a plugin
-EXTRA_ARGS=$(ARG0) $(ARG1) $(ARG2) $(ARG3) $(ARG4) $(ARG5) $(ARG6) $(ARG7) $(ARG8) $(ARG9) $(ARG10) $(ARG11) $(ARG12) $(ARG13) $(ARG14) $(ARG15) $(ARG16) $(ARG17) $(ARG18)
+EXTRA_ARGS=$(ARG0) $(ARG1) $(ARG2) $(ARG3) $(ARG4) $(ARG5) $(ARG6) $(ARG7) $(ARG8) $(ARG9) $(ARG10) $(ARG11) $(ARG12) $(ARG13) $(ARG14) $(ARG15) $(ARG16) $(ARG17) $(ARG18) $(ARG19)
RUN_TESTS_ARGS=--failed-dir=$(FAILED_DIR) --verbose=$(V) --jobs=$(TEST_JOBS) --filter=$(TEST) --retries=$(RETRIES) --venv-dir=$(VENV_PATH) --vpp-ws-dir=$(WS_ROOT) --vpp-tag=$(TAG) --rnd-seed=$(RND_SEED) --vpp-worker-count="$(VPP_WORKER_COUNT)" --keep-pcaps $(PLUGIN_PATH_ARGS) $(EXC_PLUGINS_ARG) $(TEST_PLUGIN_PATH_ARGS) $(EXTRA_ARGS)
RUN_SCRIPT_ARGS=--python-opts=$(PYTHON_OPTS)
RUN_TESTS_ARGS=--failed-dir=$(FAILED_DIR) --verbose=$(V) --jobs=$(TEST_JOBS) --filter=$(TEST) --retries=$(RETRIES) --venv-dir=$(VENV_PATH) --vpp-ws-dir=$(WS_ROOT) --vpp-tag=$(TAG) --rnd-seed=$(RND_SEED) --vpp-worker-count="$(VPP_WORKER_COUNT)" --keep-pcaps $(PLUGIN_PATH_ARGS) $(EXC_PLUGINS_ARG) $(TEST_PLUGIN_PATH_ARGS) $(EXTRA_ARGS)
RUN_SCRIPT_ARGS=--python-opts=$(PYTHON_OPTS)
parser.add_argument(
"--sanity", action="store_true", help="perform sanity vpp run before running tests"
)
parser.add_argument(
"--sanity", action="store_true", help="perform sanity vpp run before running tests"
)
+parser.add_argument("--api-preload", action="store_true", help="preload API files")
parser.add_argument(
"--force-foreground",
parser.add_argument(
"--force-foreground",
from multiprocessing.queues import Queue
from multiprocessing.managers import BaseManager
from config import config, num_cpus, available_cpus, max_vpp_cpus
from multiprocessing.queues import Queue
from multiprocessing.managers import BaseManager
from config import config, num_cpus, available_cpus, max_vpp_cpus
+from vpp_papi import VPPApiJSONFiles
from asfframework import (
VppTestRunner,
get_testcase_doc_name,
from asfframework import (
VppTestRunner,
get_testcase_doc_name,
if __name__ == "__main__":
print(f"Config is: {config}")
if __name__ == "__main__":
print(f"Config is: {config}")
+ if config.api_preload:
+ VPPApiJSONFiles.load_api(apidir=config.extern_apidir + [config.vpp_install_dir])
+
if config.sanity:
print("Running sanity test case.")
try:
if config.sanity:
print("Running sanity test case.")
try:
self._expect_api_retval = self._zero
self._expect_stack = []
self._expect_api_retval = self._zero
self._expect_stack = []
- # install_dir is a class attribute. We need to set it before
- # calling the constructor.
- VPPApiClient.apidir = config.extern_apidir + [config.vpp_install_dir]
-
+ apidir=config.extern_apidir + [config.vpp_install_dir],
logger=test_class.logger,
read_timeout=read_timeout,
use_socket=True,
logger=test_class.logger,
read_timeout=read_timeout,
use_socket=True,