Merge lp:~allanlesage/indicator-bluetooth/add-coverage-tooling into lp:indicator-bluetooth/13.10

Proposed by Allan LeSage on 2013-08-08
Status: Work in progress
Proposed branch: lp:~allanlesage/indicator-bluetooth/add-coverage-tooling
Merge into: lp:indicator-bluetooth/13.10
Diff against target: 217 lines (+158/-3)
5 files modified
Makefile.am (+2/-0)
Makefile.am.coverage (+48/-0)
configure.ac (+13/-0)
m4/gcov.m4 (+86/-0)
src/Makefile.am (+9/-3)
To merge this branch: bzr merge lp:~allanlesage/indicator-bluetooth/add-coverage-tooling
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing on 2013-08-23
Charles Kerr (community) 2013-08-08 Needs Fixing on 2013-08-09
Review via email: mp+179299@code.launchpad.net

Commit message

Add gcov coverage tooling.

Description of the change

Here comes alesage brandishing the familiar hammer! Add gcov tooling; do ./autogen.sh --enable-gcov and then make coverage-html to see test coverage, more rationale in this old blog post: http://qualityhour.wordpress.com/2012/01/29/test-coverage-tutorial-for-cc-autotools-projects/ .

To post a comment you must log in.
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Charles Kerr (charlesk) wrote :

alesage, the familiar hammer looks fine but it's hitting the wrong anvil. Could you apply this on top of lp:~charlesk/indicator-bluetooth/gmenuify and have this depend on that merge? Otherwise we're going to get conflicts in configure.ac and src/Makefile.am.

review: Needs Fixing

Unmerged revisions

53. By Allan LeSage on 2013-08-08

Add coverage tooling.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile.am'
2--- Makefile.am 2012-12-06 02:58:44 +0000
3+++ Makefile.am 2013-08-08 22:48:20 +0000
4@@ -3,3 +3,5 @@
5 EXTRA_DIST = autogen.sh NEWS
6
7 DISTCHECK_CONFIGURE_FLAGS = --enable-localinstall
8+
9+include $(top_srcdir)/Makefile.am.coverage
10
11=== added file 'Makefile.am.coverage'
12--- Makefile.am.coverage 1970-01-01 00:00:00 +0000
13+++ Makefile.am.coverage 2013-08-08 22:48:20 +0000
14@@ -0,0 +1,48 @@
15+
16+# Coverage targets
17+
18+.PHONY: clean-gcno clean-gcda \
19+ coverage-html generate-coverage-html clean-coverage-html \
20+ coverage-gcovr generate-coverage-gcovr clean-coverage-gcovr
21+
22+clean-local: clean-gcno clean-coverage-html clean-coverage-gcovr
23+
24+if HAVE_GCOV
25+
26+clean-gcno:
27+ @echo Removing old coverage instrumentation
28+ -find -name '*.gcno' -print | xargs -r rm
29+
30+clean-gcda:
31+ @echo Removing old coverage results
32+ -find -name '*.gcda' -print | xargs -r rm
33+
34+coverage-html: clean-gcda
35+ -$(MAKE) $(AM_MAKEFLAGS) -k check
36+ $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html
37+
38+generate-coverage-html:
39+ @echo Collecting coverage data
40+ $(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool
41+ LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
42+
43+clean-coverage-html: clean-gcda
44+ -$(LCOV) --directory $(top_builddir) -z
45+ -rm -rf coverage.info coveragereport
46+
47+if HAVE_GCOVR
48+
49+coverage-gcovr: clean-gcda
50+ -$(MAKE) $(AM_MAKEFLAGS) -k check
51+ $(MAKE) $(AM_MAKEFLAGS) generate-coverage-gcovr
52+
53+generate-coverage-gcovr:
54+ @echo Generating coverage GCOVR report
55+ $(GCOVR) -x -r $(top_builddir) -o $(top_builddir)/coverage.xml
56+
57+clean-coverage-gcovr: clean-gcda
58+ -rm -rf $(top_builddir)/coverage.xml
59+
60+endif # HAVE_GCOVR
61+
62+endif # HAVE_GCOV
63
64=== modified file 'configure.ac'
65--- configure.ac 2013-02-11 21:47:09 +0000
66+++ configure.ac 2013-08-08 22:48:20 +0000
67@@ -62,6 +62,19 @@
68 fi
69 AC_SUBST(DBUSSERVICEDIR)
70
71+dnl #########################
72+dnl gcov coverage reporting
73+dnl #########################
74+
75+m4_include([m4/gcov.m4])
76+AC_TDD_GCOV
77+AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes])
78+AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes])
79+AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes])
80+AC_SUBST(COVERAGE_CFLAGS)
81+AC_SUBST(COVERAGE_CXXFLAGS)
82+AC_SUBST(COVERAGE_LDFLAGS)
83+
84 dnl ###########################################################################
85 dnl Files to generate
86 dnl ###########################################################################
87
88=== added directory 'm4'
89=== added file 'm4/gcov.m4'
90--- m4/gcov.m4 1970-01-01 00:00:00 +0000
91+++ m4/gcov.m4 2013-08-08 22:48:20 +0000
92@@ -0,0 +1,86 @@
93+# Checks for existence of coverage tools:
94+# * gcov
95+# * lcov
96+# * genhtml
97+# * gcovr
98+#
99+# Sets ac_cv_check_gcov to yes if tooling is present
100+# and reports the executables to the variables LCOV, GCOVR and GENHTML.
101+AC_DEFUN([AC_TDD_GCOV],
102+[
103+ AC_ARG_ENABLE(gcov,
104+ AS_HELP_STRING([--enable-gcov],
105+ [enable coverage testing with gcov]),
106+ [use_gcov=$enableval], [use_gcov=no])
107+
108+ if test "x$use_gcov" = "xyes"; then
109+ # we need gcc:
110+ if test "$GCC" != "yes"; then
111+ AC_MSG_ERROR([GCC is required for --enable-gcov])
112+ fi
113+
114+ # Check if ccache is being used
115+ AC_CHECK_PROG(SHTOOL, shtool, shtool)
116+ case `$SHTOOL path $CC` in
117+ *ccache*[)] gcc_ccache=yes;;
118+ *[)] gcc_ccache=no;;
119+ esac
120+
121+ if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
122+ AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
123+ fi
124+
125+ lcov_version_list="1.6 1.7 1.8 1.9"
126+ AC_CHECK_PROG(LCOV, lcov, lcov)
127+ AC_CHECK_PROG(GENHTML, genhtml, genhtml)
128+
129+ if test "$LCOV"; then
130+ AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [
131+ glib_cv_lcov_version=invalid
132+ lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
133+ for lcov_check_version in $lcov_version_list; do
134+ if test "$lcov_version" = "$lcov_check_version"; then
135+ glib_cv_lcov_version="$lcov_check_version (ok)"
136+ fi
137+ done
138+ ])
139+ else
140+ lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
141+ AC_MSG_ERROR([$lcov_msg])
142+ fi
143+
144+ case $glib_cv_lcov_version in
145+ ""|invalid[)]
146+ lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
147+ AC_MSG_ERROR([$lcov_msg])
148+ LCOV="exit 0;"
149+ ;;
150+ esac
151+
152+ if test -z "$GENHTML"; then
153+ AC_MSG_ERROR([Could not find genhtml from the lcov package])
154+ fi
155+
156+ ac_cv_check_gcov=yes
157+ ac_cv_check_lcov=yes
158+
159+ # Remove all optimization flags from CFLAGS
160+ changequote({,})
161+ CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
162+ changequote([,])
163+
164+ # Add the special gcc flags
165+ COVERAGE_CFLAGS="-O0 -fprofile-arcs -ftest-coverage"
166+ COVERAGE_CXXFLAGS="-O0 -fprofile-arcs -ftest-coverage"
167+ COVERAGE_LDFLAGS="-lgcov"
168+
169+ # Check availability of gcovr
170+ AC_CHECK_PROG(GCOVR, gcovr, gcovr)
171+ if test -z "$GCOVR"; then
172+ ac_cv_check_gcovr=no
173+ else
174+ ac_cv_check_gcovr=yes
175+ fi
176+
177+fi
178+]) # AC_TDD_GCOV
179
180=== modified file 'src/Makefile.am'
181--- src/Makefile.am 2013-02-06 03:16:55 +0000
182+++ src/Makefile.am 2013-08-08 22:48:20 +0000
183@@ -17,11 +17,15 @@
184 indicator_bluetooth_service_CFLAGS = \
185 -DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \
186 -DLOCALE_DIR=\"$(datadir)/locale\" \
187- $(INDICATOR_BLUETOOTH_SERVICE_CFLAGS)
188+ $(INDICATOR_BLUETOOTH_SERVICE_CFLAGS) \
189+ $(COVERAGE_CFLAGS)
190
191 indicator_bluetooth_service_LDADD = \
192 $(INDICATOR_BLUETOOTH_SERVICE_LIBS)
193
194+indicator_bluetooth_service_LDFLAGS = \
195+ $(COVERAGE_LDFLAGS)
196+
197 libbluetooth_la_SOURCES = \
198 config.vapi \
199 indicator3-0.4.vapi \
200@@ -37,13 +41,15 @@
201
202 libbluetooth_la_CFLAGS = \
203 -DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \
204- $(INDICATOR_BLUETOOTH_CFLAGS)
205+ $(INDICATOR_BLUETOOTH_CFLAGS) \
206+ $(COVERAGE_CFLAGS)
207
208 libbluetooth_la_LIBADD = \
209 $(INDICATOR_BLUETOOTH_LIBS)
210
211 libbluetooth_la_LDFLAGS = \
212- -module -avoid-version
213+ -module -avoid-version \
214+ $(COVERAGE_LDFLAGS)
215
216 CLEANFILES = \
217 $(patsubst %.vala,%.c,$(filter %.vala, $(SOURCES))) \

Subscribers

People subscribed via source and target branches