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

Proposed by Allan LeSage
Status: Merged
Approved by: William Hua
Approved revision: 101
Merged at revision: 182
Proposed branch: lp:~allanlesage/indicator-keyboard/add-coverage-tooling
Merge into: lp:indicator-keyboard
Diff against target: 239 lines (+160/-5)
7 files modified
.bzrignore (+7/-1)
Makefile.am (+2/-0)
Makefile.am.coverage (+48/-0)
configure.ac (+9/-0)
data/Makefile.am (+4/-2)
lib/Makefile.am (+4/-2)
m4/gcov.m4 (+86/-0)
To merge this branch: bzr merge lp:~allanlesage/indicator-keyboard/add-coverage-tooling
Reviewer Review Type Date Requested Status
William Hua (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+179294@code.launchpad.net

Description of the change

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/ .

To post a comment you must log in.
Revision history for this message
Allan LeSage (allanlesage) wrote :

Oops one thing comes up: I have an .m4 file that I'm putting into the m4 dir, do you mind if I modify the .bzrignore? Will resubmit in a second.

100. By Allan LeSage

Add gcov.m4, adjust .bzrignore for m4 files, add coverage Makefile.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
William Hua (attente) wrote :

The .gcda files may not be writing properly every time because the indicator-keyboard-service process in the test gets killed before it has a chance to write it, leading to the raciness of having those files or not. I'll try adding a way to cleanly exit the service and hopefully this will work properly every time.

Revision history for this message
William Hua (attente) wrote :

Approve, just needs conflict resolution with trunk.

review: Approve
101. By Allan LeSage

Merge trunk, resolving Makefile conflict.

Revision history for this message
Allan LeSage (allanlesage) wrote :

Resolved and tested.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
William Hua (attente) wrote :

Thanks, works on my end too!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2013-07-18 22:01:28 +0000
3+++ .bzrignore 2013-11-21 16:37:49 +0000
4@@ -1,6 +1,5 @@
5 *.c
6 *.log
7-*.m4
8 *.pyc
9 *.stamp
10 *.stamp-t
11@@ -34,3 +33,10 @@
12 tests/indicator-keyboard-test.trs
13 tests/indicator-keyboard-tests
14 tests/services/indicator-keyboard.service
15+aclocal.m4
16+m4/intltool.m4
17+m4/libtool.m4
18+m4/lt~obsolete.m4
19+m4/ltoptions.m4
20+m4/ltsugar.m4
21+m4/ltversion.m4
22\ No newline at end of file
23
24=== modified file 'Makefile.am'
25--- Makefile.am 2013-07-02 13:10:50 +0000
26+++ Makefile.am 2013-11-21 16:37:49 +0000
27@@ -1,3 +1,5 @@
28 ACLOCAL_AMFLAGS = -I m4
29
30 SUBDIRS = po lib data tests
31+
32+include $(top_srcdir)/Makefile.am.coverage
33
34=== added file 'Makefile.am.coverage'
35--- Makefile.am.coverage 1970-01-01 00:00:00 +0000
36+++ Makefile.am.coverage 2013-11-21 16:37:49 +0000
37@@ -0,0 +1,48 @@
38+
39+# Coverage targets
40+
41+.PHONY: clean-gcno clean-gcda \
42+ coverage-html generate-coverage-html clean-coverage-html \
43+ coverage-gcovr generate-coverage-gcovr clean-coverage-gcovr
44+
45+clean-local: clean-gcno clean-coverage-html clean-coverage-gcovr
46+
47+if HAVE_GCOV
48+
49+clean-gcno:
50+ @echo Removing old coverage instrumentation
51+ -find -name '*.gcno' -print | xargs -r rm
52+
53+clean-gcda:
54+ @echo Removing old coverage results
55+ -find -name '*.gcda' -print | xargs -r rm
56+
57+coverage-html: clean-gcda
58+ -$(MAKE) $(AM_MAKEFLAGS) -k check
59+ $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html
60+
61+generate-coverage-html:
62+ @echo Collecting coverage data
63+ $(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool
64+ LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
65+
66+clean-coverage-html: clean-gcda
67+ -$(LCOV) --directory $(top_builddir) -z
68+ -rm -rf coverage.info coveragereport
69+
70+if HAVE_GCOVR
71+
72+coverage-gcovr: clean-gcda
73+ -$(MAKE) $(AM_MAKEFLAGS) -k check
74+ $(MAKE) $(AM_MAKEFLAGS) generate-coverage-gcovr
75+
76+generate-coverage-gcovr:
77+ @echo Generating coverage GCOVR report
78+ $(GCOVR) -x -r $(top_builddir) -o $(top_builddir)/coverage.xml
79+
80+clean-coverage-gcovr: clean-gcda
81+ -rm -rf $(top_builddir)/coverage.xml
82+
83+endif # HAVE_GCOVR
84+
85+endif # HAVE_GCOV
86
87=== modified file 'configure.ac'
88--- configure.ac 2013-08-22 10:36:10 +0000
89+++ configure.ac 2013-11-21 16:37:49 +0000
90@@ -82,6 +82,15 @@
91 AC_SUBST([BAMF_CFLAGS])
92 AC_SUBST([BAMF_LIBS])
93
94+m4_include([m4/gcov.m4])
95+AC_TDD_GCOV
96+AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes])
97+AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes])
98+AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes])
99+AC_SUBST(COVERAGE_CFLAGS)
100+AC_SUBST(COVERAGE_CXXFLAGS)
101+AC_SUBST(COVERAGE_LDFLAGS)
102+
103 AC_CONFIG_FILES([Makefile
104 data/Makefile
105 lib/Makefile
106
107=== modified file 'data/Makefile.am'
108--- data/Makefile.am 2013-10-31 18:39:04 +0000
109+++ data/Makefile.am 2013-11-21 16:37:49 +0000
110@@ -22,13 +22,15 @@
111 $(PANGOFT2_CFLAGS) \
112 $(GTK_CFLAGS) \
113 $(GNOME_DESKTOP_CFLAGS) \
114- $(LIBXKLAVIER_CFLAGS)
115+ $(LIBXKLAVIER_CFLAGS) \
116+ $(COVERAGE_CFLAGS)
117 indicator_keyboard_icon_generator_LDFLAGS = $(AM_LDFLAGS) \
118 $(GEE_LIBS) \
119 $(PANGOFT2_LIBS) \
120 $(GTK_LIBS) \
121 $(GNOME_DESKTOP_LIBS) \
122- $(LIBXKLAVIER_LIBS)
123+ $(LIBXKLAVIER_LIBS) \
124+ $(COVERAGE_LDFLAGS)
125
126 dist_service_DATA = indicator-keyboard.service
127 servicedir = $(DBUS_SERVICE_DIR)
128
129=== modified file 'lib/Makefile.am'
130--- lib/Makefile.am 2013-10-31 00:22:26 +0000
131+++ lib/Makefile.am 2013-11-21 16:37:49 +0000
132@@ -32,7 +32,8 @@
133 $(IBUS_CFLAGS) \
134 $(ACCOUNTSSERVICE_CFLAGS) \
135 $(LIGHTDM_CFLAGS) \
136- $(BAMF_CFLAGS)
137+ $(BAMF_CFLAGS) \
138+ $(COVERAGE_CFLAGS)
139 indicator_keyboard_service_LDFLAGS = $(AM_LDFLAGS) \
140 $(GEE_LIBS) \
141 $(PANGOCAIRO_LIBS) \
142@@ -43,4 +44,5 @@
143 $(IBUS_LIBS) \
144 $(ACCOUNTSSERVICE_LIBS) \
145 $(LIGHTDM_LIBS) \
146- $(BAMF_LIBS)
147+ $(BAMF_LIBS) \
148+ $(COVERAGE_LDFLAGS)
149
150=== added file 'm4/gcov.m4'
151--- m4/gcov.m4 1970-01-01 00:00:00 +0000
152+++ m4/gcov.m4 2013-11-21 16:37:49 +0000
153@@ -0,0 +1,86 @@
154+# Checks for existence of coverage tools:
155+# * gcov
156+# * lcov
157+# * genhtml
158+# * gcovr
159+#
160+# Sets ac_cv_check_gcov to yes if tooling is present
161+# and reports the executables to the variables LCOV, GCOVR and GENHTML.
162+AC_DEFUN([AC_TDD_GCOV],
163+[
164+ AC_ARG_ENABLE(gcov,
165+ AS_HELP_STRING([--enable-gcov],
166+ [enable coverage testing with gcov]),
167+ [use_gcov=$enableval], [use_gcov=no])
168+
169+ if test "x$use_gcov" = "xyes"; then
170+ # we need gcc:
171+ if test "$GCC" != "yes"; then
172+ AC_MSG_ERROR([GCC is required for --enable-gcov])
173+ fi
174+
175+ # Check if ccache is being used
176+ AC_CHECK_PROG(SHTOOL, shtool, shtool)
177+ case `$SHTOOL path $CC` in
178+ *ccache*[)] gcc_ccache=yes;;
179+ *[)] gcc_ccache=no;;
180+ esac
181+
182+ if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
183+ AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
184+ fi
185+
186+ lcov_version_list="1.6 1.7 1.8 1.9"
187+ AC_CHECK_PROG(LCOV, lcov, lcov)
188+ AC_CHECK_PROG(GENHTML, genhtml, genhtml)
189+
190+ if test "$LCOV"; then
191+ AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [
192+ glib_cv_lcov_version=invalid
193+ lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
194+ for lcov_check_version in $lcov_version_list; do
195+ if test "$lcov_version" = "$lcov_check_version"; then
196+ glib_cv_lcov_version="$lcov_check_version (ok)"
197+ fi
198+ done
199+ ])
200+ else
201+ lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
202+ AC_MSG_ERROR([$lcov_msg])
203+ fi
204+
205+ case $glib_cv_lcov_version in
206+ ""|invalid[)]
207+ lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
208+ AC_MSG_ERROR([$lcov_msg])
209+ LCOV="exit 0;"
210+ ;;
211+ esac
212+
213+ if test -z "$GENHTML"; then
214+ AC_MSG_ERROR([Could not find genhtml from the lcov package])
215+ fi
216+
217+ ac_cv_check_gcov=yes
218+ ac_cv_check_lcov=yes
219+
220+ # Remove all optimization flags from CFLAGS
221+ changequote({,})
222+ CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
223+ changequote([,])
224+
225+ # Add the special gcc flags
226+ COVERAGE_CFLAGS="-O0 -fprofile-arcs -ftest-coverage"
227+ COVERAGE_CXXFLAGS="-O0 -fprofile-arcs -ftest-coverage"
228+ COVERAGE_LDFLAGS="-lgcov"
229+
230+ # Check availability of gcovr
231+ AC_CHECK_PROG(GCOVR, gcovr, gcovr)
232+ if test -z "$GCOVR"; then
233+ ac_cv_check_gcovr=no
234+ else
235+ ac_cv_check_gcovr=yes
236+ fi
237+
238+fi
239+]) # AC_TDD_GCOV

Subscribers

People subscribed via source and target branches

to all changes: