1 ASAN_OPTIONS?=verify_asan_link_order=0:detect_leaks=0:abort_on_error=1:unmap_shadow_on_exit=1:disable_coredump=0
7 $(error WS_ROOT is not set)
10 $(error BR is not set)
13 $(error TEST_DIR is not set)
16 export TEST_BR = $(TEST_DIR)
17 FAILED_DIR=/tmp/vpp-failed-unittests/
18 VPP_TEST_DIRS=$(shell ls -d $(TEST_DIR) $(EXTERN_TESTS))
23 else ifeq ($(DEBUG),gdbserver)
25 else ifeq ($(DEBUG),gdb-all)
27 else ifeq ($(DEBUG),gdbserver-all)
29 else ifeq ($(DEBUG),core)
31 else ifeq ($(DEBUG),attach)
34 else ifeq ($(STEP),yes)
45 PROFILE_OUTPUT_OPTS=-o $(PROFILE_OUTPUT)
48 ifndef PROFILE_SORT_BY
49 PROFILE_SORT_BY=cumtime
53 PYTHON_OPTS="-m cProfile $(PROFILE_OUTPUT_OPTS) -s $(PROFILE_SORT_BY)"
57 VENV_PATH=$(TEST_DIR)/venv
59 ifeq ($(TEST_DEBUG),1)
60 VENV_RUN_DIR:=$(VENV_PATH)/run-debug
62 VENV_RUN_DIR:=$(VENV_PATH)/run
68 PYTHON_INTERP=$(PYTHON)
75 PYTHON_VERSION=$(shell $(PYTHON_INTERP) -c 'import sys; print(sys.version_info.major)')
77 # Keep in sync with requirements.txt
78 PIP_TOOLS_VERSION=6.5.0
79 PIP_SETUPTOOLS_VERSION=60.7.1
80 PYTHON_DEPENDS=requirements-$(PYTHON_VERSION).txt
81 SCAPY_SOURCE=$(shell find $(VENV_PATH)/lib/python* -name site-packages)
82 BUILD_COV_DIR=$(TEST_BR)/coverage
84 PIP_TOOLS_INSTALL_DONE=$(VENV_RUN_DIR)/pip-tools-install-$(PYTHON_VERSION)-$(PIP_TOOLS_VERSION).done
85 PIP_INSTALL_DONE=$(VENV_RUN_DIR)/pip-install-$(PYTHON_VERSION)-$(PIP_VERSION).done
86 PIP_PATCH_DONE=$(VENV_RUN_DIR)/pip-patch-$(PYTHON_VERSION).done
87 PAPI_INSTALL_DONE=$(VENV_RUN_DIR)/papi-install-$(PYTHON_VERSION).done
88 PAPI_PYTHON_SRC_DIR=$(WS_ROOT)/src/vpp-api/python
89 PAPI_WIPE_DIST=$(WS_ROOT)/src/vpp-api/vapi/__pycache__ \
90 $(PAPI_PYTHON_SRC_DIR)/build \
91 $(PAPI_PYTHON_SRC_DIR)/vpp_papi.egg-info \
92 $(PAPI_PYTHON_SRC_DIR)/vpp_papi/__pycache__
94 $(PIP_TOOLS_INSTALL_DONE):
96 @mkdir -p $(VENV_RUN_DIR)
97 @$(PYTHON_INTERP) -m venv $(VENV_PATH)
99 @bash -c "source $(VENV_PATH)/bin/activate && \
100 python3 -m pip install pip===$(PIP_VERSION)"
101 @bash -c "source $(VENV_PATH)/bin/activate && \
102 python3 -m pip install pip-tools===$(PIP_TOOLS_VERSION)"
103 @bash -c "source $(VENV_PATH)/bin/activate && \
104 python3 -m pip install setuptools===$(PIP_SETUPTOOLS_VERSION)"
107 $(PYTHON_DEPENDS): requirements.txt
108 @bash -c "source $(VENV_PATH)/bin/activate && \
109 CUSTOM_COMPILE_COMMAND='make test-refresh-deps (or update requirements.txt)' \
110 python3 -m piptools compile -q --generate-hashes requirements.txt --output-file $@"
112 $(PIP_INSTALL_DONE): $(PIP_TOOLS_INSTALL_DONE) $(PYTHON_DEPENDS)
113 @bash -c "source $(VENV_PATH)/bin/activate && \
114 python3 -m piptools sync $(PYTHON_DEPENDS)"
117 $(PIP_PATCH_DONE): $(PIP_INSTALL_DONE)
118 @echo --- patching ---
119 @sleep 1 # Ensure python recompiles patched *.py files -> *.pyc
120 for f in $(CURDIR)/patches/scapy-2.4.3/*.patch ; do \
121 echo Applying patch: $$(basename $$f) ; \
122 patch --forward -p1 -d $(SCAPY_SOURCE) < $$f ; \
124 [ $$retCode -gt 1 ] && exit $$retCode; \
128 $(PAPI_INSTALL_DONE): $(PIP_PATCH_DONE)
129 @bash -c "source $(VENV_PATH)/bin/activate && python3 -m pip install -e $(PAPI_PYTHON_SRC_DIR)"
133 refresh-deps: clean-deps $(PYTHON_DEPENDS)
137 @rm -f $(PYTHON_DEPENDS)
139 INTERN_PLUGIN_SRC_DIR=$(WS_ROOT)/src/plugins
140 ifneq ($(EXTERN_PLUGIN_SRC_DIR),)
141 PLUGIN_SRC_DIR=$(EXTERN_PLUGIN_SRC_DIR)
143 PLUGIN_SRC_DIR=$(INTERN_PLUGIN_SRC_DIR)
151 else ifeq ($(FORCE_FOREGROUND),0)
153 else ifneq ($(findstring $(TEST_JOBS),1 auto),)
163 ifneq ($(findstring $(SANITY),0 n no),)
164 SANITY_IMPORT_VPP_PAPI_CMD=true
167 SANITY_IMPORT_VPP_PAPI_CMD=source $(VENV_PATH)/bin/activate && $(PYTHON_INTERP) sanity_import_vpp_papi.py
172 ifneq ($(findstring $(FAILFAST),1 y yes),)
177 ifneq ($(findstring $(EXTENDED_TESTS),1 y yes),)
182 ifneq ($(EXTERN_TESTS),)
183 ARG3=--test-src-dir $(EXTERN_TESTS)
187 ifneq ($(findstring $(FORCE_FOREGROUND),1 y yes),)
188 ARG4=--force-foreground
192 ifneq ($(findstring $(COREDUMP_COMPRESS),1 y yes),)
197 ifneq ($(findstring $(STEP),1 y yes),)
202 ifneq ($(findstring $(TESTS_GCOV),1 y yes),)
207 ifneq ($(EXTERN_PLUGINS),)
208 ARG8=--extern-plugin-dir=$(EXTERN_PLUGINS)
213 ARG9=--debug=$(DEBUG)
217 ifneq ($(COREDUMP_SIZE),)
218 ARG10=--coredump-size=$(COREDUMP_SIZE)
223 ARG11=--variant=$(VARIANT)
226 ARG12=--cache-vpp-output
227 ifneq ($(findstring $(CACHE_OUTPUT),0 n no),)
232 ifneq ($(MAX_VPP_CPUS),)
233 ARG13=--max-vpp-cpus=$(MAX_VPP_CPUS)
238 ARG14=--timeout=$(TIMEOUT)
242 ifneq ($(findstring $(TEST_DEBUG),1 y yes),)
243 ARG15=--debug-framework
247 ifneq ($(findstring $(API_FUZZ),1 y yes),)
251 EXTRA_ARGS=$(ARG0) $(ARG1) $(ARG2) $(ARG3) $(ARG4) $(ARG5) $(ARG6) $(ARG7) $(ARG8) $(ARG9) $(ARG10) $(ARG11) $(ARG12) $(ARG13) $(ARG14) $(ARG15) $(ARG16)
253 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) $(TEST_PLUGIN_PATH_ARGS) $(EXTRA_ARGS)
254 RUN_SCRIPT_ARGS=--python-opts=$(PYTHON_OPTS)
257 @scripts/run.sh $(RUN_SCRIPT_ARGS) $(RUN_TESTS_ARGS) || env FAILED_DIR=$(FAILED_DIR) COMPRESS_FAILED_TEST_LOGS=$(COMPRESS_FAILED_TEST_LOGS) scripts/compress_failed.sh
261 @bash -c "test $(PARALLEL_ILLEGAL) -eq 0 ||\
262 (echo \"*******************************************************************\" &&\
263 echo \"* Sanity check failed, TEST_JOBS is not 1 or 'auto' and DEBUG, STEP or PROFILE is set\" &&\
264 echo \"*******************************************************************\" &&\
266 @bash -c "$(SANITY_IMPORT_VPP_PAPI_CMD) ||\
267 (echo \"*******************************************************************\" &&\
268 echo \"* Sanity check failed, cannot import vpp_papi\" &&\
269 echo \"* to debug: \" &&\
270 echo \"* 1. enter test shell: make test-shell\" &&\
271 echo \"* 2. execute debugger: gdb python -ex 'run sanity_import_vpp_papi.py'\" &&\
272 echo \"*******************************************************************\" &&\
279 test-dep: $(PAPI_INSTALL_DONE) $(FAILED_DIR)
282 test: test-dep sanity
286 retest: verify-env sanity $(FAILED_DIR)
291 @echo "source $(VENV_PATH)/bin/activate;\
292 export RND_SEED=$(RND_SEED);\
294 echo PYTHONPATH=$(PYTHONPATH);\
295 echo RND_SEED=$(RND_SEED);\
296 echo VPP_BUILD_DIR=$(VPP_BUILD_DIR);\
297 echo VPP_PLUGIN_PATH=$(VPP_PLUGIN_PATH);\
298 echo VPP_TEST_PLUGIN_PATH=$(VPP_TEST_PLUGIN_PATH);\
299 echo VPP_INSTALL_PATH=$(VPP_INSTALL_PATH);\
300 echo EXTERN_TESTS=$(EXTERN_TESTS);\
301 echo EXTERN_PLUGINS=$(EXTERN_PLUGINS);\
302 echo EXTERN_COV_DIR=$(EXTERN_COV_DIR);\
303 echo LD_LIBRARY_PATH=$(LD_LIBRARY_PATH);\
305 exec </dev/tty" | bash -i
309 @rm -f /dev/shm/vpp-unittest-*
310 @if [ $(FORCE_NO_WIPE) -eq "0" ] ; then rm -rf /tmp/vpp-unittest-*; fi
311 @rm -f /tmp/api_post_mortem.*
312 @rm -rf $(FAILED_DIR)
317 @rm -rf $(patsubst %,%/__pycache__, $(VPP_TEST_DIRS))
323 cov: wipe-cov test-dep ext $(BUILD_COV_DIR)
324 @lcov --zerocounters --directory $(VPP_BUILD_DIR)
325 @test -z "$(EXTERN_COV_DIR)" || lcov --zerocounters --directory $(EXTERN_COV_DIR)
327 @lcov --capture --directory $(VPP_BUILD_DIR) --output-file $(BUILD_COV_DIR)/coverage.info
328 @test -z "$(EXTERN_COV_DIR)" || lcov --capture --directory $(EXTERN_COV_DIR) --output-file $(BUILD_COV_DIR)/extern-coverage.info
329 @genhtml $(BUILD_COV_DIR)/coverage.info --output-directory $(BUILD_COV_DIR)/html
330 @test -z "$(EXTERN_COV_DIR)" || genhtml $(BUILD_COV_DIR)/extern-coverage.info --output-directory $(BUILD_COV_DIR)/extern-html
332 @echo "Build finished. Code coverage report is in $(BUILD_COV_DIR)/html/index.html"
333 @test -z "$(EXTERN_COV_DIR)" || echo "Code coverage report for out-of-tree objects is in $(BUILD_COV_DIR)/extern-html/index.html"
337 @rm -rf $(BUILD_COV_DIR)
341 @rm -rf $(PAPI_INSTALL_DONE) $(PAPI_WIPE_DIST)
344 wipe-all: wipe wipe-papi wipe-cov
347 .PHONY: checkstyle-diff
348 checkstyle-diff: $(PIP_INSTALL_DONE)
349 @bash -c "source $(VENV_PATH)/bin/activate &&\
350 python3 -m pip install pycodestyle"
351 @bash -c "source $(VENV_PATH)/bin/activate &&\
352 cd $(WS_ROOT) && git diff --name-only --no-color --relative HEAD~1 ':!*.patch' | grep '.py$$' | xargs -I XXX \
353 pycodestyle --show-source --ignore=W504,E126,E241,E226,E305,E704,E741,E722 -v XXX ||\
354 (echo \"*********************************************************************\" &&\
355 echo \"* Test framework PEP8 compliance check FAILED (checked changed files)\" &&\
356 echo \"*********************************************************************\" &&\
358 @echo "*********************************************************************"
359 @echo "* Test framework PEP8 compliance check passed (checked changed files)"
360 @echo "*********************************************************************"
364 @bash -c "source $(VENV_PATH)/bin/activate && python3 -c 'from debug import start_vpp_in_gdb; start_vpp_in_gdb()' $(RUN_TESTS_ARGS)"
367 checkstyle: $(PIP_INSTALL_DONE)
368 @bash -c "source $(VENV_PATH)/bin/activate &&\
369 python3 -m pip install pycodestyle"
370 @bash -c "source $(VENV_PATH)/bin/activate &&\
371 pycodestyle --show-source --ignore=W504,E126,E241,E226,E305,E704,E741,E722 -v *.py ||\
372 (echo \"*******************************************************************\" &&\
373 echo \"* Test framework PEP8 compliance check FAILED (checked all files)\" &&\
374 echo \"*******************************************************************\" &&\
376 @echo "*******************************************************************"
377 @echo "* Test framework PEP8 compliance check passed (checked all files)"
378 @echo "*******************************************************************"
382 @echo "Running tests:"
384 @echo " test - build and run (basic) functional tests"
385 @echo " test-debug - build and run (basic) functional tests (debug build)"
386 @echo " test-all - build and run functional and extended tests"
387 @echo " test-all-debug - build and run functional and extended tests (debug build)"
388 @echo " retest - run functional tests"
389 @echo " retest-debug - run functional tests (debug build)"
390 @echo " retest-all - run functional and extended tests"
391 @echo " retest-all-debug - run functional and extended tests (debug build)"
392 @echo " test-cov - generate code coverage report for test framework"
393 @echo " test-gcov - build and run functional tests (gcov build)"
394 @echo " test-wipe - wipe (temporary) files generated by unit tests"
395 @echo " test-wipe-cov - wipe code coverage report for test framework"
396 @echo " test-wipe-papi - rebuild vpp_papi sources"
397 @echo " test-wipe-all - wipe (temporary) files generated by unit tests, and coverage"
398 @echo " test-shell - enter shell with test environment"
399 @echo " test-shell-debug - enter shell with test environment (debug build)"
400 @echo " test-checkstyle - check PEP8 compliance for test framework"
401 @echo " test-refresh-deps - refresh the Python dependencies for the tests"
403 @echo "Arguments controlling test runs:"
405 @echo " V=[0|1|2] - set test verbosity level"
406 @echo " 0=ERROR, 1=INFO, 2=DEBUG"
407 @echo " TEST_JOBS=[<n>|auto] - use at most <n> parallel python processes for test execution, if auto, set to number of available cpus (default: 1)"
408 @echo " MAX_VPP_CPUS=[<n>|auto]- use at most <n> cpus for running vpp main and worker threads, if auto, set to number of available cpus (default: auto)"
409 @echo " CACHE_OUTPUT=[0|n|no] - disable cache VPP stdout/stderr and log as one block after test finishes (default: yes)"
410 @echo " FAILFAST=[1|y|yes] - fail fast if 1, otherwise complete all tests"
411 @echo " TIMEOUT=<timeout> - fail test suite if any single test takes longer than <timeout> (in seconds) to finish (default: 600)"
412 @echo " RETRIES=<n> - retry failed tests <n> times"
413 @echo " DEBUG=<type> - set VPP debugging kind"
414 @echo " DEBUG=core - detect coredump and load it in gdb on crash"
415 @echo " DEBUG=gdb - allow easy debugging by printing VPP PID"
416 @echo " and waiting for user input before running"
417 @echo " and tearing down a testcase"
418 @echo " DEBUG=gdbserver - run gdb inside a gdb server, otherwise"
419 @echo " same as above"
420 @echo " DEBUG=attach - attach test case to already running vpp in gdb (see test-start-vpp-in-gdb)"
421 @echo " STEP=[1|y|yes] - enable stepping through a testcase (for testcase debugging)"
422 @echo " SANITY=[0|n|no] - disable sanity import of vpp-api/sanity vpp run before running tests"
423 @echo " EXTENDED_TESTS=[1|y|yes] - run extended tests"
424 @echo " TEST=<filter> - filter the set of tests:"
425 @echo " by file-name - only run tests from specified file, e.g. TEST=test_bfd selects all tests from test_bfd.py"
426 @echo " by file-suffix - same as file-name, but 'test_' is omitted e.g. TEST=bfd selects all tests from test_bfd.py"
427 @echo " by wildcard - wildcard filter is <file>.<class>.<test function>, each can be replaced by '*'"
428 @echo " e.g. TEST='test_bfd.*.*' is equivalent to above example of filter by file-name"
429 @echo " TEST='bfd.*.*' is equivalent to above example of filter by file-suffix"
430 @echo " TEST='bfd.BFDAPITestCase.*' selects all tests from test_bfd.py which are part of BFDAPITestCase class"
431 @echo " TEST='bfd.BFDAPITestCase.test_add_bfd' selects a single test named test_add_bfd from test_bfd.py/BFDAPITestCase"
432 @echo " TEST='*.*.test_add_bfd' selects all test functions named test_add_bfd from all files/classes"
433 @echo " VARIANT=<variant> - specify which march node variant to unit test"
434 @echo " e.g. VARIANT=skx test the skx march variants"
435 @echo " e.g. VARIANT=icl test the icl march variants"
436 @echo " COREDUMP_SIZE=<size> - pass <size> as unix { coredump-size <size> } argument to vpp"
437 @echo " e.g. COREDUMP_SIZE=4g"
438 @echo " COREDUMP_SIZE=unlimited"
439 @echo " COREDUMP_COMPRESS=[1|y|yes] - compress core files if not debugging them"
440 @echo " EXTERN_TESTS=<path> - path to out-of-tree test_<name>.py files containing test cases"
441 @echo " EXTERN_PLUGINS=<path> - path to out-of-tree plugins to be loaded by vpp under test"
442 @echo " EXTERN_COV_DIR=<path> - path to out-of-tree prefix, where source, object and .gcda files can be found for coverage report"
443 @echo " PROFILE=[1|y|yes] - enable profiling of test framework via cProfile module"
444 @echo " PROFILE_SORT_BY=opt - sort profiling report by opt - consult cProfile documentation for possible values (default: cumtime)"
445 @echo " PROFILE_OUTPUT=file - output profiling info to file - use absolute path (default: stdout)"
446 @echo " TEST_DEBUG=[1|y|yes] - enable debugging of the test framework itself (expert)"
447 @echo " API_FUZZ=[1|y|yes] - enable VPP api fuzz testing"
448 @echo " RND_SEED=<seed> - Seed RND with given seed"
450 @echo "Starting VPP in GDB for use with DEBUG=attach:"
452 @echo " test-start-vpp-in-gdb - start VPP in gdb (release)"
453 @echo " test-start-vpp-debug-in-gdb - start VPP in gdb (debug)"
455 @echo "Creating test code coverage report:"
457 @echo " test-cov - generate code coverage report for test framework"
458 @echo " test-wipe-cov - wipe code coverage report for test framework"
460 @echo "Verifying code-style:"
462 @echo " test-checkstyle - check PEP8 compliance"