aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan LeSage <allanlesage@gmail.com>2011-12-06 18:43:35 -0600
committerAllan LeSage <allanlesage@gmail.com>2011-12-06 18:43:35 -0600
commit4b4a2a0b444d26303df7865cebb56bf942c6d022 (patch)
treefcbe197a1cab8e810e13c3cc70c6b94b800cd2ea
parentba87e5cb673992cee0fcb0bb3c90523974836a30 (diff)
downloadayatana-indicator-datetime-4b4a2a0b444d26303df7865cebb56bf942c6d022.tar.gz
ayatana-indicator-datetime-4b4a2a0b444d26303df7865cebb56bf942c6d022.tar.bz2
ayatana-indicator-datetime-4b4a2a0b444d26303df7865cebb56bf942c6d022.zip
Added coverage reporting via gcov config and targets.
-rw-r--r--Makefile.am36
-rw-r--r--configure.ac11
-rw-r--r--m4/gcov.m483
-rw-r--r--src/Makefile.am10
4 files changed, 139 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index feea4de..2b6ba90 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -36,3 +36,39 @@ dist-hook:
else \
echo Failed to generate AUTHORS: not a branch >&2; \
fi
+
+
+# Coverage targets
+
+.PHONY: clean-gcda
+clean-gcda:
+ @echo Removing old coverage results
+ -find -name '*.gcda' -print | xargs -r rm
+
+.PHONY: coverage-html generate-coverage-html clean-coverage-html
+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
+
+.PHONY: coverage-xml generate-coverage-xml clean-coverage-xml
+coverage-xml: clean-gcda
+ -$(MAKE) $(AM_MAKEFLAGS) -k check
+ $(MAKE) $(AM_MAKEFLAGS) generate-coverage-xml
+
+generate-coverage-xml:
+ @echo Generating coverage XML report
+ $(GCOVR) -x -r $(top_builddir) -o $(top_builddir)/coverage.xml
+
+clean-coverage-xml: clean-gcda
+ -rm -rf $(top_builddir)/coverage.xml
+
+clean-local: clean-coverage-html clean-coverage-xml
diff --git a/configure.ac b/configure.ac
index 07f52d7..6b01de7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -119,6 +119,16 @@ PKG_CHECK_MODULES(LIBMAP, gio-2.0 >= $GIO_REQUIRED_VERSION
GLIB_GSETTINGS
###########################
+# gcov coverage reporting
+###########################
+
+m4_include([m4/gcov.m4])
+AC_TDD_GCOV
+AC_SUBST(COVERAGE_CFLAGS)
+AC_SUBST(COVERAGE_CXXFLAGS)
+AC_SUBST(COVERAGE_LDFLAGS)
+
+###########################
# Check to see if we're local
###########################
@@ -225,4 +235,5 @@ Date and Time Indicator Configuration:
Prefix: $prefix
Indicator Dir: $INDICATORDIR
CC Panel Dir: $CCPANELDIR
+ gcov: $use_gcov
])
diff --git a/m4/gcov.m4 b/m4/gcov.m4
new file mode 100644
index 0000000..1169573
--- /dev/null
+++ b/m4/gcov.m4
@@ -0,0 +1,83 @@
+# 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_CACHE_CHECK([whether code coverage tools are available], ac_cv_check_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)
+ AC_CHECK_PROG(GCOVR, gcovr, gcovr)
+
+ 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
+
+ if test -z "$GCOVR"; then
+ AC_MSG_ERROR([Could not find gcovr; easy_install (or pip) gcovr])
+ fi
+
+
+ # 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"
+
+fi
+])]) # AC_TDD_GCOV
+
diff --git a/src/Makefile.am b/src/Makefile.am
index 254022e..e4269f8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,10 +17,13 @@ indicator_datetime_service_CFLAGS = \
-Wall \
-Werror \
$(SERVICE_CFLAGS) \
+ $(COVERAGE_CFLAGS) \
-DTIMEZONE_FILE="\"/etc/timezone\"" \
-DG_LOG_DOMAIN=\"Indicator-Datetime\"
indicator_datetime_service_LDADD = \
$(SERVICE_LIBS)
+indicator_datetime_service_LDFLAGS = \
+ $(COVERAGE_LDFLAGS)
datetimelibdir = $(INDICATORDIR)
datetimelib_LTLIBRARIES = libdatetime.la
@@ -33,12 +36,14 @@ libdatetime_la_SOURCES = \
indicator-datetime.c
libdatetime_la_CFLAGS = \
$(INDICATOR_CFLAGS) \
+ $(COVERAGE_CFLAGS) \
-Wall -Werror \
-DTIMEZONE_FILE="\"/etc/timezone\"" \
-DG_LOG_DOMAIN=\"Indicator-Datetime\"
libdatetime_la_LIBADD = \
$(INDICATOR_LIBS)
libdatetime_la_LDFLAGS = \
+ $(COVERAGE_LDFLAGS) \
-module \
-avoid-version
@@ -56,12 +61,15 @@ libindicator_datetime_la_CFLAGS = \
-Werror \
-I$(top_srcdir)/libmap \
$(PREF_CFLAGS) \
+ $(COVERAGE_CFLAGS) \
-DTIMEZONE_FILE="\"/etc/timezone\"" \
-DPKGDATADIR="\"$(pkgdatadir)\""
libindicator_datetime_la_LIBADD = \
$(top_builddir)/libmap/libmap.la \
$(PREF_LIBS)
-libindicator_datetime_la_LDFLAGS = -module -avoid-version
+libindicator_datetime_la_LDFLAGS = \
+ $(COVERAGE_LDFLAGS) \
+ -module -avoid-version
gen-%.xml.c: %.xml
@echo "Building $@ from $<"