diff --git a/Makefile.am b/Makefile.am --- a/Makefile.am +++ b/Makefile.am @@ -73,3 +73,37 @@ stowinstall: $(MAKE) $(AM_MAKEFLAGS) install prefix=/usr/local/stow/libksba + +# Coverage targets + +if HAVE_GCOV + +.PHONY: clean-gcda +clean-gcda: + @echo Removing old coverage results + -find -name '*.gcda' -print | xargs -r rm + -find -name '*.gcno' -print | xargs -r rm + +.PHONY: coverage-html generate-coverage-html clean-coverage-html +#coverage-html: clean-gcda +coverage-html: + $(MAKE) $(AM_MAKEFLAGS) -k check + $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html + +generate-coverage-html: + @echo Collecting coverage data with lcov + $(LCOV) --gcov-tool $(GCOV) -b src --directory $(builddir)/src --capture --output-file coverage.info.src --no-checksum --compat-libtool --rc lcov_branch_coverage=1 + $(LCOV) --gcov-tool $(GCOV) -b tests --directory $(builddir)/tests --capture --output-file coverage.info.tests --no-checksum --compat-libtool --rc lcov_branch_coverage=1 + $(LCOV) -a coverage.info.src -a coverage.info.tests --output-file coverage.info --no-checksum --rc lcov_branch_coverage=1 + $(LCOV) --remove coverage.info "/usr*" -o coverage.info --rc lcov_branch_coverage=1 + $(LCOV) --remove coverage.info "/opt*" -o coverage.info --rc lcov_branch_coverage=1 + $(LCOV) --remove coverage.info "*/tests/*" -o coverage.info --rc lcov_branch_coverage=1 + LANG=C $(GENHTML) --prefix $(builddir)/src --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info --rc lcov_branch_coverage=1 + +clean-coverage-html: clean-gcda + -$(LCOV) --directory $(builddir)/src -z + -$(LCOV) --directory $(builddir)/test -z + -rm -rf coverage.info coveragereport + +clean-local: clean-coverage-html +endif # HAVE_GCOV diff --git a/README.GIT b/README.GIT --- a/README.GIT +++ b/README.GIT @@ -47,3 +47,7 @@ maintainer should also make sure that the required version of automake et al. are properly indicated at the top of configure.ac and take care to copy the files and not merely use symlinks. + +In order to generate coverage information, compile with --enable-gcov. +You need to install lcov for this. Running "make coverage-html" will +generate a coverage report in coveragereport/index.html. diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -127,6 +127,12 @@ AC_PROG_YACC AX_PROG_BISON([have_bison=yes],[have_bison=no]) +# gcov coverage reporting +AC_CHECK_PROGS(GCOV, [gcov], gcov) +AC_TDD_GCOV +AC_SUBST(COVERAGE_CFLAGS) +AC_SUBST(COVERAGE_LDFLAGS) + AC_C_INLINE # We need to compile and run a program on the build machine. diff --git a/m4/Makefile.am b/m4/Makefile.am --- a/m4/Makefile.am +++ b/m4/Makefile.am @@ -1,5 +1,5 @@ EXTRA_DIST = autobuild.m4 gnupg-typedef.m4 gpg-error.m4 libgcrypt.m4 \ - libtool.m4 ax_prog_bison.m4 + libtool.m4 ax_prog_bison.m4 gcov.m4 diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,7 +36,7 @@ DISTCLEANFILES = asn1-tables.c AM_CPPFLAGS = -I$(top_builddir)/gl -I$(top_srcdir)/gl -AM_CFLAGS = $(GPG_ERROR_CFLAGS) +AM_CFLAGS = $(GPG_ERROR_CFLAGS) $(COVERAGE_CFLAGS) if HAVE_LD_VERSION_SCRIPT @@ -82,7 +82,8 @@ libksba_la_LDFLAGS = $(no_undefined) $(export_symbols) $(extra_ltoptions) \ $(libksba_version_script_cmd) -version-info \ - @LIBKSBA_LT_CURRENT@:@LIBKSBA_LT_REVISION@:@LIBKSBA_LT_AGE@ + @LIBKSBA_LT_CURRENT@:@LIBKSBA_LT_REVISION@:@LIBKSBA_LT_AGE@ \ + $(COVERAGE_LDFLAGS) libksba_la_INCLUDES = -I$(top_srcdir)/lib libksba_la_DEPENDENCIES = $(srcdir)/libksba.vers $(ksba_deps) libksba_la_LIBADD = $(ksba_res) @LTLIBOBJS@ @GPG_ERROR_LIBS@ diff --git a/tests/Makefile.am b/tests/Makefile.am --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -41,8 +41,8 @@ TESTS = cert-basic t-crl-parser t-dnparser t-oid t-reader -AM_CFLAGS = $(GPG_ERROR_CFLAGS) -AM_LDFLAGS = -no-install +AM_CFLAGS = $(GPG_ERROR_CFLAGS) $(COVERAGE_CFLAGS) +AM_LDFLAGS = -no-install $(COVERAGE_LDFLAGS) noinst_HEADERS = t-common.h noinst_PROGRAMS = $(TESTS) t-cms-parser t-crl-parser t-dnparser t-ocsp