make test: improve documentation and PEP8 compliance
[vpp.git] / test / Makefile
index 63cee20..543fe91 100644 (file)
@@ -6,31 +6,77 @@ ifndef VPP_PYTHON_PREFIX
 endif
 
 PYTHON_VENV_PATH=$(VPP_PYTHON_PREFIX)/virtualenv
+PYTHON_DEPENDS=scapy==2.3.3 pexpect
+SCAPY_SOURCE=$(PYTHON_VENV_PATH)/lib/python2.7/site-packages/
+BUILD_COV_DIR = $(BR)/test-cov
 
-test: wipe verify-python-path
-       @virtualenv $(PYTHON_VENV_PATH)
-       @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && pip install scapy"
-       @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && pip install pexpect"
-       @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\""
+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
+
+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_DONE): $(PIP_INSTALL_DONE)
+       @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 $@
 
-retest: wipe verify-python-path
+$(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 $@
+
+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
+       $(call retest-func)
 
 .PHONY: wipe doc
 
-wipe: verify-python-path
+reset:
        @rm -f /dev/shm/vpp-unittest-*
        @rm -rf /tmp/vpp-unittest-*
 
+wipe: reset
+       @rm -rf $(PYTHON_VENV_PATH)
+       @rm -f $(PAPI_INSTALL_FLAGS)
+
 doc: verify-python-path
-       @virtualenv $(PYTHON_VENV_PATH)
-       @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && pip install sphinx"
+       @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 ""
@@ -38,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"
@@ -54,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 ""