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

Proposed by Allan LeSage
Status: Merged
Approved by: Charles Kerr
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) Approve
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.
Revision history for this message
Charles Kerr (charlesk) :
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-08-03 15:24:01 +0000
+++ Makefile.am 2012-04-02 14:30:26 +0000
@@ -23,3 +23,5 @@
23EXTRA_DIST = libido.pc.in libido3.pc.in23EXTRA_DIST = libido.pc.in libido3.pc.in
2424
25DISTCHECK_CONFIGURE_FLAGS = --disable-gtk-doc25DISTCHECK_CONFIGURE_FLAGS = --disable-gtk-doc
26
27include $(top_srcdir)/Makefile.am.coverage
2628
=== added file 'Makefile.am.coverage'
--- Makefile.am.coverage 1970-01-01 00:00:00 +0000
+++ Makefile.am.coverage 2012-04-02 14:30:26 +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-21 19:33:21 +0000
+++ configure.ac 2012-04-02 14:30:26 +0000
@@ -117,6 +117,16 @@
117117
118AC_SUBST(MAINTAINER_CFLAGS)118AC_SUBST(MAINTAINER_CFLAGS)
119119
120dnl = gcov Coverage Reporting =================================================
121
122m4_include([m4/gcov.m4])
123AC_TDD_GCOV
124AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes])
125AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes])
126AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes])
127AC_SUBST(COVERAGE_CFLAGS)
128AC_SUBST(COVERAGE_CXXFLAGS)
129AC_SUBST(COVERAGE_LDFLAGS)
120130
121dnl = GTK Doc Check ===========================================================131dnl = GTK Doc Check ===========================================================
122132
@@ -140,6 +150,7 @@
140echo ""150echo ""
141echo " Prefix : ${prefix}"151echo " Prefix : ${prefix}"
142echo " GTK : ${with_gtk}"152echo " GTK : ${with_gtk}"
153echo " gcov : ${use_gcov}"
143echo ""154echo ""
144echo " Documentation: ${enable_gtk_doc}"155echo " Documentation: ${enable_gtk_doc}"
145echo ""156echo ""
146157
=== added directory 'm4'
=== added file 'm4/gcov.m4'
--- m4/gcov.m4 1970-01-01 00:00:00 +0000
+++ m4/gcov.m4 2012-04-02 14:30:26 +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
087
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2012-03-10 01:10:25 +0000
+++ src/Makefile.am 2012-04-02 14:30:26 +0000
@@ -57,6 +57,9 @@
57 $(MAINTAINER_CFLAGS) \57 $(MAINTAINER_CFLAGS) \
58 -Wall -Werror -Wextra -Wno-unused-parameter58 -Wall -Werror -Wextra -Wno-unused-parameter
5959
60AM_CFLAGS = \
61 $(COVERAGE_CFLAGS)
62
60libido_0_1_la_SOURCES = \63libido_0_1_la_SOURCES = \
61 idotypebuiltins.c \64 idotypebuiltins.c \
62 idocalendarmenuitem.c \65 idocalendarmenuitem.c \
@@ -80,9 +83,13 @@
80 libido.h83 libido.h
8184
82libido_0_1_la_LIBADD = $(GTK_LIBS)85libido_0_1_la_LIBADD = $(GTK_LIBS)
83libido_0_1_la_LDFLAGS = $(GTK_LT_LDFLAGS)86libido_0_1_la_LDFLAGS = \
87 $(GTK_LT_LDFLAGS) \
88 $(COVERAGE_LDFLAGS)
84libido3_0_1_la_LIBADD = $(libido_0_1_la_LIBADD)89libido3_0_1_la_LIBADD = $(libido_0_1_la_LIBADD)
85libido3_0_1_la_LDFLAGS = $(libido_0_1_la_LDFLAGS)90libido3_0_1_la_LDFLAGS = \
91 $(libido_0_1_la_LDFLAGS) \
92 $(COVERAGE_LDFLAGS)
8693
87DISTCLEANFILES = \94DISTCLEANFILES = \
88 stamp-idotypebuiltins.h \95 stamp-idotypebuiltins.h \

Subscribers

People subscribed via source and target branches