coverage analysis improvements

Started by Peter Eisentrautover 8 years ago13 messages
#1Peter Eisentraut
peter.eisentraut@2ndquadrant.com
9 attachment(s)

Here is a patch series with some significant reworking and adjusting of
how the coverage analysis tools are run. The result should be that the
"make coverage" runs are faster and more robust, the results are more
accurate, and the code is simpler. Please see the individual patches
for details.

I have replaced "make coverage-html" with "make coverage" (but kept the
previous name for compatibility), since the old meaning of the latter
has gone away and was never very useful. Other than that, the usage of
everything stays the same.

I will add it to the commit fest. Testing with different versions of
tools would be especially valuable.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

0007-Improve-vpath-support-in-plperl-build.patchtext/plain; charset=UTF-8; name=0007-Improve-vpath-support-in-plperl-build.patch; x-mac-creator=0; x-mac-type=0Download
From 51a957805710244928c47877d54ff828bdba70ea Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH 7/9] Improve vpath support in plperl build

Run xsubpp with the -output option instead of redirecting stdout.  That
ensures that the #line directives in the output file point to the right
place in a vpath build.  This in turn fixes an error in coverage builds
that it can't find the source files.

Refactor the makefile rules while we're here.
---
 src/pl/plperl/GNUmakefile | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/pl/plperl/GNUmakefile b/src/pl/plperl/GNUmakefile
index 191f74067a..66a2c3d4c9 100644
--- a/src/pl/plperl/GNUmakefile
+++ b/src/pl/plperl/GNUmakefile
@@ -81,13 +81,9 @@ perlchunks.h: $(PERLCHUNKS)
 
 all: all-lib
 
-SPI.c: SPI.xs plperl_helpers.h
+%.c: %.xs
 	@if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch --with-perl was not specified."; exit 1; fi
-	$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap $< >$@
-
-Util.c: Util.xs plperl_helpers.h
-	@if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch --with-perl was not specified."; exit 1; fi
-	$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap $< >$@
+	$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap -output $@ $<
 
 
 install: all install-lib install-data
-- 
2.14.0

0001-Run-only-top-level-recursive-lcov.patchtext/plain; charset=UTF-8; name=0001-Run-only-top-level-recursive-lcov.patch; x-mac-creator=0; x-mac-type=0Download
From 3c8a2c6afb3a8873a70c61c427128bb4d1cade2b Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH 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.

This also removes the direct gcov calls and lets lcov do it instead.
The direct gcov calls are useless because lcov/geninfo call gcov
internally and use that information.
---
 .gitignore                |  3 +--
 GNUmakefile.in            |  2 +-
 doc/src/sgml/regress.sgml |  2 +-
 src/Makefile.global.in    | 33 +++++++++++----------------------
 4 files changed, 14 insertions(+), 26 deletions(-)

diff --git a/.gitignore b/.gitignore
index 4976fd9119..2052f719d1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,10 +19,9 @@ objfiles.txt
 .deps/
 *.gcno
 *.gcda
-*.gcov
-*.gcov.out
 lcov.info
 coverage/
+coverage-stamp
 *.vcproj
 *.vcxproj
 win32ver.rc
diff --git a/GNUmakefile.in b/GNUmakefile.in
index dc76a5d11d..8d77b01eea 100644
--- a/GNUmakefile.in
+++ b/GNUmakefile.in
@@ -41,7 +41,7 @@ install-world-contrib-recurse: install-world-src-recurse
 
 $(call recurse,installdirs uninstall init-po update-po,doc src config)
 
-$(call recurse,distprep coverage,doc src config contrib)
+$(call recurse,distprep,doc src config contrib)
 
 # clean, distclean, etc should apply to contrib too, even though
 # it's not built by default
diff --git a/doc/src/sgml/regress.sgml b/doc/src/sgml/regress.sgml
index 7c2b1029c2..796cdc26ff 100644
--- a/doc/src/sgml/regress.sgml
+++ b/doc/src/sgml/regress.sgml
@@ -699,7 +699,7 @@ <title>Test Coverage Examination</title>
 ./configure --enable-coverage ... OTHER OPTIONS ...
 make
 make check # or other test suite
-make coverage-html
+make coverage
 </screen>
     Then point your HTML browser
     to <filename>coverage/index.html</filename>.
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 0d3f8ca950..b01e578238 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -19,7 +19,7 @@
 #
 # Meta configuration
 
-standard_targets = all install installdirs uninstall distprep clean distclean maintainer-clean coverage check installcheck init-po update-po
+standard_targets = all install installdirs uninstall distprep clean distclean maintainer-clean check installcheck init-po update-po
 # these targets should recurse even into subdirectories not being built:
 standard_always_targets = distprep clean distclean maintainer-clean
 
@@ -863,34 +863,23 @@ endif # enable_nls
 #		(by gcc -ftest-coverage)
 #   foo.gcda	gcov data file, created when the program is run (for
 #		programs compiled with gcc -fprofile-arcs)
-#   foo.c.gcov	gcov output file with coverage information, created by
-#		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,
 #		later collected by "make coverage-html"
 
 ifeq ($(enable_coverage), yes)
 
-# There is a strange interaction between lcov and existing .gcov
-# output files.  Hence the rm command and the ordering dependency.
-
-gcda_files := $(wildcard *.gcda)
+gcda_files = $(shell find . -name '*.gcda' -print)
 
 lcov.info: $(gcda_files)
-	rm -f *.gcov
-	$(if $^,$(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV))
-
-%.c.gcov: %.gcda | lcov.info
-	$(GCOV) -b -f -p -o . $(GCOVFLAGS) $*.c >$*.c.gcov.out
-
-coverage: $(gcda_files:.gcda=.c.gcov) lcov.info
+	$(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV)
 
-.PHONY: coverage-html
-coverage-html: coverage
+coverage-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 $@
+
+.PHONY: coverage coverage-html
+coverage coverage-html: coverage-stamp
 
 
 # hook for clean-up
@@ -898,8 +887,8 @@ clean distclean maintainer-clean: clean-coverage
 
 .PHONY: clean-coverage
 clean-coverage:
-	rm -rf coverage
-	rm -f *.gcda *.gcno lcov.info *.gcov *.gcov.out
+	rm -rf coverage/ coverage-stamp
+	rm -f *.gcda *.gcno lcov.info
 
 
 # User-callable target to reset counts between test runs

base-commit: 8d6442377df5451a8db598788847e6a70b3b49ef
-- 
2.14.0

0002-Have-lcov-exclude-external-files.patchtext/plain; charset=UTF-8; name=0002-Have-lcov-exclude-external-files.patch; x-mac-creator=0; x-mac-type=0Download
From 6f8b86db57e395712fcf3789a337c0e5b8f22e05 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH 2/9] Have lcov exclude external files

Call lcov with --no-external option to exclude external files (for
example, system headers with inline functions) from output.
---
 src/Makefile.global.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index b01e578238..9e162c40f0 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -871,7 +871,7 @@ ifeq ($(enable_coverage), yes)
 gcda_files = $(shell find . -name '*.gcda' -print)
 
 lcov.info: $(gcda_files)
-	$(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV)
+	$(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV) --no-external
 
 coverage-stamp: lcov.info
 	rm -rf coverage
-- 
2.14.0

0003-Add-lcov-initial.patchtext/plain; charset=UTF-8; name=0003-Add-lcov-initial.patch; x-mac-creator=0; x-mac-type=0Download
From 23b05ddceceabfcbb006a4df912dda613ee96dfc Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH 3/9] Add lcov --initial

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.
---
 .gitignore             |  2 +-
 src/Makefile.global.in | 25 +++++++++++++++++++------
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore
index 2052f719d1..de6365cb4f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,7 +19,7 @@ objfiles.txt
 .deps/
 *.gcno
 *.gcda
-lcov.info
+lcov*.info
 coverage/
 coverage-stamp
 *.vcproj
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 9e162c40f0..70e92ee800 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -863,19 +863,32 @@ endif # enable_nls
 #		(by gcc -ftest-coverage)
 #   foo.gcda	gcov data file, created when the program is run (for
 #		programs compiled with gcc -fprofile-arcs)
-#   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)
 
+LCOV += --gcov-tool $(GCOV)
+LCOVFLAGS = --no-external
+
+gcno_files = $(shell find . -name '*.gcno' -print)
+
+lcov_base.info: $(gcno_files)
+	$(LCOV) $(LCOVFLAGS) -c -i -d . -o $@
+
 gcda_files = $(shell find . -name '*.gcda' -print)
 
-lcov.info: $(gcda_files)
-	$(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV) --no-external
+lcov_test.info: $(gcda_files)
+	$(LCOV) $(LCOVFLAGS) -c -d . -o $@
 
-coverage-stamp: lcov.info
+coverage-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 $@
 
 .PHONY: coverage coverage-html
@@ -888,7 +901,7 @@ clean distclean maintainer-clean: clean-coverage
 .PHONY: clean-coverage
 clean-coverage:
 	rm -rf coverage/ coverage-stamp
-	rm -f *.gcda *.gcno lcov.info
+	rm -f *.gcda *.gcno lcov*.info
 
 
 # User-callable target to reset counts between test runs
-- 
2.14.0

0004-Add-PostgreSQL-version-to-coverage-output.patchtext/plain; charset=UTF-8; name=0004-Add-PostgreSQL-version-to-coverage-output.patch; x-mac-creator=0; x-mac-type=0Download
From 8596718d2ecdabafe351aa8a7076fec39f6fcd2c Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH 4/9] Add PostgreSQL version to coverage output

