# Author: Alecsandru Patrascu diff -r d7b5c2f99a99 Makefile.pre.in --- a/Makefile.pre.in Mon Dec 21 11:43:03 2015 -0600 +++ b/Makefile.pre.in Tue Dec 22 11:19:18 2015 +0200 @@ -211,6 +211,11 @@ # The task to run while instrument when building the profile-opt target PROFILE_TASK=-m test.regrtest --pgo +# report files for gcov / lcov coverage report +COVERAGE_INFO= $(abs_builddir)/coverage.info +COVERAGE_REPORT=$(abs_builddir)/lcov-report +COVERAGE_REPORT_OPTIONS=--no-branch-coverage --title "CPython lcov report" + # === Definitions added by makesetup === @@ -457,11 +462,49 @@ build_all_use_profile: $(MAKE) all CFLAGS="$(CFLAGS) $(PGO_PROF_USE_FLAG)" +# Compile and run with gcov +.PHONY=coverage coverage-lcov coverage-report coverage: @echo "Building with support for coverage checking:" - $(MAKE) clean + $(MAKE) clean profile-removal $(MAKE) all CFLAGS="$(CFLAGS) -O0 -pg -fprofile-arcs -ftest-coverage" LIBS="$(LIBS) -lgcov" +coverage-lcov: + @echo "Creating Coverage HTML report with LCOV:" + @rm -f $(COVERAGE_INFO) + @rm -rf $(COVERAGE_REPORT) + @lcov --capture --directory $(abs_builddir) \ + --base-directory $(realpath $(abs_builddir)) \ + --path $(realpath $(abs_srcdir)) \ + --output-file $(COVERAGE_INFO) + : # remove 3rd party modules and system headers + @lcov --remove $(COVERAGE_INFO) \ + '*/Modules/_ctypes/libffi*/*' \ + '*/Modules/_decimal/libmpdec/*' \ + '*/Modules/expat/*' \ + '*/Modules/zlib/*' \ + '*/Include/*' \ + '/usr/include/*' \ + '/usr/local/include/*' \ + --output-file $(COVERAGE_INFO) + @genhtml $(COVERAGE_INFO) --output-directory $(COVERAGE_REPORT) \ + $(COVERAGE_REPORT_OPTIONS) + @echo + @echo "lcov report at $(COVERAGE_REPORT)/index.html" + @echo + +coverage-report: + : # force rebuilding of parser and importlib + @touch $(GRAMMAR_INPUT) + @touch $(srcdir)/Lib/importlib/_bootstrap.py + @touch $(srcdir)/Lib/importlib/_bootstrap_external.py + : # build with coverage info + $(MAKE) coverage + : # run tests, ignore failures + $(TESTPYTHON) $(TESTPROG) || true + : # build lcov report + $(MAKE) coverage-lcov + # Build the interpreter $(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY)