Merge lp:~allanlesage/ido/TDD into lp:ido/0.3

Proposed by Allan LeSage on 2012-04-02
Status: Merged
Approved by: Charles Kerr on 2012-04-12
Approved revision: 101
Merged at revision: 108
Proposed branch: lp:~allanlesage/ido/TDD
Merge into: lp:ido/0.3
Diff against target: 213 lines (+156/-2)
5 files modified
Makefile.am (+2/-0)
Makefile.am.coverage (+48/-0)
configure.ac (+11/-0)
m4/gcov.m4 (+86/-0)
src/Makefile.am (+9/-2)
To merge this branch: bzr merge lp:~allanlesage/ido/TDD
Reviewer Review Type Date Requested Status
Charles Kerr (community) 2012-04-02 Approve on 2012-04-12
Review via email: mp+100424@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.
Charles Kerr (charlesk) :
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-08-03 15:24:01 +0000
3+++ Makefile.am 2012-04-02 14:30:26 +0000
4@@ -23,3 +23,5 @@
5 EXTRA_DIST = libido.pc.in libido3.pc.in
6
7 DISTCHECK_CONFIGURE_FLAGS = --disable-gtk-doc
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:30:26 +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-21 19:33:21 +0000
66+++ configure.ac 2012-04-02 14:30:26 +0000
67@@ -117,6 +117,16 @@
68
69 AC_SUBST(MAINTAINER_CFLAGS)
70
71+dnl = gcov Coverage Reporting =================================================
72+
73+m4_include([m4/gcov.m4])
74+AC_TDD_GCOV
75+AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes])
76+AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes])
77+AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes])
78+AC_SUBST(COVERAGE_CFLAGS)
79+AC_SUBST(COVERAGE_CXXFLAGS)
80+AC_SUBST(COVERAGE_LDFLAGS)
81
82 dnl = GTK Doc Check ===========================================================
83
84@@ -140,6 +150,7 @@
85 echo ""
86 echo " Prefix : ${prefix}"
87 echo " GTK : ${with_gtk}"
88+echo " gcov : ${use_gcov}"
89 echo ""
90 echo " Documentation: ${enable_gtk_doc}"
91 echo ""
92
93=== added directory 'm4'
94=== added file 'm4/gcov.m4'
95--- m4/gcov.m4 1970-01-01 00:00:00 +0000
96+++ m4/gcov.m4 2012-04-02 14:30:26 +0000
97@@ -0,0 +1,86 @@
98+# Checks for existence of coverage tools:
99+# * gcov
100+# * lcov
101+# * genhtml
102+# * gcovr
103+#
104+# Sets ac_cv_check_gcov to yes if tooling is present
105+# and reports the executables to the variables LCOV, GCOVR and GENHTML.
106+AC_DEFUN([AC_TDD_GCOV],
107+[
108+ AC_ARG_ENABLE(gcov,
109+ AS_HELP_STRING([--enable-gcov],
110+ [enable coverage testing with gcov]),
111+ [use_gcov=$enableval], [use_gcov=no])
112+
113+ if test "x$use_gcov" = "xyes"; then
114+ # we need gcc:
115+ if test "$GCC" != "yes"; then
116+ AC_MSG_ERROR([GCC is required for --enable-gcov])
117+ fi
118+
119+ # Check if ccache is being used
120+ AC_CHECK_PROG(SHTOOL, shtool, shtool)
121+ case `$SHTOOL path $CC` in
122+ *ccache*[)] gcc_ccache=yes;;
123+ *[)] gcc_ccache=no;;
124+ esac
125+
126+ if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
127+ AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
128+ fi
129+
130+ lcov_version_list="1.6 1.7 1.8 1.9"
131+ AC_CHECK_PROG(LCOV, lcov, lcov)
132+ AC_CHECK_PROG(GENHTML, genhtml, genhtml)
133+
134+ if test "$LCOV"; then
135+ AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [
136+ glib_cv_lcov_version=invalid
137+ lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
138+ for lcov_check_version in $lcov_version_list; do
139+ if test "$lcov_version" = "$lcov_check_version"; then
140+ glib_cv_lcov_version="$lcov_check_version (ok)"
141+ fi
142+ done
143+ ])
144+ else
145+ lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
146+ AC_MSG_ERROR([$lcov_msg])
147+ fi
148+
149+ case $glib_cv_lcov_version in
150+ ""|invalid[)]
151+ lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
152+ AC_MSG_ERROR([$lcov_msg])
153+ LCOV="exit 0;"
154+ ;;
155+ esac
156+
157+ if test -z "$GENHTML"; then
158+ AC_MSG_ERROR([Could not find genhtml from the lcov package])
159+ fi
160+
161+ ac_cv_check_gcov=yes
162+ ac_cv_check_lcov=yes
163+
164+ # Remove all optimization flags from CFLAGS
165+ changequote({,})
166+ CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
167+ changequote([,])
168+
169+ # Add the special gcc flags
170+ COVERAGE_CFLAGS="-O0 -fprofile-arcs -ftest-coverage"
171+ COVERAGE_CXXFLAGS="-O0 -fprofile-arcs -ftest-coverage"
172+ COVERAGE_LDFLAGS="-lgcov"
173+
174+ # Check availability of gcovr
175+ AC_CHECK_PROG(GCOVR, gcovr, gcovr)
176+ if test -z "$GCOVR"; then
177+ ac_cv_check_gcovr=no
178+ else
179+ ac_cv_check_gcovr=yes
180+ fi
181+
182+fi
183+]) # AC_TDD_GCOV
184
185=== modified file 'src/Makefile.am'
186--- src/Makefile.am 2012-03-10 01:10:25 +0000
187+++ src/Makefile.am 2012-04-02 14:30:26 +0000
188@@ -57,6 +57,9 @@
189 $(MAINTAINER_CFLAGS) \
190 -Wall -Werror -Wextra -Wno-unused-parameter
191
192+AM_CFLAGS = \
193+ $(COVERAGE_CFLAGS)
194+
195 libido_0_1_la_SOURCES = \
196 idotypebuiltins.c \
197 idocalendarmenuitem.c \
198@@ -80,9 +83,13 @@
199 libido.h
200
201 libido_0_1_la_LIBADD = $(GTK_LIBS)
202-libido_0_1_la_LDFLAGS = $(GTK_LT_LDFLAGS)
203+libido_0_1_la_LDFLAGS = \
204+ $(GTK_LT_LDFLAGS) \
205+ $(COVERAGE_LDFLAGS)
206 libido3_0_1_la_LIBADD = $(libido_0_1_la_LIBADD)
207-libido3_0_1_la_LDFLAGS = $(libido_0_1_la_LDFLAGS)
208+libido3_0_1_la_LDFLAGS = \
209+ $(libido_0_1_la_LDFLAGS) \
210+ $(COVERAGE_LDFLAGS)
211
212 DISTCLEANFILES = \
213 stamp-idotypebuiltins.h \

Subscribers

People subscribed via source and target branches