make test: improve documentation and PEP8 compliance
[vpp.git] / test / Makefile
1 .PHONY: verify-python-path
2
3 verify-python-path:
4 ifndef VPP_PYTHON_PREFIX
5         $(error VPP_PYTHON_PREFIX is not set)
6 endif
7
8 PYTHON_VENV_PATH=$(VPP_PYTHON_PREFIX)/virtualenv
9 PYTHON_DEPENDS=scapy==2.3.3 pexpect
10 SCAPY_SOURCE=$(PYTHON_VENV_PATH)/lib/python2.7/site-packages/
11 BUILD_COV_DIR = $(BR)/test-cov
12
13 PIP_INSTALL_DONE=$(VPP_PYTHON_PREFIX)/pip-install.done
14 PIP_PATCH_DONE=$(VPP_PYTHON_PREFIX)/pip-patch.done
15 PAPI_INSTALL_DONE=$(VPP_PYTHON_PREFIX)/papi-install.done
16
17 PAPI_INSTALL_FLAGS=$(PIP_INSTALL_DONE) $(PIP_PATCH_DONE) $(PAPI_INSTALL_DONE)
18
19 $(PIP_INSTALL_DONE):
20         @virtualenv $(PYTHON_VENV_PATH) -p python2.7
21         @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && pip install $(PYTHON_DEPENDS)"
22         @touch $@
23
24 $(PIP_PATCH_DONE): $(PIP_INSTALL_DONE)
25         @echo --- patching ---
26         for f in $(CURDIR)/patches/scapy-2.3.3/*.patch ; do \
27                 echo Applying patch: $$(basename $$f) ; \
28                 patch -p1 -d $(SCAPY_SOURCE) < $$f ; \
29         done
30         @touch $@
31
32 $(PAPI_INSTALL_DONE): $(PIP_PATCH_DONE)
33         @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && cd $(WS_ROOT)/src/vpp-api/python && python setup.py install"
34         @touch $@
35
36 define retest-func
37         @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && python run_tests.py discover -p test_$(TEST)\"*.py\""
38 endef
39
40 test: reset verify-python-path $(PAPI_INSTALL_DONE)
41         $(call retest-func)
42
43 retest: reset verify-python-path
44         $(call retest-func)
45
46 .PHONY: wipe doc
47
48 reset:
49         @rm -f /dev/shm/vpp-unittest-*
50         @rm -rf /tmp/vpp-unittest-*
51
52 wipe: reset
53         @rm -rf $(PYTHON_VENV_PATH)
54         @rm -f $(PAPI_INSTALL_FLAGS)
55
56 doc: verify-python-path
57         @virtualenv $(PYTHON_VENV_PATH) -p python2.7
58         @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && pip install $(PYTHON_DEPENDS) sphinx"
59         @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && make -C doc WS_ROOT=$(WS_ROOT) BR=$(BR) NO_VPP_PAPI=1 html"
60
61 .PHONY: wipe-doc
62
63 wipe-doc:
64         @make -C doc wipe BR=$(BR)
65
66 cov: wipe-cov reset verify-python-path $(PAPI_INSTALL_DONE)
67         @lcov --zerocounters --directory $(VPP_TEST_BUILD_DIR)
68         $(call retest-func)
69         @mkdir $(BUILD_COV_DIR)
70         @lcov --capture --directory $(VPP_TEST_BUILD_DIR) --output-file $(BUILD_COV_DIR)/coverage.info
71         @genhtml $(BUILD_COV_DIR)/coverage.info --output-directory $(BUILD_COV_DIR)/html
72         @echo
73         @echo "Build finished. Code coverage report is in $(BUILD_COV_DIR)/html/index.html"
74
75 .PHONY: wipe-cov
76
77 wipe-cov: wipe
78         @rm -rf $(BUILD_COV_DIR)
79
80 help:
81         @echo "Running tests:"
82         @echo ""
83         @echo " test                - build and run functional tests"
84         @echo " test-debug          - build and run functional tests (debug build)"
85         @echo " retest              - run functional tests"
86         @echo " retest-debug        - run functional tests (debug build)"
87         @echo " test-wipe           - wipe (temporary) files generated by unit tests"
88         @echo ""
89         @echo "Arguments controlling test runs:"
90         @echo " V=[0|1|2]            - set test verbosity level"
91         @echo " DEBUG=<type>         - set VPP debugging kind"
92         @echo "    DEBUG=core        - detect coredump and load it in gdb on crash"
93         @echo "    DEBUG=gdb         - allow easy debugging by printing VPP PID "
94         @echo "                        and waiting for user input before running "
95         @echo "                        and tearing down a testcase"
96         @echo "    DEBUG=gdbserver   - run gdb inside a gdb server, otherwise "
97         @echo "                        same as above"
98         @echo " STEP=[yes|no]        - ease debugging by stepping through a testcase "
99         @echo " TEST=<name>          - only run specific test"
100         @echo ""
101         @echo "Creating test documentation"
102         @echo " test-doc            - generate documentation for test framework"
103         @echo " test-wipe-doc       - wipe documentation for test framework"
104         @echo ""
105         @echo "Creating test code coverage report"
106         @echo " test-cov            - generate code coverage report for test framework"
107         @echo " test-wipe-cov       - wipe code coverage report for test framework"
108         @echo ""