Add make test code coverage reporting using gcov
[vpp.git] / test / Makefile
index aac637d..7561a00 100644 (file)
@@ -6,23 +6,50 @@ ifndef VPP_PYTHON_PREFIX
 endif
 
 PYTHON_VENV_PATH=$(VPP_PYTHON_PREFIX)/virtualenv
-PYTHON_DEPENDS=scapy pexpect
+PYTHON_DEPENDS=scapy==2.3.3 pexpect
+SCAPY_SOURCE=$(WS_ROOT)/build-root/python/virtualenv/lib/python2.7/site-packages/
+BUILD_COV_DIR = $(BR)/test-cov
 
-test: wipe verify-python-path
+
+.pip-install.ok:
        @virtualenv $(PYTHON_VENV_PATH)
        @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && pip install $(PYTHON_DEPENDS)"
+       @touch $@
+
+.pip-patch.ok: .pip-install.ok
+       @echo --- patching ---
+       for f in $(CURDIR)/patches/scapy-2.3.3/*.patch ; do \
+               echo Applying patch: $$(basename $$f) ; \
+               patch -p1 -d $(SCAPY_SOURCE) < $$f ; \
+       done
+       @touch $@
+
+.install.ok: .pip-patch.ok
        @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && cd $(WS_ROOT)/vpp-api/python && python setup.py install"
-       @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && python run_tests.py discover -p test_$(TEST)\"*.py\""
+       @touch $@
+
+PHONIES=.install.ok .pip-patch.ok .pip-install.ok
+.PHONY: $(PHONIES)
 
-retest: wipe verify-python-path
+define retest-func
        @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && python run_tests.py discover -p test_$(TEST)\"*.py\""
+endef
+
+test: reset verify-python-path .install.ok
+       $(call retest-func)
+
+retest: reset verify-python-path
+       $(call retest-func)
 
 .PHONY: wipe doc
 
-wipe:
+reset:
        @rm -f /dev/shm/vpp-unittest-*
        @rm -rf /tmp/vpp-unittest-*
 
+wipe: reset
+       @rm -f $(PHONIES)
+
 doc: verify-python-path
        @virtualenv $(PYTHON_VENV_PATH)
        @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && pip install $(PYTHON_DEPENDS) sphinx"
@@ -31,6 +58,18 @@ doc: verify-python-path
 wipe-doc:
        @make -C doc wipe BR=$(BR)
 
+cov: wipe-cov reset verify-python-path .install.ok
+       @lcov --zerocounters --directory $(VPP_TEST_BUILD_DIR)
+       $(call retest-func)
+       @mkdir $(BUILD_COV_DIR)
+       @lcov --capture --directory $(VPP_TEST_BUILD_DIR) --output-file $(BUILD_COV_DIR)/coverage.info
+       @genhtml $(BUILD_COV_DIR)/coverage.info --output-directory $(BUILD_COV_DIR)/html
+       @echo
+       @echo "Build finished. Code coverage report is in $(BUILD_COV_DIR)/html/index.html"
+
+wipe-cov: wipe
+       @rm -rf $(BUILD_COV_DIR)
+
 help:
        @echo "Running tests:"
        @echo ""
@@ -38,7 +77,7 @@ help:
        @echo " test-debug          - build and run functional tests (debug build)"
        @echo " retest              - run functional tests"
        @echo " retest-debug        - run functional tests (debug build)"
-       @echo " wipe-test           - wipe (temporary) files generated by unit tests"
+       @echo " test-wipe           - wipe (temporary) files generated by unit tests"
        @echo ""
        @echo "Arguments controlling test runs:"
        @echo " V=[0|1|2]            - set test verbosity level"
@@ -54,5 +93,9 @@ help:
        @echo ""
        @echo "Creating test documentation"
        @echo " test-doc            - generate documentation for test framework"
-       @echo " wipe-test-doc       - wipe documentation for test framework"
+       @echo " test-wipe-doc       - wipe documentation for test framework"
+       @echo ""
+       @echo "Creating test code coverage report"
+       @echo " test-cov            - generate code coverage report for test framework"
+       @echo " test-wipe-cov       - wipe code coverage report for test framework"
        @echo ""