[glom] Added a "make gcov" target to get some test coverage statistics.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Added a "make gcov" target to get some test coverage statistics.
- Date: Fri, 25 Nov 2011 09:59:07 +0000 (UTC)
commit 26010acee6f7c0e25b3395298fa6c6ebe16c2f6b
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Nov 25 10:58:51 2011 +0100
Added a "make gcov" target to get some test coverage statistics.
* configure.ac: Add an --enable-gcov option which add gcc/g++ flags.
* Makefile_glom.am:
* Makefile_libglom.am:
* Makefile.am: Add some cargo-culted and hacked-together bash scripted
rules that generate the .gcov files and parse them to give some
percentages on stdout.
.gitignore | 4 +++
ChangeLog | 11 +++++++++
Makefile.am | 58 +++++++++++++++++++++++++++++++++++++++++++++++++-
Makefile_glom.am | 2 +-
Makefile_libglom.am | 4 +-
configure.ac | 21 ++++++++++++++++++
6 files changed, 95 insertions(+), 5 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 7693d48..660f4aa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,10 @@
*.a
*.la
*~
+*.gcno
+*.gcda
+*.gcov
+/gcov-report.txt
.deps
.dirstamp
diff --git a/ChangeLog b/ChangeLog
index 2ba5e8c..44b9b4f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-11-25 Murray Cumming <murrayc murrayc com>
+
+ Added a "make gcov" target to get some test coverage statistics.
+
+ * configure.ac: Add an --enable-gcov option which add gcc/g++ flags.
+ * Makefile_glom.am:
+ * Makefile_libglom.am:
+ * Makefile.am: Add some cargo-culted and hacked-together bash scripted
+ rules that generate the .gcov files and parse them to give some
+ percentages on stdout.
+
2011-11-23 Murray Cumming <murrayc murrayc com>
Avoid deprecated glibmm API (from glibmm/thread.h).
diff --git a/Makefile.am b/Makefile.am
index 9a145d0..de3bf85 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -78,6 +78,59 @@ endif
include Makefile_tests.am
+#We must do this so we can use += later:
+MAINTAINERCLEANFILES =
+
+# gcov
+if GCOV_ENABLED
+gcov-report.txt: gcov-clean all check
+ $(AM_V_GEN)(rm -f $@; \
+ echo -e "Test coverage:\n" >> $@; \
+ total_covered=0; total_actual=0; \
+ for file in $(filter %.cc,$(glom_glom_SOURCES) $(libglom_sources)); do \
+ file_basename=$${file##*/}; \
+ file_basename_gcda="*-$${file_basename/.cc/.gcda}"; \
+ file_o=`find -newer $$file -name $${file_basename_gcda} | sed -e 's/\.gcda/\.o/'`; \
+ if [ -z $file_o ]; then \
+ echo "Glom: gcov input file (.o) not found."; \
+ else \
+ gcov -o $$file_o $$file_basename > /dev/null; \
+ file_gcov=$$file_basename.gcov; \
+ if test -f $$file_gcov; then \
+ actual=`grep -v ' -:' $$file_basename.gcov | wc -l`; \
+ uncovered=`grep '#####:' $$file_basename.gcov | wc -l`; \
+ covered=$$((actual - uncovered)); \
+ total_covered=$$((total_covered + covered)); \
+ total_actual=$$((total_actual + actual)); \
+ if [ -z $$actual ]; then \
+ echo "Glom: gcov failure: actual is 0"; \
+ else \
+ echo -e "$$file:\t$$covered / $$actual\t($$((($$covered * 100) / $$actual))%)"; \
+ fi \
+ else \
+ echo "generated gcov file not found: $$file_gcov"; \
+ fi \
+ fi \
+ done >> $@; \
+ cd $(abs_srcdir); \
+ echo -e "\nSource lines: $$total_actual\nCovered statements: $$total_covered\nTotal coverage: $$((($$total_covered * 100) / $$total_actual))%" >> $@)
+
+gcov: gcov-report.txt
+ @cat gcov-report.txt
+
+clean: gcov-clean
+gcov-clean:
+ @find . -name "*.gcda" -o -name "*.gcov" -delete
+
+MAINTAINERCLEANFILES += gcov-report.txt
+gcov_phony_files = gcov gcov-clean gcov-report.txt
+else
+gcov:
+ @echo "Need to reconfigure with --enable-gcov"
+endif
+
+
+
dist_pkgdata_DATA = glom/glom_document.dtd
@@ -212,7 +265,7 @@ dist_noinst_SCRIPTS += autogen.sh win32/build-installer
CLEANFILES = $(dbusservice_DATA) $(desktop_DATA) $(win_resfile)
DISTCLEANFILES = intltool-extract intltool-merge intltool-update
-MAINTAINERCLEANFILES = \
+MAINTAINERCLEANFILES += \
$(dist_docutils) $(dist_intltool) \
macros/gnome-doc-utils.m4 macros/intltool.m4 \
macros/libtool.m4 macros/ltoptions.m4 macros/ltsugar.m4 \
@@ -253,7 +306,8 @@ endif
@INTLTOOL_DESKTOP_RULE@
.PHONY: install-update-icon-cache uninstall-update-icon-cache \
- install-update-mime-database uninstall-update-mime-database
+ install-update-mime-database uninstall-update-mime-database \
+ $(gcov_phony_files)
# Instruct GNU make to delete the targets of a rule after it failed, in
# order to avoid the complication of handling that situation manually.
diff --git a/Makefile_glom.am b/Makefile_glom.am
index cf1ae7b..b756d3f 100644
--- a/Makefile_glom.am
+++ b/Makefile_glom.am
@@ -26,7 +26,7 @@ glom_includes += -I$(top_srcdir)/glom/utility_widgets/gimpruler
bin_PROGRAMS += glom/glom
-glom_glom_CPPFLAGS = $(glom_includes) $(GLOM_CFLAGS) $(PYTHON_CPPFLAGS) $(BOOST_PYTHON_CFLAGS) $(glom_defines)
+glom_glom_CPPFLAGS = $(glom_includes) $(GLOM_CFLAGS) $(PYTHON_CPPFLAGS) $(BOOST_PYTHON_CFLAGS) $(GCOV_CFLAGS) $(glom_defines)
glom_eggspreadtable_files = \
glom/utility_widgets/eggspreadtable/eggmarshalers.c \
diff --git a/Makefile_libglom.am b/Makefile_libglom.am
index ed9f554..f72976b 100644
--- a/Makefile_libglom.am
+++ b/Makefile_libglom.am
@@ -47,7 +47,7 @@ libglom_d_b_view_include_HEADERS = $(libglom_d_b_view_headers)
glom_libglom_libglom_ GLOM_ABI_VERSION@_la_SOURCES = $(libglom_sources)
-libglom_all_libs = $(LIBGLOM_LIBS) $(PYTHON_LIBS) $(BOOST_PYTHON_LIBS)
+libglom_all_libs = $(LIBGLOM_LIBS) $(PYTHON_LIBS) $(BOOST_PYTHON_LIBS) $(GCOV_CFLAGS)
glom_libglom_libglom_ GLOM_ABI_VERSION@_la_LIBADD = $(libglom_all_libs)
if HOST_WIN32
@@ -55,7 +55,7 @@ glom_libglom_libglom_ GLOM_ABI_VERSION@_la_LIBADD += -lws2_32
endif
glom_libglom_libglom_ GLOM_ABI_VERSION@_la_LDFLAGS = -no-undefined
-glom_libglom_libglom_ GLOM_ABI_VERSION@_la_CPPFLAGS = $(glom_includes) $(LIBGLOM_CFLAGS) $(PYTHON_CPPFLAGS) $(BOOST_PYTHON_CFLAGS) $(libglom_defines)
+glom_libglom_libglom_ GLOM_ABI_VERSION@_la_CPPFLAGS = $(glom_includes) $(LIBGLOM_CFLAGS) $(PYTHON_CPPFLAGS) $(BOOST_PYTHON_CFLAGS) $(GCOV_CFLAGS) $(libglom_defines)
pyexec_LTLIBRARIES = glom/python_embed/python_module/glom_ GLOM_ABI_VERSION_UNDERLINED@.la
diff --git a/configure.ac b/configure.ac
index 849ab68..779d20b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -270,6 +270,27 @@ AC_CHECK_PROG([GLOM_GZIP], [gzip], [yes], [no])
AS_IF([test "$GLOM_GZIP" = no],
[AC_MSG_ERROR([gzip not found. Glom needs this to create backup files.])])
+
+# Code testing coverage with gcov
+AC_MSG_CHECKING(whether to build with gcov testing)
+AC_ARG_ENABLE(gcov, AS_HELP_STRING([--enable-gcov], [Whether to enable gcov testing]),, enable_gcov=no)
+
+if test "x$enable_gcov" = "xyes"; then
+ if test "$GCC" = "no"; then
+ AC_MSG_ERROR(not compiling with gcc, which is required for gcov testing)
+ fi
+
+ GCOV_CFLAGS="-fprofile-arcs -ftest-coverage"
+ GCOV_LIBS="-lgcov"
+
+ AC_SUBST(GCOV_CFLAGS)
+ AC_SUBST(GCOV_LIBS)
+fi
+
+AM_CONDITIONAL(GCOV_ENABLED, test x$enable_gcov = xyes)
+AC_MSG_RESULT($enable_gcov)
+
+
AC_CONFIG_FILES([Makefile
docs/user-guide/Makefile
po/Makefile.in
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]