Also make overriding the title easier.  That helps telling where the
report came from and labeling different variants of a report.
---
 src/Makefile.global.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 70e92ee800..554e72b8ee 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -875,6 +875,8 @@ ifeq ($(enable_coverage), yes)
 
 LCOV += --gcov-tool $(GCOV)
 LCOVFLAGS = --no-external
+GENHTML_FLAGS = --show-details --legend
+GENHTML_TITLE = PostgreSQL $(VERSION)
 
 gcno_files = $(shell find . -name '*.gcno' -print)
 
@@ -888,7 +890,7 @@ lcov_test.info: $(gcda_files)
 
 coverage-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) $(GENHTML_FLAGS) -o coverage --title='$(GENHTML_TITLE)' --num-spaces=4 --prefix='$(abs_top_srcdir)' $^
 	touch $@
 
 .PHONY: coverage coverage-html
-- 
2.14.0

0005-Remove-coverage-details-view.patchtext/plain; charset=UTF-8; name=0005-Remove-coverage-details-view.patch; x-mac-creator=0; x-mac-type=0Download
From 3a254dbba98609701409ee30db2c51437d833a5f Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH 5/9] Remove coverage details view

This is only useful if we name the different tests, which we don't do at
the moment.
---
 src/Makefile.global.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 554e72b8ee..e865aedfb6 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -875,7 +875,7 @@ ifeq ($(enable_coverage), yes)
 
 LCOV += --gcov-tool $(GCOV)
 LCOVFLAGS = --no-external
-GENHTML_FLAGS = --show-details --legend
+GENHTML_FLAGS = --legend
 GENHTML_TITLE = PostgreSQL $(VERSION)
 
 gcno_files = $(shell find . -name '*.gcno' -print)
-- 
2.14.0

0006-Run-coverage-commands-quietly.patchtext/plain; charset=UTF-8; name=0006-Run-coverage-commands-quietly.patch; x-mac-creator=0; x-mac-type=0Download
From 4da5bd0597eb90aa5fb383b7528144a30c9b92fd Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH 6/9] Run coverage commands quietly

They are very chatty by default, but the output doesn't seem all that
useful for normal operation.
---
 src/Makefile.global.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index e865aedfb6..f40b1db0cd 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -874,8 +874,8 @@ endif # enable_nls
 ifeq ($(enable_coverage), yes)
 
 LCOV += --gcov-tool $(GCOV)
-LCOVFLAGS = --no-external
-GENHTML_FLAGS = --legend
+LCOVFLAGS = -q --no-external
+GENHTML_FLAGS = -q --legend
 GENHTML_TITLE = PostgreSQL $(VERSION)
 
 gcno_files = $(shell find . -name '*.gcno' -print)
-- 
2.14.0

0008-Support-coverage-on-vpath-builds.patchtext/plain; charset=UTF-8; name=0008-Support-coverage-on-vpath-builds.patch; x-mac-creator=0; x-mac-type=0Download
From ab0151123c233a670b88013363e3a36483364912 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH 8/9] Support coverage on vpath builds

A few paths needed to be tweaked so everything looks into the
appropriate directories.
---
 src/Makefile.global.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index f40b1db0cd..54ea92bbfb 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -881,16 +881,16 @@ GENHTML_TITLE = PostgreSQL $(VERSION)
 gcno_files = $(shell find . -name '*.gcno' -print)
 
 lcov_base.info: $(gcno_files)
-	$(LCOV) $(LCOVFLAGS) -c -i -d . -o $@
+	$(LCOV) $(LCOVFLAGS) -c -i -d . -d $(srcdir) -o $@
 
 gcda_files = $(shell find . -name '*.gcda' -print)
 
 lcov_test.info: $(gcda_files)
-	$(LCOV) $(LCOVFLAGS) -c -d . -o $@
+	$(LCOV) $(LCOVFLAGS) -c -d . -d $(srcdir) -o $@
 
 coverage-stamp: lcov_base.info lcov_test.info
 	rm -rf coverage
-	$(GENHTML) $(GENHTML_FLAGS) -o coverage --title='$(GENHTML_TITLE)' --num-spaces=4 --prefix='$(abs_top_srcdir)' $^
+	$(GENHTML) $(GENHTML_FLAGS) -o coverage --title='$(GENHTML_TITLE)' --num-spaces=4 $^
 	touch $@
 
 .PHONY: coverage coverage-html
-- 
2.14.0

0009-Exclude-flex-generated-code-from-coverage-testing.patchtext/plain; charset=UTF-8; name=0009-Exclude-flex-generated-code-from-coverage-testing.patch; x-mac-creator=0; x-mac-type=0Download
From ddd4f65ddcbe26c442d792d553ff46b93524c8d3 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH 9/9] Exclude flex-generated code from coverage testing

Flex generates a lot of functions that are not actually used.  In order
to avoid coverage figures being ruined by that, mark up the part of the
.l files where the generated code appears by lcov exclusion markers.
That way, lcov will typically only reported on coverage for the .l file,
which is under our control, but not for the .c file.
---
 contrib/cube/cubescan.l                   | 4 ++++
 contrib/seg/segscan.l                     | 4 ++++
 src/backend/bootstrap/bootscanner.l       | 3 +++
 src/backend/parser/scan.l                 | 5 +++++
 src/backend/replication/repl_scanner.l    | 3 +++
 src/backend/replication/syncrep_scanner.l | 3 +++
 src/backend/utils/misc/guc-file.l         | 4 +++-
 src/bin/pgbench/exprscan.l                | 4 ++++
 src/bin/psql/psqlscanslash.l              | 4 ++++
 src/fe_utils/psqlscan.l                   | 4 ++++
 src/interfaces/ecpg/preproc/pgc.l         | 6 ++++++
 src/test/isolation/specscanner.l          | 4 ++++
 12 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/contrib/cube/cubescan.l b/contrib/cube/cubescan.l
index dada917820..bd400e3684 100644
--- a/contrib/cube/cubescan.l
+++ b/contrib/cube/cubescan.l
@@ -4,6 +4,8 @@
  * contrib/cube/cubescan.l
  */
 
+/* LCOV_EXCL_START */
+
 /* No reason to constrain amount of data slurped */
 #define YY_READ_BUF_SIZE 16777216
 
@@ -56,6 +58,8 @@ NaN          [nN][aA][nN]
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 /* result is not used, but Bison expects this signature */
 void
 yyerror(NDBOX **result, const char *message)
diff --git a/contrib/seg/segscan.l b/contrib/seg/segscan.l
index 6db24fdd1f..5f6595e9eb 100644
--- a/contrib/seg/segscan.l
+++ b/contrib/seg/segscan.l
@@ -3,6 +3,8 @@
  * A scanner for EMP-style numeric ranges
  */
 
+/* LCOV_EXCL_START */
+
 /* No reason to constrain amount of data slurped */
 #define YY_READ_BUF_SIZE 16777216
 
@@ -51,6 +53,8 @@ float        ({integer}|{real})([eE]{integer})?
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 void
 yyerror(SEG *result, const char *message)
 {
diff --git a/src/backend/bootstrap/bootscanner.l b/src/backend/bootstrap/bootscanner.l
index 6467882fa3..4fd23f932c 100644
--- a/src/backend/bootstrap/bootscanner.l
+++ b/src/backend/bootstrap/bootscanner.l
@@ -38,6 +38,7 @@
 /* Not needed now that this file is compiled as part of bootparse. */
 /* #include "bootparse.h" */
 
+/* LCOV_EXCL_START */
 
 /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
 #undef fprintf
@@ -134,6 +135,8 @@ insert			{ return(INSERT_TUPLE); }
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 void
 yyerror(const char *message)
 {
diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l
index 634bfa512f..6af2199cdc 100644
--- a/src/backend/parser/scan.l
+++ b/src/backend/parser/scan.l
@@ -41,6 +41,9 @@
 }
 
 %{
+
+/* LCOV_EXCL_START */
+
 /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
 #undef fprintf
 #define fprintf(file, fmt, msg)  fprintf_to_ereport(fmt, msg)
@@ -1011,6 +1014,8 @@ other			.
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 /*
  * Arrange access to yyextra for subroutines of the main yylex() function.
  * We expect each subroutine to have a yyscanner parameter.  Rather than
diff --git a/src/backend/replication/repl_scanner.l b/src/backend/replication/repl_scanner.l
index 52ae7b343f..9c2f5fdd65 100644
--- a/src/backend/replication/repl_scanner.l
+++ b/src/backend/replication/repl_scanner.l
@@ -38,6 +38,8 @@ static char *litbufdup(void);
 static void addlit(char *ytext, int yleng);
 static void addlitchar(unsigned char ychar);
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option 8bit
@@ -185,6 +187,7 @@ USE_SNAPSHOT		{ return K_USE_SNAPSHOT; }
 				}
 %%
 
+/* LCOV_EXCL_STOP */
 
 static void
 startlit(void)
diff --git a/src/backend/replication/syncrep_scanner.l b/src/backend/replication/syncrep_scanner.l
index d1d1b26a48..1fbc936aa6 100644
--- a/src/backend/replication/syncrep_scanner.l
+++ b/src/backend/replication/syncrep_scanner.l
@@ -32,6 +32,8 @@ static YY_BUFFER_STATE scanbufhandle;
 
 static StringInfoData xdbuf;
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option 8bit
@@ -112,6 +114,7 @@ xdinside		[^"]+
 .			{ return JUNK; }
 %%
 
+/* LCOV_EXCL_STOP */
 
 /* Needs to be here for access to yytext */
 void
diff --git a/src/backend/utils/misc/guc-file.l b/src/backend/utils/misc/guc-file.l
index f01b814c6e..3de8e791f2 100644
--- a/src/backend/utils/misc/guc-file.l
+++ b/src/backend/utils/misc/guc-file.l
@@ -57,6 +57,8 @@ static void record_config_file_error(const char *errmsg,
 static int	GUC_flex_fatal(const char *msg);
 static char *GUC_scanstr(const char *s);
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option 8bit
@@ -107,7 +109,7 @@ STRING			\'([^'\\\n]|\\.|\'\')*\'
 
 %%
 
-
+/* LCOV_EXCL_STOP */
 
 /*
  * Exported function to read and process the configuration file. The
diff --git a/src/bin/pgbench/exprscan.l b/src/bin/pgbench/exprscan.l
index dc1367bbdb..15cedd3c9d 100644
--- a/src/bin/pgbench/exprscan.l
+++ b/src/bin/pgbench/exprscan.l
@@ -43,6 +43,8 @@ static bool last_was_newline = false;
 extern int	expr_yyget_column(yyscan_t yyscanner);
 extern void expr_yyset_column(int column_no, yyscan_t yyscanner);
 
+/* LCOV_EXCL_START */
+
 %}
 
 /* Except for the prefix, these options should match psqlscan.l */
@@ -190,6 +192,8 @@ continuation	\\{newline}
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 void
 expr_yyerror_more(yyscan_t yyscanner, const char *message, const char *more)
 {
diff --git a/src/bin/psql/psqlscanslash.l b/src/bin/psql/psqlscanslash.l
index db7a1b9eea..080dc37a2f 100644
--- a/src/bin/psql/psqlscanslash.l
+++ b/src/bin/psql/psqlscanslash.l
@@ -67,6 +67,8 @@ static void evaluate_backtick(PsqlScanState state);
 extern int	slash_yyget_column(yyscan_t yyscanner);
 extern void slash_yyset_column(int column_no, yyscan_t yyscanner);
 
+/* LCOV_EXCL_START */
+
 %}
 
 /* Except for the prefix, these options should match psqlscan.l */
@@ -450,6 +452,8 @@ other			.
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 /*
  * Scan the command name of a psql backslash command.  This should be called
  * after psql_scan() returns PSCAN_BACKSLASH.  It is assumed that the input
diff --git a/src/fe_utils/psqlscan.l b/src/fe_utils/psqlscan.l
index 27689d72da..205756a2fe 100644
--- a/src/fe_utils/psqlscan.l
+++ b/src/fe_utils/psqlscan.l
@@ -71,6 +71,8 @@ typedef int YYSTYPE;
 extern int	psql_yyget_column(yyscan_t yyscanner);
 extern void psql_yyset_column(int column_no, yyscan_t yyscanner);
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option reentrant
@@ -884,6 +886,8 @@ other			.
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 /*
  * Create a lexer working state struct.
  *
diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l
index 7b2bfdccc9..8602748faa 100644
--- a/src/interfaces/ecpg/preproc/pgc.l
+++ b/src/interfaces/ecpg/preproc/pgc.l
@@ -79,6 +79,8 @@ static struct _if_value
 	short else_branch;
 } stacked_if_value[MAX_NESTED_IF];
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option 8bit
@@ -1249,7 +1251,11 @@ cppline			{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
 					}
 				}
 <INITIAL>{other}|\n	{ mmfatal(PARSE_ERROR, "internal error: unreachable state; please report this to <pgsql-bugs@postgresql.org>"); }
+
 %%
+
+/* LCOV_EXCL_STOP */
+
 void
 lex_init(void)
 {
diff --git a/src/test/isolation/specscanner.l b/src/test/isolation/specscanner.l
index aed9269c63..7c571bc101 100644
--- a/src/test/isolation/specscanner.l
+++ b/src/test/isolation/specscanner.l
@@ -17,6 +17,8 @@ static int litbufpos = 0;
 
 static void addlitchar(char c);
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option 8bit
@@ -93,6 +95,8 @@ teardown		{ return(TEARDOWN); }
 				}
 %%
 
+/* LCOV_EXCL_STOP */
+
 static void
 addlitchar(char c)
 {
-- 
2.14.0

#2Michael Paquier
michael.paquier@gmail.com
In reply to: Peter Eisentraut (#1)
Re: coverage analysis improvements

On Fri, Aug 11, 2017 at 1:05 PM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

Here is a patch series with some significant reworking and adjusting of
how the coverage analysis tools are run. The result should be that the
"make coverage" runs are faster and more robust, the results are more
accurate, and the code is simpler. Please see the individual patches
for details.

I have replaced "make coverage-html" with "make coverage" (but kept the
previous name for compatibility), since the old meaning of the latter
has gone away and was never very useful. Other than that, the usage of
everything stays the same.

I will add it to the commit fest. Testing with different versions of
tools would be especially valuable.

Patch 0001 fails to apply as of c629324. Which versions of lcov and
gcov did you use for your tests?
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Michael Paquier (#2)
9 attachment(s)
Re: coverage analysis improvements

On 8/21/17 01:23, Michael Paquier wrote:

Patch 0001 fails to apply as of c629324.

Updated patches attached.

Which versions of lcov and gcov did you use for your tests?

LCOV version 1.13, and gcc-7 and gcc-6

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

v2-0001-Run-only-top-level-recursive-lcov.patchtext/plain; charset=UTF-8; name=v2-0001-Run-only-top-level-recursive-lcov.patch; x-mac-creator=0; x-mac-type=0Download
From 7b2f5087a2d0710e6a5c7ffa946dcfabd163f987 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v2 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.

This also removes the direct gcov calls and lets lcov do it instead.
The direct gcov calls are useless because lcov/geninfo call gcov
internally and use that information.
---
 .gitignore                |  3 +--
 GNUmakefile.in            |  2 +-
 doc/src/sgml/regress.sgml |  2 +-
 src/Makefile.global.in    | 33 +++++++++++----------------------
 4 files changed, 14 insertions(+), 26 deletions(-)

diff --git a/.gitignore b/.gitignore
index 4976fd9119..2052f719d1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,10 +19,9 @@ objfiles.txt
 .deps/
 *.gcno
 *.gcda
-*.gcov
-*.gcov.out
 lcov.info
 coverage/
+coverage-stamp
 *.vcproj
 *.vcxproj
 win32ver.rc
diff --git a/GNUmakefile.in b/GNUmakefile.in
index dc76a5d11d..8d77b01eea 100644
--- a/GNUmakefile.in
+++ b/GNUmakefile.in
@@ -41,7 +41,7 @@ install-world-contrib-recurse: install-world-src-recurse
 
 $(call recurse,installdirs uninstall init-po update-po,doc src config)
 
-$(call recurse,distprep coverage,doc src config contrib)
+$(call recurse,distprep,doc src config contrib)
 
 # clean, distclean, etc should apply to contrib too, even though
 # it's not built by default
diff --git a/doc/src/sgml/regress.sgml b/doc/src/sgml/regress.sgml
index 7c2b1029c2..796cdc26ff 100644
--- a/doc/src/sgml/regress.sgml
+++ b/doc/src/sgml/regress.sgml
@@ -699,7 +699,7 @@ <title>Test Coverage Examination</title>
 ./configure --enable-coverage ... OTHER OPTIONS ...
 make
 make check # or other test suite
-make coverage-html
+make coverage
 </screen>
     Then point your HTML browser
     to <filename>coverage/index.html</filename>.
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index e8b3a519cb..e39ed884e7 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -19,7 +19,7 @@
 #
 # Meta configuration
 
-standard_targets = all install installdirs uninstall distprep clean distclean maintainer-clean coverage check installcheck init-po update-po
+standard_targets = all install installdirs uninstall distprep clean distclean maintainer-clean check installcheck init-po update-po
 # these targets should recurse even into subdirectories not being built:
 standard_always_targets = distprep clean distclean maintainer-clean
 
@@ -863,34 +863,23 @@ endif # enable_nls
 #		(by gcc -ftest-coverage)
 #   foo.gcda	gcov data file, created when the program is run (for
 #		programs compiled with gcc -fprofile-arcs)
-#   foo.c.gcov	gcov output file with coverage information, created by
-#		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,
 #		later collected by "make coverage-html"
 
 ifeq ($(enable_coverage), yes)
 
-# There is a strange interaction between lcov and existing .gcov
-# output files.  Hence the rm command and the ordering dependency.
-
-gcda_files := $(wildcard *.gcda)
+gcda_files = $(shell find . -name '*.gcda' -print)
 
 lcov.info: $(gcda_files)
-	rm -f *.gcov .*.gcov
-	$(if $^,$(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV))
-
-%.c.gcov: %.gcda | lcov.info
-	$(GCOV) -b -f -p -o . $(GCOVFLAGS) $*.c >$*.c.gcov.out
-
-coverage: $(gcda_files:.gcda=.c.gcov) lcov.info
+	$(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV)
 
-.PHONY: coverage-html
-coverage-html: coverage
+coverage-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 $@
+
+.PHONY: coverage coverage-html
+coverage coverage-html: coverage-stamp
 
 
 # hook for clean-up
@@ -898,8 +887,8 @@ clean distclean maintainer-clean: clean-coverage
 
 .PHONY: clean-coverage
 clean-coverage:
-	rm -rf coverage
-	rm -f *.gcda *.gcno lcov.info *.gcov .*.gcov *.gcov.out
+	rm -rf coverage/ coverage-stamp
+	rm -f *.gcda *.gcno lcov.info
 
 
 # User-callable target to reset counts between test runs

base-commit: 2bfd1b1ee562c4e4fd065c7f7d1beaa9b9852070
-- 
2.14.1

v2-0002-Have-lcov-exclude-external-files.patchtext/plain; charset=UTF-8; name=v2-0002-Have-lcov-exclude-external-files.patch; x-mac-creator=0; x-mac-type=0Download
From 0bbf137972e22923f650a38ff46c0e1397795384 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v2 2/9] Have lcov exclude external files

Call lcov with --no-external option to exclude external files (for
example, system headers with inline functions) from output.
---
 src/Makefile.global.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index e39ed884e7..7d8f3dd33d 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -871,7 +871,7 @@ ifeq ($(enable_coverage), yes)
 gcda_files = $(shell find . -name '*.gcda' -print)
 
 lcov.info: $(gcda_files)
-	$(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV)
+	$(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV) --no-external
 
 coverage-stamp: lcov.info
 	rm -rf coverage
-- 
2.14.1

v2-0003-Add-lcov-initial.patchtext/plain; charset=UTF-8; name=v2-0003-Add-lcov-initial.patch; x-mac-creator=0; x-mac-type=0Download
From 2bb11bb176b8feec6ea06af157bcede1de30bd1f Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v2 3/9] Add lcov --initial

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.
---
 .gitignore             |  2 +-
 src/Makefile.global.in | 25 +++++++++++++++++++------
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore
index 2052f719d1..de6365cb4f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,7 +19,7 @@ objfiles.txt
 .deps/
 *.gcno
 *.gcda
-lcov.info
+lcov*.info
 coverage/
 coverage-stamp
 *.vcproj
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 7d8f3dd33d..c95cff543b 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -863,19 +863,32 @@ endif # enable_nls
 #		(by gcc -ftest-coverage)
 #   foo.gcda	gcov data file, created when the program is run (for
 #		programs compiled with gcc -fprofile-arcs)
-#   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)
 
+LCOV += --gcov-tool $(GCOV)
+LCOVFLAGS = --no-external
+
+gcno_files = $(shell find . -name '*.gcno' -print)
+
+lcov_base.info: $(gcno_files)
+	$(LCOV) $(LCOVFLAGS) -c -i -d . -o $@
+
 gcda_files = $(shell find . -name '*.gcda' -print)
 
-lcov.info: $(gcda_files)
-	$(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV) --no-external
+lcov_test.info: $(gcda_files)
+	$(LCOV) $(LCOVFLAGS) -c -d . -o $@
 
-coverage-stamp: lcov.info
+coverage-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 $@
 
 .PHONY: coverage coverage-html
@@ -888,7 +901,7 @@ clean distclean maintainer-clean: clean-coverage
 .PHONY: clean-coverage
 clean-coverage:
 	rm -rf coverage/ coverage-stamp
-	rm -f *.gcda *.gcno lcov.info
+	rm -f *.gcda *.gcno lcov*.info
 
 
 # User-callable target to reset counts between test runs
-- 
2.14.1

v2-0004-Add-PostgreSQL-version-to-coverage-output.patchtext/plain; charset=UTF-8; name=v2-0004-Add-PostgreSQL-version-to-coverage-output.patch; x-mac-creator=0; x-mac-type=0Download
From fa87c19989d1797c7f52a1160a09d2900816e382 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v2 4/9] Add PostgreSQL version to coverage output

Also make overriding the title easier.  That helps telling where the
report came from and labeling different variants of a report.
---
 src/Makefile.global.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index c95cff543b..ec2ae8f45d 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -875,6 +875,8 @@ ifeq ($(enable_coverage), yes)
 
 LCOV += --gcov-tool $(GCOV)
 LCOVFLAGS = --no-external
+GENHTML_FLAGS = --show-details --legend
+GENHTML_TITLE = PostgreSQL $(VERSION)
 
 gcno_files = $(shell find . -name '*.gcno' -print)
 
@@ -888,7 +890,7 @@ lcov_test.info: $(gcda_files)
 
 coverage-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) $(GENHTML_FLAGS) -o coverage --title='$(GENHTML_TITLE)' --num-spaces=4 --prefix='$(abs_top_srcdir)' $^
 	touch $@
 
 .PHONY: coverage coverage-html
-- 
2.14.1

v2-0005-Remove-coverage-details-view.patchtext/plain; charset=UTF-8; name=v2-0005-Remove-coverage-details-view.patch; x-mac-creator=0; x-mac-type=0Download
From 728c35a753ecf577c70700b07b416a77cd205956 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v2 5/9] Remove coverage details view

