Nux

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

Proposed by Francis Ginther
Status: Merged
Approved by: Brandon Schaefer
Approved revision: 732
Merged at revision: 732
Proposed branch: lp:~fginther/nux/add-code-coverage
Merge into: lp:nux
Diff against target: 259 lines (+163/-6)
7 files modified
Makefile.am (+1/-0)
Makefile.am.coverage (+49/-0)
Nux/Makefile.am (+4/-2)
NuxCore/Makefile.am (+4/-2)
NuxGraphics/Makefile.am (+4/-2)
configure.ac (+12/-0)
m4/gcov.m4 (+89/-0)
To merge this branch: bzr merge lp:~fginther/nux/add-code-coverage
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Brandon Schaefer (community) Approve
Allan LeSage (community) Approve
Review via email: mp+138007@code.launchpad.net

Commit message

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

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

Description of the change

Add code coverage reporting with coverage-html and coverage-xml 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
Allan LeSage (allanlesage) wrote :

* Teensy correction restores coverage for the NuxGraphics dir:

=== modified file 'NuxGraphics/Makefile.am'
--- NuxGraphics/Makefile.am 2012-12-04 19:36:00 +0000
+++ NuxGraphics/Makefile.am 2012-12-05 15:32:28 +0000
@@ -18,7 +18,7 @@
   $(NUX_GRAPHICS_CFLAGS) \
   $(MAINTAINER_CFLAGS) \
   $(GEIS_CFLAGS) \
- $(COVERAGE_FLAGS)
+ $(COVERAGE_CFLAGS)

 libnux_graphics_@NUX_API_VERSION@_la_LIBADD = \
   $(top_builddir)/NuxCore/libnux-core-@NUX_API_VERSION@.la \

* I'll attach a diff of what was necessary to get tests running FYI.

* We could consider splitting these tests into "small" and "large" but can take that up in another MP :) .

* The choice to make "make coverage-html" et.al. not depend on "make check" is evidently a considered one to which I don't object.

Approval contingent on the small correction above.

review: Approve
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

It looks good to me, but possibly making it easier to know you need to do a make check or make check-headless before running make coverage-html would be nice. Or possibly to check if no *.gcda files are found through an error message saying to run those commands.

Otherwise looks good to me :)

Revision history for this message
Francis Ginther (fginther) wrote :

> It looks good to me, but possibly making it easier to know you need to do a
> make check or make check-headless before running make coverage-html would be
> nice. Or possibly to check if no *.gcda files are found through an error
> message saying to run those commands.
>
> Otherwise looks good to me :)

Brandon, I added make check to the two main coverage targets to make it more intuitive for developers. This still allows our jenkins automation to run make check-headless via hook scripts instead of make check and collect the results with gcovr.

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Awesome, im happy with that :)

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Martin Mrazik (mrazik) wrote :

Sorry, Jenkins failure which should be fixed now -> reapproving.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Martin Mrazik (mrazik) wrote :

It looks like Brandon did something weird in his branch and hence the conflict. I see some coverage related commits in bzr log --include-merged lp:nux ....

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

What the heck...all I did was a bzr merge...check it out, then a bzr revert...then did my own thing and pushed the other branch. I don't see how this should carry any info with it...

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-05-25 20:36:09 +0000
3+++ Makefile.am 2012-12-06 01:28:22 +0000
4@@ -2,6 +2,7 @@
5
6 CXXFLAGS += -fno-permissive
7
8+include $(top_srcdir)/Makefile.am.coverage
9 include doxygen-include.am
10
11 if BUILD_DOCUMENTATION
12
13=== added file 'Makefile.am.coverage'
14--- Makefile.am.coverage 1970-01-01 00:00:00 +0000
15+++ Makefile.am.coverage 2012-12-06 01:28:22 +0000
16@@ -0,0 +1,49 @@
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+ $(LCOV) --extract coverage.info "$(abs_top_srcdir)/*" -o coverage.info
44+ LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
45+
46+clean-coverage-html: clean-gcda
47+ -$(LCOV) --directory $(top_builddir) -z
48+ -rm -rf coverage.info coveragereport
49+
50+if HAVE_GCOVR
51+
52+coverage-gcovr:
53+ -$(MAKE) $(AM_MAKEFLAGS) -k check
54+ $(MAKE) $(AM_MAKEFLAGS) generate-coverage-gcovr
55+
56+generate-coverage-gcovr:
57+ @echo Generating coverage GCOVR report
58+ $(GCOVR) --xml -r $(top_builddir) -o $(top_builddir)/coverage.xml
59+
60+clean-coverage-gcovr: clean-gcda
61+ -rm -rf $(top_builddir)/coverage.xml
62+
63+endif # HAVE_GCOVR
64+
65+endif # HAVE_GCOV
66
67=== modified file 'Nux/Makefile.am'
68--- Nux/Makefile.am 2012-11-20 22:13:38 +0000
69+++ Nux/Makefile.am 2012-12-06 01:28:22 +0000
70@@ -17,7 +17,8 @@
71 $(NUX_CFLAGS) \
72 $(IBUS_CFLAGS) \
73 $(GEIS_CFLAGS) \
74- $(MAINTAINER_CFLAGS)
75+ $(MAINTAINER_CFLAGS) \
76+ $(COVERAGE_CFLAGS)
77
78 libnux_@NUX_API_VERSION@_la_LIBADD = \
79 $(top_builddir)/NuxCore/libnux-core-@NUX_API_VERSION@.la \
80@@ -27,7 +28,8 @@
81 $(GEIS_LIBS)
82
83 libnux_@NUX_API_VERSION@_la_LDFLAGS = \
84- $(NUX_LT_LDFLAGS)
85+ $(NUX_LT_LDFLAGS) \
86+ $(COVERAGE_LDFLAGS)
87
88 source_cpp = \
89 $(srcdir)/AbstractButton.cpp \
90
91=== modified file 'NuxCore/Makefile.am'
92--- NuxCore/Makefile.am 2012-09-12 00:52:05 +0000
93+++ NuxCore/Makefile.am 2012-12-06 01:28:22 +0000
94@@ -16,13 +16,15 @@
95 libnux_core_@NUX_API_VERSION@_la_CPPFLAGS= \
96 $(GCC_FLAGS) \
97 $(NUX_CORE_CFLAGS) \
98- $(MAINTAINER_CFLAGS)
99+ $(MAINTAINER_CFLAGS) \
100+ $(COVERAGE_CFLAGS)
101
102 libnux_core_@NUX_API_VERSION@_la_LIBADD = \
103 $(NUX_CORE_LIBS) -lpthread
104
105 libnux_core_@NUX_API_VERSION@_la_LDFLAGS = \
106- $(NUX_LT_LDFLAGS)
107+ $(NUX_LT_LDFLAGS) \
108+ $(COVERAGE_LDFLAGS)
109
110 source_cpp = \
111 $(srcdir)/Animation.cpp \
112
113=== modified file 'NuxGraphics/Makefile.am'
114--- NuxGraphics/Makefile.am 2012-11-05 17:47:31 +0000
115+++ NuxGraphics/Makefile.am 2012-12-06 01:28:22 +0000
116@@ -17,7 +17,8 @@
117 $(GCC_FLAGS) \
118 $(NUX_GRAPHICS_CFLAGS) \
119 $(MAINTAINER_CFLAGS) \
120- $(GEIS_CFLAGS)
121+ $(GEIS_CFLAGS) \
122+ $(COVERAGE_CFLAGS)
123
124 libnux_graphics_@NUX_API_VERSION@_la_LIBADD = \
125 $(top_builddir)/NuxCore/libnux-core-@NUX_API_VERSION@.la \
126@@ -25,7 +26,8 @@
127 $(GEIS_LIBS)
128
129 libnux_graphics_@NUX_API_VERSION@_la_LDFLAGS = \
130- $(NUX_LT_LDFLAGS)
131+ $(NUX_LT_LDFLAGS) \
132+ $(COVERAGE_LDFLAGS)
133
134 source_h = \
135 $(srcdir)/BitmapFormats.h \
136
137=== modified file 'configure.ac'
138--- configure.ac 2012-11-27 15:12:37 +0000
139+++ configure.ac 2012-12-06 01:28:22 +0000
140@@ -342,6 +342,17 @@
141
142 AM_CONDITIONAL(BUILD_TESTS, [test "x$enable_tests" = "xyes"])
143
144+###########################
145+# gcov coverage reporting
146+###########################
147+m4_include([m4/gcov.m4])
148+AC_TDD_GCOV
149+AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes])
150+AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes])
151+AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes])
152+AC_SUBST(COVERAGE_CFLAGS)
153+AC_SUBST(COVERAGE_LDFLAGS)
154+
155 dnl ===========================================================================
156
157 # sets up doxygen
158@@ -485,6 +496,7 @@
159 echo -e " Build Examples : ${BOLD_WHITE}${enable_examples}${RESET}"
160 echo -e " Build Gpu Tests : ${BOLD_WHITE}${enable_gputests}${RESET}"
161 echo -e " Build Nux Tests : ${BOLD_WHITE}${enable_tests}${RESET}"
162+echo -e " Coverage Reporting : ${BOLD_WHITE}${use_gcov}${RESET}"
163 echo -e " Gestures support : ${BOLD_WHITE}${have_geis}${RESET}"
164 echo -e " X11 build support : ${BOLD_WHITE}${enable_x_support}${RESET}"
165 echo -e " Minimal build : ${BOLD_WHITE}${enable_minimal_build}${RESET}"
166
167=== added file 'm4/gcov.m4'
168--- m4/gcov.m4 1970-01-01 00:00:00 +0000
169+++ m4/gcov.m4 2012-12-06 01:28:22 +0000
170@@ -0,0 +1,89 @@
171+# Checks for existence of coverage tools:
172+# * gcov
173+# * lcov
174+# * genhtml
175+# * gcovr
176+#
177+# Sets ac_cv_check_gcov to yes if tooling is present
178+# and reports the executables to the variables LCOV, GCOVR and GENHTML.
179+AC_DEFUN([AC_TDD_GCOV],
180+[
181+ AC_ARG_ENABLE(gcov,
182+ AS_HELP_STRING([--enable-gcov],
183+ [enable coverage testing with gcov]),
184+ [use_gcov=$enableval], [use_gcov=no])
185+
186+ AM_CONDITIONAL(HAVE_GCOV, test "x$use_gcov" = "xyes")
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+ if test "$SHTOOL"; then
197+ AS_CASE([`$SHTOOL path $CC`],
198+ [*ccache*], [gcc_ccache=yes],
199+ [gcc_ccache=no])
200+ fi
201+
202+ if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
203+ AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
204+ fi
205+
206+ lcov_version_list="1.6 1.7 1.8 1.9"
207+ AC_CHECK_PROG(LCOV, lcov, lcov)
208+ AC_CHECK_PROG(GENHTML, genhtml, genhtml)
209+
210+ if test "$LCOV"; then
211+ AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [
212+ glib_cv_lcov_version=invalid
213+ lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
214+ for lcov_check_version in $lcov_version_list; do
215+ if test "$lcov_version" = "$lcov_check_version"; then
216+ glib_cv_lcov_version="$lcov_check_version (ok)"
217+ fi
218+ done
219+ ])
220+ else
221+ lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
222+ AC_MSG_ERROR([$lcov_msg])
223+ fi
224+
225+ case $glib_cv_lcov_version in
226+ ""|invalid[)]
227+ lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
228+ AC_MSG_ERROR([$lcov_msg])
229+ LCOV="exit 0;"
230+ ;;
231+ esac
232+
233+ if test -z "$GENHTML"; then
234+ AC_MSG_ERROR([Could not find genhtml from the lcov package])
235+ fi
236+
237+ ac_cv_check_gcov=yes
238+ ac_cv_check_lcov=yes
239+
240+ # Remove all optimization flags from CFLAGS
241+ changequote({,})
242+ CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
243+ changequote([,])
244+
245+ # Add the special gcc flags
246+ COVERAGE_CFLAGS="-O0 --coverage"
247+ COVERAGE_CXXFLAGS="-O0 --coverage"
248+ COVERAGE_LDFLAGS="-lgcov"
249+
250+ # Check availability of gcovr
251+ AC_CHECK_PROG(GCOVR, gcovr, gcovr)
252+ if test -z "$GCOVR"; then
253+ ac_cv_check_gcovr=no
254+ else
255+ ac_cv_check_gcovr=yes
256+ fi
257+fi
258+]) # AC_TDD_GCOV
259+

Subscribers

People subscribed via source and target branches