From 948db40c875f8eb7032582a32515737be6587067 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 4 Jan 2010 14:53:03 +0000 Subject: [PATCH] Add gcov support to the build Using gcov it's possible to get a coverage report, that is a break down of how much the exposed API is exercised by the conformance test suite. --- .gitignore | 2 ++ Makefile.am | 3 +++ build/autotools/Makefile.am | 1 + build/autotools/Makefile.am.gcov | 33 ++++++++++++++++++++++++++++++++ clutter/Makefile.am | 20 ++++++++++--------- configure.ac | 26 +++++++++++++++++++++++++ 6 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 build/autotools/Makefile.am.gcov diff --git a/.gitignore b/.gitignore index bdcab8ce2..0e048e5a0 100644 --- a/.gitignore +++ b/.gitignore @@ -11,11 +11,13 @@ clutter.pc *.o *.lo *.la +*.gcov ChangeLog* clutter/clutter-enum-types.[ch] clutter/clutter-marshal.[ch] clutter/clutter-version.h clutter/stamp-* +/clutter/gcov-report.txt /clutter/clutter-json.h /clutter/cogl/cogl/cogl-defines.h /clutter/cogl/cogl/*.pc diff --git a/Makefile.am b/Makefile.am index f003afeb1..fc7ef37d3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -48,3 +48,6 @@ MAINTAINERCLEANFILES = \ $(NULL) include $(top_srcdir)/build/autotools/Makefile.am.changelog + +gcov: + @( cd clutter && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $$? diff --git a/build/autotools/Makefile.am b/build/autotools/Makefile.am index bbdcf8955..663c3edf3 100644 --- a/build/autotools/Makefile.am +++ b/build/autotools/Makefile.am @@ -5,6 +5,7 @@ EXTRA_DIST = \ Makefile.am.marshal \ Makefile.am.enums \ Makefile.am.changelog \ + Makefile.am.gcov \ dolt.m4 \ introspection.m4 \ gtk-doc.m4 \ diff --git a/build/autotools/Makefile.am.gcov b/build/autotools/Makefile.am.gcov new file mode 100644 index 000000000..a16edbd76 --- /dev/null +++ b/build/autotools/Makefile.am.gcov @@ -0,0 +1,33 @@ +if GCOV_ENABLED +gcov-report.txt: gcov-clean + $(QUIET_GEN)(rm -f $@; \ + echo -e "Test coverage for Clutter:\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 + @echo ""; 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 diff --git a/clutter/Makefile.am b/clutter/Makefile.am index 1a23d9978..401b3e5e9 100644 --- a/clutter/Makefile.am +++ b/clutter/Makefile.am @@ -41,14 +41,7 @@ AM_CPPFLAGS = \ $(CLUTTER_DEBUG_CFLAGS) \ $(NULL) -AM_CFLAGS = $(CLUTTER_CFLAGS) $(MAINTAINER_CFLAGS) - -LDADD = \ - $(CLUTTER_LT_LDFLAGS) \ - -export-dynamic \ - -export-symbols-regex "^(clutter|cogl|json).*" \ - -rpath $(libdir) \ - $(NULL) +AM_CFLAGS = $(CLUTTER_CFLAGS) $(MAINTAINER_CFLAGS) $(GCOV_CFLAGS) # please, keep this sorted alphabetically source_h = \ @@ -220,7 +213,13 @@ libclutter_@CLUTTER_WINSYS@_@CLUTTER_API_VERSION@_la_SOURCES = \ $(source_c_priv) \ $(source_h_priv) -libclutter_@CLUTTER_WINSYS@_@CLUTTER_API_VERSION@_la_LDFLAGS = $(LDADD) +libclutter_@CLUTTER_WINSYS@_@CLUTTER_API_VERSION@_la_LDFLAGS = \ + $(CLUTTER_LT_LDFLAGS) \ + $(GCOV_LDFLAGS) \ + -export-dynamic \ + -export-symbols-regex "^(clutter|cogl|json).*" \ + -rpath $(libdir) \ + $(NULL) lib_LTLIBRARIES = $(CLUTTER_WINSYS_LIB) @@ -322,3 +321,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 diff --git a/configure.ac b/configure.ac index 93f0b5473..302e6686b 100644 --- a/configure.ac +++ b/configure.ac @@ -720,6 +720,31 @@ AM_CONDITIONAL(PROFILE, test "x$enable_profile" != "xno") AC_SUBST(CLUTTER_PROFILE_CFLAGS) AC_SUBST(CLUTTER_PROFILE_LDFLAGS) +dnl === Coverage report ======================================================= + +AC_PATH_PROG([GCOV], [gcov], [enable_gcov=no]) + +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="-g -O0 -fprofile-arcs -ftest-coverage" + GCOV_LDFLAGS="-lgcov" + ] +) + +AM_CONDITIONAL([GCOV_ENABLED], [test "x$enable_gcov" = "xyes"]) +AC_SUBST([GCOV_CFLAGS]) +AC_SUBST([GCOV_LDFLAGS]) +AC_MSG_RESULT([$enable_gcov]) + dnl === Enable strict compiler flags ========================================== # use strict compiler flags only on development releases @@ -908,6 +933,7 @@ echo " Clutter debug level: ${enable_debug}" echo " COGL debug level: ${enable_cogl_debug}" echo " Compiler flags: ${MAINTAINER_CFLAGS}" echo " Profiling enabled: ${enable_profile}" +echo " Enable coverage tests: ${enable_gcov}" # Documentation echo ""