This is only useful if we name the different tests, which we don't do at
the moment.
---
 src/Makefile.global.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index ec2ae8f45d..4b2aa2ae0f 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -875,7 +875,7 @@ ifeq ($(enable_coverage), yes)
 
 LCOV += --gcov-tool $(GCOV)
 LCOVFLAGS = --no-external
-GENHTML_FLAGS = --show-details --legend
+GENHTML_FLAGS = --legend
 GENHTML_TITLE = PostgreSQL $(VERSION)
 
 gcno_files = $(shell find . -name '*.gcno' -print)
-- 
2.14.1

v2-0006-Run-coverage-commands-quietly.patchtext/plain; charset=UTF-8; name=v2-0006-Run-coverage-commands-quietly.patch; x-mac-creator=0; x-mac-type=0Download
From 599b3ed89e796b029cccf1ccfe9ad18bf04419fa Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v2 6/9] Run coverage commands quietly

They are very chatty by default, but the output doesn't seem all that
useful for normal operation.
---
 src/Makefile.global.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 4b2aa2ae0f..e9d89005ec 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -874,8 +874,8 @@ endif # enable_nls
 ifeq ($(enable_coverage), yes)
 
 LCOV += --gcov-tool $(GCOV)
-LCOVFLAGS = --no-external
-GENHTML_FLAGS = --legend
+LCOVFLAGS = -q --no-external
+GENHTML_FLAGS = -q --legend
 GENHTML_TITLE = PostgreSQL $(VERSION)
 
 gcno_files = $(shell find . -name '*.gcno' -print)
-- 
2.14.1

v2-0007-Improve-vpath-support-in-plperl-build.patchtext/plain; charset=UTF-8; name=v2-0007-Improve-vpath-support-in-plperl-build.patch; x-mac-creator=0; x-mac-type=0Download
From 48f7bbddd876265c22fe5e7bf685995bce6a2f1d Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v2 7/9] Improve vpath support in plperl build

Run xsubpp with the -output option instead of redirecting stdout.  That
ensures that the #line directives in the output file point to the right
place in a vpath build.  This in turn fixes an error in coverage builds
that it can't find the source files.

Refactor the makefile rules while we're here.
---
 src/pl/plperl/GNUmakefile | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/pl/plperl/GNUmakefile b/src/pl/plperl/GNUmakefile
index 191f74067a..66a2c3d4c9 100644
--- a/src/pl/plperl/GNUmakefile
+++ b/src/pl/plperl/GNUmakefile
@@ -81,13 +81,9 @@ perlchunks.h: $(PERLCHUNKS)
 
 all: all-lib
 
-SPI.c: SPI.xs plperl_helpers.h
+%.c: %.xs
 	@if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch --with-perl was not specified."; exit 1; fi
-	$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap $< >$@
-
-Util.c: Util.xs plperl_helpers.h
-	@if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch --with-perl was not specified."; exit 1; fi
-	$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap $< >$@
+	$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap -output $@ $<
 
 
 install: all install-lib install-data
-- 
2.14.1

v2-0008-Support-coverage-on-vpath-builds.patchtext/plain; charset=UTF-8; name=v2-0008-Support-coverage-on-vpath-builds.patch; x-mac-creator=0; x-mac-type=0Download
From 7f7f175252d992a9ab213dfb6caeac33ece78417 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v2 8/9] Support coverage on vpath builds

A few paths needed to be tweaked so everything looks into the
appropriate directories.
---
 src/Makefile.global.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index e9d89005ec..b09ef3e418 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -881,16 +881,16 @@ GENHTML_TITLE = PostgreSQL $(VERSION)
 gcno_files = $(shell find . -name '*.gcno' -print)
 
 lcov_base.info: $(gcno_files)
-	$(LCOV) $(LCOVFLAGS) -c -i -d . -o $@
+	$(LCOV) $(LCOVFLAGS) -c -i -d . -d $(srcdir) -o $@
 
 gcda_files = $(shell find . -name '*.gcda' -print)
 
 lcov_test.info: $(gcda_files)
-	$(LCOV) $(LCOVFLAGS) -c -d . -o $@
+	$(LCOV) $(LCOVFLAGS) -c -d . -d $(srcdir) -o $@
 
 coverage-stamp: lcov_base.info lcov_test.info
 	rm -rf coverage
-	$(GENHTML) $(GENHTML_FLAGS) -o coverage --title='$(GENHTML_TITLE)' --num-spaces=4 --prefix='$(abs_top_srcdir)' $^
+	$(GENHTML) $(GENHTML_FLAGS) -o coverage --title='$(GENHTML_TITLE)' --num-spaces=4 $^
 	touch $@
 
 .PHONY: coverage coverage-html
-- 
2.14.1

v2-0009-Exclude-flex-generated-code-from-coverage-testing.patchtext/plain; charset=UTF-8; name=v2-0009-Exclude-flex-generated-code-from-coverage-testing.patch; x-mac-creator=0; x-mac-type=0Download
From 040d5df93100293919fe2a729d3b612d9df13fdf Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v2 9/9] Exclude flex-generated code from coverage testing

Flex generates a lot of functions that are not actually used.  In order
to avoid coverage figures being ruined by that, mark up the part of the
.l files where the generated code appears by lcov exclusion markers.
That way, lcov will typically only reported on coverage for the .l file,
which is under our control, but not for the .c file.
---
 contrib/cube/cubescan.l                   | 4 ++++
 contrib/seg/segscan.l                     | 4 ++++
 src/backend/bootstrap/bootscanner.l       | 3 +++
 src/backend/parser/scan.l                 | 5 +++++
 src/backend/replication/repl_scanner.l    | 3 +++
 src/backend/replication/syncrep_scanner.l | 3 +++
 src/backend/utils/misc/guc-file.l         | 4 +++-
 src/bin/pgbench/exprscan.l                | 4 ++++
 src/bin/psql/psqlscanslash.l              | 4 ++++
 src/fe_utils/psqlscan.l                   | 4 ++++
 src/interfaces/ecpg/preproc/pgc.l         | 6 ++++++
 src/test/isolation/specscanner.l          | 4 ++++
 12 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/contrib/cube/cubescan.l b/contrib/cube/cubescan.l
index dada917820..bd400e3684 100644
--- a/contrib/cube/cubescan.l
+++ b/contrib/cube/cubescan.l
@@ -4,6 +4,8 @@
  * contrib/cube/cubescan.l
  */
 
+/* LCOV_EXCL_START */
+
 /* No reason to constrain amount of data slurped */
 #define YY_READ_BUF_SIZE 16777216
 
@@ -56,6 +58,8 @@ NaN          [nN][aA][nN]
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 /* result is not used, but Bison expects this signature */
 void
 yyerror(NDBOX **result, const char *message)
diff --git a/contrib/seg/segscan.l b/contrib/seg/segscan.l
index 6db24fdd1f..5f6595e9eb 100644
--- a/contrib/seg/segscan.l
+++ b/contrib/seg/segscan.l
@@ -3,6 +3,8 @@
  * A scanner for EMP-style numeric ranges
  */
 
+/* LCOV_EXCL_START */
+
 /* No reason to constrain amount of data slurped */
 #define YY_READ_BUF_SIZE 16777216
 
@@ -51,6 +53,8 @@ float        ({integer}|{real})([eE]{integer})?
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 void
 yyerror(SEG *result, const char *message)
 {
diff --git a/src/backend/bootstrap/bootscanner.l b/src/backend/bootstrap/bootscanner.l
index 6467882fa3..4fd23f932c 100644
--- a/src/backend/bootstrap/bootscanner.l
+++ b/src/backend/bootstrap/bootscanner.l
@@ -38,6 +38,7 @@
 /* Not needed now that this file is compiled as part of bootparse. */
 /* #include "bootparse.h" */
 
+/* LCOV_EXCL_START */
 
 /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
 #undef fprintf
@@ -134,6 +135,8 @@ insert			{ return(INSERT_TUPLE); }
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 void
 yyerror(const char *message)
 {
diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l
index 634bfa512f..6af2199cdc 100644
--- a/src/backend/parser/scan.l
+++ b/src/backend/parser/scan.l
@@ -41,6 +41,9 @@
 }
 
 %{
+
+/* LCOV_EXCL_START */
+
 /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
 #undef fprintf
 #define fprintf(file, fmt, msg)  fprintf_to_ereport(fmt, msg)
@@ -1011,6 +1014,8 @@ other			.
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 /*
  * Arrange access to yyextra for subroutines of the main yylex() function.
  * We expect each subroutine to have a yyscanner parameter.  Rather than
diff --git a/src/backend/replication/repl_scanner.l b/src/backend/replication/repl_scanner.l
index 52ae7b343f..9c2f5fdd65 100644
--- a/src/backend/replication/repl_scanner.l
+++ b/src/backend/replication/repl_scanner.l
@@ -38,6 +38,8 @@ static char *litbufdup(void);
 static void addlit(char *ytext, int yleng);
 static void addlitchar(unsigned char ychar);
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option 8bit
@@ -185,6 +187,7 @@ USE_SNAPSHOT		{ return K_USE_SNAPSHOT; }
 				}
 %%
 
+/* LCOV_EXCL_STOP */
 
 static void
 startlit(void)
diff --git a/src/backend/replication/syncrep_scanner.l b/src/backend/replication/syncrep_scanner.l
index d1d1b26a48..1fbc936aa6 100644
--- a/src/backend/replication/syncrep_scanner.l
+++ b/src/backend/replication/syncrep_scanner.l
@@ -32,6 +32,8 @@ static YY_BUFFER_STATE scanbufhandle;
 
 static StringInfoData xdbuf;
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option 8bit
@@ -112,6 +114,7 @@ xdinside		[^"]+
 .			{ return JUNK; }
 %%
 
+/* LCOV_EXCL_STOP */
 
 /* Needs to be here for access to yytext */
 void
diff --git a/src/backend/utils/misc/guc-file.l b/src/backend/utils/misc/guc-file.l
index f01b814c6e..3de8e791f2 100644
--- a/src/backend/utils/misc/guc-file.l
+++ b/src/backend/utils/misc/guc-file.l
@@ -57,6 +57,8 @@ static void record_config_file_error(const char *errmsg,
 static int	GUC_flex_fatal(const char *msg);
 static char *GUC_scanstr(const char *s);
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option 8bit
@@ -107,7 +109,7 @@ STRING			\'([^'\\\n]|\\.|\'\')*\'
 
 %%
 
-
+/* LCOV_EXCL_STOP */
 
 /*
  * Exported function to read and process the configuration file. The
diff --git a/src/bin/pgbench/exprscan.l b/src/bin/pgbench/exprscan.l
index dc1367bbdb..15cedd3c9d 100644
--- a/src/bin/pgbench/exprscan.l
+++ b/src/bin/pgbench/exprscan.l
@@ -43,6 +43,8 @@ static bool last_was_newline = false;
 extern int	expr_yyget_column(yyscan_t yyscanner);
 extern void expr_yyset_column(int column_no, yyscan_t yyscanner);
 
+/* LCOV_EXCL_START */
+
 %}
 
 /* Except for the prefix, these options should match psqlscan.l */
@@ -190,6 +192,8 @@ continuation	\\{newline}
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 void
 expr_yyerror_more(yyscan_t yyscanner, const char *message, const char *more)
 {
diff --git a/src/bin/psql/psqlscanslash.l b/src/bin/psql/psqlscanslash.l
index db7a1b9eea..080dc37a2f 100644
--- a/src/bin/psql/psqlscanslash.l
+++ b/src/bin/psql/psqlscanslash.l
@@ -67,6 +67,8 @@ static void evaluate_backtick(PsqlScanState state);
 extern int	slash_yyget_column(yyscan_t yyscanner);
 extern void slash_yyset_column(int column_no, yyscan_t yyscanner);
 
+/* LCOV_EXCL_START */
+
 %}
 
 /* Except for the prefix, these options should match psqlscan.l */
@@ -450,6 +452,8 @@ other			.
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 /*
  * Scan the command name of a psql backslash command.  This should be called
  * after psql_scan() returns PSCAN_BACKSLASH.  It is assumed that the input
diff --git a/src/fe_utils/psqlscan.l b/src/fe_utils/psqlscan.l
index 27689d72da..205756a2fe 100644
--- a/src/fe_utils/psqlscan.l
+++ b/src/fe_utils/psqlscan.l
@@ -71,6 +71,8 @@ typedef int YYSTYPE;
 extern int	psql_yyget_column(yyscan_t yyscanner);
 extern void psql_yyset_column(int column_no, yyscan_t yyscanner);
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option reentrant
@@ -884,6 +886,8 @@ other			.
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 /*
  * Create a lexer working state struct.
  *
diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l
index 3598a200d0..14522821be 100644
--- a/src/interfaces/ecpg/preproc/pgc.l
+++ b/src/interfaces/ecpg/preproc/pgc.l
@@ -79,6 +79,8 @@ static struct _if_value
 	short else_branch;
 } stacked_if_value[MAX_NESTED_IF];
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option 8bit
@@ -1249,7 +1251,11 @@ cppline			{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
 					}
 				}
 <INITIAL>{other}|\n	{ mmfatal(PARSE_ERROR, "internal error: unreachable state; please report this to <pgsql-bugs@postgresql.org>"); }
+
 %%
+
+/* LCOV_EXCL_STOP */
+
 void
 lex_init(void)
 {
diff --git a/src/test/isolation/specscanner.l b/src/test/isolation/specscanner.l
index aed9269c63..7c571bc101 100644
--- a/src/test/isolation/specscanner.l
+++ b/src/test/isolation/specscanner.l
@@ -17,6 +17,8 @@ static int litbufpos = 0;
 
 static void addlitchar(char c);
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option 8bit
@@ -93,6 +95,8 @@ teardown		{ return(TEARDOWN); }
 				}
 %%
 
+/* LCOV_EXCL_STOP */
+
 static void
 addlitchar(char c)
 {
-- 
2.14.1

#4Michael Paquier
michael.paquier@gmail.com
In reply to: Peter Eisentraut (#3)
Re: coverage analysis improvements

On Wed, Aug 23, 2017 at 3:47 AM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

On 8/21/17 01:23, Michael Paquier wrote:

Patch 0001 fails to apply as of c629324.

Updated patches attached.

Which versions of lcov and gcov did you use for your tests?

LCOV version 1.13, and gcc-7 and gcc-6

LCOV can be compiled from here (I have for example just changed PREFIX
in the main makefile):
https://github.com/linux-test-project/lcov.gi
And testing down to 1.11 I am not seeing issues with your patches. I
have used gcc 7.1.1.

Patch 0001 removes the .gcov files, which offer a text representation
of the coverage. Sometimes I use that with a terminal... Not sure for
the others, but that's my status on the matter. This also removes the
target coverage. Please note that on some distributions, like, err...
ArchLinux, lcov is not packaged in the core packages and it is
necessary to make use of external sources (AUR). It would be nice to
keep the original gcov calls as well, and keep the split between
coverage-html and coverage. I think as well that html generate should
be done only if lcov is found, and that text generation should be done
only if gcov is used. It is annoying to see --enable-coverage fail
because lcov only is missing, but it is not mandatory for coverage.

Patches 2, 4, 5, 6 and 9 are good independent ideas.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Michael Paquier (#4)
9 attachment(s)
Re: coverage analysis improvements

On 8/24/17 04:12, Michael Paquier wrote:

Patch 0001 removes the .gcov files, which offer a text representation
of the coverage. Sometimes I use that with a terminal... Not sure for
the others, but that's my status on the matter. This also removes the
target coverage. Please note that on some distributions, like, err...
ArchLinux, lcov is not packaged in the core packages and it is
necessary to make use of external sources (AUR). It would be nice to
keep the original gcov calls as well, and keep the split between
coverage-html and coverage. I think as well that html generate should
be done only if lcov is found, and that text generation should be done
only if gcov is used. It is annoying to see --enable-coverage fail
because lcov only is missing, but it is not mandatory for coverage.

OK, I was not aware that people are using it that way. So updated patch
set there, which separates coverage and coverage-html into two
independent targets.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

v3-0007-Improve-vpath-support-in-plperl-build.patchtext/plain; charset=UTF-8; name=v3-0007-Improve-vpath-support-in-plperl-build.patch; x-mac-creator=0; x-mac-type=0Download
From 78d933a2a839216a0ae56b645324200794142854 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v3 7/9] Improve vpath support in plperl build

Run xsubpp with the -output option instead of redirecting stdout.  That
ensures that the #line directives in the output file point to the right
place in a vpath build.  This in turn fixes an error in coverage builds
that it can't find the source files.

Refactor the makefile rules while we're here.
---
 src/pl/plperl/GNUmakefile | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/pl/plperl/GNUmakefile b/src/pl/plperl/GNUmakefile
index 191f74067a..66a2c3d4c9 100644
--- a/src/pl/plperl/GNUmakefile
+++ b/src/pl/plperl/GNUmakefile
@@ -81,13 +81,9 @@ perlchunks.h: $(PERLCHUNKS)
 
 all: all-lib
 
-SPI.c: SPI.xs plperl_helpers.h
+%.c: %.xs
 	@if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch --with-perl was not specified."; exit 1; fi
-	$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap $< >$@
-
-Util.c: Util.xs plperl_helpers.h
-	@if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch --with-perl was not specified."; exit 1; fi
-	$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap $< >$@
+	$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap -output $@ $<
 
 
 install: all install-lib install-data
-- 
2.14.1

v3-0008-Support-coverage-on-vpath-builds.patchtext/plain; charset=UTF-8; name=v3-0008-Support-coverage-on-vpath-builds.patch; x-mac-creator=0; x-mac-type=0Download
From 84ecd03155140a2f75218ccafd08d37da32f5335 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v3 8/9] Support coverage on vpath builds

A few paths needed to be tweaked so everything looks into the
appropriate directories.
---
 src/Makefile.global.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 9340d60de5..a4209df7c9 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -898,7 +898,7 @@ GENHTML_TITLE = PostgreSQL $(VERSION)
 
 coverage-html-stamp: lcov_base.info lcov_test.info
 	rm -rf coverage
-	$(GENHTML) $(GENHTML_FLAGS) -o coverage --title='$(GENHTML_TITLE)' --num-spaces=4 --prefix='$(abs_top_srcdir)' $^
+	$(GENHTML) $(GENHTML_FLAGS) -o coverage --title='$(GENHTML_TITLE)' --num-spaces=4 $^
 	touch $@
 
 LCOV += --gcov-tool $(GCOV)
@@ -907,12 +907,12 @@ LCOVFLAGS = -q --no-external
 all_gcno_files = $(shell find . -name '*.gcno' -print)
 
 lcov_base.info: $(all_gcno_files)
-	$(LCOV) $(LCOVFLAGS) -c -i -d . -o $@
+	$(LCOV) $(LCOVFLAGS) -c -i -d . -d $(srcdir) -o $@
 
 all_gcda_files = $(shell find . -name '*.gcda' -print)
 
 lcov_test.info: $(all_gcda_files)
-	$(LCOV) $(LCOVFLAGS) -c -d . -o $@
+	$(LCOV) $(LCOVFLAGS) -c -d . -d $(srcdir) -o $@
 
 
 # hook for clean-up
-- 
2.14.1

v3-0001-Run-only-top-level-recursive-lcov.patchtext/plain; charset=UTF-8; name=v3-0001-Run-only-top-level-recursive-lcov.patch; x-mac-creator=0; x-mac-type=0Download
From 39969d232e9d137aadae55f67a45fa2306f43df9 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
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 @@ <title>Test Coverage Examination</title>
     The <command>make</command> commands also work in subdirectories.
    </para>
 
+   <para>
+    If you don't have <command>lcov</command> or prefer text output over an
+    HTML report, you can also run
+<screen>
+make coverage
+</screen>
+    instead of <literal>make coverage-html</literal>, which will
+    produce <filename>.gcov</filename> output files for each source file
+    relevant to the test.  (<literal>make coverage</literal> and <literal>make
+    coverage-html</literal> will overwrite each other's files, so mixing them
+    might be confusing.)
+   </para>
+
    <para>
     To reset the execution counts between test runs, run:
 <screen>
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

v3-0002-Have-lcov-exclude-external-files.patchtext/plain; charset=UTF-8; name=v3-0002-Have-lcov-exclude-external-files.patch; x-mac-creator=0; x-mac-type=0Download
From 48c874997f2714268ef2dbdf44d65ebca2a2d5a3 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v3 2/9] Have lcov exclude external files

Call lcov with --no-external option to exclude external files (for
example, system headers with inline functions) from output.
---
 src/Makefile.global.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index f352ba20e2..2b22f0de29 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -896,7 +896,7 @@ coverage-html-stamp: lcov.info
 all_gcda_files = $(shell find . -name '*.gcda' -print)
 
 lcov.info: $(all_gcda_files)
-	$(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV)
+	$(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV) --no-external
 
 
 # hook for clean-up
-- 
2.14.1

v3-0003-Add-lcov-initial.patchtext/plain; charset=UTF-8; name=v3-0003-Add-lcov-initial.patch; x-mac-creator=0; x-mac-type=0Download
From bca43e4dc3f439463a01e3d1458878cd0c45f7ce Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v3 3/9] Add lcov --initial

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.
---
 .gitignore             |  2 +-
 src/Makefile.global.in | 25 +++++++++++++++++++------
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore
index 94e2c582f5..a59e3da3be 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,7 +21,7 @@ objfiles.txt
 *.gcda
 *.gcov
 *.gcov.out
-lcov.info
+lcov*.info
 coverage/
 coverage-html-stamp
 *.vcproj
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 2b22f0de29..c0a88c9152 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -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
-- 
2.14.1

v3-0004-Add-PostgreSQL-version-to-coverage-output.patchtext/plain; charset=UTF-8; name=v3-0004-Add-PostgreSQL-version-to-coverage-output.patch; x-mac-creator=0; x-mac-type=0Download
From 28c7d7bebc5c9f57251c05ec0cbffe052061f81a Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v3 4/9] Add PostgreSQL version to coverage output

Also make overriding the title easier.  That helps telling where the
report came from and labeling different variants of a report.
---
 src/Makefile.global.in | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index c0a88c9152..1a0faf9023 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -893,9 +893,12 @@ coverage: $(local_gcda_files:.gcda=.c.gcov)
 .PHONY: coverage-html
 coverage-html: coverage-html-stamp
 
+GENHTML_FLAGS = --show-details --legend
+GENHTML_TITLE = PostgreSQL $(VERSION)
+
 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) $(GENHTML_FLAGS) -o coverage --title='$(GENHTML_TITLE)' --num-spaces=4 --prefix='$(abs_top_srcdir)' $^
 	touch $@
 
 LCOV += --gcov-tool $(GCOV)
-- 
2.14.1

v3-0005-Remove-coverage-details-view.patchtext/plain; charset=UTF-8; name=v3-0005-Remove-coverage-details-view.patch; x-mac-creator=0; x-mac-type=0Download
From b2c42a90be051d69ccd9becb2d60566d29853015 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v3 5/9] Remove coverage details view

This is only useful if we name the different tests, which we don't do at
the moment.
---
 src/Makefile.global.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 1a0faf9023..d4fed90405 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -893,7 +893,7 @@ coverage: $(local_gcda_files:.gcda=.c.gcov)
 .PHONY: coverage-html
 coverage-html: coverage-html-stamp
 
-GENHTML_FLAGS = --show-details --legend
+GENHTML_FLAGS = --legend
 GENHTML_TITLE = PostgreSQL $(VERSION)
 
 coverage-html-stamp: lcov_base.info lcov_test.info
-- 
2.14.1

v3-0006-Run-coverage-commands-quietly.patchtext/plain; charset=UTF-8; name=v3-0006-Run-coverage-commands-quietly.patch; x-mac-creator=0; x-mac-type=0Download
From 504d9da1fc72b1e8bab03cc31e7f873f6edaae7a Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v3 6/9] Run coverage commands quietly

They are very chatty by default, but the output doesn't seem all that
useful for normal operation.
---
 src/Makefile.global.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index d4fed90405..9340d60de5 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -893,7 +893,7 @@ coverage: $(local_gcda_files:.gcda=.c.gcov)
 .PHONY: coverage-html
 coverage-html: coverage-html-stamp
 
-GENHTML_FLAGS = --legend
+GENHTML_FLAGS = -q --legend
 GENHTML_TITLE = PostgreSQL $(VERSION)
 
 coverage-html-stamp: lcov_base.info lcov_test.info
@@ -902,7 +902,7 @@ coverage-html-stamp: lcov_base.info lcov_test.info
 	touch $@
 
 LCOV += --gcov-tool $(GCOV)
-LCOVFLAGS = --no-external
+LCOVFLAGS = -q --no-external
 
 all_gcno_files = $(shell find . -name '*.gcno' -print)
 
-- 
2.14.1

v3-0009-Exclude-flex-generated-code-from-coverage-testing.patchtext/plain; charset=UTF-8; name=v3-0009-Exclude-flex-generated-code-from-coverage-testing.patch; x-mac-creator=0; x-mac-type=0Download
From fbfdc462ee0f54b716eda3ce88033a792d0f6470 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 10 Aug 2017 23:33:47 -0400
Subject: [PATCH v3 9/9] Exclude flex-generated code from coverage testing

Flex generates a lot of functions that are not actually used.  In order
to avoid coverage figures being ruined by that, mark up the part of the
.l files where the generated code appears by lcov exclusion markers.
That way, lcov will typically only reported on coverage for the .l file,
which is under our control, but not for the .c file.
---
 contrib/cube/cubescan.l                   | 4 ++++
 contrib/seg/segscan.l                     | 4 ++++
 src/backend/bootstrap/bootscanner.l       | 3 +++
 src/backend/parser/scan.l                 | 5 +++++
 src/backend/replication/repl_scanner.l    | 3 +++
 src/backend/replication/syncrep_scanner.l | 3 +++
 src/backend/utils/misc/guc-file.l         | 4 +++-
 src/bin/pgbench/exprscan.l                | 4 ++++
 src/bin/psql/psqlscanslash.l              | 4 ++++
 src/fe_utils/psqlscan.l                   | 4 ++++
 src/interfaces/ecpg/preproc/pgc.l         | 6 ++++++
 src/test/isolation/specscanner.l          | 4 ++++
 12 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/contrib/cube/cubescan.l b/contrib/cube/cubescan.l
index dada917820..bd400e3684 100644
--- a/contrib/cube/cubescan.l
+++ b/contrib/cube/cubescan.l
@@ -4,6 +4,8 @@
  * contrib/cube/cubescan.l
  */
 
+/* LCOV_EXCL_START */
+
 /* No reason to constrain amount of data slurped */
 #define YY_READ_BUF_SIZE 16777216
 
@@ -56,6 +58,8 @@ NaN          [nN][aA][nN]
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 /* result is not used, but Bison expects this signature */
 void
 yyerror(NDBOX **result, const char *message)
diff --git a/contrib/seg/segscan.l b/contrib/seg/segscan.l
index 6db24fdd1f..5f6595e9eb 100644
--- a/contrib/seg/segscan.l
+++ b/contrib/seg/segscan.l
@@ -3,6 +3,8 @@
  * A scanner for EMP-style numeric ranges
  */
 
+/* LCOV_EXCL_START */
+
 /* No reason to constrain amount of data slurped */
 #define YY_READ_BUF_SIZE 16777216
 
@@ -51,6 +53,8 @@ float        ({integer}|{real})([eE]{integer})?
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 void
 yyerror(SEG *result, const char *message)
 {
diff --git a/src/backend/bootstrap/bootscanner.l b/src/backend/bootstrap/bootscanner.l
index 51c5e5e3cd..5465217bc3 100644
--- a/src/backend/bootstrap/bootscanner.l
+++ b/src/backend/bootstrap/bootscanner.l
@@ -38,6 +38,7 @@
 /* Not needed now that this file is compiled as part of bootparse. */
 /* #include "bootparse.h" */
 
+/* LCOV_EXCL_START */
 
 /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
 #undef fprintf
@@ -134,6 +135,8 @@ insert			{ return INSERT_TUPLE; }
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 void
 yyerror(const char *message)
 {
diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l
index 634bfa512f..6af2199cdc 100644
--- a/src/backend/parser/scan.l
+++ b/src/backend/parser/scan.l
@@ -41,6 +41,9 @@
 }
 
 %{
+
+/* LCOV_EXCL_START */
+
 /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
 #undef fprintf
 #define fprintf(file, fmt, msg)  fprintf_to_ereport(fmt, msg)
@@ -1011,6 +1014,8 @@ other			.
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 /*
  * Arrange access to yyextra for subroutines of the main yylex() function.
  * We expect each subroutine to have a yyscanner parameter.  Rather than
diff --git a/src/backend/replication/repl_scanner.l b/src/backend/replication/repl_scanner.l
index 62bb5288c0..568d55ac95 100644
--- a/src/backend/replication/repl_scanner.l
+++ b/src/backend/replication/repl_scanner.l
@@ -38,6 +38,8 @@ static char *litbufdup(void);
 static void addlit(char *ytext, int yleng);
 static void addlitchar(unsigned char ychar);
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option 8bit
@@ -186,6 +188,7 @@ WAIT				{ return K_WAIT; }
 				}
 %%
 
+/* LCOV_EXCL_STOP */
 
 static void
 startlit(void)
diff --git a/src/backend/replication/syncrep_scanner.l b/src/backend/replication/syncrep_scanner.l
index d1d1b26a48..1fbc936aa6 100644
--- a/src/backend/replication/syncrep_scanner.l
+++ b/src/backend/replication/syncrep_scanner.l
@@ -32,6 +32,8 @@ static YY_BUFFER_STATE scanbufhandle;
 
 static StringInfoData xdbuf;
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option 8bit
@@ -112,6 +114,7 @@ xdinside		[^"]+
 .			{ return JUNK; }
 %%
 
+/* LCOV_EXCL_STOP */
 
 /* Needs to be here for access to yytext */
 void
diff --git a/src/backend/utils/misc/guc-file.l b/src/backend/utils/misc/guc-file.l
index f01b814c6e..3de8e791f2 100644
--- a/src/backend/utils/misc/guc-file.l
+++ b/src/backend/utils/misc/guc-file.l
@@ -57,6 +57,8 @@ static void record_config_file_error(const char *errmsg,
 static int	GUC_flex_fatal(const char *msg);
 static char *GUC_scanstr(const char *s);
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option 8bit
@@ -107,7 +109,7 @@ STRING			\'([^'\\\n]|\\.|\'\')*\'
 
 %%
 
-
+/* LCOV_EXCL_STOP */
 
 /*
  * Exported function to read and process the configuration file. The
diff --git a/src/bin/pgbench/exprscan.l b/src/bin/pgbench/exprscan.l
index 9bf6d237f5..9f46fb9db8 100644
--- a/src/bin/pgbench/exprscan.l
+++ b/src/bin/pgbench/exprscan.l
@@ -43,6 +43,8 @@ static bool last_was_newline = false;
 extern int	expr_yyget_column(yyscan_t yyscanner);
 extern void expr_yyset_column(int column_no, yyscan_t yyscanner);
 
+/* LCOV_EXCL_START */
+
 %}
 
 /* Except for the prefix, these options should match psqlscan.l */
@@ -190,6 +192,8 @@ continuation	\\{newline}
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 void
 expr_yyerror_more(yyscan_t yyscanner, const char *message, const char *more)
 {
diff --git a/src/bin/psql/psqlscanslash.l b/src/bin/psql/psqlscanslash.l
index db7a1b9eea..080dc37a2f 100644
--- a/src/bin/psql/psqlscanslash.l
+++ b/src/bin/psql/psqlscanslash.l
@@ -67,6 +67,8 @@ static void evaluate_backtick(PsqlScanState state);
 extern int	slash_yyget_column(yyscan_t yyscanner);
 extern void slash_yyset_column(int column_no, yyscan_t yyscanner);
 
+/* LCOV_EXCL_START */
+
 %}
 
 /* Except for the prefix, these options should match psqlscan.l */
@@ -450,6 +452,8 @@ other			.
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 /*
  * Scan the command name of a psql backslash command.  This should be called
  * after psql_scan() returns PSCAN_BACKSLASH.  It is assumed that the input
diff --git a/src/fe_utils/psqlscan.l b/src/fe_utils/psqlscan.l
index 27689d72da..205756a2fe 100644
--- a/src/fe_utils/psqlscan.l
+++ b/src/fe_utils/psqlscan.l
@@ -71,6 +71,8 @@ typedef int YYSTYPE;
 extern int	psql_yyget_column(yyscan_t yyscanner);
 extern void psql_yyset_column(int column_no, yyscan_t yyscanner);
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option reentrant
@@ -884,6 +886,8 @@ other			.
 
 %%
 
+/* LCOV_EXCL_STOP */
+
 /*
  * Create a lexer working state struct.
  *
diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l
index fc450f30ab..e35843ba4e 100644
--- a/src/interfaces/ecpg/preproc/pgc.l
+++ b/src/interfaces/ecpg/preproc/pgc.l
@@ -79,6 +79,8 @@ static struct _if_value
 	short else_branch;
 } stacked_if_value[MAX_NESTED_IF];
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option 8bit
@@ -1249,7 +1251,11 @@ cppline			{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
 					}
 				}
 <INITIAL>{other}|\n	{ mmfatal(PARSE_ERROR, "internal error: unreachable state; please report this to <pgsql-bugs@postgresql.org>"); }
+
 %%
+
+/* LCOV_EXCL_STOP */
+
 void
 lex_init(void)
 {
diff --git a/src/test/isolation/specscanner.l b/src/test/isolation/specscanner.l
index a9528bda6b..9c0532c0c5 100644
--- a/src/test/isolation/specscanner.l
+++ b/src/test/isolation/specscanner.l
@@ -17,6 +17,8 @@ static int litbufpos = 0;
 
 static void addlitchar(char c);
 
+/* LCOV_EXCL_START */
+
 %}
 
 %option 8bit
@@ -93,6 +95,8 @@ teardown		{ return TEARDOWN; }
 				}
 %%
 
+/* LCOV_EXCL_STOP */
+
 static void
 addlitchar(char c)
 {
-- 
2.14.1

#6Noname
ilmari@ilmari.org
In reply to: Peter Eisentraut (#5)
Re: coverage analysis improvements

Hi Peter,

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

OK, I was not aware that people are using it that way. So updated patch
set there, which separates coverage and coverage-html into two
independent targets.

I have no opinion on the bulk of this patch set, but skimming it out of
curiosity I noticed that the plperl change seems to have lost the
dependency on plperl_helpers.h from the xsubpp targets:

diff --git a/src/pl/plperl/GNUmakefile b/src/pl/plperl/GNUmakefile
index 191f74067a..66a2c3d4c9 100644
--- a/src/pl/plperl/GNUmakefile
+++ b/src/pl/plperl/GNUmakefile
@@ -81,13 +81,9 @@ perlchunks.h: $(PERLCHUNKS)

all: all-lib

-SPI.c: SPI.xs plperl_helpers.h
+%.c: %.xs
@if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch --with-perl was not specified."; exit 1; fi
-	$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap $< >$@
-
-Util.c: Util.xs plperl_helpers.h
-	@if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch --with-perl was not specified."; exit 1; fi
-	$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap $< >$@
+	$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap -output $@ $<

install: all install-lib install-data

--
- Twitter seems more influential [than blogs] in the 'gets reported in
the mainstream press' sense at least. - Matt McLeod
- That'd be because the content of a tweet is easier to condense down
to a mainstream media article. - Calle Dybedahl

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#7Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Noname (#6)
Re: coverage analysis improvements

On 9/20/17 13:13, Dagfinn Ilmari Mannsåker wrote:

I have no opinion on the bulk of this patch set, but skimming it out of
curiosity I noticed that the plperl change seems to have lost the
dependency on plperl_helpers.h from the xsubpp targets:

Those commands don't actually require plperl_helpers.h, do they?

diff --git a/src/pl/plperl/GNUmakefile b/src/pl/plperl/GNUmakefile
index 191f74067a..66a2c3d4c9 100644
--- a/src/pl/plperl/GNUmakefile
+++ b/src/pl/plperl/GNUmakefile
@@ -81,13 +81,9 @@ perlchunks.h: $(PERLCHUNKS)

all: all-lib

-SPI.c: SPI.xs plperl_helpers.h
+%.c: %.xs
@if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch --with-perl was not specified."; exit 1; fi
-	$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap $< >$@
-
-Util.c: Util.xs plperl_helpers.h
-	@if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch --with-perl was not specified."; exit 1; fi
-	$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap $< >$@
+	$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap -output $@ $<

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#8Michael Paquier
michael.paquier@gmail.com
In reply to: Peter Eisentraut (#5)
Re: coverage analysis improvements

On Thu, Sep 21, 2017 at 1:48 AM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

OK, I was not aware that people are using it that way.

At least one.

So updated patch
set there, which separates coverage and coverage-html into two
independent targets.

Thanks for the new versions.

Patches 4 and 5 could be merged. They step on each other's code paths.
Some other things could be merged as well.

 coverage-html-stamp: lcov_base.info lcov_test.info
    rm -rf coverage
-   $(GENHTML) $(GENHTML_FLAGS) -o coverage --title='$(GENHTML_TITLE)'
--num-spaces=4 --prefix='$(abs_top_srcdir)' $^
+   $(GENHTML) $(GENHTML_FLAGS) -o coverage --title='$(GENHTML_TITLE)'
--num-spaces=4 $^
    touch $@
Actually this is very nice. I have been always enforcing
abs_top_srcdir when using coverage stuff on things out of the main
tree.
-SPI.c: SPI.xs plperl_helpers.h
+%.c: %.xs
    @if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch
--with-perl was not specified."; exit 1; fi
-   $(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap
$(perl_privlibexp)/ExtUtils/typemap $< >$@
Doing coverage on plperl with this patch applied, those do not seem
necessary. But I don't know enough this code to give a clear opinion.

Running coverage-html with all the patches, I am seeing the following
warnings with a fresh build on my macos laptop 10.11:
geninfo: WARNING: gcov did not create any files for
/Users/mpaquier/git/postgres/src/backend/access/transam/rmgr.gcda!
I don't think that this is normal.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#9Noname
ilmari@ilmari.org
In reply to: Peter Eisentraut (#7)
Re: coverage analysis improvements

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

On 9/20/17 13:13, Dagfinn Ilmari Mannsåker wrote:

I have no opinion on the bulk of this patch set, but skimming it out of
curiosity I noticed that the plperl change seems to have lost the
dependency on plperl_helpers.h from the xsubpp targets:

Those commands don't actually require plperl_helpers.h, do they?

No, but the .xs files #include it. I guess it's SPI.o and Util.o that
should depend on the header..

- ilmari
--
"I use RMS as a guide in the same way that a boat captain would use
a lighthouse. It's good to know where it is, but you generally
don't want to find yourself in the same spot." - Tollef Fog Heen

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#10Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Michael Paquier (#8)
Re: coverage analysis improvements

On 9/21/17 03:42, Michael Paquier wrote:

-SPI.c: SPI.xs plperl_helpers.h
+%.c: %.xs
@if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch
--with-perl was not specified."; exit 1; fi
-   $(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap
$(perl_privlibexp)/ExtUtils/typemap $< >$@
Doing coverage on plperl with this patch applied, those do not seem
necessary. But I don't know enough this code to give a clear opinion.

That patch is necessary for doing make coverage in vpath builds.
Otherwise it makes no difference.

Running coverage-html with all the patches, I am seeing the following
warnings with a fresh build on my macos laptop 10.11:
geninfo: WARNING: gcov did not create any files for
/Users/mpaquier/git/postgres/src/backend/access/transam/rmgr.gcda!
I don't think that this is normal.

Apparently, rmgr.c doesn't contain any instrumentable code. I don't see
this warning, but it might depend on tool versions and compiler options.

Note that rmgr.c doesn't show up here either:
https://coverage.postgresql.org/src/backend/access/transam/index.html

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#11Michael Paquier
michael.paquier@gmail.com
In reply to: Peter Eisentraut (#10)
Re: coverage analysis improvements

On Fri, Sep 22, 2017 at 11:34 PM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

Apparently, rmgr.c doesn't contain any instrumentable code. I don't see
this warning, but it might depend on tool versions and compiler options.

Even on HEAD I am seeing the same problem, this is not outlined just
because the quiet mode of lcov is not used, but the warnings are there
like in this report:
/messages/by-id/ec92eb95-26de-6da8-9862-ded3ff678c5c@BlueTreble.com
So please let me discard my concerns about this portion of the patch.

Except for the plperl patch, I don't have more comments to offer about
this patch set. It would be nice to make configure a bit smarter for
lcov and gcov detection by not hard-failing if gcov can be found but
not lcov. It is after all possible to run coverage without lcov, like
on ArchLinux. Still that's a different request than what this patch
set is doing, so this is not a blocker for this patch set.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#12Michael Paquier
michael.paquier@gmail.com
In reply to: Michael Paquier (#11)
Re: coverage analysis improvements

On Tue, Sep 26, 2017 at 3:45 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

Except for the plperl patch, I don't have more comments to offer about
this patch set. It would be nice to make configure a bit smarter for
lcov and gcov detection by not hard-failing if gcov can be found but
not lcov. It is after all possible to run coverage without lcov, like
on ArchLinux. Still that's a different request than what this patch
set is doing, so this is not a blocker for this patch set.

-SPI.c: SPI.xs plperl_helpers.h
+%.c: %.xs
    @if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch
--with-perl was not specified."; exit 1; fi
-   $(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap
$(perl_privlibexp)/ExtUtils/typemap $< >$@
-
-Util.c: Util.xs plperl_helpers.h
-   @if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch
--with-perl was not specified."; exit 1; fi
-   $(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap
$(perl_privlibexp)/ExtUtils/typemap $< >$@
+   $(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap
$(perl_privlibexp)/ExtUtils/typemap -output $@ $<
I just looked at the plperl portion of this patch, and I think that
01d83ffd has done some unnecessary things here. Contrary to
perlchunks.h and plperl_opmask.h which are generated during the build,
plperl_helpers.h is part of the source code so there is no meaning in
having a dependency with it. The .c files do not need this header
anyway, but their .o files would, still there is no need for that
either as plperl_helpers.h will not go away.

I am marking the full set of patches as ready for committer.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#13Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Michael Paquier (#12)
Re: coverage analysis improvements

On 9/27/17 01:52, Michael Paquier wrote:

I am marking the full set of patches as ready for committer.

All these patches have now been committed.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers