Merge lp:~fginther/bamf/add-code-coverage into lp:bamf/0.4

Proposed by Francis Ginther on 2012-12-06
Status: Merged
Approved by: Francis Ginther on 2012-12-17
Approved revision: 504
Merged at revision: 508
Proposed branch: lp:~fginther/bamf/add-code-coverage
Merge into: lp:bamf/0.4
Diff against target: 221 lines (+154/-0)
6 files modified
Makefile.am (+2/-0)
Makefile.am.coverage (+48/-0)
configure.ac (+11/-0)
lib/libbamf/Makefile.am (+2/-0)
m4/gcov.m4 (+89/-0)
src/Makefile.am (+2/-0)
To merge this branch: bzr merge lp:~fginther/bamf/add-code-coverage
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing on 2012-12-17
Marco Trevisan (Treviño) Approve on 2012-12-17
Allan LeSage (community) 2012-12-06 Approve on 2012-12-13
Review via email: mp+138590@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.
Allan LeSage (allanlesage) wrote :

I think this might be necessary:

=== modified file 'lib/libbamf/Makefile.am'
--- lib/libbamf/Makefile.am 2012-12-06 21:29:22 +0000
+++ lib/libbamf/Makefile.am 2012-12-13 17:42:59 +0000
@@ -73,7 +73,7 @@
 libbamf3_la_LDFLAGS = \
   -shared \
   -export-symbols-regex "^bamf_" \
- $(COVERAGE_CFLAGS) \
+ $(COVERAGE_LDFLAGS) \
   $(NULL)

 glib_marshal_list = bamf-marshal.list

Otherwise looks good!

review: Approve
Francis Ginther (fginther) wrote :

Allan, thanks for catching the error. I've fixed it and also fixed some 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).

Marco Trevisan (Treviño) (3v1n0) wrote :

Looks fine, works ok.

review: Approve
Francis Ginther (fginther) wrote :

Cleaned up stale dbus process on test systems and re-trying.

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-01 13:56:43 +0000
3+++ Makefile.am 2012-12-13 21:57:19 +0000
4@@ -1,5 +1,7 @@
5 ACLOCAL_AMFLAGS = -I m4
6
7+include $(top_srcdir)/Makefile.am.coverage
8+
9 SUBDIRS = \
10 lib/libbamf \
11 src \
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:57: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=== modified file 'configure.ac'
67--- configure.ac 2012-11-15 17:45:29 +0000
68+++ configure.ac 2012-12-13 21:57:19 +0000
69@@ -129,6 +129,16 @@
70 AC_PATH_PROG([DBUS_LAUNCH],[dbus-launch])
71 fi
72
73+###########################
74+# gcov coverage reporting
75+###########################
76+AC_TDD_GCOV
77+AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes])
78+AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes])
79+AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes])
80+AC_SUBST(COVERAGE_CFLAGS)
81+AC_SUBST(COVERAGE_LDFLAGS)
82+
83 #
84 # Gnome/GTK checks
85 #
86@@ -169,5 +179,6 @@
87 Introspection: ${enable_introspection}
88 Unity Webapps: ${enable_webapps}
89 Headless tests: ${enable_headless_tests}
90+ Coverage Reporting: ${use_gcov}
91
92 EOF
93
94=== modified file 'lib/libbamf/Makefile.am'
95--- lib/libbamf/Makefile.am 2012-11-14 19:30:00 +0000
96+++ lib/libbamf/Makefile.am 2012-12-13 21:57:19 +0000
97@@ -67,11 +67,13 @@
98 $(LIBWSBIND_CFLAGS) \
99 $(GLIB_CFLAGS) \
100 $(DBUS_CFLAGS) \
101+ $(COVERAGE_CFLAGS) \
102 $(NULL)
103
104 libbamf3_la_LDFLAGS = \
105 -shared \
106 -export-symbols-regex "^bamf_" \
107+ $(COVERAGE_LDFLAGS) \
108 $(NULL)
109
110 glib_marshal_list = bamf-marshal.list
111
112=== added file 'm4/gcov.m4'
113--- m4/gcov.m4 1970-01-01 00:00:00 +0000
114+++ m4/gcov.m4 2012-12-13 21:57:19 +0000
115@@ -0,0 +1,89 @@
116+# Checks for existence of coverage tools:
117+# * gcov
118+# * lcov
119+# * genhtml
120+# * gcovr
121+#
122+# Sets ac_cv_check_gcov to yes if tooling is present
123+# and reports the executables to the variables LCOV, GCOVR and GENHTML.
124+AC_DEFUN([AC_TDD_GCOV],
125+[
126+ AC_ARG_ENABLE(gcov,
127+ AS_HELP_STRING([--enable-gcov],
128+ [enable coverage testing with gcov]),
129+ [use_gcov=$enableval], [use_gcov=no])
130+
131+ AM_CONDITIONAL(HAVE_GCOV, test "x$use_gcov" = "xyes")
132+
133+ if test "x$use_gcov" = "xyes"; then
134+ # we need gcc:
135+ if test "$GCC" != "yes"; then
136+ AC_MSG_ERROR([GCC is required for --enable-gcov])
137+ fi
138+
139+ # Check if ccache is being used
140+ AC_CHECK_PROG(SHTOOL, shtool, shtool)
141+ if test "$SHTOOL"; then
142+ AS_CASE([`$SHTOOL path $CC`],
143+ [*ccache*], [gcc_ccache=yes],
144+ [gcc_ccache=no])
145+ fi
146+
147+ if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
148+ AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
149+ fi
150+
151+ lcov_version_list="1.6 1.7 1.8 1.9"
152+ AC_CHECK_PROG(LCOV, lcov, lcov)
153+ AC_CHECK_PROG(GENHTML, genhtml, genhtml)
154+
155+ if test "$LCOV"; then
156+ AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [
157+ glib_cv_lcov_version=invalid
158+ lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
159+ for lcov_check_version in $lcov_version_list; do
160+ if test "$lcov_version" = "$lcov_check_version"; then
161+ glib_cv_lcov_version="$lcov_check_version (ok)"
162+ fi
163+ done
164+ ])
165+ else
166+ lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
167+ AC_MSG_ERROR([$lcov_msg])
168+ fi
169+
170+ case $glib_cv_lcov_version in
171+ ""|invalid[)]
172+ lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
173+ AC_MSG_ERROR([$lcov_msg])
174+ LCOV="exit 0;"
175+ ;;
176+ esac
177+
178+ if test -z "$GENHTML"; then
179+ AC_MSG_ERROR([Could not find genhtml from the lcov package])
180+ fi
181+
182+ ac_cv_check_gcov=yes
183+ ac_cv_check_lcov=yes
184+
185+ # Remove all optimization flags from CFLAGS
186+ changequote({,})
187+ CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
188+ changequote([,])
189+
190+ # Add the special gcc flags
191+ COVERAGE_CFLAGS="-O0 --coverage"
192+ COVERAGE_CXXFLAGS="-O0 --coverage"
193+ COVERAGE_LDFLAGS="-lgcov"
194+
195+ # Check availability of gcovr
196+ AC_CHECK_PROG(GCOVR, gcovr, gcovr)
197+ if test -z "$GCOVR"; then
198+ ac_cv_check_gcovr=no
199+ else
200+ ac_cv_check_gcovr=yes
201+ fi
202+fi
203+]) # AC_TDD_GCOV
204+
205
206=== modified file 'src/Makefile.am'
207--- src/Makefile.am 2012-11-07 19:51:56 +0000
208+++ src/Makefile.am 2012-12-13 21:57:19 +0000
209@@ -138,10 +138,12 @@
210 $(WNCK_CFLAGS) \
211 $(GTOP_CFLAGS) \
212 $(LIBUNITY_WEBAPPS_CFLAGS) \
213+ $(COVERAGE_CFLAGS) \
214 $(NULL)
215
216 bamfdaemon_LDFLAGS = \
217 -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions \
218+ $(COVERAGE_LDFLAGS) \
219 $(NULL)
220
221 bamf-gdbus-generated.c bamf-gdbus-generated.h: org.ayatana.bamf.xml

Subscribers

People subscribed via source and target branches