aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan LeSage <allan.lesage@canonical.com>2013-11-21 19:14:21 +0000
committerTarmac <Unknown>2013-11-21 19:14:21 +0000
commit875ee4d733ce751fcd8d974a32c4bfdebbe501a3 (patch)
tree406500af69bd6555eb4e4dc63e3711bd341bb6b4
parentf90c7c21d0e82779356eaa8ae471703cda45d7cc (diff)
parentbf2aab363e93263b1615f1811524fb22b14bf34b (diff)
downloadayatana-indicator-keyboard-875ee4d733ce751fcd8d974a32c4bfdebbe501a3.tar.gz
ayatana-indicator-keyboard-875ee4d733ce751fcd8d974a32c4bfdebbe501a3.tar.bz2
ayatana-indicator-keyboard-875ee4d733ce751fcd8d974a32c4bfdebbe501a3.zip
Add gcov coverage tooling; use ./autogen.sh --enable-gcov and then make coverage-html to see a report of what's covered. You can read about the rationale in this old blog post: http://qualityhour.wordpress.com/2012/01/29/test-coverage-tutorial-for-cc-autotools-projects/ .
Approved by William Hua, PS Jenkins bot.
-rw-r--r--.bzrignore8
-rw-r--r--Makefile.am2
-rw-r--r--Makefile.am.coverage48
-rw-r--r--configure.ac9
-rw-r--r--data/Makefile.am6
-rw-r--r--lib/Makefile.am6
-rw-r--r--m4/gcov.m486
7 files changed, 160 insertions, 5 deletions
diff --git a/.bzrignore b/.bzrignore
index a43695b7..8c441a49 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -1,6 +1,5 @@
*.c
*.log
-*.m4
*.pyc
*.stamp
*.stamp-t
@@ -34,3 +33,10 @@ tests/indicator-keyboard-test
tests/indicator-keyboard-test.trs
tests/indicator-keyboard-tests
tests/services/indicator-keyboard.service
+aclocal.m4
+m4/intltool.m4
+m4/libtool.m4
+m4/lt~obsolete.m4
+m4/ltoptions.m4
+m4/ltsugar.m4
+m4/ltversion.m4 \ No newline at end of file
diff --git a/Makefile.am b/Makefile.am
index c0d4a471..94cd26da 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,3 +1,5 @@
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = po lib data tests
+
+include $(top_srcdir)/Makefile.am.coverage
diff --git a/Makefile.am.coverage b/Makefile.am.coverage
new file mode 100644
index 00000000..fb977474
--- /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 ccd69620..5a333009 100644
--- a/configure.ac
+++ b/configure.ac
@@ -82,6 +82,15 @@ PKG_CHECK_MODULES([BAMF], [libbamf3])
AC_SUBST([BAMF_CFLAGS])
AC_SUBST([BAMF_LIBS])
+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_CXXFLAGS)
+AC_SUBST(COVERAGE_LDFLAGS)
+
AC_CONFIG_FILES([Makefile
data/Makefile
lib/Makefile
diff --git a/data/Makefile.am b/data/Makefile.am
index 26e819dc..29ad3e7a 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -22,13 +22,15 @@ indicator_keyboard_icon_generator_CFLAGS = $(AM_CFLAGS) \
$(PANGOFT2_CFLAGS) \
$(GTK_CFLAGS) \
$(GNOME_DESKTOP_CFLAGS) \
- $(LIBXKLAVIER_CFLAGS)
+ $(LIBXKLAVIER_CFLAGS) \
+ $(COVERAGE_CFLAGS)
indicator_keyboard_icon_generator_LDFLAGS = $(AM_LDFLAGS) \
$(GEE_LIBS) \
$(PANGOFT2_LIBS) \
$(GTK_LIBS) \
$(GNOME_DESKTOP_LIBS) \
- $(LIBXKLAVIER_LIBS)
+ $(LIBXKLAVIER_LIBS) \
+ $(COVERAGE_LDFLAGS)
dist_service_DATA = indicator-keyboard.service
servicedir = $(DBUS_SERVICE_DIR)
diff --git a/lib/Makefile.am b/lib/Makefile.am
index fc6eeb42..72f5f949 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -32,7 +32,8 @@ indicator_keyboard_service_CFLAGS = $(AM_CFLAGS) \
$(IBUS_CFLAGS) \
$(ACCOUNTSSERVICE_CFLAGS) \
$(LIGHTDM_CFLAGS) \
- $(BAMF_CFLAGS)
+ $(BAMF_CFLAGS) \
+ $(COVERAGE_CFLAGS)
indicator_keyboard_service_LDFLAGS = $(AM_LDFLAGS) \
$(GEE_LIBS) \
$(PANGOCAIRO_LIBS) \
@@ -43,4 +44,5 @@ indicator_keyboard_service_LDFLAGS = $(AM_LDFLAGS) \
$(IBUS_LIBS) \
$(ACCOUNTSSERVICE_LIBS) \
$(LIGHTDM_LIBS) \
- $(BAMF_LIBS)
+ $(BAMF_LIBS) \
+ $(COVERAGE_LDFLAGS)
diff --git a/m4/gcov.m4 b/m4/gcov.m4
new file mode 100644
index 00000000..31635840
--- /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