dee

Merge lp:~fginther/dee/add-code-coverage into lp:dee

Proposed by Francis Ginther
Status: Merged
Approved by: Michal Hruby
Approved revision: 396
Merged at revision: 395
Proposed branch: lp:~fginther/dee/add-code-coverage
Merge into: lp:dee
Diff against target: 211 lines (+156/-2)
5 files modified
Makefile.am (+4/-0)
Makefile.am.coverage (+48/-0)
build/autotools/gcov.m4 (+89/-0)
configure.ac (+11/-0)
src/Makefile.am (+4/-2)
To merge this branch: bzr merge lp:~fginther/dee/add-code-coverage
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+139586@code.launchpad.net

Commit message

Add code coverage reporting with coverage-html and coverage-gcovr targets.

Coverage reporting can be enabled with --enable-gcov.

Description of the change

Add code coverage reporting with coverage-html and coverage-gcovr targets.

Coverage reporting can be enabled with --enable-gcov.

Testing:
 - Built coverage targets and verified results.
 - Built in pbuilder chroot with hooks to enable gcovr report.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
lp:~fginther/dee/add-code-coverage updated
396. By Francis Ginther

Fixed building for non-srcdir builds and cleaned up a warning message.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Francis Ginther (fginther) wrote :

I've fixed the issues with non-srcdir builds:

# mkdir builddir;cd builddir; ../autogen.sh; make

Retested with local builds, pbuilder and jenkins (the -ci run above includes coverage data).

Revision history for this message
Michal Hruby (mhr3) wrote :

