aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2012-04-03 21:33:03 -0500
committerCharles Kerr <charles.kerr@canonical.com>2012-04-03 21:33:03 -0500
commit72c1f1c6b9f169dff5f70be3c7fcaac570254508 (patch)
treeb2fe38f07b9d0acc16636d9e12a82ee93bd41b83
parent5c3834907b18b2c9230d39767ab9092e80c5c849 (diff)
parentc54e02d80857bd08071e2311f456ef992a9d7a01 (diff)
downloadlibdbusmenu-72c1f1c6b9f169dff5f70be3c7fcaac570254508.tar.gz
libdbusmenu-72c1f1c6b9f169dff5f70be3c7fcaac570254508.tar.bz2
libdbusmenu-72c1f1c6b9f169dff5f70be3c7fcaac570254508.zip
Merge lp:~allanlesage/dbusmenu/TDD to add gcov targets to autotools build for code-coverage reporting. For more information, see this blog post: http://qualityhour.wordpress.com/2012/01/29/test-coverage-tutorial-for-cc-autotools-projects/ .
To compile with coverage tooling, ./autogen.sh --enable-gcov, then make coverage-html . Note that you'll need lcov to autoconf. Also note that you'll get an error on make if you have no tests, as there are no coverage artifacts to generate the html report. For review, please pay special attention to flags added in the project's makefiles.
-rw-r--r--Makefile.am2
-rw-r--r--Makefile.am.coverage48
-rw-r--r--configure.ac16
-rw-r--r--libdbusmenu-glib/Makefile.am9
-rw-r--r--libdbusmenu-gtk/Makefile.am10
-rw-r--r--m4/gcov.m486
6 files changed, 169 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index 6b11b31..948cb3d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -53,3 +53,5 @@ dist-hook:
else \
echo Failed to generate AUTHORS: not a branch >&2; \
fi
+
+include $(top_srcdir)/Makefile.am.coverage
diff --git a/Makefile.am.coverage b/Makefile.am.coverage
new file mode 100644
index 0000000..fb97747
--- /dev/null
+++ b/Makefile.am.coverage
@@ -0,0 +1,48 @@
+
+# Coverage targets
+
+.PHONY: clean-gcno clean-gcda \
+ coverage-html generate-coverage-html clean-coverage-html \
+ coverage-gcovr generate-coverage-gcovr clean-coverage-gcovr
+
+clean-local: clean-gcno clean-coverage-html clean-coverage-gcovr
+
+if HAVE_GCOV
+
+clean-gcno:
+ @echo Removing old coverage instrumentation
+ -find -name '*.gcno' -print | xargs -r rm
+
+clean-gcda:
+ @echo Removing old coverage results
+ -find -name '*.gcda' -print | xargs -r rm
+
+coverage-html: clean-gcda
+ -$(MAKE) $(AM_MAKEFLAGS) -k check
+ $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html
+
+generate-coverage-html:
+ @echo Collecting coverage data
+ $(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool
+ LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
+
+clean-coverage-html: clean-gcda
+ -$(LCOV) --directory $(top_builddir) -z
+ -rm -rf coverage.info coveragereport
+
+if HAVE_GCOVR
+
+coverage-gcovr: clean-gcda
+ -$(MAKE) $(AM_MAKEFLAGS) -k check
+ $(MAKE) $(AM_MAKEFLAGS) generate-coverage-gcovr
+
+generate-coverage-gcovr:
+ @echo Generating coverage GCOVR report
+ $(GCOVR) -x -r $(top_builddir) -o $(top_builddir)/coverage.xml
+
+clean-coverage-gcovr: clean-gcda
+ -rm -rf $(top_builddir)/coverage.xml
+
+endif # HAVE_GCOVR
+
+endif # HAVE_GCOV
diff --git a/configure.ac b/configure.ac
index a46901f..be12b31 100644
--- a/configure.ac
+++ b/configure.ac
@@ -194,6 +194,18 @@ if test "x$with_massivedebugging" = "xyes"; then
fi
###########################
+# gcov coverage reporting
+###########################
+
+m4_include([m4/gcov.m4])
+AC_TDD_GCOV
+AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes])
+AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes])
+AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes])
+AC_SUBST(COVERAGE_CFLAGS)
+AC_SUBST(COVERAGE_LDFLAGS)
+
+###########################
# Files
###########################
@@ -251,3 +263,7 @@ AS_IF([test "x$have_dumper" = "xyes"],
AC_MSG_NOTICE([ Dumper: no])
)
+AS_IF([test "x$use_gcov" = "xyes"],
+ AC_MSG_NOTICE([ Coverage reporting: yes]),
+ AC_MSG_NOTICE([ Coverage reporting: no])
+)
diff --git a/libdbusmenu-glib/Makefile.am b/libdbusmenu-glib/Makefile.am
index fa7c8cb..b2e796c 100644
--- a/libdbusmenu-glib/Makefile.am
+++ b/libdbusmenu-glib/Makefile.am
@@ -58,12 +58,14 @@ libdbusmenu_glib_la_SOURCES = \
client.c
libdbusmenu_glib_la_LDFLAGS = \
+ $(COVERAGE_LDFLAGS) \
-version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \
-no-undefined \
-export-symbols-regex "^[^_].*"
libdbusmenu_glib_la_CFLAGS = \
$(DBUSMENUGLIB_CFLAGS) \
+ $(COVERAGE_CFLAGS) \
-Wall -Werror -Wno-error=deprecated-declarations \
-DG_LOG_DOMAIN="\"LIBDBUSMENU-GLIB\""
@@ -181,7 +183,12 @@ introspection_sources = \
Dbusmenu-0.4.gir: libdbusmenu-glib.la
Dbusmenu_0_4_gir_INCLUDES = \
GObject-2.0
-Dbusmenu_0_4_gir_CFLAGS = $(DBUSMENUGLIB_CFLAGS) -I$(top_srcdir)
+Dbusmenu_0_4_gir_CFLAGS = \
+ $(DBUSMENUGLIB_CFLAGS) \
+ $(COVERAGE_CFLAGS) \
+ -I$(top_srcdir)
+Dbusmenu_0_4_gir_LDFLAGS = \
+ $(COVERAGE_LDFLAGS)
Dbusmenu_0_4_gir_LIBS = libdbusmenu-glib.la
Dbusmenu_0_4_gir_FILES = $(introspection_sources)
Dbusmenu_0_4_gir_NAMESPACE = Dbusmenu
diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am
index fcebd04..b52098f 100644
--- a/libdbusmenu-gtk/Makefile.am
+++ b/libdbusmenu-gtk/Makefile.am
@@ -57,12 +57,14 @@ libdbusmenu_gtk_la_SOURCES = \
parser.c
libdbusmenu_gtk_la_LDFLAGS = \
+ $(COVERAGE_LDFLAGS) \
-version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \
-no-undefined \
-export-symbols-regex "^[^_].*"
libdbusmenu_gtk_la_CFLAGS = \
$(DBUSMENUGTK_CFLAGS) \
+ $(COVERAGE_CFLAGS) \
-I$(top_srcdir) \
-Wall -Werror -Wno-error=deprecated-declarations \
-DG_LOG_DOMAIN="\"LIBDBUSMENU-GTK\""
@@ -117,7 +119,12 @@ DbusmenuGtk_0_4_gir_INCLUDES = \
GObject-2.0 \
$(GTKGIR) \
Dbusmenu-0.4
-DbusmenuGtk_0_4_gir_CFLAGS = $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir)
+DbusmenuGtk_0_4_gir_CFLAGS = \
+ $(DBUSMENUGTK_CFLAGS) \
+ $(COVERAGE_CFLAGS) \
+ -I$(top_srcdir)
+DbusmenuGtk_0_4_gir_LDFLAGS = \
+ $(COVERAGE_LDFLAGS)
DbusmenuGtk_0_4_gir_LIBS = libdbusmenu-gtk$(VER).la \
$(top_builddir)/libdbusmenu-glib/libdbusmenu-glib.la
DbusmenuGtk_0_4_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources))
@@ -127,6 +134,7 @@ DbusmenuGtk_0_4_gir_EXPORT_PACKAGES = dbusmenu-gtk$(VER)-0.4
# We duplicate these for the same reason as libdbusmenu_gtk3includedir above
DbusmenuGtk3_0_4_gir_INCLUDES = $(DbusmenuGtk_0_4_gir_INCLUDES)
DbusmenuGtk3_0_4_gir_CFLAGS = $(DbusmenuGtk_0_4_gir_CFLAGS)
+DbusmenuGtk3_0_4_gir_LDFLAGS = $(DbusmenuGtk_0_4_gir_LDFLAGS)
DbusmenuGtk3_0_4_gir_LIBS = $(DbusmenuGtk_0_4_gir_LIBS)
DbusmenuGtk3_0_4_gir_FILES = $(DbusmenuGtk_0_4_gir_FILES)
DbusmenuGtk3_0_4_gir_NAMESPACE = $(DbusmenuGtk_0_4_gir_NAMESPACE)
diff --git a/m4/gcov.m4 b/m4/gcov.m4
new file mode 100644
index 0000000..3163584
--- /dev/null
+++ b/m4/gcov.m4
@@ -0,0 +1,86 @@
+# Checks for existence of coverage tools:
+# * gcov
+# * lcov
+# * genhtml
+# * gcovr
+#
+# Sets ac_cv_check_gcov to yes if tooling is present
+# and reports the executables to the variables LCOV, GCOVR and GENHTML.
+AC_DEFUN([AC_TDD_GCOV],
+[
+ AC_ARG_ENABLE(gcov,
+ AS_HELP_STRING([--enable-gcov],
+ [enable coverage testing with gcov]),
+ [use_gcov=$enableval], [use_gcov=no])
+
+ if test "x$use_gcov" = "xyes"; then
+ # we need gcc:
+ if test "$GCC" != "yes"; then
+ AC_MSG_ERROR([GCC is required for --enable-gcov])
+ fi
+
+ # 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
+
+ lcov_version_list="1.6 1.7 1.8 1.9"
+ AC_CHECK_PROG(LCOV, lcov, lcov)
+ AC_CHECK_PROG(GENHTML, genhtml, genhtml)
+
+ if test "$LCOV"; then
+ AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [
+ glib_cv_lcov_version=invalid
+ lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
+ for lcov_check_version in $lcov_version_list; do
+ if test "$lcov_version" = "$lcov_check_version"; then
+ glib_cv_lcov_version="$lcov_check_version (ok)"
+ fi
+ done
+ ])
+ else
+ lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
+ AC_MSG_ERROR([$lcov_msg])
+ fi
+
+ case $glib_cv_lcov_version in
+ ""|invalid[)]
+ lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
+ AC_MSG_ERROR([$lcov_msg])
+ LCOV="exit 0;"
+ ;;
+ esac
+
+ if test -z "$GENHTML"; then
+ AC_MSG_ERROR([Could not find genhtml from the lcov package])
+ fi
+
+ ac_cv_check_gcov=yes
+ ac_cv_check_lcov=yes
+
+ # Remove all optimization flags from CFLAGS
+ changequote({,})
+ CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
+ changequote([,])
+
+ # Add the special gcc flags
+ COVERAGE_CFLAGS="-O0 -fprofile-arcs -ftest-coverage"
+ COVERAGE_CXXFLAGS="-O0 -fprofile-arcs -ftest-coverage"
+ COVERAGE_LDFLAGS="-lgcov"
+
+ # Check availability of gcovr
+ AC_CHECK_PROG(GCOVR, gcovr, gcovr)
+ if test -z "$GCOVR"; then
+ ac_cv_check_gcovr=no
+ else
+ ac_cv_check_gcovr=yes
+ fi
+
+fi
+]) # AC_TDD_GCOV