Revision: 1158
http://vcs.pcre.org/viewvc?view=rev&revision=1158
Author: chpe
Date: 2012-10-22 20:43:50 +0100 (Mon, 22 Oct 2012)
Log Message:
-----------
build: Add code coverage reporting
Add --enable-coverage which uses gcov/lcov to generate a code coverage report
from the test suite.
http://bugs.exim.org/show_bug.cgi?id=1266
Modified Paths:
--------------
code/trunk/.gitignore
code/trunk/Makefile.am
code/trunk/configure.ac
code/trunk/doc/pcrebuild.3
Modified: code/trunk/.gitignore
===================================================================
--- code/trunk/.gitignore 2012-10-21 17:22:30 UTC (rev 1157)
+++ code/trunk/.gitignore 2012-10-22 19:43:50 UTC (rev 1158)
@@ -10,6 +10,7 @@
/configure
/depcomp
/.deps
+/dftables
/*.gcda
/*.gcno
/INSTALL
@@ -21,6 +22,7 @@
/*.lo
/ltmain.sh
/m4/
+/maint/ucptest
/Makefile
/Makefile.in
/missing
@@ -32,8 +34,8 @@
/pcrecpp_unittest
pcregrep
/pcre.h
-/pcre-lcov.info
-/pcre-lcov/
+/pcre-*-coverage.info
+/pcre-*-coverage/
/pcre_jit_test
/pcre_scanner_unittest
/pcre_stringpiece.h
Modified: code/trunk/Makefile.am
===================================================================
--- code/trunk/Makefile.am 2012-10-21 17:22:30 UTC (rev 1157)
+++ code/trunk/Makefile.am 2012-10-22 19:43:50 UTC (rev 1158)
@@ -344,6 +344,18 @@
endif # WITH_PCRE32
endif # WITH_VALGRIND
+if WITH_GCOV
+if WITH_PCRE8
+libpcre_la_CFLAGS += $(GCOV_CFLAGS)
+endif # WITH_PCRE8
+if WITH_PCRE16
+libpcre16_la_CFLAGS += $(GCOV_CFLAGS)
+endif # WITH_PCRE16
+if WITH_PCRE32
+libpcre32_la_CFLAGS += $(GCOV_CFLAGS)
+endif # WITH_PCRE32
+endif # WITH_GCOV
+
CLEANFILES += pcre_chartables.c
## If JIT support is enabled, arrange for the JIT test program to run.
@@ -351,6 +363,7 @@
TESTS += pcre_jit_test
noinst_PROGRAMS += pcre_jit_test
pcre_jit_test_SOURCES = pcre_jit_test.c
+pcre_jit_test_CFLAGS = $(AM_CFLAGS)
pcre_jit_test_LDADD =
if WITH_PCRE8
pcre_jit_test_LDADD += libpcre.la
@@ -361,15 +374,26 @@
if WITH_PCRE32
pcre_jit_test_LDADD += libpcre32.la
endif # WITH_PCRE32
+if WITH_GCOV
+pcre_jit_test_CFLAGS += $(GCOV_CFLAGS)
+pcre_jit_test_LDADD += $(GCOV_LIBS)
+endif # WITH_GCOV
endif # WITH_JIT
## A version of the main pcre library that has a posix re API.
if WITH_PCRE8
+
lib_LTLIBRARIES += libpcreposix.la
libpcreposix_la_SOURCES = \
pcreposix.c
+libpcreposix_la_CFLAGS = $(AM_CFLAGS)
libpcreposix_la_LDFLAGS = $(EXTRA_LIBPCREPOSIX_LDFLAGS)
libpcreposix_la_LIBADD = libpcre.la
+
+if WITH_GCOV
+libpcreposix_la_CFLAGS += $(GCOV_CFLAGS)
+endif # WITH_GCOV
+
endif # WITH_PCRE8
## There's a C++ library as well.
@@ -381,24 +405,35 @@
pcrecpp.cc \
pcre_scanner.cc \
pcre_stringpiece.cc
+libpcrecpp_la_CXXFLAGS = $(AM_CXXFLAGS)
libpcrecpp_la_LDFLAGS = $(EXTRA_LIBPCRECPP_LDFLAGS)
libpcrecpp_la_LIBADD = libpcre.la
TESTS += pcrecpp_unittest
noinst_PROGRAMS += pcrecpp_unittest
pcrecpp_unittest_SOURCES = pcrecpp_unittest.cc
+pcrecpp_unittest_CXXFLAGS = $(AM_CXXFLAGS)
pcrecpp_unittest_LDADD = libpcrecpp.la
TESTS += pcre_scanner_unittest
noinst_PROGRAMS += pcre_scanner_unittest
pcre_scanner_unittest_SOURCES = pcre_scanner_unittest.cc
+pcre_scanner_unittest_CXXFLAGS = $(AM_CXXFLAGS)
pcre_scanner_unittest_LDADD = libpcrecpp.la
TESTS += pcre_stringpiece_unittest
noinst_PROGRAMS += pcre_stringpiece_unittest
pcre_stringpiece_unittest_SOURCES = pcre_stringpiece_unittest.cc
+pcre_stringpiece_unittest_CXXFLAGS = $(AM_CXXFLAGS)
pcre_stringpiece_unittest_LDADD = libpcrecpp.la
+if WITH_GCOV
+libpcrecpp_la_CXXFLAGS += $(GCOV_CXXFLAGS)
+pcrecpp_unittest_LDADD += $(GCOV_LIBS)
+pcre_scanner_unittest_LDADD += $(GCOV_LIBS)
+pcre_stringpiece_unittest_LDADD += $(GCOV_LIBS)
+endif # WITH_GCOV
+
endif # WITH_PCRE_CPP
## The main unit tests
@@ -428,14 +463,23 @@
if WITH_VALGRIND
pcretest_CFLAGS += $(VALGRIND_CFLAGS)
endif # WITH_VALGRIND
+if WITH_GCOV
+pcretest_CFLAGS += $(GCOV_CFLAGS)
+pcretest_LDADD += $(GCOV_LIBS)
+endif # WITH_GCOV
if WITH_PCRE8
TESTS += RunGrepTest
dist_noinst_SCRIPTS += RunGrepTest
bin_PROGRAMS += pcregrep
pcregrep_SOURCES = pcregrep.c
+pcregrep_CFLAGS = $(AM_CFLAGS)
pcregrep_LDADD = $(LIBZ) $(LIBBZ2)
pcregrep_LDADD += libpcre.la libpcreposix.la
+if WITH_GCOV
+pcregrep_CFLAGS += $(GCOV_CFLAGS)
+pcregrep_LDADD += $(GCOV_LIBS)
+endif # WITH_GCOV
endif # WITH_PCRE8
EXTRA_DIST += \
@@ -677,6 +721,58 @@
man_MANS = $(pcrecpp_man)
endif
+# gcov/lcov code coverage reporting
+
+GCOV_NAME ?= $(PACKAGE)-$(VERSION)
+GCOV_OUTPUT_FILE ?= $(GCOV_NAME)-coverage.info
+GCOV_OUTPUT_DIR ?= $(GCOV_NAME)-coverage
+GCOV_LCOV_FLAGS ?=
+GCOV_GENHTML_FLAGS ?=
+
+gcov_quiet = $(gcov_quiet_$(V))
+gcov_quiet_ = $(gcov_quiet_$(AM_DEFAULT_VERBOSITY))
+gcov_quiet_0 = --quiet
+
+coverage-check: all
+ -$(MAKE) $(AM_MAKEFLAGS) -k check
+
+coverage-report:
+ $(LCOV) $(gcov_quiet) \
+ --directory $(top_builddir) \
+ --capture \
+ --output-file "$(GCOV_OUTPUT_FILE).tmp" \
+ --test-name "$(GCOV_NAME)" \
+ --no-checksum \
+ --compat-libtool \
+ $(GCOV_LCOV_FLAGS)
+ $(LCOV) $(gcov_quiet) \
+ --directory $(top_builddir) \
+ --output-file "$(GCOV_OUTPUT_FILE)" \
+ --remove "$(GCOV_OUTPUT_FILE).tmp" \
+ "/tmp/*" \
+ "/usr/include/*" \
+ "$(includedir)/*"
+ -@rm -f "$(GCOV_OUTPUT_FILE).tmp"
+ LANG=C $(GENHTML) $(gcov_quiet) \
+ --prefix $(top_builddir) \
+ --output-directory "$(GCOV_OUTPUT_DIR)" \
+ --title "$(PACKAGE) $(VERSION) Code Coverage Report" \
+ --show-details "$(GCOV_OUTPUT_FILE)" \
+ --legend \
+ $(GCOV_GENHTML_FLAGS)
+ @echo "Code coverage report written to file://$(abs_builddir)/$(GCOV_OUTPUT_DIR)/index.html"
+
+coverage-clean:
+ -$(LCOV) $(gcov_quiet) --zerocounters --directory $(top_builddir)
+ -rm -f "$(GCOV_OUTPUT_FILE)"
+ -rm -f "$(GCOV_OUTPUT_FILE).tmp"
+ -rm -rf "$(GCOV_NAME)"
+ -find $(top_builddir) -name '*.gcda' -o -name "*.gcov" -delete
+
+coverage: coverage-check coverage-report
+clean-local: coverage-clean
+distclean-local: coverage-clean
+
## CMake support
EXTRA_DIST += \
Modified: code/trunk/configure.ac
===================================================================
--- code/trunk/configure.ac 2012-10-21 17:22:30 UTC (rev 1157)
+++ code/trunk/configure.ac 2012-10-22 19:43:50 UTC (rev 1158)
@@ -291,6 +291,12 @@
[valgrind support]),
, enable_valgrind=no)
+# Enable code coverage reports using gcov
+AC_ARG_ENABLE(coverage,
+ AS_HELP_STRING([--enable-coverage],
+ [enable code coverage reports using gcov]),
+ , enable_coverage=no)
+
# Copy enable_utf8 value to enable_utf for compatibility reasons
if test "x$enable_utf8" != "xunset"
then
@@ -937,6 +943,52 @@
[AC_MSG_ERROR([pkg-config not supported])])
fi
+# test code coverage reporting
+if test "$enable_coverage" = "yes"; then
+ if test "x$GCC" != "xyes"; then
+ AC_MSG_ERROR([Code coverage reports can only be generated when using GCC])
+ fi
+
+ # ccache is incompatible with gcov
+ AC_PATH_PROG([SHTOOL],[shtool],[false])
+ case `$SHTOOL path $CC` in
+ *ccache*) cc_ccache=yes;;
+ *) cc_ccache=no;;
+ esac
+
+ if test "$cc_ccache" = "yes"; then
+ if test -z "$CCACHE_DISABLE" -o "$CCACHE_DISABLE" != "1"; then
+ AC_MSG_ERROR([must export CCACHE_DISABLE=1 to disable ccache for code coverage])
+ fi
+ fi
+
+ AC_ARG_VAR([LCOV],[the ltp lcov program])
+ AC_PATH_PROG([LCOV],[lcov],[false])
+ if test "x$LCOV" = "xfalse"; then
+ AC_MSG_ERROR([lcov not found])
+ fi
+
+ AC_ARG_VAR([GENHTML],[the ltp genhtml program])
+ AC_PATH_PROG([GENHTML],[genhtml],[false])
+ if test "x$GENHTML" = "xfalse"; then
+ AC_MSG_ERROR([genhtml not found])
+ fi
+
+ AC_DEFINE([SUPPORT_GCOV],[1], [
+ Define to allow pcregrep to be linked with gcov, so that it is
+ able to generate code coverage reports.])
+
+ # And add flags needed for gcov
+ GCOV_CFLAGS="-O0 -ggdb3 -fprofile-arcs -ftest-coverage"
+ GCOV_CXXFLAGS="-O0 -ggdb3 -fprofile-arcs -ftest-coverage"
+ GCOV_LIBS="-lgcov"
+ AC_SUBST([GCOV_CFLAGS])
+ AC_SUBST([GCOV_CXXFLAGS])
+ AC_SUBST([GCOV_LIBS])
+fi # enable_coverage
+
+AM_CONDITIONAL([WITH_GCOV],[test "x$enable_coverage" = "xyes"])
+
# Produce these files, in addition to config.h.
AC_CONFIG_FILES(
Makefile
@@ -1012,6 +1064,7 @@
Link pcretest with libedit ...... : ${enable_pcretest_libedit}
Link pcretest with libreadline .. : ${enable_pcretest_libreadline}
Valgrind support ................ : ${enable_valgrind}
+ Code coverage ................... : ${enable_coverage}
EOF
Modified: code/trunk/doc/pcrebuild.3
===================================================================
--- code/trunk/doc/pcrebuild.3 2012-10-21 17:22:30 UTC (rev 1157)
+++ code/trunk/doc/pcrebuild.3 2012-10-22 19:43:50 UTC (rev 1158)
@@ -437,6 +437,26 @@
memory accesses, and is mostly useful for debugging PCRE itself.
.
.
+.SH "CODE COVERAGE REPORTING"
+.rs
+.sp
+The build process can generate a code coverage report for the test suite.
+To enable this, you must install \fBlcov\fP version 1.6 or above. Then use
+.sp
+ --enable-coverage
+.sp
+to the \fBconfigure\fP command, and generate the report by running
+.sp
+ make coverage
+.sp
+Note that using \fBccache\fP is incompatible with code coverage reporting;
+you must set the environment variable
+.sp
+ CCACHE_DISABLE=1
+.sp
+before running make.
+.
+.
.SH "SEE ALSO"
.rs
.sp