]> granicus.if.org Git - python/commitdiff
Issue #25925: Backport C coverage reporting Makefile targets
authorZachary Ware <zachary.ware@gmail.com>
Wed, 20 Jan 2016 06:11:52 +0000 (00:11 -0600)
committerZachary Ware <zachary.ware@gmail.com>
Wed, 20 Jan 2016 06:11:52 +0000 (00:11 -0600)
Originally added by Christian Heimes in 85ec2b5bfcd2.

Initial patch for the backport by Alecsandru Patrascu.

.hgignore
Makefile.pre.in

index a9caf72a72a910bab31df7313136a3b12711c945..16662a0a284ddad798481cf3c4e0dec156e49d13 100644 (file)
--- a/.hgignore
+++ b/.hgignore
@@ -30,6 +30,7 @@ Modules/config.c
 Modules/ld_so_aix$
 Parser/pgen$
 Parser/pgen.stamp$
+^lcov-report/
 ^core
 ^python-gdb.py
 ^pybuilddir.txt
@@ -81,6 +82,10 @@ PCbuild/*.lib
 PCbuild/*.pdb
 PCbuild/amd64
 PCbuild/obj
+*.gcda
+*.gcno
+*.gcov
+coverage.info
 .coverage
 coverage/
 externals/
index b495ac90bdc10a8fa083ad7cf2733ee7a946ed22..3b43f1be8e7430b33792e7a5a798cadfa8c23bb8 100644 (file)
@@ -211,6 +211,11 @@ TCLTK_LIBS=        @TCLTK_LIBS@
 # 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,46 @@ build_all_merge_profile:
 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/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
+       @touch $(GRAMMAR_INPUT)
+       : # build with coverage info
+       $(MAKE) coverage
+       : # run tests, ignore failures
+       $(TESTPYTHON) $(TESTPROG) $(TESTOPTS) || true
+       : # build lcov report
+       $(MAKE) coverage-lcov
+
 
 # Build the interpreter
 $(BUILDPYTHON):        Modules/python.o $(LIBRARY) $(LDLIBRARY)