From: Thomas Zimmermann Date: Fri, 12 Aug 2016 08:50:53 +0000 (+0200) Subject: Use AX_CODE_COVERAGE for test-coverage statistics X-Git-Tag: dbus-1.11.4~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=be04ba8354f8981ac33c66555464fdabc24d3a6a;p=thirdparty%2Fdbus.git 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 [smcv: do not alter compiler.m4; move AM_CXXFLAGS to the one place we compile C++] Reviewed-by: Simon McVittie Bug: https://bugs.freedesktop.org/show_bug.cgi?id=88922 --- diff --git a/Makefile.am b/Makefile.am index 756ab8b9a..db0d52289 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 90092b142..268c6f040 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,10 @@ AM_CPPFLAGS = \ # if assertions are enabled, improve backtraces AM_LDFLAGS = @R_DYNAMIC_LDFLAG@ +AM_CFLAGS = \ + $(CODE_COVERAGE_CFLAGS) \ + $(NULL) + EFENCE= CONFIG_IN_FILES= \ @@ -233,10 +240,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 +330,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 2aac82ed1..cf08a055e 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 015248654..e4aa2eeac 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 @@ -306,6 +309,10 @@ libdbus_1_la_LDFLAGS = \ libdbus_internal_la_LIBADD=$(LIBDBUS_LIBS) libdbus-1.la if DBUS_WIN +AM_CXXFLAGS = \ + $(CODE_COVERAGE_CXXFLAGS) \ + $(NULL) + # This must be a separate convenience library, otherwise libtool notices # that libdbus-1 might contain C++, links it with g++ and links in libstdc++, # even on Unix where in fact it doesn't contain any C++. For Windows, where @@ -327,6 +334,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/test/Makefile.am b/test/Makefile.am index 85799fe3e..1b6d757c2 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 @@ -555,3 +561,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 ac348671d..000000000 --- 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: