cpython: 85ec2b5bfcd2 (original) (raw)
Mercurial > cpython
changeset 84923:85ec2b5bfcd2
Issue #18481: Add C coverage reporting with gcov and lcov. A new make target "coverage-report" creates an instrumented Python build, runs unit tests and creates a HTML. The report can be updated with "make coverage-lcov". [#18481]
Christian Heimes christian@cheimes.de | |
---|---|
date | Wed, 31 Jul 2013 00:55:18 +0200 |
parents | 4df2e094f83e |
children | fca77bc5bdb8 |
files | .hgignore Makefile.pre.in Misc/NEWS |
diffstat | 3 files changed, 55 insertions(+), 1 deletions(-)[+] [-] .hgignore 5 Makefile.pre.in 47 Misc/NEWS 4 |
line wrap: on
line diff
--- a/.hgignore +++ b/.hgignore @@ -36,6 +36,7 @@ Modules/Setup.local Modules/config.c Modules/ld_so_aix$ Parser/pgen$ +^lcov-report/ ^core ^python-gdb.py ^python.exe-gdb.py @@ -91,3 +92,7 @@ Modules/_testembed .coverage coverage/ htmlcov/ +.gcda +.gcno +*.gcov +coverage.info
--- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -211,6 +211,12 @@ HOST_GNU_TYPE= @host@ PROFILE_TASK= $(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck #PROFILE_TASK= $(srcdir)/Lib/test/regrtest.py +# 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 ===
@@ -463,11 +469,48 @@ run_profile_task: build_all_use_profile: (MAKE)allCFLAGS="(MAKE) all CFLAGS="(MAKE)allCFLAGS="(CFLAGS) -fprofile-use -fprofile-correction" +# 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)allCFLAGS="(MAKE) all CFLAGS="(MAKE)allCFLAGS="(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) [](#l2.32) + --base-directory (realpath(realpath (realpath(abs_builddir)) [](#l2.33) + --path (realpath(realpath (realpath(abs_srcdir)) [](#l2.34) + --output-file $(COVERAGE_INFO) + : # remove 3rd party modules and system headers + @lcov --remove $(COVERAGE_INFO) [](#l2.37) + '/Modules/_ctypes/libffi/' [](#l2.38) + '/Modules/_sha3/keccak/' [](#l2.39) + '/Modules/_decimal/libmpdec/' [](#l2.40) + '/Modules/expat/' [](#l2.41) + '/Modules/zlib/' [](#l2.42) + '/Include/' [](#l2.43) + '/usr/include/' [](#l2.44) + '/usr/local/include/*' [](#l2.45) + --output-file $(COVERAGE_INFO) + @genhtml (COVERAGEINFO)−−output−directory(COVERAGE_INFO) --output-directory (COVERAGEINFO)−−output−directory(COVERAGE_REPORT) [](#l2.47) + $(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 + : # build with coverage info + $(MAKE) coverage + : # run tests, ignore failures
- (TESTRUNNER)(TESTRUNNER) (TESTRUNNER)(TESTOPTS) || true
- : # build lcov report
- $(MAKE) coverage-lcov
Build the interpreter(BUILDPYTHON):Modules/python.o(BUILDPYTHON): Modules/python.o (BUILDPYTHON):Modules/python.o(LIBRARY) (LDLIBRARY)(LDLIBRARY) (LDLIBRARY)(PY3LIBRARY) @@ -1396,6 +1439,8 @@ clean: pycremoval profile-removal: find . -name '*.gc??' -exec rm -f {} ';'
- rm -f $(COVERAGE_INFO)
- rm -rf $(COVERAGE_REPORT) clobber: clean profile-removal -rm -f (BUILDPYTHON)(BUILDPYTHON) (BUILDPYTHON)(PGEN) (LIBRARY)(LIBRARY) (LIBRARY)(LDLIBRARY) $(DLLLIBRARY) [](#l2.74)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -725,6 +725,10 @@ IDLE Build ----- +- Issue #18481: Add C coverage reporting with gcov and lcov. A new make target