[glib] Add support for coverage reports with lcov



commit cca48bd5b9de1d4902b12acc86778def3ae00cbe
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jun 20 22:46:47 2010 -0400

    Add support for coverage reports with lcov
    
    Patch by Patrick Hulin, bug #501057.

 Makefile.am                       |    2 +-
 Makefile.decl                     |   22 ++++++++++++
 configure.in                      |   69 +++++++++++++++++++++++++++++++++++++
 docs/reference/glib/building.sgml |   19 ++++++++++-
 4 files changed, 110 insertions(+), 2 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index ae59aa2..9ee0acd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -123,7 +123,7 @@ DISTCHECK_CONFIGURE_FLAGS = --enable-debug --enable-gtk-doc --enable-man
 
 DISTCLEANFILES = glibconfig-sysdefs.h glibconfig.h stamp-gc-h config.lt
 
-distclean-local:
+distclean-local: lcov-clean
 	if test $(srcdir) = .; then :; else \
 	    rm -f $(BUILT_EXTRA_DIST); \
 	fi
diff --git a/Makefile.decl b/Makefile.decl
index 0d7571e..c9f5d5f 100644
--- a/Makefile.decl
+++ b/Makefile.decl
@@ -61,5 +61,27 @@ test-report perf-report full-report:	${TEST_PROGS}
 	    ${GTESTER_REPORT} --version 2>/dev/null 1>&2 ; test "$$?" != 0 || ${GTESTER_REPORT} $  xml >$  html ; \
 	  }
 .PHONY: test test-report perf-report full-report
+
+.PHONY: lcov genlcov lcov-clean
+# use recursive makes in order to ignore errors during check
+lcov:
+	-$(MAKE) $(AM_MAKEFLAGS) -k check
+	$(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
+# we also have to delete tests/.libs/libmoduletestplugin_*.gcda
+genlcov:
+	rm -f $(top_builddir)/tests/.libs/libmoduletestplugin_*.gcda
+	$(LTP) --directory $(top_builddir) --capture --output-file glib-lcov.info --test-name GLIB_PERF --no-checksum
+	$(SED) -e 's#.libs/##' < glib-lcov.info > glib-lcov.info.tmp
+	LANG=C $(LTP_GENHTML) --prefix $(top_builddir) --output-directory glib-lcov --title "GLib Code Coverage" --legend --show-details glib-lcov.info.tmp
+	rm -f glib-lcov.info.tmp
+
+lcov-clean:
+	-$(LTP) --directory $(top_builddir) -z
+	-rm -rf glib-lcov.info glib-lcov
+	-find -name '*.gcda' -print | xargs rm
+
 # run make test as part of make check
 check-local: test
diff --git a/configure.in b/configure.in
index 7102bb4..29754c5 100644
--- a/configure.in
+++ b/configure.in
@@ -2831,6 +2831,75 @@ AC_ARG_WITH([tapset-install-dir],
 	    [ABS_TAPSET_DIR="\$(datadir)/systemtap/tapset"])
 AC_SUBST(ABS_TAPSET_DIR)
 
+dnl ************************************
+dnl *** Enable lcov coverage reports ***
+dnl ************************************
+
+AC_ARG_ENABLE(gcov,
+  AS_HELP_STRING([--enable-gcov],
+		 [Enable gcov]),
+  [use_gcov=$enableval], [use_gcov=no])
+
+if test "x$use_gcov" = "xyes"; then
+  dnl we need gcc:
+  if test "$GCC" != "yes"; then
+    AC_MSG_ERROR([GCC is required for --enable-gcov])
+  fi
+
+  dnl Check if ccache is being used
+  AC_CHECK_PROG(SHTOOL, shtool, shtool)
+  case `$SHTOOL path $CC` in
+    *ccache*[)] gcc_ccache=yes;;
+    *[)] gcc_ccache=no;;
+  esac
+
+  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"
+  AC_CHECK_PROG(LTP, lcov, lcov)
+  AC_CHECK_PROG(LTP_GENHTML, genhtml, genhtml)
+
+  if test "$LTP"; then
+    AC_CACHE_CHECK([for ltp version], glib_cv_ltp_version, [
+      glib_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
+          glib_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 $glib_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'`
+  changequote([,])
+
+  dnl Add the special gcc flags
+  CFLAGS="$CFLAGS -O0 -fprofile-arcs -ftest-coverage"
+  LDFLAGS="$LDFLAGS -lgcov"
+fi
+
 dnl ******************************
 dnl *** output the whole stuff ***
 dnl ******************************
diff --git a/docs/reference/glib/building.sgml b/docs/reference/glib/building.sgml
index 806349e..d420af0 100644
--- a/docs/reference/glib/building.sgml
+++ b/docs/reference/glib/building.sgml
@@ -255,11 +255,15 @@ How to compile GLib itself
             <arg>--disable-dtrace</arg>
             <arg>--enable-dtrace</arg>
           </group>
-            <group>
+          <group>
             <arg>--disable-systemtap</arg>
             <arg>--enable-systemtap</arg>
           </group>
           <group>
+            <arg>--enable-gcov</arg>
+            <arg>--disable-gcov</arg>
+          </group>
+          <group>
             <arg>--with-runtime-libdir=RELPATH</arg>
           </group>
         </cmdsynopsis>
@@ -606,6 +610,19 @@ How to compile GLib itself
      </formalpara>
 
       <formalpara>
+        <title><systemitem>--enable-gcov</systemitem> and
+          <systemitem>--disable-gcov</systemitem></title>
+
+        <para>
+          Enable the generation of coverage reports for the GLib tests.
+          This requires the lcov frontend to gcov from the
+          <ulink url="http://ltp.sourcforge.net";>Linux Test Project</ulink>.
+          To generate a coverage report, use the lcov make target. The
+          report is placed in the <filename>glib-lcov</filename> directory.
+        </para>
+      </formalpara>
+
+      <formalpara>
         <title><systemitem>--with-runtime-libdir=RELPATH</systemitem></title>
 
         <para>



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