Add lcov --initial
authorPeter Eisentraut <[email protected]>
Fri, 11 Aug 2017 03:33:47 +0000 (23:33 -0400)
committerPeter Eisentraut <[email protected]>
Fri, 29 Sep 2017 12:54:34 +0000 (08:54 -0400)
By just running lcov on the produced .gcda data files, we don't account
for source files that are not touched by tests at all.  To fix that, run
lcov --initial to create a base line info file with all zero counters,
and merge that with the actual counters when creating the final report.

Reviewed-by: Michael Paquier <[email protected]>
.gitignore
src/Makefile.global.in

index 94e2c582f513385c78a433ecea0e7952919b24df..a59e3da3bef682406d604d44e6e948cd8593ede7 100644 (file)
@@ -21,7 +21,7 @@ objfiles.txt
 *.gcda
 *.gcov
 *.gcov.out
-lcov.info
+lcov*.info
 coverage/
 coverage-html-stamp
 *.vcproj
index 2b22f0de2997fb72a5e4fcbec4ed6a477c095c95..c0a88c915270292495ab88f62af368a0a656fa36 100644 (file)
@@ -869,8 +869,13 @@ endif # enable_nls
 #      gcov from foo.gcda (by "make coverage")
 #   foo.c.gcov.out  stdout captured when foo.c.gcov is created, mildly
 #      interesting
-#   lcov.info  lcov tracefile, built from gcda files in one directory,
+#   lcov_test.info
+#      lcov tracefile, built from gcda files in one directory,
 #      later collected by "make coverage-html"
+#   lcov_base.info
+#      tracefile for zero counters for every file, so that
+#      even files that are not touched by tests are counted
+#      for the overall coverage rate
 
 ifeq ($(enable_coverage), yes)
 
@@ -888,15 +893,23 @@ coverage: $(local_gcda_files:.gcda=.c.gcov)
 .PHONY: coverage-html
 coverage-html: coverage-html-stamp
 
-coverage-html-stamp: lcov.info
+coverage-html-stamp: lcov_base.info lcov_test.info
    rm -rf coverage
-   $(GENHTML) --show-details --legend --output-directory=coverage --title=PostgreSQL --num-spaces=4 --prefix=$(abs_top_srcdir) $<
+   $(GENHTML) --show-details --legend --output-directory=coverage --title=PostgreSQL --num-spaces=4 --prefix=$(abs_top_srcdir) $^
    touch $@
 
+LCOV += --gcov-tool $(GCOV)
+LCOVFLAGS = --no-external
+
+all_gcno_files = $(shell find . -name '*.gcno' -print)
+
+lcov_base.info: $(all_gcno_files)
+   $(LCOV) $(LCOVFLAGS) -c -i -d . -o $@
+
 all_gcda_files = $(shell find . -name '*.gcda' -print)
 
-lcov.info: $(all_gcda_files)
-   $(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV) --no-external
+lcov_test.info: $(all_gcda_files)
+   $(LCOV) $(LCOVFLAGS) -c -d . -o $@
 
 
 # hook for clean-up
@@ -905,7 +918,7 @@ clean distclean maintainer-clean: clean-coverage
 .PHONY: clean-coverage
 clean-coverage:
    rm -rf coverage coverage-html-stamp
-   rm -f *.gcda *.gcno lcov.info *.gcov .*.gcov *.gcov.out
+   rm -f *.gcda *.gcno lcov*.info *.gcov .*.gcov *.gcov.out
 
 
 # User-callable target to reset counts between test runs