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