|
Packit Service |
0bf00e |
# SYNOPSIS
|
|
Packit Service |
0bf00e |
#
|
|
Packit Service |
0bf00e |
# AX_CODE_COVERAGE()
|
|
Packit Service |
0bf00e |
#
|
|
Packit Service |
0bf00e |
# DESCRIPTION
|
|
Packit Service |
0bf00e |
#
|
|
Packit Service |
0bf00e |
# Defines CODE_COVERAGE_CFLAGS and CODE_COVERAGE_LDFLAGS which should be
|
|
Packit Service |
0bf00e |
# included in the CFLAGS and LIBS/LDFLAGS variables of every build target
|
|
Packit Service |
0bf00e |
# (program or library) which should be built with code coverage support.
|
|
Packit Service |
0bf00e |
# Also defines CODE_COVERAGE_RULES which should be substituted in your
|
|
Packit Service |
0bf00e |
# Makefile; and $enable_code_coverage which can be used in subsequent
|
|
Packit Service |
0bf00e |
# configure output. CODE_COVERAGE_ENABLED is defined and substituted, and
|
|
Packit Service |
0bf00e |
# corresponds to the value of the --enable-code-coverage option, which
|
|
Packit Service |
0bf00e |
# defaults to being disabled.
|
|
Packit Service |
0bf00e |
#
|
|
Packit Service |
0bf00e |
# Note that all optimisation flags in CFLAGS must be disabled when code
|
|
Packit Service |
0bf00e |
# coverage is enabled.
|
|
Packit Service |
0bf00e |
#
|
|
Packit Service |
0bf00e |
# Usage example:
|
|
Packit Service |
0bf00e |
# configure.ac:
|
|
Packit Service |
0bf00e |
# AX_CODE_COVERAGE
|
|
Packit Service |
0bf00e |
#
|
|
Packit Service |
0bf00e |
# Makefile.am:
|
|
Packit Service |
0bf00e |
# @CODE_COVERAGE_RULES@
|
|
Packit Service |
0bf00e |
# my_program_LIBS = … $(CODE_COVERAGE_LDFLAGS) …
|
|
Packit Service |
0bf00e |
# my_program_CFLAGS = … $(CODE_COVERAGE_CFLAGS) …
|
|
Packit Service |
0bf00e |
#
|
|
Packit Service |
0bf00e |
# This results in a “check-code-coverage” rule being added to any Makefile.am
|
|
Packit Service |
0bf00e |
# which includes “@CODE_COVERAGE_RULES@” (assuming the module has been
|
|
Packit Service |
0bf00e |
# configured with --enable-code-coverage). Running `make check-code-coverage`
|
|
Packit Service |
0bf00e |
# in that directory will run the module’s test suite (`make check`) and build
|
|
Packit Service |
0bf00e |
# a code coverage report detailing the code which was touched, then print the
|
|
Packit Service |
0bf00e |
# URI for the report.
|
|
Packit Service |
0bf00e |
#
|
|
Packit Service |
0bf00e |
# LICENSE
|
|
Packit Service |
0bf00e |
#
|
|
Packit Service |
0bf00e |
# Copyright © 2012, 2014 Philip Withnall
|
|
Packit Service |
0bf00e |
# Copyright © 2012 Xan Lopez
|
|
Packit Service |
0bf00e |
# Copyright © 2012 Christian Persch
|
|
Packit Service |
0bf00e |
# Copyright © 2012 Paolo Borelli
|
|
Packit Service |
0bf00e |
# Copyright © 2012 Dan Winship
|
|
Packit Service |
0bf00e |
#
|
|
Packit Service |
0bf00e |
# Derived from Makefile.decl in GLib, originally licenced under LGPLv2.1+.
|
|
Packit Service |
0bf00e |
# This file is licenced under LGPLv2.1+.
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
#serial 1
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
AC_DEFUN([AX_CODE_COVERAGE],[
|
|
Packit Service |
0bf00e |
dnl Check for --enable-code-coverage
|
|
Packit Service |
0bf00e |
AC_MSG_CHECKING([whether to build with code coverage support])
|
|
Packit Service |
0bf00e |
AC_ARG_ENABLE([code-coverage], AS_HELP_STRING([--enable-code-coverage], [Whether to enable code coverage support]),, enable_code_coverage=no)
|
|
Packit Service |
0bf00e |
AM_CONDITIONAL([CODE_COVERAGE_ENABLED], [test x$enable_code_coverage = xyes])
|
|
Packit Service |
0bf00e |
AC_SUBST([CODE_COVERAGE_ENABLED], [$enable_code_coverage])
|
|
Packit Service |
0bf00e |
AC_MSG_RESULT($enable_code_coverage)
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
AS_IF([ test "$enable_code_coverage" = "yes" ], [
|
|
Packit Service |
0bf00e |
dnl Check if gcc is being used
|
|
Packit Service |
0bf00e |
AS_IF([ test "$GCC" = "no" ], [
|
|
Packit Service |
0bf00e |
AC_MSG_ERROR([not compiling with gcc, which is required for gcov code coverage])
|
|
Packit Service |
0bf00e |
])
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
# List of supported lcov versions.
|
|
Packit Service |
0bf00e |
lcov_version_list="1.6 1.7 1.8 1.9 1.10 1.11"
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
AC_CHECK_PROG([LCOV], [lcov], [lcov])
|
|
Packit Service |
0bf00e |
AC_CHECK_PROG([GENHTML], [genhtml], [genhtml])
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
AS_IF([ test "$LCOV" ], [
|
|
Packit Service |
0bf00e |
AC_CACHE_CHECK([for lcov version], ax_cv_lcov_version, [
|
|
Packit Service |
0bf00e |
ax_cv_lcov_version=invalid
|
|
Packit Service |
0bf00e |
lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
|
|
Packit Service |
0bf00e |
for lcov_check_version in $lcov_version_list; do
|
|
Packit Service |
0bf00e |
if test "$lcov_version" = "$lcov_check_version"; then
|
|
Packit Service |
0bf00e |
ax_cv_lcov_version="$lcov_check_version (ok)"
|
|
Packit Service |
0bf00e |
fi
|
|
Packit Service |
0bf00e |
done
|
|
Packit Service |
0bf00e |
])
|
|
Packit Service |
0bf00e |
], [
|
|
Packit Service |
0bf00e |
lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
|
|
Packit Service |
0bf00e |
AC_MSG_ERROR([$lcov_msg])
|
|
Packit Service |
0bf00e |
])
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
case $ax_cv_lcov_version in
|
|
Packit Service |
0bf00e |
""|invalid[)]
|
|
Packit Service |
0bf00e |
lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
|
|
Packit Service |
0bf00e |
AC_MSG_ERROR([$lcov_msg])
|
|
Packit Service |
0bf00e |
LCOV="exit 0;"
|
|
Packit Service |
0bf00e |
;;
|
|
Packit Service |
0bf00e |
esac
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
AS_IF([ test -z "$GENHTML" ], [
|
|
Packit Service |
0bf00e |
AC_MSG_ERROR([Could not find genhtml from the lcov package])
|
|
Packit Service |
0bf00e |
])
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
dnl Build the code coverage flags
|
|
Packit Service |
0bf00e |
CODE_COVERAGE_CFLAGS="-O0 -g -fprofile-arcs -ftest-coverage"
|
|
Packit Service |
0bf00e |
CODE_COVERAGE_LDFLAGS="-lgcov"
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
AC_SUBST([CODE_COVERAGE_CFLAGS])
|
|
Packit Service |
0bf00e |
AC_SUBST([CODE_COVERAGE_LDFLAGS])
|
|
Packit Service |
0bf00e |
])
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
CODE_COVERAGE_RULES='
|
|
Packit Service |
0bf00e |
# Code coverage
|
|
Packit Service |
0bf00e |
#
|
|
Packit Service |
0bf00e |
# Optional:
|
|
Packit Service |
0bf00e |
# - CODE_COVERAGE_DIRECTORY: Top-level directory for code coverage reporting.
|
|
Packit Service |
0bf00e |
# (Default: $(top_builddir))
|
|
Packit Service |
0bf00e |
# - CODE_COVERAGE_OUTPUT_FILE: Filename and path for the .info file generated
|
|
Packit Service |
0bf00e |
# by lcov for code coverage. (Default:
|
|
Packit Service |
0bf00e |
# $(PACKAGE_NAME)-$(PACKAGE_VERSION)-coverage.info)
|
|
Packit Service |
0bf00e |
# - CODE_COVERAGE_OUTPUT_DIRECTORY: Directory for generated code coverage
|
|
Packit Service |
0bf00e |
# reports to be created. (Default:
|
|
Packit Service |
0bf00e |
# $(PACKAGE_NAME)-$(PACKAGE_VERSION)-coverage)
|
|
Packit Service |
0bf00e |
# - CODE_COVERAGE_LCOV_OPTIONS: Extra options to pass to the lcov instance.
|
|
Packit Service |
0bf00e |
# (Default: empty)
|
|
Packit Service |
0bf00e |
# - CODE_COVERAGE_GENHTML_OPTIONS: Extra options to pass to the genhtml
|
|
Packit Service |
0bf00e |
# instance. (Default: empty)
|
|
Packit Service |
0bf00e |
# - CODE_COVERAGE_IGNORE_PATTERN: Extra glob pattern of files to ignore
|
|
Packit Service |
0bf00e |
#
|
|
Packit Service |
0bf00e |
# The generated report will be titled using the $(PACKAGE_NAME) and
|
|
Packit Service |
0bf00e |
# $(PACKAGE_VERSION). In order to add the current git hash to the title,
|
|
Packit Service |
0bf00e |
# use the git-version-gen script, available online.
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
# Optional variables
|
|
Packit Service |
0bf00e |
CODE_COVERAGE_DIRECTORY ?= $(top_builddir)
|
|
Packit Service |
0bf00e |
CODE_COVERAGE_OUTPUT_FILE ?= $(PACKAGE_NAME)-$(PACKAGE_VERSION)-coverage.info
|
|
Packit Service |
0bf00e |
CODE_COVERAGE_OUTPUT_DIRECTORY ?= $(PACKAGE_NAME)-$(PACKAGE_VERSION)-coverage
|
|
Packit Service |
0bf00e |
CODE_COVERAGE_LCOV_OPTIONS ?=
|
|
Packit Service |
0bf00e |
CODE_COVERAGE_GENHTML_OPTIONS ?=
|
|
Packit Service |
0bf00e |
CODE_COVERAGE_IGNORE_PATTERN ?=
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
code_coverage_quiet = $(code_coverage_quiet_$(V))
|
|
Packit Service |
0bf00e |
code_coverage_quiet_ = $(code_coverage_quiet_$(AM_DEFAULT_VERBOSITY))
|
|
Packit Service |
0bf00e |
code_coverage_quiet_0 = --quiet
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
# Use recursive makes in order to ignore errors during check
|
|
Packit Service |
0bf00e |
check-code-coverage:
|
|
Packit Service |
0bf00e |
ifeq ($(CODE_COVERAGE_ENABLED),yes)
|
|
Packit Service |
0bf00e |
-$(MAKE) $(AM_MAKEFLAGS) -k check
|
|
Packit Service |
0bf00e |
$(MAKE) $(AM_MAKEFLAGS) code-coverage-capture
|
|
Packit Service |
0bf00e |
else
|
|
Packit Service |
0bf00e |
@echo "Need to reconfigure with --enable-code-coverage"
|
|
Packit Service |
0bf00e |
endif
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
# Capture code coverage data
|
|
Packit Service |
0bf00e |
code-coverage-capture: code-coverage-capture-hook
|
|
Packit Service |
0bf00e |
ifeq ($(CODE_COVERAGE_ENABLED),yes)
|
|
Packit Service |
0bf00e |
$(LCOV) $(code_coverage_quiet) --directory $(CODE_COVERAGE_DIRECTORY) --capture --output-file "$(CODE_COVERAGE_OUTPUT_FILE).tmp" --test-name "$(PACKAGE_NAME)-$(PACKAGE_VERSION)" --no-checksum --compat-libtool $(CODE_COVERAGE_LCOV_OPTIONS)
|
|
Packit Service |
0bf00e |
$(LCOV) $(code_coverage_quiet) --directory $(CODE_COVERAGE_DIRECTORY) --remove "$(CODE_COVERAGE_OUTPUT_FILE).tmp" "/tmp/*" $(CODE_COVERAGE_IGNORE_PATTERN) --output-file "$(CODE_COVERAGE_OUTPUT_FILE)"
|
|
Packit Service |
0bf00e |
-@rm -f $(CODE_COVERAGE_OUTPUT_FILE).tmp
|
|
Packit Service |
0bf00e |
LANG=C $(GENHTML) $(code_coverage_quiet) --prefix $(CODE_COVERAGE_DIRECTORY) --output-directory "$(CODE_COVERAGE_OUTPUT_DIRECTORY)" --title "$(PACKAGE_NAME)-$(PACKAGE_VERSION) Code Coverage" --legend --show-details "$(CODE_COVERAGE_OUTPUT_FILE)" $(CODE_COVERAGE_GENHTML_OPTIONS)
|
|
Packit Service |
0bf00e |
@echo "file://$(abs_builddir)/$(CODE_COVERAGE_OUTPUT_DIRECTORY)/index.html"
|
|
Packit Service |
0bf00e |
else
|
|
Packit Service |
0bf00e |
@echo "Need to reconfigure with --enable-code-coverage"
|
|
Packit Service |
0bf00e |
endif
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
# Hook rule executed before code-coverage-capture, overridable by the user
|
|
Packit Service |
0bf00e |
code-coverage-capture-hook:
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
ifeq ($(CODE_COVERAGE_ENABLED),yes)
|
|
Packit Service |
0bf00e |
clean: code-coverage-clean
|
|
Packit Service |
0bf00e |
code-coverage-clean:
|
|
Packit Service |
0bf00e |
-$(LCOV) --directory $(top_builddir) -z
|
|
Packit Service |
0bf00e |
-rm -rf $(CODE_COVERAGE_OUTPUT_FILE) $(CODE_COVERAGE_OUTPUT_FILE).tmp $(CODE_COVERAGE_OUTPUT_DIRECTORY)
|
|
Packit Service |
0bf00e |
-find . -name "*.gcda" -o -name "*.gcov" -delete
|
|
Packit Service |
0bf00e |
endif
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
GITIGNOREFILES ?=
|
|
Packit Service |
0bf00e |
GITIGNOREFILES += $(CODE_COVERAGE_OUTPUT_FILE) $(CODE_COVERAGE_OUTPUT_DIRECTORY)
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
DISTCHECK_CONFIGURE_FLAGS ?=
|
|
Packit Service |
0bf00e |
DISTCHECK_CONFIGURE_FLAGS += --disable-code-coverage
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
.PHONY: check-code-coverage code-coverage-capture code-coverage-capture-hook code-coverage-clean
|
|
Packit Service |
0bf00e |
'
|
|
Packit Service |
0bf00e |
|
|
Packit Service |
0bf00e |
AC_SUBST([CODE_COVERAGE_RULES])
|
|
Packit Service |
0bf00e |
m4_ifdef([_AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE([CODE_COVERAGE_RULES])])
|
|
Packit Service |
0bf00e |
])
|