diff --git a/Makefile.am b/Makefile.am index ae59aa2c8..9ee0acd0d 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 0d7571e55..c9f5d5f50 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 7102bb4d6..29754c570 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 806349e8f..d420af0c1 100644 --- a/docs/reference/glib/building.sgml +++ b/docs/reference/glib/building.sgml @@ -255,10 +255,14 @@ How to compile GLib itself --disable-dtrace --enable-dtrace - + --disable-systemtap --enable-systemtap + + --enable-gcov + --disable-gcov + --with-runtime-libdir=RELPATH @@ -605,6 +609,19 @@ How to compile GLib itself + + <systemitem>--enable-gcov</systemitem> and + <systemitem>--disable-gcov</systemitem> + + + Enable the generation of coverage reports for the GLib tests. + This requires the lcov frontend to gcov from the + Linux Test Project. + To generate a coverage report, use the lcov make target. The + report is placed in the glib-lcov directory. + + + <systemitem>--with-runtime-libdir=RELPATH</systemitem>