Skip to content

Commit 504923a

Browse files
committed
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.) Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
1 parent 7769fc0 commit 504923a

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ objfiles.txt
2323
*.gcov.out
2424
lcov.info
2525
coverage/
26+
coverage-html-stamp
2627
*.vcproj
2728
*.vcxproj
2829
win32ver.rc

doc/src/sgml/regress.sgml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,19 @@ make coverage-html
706706
The <command>make</command> commands also work in subdirectories.
707707
</para>
708708

709+
<para>
710+
If you don't have <command>lcov</command> or prefer text output over an
711+
HTML report, you can also run
712+
<screen>
713+
make coverage
714+
</screen>
715+
instead of <literal>make coverage-html</literal>, which will
716+
produce <filename>.gcov</filename> output files for each source file
717+
relevant to the test. (<literal>make coverage</literal> and <literal>make
718+
coverage-html</literal> will overwrite each other's files, so mixing them
719+
might be confusing.)
720+
</para>
721+
709722
<para>
710723
To reset the execution counts between test runs, run:
711724
<screen>

src/Makefile.global.in

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -874,33 +874,37 @@ endif # enable_nls
874874

875875
ifeq ($(enable_coverage), yes)
876876

877-
# There is a strange interaction between lcov and existing .gcov
878-
# output files. Hence the rm command and the ordering dependency.
877+
# make coverage -- text output
879878

880-
gcda_files := $(wildcard *.gcda)
879+
local_gcda_files = $(wildcard *.gcda)
881880

882-
lcov.info: $(gcda_files)
883-
rm -f *.gcov .*.gcov
884-
$(if $^,$(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV))
881+
coverage: $(local_gcda_files:.gcda=.c.gcov)
885882

886-
%.c.gcov: %.gcda | lcov.info
883+
%.c.gcov: %.gcda
887884
$(GCOV) -b -f -p -o . $(GCOVFLAGS) $*.c >$*.c.gcov.out
888885

889-
coverage: $(gcda_files:.gcda=.c.gcov) lcov.info
886+
# make coverage-html -- HTML output via lcov
890887

891888
.PHONY: coverage-html
892-
coverage-html: coverage
889+
coverage-html: coverage-html-stamp
890+
891+
coverage-html-stamp: lcov.info
893892
rm -rf coverage
894-
mkdir coverage
895-
$(GENHTML) --show-details --legend --output-directory=coverage --title=PostgreSQL --num-spaces=4 --prefix=$(abs_top_srcdir) `find . -name lcov.info -print`
893+
$(GENHTML) --show-details --legend --output-directory=coverage --title=PostgreSQL --num-spaces=4 --prefix=$(abs_top_srcdir) $<
894+
touch $@
895+
896+
all_gcda_files = $(shell find . -name '*.gcda' -print)
897+
898+
lcov.info: $(all_gcda_files)
899+
$(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV)
896900

897901

898902
# hook for clean-up
899903
clean distclean maintainer-clean: clean-coverage
900904

901905
.PHONY: clean-coverage
902906
clean-coverage:
903-
rm -rf coverage
907+
rm -rf coverage coverage-html-stamp
904908
rm -f *.gcda *.gcno lcov.info *.gcov .*.gcov *.gcov.out
905909

906910

0 commit comments

Comments
 (0)