[json-glib] Add GCOV coverage test support



commit 5b4186eb60e953ddbaadcd53b1996d28b06d4a97
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Tue Dec 29 22:53:29 2009 +0000

    Add GCOV coverage test support
    
    Use GCOV, a GCC extension, to perform a coverage test on JSON-GLib when
    we perform a 'make check'.
    
    GCOV support builds JSON-GLib with compiler and linker flags that enable
    coverage reports; then the check-local target will build the gcov file
    for each source file, and the coverage report will be extracted from
    those.

 .gitignore                        |    7 ++++---
 build/autotools/Makefile.am       |    3 ++-
 build/autotools/Makefile.am.gcov  |   35 +++++++++++++++++++++++++++++++++++
 build/autotools/Makefile.am.gtest |    2 ++
 configure.ac                      |   25 +++++++++++++++++++++++--
 json-glib/Makefile.am             |    9 ++++++---
 6 files changed, 72 insertions(+), 9 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 4b93725..2b2e416 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,9 +4,12 @@ Makefile.in
 aclocal.m4
 autom4te.cache
 /build/autotools/*.m4
+/build/autotools/shave-libtool
+/build/autotools/shave
 !/build/autotools/shave.m4
 !/build/autotools/as-compiler-flag.m4
 !/build/autotools/introspection.m4
+!/build/autotools/Makefile.am.*
 compile
 configure
 config.guess
@@ -69,6 +72,4 @@ test-report.html
 /doc/reference/json-glib.signals
 omf.make
 xmldocs.make
-/build/autotools/gtk-doc.m4
-/build/autotools/shave-libtool
-/build/autotools/shave
+*.gcov
diff --git a/build/autotools/Makefile.am b/build/autotools/Makefile.am
index 31d36d7..4b51223 100644
--- a/build/autotools/Makefile.am
+++ b/build/autotools/Makefile.am
@@ -7,7 +7,8 @@ EXTRA_DIST = \
 	Makefile.am.silent	\
 	Makefile.am.enums	\
 	Makefile.am.marshal	\
-	Makefile.am.gtest
+	Makefile.am.gtest	\
+	Makefile.am.gcov
 
 DISTCLEANFILES = shave-libtool shave
 
diff --git a/build/autotools/Makefile.am.gcov b/build/autotools/Makefile.am.gcov
new file mode 100644
index 0000000..9786df9
--- /dev/null
+++ b/build/autotools/Makefile.am.gcov
@@ -0,0 +1,35 @@
+if GCOV_ENABLED
+gcov-report.txt: gcov-clean
+	$(QUIET_GEN)(rm -f $@; \
+	echo -e "Test coverage for json-glib:\n" >> $@; \
+	total_covered=0; total_actual=0; \
+	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)); \
+			total_covered=$$((total_covered + covered)); \
+			total_actual=$$((total_actual + actual)); \
+			echo -e "$$file:    \t$$covered / $$actual\t($$((($$covered * 100) / $$actual))%)"; \
+		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
+gcov-clean:
+	@find . -name "*.gcda" -o -name "*.gcov" -delete
+else
+gcov-report.txt:
+	@true
+gcov-clean:
+	@true
+gcov:
+	@echo "Need to reconfigure with --enable-gcov"
+endif	# GCOV_ENABLED
+
+.PHONY: gcov gcov-clean gcov-report.txt
+
+check-local: gcov
diff --git a/build/autotools/Makefile.am.gtest b/build/autotools/Makefile.am.gtest
index a01d1b0..eae0a68 100644
--- a/build/autotools/Makefile.am.gtest
+++ b/build/autotools/Makefile.am.gtest
@@ -56,6 +56,8 @@ test-report perf-report full-report:	${TEST_PROGS}
 	    rm -rf "$$GTESTER_LOGDIR"/ ; \
 	    ${GTESTER_REPORT} --version 2>/dev/null 1>&2 ; test "$$?" != 0 || ${GTESTER_REPORT} $  xml >$  html ; \
 	  }
+
 .PHONY: test test-report perf-report full-report
+
 # run make test as part of make check
 check-local: test
diff --git a/configure.ac b/configure.ac
index 2626087..9805430 100644
--- a/configure.ac
+++ b/configure.ac
@@ -76,7 +76,7 @@ AC_SUBST(JSON_LIBS)
 
 AM_CONDITIONAL(ENABLE_GLIB_TEST, [test "x$enable_glibtest" = "xyes"])
 
-dnl = Enable debug level ===================================================
+dnl = Enable debug level ======================================================
 
 m4_define([debug_default], [m4_if(m4_eval(json_minor_version % 2), [1], [yes], [minimum])])
 
@@ -109,7 +109,7 @@ AS_CASE([$enable_debug],
 
 AC_SUBST(JSON_DEBUG_CFLAGS)
 
-dnl = Enable strict compiler flags =========================================
+dnl = Enable strict compiler flags ============================================
 
 # use strict compiler flags only on development releases
 m4_define([maintainer_flags_default], [m4_if(m4_eval(json_minor_version % 2), [1], [yes], [no])])
@@ -131,6 +131,26 @@ AS_IF([test "x$enable_maintainer_flags" = "xyes" && test "x$GCC" = "xyes"],
 )
 AC_SUBST([MAINTAINER_CFLAGS])
 
+dnl = GCOV coverage checks ====================================================
+AC_MSG_CHECKING([whether to build with gcov testing])
+AC_ARG_ENABLE([gcov],
+              [AS_HELP_STRING([--enable-gcov],
+                              [Whether to enable coverage testing (requires gcc and gcov)])],
+              [],
+              [enable_gcov=no])
+
+AS_IF([test "x$enable_gcov" = "xyes" && test "x$GCC" = "xyes"],
+      [
+        GCOV_CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
+        GCOV_LDFLAGS="$LDFLAGS -fprofile-arcs -ftest-coverage"
+      ]
+)
+
+AM_CONDITIONAL([GCOV_ENABLED], [test "x$enable_gcov" = "xyes"])
+AC_SUBST([GCOV_CFLAGS])
+AC_SUBST([GCOV_LDFLAGS])
+AC_MSG_RESULT([$enable_gcov])
+
 GTK_DOC_CHECK([1.11])
 
 GOBJECT_INTROSPECTION_CHECK([0.6.4])
@@ -182,4 +202,5 @@ echo " â?¢ API reference: ${enable_gtk_doc}"
 echo ""
 echo " â?¢ Enable test suite: ${enable_glibtest}"
 echo " â?¢ Build introspection data: ${enable_introspection}"
+echo " â?¢ Enable coverage test: ${enable_gcov}"
 echo ""
diff --git a/json-glib/Makefile.am b/json-glib/Makefile.am
index 6471fa9..8492be2 100644
--- a/json-glib/Makefile.am
+++ b/json-glib/Makefile.am
@@ -1,5 +1,5 @@
-include $(top_srcdir)/build/autotools/Makefile.am.gtest
 include $(top_srcdir)/build/autotools/Makefile.am.silent
+include $(top_srcdir)/build/autotools/Makefile.am.gtest
 
 if ENABLE_GLIB_TEST
 # build this directory *before* the tests/
@@ -22,7 +22,7 @@ AM_CPPFLAGS = \
 	$(JSON_DEBUG_CFLAGS) 		\
 	$(NULL)
 
-AM_CFLAGS = $(JSON_CFLAGS) $(MAINTAINER_CFLAGS)
+AM_CFLAGS = $(JSON_CFLAGS) $(MAINTAINER_CFLAGS) $(GCOV_CFLAGS)
 
 BUILT_SOURCES =
 
@@ -69,7 +69,7 @@ lib_LTLIBRARIES = libjson-glib-1.0.la
 
 libjson_glib_1_0_la_LIBADD = $(JSON_LIBS)
 libjson_glib_1_0_la_SOURCES = $(source_c) $(source_h) $(source_h_private) $(BUILT_SOURCES)
-libjson_glib_1_0_la_LDFLAGS = $(JSON_LT_LDFLAGS) -export-dynamic -export-symbols-regex "^json.*" -rpath $(libdir)
+libjson_glib_1_0_la_LDFLAGS = $(JSON_LT_LDFLAGS) $(GCOV_LDFLAGS) -export-dynamic -export-symbols-regex "^json.*" -rpath $(libdir)
 
 jsonincludedir = $(includedir)/json-glib-1.0/json-glib
 jsoninclude_DATA = \
@@ -120,3 +120,6 @@ typelibs_DATA = $(BUILT_GIRSOURCES:.gir=.typelib)
 
 CLEANFILES += $(BUILT_GIRSOURCES) $(typelibs_DATA)
 endif # HAVE_INTROSPECTION
+
+gcov_sources = $(source_c)
+include $(top_srcdir)/build/autotools/Makefile.am.gcov



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