[libpeas: 6/18] Add a gcov make rule



commit 8313b080ee1f7929405c0cea31bfcf4aacff0ed4
Author: Garrett Regier <alias301 gmail com>
Date:   Thu Mar 3 03:21:41 2011 -0800

    Add a gcov make rule
    
    This generates .gcov files for C files in libpeas, libpeas-gtk and
    the loaders and then it reports the coverage for each of the libs.

 .gitignore                 |    1 +
 Makefile.am                |   22 +++++++++++++++++++++-
 Makefile.gcov              |   37 +++++++++++++++++++++++++++++++++++++
 configure.ac               |   34 ++++++++++++++++++++++++++++++++++
 libpeas-gtk/Makefile.am    |    7 ++++++-
 libpeas/Makefile.am        |   22 +++++++++++++---------
 loaders/Makefile.am        |    5 +++++
 loaders/c/Makefile.am      |    6 +++++-
 loaders/python/Makefile.am |    6 +++++-
 loaders/seed/Makefile.am   |    6 +++++-
 10 files changed, 132 insertions(+), 14 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 5a1ed21..768a5c3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,7 @@
 *~
 *.stamp
 .*.sw[nop]
+*.gcov
 .deps
 .libs
 Makefile
diff --git a/Makefile.am b/Makefile.am
index b7e1057..f5d5729 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,9 +3,11 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc --enable-introspection
 
 SUBDIRS = libpeas loaders
+GCOVDIRS = libpeas loaders
 
 if ENABLE_GTK
 SUBDIRS += libpeas-gtk peas-demo
+GCOVDIRS += libpeas-gtk
 endif
 
 SUBDIRS += tests data po docs
@@ -30,4 +32,22 @@ test test-gdb test-valgrind test-callgrind test-report perf-report full-report:
 demo: all
 	@cd peas-demo && $(MAKE) $(AM_MAKEFLAGS) $(@)
 
-.PHONY: all test test-gdb test-report perf-report full-report demo
+if GCOV_ENABLED
+
+gcov: test
+	@for dir in $(GCOVDIRS); do \
+	   (cd $$dir && $(MAKE) $(AM_MAKEFLAGS) $(@)); \
+	 done
+
+all-local:
+	@find . -name "*.gcda" -delete && find . -name "*.[ch].gcov" -delete
+
+else
+
+gcov:
+	@echo "You need to reconfigure with --enable-gcov"
+
+endif	# GCOV_ENABLED
+
+.PHONY: test test-gdb test-valgrind test-callgrind \
+        test-report perf-report full-report gcov demo
diff --git a/Makefile.gcov b/Makefile.gcov
new file mode 100644
index 0000000..1700b6f
--- /dev/null
+++ b/Makefile.gcov
@@ -0,0 +1,37 @@
+if GCOV_ENABLED
+
+gcov: all
+	@echo ""; \
+	 project=`basename $(abs_srcdir)`; \
+	 total_covered=0; \
+	 total_actual=0; \
+	 stats_length=`expr length "   9999 / 9999   100% "`; \
+	 filename_width=`expr 80 - 2 - $$stats_length`; \
+	 echo -e "Test coverage for $$project:\n"; \
+	 for file in $(filter %.c,$(gcov_sources)); do \
+		 gcov -o .libs/$${file/.c/.gcda} $$file > /dev/null; \
+		 if test -f $$file.gcov; then \
+		   actual=`grep -v ' -:' $$file.gcov | wc -l`; \
+		   uncovered=`grep '#####:' $$file.gcov | wc -l`; \
+		   covered=$$((actual - uncovered)); \
+		   percent=$$((($$covered * 100) / $$actual)); \
+		   total_covered=$$((total_covered + covered)); \
+		   total_actual=$$((total_actual + actual)); \
+		   filename=`echo $$file: | sed "s/^\.\///g"`; \
+	     printf "  %-*s   %4i / %4i   %3i%%\n" $$filename_width $$filename \
+	                                           $$covered $$actual $$percent; \
+		 fi \
+	 done; \
+	 printf "\nSource statements:  %4i" $$total_actual; \
+	 printf "\nCovered statements: %4i" $$total_covered; \
+	 printf "\nTotal coverage:     %3i%%\n" \
+	        $$((($$total_covered * 100) / $$total_actual)) 
+
+else
+
+gcov:
+	@echo "You need to reconfigure with --enable-gcov"
+
+endif	# GCOV_ENABLED
+
+.PHONY: gcov
diff --git a/configure.ac b/configure.ac
index 53615b5..69ab351 100644
--- a/configure.ac
+++ b/configure.ac
@@ -142,6 +142,39 @@ if test "$os_osx" = "yes"; then
 fi
 
 dnl ================================================================
+dnl Coverage testing
+dnl ================================================================
+
+AC_ARG_ENABLE([gcov],
+	      [AS_HELP_STRING([--enable-gcov],
+			      [Whether to enable coverage testing (requires gcc and gcov) [default=no]])],
+	      [enable_gcov=$enable_val],
+	      [enable_gcov=no])
+
+if test "x$enable_gcov" = "xno"; then
+        found_gcov="no (disabled, use --enable-gcov to enable)"
+        AC_MSG_CHECKING([whether to build with coverage testing])
+else
+        enable_gcov=yes
+        AC_PATH_PROG([GCOV], [gcov], [enable_gcov=no])
+        AC_MSG_CHECKING([whether to build with coverage testing])
+
+        if test "x$enable_gcov" = "xno"; then
+                AC_MSG_ERROR([You need gcov to build with coverage testing])
+        elif test "x$GCC" = "xno"; then
+                AC_MSG_ERROR([You need to use gcc to build with coverage testing])
+        else
+                GCOV_CFLAGS="-g -O0 -fprofile-arcs -ftest-coverage"
+                GCOV_LDFLAGS="-lgcov"
+        fi
+fi
+AC_MSG_RESULT([$enable_gcov])
+
+AM_CONDITIONAL([GCOV_ENABLED], [test "x$enable_gcov" = "xyes"])
+AC_SUBST([GCOV_CFLAGS])
+AC_SUBST([GCOV_LDFLAGS])
+
+dnl ================================================================
 dnl Glade
 dnl ================================================================
 
@@ -377,6 +410,7 @@ Configuration:
         Compiler                      : ${CC}
         Installation prefix           : ${prefix}
         Build libpeas-gtk             : ${enable_gtk}
+        Coverage testing              : ${enable_gcov}
         Glade Catalog                 : ${found_glade_catalog}
         Seed JS support               : ${found_seed}
         Python support                : ${found_python}
diff --git a/libpeas-gtk/Makefile.am b/libpeas-gtk/Makefile.am
index 94326b7..b6e1892 100644
--- a/libpeas-gtk/Makefile.am
+++ b/libpeas-gtk/Makefile.am
@@ -5,10 +5,12 @@ INCLUDES = \
 	-I$(srcdir)			\
 	$(PEAS_CFLAGS)			\
 	$(PEAS_GTK_CFLAGS)		\
+	$(GCOV_CFLAGS)			\
 	$(WARN_CFLAGS)			\
 	$(DISABLE_DEPRECATED)
 
 libpeas_gtk_1_0_la_LDFLAGS = \
+	$(GCOV_LDFLAGS) \
 	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
 	-export-dynamic -no-undefined -export-symbols-regex "^[^_].*"
 
@@ -29,8 +31,8 @@ NOINST_H_FILES = \
 
 C_FILES = \
 	peas-gtk-configurable.c			\
-	peas-gtk-plugin-manager.c		\
 	peas-gtk-disable-plugins-dialog.c	\
+	peas-gtk-plugin-manager.c		\
 	peas-gtk-plugin-manager-store.c		\
 	peas-gtk-plugin-manager-view.c
 
@@ -71,3 +73,6 @@ if HAVE_INTROSPECTION
 
   CLEANFILES = $(gir_DATA) $(typelib_DATA)
 endif
+
+gcov_sources = $(C_FILES)
+include $(top_srcdir)/Makefile.gcov
diff --git a/libpeas/Makefile.am b/libpeas/Makefile.am
index 340ade0..3e744b7 100644
--- a/libpeas/Makefile.am
+++ b/libpeas/Makefile.am
@@ -5,12 +5,14 @@ INCLUDES =								\
 	-I$(srcdir)							\
 	$(PEAS_CFLAGS)							\
 	$(IGE_MAC_CFLAGS)						\
+	$(GCOV_CFLAGS)							\
 	$(WARN_CFLAGS)							\
 	$(DISABLE_DEPRECATED)						\
 	-DDATADIR=\""$(datadir)"\"					\
 	-DLIBDIR=\""$(libdir)"\"
 
 libpeas_1_0_la_LDFLAGS = \
+	$(GCOV_LDFLAGS) \
 	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
 	-export-dynamic -no-undefined -export-symbols-regex "^[^_].*"
 
@@ -39,20 +41,20 @@ NOINST_H_FILES =			\
 	peas-plugin-loader.h
 
 C_FILES =				\
+	peas-activatable.c		\
 	peas-debug.c			\
 	peas-dirs.c			\
+	peas-engine.c			\
+	peas-extension.c		\
+	peas-extension-base.c		\
+	peas-extension-set.c		\
+	peas-extension-subclasses.c	\
 	peas-helpers.c			\
 	peas-i18n.c			\
-	peas-object-module.c		\
 	peas-introspection.c		\
+	peas-object-module.c		\
 	peas-plugin-info.c		\
-	peas-plugin-loader.c		\
-	peas-extension-base.c		\
-	peas-extension.c		\
-	peas-extension-set.c		\
-	peas-extension-subclasses.c	\
-	peas-activatable.c		\
-	peas-engine.c
+	peas-plugin-loader.c
 
 BUILT_SOURCES = \
 	peas-marshal.c			\
@@ -106,5 +108,7 @@ if HAVE_INTROSPECTION
   CLEANFILES += \
 	$(gir_DATA)		\
 	$(typelib_DATA)
-
 endif
+
+gcov_sources = $(C_FILES)
+include $(top_srcdir)/Makefile.gcov
diff --git a/loaders/Makefile.am b/loaders/Makefile.am
index 913f6b6..6e6c67a 100644
--- a/loaders/Makefile.am
+++ b/loaders/Makefile.am
@@ -7,3 +7,8 @@ endif
 if ENABLE_SEED
 SUBDIRS += seed
 endif
+
+gcov:
+	@for dir in $(SUBDIRS); do \
+	   (cd $$dir && $(MAKE) $(AM_MAKEFLAGS) $(@)); \
+	 done
diff --git a/loaders/c/Makefile.am b/loaders/c/Makefile.am
index 88aa841..dedece8 100644
--- a/loaders/c/Makefile.am
+++ b/loaders/c/Makefile.am
@@ -5,6 +5,7 @@ loaderdir = $(libdir)/libpeas-1.0/loaders
 INCLUDES = \
 	-I$(top_srcdir)			\
 	$(PEAS_CFLAGS)			\
+	$(GCOV_CFLAGS)			\
 	$(WARN_CFLAGS)			\
 	$(DISABLE_DEPRECATED)
 
@@ -16,5 +17,8 @@ libcloader_la_SOURCES = \
 	peas-plugin-loader-c.c 	\
 	peas-plugin-loader-c.h
 
-libcloader_la_LDFLAGS = $(LOADER_LIBTOOL_FLAGS)
+libcloader_la_LDFLAGS = $(LOADER_LIBTOOL_FLAGS) $(GCOV_LDFLAGS)
 libcloader_la_LIBADD = $(PEAS_LIBS)
+
+gcov_sources = $(libcloader_la_SOURCES)
+include $(top_srcdir)/Makefile.gcov
diff --git a/loaders/python/Makefile.am b/loaders/python/Makefile.am
index a9a966d..b95ecd8 100644
--- a/loaders/python/Makefile.am
+++ b/loaders/python/Makefile.am
@@ -5,6 +5,7 @@ loaderdir = $(libdir)/libpeas-1.0/loaders
 INCLUDES = \
 	-I$(top_srcdir)			\
 	$(PEAS_CFLAGS)			\
+	$(GCOV_CFLAGS)			\
 	$(WARN_CFLAGS)			\
 	$(DISABLE_DEPRECATED)		\
 	$(PYGTK_CFLAGS)			\
@@ -21,7 +22,8 @@ libpythonloader_la_SOURCES = \
 	peas-plugin-loader-python.h
 
 libpythonloader_la_LDFLAGS = \
-	$(LOADER_LIBTOOL_FLAGS)
+	$(LOADER_LIBTOOL_FLAGS)	\
+	$(GCOV_LDFLAGS)
 
 libpythonloader_la_LIBADD = \
 	$(PEAS_LIBS)			\
@@ -30,3 +32,5 @@ libpythonloader_la_LIBADD = \
 	$(PYTHON_EXTRA_LIBS)		\
 	$(PYGTK_LIBS)
 
+gcov_sources = $(libpythonloader_la_SOURCES)
+include $(top_srcdir)/Makefile.gcov
diff --git a/loaders/seed/Makefile.am b/loaders/seed/Makefile.am
index b707859..75566c0 100644
--- a/loaders/seed/Makefile.am
+++ b/loaders/seed/Makefile.am
@@ -5,6 +5,7 @@ loaderdir = $(libdir)/libpeas-1.0/loaders
 INCLUDES = \
 	-I$(top_srcdir)			\
 	$(PEAS_CFLAGS)			\
+	$(GCOV_CFLAGS)			\
 	$(WARN_CFLAGS)			\
 	$(DISABLE_DEPRECATED)		\
 	$(SEED_CFLAGS)
@@ -17,5 +18,8 @@ libseedloader_la_SOURCES = \
 	peas-plugin-loader-seed.c 	\
 	peas-plugin-loader-seed.h
 
-libseedloader_la_LDFLAGS = $(LOADER_LIBTOOL_FLAGS)
+libseedloader_la_LDFLAGS = $(LOADER_LIBTOOL_FLAGS) $(GCOV_LDFLAGS)
 libseedloader_la_LIBADD = $(PEAS_LIBS) $(SEED_LIBS)
+
+gcov_sources = $(libseedloader_la_SOURCES)
+include $(top_srcdir)/Makefile.gcov



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]