Merge lp:~allanlesage/libdbusmenu/TDD into lp:libdbusmenu/0.6

Proposed by Allan LeSage
Status: Merged
Approved by: Charles Kerr
Approved revision: 378
Merged at revision: 399
Proposed branch: lp:~allanlesage/libdbusmenu/TDD
Merge into: lp:libdbusmenu/0.6
Diff against target: 258 lines (+169/-2)
6 files modified
Makefile.am (+2/-0)
Makefile.am.coverage (+48/-0)
configure.ac (+16/-0)
libdbusmenu-glib/Makefile.am (+8/-1)
libdbusmenu-gtk/Makefile.am (+9/-1)
m4/gcov.m4 (+86/-0)
To merge this branch: bzr merge lp:~allanlesage/libdbusmenu/TDD
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
Review via email: mp+100425@code.launchpad.net

Description of the change

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

To post a comment you must log in.
Revision history for this message
Charles Kerr (charlesk) wrote :

This patch looks familiar.

review: Approve

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 2011-09-03 02:53:48 +0000
3+++ Makefile.am 2012-04-02 14:31:24 +0000
4@@ -53,3 +53,5 @@
5 else \
6 echo Failed to generate AUTHORS: not a branch >&2; \
7 fi
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 2012-04-02 14:31:24 +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 2012-03-29 18:08:49 +0000
66+++ configure.ac 2012-04-02 14:31:24 +0000
67@@ -194,6 +194,18 @@
68 fi
69
70 ###########################
71+# gcov coverage reporting
72+###########################
73+
74+m4_include([m4/gcov.m4])
75+AC_TDD_GCOV
76+AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes])
77+AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes])
78+AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes])
79+AC_SUBST(COVERAGE_CFLAGS)
80+AC_SUBST(COVERAGE_LDFLAGS)
81+
82+###########################
83 # Files
84 ###########################
85
86@@ -251,3 +263,7 @@
87 AC_MSG_NOTICE([ Dumper: no])
88 )
89
90+AS_IF([test "x$use_gcov" = "xyes"],
91+ AC_MSG_NOTICE([ Coverage reporting: yes]),
92+ AC_MSG_NOTICE([ Coverage reporting: no])
93+)
94
95=== modified file 'libdbusmenu-glib/Makefile.am'
96--- libdbusmenu-glib/Makefile.am 2012-03-29 17:45:44 +0000
97+++ libdbusmenu-glib/Makefile.am 2012-04-02 14:31:24 +0000
98@@ -58,12 +58,14 @@
99 client.c
100
101 libdbusmenu_glib_la_LDFLAGS = \
102+ $(COVERAGE_LDFLAGS) \
103 -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \
104 -no-undefined \
105 -export-symbols-regex "^[^_].*"
106
107 libdbusmenu_glib_la_CFLAGS = \
108 $(DBUSMENUGLIB_CFLAGS) \
109+ $(COVERAGE_CFLAGS) \
110 -Wall -Werror -Wno-error=deprecated-declarations \
111 -DG_LOG_DOMAIN="\"LIBDBUSMENU-GLIB\""
112
113@@ -181,7 +183,12 @@
114 Dbusmenu-0.4.gir: libdbusmenu-glib.la
115 Dbusmenu_0_4_gir_INCLUDES = \
116 GObject-2.0
117-Dbusmenu_0_4_gir_CFLAGS = $(DBUSMENUGLIB_CFLAGS) -I$(top_srcdir)
118+Dbusmenu_0_4_gir_CFLAGS = \
119+ $(DBUSMENUGLIB_CFLAGS) \
120+ $(COVERAGE_CFLAGS) \
121+ -I$(top_srcdir)
122+Dbusmenu_0_4_gir_LDFLAGS = \
123+ $(COVERAGE_LDFLAGS)
124 Dbusmenu_0_4_gir_LIBS = libdbusmenu-glib.la
125 Dbusmenu_0_4_gir_FILES = $(introspection_sources)
126 Dbusmenu_0_4_gir_NAMESPACE = Dbusmenu
127
128=== modified file 'libdbusmenu-gtk/Makefile.am'
129--- libdbusmenu-gtk/Makefile.am 2012-01-27 08:12:20 +0000
130+++ libdbusmenu-gtk/Makefile.am 2012-04-02 14:31:24 +0000
131@@ -57,12 +57,14 @@
132 parser.c
133
134 libdbusmenu_gtk_la_LDFLAGS = \
135+ $(COVERAGE_LDFLAGS) \
136 -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \
137 -no-undefined \
138 -export-symbols-regex "^[^_].*"
139
140 libdbusmenu_gtk_la_CFLAGS = \
141 $(DBUSMENUGTK_CFLAGS) \
142+ $(COVERAGE_CFLAGS) \
143 -I$(top_srcdir) \
144 -Wall -Werror -Wno-error=deprecated-declarations \
145 -DG_LOG_DOMAIN="\"LIBDBUSMENU-GTK\""
146@@ -117,7 +119,12 @@
147 GObject-2.0 \
148 $(GTKGIR) \
149 Dbusmenu-0.4
150-DbusmenuGtk_0_4_gir_CFLAGS = $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir)
151+DbusmenuGtk_0_4_gir_CFLAGS = \
152+ $(DBUSMENUGTK_CFLAGS) \
153+ $(COVERAGE_CFLAGS) \
154+ -I$(top_srcdir)
155+DbusmenuGtk_0_4_gir_LDFLAGS = \
156+ $(COVERAGE_LDFLAGS)
157 DbusmenuGtk_0_4_gir_LIBS = libdbusmenu-gtk$(VER).la \
158 $(top_builddir)/libdbusmenu-glib/libdbusmenu-glib.la
159 DbusmenuGtk_0_4_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources))
160@@ -127,6 +134,7 @@
161 # We duplicate these for the same reason as libdbusmenu_gtk3includedir above
162 DbusmenuGtk3_0_4_gir_INCLUDES = $(DbusmenuGtk_0_4_gir_INCLUDES)
163 DbusmenuGtk3_0_4_gir_CFLAGS = $(DbusmenuGtk_0_4_gir_CFLAGS)
164+DbusmenuGtk3_0_4_gir_LDFLAGS = $(DbusmenuGtk_0_4_gir_LDFLAGS)
165 DbusmenuGtk3_0_4_gir_LIBS = $(DbusmenuGtk_0_4_gir_LIBS)
166 DbusmenuGtk3_0_4_gir_FILES = $(DbusmenuGtk_0_4_gir_FILES)
167 DbusmenuGtk3_0_4_gir_NAMESPACE = $(DbusmenuGtk_0_4_gir_NAMESPACE)
168
169=== added file 'm4/gcov.m4'
170--- m4/gcov.m4 1970-01-01 00:00:00 +0000
171+++ m4/gcov.m4 2012-04-02 14:31:24 +0000
172@@ -0,0 +1,86 @@
173+# Checks for existence of coverage tools:
174+# * gcov
175+# * lcov
176+# * genhtml
177+# * gcovr
178+#
179+# Sets ac_cv_check_gcov to yes if tooling is present
180+# and reports the executables to the variables LCOV, GCOVR and GENHTML.
181+AC_DEFUN([AC_TDD_GCOV],
182+[
183+ AC_ARG_ENABLE(gcov,
184+ AS_HELP_STRING([--enable-gcov],
185+ [enable coverage testing with gcov]),
186+ [use_gcov=$enableval], [use_gcov=no])
187+
188+ if test "x$use_gcov" = "xyes"; then
189+ # we need gcc:
190+ if test "$GCC" != "yes"; then
191+ AC_MSG_ERROR([GCC is required for --enable-gcov])
192+ fi
193+
194+ # Check if ccache is being used
195+ AC_CHECK_PROG(SHTOOL, shtool, shtool)
196+ case `$SHTOOL path $CC` in
197+ *ccache*[)] gcc_ccache=yes;;
198+ *[)] gcc_ccache=no;;
199+ esac
200+
201+ if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
202+ AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
203+ fi
204+
205+ lcov_version_list="1.6 1.7 1.8 1.9"
206+ AC_CHECK_PROG(LCOV, lcov, lcov)
207+ AC_CHECK_PROG(GENHTML, genhtml, genhtml)
208+
209+ if test "$LCOV"; then
210+ AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [
211+ glib_cv_lcov_version=invalid
212+ lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
213+ for lcov_check_version in $lcov_version_list; do
214+ if test "$lcov_version" = "$lcov_check_version"; then
215+ glib_cv_lcov_version="$lcov_check_version (ok)"
216+ fi
217+ done
218+ ])
219+ else
220+ lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
221+ AC_MSG_ERROR([$lcov_msg])
222+ fi
223+
224+ case $glib_cv_lcov_version in
225+ ""|invalid[)]
226+ lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
227+ AC_MSG_ERROR([$lcov_msg])
228+ LCOV="exit 0;"
229+ ;;
230+ esac
231+
232+ if test -z "$GENHTML"; then
233+ AC_MSG_ERROR([Could not find genhtml from the lcov package])
234+ fi
235+
236+ ac_cv_check_gcov=yes
237+ ac_cv_check_lcov=yes
238+
239+ # Remove all optimization flags from CFLAGS
240+ changequote({,})
241+ CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
242+ changequote([,])
243+
244+ # Add the special gcc flags
245+ COVERAGE_CFLAGS="-O0 -fprofile-arcs -ftest-coverage"
246+ COVERAGE_CXXFLAGS="-O0 -fprofile-arcs -ftest-coverage"
247+ COVERAGE_LDFLAGS="-lgcov"
248+
249+ # Check availability of gcovr
250+ AC_CHECK_PROG(GCOVR, gcovr, gcovr)
251+ if test -z "$GCOVR"; then
252+ ac_cv_check_gcovr=no
253+ else
254+ ac_cv_check_gcovr=yes
255+ fi
256+
257+fi
258+]) # AC_TDD_GCOV

Subscribers

People subscribed via source and target branches

to all changes: