[PATCH] Fix 'make coverage' when used with lcov version 2.0+

2024-05-06 Thread Aaron Merey
Starting with version 2.0, various lcov warnings now trigger an error
exit.  This results in 'make coverage' terminating before completion.

Fix this by invoking lcov and genhtml with --ignore-errors to prevent
the error exit when version 2.0+ is in use.

Manually tested by running elfutils-htdocs/update-coverage.sh with
lcov 1.14 and 2.0.

Signed-off-by: Aaron Merey 
---
 Makefile.am  | 30 +-
 configure.ac |  4 
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index c9d59d4a..a1f0b0c3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -77,6 +77,7 @@ coverage-clean:
 coverage: $(COVERAGE_OUTPUT_INDEX_HTML)
@echo 'file://$(abs_builddir)/$(COVERAGE_OUTPUT_INDEX_HTML)'
 
+if LCOV_OLD
 $(COVERAGE_OUTPUT_INDEX_HTML): $(COVERAGE_OUTPUT_FILE)
LC_ALL=C $(GENHTML) \
--legend \
@@ -89,7 +90,23 @@ $(COVERAGE_OUTPUT_INDEX_HTML): $(COVERAGE_OUTPUT_FILE)
--prefix='$(realpath $(abs_builddir)/..)' \
--output-directory='$(COVERAGE_OUTPUT_DIRECTORY)' \
$<
+else
+$(COVERAGE_OUTPUT_INDEX_HTML): $(COVERAGE_OUTPUT_FILE)
+   LC_ALL=C $(GENHTML) \
+   --legend \
+   --show-details \
+   --ignore-errors empty,negative \
+   --rc=genhtml_branch_coverage=1 \
+   --title='$(COVERAGE_TITLE)' \
+   --prefix='$(abspath $(abs_srcdir))' \
+   --prefix='$(realpath $(abs_srcdir))' \
+   --prefix='$(abspath $(abs_builddir)/..)' \
+   --prefix='$(realpath $(abs_builddir)/..)' \
+   --output-directory='$(COVERAGE_OUTPUT_DIRECTORY)' \
+   $<
+endif
 
+if LCOV_OLD
 $(COVERAGE_OUTPUT_FILE):
$(LCOV) \
--capture \
@@ -99,7 +116,18 @@ $(COVERAGE_OUTPUT_FILE):
--gcov-tool='$(GCOV)' \
--output-file='$@' \
$(LCOV_DIRS_ARGS)
-
+else
+$(COVERAGE_OUTPUT_FILE):
+   $(LCOV) \
+   --capture \
+   --no-external \
+   --no-checksum \
+   --ignore-errors empty,negative \
+   --rc=lcov_branch_coverage=1 \
+   --gcov-tool='$(GCOV)' \
+   --output-file='$@' \
+   $(LCOV_DIRS_ARGS)
+endif
 endif
 
 # Tell version 3.79 and up of GNU make to not build goals in this
diff --git a/configure.ac b/configure.ac
index a279bb52..2aa728bd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -322,6 +322,10 @@ if test "$use_gcov" = yes; then
 fi
 AM_CONDITIONAL(GCOV, test "$use_gcov" = yes)
 
+# Check if lcov/genhtml supports ignoring additional errors.
+AM_CONDITIONAL([LCOV_OLD],
+  [test "$LCOV" = "lcov" && lcov --version | grep -E -q "version 0|version 1"])
+
 AC_ARG_ENABLE([sanitize-undefined],
   AS_HELP_STRING([--enable-sanitize-undefined],
  [Use gcc undefined behaviour sanitizer]),
-- 
2.43.0



Re: [PATCH] Fix 'make coverage' when used with lcov version 2.0+

2024-05-06 Thread Dmitry V. Levin
Hi,

On Mon, May 06, 2024 at 04:45:27PM -0400, Aaron Merey wrote:
> Starting with version 2.0, various lcov warnings now trigger an error
> exit.  This results in 'make coverage' terminating before completion.
> 
> Fix this by invoking lcov and genhtml with --ignore-errors to prevent
> the error exit when version 2.0+ is in use.
> 
> Manually tested by running elfutils-htdocs/update-coverage.sh with
> lcov 1.14 and 2.0.
> 
> Signed-off-by: Aaron Merey 
> ---
>  Makefile.am  | 30 +-
>  configure.ac |  4 
>  2 files changed, 33 insertions(+), 1 deletion(-)
> 
> diff --git a/Makefile.am b/Makefile.am
> index c9d59d4a..a1f0b0c3 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -77,6 +77,7 @@ coverage-clean:
>  coverage: $(COVERAGE_OUTPUT_INDEX_HTML)
>   @echo 'file://$(abs_builddir)/$(COVERAGE_OUTPUT_INDEX_HTML)'
>  
> +if LCOV_OLD
>  $(COVERAGE_OUTPUT_INDEX_HTML): $(COVERAGE_OUTPUT_FILE)
>   LC_ALL=C $(GENHTML) \
>   --legend \
> @@ -89,7 +90,23 @@ $(COVERAGE_OUTPUT_INDEX_HTML): $(COVERAGE_OUTPUT_FILE)
>   --prefix='$(realpath $(abs_builddir)/..)' \
>   --output-directory='$(COVERAGE_OUTPUT_DIRECTORY)' \
>   $<
> +else
> +$(COVERAGE_OUTPUT_INDEX_HTML): $(COVERAGE_OUTPUT_FILE)
> + LC_ALL=C $(GENHTML) \
> + --legend \
> + --show-details \
> + --ignore-errors empty,negative \
> + --rc=genhtml_branch_coverage=1 \
> + --title='$(COVERAGE_TITLE)' \
> + --prefix='$(abspath $(abs_srcdir))' \
> + --prefix='$(realpath $(abs_srcdir))' \
> + --prefix='$(abspath $(abs_builddir)/..)' \
> + --prefix='$(realpath $(abs_builddir)/..)' \
> + --output-directory='$(COVERAGE_OUTPUT_DIRECTORY)' \
> + $<
> +endif
>  
> +if LCOV_OLD
>  $(COVERAGE_OUTPUT_FILE):
>   $(LCOV) \
>   --capture \
> @@ -99,7 +116,18 @@ $(COVERAGE_OUTPUT_FILE):
>   --gcov-tool='$(GCOV)' \
>   --output-file='$@' \
>   $(LCOV_DIRS_ARGS)
> -
> +else
> +$(COVERAGE_OUTPUT_FILE):
> + $(LCOV) \
> + --capture \
> + --no-external \
> + --no-checksum \
> + --ignore-errors empty,negative \
> + --rc=lcov_branch_coverage=1 \
> + --gcov-tool='$(GCOV)' \
> + --output-file='$@' \
> + $(LCOV_DIRS_ARGS)
> +endif
>  endif
>  
>  # Tell version 3.79 and up of GNU make to not build goals in this

Would it be possible to avoid code duplication by parametrizing just
the difference?


-- 
ldv