From d030955787ea2be9247e5a5bc4e7adf84316a0da Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Fri, 12 Aug 2016 10:50:53 +0200 Subject: Use AX_CODE_COVERAGE for test-coverage statistics DBus uses custom rules in its Makefiles to implement test-coverage statistics. This patch implements test-coverage statistics with the autoconf macro AX_CODE_COVERAGE. The script automatically tests for tools (e.g., gcov, lcov), sets build variables and creates Makefile rules. Run 'configure' with '--enable-code-coverage' to enable support for test-coverage statistics. Run 'make check-code-coverage' to run the tests and generate the statistics. Signed-off-by: Thomas Zimmermann --- Makefile.am | 3 ++- bus/Makefile.am | 18 ++++++++++++++---- configure.ac | 21 ++++++++++++--------- dbus/Makefile.am | 10 ++++++---- m4/compiler.m4 | 14 -------------- test/Makefile.am | 13 +++++++++++-- tools/lcov.am | 43 ------------------------------------------- 7 files changed, 45 insertions(+), 77 deletions(-) delete mode 100644 tools/lcov.am diff --git a/Makefile.am b/Makefile.am index 756ab8b..db0d522 100644 --- a/Makefile.am +++ b/Makefile.am @@ -33,4 +33,5 @@ DISTCHECK_CONFIGURE_FLAGS = \ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} -include tools/lcov.am +# Add rules for code-coverage testing, as defined by AX_CODE_COVERAGE +@CODE_COVERAGE_RULES@ diff --git a/bus/Makefile.am b/bus/Makefile.am index 90092b1..0027e07 100644 --- a/bus/Makefile.am +++ b/bus/Makefile.am @@ -3,6 +3,7 @@ legacydbusdatadir=$(sysconfdir)/dbus-1 dbus_daemon_execdir = $(DBUS_DAEMONDIR) DBUS_BUS_LIBS = \ + $(CODE_COVERAGE_LDFLAGS) \ $(XML_LIBS) \ $(SELINUX_LIBS) \ $(APPARMOR_LIBS) \ @@ -12,12 +13,14 @@ DBUS_BUS_LIBS = \ $(NULL) DBUS_LAUNCHER_LIBS = \ + $(CODE_COVERAGE_LDFLAGS) \ $(XML_LIBS) \ $(THREAD_LIBS) \ $(NETWORK_libs) \ $(NULL) AM_CPPFLAGS = \ + $(CODE_COVERAGE_CPPFLAGS) \ -I$(top_srcdir) \ $(DBUS_STATIC_BUILD_CPPFLAGS) \ $(XML_CFLAGS) \ @@ -29,6 +32,14 @@ AM_CPPFLAGS = \ # if assertions are enabled, improve backtraces AM_LDFLAGS = @R_DYNAMIC_LDFLAG@ +AM_CFLAGS = \ + $(CODE_COVERAGE_CFLAGS) \ + $(NULL) + +AM_CXXFLAGS = \ + $(CODE_COVERAGE_CXXFLAGS) \ + $(NULL) + EFENCE= CONFIG_IN_FILES= \ @@ -233,10 +244,6 @@ test_bus_LDADD = \ $(DBUS_BUS_LIBS) \ $(NULL) -## mop up the gcov files -clean-local: - /bin/rm *.bb *.bbg *.da *.gcov || true - install-data-hook: $(mkinstalldirs) $(DESTDIR)$(dbusdatadir)/session.d $(mkinstalldirs) $(DESTDIR)$(dbusdatadir)/services @@ -327,6 +334,9 @@ systemduserunit_DATA = \ $(NULL) endif +# Add rules for code-coverage testing, as defined by AX_CODE_COVERAGE +@CODE_COVERAGE_RULES@ + #### Extra dist EXTRA_DIST=$(CONFIG_IN_FILES) $(SCRIPT_IN_FILES) diff --git a/configure.ac b/configure.ac index 2aac82e..cf08a05 100644 --- a/configure.ac +++ b/configure.ac @@ -71,7 +71,6 @@ AC_HEADER_STDC AC_C_INLINE AM_PROG_LIBTOOL AC_PROG_MKDIR_P -COMPILER_COVERAGE COMPILER_OPTIMISATIONS PKG_PROG_PKG_CONFIG @@ -333,10 +332,14 @@ AH_BOTTOM([ # define DBUS_ENABLE_CHECKS 1 #endif]) -if test x$enable_compiler_coverage = xyes; then - ## so that config.h changes when you toggle gcov support - AC_DEFINE_UNQUOTED(DBUS_GCOV_ENABLED, 1, [Defined if gcov is enabled to force a rebuild due to config.h changing]) -fi +# Test for code-coverage tools if --enable-code-coverage +AX_CODE_COVERAGE + +AS_IF([test x$enable_code_coverage = xyes],[ + AC_DEFINE_UNQUOTED( + [DBUS_GCOV_ENABLED], [1], + [Defined if gcov is enabled to force a rebuild due to config.h changing]) + ]) #### Integer sizes @@ -1893,7 +1896,7 @@ echo " echo " Rebuilding generated files: ${USE_MAINTAINER_MODE} - gcc coverage profiling: ${enable_compiler_coverage} + gcc coverage profiling: ${enable_code_coverage} Building embedded tests: ${enable_embedded_tests} Building modular tests: ${enable_modular_tests} - with GLib: ${with_glib} @@ -1937,9 +1940,9 @@ fi if test x$enable_embedded_tests = xyes -a x$enable_asserts = xno; then echo "NOTE: building with embedded tests but without assertions means tests may not properly report failures (this configuration is only useful when doing something like profiling the tests)" fi -if test x$enable_compiler_coverage = xyes; then - echo "NOTE: building with coverage profiling is definitely for developers only." -fi +AS_IF([test x$enable_code_coverage = xyes],[ + AC_MSG_WARN([Building with coverage profiling is definitely for developers only.]) + ]) if test x$enable_verbose_mode = xyes; then echo "NOTE: building with verbose mode increases library size, may slightly increase security risk, and decreases performance." fi diff --git a/dbus/Makefile.am b/dbus/Makefile.am index 0152486..a37aa56 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -2,6 +2,7 @@ dbusdatadir=$(datadir)/dbus-1 AM_CPPFLAGS = \ + $(CODE_COVERAGE_CPPFLAGS) \ -I$(top_builddir) \ -I$(top_srcdir) \ $(DBUS_STATIC_BUILD_CPPFLAGS) \ @@ -13,7 +14,9 @@ AM_CPPFLAGS = \ -DDBUS_SESSION_CONFIG_FILE=\""$(dbusdatadir)/session.conf"\" \ $(NULL) -AM_CFLAGS = +AM_CFLAGS = \ + $(CODE_COVERAGE_CFLAGS) \ + $(NULL) if HAVE_VISIBILITY if !DBUS_WIN @@ -327,6 +330,5 @@ test_dbus_SOURCES= \ test_dbus_LDADD = libdbus-internal.la -## mop up the gcov files -clean-local: - /bin/rm *.bb *.bbg *.da *.gcov .libs/*.da .libs/*.bbg || true +# Add rules for code-coverage testing, as defined by AX_CODE_COVERAGE +@CODE_COVERAGE_RULES@ diff --git a/m4/compiler.m4 b/m4/compiler.m4 index 5a197ad..b01d835 100644 --- a/m4/compiler.m4 +++ b/m4/compiler.m4 @@ -51,17 +51,3 @@ AC_DEFUN([COMPILER_OPTIMISATIONS], [CFLAGS=`echo "$CFLAGS" | sed -e "s/ -O[1-9]*\b/ -O0/g"`] fi])dnl ])# COMPILER_OPTIMISATIONS - -# COMPILER_COVERAGE -# ---------------------- -# Add configure option to enable coverage data. -AC_DEFUN([COMPILER_COVERAGE], -[AC_ARG_ENABLE(compiler-coverage, - AS_HELP_STRING([--enable-compiler-coverage], - [Enable generation of coverage data]), -[if test "x$enable_compiler_coverage" = "xyes"; then - if test "x$GCC" = "xyes"; then - CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage" - fi -fi],[enable_compiler_coverage=no])dnl -])# COMPILER_COVERAGE diff --git a/test/Makefile.am b/test/Makefile.am index 0efd204..75608d1 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,13 +1,14 @@ -## the "name-test" subdir in fact contains a bunch of tests now that need a temporary bus +## the "name-test" subdir in fact contains a bunch of tests now that need a temporary bus ## to be running to do stuff with. The directory should be renamed. ## We want to build the current directory first to pick up the testutils lib -SUBDIRS= . name-test +SUBDIRS= . name-test DIST_SUBDIRS=name-test CLEANFILES = EXTRA_DIST = AM_CPPFLAGS = \ + $(CODE_COVERAGE_CPPFLAGS) \ -I$(top_srcdir) \ $(DBUS_STATIC_BUILD_CPPFLAGS) \ -DDBUS_COMPILATION \ @@ -17,6 +18,10 @@ AM_CPPFLAGS = \ # improve backtraces from test stuff AM_LDFLAGS = @R_DYNAMIC_LDFLAG@ +AM_CFLAGS = \ + $(CODE_COVERAGE_CFLAGS) \ + $(NULL) + noinst_LTLIBRARIES = libdbus-testutils.la libdbus_testutils_la_SOURCES = \ @@ -34,6 +39,7 @@ endif libdbus_testutils_la_LIBADD = \ $(top_builddir)/dbus/libdbus-1.la \ $(top_builddir)/dbus/libdbus-internal.la \ + $(CODE_COVERAGE_LDFLAGS) \ $(NULL) TEST_EXTENSIONS = .sh @@ -525,3 +531,6 @@ $(installable_test_meta_with_config): %_with_config.test: %$(EXEEXT) Makefile echo 'Output=TAP'; \ echo 'Exec=env DBUS_TEST_DATA=$(testexecdir)/data $(testexecdir)/$* --tap'; \ ) > $@.tmp && mv $@.tmp $@ + +# Add rules for code-coverage testing, as defined by AX_CODE_COVERAGE +@CODE_COVERAGE_RULES@ diff --git a/tools/lcov.am b/tools/lcov.am deleted file mode 100644 index ac34867..0000000 --- a/tools/lcov.am +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright © 2008-2011 Collabora Ltd. -# Copyright © 2008-2011 Nokia Corporation -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -lcov-reset: - lcov --directory @abs_top_builddir@ --zerocounters - -lcov-report: - lcov --directory @abs_top_builddir@ --capture \ - --output-file @abs_top_builddir@/lcov.info - $(mkdir_p) @abs_top_builddir@/lcov.html - git_commit=`GIT_DIR=@abs_top_srcdir@/.git git log -1 --pretty=format:%h 2>/dev/null`;\ - genhtml --title "@PACKAGE_STRING@ $$git_commit" \ - --output-directory @abs_top_builddir@/lcov.html lcov.info - @echo - @echo 'lcov report can be found in:' - @echo 'file://@abs_top_builddir@/lcov.html/index.html' - @echo - -lcov-check: - $(MAKE) lcov-reset - $(MAKE) check $(LCOV_CHECK_ARGS) - $(MAKE) lcov-report - -## vim:set ft=automake: -- 2.7.4