Seems to work fine now (minus some warnings about double PHONY declaration)

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-08-10 10:56:44 +0000
3+++ Makefile.am 2012-12-13 21:16:19 +0000
4@@ -1,3 +1,7 @@
5+ACLOCAL_AMFLAGS = -I build/autotools
6+
7+include $(top_srcdir)/Makefile.am.coverage
8+
9 SUBDIRS = build src doc examples tools vapi bindings
10
11 pkgconfigdir = $(libdir)/pkgconfig
12
13=== added file 'Makefile.am.coverage'
14--- Makefile.am.coverage 1970-01-01 00:00:00 +0000
15+++ Makefile.am.coverage 2012-12-13 21:16:19 +0000
16@@ -0,0 +1,48 @@
17+
18+# Coverage targets
19+
20+.PHONY: clean-gcno clean-gcda \
21+ coverage-html generate-coverage-html clean-coverage-html \
22+ coverage-gcovr generate-coverage-gcovr clean-coverage-gcovr
23+
24+clean-local: clean-gcno clean-coverage-html clean-coverage-gcovr
25+
26+if HAVE_GCOV
27+
28+clean-gcno:
29+ @echo Removing old coverage instrumentation
30+ -find -name '*.gcno' -print | xargs -r rm
31+
32+clean-gcda:
33+ @echo Removing old coverage results
34+ -find -name '*.gcda' -print | xargs -r rm
35+
36+coverage-html:
37+ -$(MAKE) $(AM_MAKEFLAGS) -k check
38+ $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html
39+
40+generate-coverage-html:
41+ @echo Collecting coverage data
42+ $(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool
43+ LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
44+
45+clean-coverage-html: clean-gcda
46+ -$(LCOV) --directory $(top_builddir) -z
47+ -rm -rf coverage.info coveragereport
48+
49+if HAVE_GCOVR
50+
51+coverage-gcovr:
52+ -$(MAKE) $(AM_MAKEFLAGS) -k check
53+ $(MAKE) $(AM_MAKEFLAGS) generate-coverage-gcovr
54+
55+generate-coverage-gcovr:
56+ @echo Generating coverage GCOVR report
57+ $(GCOVR) --xml -r $(top_builddir) -o $(top_builddir)/coverage.xml
58+
59+clean-coverage-gcovr: clean-gcda
60+ -rm -rf $(top_builddir)/coverage.xml
61+
62+endif # HAVE_GCOVR
63+
64+endif # HAVE_GCOV
65
66=== added file 'build/autotools/gcov.m4'
67--- build/autotools/gcov.m4 1970-01-01 00:00:00 +0000
68+++ build/autotools/gcov.m4 2012-12-13 21:16:19 +0000
69@@ -0,0 +1,89 @@
70+# Checks for existence of coverage tools:
71+# * gcov
72+# * lcov
73+# * genhtml
74+# * gcovr
75+#
76+# Sets ac_cv_check_gcov to yes if tooling is present
77+# and reports the executables to the variables LCOV, GCOVR and GENHTML.
78+AC_DEFUN([AC_TDD_GCOV],
79+[
80+ AC_ARG_ENABLE(gcov,
81+ AS_HELP_STRING([--enable-gcov],
82+ [enable coverage testing with gcov]),
83+ [use_gcov=$enableval], [use_gcov=no])
84+
85+ AM_CONDITIONAL(HAVE_GCOV, test "x$use_gcov" = "xyes")
86+
87+ if test "x$use_gcov" = "xyes"; then
88+ # we need gcc:
89+ if test "$GCC" != "yes"; then
90+ AC_MSG_ERROR([GCC is required for --enable-gcov])
91+ fi
92+
93+ # Check if ccache is being used
94+ AC_CHECK_PROG(SHTOOL, shtool, shtool)
95+ if test "$SHTOOL"; then
96+ AS_CASE([`$SHTOOL path $CC`],
97+ [*ccache*], [gcc_ccache=yes],
98+ [gcc_ccache=no])
99+ fi
100+
101+ if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
102+ AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
103+ fi
104+
105+ lcov_version_list="1.6 1.7 1.8 1.9"
106+ AC_CHECK_PROG(LCOV, lcov, lcov)
107+ AC_CHECK_PROG(GENHTML, genhtml, genhtml)
108+
109+ if test "$LCOV"; then
110+ AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [
111+ glib_cv_lcov_version=invalid
112+ lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
113+ for lcov_check_version in $lcov_version_list; do
114+ if test "$lcov_version" = "$lcov_check_version"; then
115+ glib_cv_lcov_version="$lcov_check_version (ok)"
116+ fi
117+ done
118+ ])
119+ else
120+ lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
121+ AC_MSG_ERROR([$lcov_msg])
122+ fi
123+
124+ case $glib_cv_lcov_version in
125+ ""|invalid[)]
126+ lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
127+ AC_MSG_ERROR([$lcov_msg])
128+ LCOV="exit 0;"
129+ ;;
130+ esac
131+
132+ if test -z "$GENHTML"; then
133+ AC_MSG_ERROR([Could not find genhtml from the lcov package])
134+ fi
135+
136+ ac_cv_check_gcov=yes
137+ ac_cv_check_lcov=yes
138+
139+ # Remove all optimization flags from CFLAGS
140+ changequote({,})
141+ CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
142+ changequote([,])
143+
144+ # Add the special gcc flags
145+ COVERAGE_CFLAGS="-O0 --coverage"
146+ COVERAGE_CXXFLAGS="-O0 --coverage"
147+ COVERAGE_LDFLAGS="-lgcov"
148+
149+ # Check availability of gcovr
150+ AC_CHECK_PROG(GCOVR, gcovr, gcovr)
151+ if test -z "$GCOVR"; then
152+ ac_cv_check_gcovr=no
153+ else
154+ ac_cv_check_gcovr=yes
155+ fi
156+fi
157+]) # AC_TDD_GCOV
158+
159
160=== modified file 'configure.ac'
161--- configure.ac 2012-11-28 08:53:48 +0000
162+++ configure.ac 2012-12-13 21:16:19 +0000
163@@ -140,6 +140,16 @@
164
165 AM_CONDITIONAL([WANT_TESTS], [test "x$enable_tests" != "xno"])
166
167+###########################
168+# gcov coverage reporting
169+###########################
170+AC_TDD_GCOV
171+AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes])
172+AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes])
173+AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes])
174+AC_SUBST(COVERAGE_CFLAGS)
175+AC_SUBST(COVERAGE_LDFLAGS)
176+
177 dnl = Check for GLib Test Extensions (GTX) ====================================
178 AC_ARG_ENABLE([extended-tests],
179 AS_HELP_STRING([--enable-extended-tests=@<:@no/yes@:>@],[build extended test suite (requires libgtx from lp:gtx) @<:@default=no@:>@]),,
180@@ -245,6 +255,7 @@
181
182 Tests : ${enable_tests}
183 Extended Tests : ${enable_extended_tests}
184+ Coverage : ${use_gcov}
185 Verbose logging: ${enable_trace_log}
186
187 Extra CFlags : ${CPPFLAGS} $MAINTAINER_CFLAGS
188
189=== modified file 'src/Makefile.am'
190--- src/Makefile.am 2012-11-28 08:53:48 +0000
191+++ src/Makefile.am 2012-12-13 21:16:19 +0000
192@@ -101,7 +101,8 @@
193 $(DEE_LIBS)
194
195 libdee_1_0_la_LDFLAGS = \
196- $(DEE_LT_LDFLAGS)
197+ $(DEE_LT_LDFLAGS) \
198+ $(COVERAGE_LDFLAGS)
199
200 libdee_1_0_la_CPPFLAGS = \
201 -I$(srcdir) \
202@@ -114,7 +115,8 @@
203 -DDEE_COMPILATION \
204 $(GCC_FLAGS) \
205 $(DEE_CFLAGS) \
206- $(MAINTAINER_CFLAGS)
207+ $(MAINTAINER_CFLAGS) \
208+ $(COVERAGE_CFLAGS)
209
210 if HAVE_ICU
211 devel_headers += dee-icu.h

Subscribers

People subscribed via source and target branches

to all changes: