Merge lp:~allanlesage/appmenu-gtk/TDD into lp:appmenu-gtk/0.4

Proposed by Allan LeSage
Status: Merged
Approved by: Charles Kerr
Approved revision: 148
Merged at revision: 151
Proposed branch: lp:~allanlesage/appmenu-gtk/TDD
Merge into: lp:appmenu-gtk/0.4
Diff against target: 215 lines (+155/-2)
5 files modified
Makefile.am (+3/-1)
Makefile.am.coverage (+48/-0)
configure.ac (+14/-1)
m4/gcov.m4 (+86/-0)
src/Makefile.am (+4/-0)
To merge this branch: bzr merge lp:~allanlesage/appmenu-gtk/TDD
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
Review via email: mp+100426@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 2012-02-08 16:00:23 +0000
3+++ Makefile.am 2012-04-02 14:32:28 +0000
4@@ -1,4 +1,4 @@
5-ACLOCAL_AMFLAGS = -I build/autotools
6+ACLOCAL_AMFLAGS = -I m4
7
8 SUBDIRS = \
9 src
10@@ -17,3 +17,5 @@
11 80appmenu.in
12
13 DISTCLEANFILES = $(sessionfile)
14+
15+include $(top_srcdir)/Makefile.am.coverage
16
17=== added file 'Makefile.am.coverage'
18--- Makefile.am.coverage 1970-01-01 00:00:00 +0000
19+++ Makefile.am.coverage 2012-04-02 14:32:28 +0000
20@@ -0,0 +1,48 @@
21+
22+# Coverage targets
23+
24+.PHONY: clean-gcno clean-gcda \
25+ coverage-html generate-coverage-html clean-coverage-html \
26+ coverage-gcovr generate-coverage-gcovr clean-coverage-gcovr
27+
28+clean-local: clean-gcno clean-coverage-html clean-coverage-gcovr
29+
30+if HAVE_GCOV
31+
32+clean-gcno:
33+ @echo Removing old coverage instrumentation
34+ -find -name '*.gcno' -print | xargs -r rm
35+
36+clean-gcda:
37+ @echo Removing old coverage results
38+ -find -name '*.gcda' -print | xargs -r rm
39+
40+coverage-html: clean-gcda
41+ -$(MAKE) $(AM_MAKEFLAGS) -k check
42+ $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html
43+
44+generate-coverage-html:
45+ @echo Collecting coverage data
46+ $(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool
47+ LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
48+
49+clean-coverage-html: clean-gcda
50+ -$(LCOV) --directory $(top_builddir) -z
51+ -rm -rf coverage.info coveragereport
52+
53+if HAVE_GCOVR
54+
55+coverage-gcovr: clean-gcda
56+ -$(MAKE) $(AM_MAKEFLAGS) -k check
57+ $(MAKE) $(AM_MAKEFLAGS) generate-coverage-gcovr
58+
59+generate-coverage-gcovr:
60+ @echo Generating coverage GCOVR report
61+ $(GCOVR) -x -r $(top_builddir) -o $(top_builddir)/coverage.xml
62+
63+clean-coverage-gcovr: clean-gcda
64+ -rm -rf $(top_builddir)/coverage.xml
65+
66+endif # HAVE_GCOVR
67+
68+endif # HAVE_GCOV
69
70=== modified file 'configure.ac'
71--- configure.ac 2012-03-08 23:15:31 +0000
72+++ configure.ac 2012-04-02 14:32:28 +0000
73@@ -3,7 +3,7 @@
74 AC_INIT([appmenu-gtk], [0.3.91], [crussell@canonical.com])
75 AC_COPYRIGHT([Copyright 2010 Canonical])
76 AC_CONFIG_SRCDIR([src/bridge.c])
77-AC_CONFIG_MACRO_DIR([build/autotools])
78+AC_CONFIG_MACRO_DIR([m4])
79
80 AM_CONFIG_HEADER(config.h)
81 AM_INIT_AUTOMAKE([1.9])
82@@ -59,6 +59,18 @@
83 AC_SUBST(moduledir)
84 AC_SUBST(sessionfile)
85
86+###########################
87+# gcov coverage reporting
88+###########################
89+
90+m4_include([m4/gcov.m4])
91+AC_TDD_GCOV
92+AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes])
93+AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes])
94+AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes])
95+AC_SUBST(COVERAGE_CFLAGS)
96+AC_SUBST(COVERAGE_LDFLAGS)
97+
98 AC_CONFIG_FILES([
99 Makefile
100 src/Makefile
101@@ -76,5 +88,6 @@
102
103 Prefix: $prefix
104 GTK+ API: $gtk_api
105+ Coverage reporting: $use_gcov
106 ])
107
108
109=== added directory 'm4'
110=== added file 'm4/gcov.m4'
111--- m4/gcov.m4 1970-01-01 00:00:00 +0000
112+++ m4/gcov.m4 2012-04-02 14:32:28 +0000
113@@ -0,0 +1,86 @@
114+# Checks for existence of coverage tools:
115+# * gcov
116+# * lcov
117+# * genhtml
118+# * gcovr
119+#
120+# Sets ac_cv_check_gcov to yes if tooling is present
121+# and reports the executables to the variables LCOV, GCOVR and GENHTML.
122+AC_DEFUN([AC_TDD_GCOV],
123+[
124+ AC_ARG_ENABLE(gcov,
125+ AS_HELP_STRING([--enable-gcov],
126+ [enable coverage testing with gcov]),
127+ [use_gcov=$enableval], [use_gcov=no])
128+
129+ if test "x$use_gcov" = "xyes"; then
130+ # we need gcc:
131+ if test "$GCC" != "yes"; then
132+ AC_MSG_ERROR([GCC is required for --enable-gcov])
133+ fi
134+
135+ # Check if ccache is being used
136+ AC_CHECK_PROG(SHTOOL, shtool, shtool)
137+ case `$SHTOOL path $CC` in
138+ *ccache*[)] gcc_ccache=yes;;
139+ *[)] gcc_ccache=no;;
140+ esac
141+
142+ if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
143+ AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
144+ fi
145+
146+ lcov_version_list="1.6 1.7 1.8 1.9"
147+ AC_CHECK_PROG(LCOV, lcov, lcov)
148+ AC_CHECK_PROG(GENHTML, genhtml, genhtml)
149+
150+ if test "$LCOV"; then
151+ AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [
152+ glib_cv_lcov_version=invalid
153+ lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
154+ for lcov_check_version in $lcov_version_list; do
155+ if test "$lcov_version" = "$lcov_check_version"; then
156+ glib_cv_lcov_version="$lcov_check_version (ok)"
157+ fi
158+ done
159+ ])
160+ else
161+ lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
162+ AC_MSG_ERROR([$lcov_msg])
163+ fi
164+
165+ case $glib_cv_lcov_version in
166+ ""|invalid[)]
167+ lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
168+ AC_MSG_ERROR([$lcov_msg])
169+ LCOV="exit 0;"
170+ ;;
171+ esac
172+
173+ if test -z "$GENHTML"; then
174+ AC_MSG_ERROR([Could not find genhtml from the lcov package])
175+ fi
176+
177+ ac_cv_check_gcov=yes
178+ ac_cv_check_lcov=yes
179+
180+ # Remove all optimization flags from CFLAGS
181+ changequote({,})
182+ CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
183+ changequote([,])
184+
185+ # Add the special gcc flags
186+ COVERAGE_CFLAGS="-O0 -fprofile-arcs -ftest-coverage"
187+ COVERAGE_CXXFLAGS="-O0 -fprofile-arcs -ftest-coverage"
188+ COVERAGE_LDFLAGS="-lgcov"
189+
190+ # Check availability of gcovr
191+ AC_CHECK_PROG(GCOVR, gcovr, gcovr)
192+ if test -z "$GCOVR"; then
193+ ac_cv_check_gcovr=no
194+ else
195+ ac_cv_check_gcovr=yes
196+ fi
197+
198+fi
199+]) # AC_TDD_GCOV
200
201=== modified file 'src/Makefile.am'
202--- src/Makefile.am 2011-05-08 20:07:37 +0000
203+++ src/Makefile.am 2012-04-02 14:32:28 +0000
204@@ -15,7 +15,11 @@
205 -Wall -Werror \
206 $(APPMENU_CFLAGS)
207
208+libappmenu_la_CFLAGS = \
209+ $(COVERAGE_CFLAGS)
210+
211 libappmenu_la_LDFLAGS = \
212+ $(COVERAGE_LDFLAGS) \
213 -module -avoid-version
214
215 libappmenu_la_LIBADD = \

Subscribers

People subscribed via source and target branches