diff options
author | Dmitry V. Levin <ldv@altlinux.org> | 2021-01-12 08:00:00 +0000 |
---|---|---|
committer | Dmitry V. Levin <ldv@altlinux.org> | 2021-01-12 09:09:25 +0000 |
commit | 2a16a0fc7e353f8fcfc27a57710e008840297847 (patch) | |
tree | 79d54ce2a51409f081457ca836c7e966fec43acd | |
parent | ada269939a17f973cb883a29d40e437ad39ca292 (diff) | |
download | elfutils-2a16a0fc7e353f8fcfc27a57710e008840297847.tar.gz |
Add coverage target
Implement a target for capturing code coverage using lcov.
It is available when elfutils is configured using --enable-gcov.
Tested with
autoreconf -if && ./configure --enable-maintainer-mode --enable-gcov &&
make && make check && make coverage
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | Makefile.am | 51 | ||||
-rw-r--r-- | configure.ac | 3 |
4 files changed, 62 insertions, 0 deletions
@@ -16,6 +16,7 @@ =* Makefile Makefile.in +/*.lcov /ABOUT-NLS /INSTALL /aclocal.m4 @@ -26,6 +27,7 @@ Makefile.in /config.log /config.status /configure +/coverage /elfutils.spec /stamp-h1 /version.h @@ -1,3 +1,9 @@ +2021-01-12 Dmitry V. Levin <ldv@altlinux.org> + + * configure.ac [--enable-gcov]: Check for gcov, lcov, and genhtml. + * Makefile.am [GCOV] (coverage, coverage-clean): New targets. + * .gitignore: Update. + 2020-12-20 Dmitry V. Levin <ldv@altlinux.org> * .gitignore: Move subdirectory patterns to separate .gitignore files. diff --git a/Makefile.am b/Makefile.am index 818e3599..9c47afa9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -47,6 +47,57 @@ distcheck-hook: rpm: dist rpmbuild -ts --sign elfutils-@PACKAGE_VERSION@.tar.bz2 +if GCOV + +COVERAGE_OUTPUT_FILE = $(PACKAGE_NAME).lcov +COVERAGE_OUTPUT_DIRECTORY = coverage +COVERAGE_OUTPUT_INDEX_HTML = $(COVERAGE_OUTPUT_DIRECTORY)/index.html +COVERAGE_TITLE = $(PACKAGE_NAME)-$(PACKAGE_VERSION) + +COVERAGE_DIRS = $(filter-out tests,$(SUBDIRS)) +src_COVERAGE_DIRS = $(patsubst %,$(srcdir)/%,$(COVERAGE_DIRS)) +build_COVERAGE_DIRS = $(patsubst %,$(builddir)/%,$(COVERAGE_DIRS)) +all_COVERAGE_DIRS = $(sort $(src_COVERAGE_DIRS) $(build_COVERAGE_DIRS)) +LCOV_DIRS_ARGS = $(patsubst %,--directory=%,$(all_COVERAGE_DIRS)) + +CLEANFILES = $(COVERAGE_OUTPUT_FILE) + +.PHONY: coverage coverage-clean + +clean-local: coverage-clean +distclean-local: coverage-clean + +coverage-clean: + -rm -rf $(COVERAGE_OUTPUT_DIRECTORY) + +coverage: $(COVERAGE_OUTPUT_INDEX_HTML) + @echo 'file://$(abs_builddir)/$(COVERAGE_OUTPUT_INDEX_HTML)' + +$(COVERAGE_OUTPUT_INDEX_HTML): $(COVERAGE_OUTPUT_FILE) + LC_ALL=C $(GENHTML) \ + --legend \ + --show-details \ + --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)' \ + $< + +$(COVERAGE_OUTPUT_FILE): + $(LCOV) \ + --capture \ + --no-external \ + --no-checksum \ + --rc=lcov_branch_coverage=1 \ + --gcov-tool='$(GCOV)' \ + --output-file='$@' \ + $(LCOV_DIRS_ARGS) + +endif + # Tell version 3.79 and up of GNU make to not build goals in this # directory in parallel. .NOTPARALLEL: diff --git a/configure.ac b/configure.ac index 60747bc8..346ab800 100644 --- a/configure.ac +++ b/configure.ac @@ -311,6 +311,9 @@ if test "$use_gcov" = yes; then CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage" CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage" LDFLAGS="$LDFLAGS -fprofile-arcs" + AC_CHECK_PROG([GCOV], [gcov], [gcov]) + AC_CHECK_PROG([LCOV], [lcov], [lcov]) + AC_CHECK_PROG([GENHTML], [genhtml], [genhtml]) fi AM_CONDITIONAL(GCOV, test "$use_gcov" = yes) |