[clutter] build: Add coverage support using lcov



commit 5eb3fbf3cf89950d43d495fcd8e89d93731e8869
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Tue Jun 19 14:43:40 2012 +0100

    build: Add coverage support using lcov
    
    Unlike gcov, lcov provides a nice HTML output that allows immediate
    visualization of the current coverage.
    
    The updates of the build system have been taken from GLib, which has
    been using lcov for a while with good results.

 .gitignore   |    4 +++
 Makefile.am  |   26 +++++++++++++++++++-
 configure.ac |   77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 104 insertions(+), 3 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 55dab82..db70c63 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,12 +23,16 @@ stamp-marshal
 /clutter/gcov-report.txt
 /clutter/clutter-json.h
 /clutter/cex100/clutter-cex100.h
+/clutter-lcov.info
+/clutter-lcov
 /build/autotools/*.m4
 !/build/autotools/introspection.m4
 !/build/autotools/as-linguas.m4
 !/build/autotools/as-compiler-flag.m4
 *.gir
 *.typelib
+*.gcda
+*.gcno
 config.*
 configure
 depcomp
diff --git a/Makefile.am b/Makefile.am
index 2bf2b89..1b024f9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -44,4 +44,28 @@ test-report full-report:
 perf-report:
 	$(MAKE) -C tests/performance $(@)
 
-.PHONY: test-report full-report perf-report
+if ENABLE_GCOV
+# use recursive makes in order to ignore errors during check/perf
+lcov:
+	-$(MAKE) $(AM_MAKEFLAGS) -C clutter check
+	-$(MAKE) $(AM_MAKEFLAGS) -C tests/conform test
+	$(MAKE) $(AM_MAKEFLAGS) genlcov
+
+# we have to massage the lcov.info file slightly to hide the effect of libtool
+# placing the objects files in the .libs/ directory separate from the *.c
+genlcov:
+	$(LTP) --directory $(top_builddir) --capture --output-file clutter-lcov.info --test-name CLUTTER_TEST --no-checksum
+	$(SED) -e 's#.libs/##' < clutter-lcov.info > clutter-lcov.info.tmp
+	LANG=C $(LTP_GENHTML) --prefix $(top_builddir) --output-directory clutter-lcov --title "Clutter Code Coverage" --show-details clutter-lcov.info.tmp
+	rm -f clutter-lcov.info.tmp
+
+lcov-clean:
+	-$(LTP) --directory $(top_builddir) -z
+	-$(RM) -rf clutter-lcov.info clutter-lcov
+else
+lcov genlcov lcov-clean:
+	@echo You need to configure Clutter with support for gcov enabled.
+	@echo e.g., ./configure --enable-gcov
+endif
+
+.PHONY: test-report full-report perf-report lcov genlcov lcov-clean
diff --git a/configure.ac b/configure.ac
index d0c31ab..48547a0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -870,7 +870,6 @@ AS_CASE([$enable_deprecated],
 
 AC_SUBST([CLUTTER_DEPRECATED_CFLAGS])
 
-
 dnl === Profiling =============================================================
 
 m4_define([profile_default], [no])
@@ -981,6 +980,80 @@ CLUTTER_LIBS="$FLAVOUR_LIBS $CLUTTER_DEPS_LIBS $CLUTTER_DEPS_PRIVATE_LIBS $CLUTT
 AC_SUBST(CLUTTER_CFLAGS)
 AC_SUBST(CLUTTER_LIBS)
 
+dnl === Test coverage =========================================================
+
+AC_ARG_ENABLE([gcov],
+              [AS_HELP_STRING([--enable-gcov], [Enable gcov])],
+              [use_gcov=$enableval],
+              [use_gcov=no])
+
+AS_IF([test "x$use_gcov" = "xyes"],
+      [
+        dnl we need gcc:
+        AS_IF([test "$GCC" != "yes"], [AC_MSG_ERROR([GCC is required for --enable-gcov])])
+
+        dnl Check if ccache is being used
+        AC_CHECK_PROG(SHTOOL, shtool, shtool)
+        AS_CASE([`$SHTOOL path $CC`],
+                [*ccache*], [gcc_ccache=yes],
+                [gcc_ccache=no])
+
+        if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
+          AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
+        fi
+
+        ltp_version_list="1.6 1.7 1.8 1.9"
+        AC_CHECK_PROG(LTP, lcov, lcov)
+        AC_CHECK_PROG(LTP_GENHTML, genhtml, genhtml)
+
+        if test "$LTP"; then
+          AC_CACHE_CHECK([for ltp version], clutter_cv_ltp_version,
+                         [
+                           clutter_cv_ltp_version=invalid
+                           ltp_version=`$LTP -v 2>/dev/null | $SED -e 's/^.* //'`
+                           for ltp_check_version in $ltp_version_list; do
+                             if test "$ltp_version" = "$ltp_check_version"; then
+                               clutter_cv_ltp_version="$ltp_check_version (ok)"
+                             fi
+                           done
+                         ])
+        else
+          ltp_msg="To enable code coverage reporting you must have one of the following LTP versions installed: $ltp_version_list"
+          AC_MSG_ERROR([$ltp_msg])
+        fi
+
+        case $clutter_cv_ltp_version in
+          ""|invalid[)]
+          ltp_msg="You must have one of the following versions of LTP: $ltp_version_list (found: $ltp_version)."
+          AC_MSG_ERROR([$ltp_msg])
+          LTP="exit 0;"
+          ;;
+        esac
+
+        if test -z "$LTP_GENHTML"; then
+          AC_MSG_ERROR([Could not find genhtml from the LTP package])
+        fi
+
+        AC_DEFINE(HAVE_GCOV, 1, [Whether you have gcov])
+
+        dnl Remove all optimization flags from CFLAGS
+        changequote({,})
+        CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
+        CLUTTER_CFLAGS=`echo "$CLUTTER_CFLAGS" | $SED -e 's/-O[0-9]*//g'`
+        changequote([,])
+
+        dnl Define the special gcc flags
+        CLUTTER_GCOV_CFLAGS="-O0 -fprofile-arcs -ftest-coverage"
+        CLUTTER_GCOV_LDADD="-lgcov"
+
+        AC_SUBST(CLUTTER_GCOV_CFLAGS)
+        AC_SUBST(CLUTTER_GCOV_LDADD)
+
+        CLUTTER_CFLAGS="$CLUTTER_CFLAGS $CLUTTER_GCOV_CFLAGS"
+        CLUTTER_LIBS="$CLUTTER_LIBS $CLUTTER_GCOV_LDADD"
+      ])
+
+AM_CONDITIONAL(ENABLE_GCOV, test "x$use_gcov" = "xyes")
 
 dnl === GObject-Introspection check ===========================================
 
@@ -1143,7 +1216,7 @@ echo " â Compiler options:"
 echo "        Clutter debug level: ${enable_debug}"
 echo "        Compiler flags: ${CFLAGS} ${MAINTAINER_CFLAGS}"
 echo "        Profiling enabled: ${enable_profile}"
-echo "        Enable coverage tests: ${enable_gcov}"
+echo "        Enable coverage tests: ${use_gcov}"
 echo "        Enable deprecated symbols: ${enable_deprecated}"
 
 # Documentation



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