make test: improve documentation and PEP8 compliance
[vpp.git] / test / Makefile
index de6aaa7..543fe91 100644 (file)
@@ -7,15 +7,21 @@ endif
 
 PYTHON_VENV_PATH=$(VPP_PYTHON_PREFIX)/virtualenv
 PYTHON_DEPENDS=scapy==2.3.3 pexpect
-SCAPY_SOURCE=$(WS_ROOT)/build-root/python/virtualenv/lib/python2.7/site-packages/
+SCAPY_SOURCE=$(PYTHON_VENV_PATH)/lib/python2.7/site-packages/
+BUILD_COV_DIR = $(BR)/test-cov
 
+PIP_INSTALL_DONE=$(VPP_PYTHON_PREFIX)/pip-install.done
+PIP_PATCH_DONE=$(VPP_PYTHON_PREFIX)/pip-patch.done
+PAPI_INSTALL_DONE=$(VPP_PYTHON_PREFIX)/papi-install.done
 
-.pip-install.ok:
-       @virtualenv $(PYTHON_VENV_PATH)
+PAPI_INSTALL_FLAGS=$(PIP_INSTALL_DONE) $(PIP_PATCH_DONE) $(PAPI_INSTALL_DONE)
+
+$(PIP_INSTALL_DONE):
+       @virtualenv $(PYTHON_VENV_PATH) -p python2.7
        @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && pip install $(PYTHON_DEPENDS)"
        @touch $@
 
-.pip-patch.ok: .pip-install.ok
+$(PIP_PATCH_DONE): $(PIP_INSTALL_DONE)
        @echo --- patching ---
        for f in $(CURDIR)/patches/scapy-2.3.3/*.patch ; do \
                echo Applying patch: $$(basename $$f) ; \
@@ -23,18 +29,19 @@ SCAPY_SOURCE=$(WS_ROOT)/build-root/python/virtualenv/lib/python2.7/site-packages
        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"
+$(PAPI_INSTALL_DONE): $(PIP_PATCH_DONE)
+       @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && cd $(WS_ROOT)/src/vpp-api/python && python setup.py install"
        @touch $@
 
-PHONIES=.install.ok .pip-patch.ok .pip-install.ok
-.PHONY: $(PHONIES)
-
-test: reset verify-python-path .install.ok
+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 $(PAPI_INSTALL_DONE)
+       $(call retest-func)
 
 retest: reset verify-python-path
-       @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && python run_tests.py discover -p test_$(TEST)\"*.py\""
+       $(call retest-func)
 
 .PHONY: wipe doc
 
@@ -43,16 +50,33 @@ reset:
        @rm -rf /tmp/vpp-unittest-*
 
 wipe: reset
-       @rm -f $(PHONIES)
+       @rm -rf $(PYTHON_VENV_PATH)
+       @rm -f $(PAPI_INSTALL_FLAGS)
 
 doc: verify-python-path
-       @virtualenv $(PYTHON_VENV_PATH)
+       @virtualenv $(PYTHON_VENV_PATH) -p python2.7
        @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && pip install $(PYTHON_DEPENDS) sphinx"
        @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && make -C doc WS_ROOT=$(WS_ROOT) BR=$(BR) NO_VPP_PAPI=1 html"
 
+.PHONY: wipe-doc
+
 wipe-doc:
        @make -C doc wipe BR=$(BR)
 
+cov: wipe-cov reset verify-python-path $(PAPI_INSTALL_DONE)
+       @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"
+
+.PHONY: wipe-cov
+
+wipe-cov: wipe
+       @rm -rf $(BUILD_COV_DIR)
+
 help:
        @echo "Running tests:"
        @echo ""
@@ -60,7 +84,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"
@@ -76,5 +100,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 ""