Merge lp:~allanlesage/appmenu-gtk/TDD into lp:appmenu-gtk/0.4

Proposed by Allan LeSage
Status: Merged
Approved by: Charles Kerr
Approved revision: 148
Merged at revision: 151
Proposed branch: lp:~allanlesage/appmenu-gtk/TDD
Merge into: lp:appmenu-gtk/0.4
Diff against target: 215 lines (+155/-2)
5 files modified
Makefile.am (+3/-1)
Makefile.am.coverage (+48/-0)
configure.ac (+14/-1)
m4/gcov.m4 (+86/-0)
src/Makefile.am (+4/-0)
To merge this branch: bzr merge lp:~allanlesage/appmenu-gtk/TDD
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
Review via email: mp+100426@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 2012-02-08 16:00:23 +0000
+++ Makefile.am 2012-04-02 14:32:28 +0000
@@ -1,4 +1,4 @@
1ACLOCAL_AMFLAGS = -I build/autotools1ACLOCAL_AMFLAGS = -I m4
22
3SUBDIRS = \3SUBDIRS = \
4 src4 src
@@ -17,3 +17,5 @@
17 80appmenu.in17 80appmenu.in
1818
19DISTCLEANFILES = $(sessionfile)19DISTCLEANFILES = $(sessionfile)
20
21include $(top_srcdir)/Makefile.am.coverage
2022
=== added file 'Makefile.am.coverage'
--- Makefile.am.coverage 1970-01-01 00:00:00 +0000
+++ Makefile.am.coverage 2012-04-02 14:32:28 +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-08 23:15:31 +0000
+++ configure.ac 2012-04-02 14:32:28 +0000
@@ -3,7 +3,7 @@
3AC_INIT([appmenu-gtk], [0.3.91], [crussell@canonical.com])3AC_INIT([appmenu-gtk], [0.3.91], [crussell@canonical.com])
4AC_COPYRIGHT([Copyright 2010 Canonical])4AC_COPYRIGHT([Copyright 2010 Canonical])
5AC_CONFIG_SRCDIR([src/bridge.c])5AC_CONFIG_SRCDIR([src/bridge.c])
6AC_CONFIG_MACRO_DIR([build/autotools])6AC_CONFIG_MACRO_DIR([m4])
77
8AM_CONFIG_HEADER(config.h)8AM_CONFIG_HEADER(config.h)
9AM_INIT_AUTOMAKE([1.9])9AM_INIT_AUTOMAKE([1.9])
@@ -59,6 +59,18 @@
59AC_SUBST(moduledir)59AC_SUBST(moduledir)
60AC_SUBST(sessionfile)60AC_SUBST(sessionfile)
6161
62###########################
63# gcov coverage reporting
64###########################
65
66m4_include([m4/gcov.m4])
67AC_TDD_GCOV
68AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes])
69AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes])
70AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes])
71AC_SUBST(COVERAGE_CFLAGS)
72AC_SUBST(COVERAGE_LDFLAGS)
73
62AC_CONFIG_FILES([74AC_CONFIG_FILES([
63Makefile75Makefile
64src/Makefile76src/Makefile
@@ -76,5 +88,6 @@
7688
77 Prefix: $prefix89 Prefix: $prefix
78 GTK+ API: $gtk_api90 GTK+ API: $gtk_api
91 Coverage reporting: $use_gcov
79])92])
8093
8194
=== 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:32:28 +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 2011-05-08 20:07:37 +0000
+++ src/Makefile.am 2012-04-02 14:32:28 +0000
@@ -15,7 +15,11 @@
15 -Wall -Werror \15 -Wall -Werror \
16 $(APPMENU_CFLAGS)16 $(APPMENU_CFLAGS)
1717
18libappmenu_la_CFLAGS = \
19 $(COVERAGE_CFLAGS)
20
18libappmenu_la_LDFLAGS = \21libappmenu_la_LDFLAGS = \
22 $(COVERAGE_LDFLAGS) \
19 -module -avoid-version23 -module -avoid-version
2024
21libappmenu_la_LIBADD = \25libappmenu_la_LIBADD = \

Subscribers

People subscribed via source and target branches