The following commit has been merged in the master branch:
commit 0581dda824f26e9eec996ebf4de5f6474336bec2
Author: Guillem Jover <[email protected]>
Date: Sun Jul 11 11:44:41 2010 +0200
build: Add optional code coverage support
Enable code coverage support with 'configure --enable-coverage'. Use
gcov and lcov for C code coverage, and Devel::Cover and cover for Perl
code coverage.
diff --git a/.gitignore b/.gitignore
index 4d48623..8052d2a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,10 @@
# Inherited ignores
*.a
*.o
+*.gcno
+*.gcda
+*.gcov
+*.lcov
.*.swp
.deps/
Makefile
diff --git a/Makecheck.am b/Makecheck.am
index b88c1ea..afeeefc 100644
--- a/Makecheck.am
+++ b/Makecheck.am
@@ -4,6 +4,7 @@
#
# TEST_VERBOSE - set to 0 or 1 to control test suite verbosity
# TEST_ENV_VARS - environment variables to be set for the test suite
+# TEST_COVERAGE - set to the perl module in charge of getting test coverage
# test_tmpdir - test suite temporary directory
# test_cases - list of test case files
# test_data - list of test data files
@@ -16,6 +17,7 @@ check-local: $(test_data) $(test_cases)
PATH="$(top_builddir)/src:$(top_builddir)/scripts:$(top_builddir)/utils:$(PATH)"
\
srcdir=$(srcdir) builddir=$(builddir) \
PERL5LIB=$(top_srcdir)/scripts PERL_DL_NONLAZY=1 \
+ PERL5OPT=$(TEST_COVERAGE) \
$(PERL) -I$(top_srcdir)/scripts \
-MExtUtils::Command::MM -e "test_harness($(TEST_VERBOSE), '.')" \
$(addprefix $(srcdir)/,$(test_cases))
diff --git a/Makefile.am b/Makefile.am
index b6d634e..a18c4e0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -72,9 +72,50 @@ EXTRA_DIST = \
doc: doc/Doxyfile
$(DOXYGEN) doc/Doxyfile
-clean-local:
+doc-clean:
rm -rf doc/html/
+# Code coverage support
+
+.PHONY: coverage coverage-clean
+
+if COVERAGE_ENABLED
+LCOV_OPTS = -q --checksum
+LCOV_CAPTURE_OPTS = $(LCOV_OPTS) --no-recursion \
+ -d $(top_builddir)/lib/dpkg \
+ -d $(top_builddir)/src \
+ -d $(top_builddir)/utils
+
+coverage: all
+ $(RM) -f *.lcov
+ find -name '*.gcda' -o -name '*.gcov' | xargs $(RM) -f
+
+ $(LCOV) $(LCOV_CAPTURE_OPTS) -c -o dpkg_base.lcov -i
+ $(MAKE) -C lib/dpkg check
+ $(MAKE) -C src check
+ $(MAKE) -C utils check
+ $(LCOV) $(LCOV_CAPTURE_OPTS) -c -o dpkg_test.lcov
+ $(LCOV) $(LCOV_OPTS) -a dpkg_base.lcov -a dpkg_test.lcov \
+ -o dpkg_merge.lcov
+ $(LCOV) $(LCOV_OPTS) -r dpkg_merge.lcov '/usr/include/*' -o dpkg.lcov
+ $(LCOV_GENHTML) -q --legend --title "dpkg C code coverage" \
+ --html-prolog $(top_srcdir)/doc/lcov-prolog \
+ --html-epilog $(top_srcdir)/doc/lcov-epilog \
+ -o doc/coverage dpkg.lcov
+
+ $(MAKE) -C scripts $@
+
+coverage-clean:
+ rm -rf doc/coverage/
+ find -name '*.gcno' -o -name '*.gcda' -o \
+ -name '*.gcov' -o -name '*.lcov' | xargs rm -f
+else
+coverage:
+ @echo "Need to reconfigure with --enable-coverage"
+
+coverage-clean:
+endif
+
.PHONY: update-po
update-po:
@@ -102,3 +143,4 @@ dist-hook:
done ; \
fi
+clean-local: doc-clean coverage-clean
diff --git a/configure.ac b/configure.ac
index 6d79ae5..b741769 100644
--- a/configure.ac
+++ b/configure.ac
@@ -91,6 +91,7 @@ AC_CHECK_PROG([HAVE_DOT], [dot], [YES], [NO])
DPKG_PROG_PO4A
DPKG_PROG_PERL
DPKG_PROG_POD2MAN
+DPKG_CODE_COVERAGE
# Checks for operating system services and capabilities.
AC_SYS_LARGEFILE
diff --git a/doc/.gitignore b/doc/.gitignore
index acdcabb..5211926 100644
--- a/doc/.gitignore
+++ b/doc/.gitignore
@@ -1,2 +1,3 @@
Doxyfile
html
+coverage
diff --git a/doc/lcov-epilog b/doc/lcov-epilog
new file mode 100644
index 0000000..8bc660c
--- /dev/null
+++ b/doc/lcov-epilog
@@ -0,0 +1,8 @@
+ <table width="100%" border=0 cellspacing=0 cellpadding=0>
+ <tr>
+ <td class="coverFile"><a href="scripts/coverage.html">scripts</a></td>
+ </tr>
+ </table>
+ <br />
+</body>
+</html>
diff --git a/doc/lcov-prolog b/doc/lcov-prolog
new file mode 100644
index 0000000..49f2a4b
--- /dev/null
+++ b/doc/lcov-prolog
@@ -0,0 +1,8 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html lang="en">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>@pagetitle@</title>
+ <link rel="stylesheet" type="text/css" href="@[email protected]">
+</head>
+<body>
diff --git a/m4/dpkg-coverage.m4 b/m4/dpkg-coverage.m4
new file mode 100644
index 0000000..7a18795
--- /dev/null
+++ b/m4/dpkg-coverage.m4
@@ -0,0 +1,51 @@
+# Copyright © 2010 Guillem Jover <[email protected]>
+
+# DPKG_CODE_COVERAGE
+# ------------------
+# Add configuration option to enable code coverage support.
+AC_DEFUN([DPKG_CODE_COVERAGE],
+[
+AC_ARG_ENABLE(coverage,
+ AS_HELP_STRING([--enable-coverage],
+ [whether to enable code coverage]),
+ [],
+ [enable_coverage=no])
+AM_CONDITIONAL(COVERAGE_ENABLED, test x$enable_coverage = xyes)
+
+if test "x$enable_coverage" = "xyes"; then
+ if test "x$GCC" = "xno"; then
+ AC_MSG_ERROR([not compiling with gcc, which is required for C coverage
support])
+ fi
+
+ AC_CHECK_PROGS([GCOV], [gcov])
+ if test -z "$GCOV"; then
+ AC_MSG_ERROR([missing gcov, which is required for C coverage support])
+ fi
+
+ AC_CHECK_PROGS([LCOV], [lcov])
+ if test -z "$LCOV"; then
+ AC_MSG_ERROR([missing lcov, which is required for C coverage support])
+ fi
+
+ AC_CHECK_PROGS([LCOV_GENHTML], [genhtml])
+ if test -z "$LCOV_GENHTML"; then
+ AC_MSG_ERROR([missing genhtml, which is required for C coverage support])
+ fi
+
+ CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
+ LDFLAGS="$LDFLAGS -fprofile-arcs -ftest-coverage"
+
+ AC_MSG_CHECKING([for Devel::Cover perl module])
+ if $($PERL -e "require Devel::Cover;" 2>/dev/null); then
+ PERL_COVERAGE="-MDevel::Cover"
+ AC_SUBST(PERL_COVERAGE)
+ AC_MSG_RESULT([ok])
+ else
+ AC_MSG_ERROR([Devel::Cover perl module is required for coverage support])
+ fi
+ AC_CHECK_PROGS([PERL_COVER], [cover])
+ if test -z "$PERL_COVER"; then
+ AC_MSG_ERROR([missing cover, which is required for perl coverage
support])
+ fi
+fi
+])
diff --git a/scripts/.gitignore b/scripts/.gitignore
index d12947c..380ad91 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -17,3 +17,4 @@ dpkg-source
dpkg-statoverride
dpkg-vendor
t.tmp
+cover_db
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 1661460..9b4d394 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -159,10 +159,17 @@ if BUILD_POD_DOC
done
endif
+coverage: check
+ $(PERL_COVER) -silent -outputdir $(top_builddir)/doc/coverage/scripts
+
+coverage-clean:
+ rm -rf cover_db
+
TEST_VERBOSE= 0
TEST_ENV_VARS = \
DPKG_DATADIR=$(srcdir)/.. \
DPKG_ORIGINS_DIR=$(srcdir)/t/origins
+TEST_COVERAGE = $(PERL_COVERAGE)
test_tmpdir = t.tmp
@@ -247,5 +254,5 @@ $(test_tmpdir)/200_Dpkg_Shlibs/objdump.patterns:
$(srcdir)/t/200_Dpkg_Shlibs/pat
include $(top_srcdir)/Makecheck.am
-clean-local: check-clean
+clean-local: check-clean coverage-clean
rm -fr man
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]