Merge lp:~allanlesage/libdbusmenu/TDD into lp:libdbusmenu/0.6

Proposed by Allan LeSage
Status: Merged
Approved by: Charles Kerr
Approved revision: 378
Merged at revision: 399
Proposed branch: lp:~allanlesage/libdbusmenu/TDD
Merge into: lp:libdbusmenu/0.6
Diff against target: 258 lines (+169/-2)
6 files modified
Makefile.am (+2/-0)
Makefile.am.coverage (+48/-0)
configure.ac (+16/-0)
libdbusmenu-glib/Makefile.am (+8/-1)
libdbusmenu-gtk/Makefile.am (+9/-1)
m4/gcov.m4 (+86/-0)
To merge this branch: bzr merge lp:~allanlesage/libdbusmenu/TDD
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
Review via email: mp+100425@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
=== modified file 'Makefile.am'
--- Makefile.am 2011-09-03 02:53:48 +0000
+++ Makefile.am 2012-04-02 14:31:24 +0000
@@ -53,3 +53,5 @@
53 else \53 else \
54 echo Failed to generate AUTHORS: not a branch >&2; \54 echo Failed to generate AUTHORS: not a branch >&2; \
55 fi55 fi
56
57include $(top_srcdir)/Makefile.am.coverage
5658
=== added file 'Makefile.am.coverage'
--- Makefile.am.coverage 1970-01-01 00:00:00 +0000
+++ Makefile.am.coverage 2012-04-02 14:31:24 +0000
@@ -0,0 +1,48 @@
1
2# Coverage targets
3
4.PHONY: clean-gcno clean-gcda \
5 coverage-html generate-coverage-html clean-coverage-html \
6 coverage-gcovr generate-coverage-gcovr clean-coverage-gcovr
7
8clean-local: clean-gcno clean-coverage-html clean-coverage-gcovr
9
10if HAVE_GCOV
11
12clean-gcno:
13 @echo Removing old coverage instrumentation
14 -find -name '*.gcno' -print | xargs -r rm
15
16clean-gcda:
17 @echo Removing old coverage results
18 -find -name '*.gcda' -print | xargs -r rm
19
20coverage-html: clean-gcda
21 -$(MAKE) $(AM_MAKEFLAGS) -k check
22 $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html
23
24generate-coverage-html:
25 @echo Collecting coverage data
26 $(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool
27 LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
28
29clean-coverage-html: clean-gcda
30 -$(LCOV) --directory $(top_builddir) -z
31 -rm -rf coverage.info coveragereport
32
33if HAVE_GCOVR
34
35coverage-gcovr: clean-gcda
36 -$(MAKE) $(AM_MAKEFLAGS) -k check
37 $(MAKE) $(AM_MAKEFLAGS) generate-coverage-gcovr
38
39generate-coverage-gcovr:
40 @echo Generating coverage GCOVR report
41 $(GCOVR) -x -r $(top_builddir) -o $(top_builddir)/coverage.xml
42
43clean-coverage-gcovr: clean-gcda
44 -rm -rf $(top_builddir)/coverage.xml
45
46endif # HAVE_GCOVR
47
48endif # HAVE_GCOV
049
=== modified file 'configure.ac'
--- configure.ac 2012-03-29 18:08:49 +0000
+++ configure.ac 2012-04-02 14:31:24 +0000
@@ -194,6 +194,18 @@
194fi194fi
195195
196###########################196###########################
197# gcov coverage reporting
198###########################
199
200m4_include([m4/gcov.m4])
201AC_TDD_GCOV
202AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes])
203AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes])
204AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes])
205AC_SUBST(COVERAGE_CFLAGS)
206AC_SUBST(COVERAGE_LDFLAGS)
207
208###########################
197# Files209# Files
198###########################210###########################
199211
@@ -251,3 +263,7 @@
251 AC_MSG_NOTICE([ Dumper: no])263 AC_MSG_NOTICE([ Dumper: no])
252)264)
253265
266AS_IF([test "x$use_gcov" = "xyes"],
267 AC_MSG_NOTICE([ Coverage reporting: yes]),
268 AC_MSG_NOTICE([ Coverage reporting: no])
269)
254270
=== modified file 'libdbusmenu-glib/Makefile.am'
--- libdbusmenu-glib/Makefile.am 2012-03-29 17:45:44 +0000
+++ libdbusmenu-glib/Makefile.am 2012-04-02 14:31:24 +0000
@@ -58,12 +58,14 @@
58 client.c58 client.c
5959
60libdbusmenu_glib_la_LDFLAGS = \60libdbusmenu_glib_la_LDFLAGS = \
61 $(COVERAGE_LDFLAGS) \
61 -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \62 -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \
62 -no-undefined \63 -no-undefined \
63 -export-symbols-regex "^[^_].*"64 -export-symbols-regex "^[^_].*"
6465
65libdbusmenu_glib_la_CFLAGS = \66libdbusmenu_glib_la_CFLAGS = \
66 $(DBUSMENUGLIB_CFLAGS) \67 $(DBUSMENUGLIB_CFLAGS) \
68 $(COVERAGE_CFLAGS) \
67 -Wall -Werror -Wno-error=deprecated-declarations \69 -Wall -Werror -Wno-error=deprecated-declarations \
68 -DG_LOG_DOMAIN="\"LIBDBUSMENU-GLIB\""70 -DG_LOG_DOMAIN="\"LIBDBUSMENU-GLIB\""
6971
@@ -181,7 +183,12 @@
181Dbusmenu-0.4.gir: libdbusmenu-glib.la183Dbusmenu-0.4.gir: libdbusmenu-glib.la
182Dbusmenu_0_4_gir_INCLUDES = \184Dbusmenu_0_4_gir_INCLUDES = \
183 GObject-2.0185 GObject-2.0
184Dbusmenu_0_4_gir_CFLAGS = $(DBUSMENUGLIB_CFLAGS) -I$(top_srcdir)186Dbusmenu_0_4_gir_CFLAGS = \
187 $(DBUSMENUGLIB_CFLAGS) \
188 $(COVERAGE_CFLAGS) \
189 -I$(top_srcdir)
190Dbusmenu_0_4_gir_LDFLAGS = \
191 $(COVERAGE_LDFLAGS)
185Dbusmenu_0_4_gir_LIBS = libdbusmenu-glib.la192Dbusmenu_0_4_gir_LIBS = libdbusmenu-glib.la
186Dbusmenu_0_4_gir_FILES = $(introspection_sources)193Dbusmenu_0_4_gir_FILES = $(introspection_sources)
187Dbusmenu_0_4_gir_NAMESPACE = Dbusmenu194Dbusmenu_0_4_gir_NAMESPACE = Dbusmenu
188195
=== modified file 'libdbusmenu-gtk/Makefile.am'
--- libdbusmenu-gtk/Makefile.am 2012-01-27 08:12:20 +0000
+++ libdbusmenu-gtk/Makefile.am 2012-04-02 14:31:24 +0000
@@ -57,12 +57,14 @@
57 parser.c57 parser.c
5858
59libdbusmenu_gtk_la_LDFLAGS = \59libdbusmenu_gtk_la_LDFLAGS = \
60 $(COVERAGE_LDFLAGS) \
60 -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \61 -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \
61 -no-undefined \62 -no-undefined \
62 -export-symbols-regex "^[^_].*"63 -export-symbols-regex "^[^_].*"
6364
64libdbusmenu_gtk_la_CFLAGS = \65libdbusmenu_gtk_la_CFLAGS = \
65 $(DBUSMENUGTK_CFLAGS) \66 $(DBUSMENUGTK_CFLAGS) \
67 $(COVERAGE_CFLAGS) \
66 -I$(top_srcdir) \68 -I$(top_srcdir) \
67 -Wall -Werror -Wno-error=deprecated-declarations \69 -Wall -Werror -Wno-error=deprecated-declarations \
68 -DG_LOG_DOMAIN="\"LIBDBUSMENU-GTK\""70 -DG_LOG_DOMAIN="\"LIBDBUSMENU-GTK\""
@@ -117,7 +119,12 @@
117 GObject-2.0 \119 GObject-2.0 \
118 $(GTKGIR) \120 $(GTKGIR) \
119 Dbusmenu-0.4 121 Dbusmenu-0.4
120DbusmenuGtk_0_4_gir_CFLAGS = $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir)122DbusmenuGtk_0_4_gir_CFLAGS = \
123 $(DBUSMENUGTK_CFLAGS) \
124 $(COVERAGE_CFLAGS) \
125 -I$(top_srcdir)
126DbusmenuGtk_0_4_gir_LDFLAGS = \
127 $(COVERAGE_LDFLAGS)
121DbusmenuGtk_0_4_gir_LIBS = libdbusmenu-gtk$(VER).la \128DbusmenuGtk_0_4_gir_LIBS = libdbusmenu-gtk$(VER).la \
122 $(top_builddir)/libdbusmenu-glib/libdbusmenu-glib.la129 $(top_builddir)/libdbusmenu-glib/libdbusmenu-glib.la
123DbusmenuGtk_0_4_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources))130DbusmenuGtk_0_4_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources))
@@ -127,6 +134,7 @@
127# We duplicate these for the same reason as libdbusmenu_gtk3includedir above134# We duplicate these for the same reason as libdbusmenu_gtk3includedir above
128DbusmenuGtk3_0_4_gir_INCLUDES = $(DbusmenuGtk_0_4_gir_INCLUDES)135DbusmenuGtk3_0_4_gir_INCLUDES = $(DbusmenuGtk_0_4_gir_INCLUDES)
129DbusmenuGtk3_0_4_gir_CFLAGS = $(DbusmenuGtk_0_4_gir_CFLAGS)136DbusmenuGtk3_0_4_gir_CFLAGS = $(DbusmenuGtk_0_4_gir_CFLAGS)
137DbusmenuGtk3_0_4_gir_LDFLAGS = $(DbusmenuGtk_0_4_gir_LDFLAGS)
130DbusmenuGtk3_0_4_gir_LIBS = $(DbusmenuGtk_0_4_gir_LIBS)138DbusmenuGtk3_0_4_gir_LIBS = $(DbusmenuGtk_0_4_gir_LIBS)
131DbusmenuGtk3_0_4_gir_FILES = $(DbusmenuGtk_0_4_gir_FILES)139DbusmenuGtk3_0_4_gir_FILES = $(DbusmenuGtk_0_4_gir_FILES)
132DbusmenuGtk3_0_4_gir_NAMESPACE = $(DbusmenuGtk_0_4_gir_NAMESPACE)140DbusmenuGtk3_0_4_gir_NAMESPACE = $(DbusmenuGtk_0_4_gir_NAMESPACE)
133141
=== added file 'm4/gcov.m4'
--- m4/gcov.m4 1970-01-01 00:00:00 +0000
+++ m4/gcov.m4 2012-04-02 14:31:24 +0000
@@ -0,0 +1,86 @@
1# Checks for existence of coverage tools:
2# * gcov
3# * lcov
4# * genhtml
5# * gcovr
6#
7# Sets ac_cv_check_gcov to yes if tooling is present
8# and reports the executables to the variables LCOV, GCOVR and GENHTML.
9AC_DEFUN([AC_TDD_GCOV],
10[
11 AC_ARG_ENABLE(gcov,
12 AS_HELP_STRING([--enable-gcov],
13 [enable coverage testing with gcov]),
14 [use_gcov=$enableval], [use_gcov=no])
15
16 if test "x$use_gcov" = "xyes"; then
17 # we need gcc:
18 if test "$GCC" != "yes"; then
19 AC_MSG_ERROR([GCC is required for --enable-gcov])
20 fi
21
22 # Check if ccache is being used
23 AC_CHECK_PROG(SHTOOL, shtool, shtool)
24 case `$SHTOOL path $CC` in
25 *ccache*[)] gcc_ccache=yes;;
26 *[)] gcc_ccache=no;;
27 esac
28
29 if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
30 AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
31 fi
32
33 lcov_version_list="1.6 1.7 1.8 1.9"
34 AC_CHECK_PROG(LCOV, lcov, lcov)
35 AC_CHECK_PROG(GENHTML, genhtml, genhtml)
36
37 if test "$LCOV"; then
38 AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [
39 glib_cv_lcov_version=invalid
40 lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
41 for lcov_check_version in $lcov_version_list; do
42 if test "$lcov_version" = "$lcov_check_version"; then
43 glib_cv_lcov_version="$lcov_check_version (ok)"
44 fi
45 done
46 ])
47 else
48 lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
49 AC_MSG_ERROR([$lcov_msg])
50 fi
51
52 case $glib_cv_lcov_version in
53 ""|invalid[)]
54 lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
55 AC_MSG_ERROR([$lcov_msg])
56 LCOV="exit 0;"
57 ;;
58 esac
59
60 if test -z "$GENHTML"; then
61 AC_MSG_ERROR([Could not find genhtml from the lcov package])
62 fi
63
64 ac_cv_check_gcov=yes
65 ac_cv_check_lcov=yes
66
67 # Remove all optimization flags from CFLAGS
68 changequote({,})
69 CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
70 changequote([,])
71
72 # Add the special gcc flags
73 COVERAGE_CFLAGS="-O0 -fprofile-arcs -ftest-coverage"
74 COVERAGE_CXXFLAGS="-O0 -fprofile-arcs -ftest-coverage"
75 COVERAGE_LDFLAGS="-lgcov"
76
77 # Check availability of gcovr
78 AC_CHECK_PROG(GCOVR, gcovr, gcovr)
79 if test -z "$GCOVR"; then
80 ac_cv_check_gcovr=no
81 else
82 ac_cv_check_gcovr=yes
83 fi
84
85fi
86]) # AC_TDD_GCOV

Subscribers

People subscribed via source and target branches

to all changes: