From 39969d232e9d137aadae55f67a45fa2306f43df9 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 10 Aug 2017 23:33:47 -0400 Subject: [PATCH v3 1/9] Run only top-level recursive lcov This is the way lcov was intended to be used. It is much faster and more robust and makes the makefiles simpler than running it in each subdirectory. The previous coding ran gcov before lcov, but that is useless because lcov/geninfo call gcov internally and use that information. Moreover, this led to complications and failures during parallel make. This separates the two targets: You either use "make coverage" to get textual output from gcov or "make coverage-html" to get an HTML report via lcov. (Using both is still problematic because they write the same output files.) --- .gitignore | 1 + doc/src/sgml/regress.sgml | 13 +++++++++++++ src/Makefile.global.in | 28 ++++++++++++++++------------ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 4976fd9119..94e2c582f5 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ objfiles.txt *.gcov.out lcov.info coverage/ +coverage-html-stamp *.vcproj *.vcxproj win32ver.rc diff --git a/doc/src/sgml/regress.sgml b/doc/src/sgml/regress.sgml index 7c2b1029c2..14747e5f3b 100644 --- a/doc/src/sgml/regress.sgml +++ b/doc/src/sgml/regress.sgml @@ -706,6 +706,19 @@ Test Coverage Examination The make commands also work in subdirectories. + + If you don't have lcov or prefer text output over an + HTML report, you can also run + +make coverage + + instead of make coverage-html, which will + produce .gcov output files for each source file + relevant to the test. (make coverage and make + coverage-html will overwrite each other's files, so mixing them + might be confusing.) + + To reset the execution counts between test runs, run: diff --git a/src/Makefile.global.in b/src/Makefile.global.in index fae8068150..f352ba20e2 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -874,25 +874,29 @@ endif # enable_nls ifeq ($(enable_coverage), yes) -# There is a strange interaction between lcov and existing .gcov -# output files. Hence the rm command and the ordering dependency. +# make coverage -- text output -gcda_files := $(wildcard *.gcda) +local_gcda_files = $(wildcard *.gcda) -lcov.info: $(gcda_files) - rm -f *.gcov .*.gcov - $(if $^,$(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV)) +coverage: $(local_gcda_files:.gcda=.c.gcov) -%.c.gcov: %.gcda | lcov.info +%.c.gcov: %.gcda $(GCOV) -b -f -p -o . $(GCOVFLAGS) $*.c >$*.c.gcov.out -coverage: $(gcda_files:.gcda=.c.gcov) lcov.info +# make coverage-html -- HTML output via lcov .PHONY: coverage-html -coverage-html: coverage +coverage-html: coverage-html-stamp + +coverage-html-stamp: lcov.info rm -rf coverage - mkdir coverage - $(GENHTML) --show-details --legend --output-directory=coverage --title=PostgreSQL --num-spaces=4 --prefix=$(abs_top_srcdir) `find . -name lcov.info -print` + $(GENHTML) --show-details --legend --output-directory=coverage --title=PostgreSQL --num-spaces=4 --prefix=$(abs_top_srcdir) $< + touch $@ + +all_gcda_files = $(shell find . -name '*.gcda' -print) + +lcov.info: $(all_gcda_files) + $(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV) # hook for clean-up @@ -900,7 +904,7 @@ clean distclean maintainer-clean: clean-coverage .PHONY: clean-coverage clean-coverage: - rm -rf coverage + rm -rf coverage coverage-html-stamp rm -f *.gcda *.gcno lcov.info *.gcov .*.gcov *.gcov.out base-commit: d42294fc00da4b97d04ddb4401b76295e8d86816 -- 2.14.1