Blame SOURCES/libsodium-1.0.18/m4/ax_valgrind_check.m4

ca16be
# ===========================================================================
ca16be
#    https://www.gnu.org/software/autoconf-archive/ax_valgrind_check.html
ca16be
# ===========================================================================
ca16be
#
ca16be
# SYNOPSIS
ca16be
#
ca16be
#   AX_VALGRIND_DFLT(memcheck|helgrind|drd|sgcheck, on|off)
ca16be
#   AX_VALGRIND_CHECK()
ca16be
#
ca16be
# DESCRIPTION
ca16be
#
ca16be
#   AX_VALGRIND_CHECK checks whether Valgrind is present and, if so, allows
ca16be
#   running `make check` under a variety of Valgrind tools to check for
ca16be
#   memory and threading errors.
ca16be
#
ca16be
#   Defines VALGRIND_CHECK_RULES which should be substituted in your
ca16be
#   Makefile; and $enable_valgrind which can be used in subsequent configure
ca16be
#   output. VALGRIND_ENABLED is defined and substituted, and corresponds to
ca16be
#   the value of the --enable-valgrind option, which defaults to being
ca16be
#   enabled if Valgrind is installed and disabled otherwise. Individual
ca16be
#   Valgrind tools can be disabled via --disable-valgrind-<tool>, the
ca16be
#   default is configurable via the AX_VALGRIND_DFLT command or is to use
ca16be
#   all commands not disabled via AX_VALGRIND_DFLT. All AX_VALGRIND_DFLT
ca16be
#   calls must be made before the call to AX_VALGRIND_CHECK.
ca16be
#
ca16be
#   If unit tests are written using a shell script and automake's
ca16be
#   LOG_COMPILER system, the $(VALGRIND) variable can be used within the
ca16be
#   shell scripts to enable Valgrind, as described here:
ca16be
#
ca16be
#     https://www.gnu.org/software/gnulib/manual/html_node/Running-self_002dtests-under-valgrind.html
ca16be
#
ca16be
#   Usage example:
ca16be
#
ca16be
#   configure.ac:
ca16be
#
ca16be
#     AX_VALGRIND_DFLT([sgcheck], [off])
ca16be
#     AX_VALGRIND_CHECK
ca16be
#
ca16be
#   Makefile.am:
ca16be
#
ca16be
#     @VALGRIND_CHECK_RULES@
ca16be
#     VALGRIND_SUPPRESSIONS_FILES = my-project.supp
ca16be
#     EXTRA_DIST = my-project.supp
ca16be
#
ca16be
#   This results in a "check-valgrind" rule being added to any Makefile.am
ca16be
#   which includes "@VALGRIND_CHECK_RULES@" (assuming the module has been
ca16be
#   configured with --enable-valgrind). Running `make check-valgrind` in
ca16be
#   that directory will run the module's test suite (`make check`) once for
ca16be
#   each of the available Valgrind tools (out of memcheck, helgrind and drd)
ca16be
#   while the sgcheck will be skipped unless enabled again on the
ca16be
#   commandline with --enable-valgrind-sgcheck. The results for each check
ca16be
#   will be output to test-suite-$toolname.log. The target will succeed if
ca16be
#   there are zero errors and fail otherwise.
ca16be
#
ca16be
#   Alternatively, a "check-valgrind-$TOOL" rule will be added, for $TOOL in
ca16be
#   memcheck, helgrind, drd and sgcheck. These are useful because often only
ca16be
#   some of those tools can be ran cleanly on a codebase.
ca16be
#
ca16be
#   The macro supports running with and without libtool.
ca16be
#
ca16be
# LICENSE
ca16be
#
ca16be
#   Copyright (c) 2014, 2015, 2016 Philip Withnall <philip.withnall@collabora.co.uk>
ca16be
#
ca16be
#   Copying and distribution of this file, with or without modification, are
ca16be
#   permitted in any medium without royalty provided the copyright notice
ca16be
#   and this notice are preserved.  This file is offered as-is, without any
ca16be
#   warranty.
ca16be
ca16be
#serial 15
ca16be
ca16be
dnl Configured tools
ca16be
m4_define([valgrind_tool_list], [[memcheck], [helgrind], [drd], [sgcheck]])
ca16be
m4_set_add_all([valgrind_exp_tool_set], [sgcheck])
ca16be
m4_foreach([vgtool], [valgrind_tool_list],
ca16be
           [m4_define([en_dflt_valgrind_]vgtool, [on])])
ca16be
ca16be
AC_DEFUN([AX_VALGRIND_DFLT],[
ca16be
	m4_define([en_dflt_valgrind_$1], [$2])
ca16be
])dnl
ca16be
ca16be
AC_DEFUN([AX_VALGRIND_CHECK],[
ca16be
	dnl Check for --enable-valgrind
ca16be
	AC_ARG_ENABLE([valgrind],
ca16be
				  [AS_HELP_STRING([--enable-valgrind], [Whether to enable Valgrind on the unit tests (requires GNU make)])],
ca16be
				  [enable_valgrind=$enableval],[enable_valgrind=no])
ca16be
ca16be
	AS_IF([test "$enable_valgrind" != "no"],[
ca16be
		# Check for Valgrind.
ca16be
		AC_CHECK_PROG([VALGRIND],[valgrind],[valgrind])
ca16be
		AS_IF([test "$VALGRIND" = ""],[
ca16be
			AS_IF([test "$enable_valgrind" = "yes"],[
ca16be
				AC_MSG_ERROR([Could not find valgrind; either install it or reconfigure with --disable-valgrind])
ca16be
			],[
ca16be
				enable_valgrind=no
ca16be
			])
ca16be
		],[
ca16be
			enable_valgrind=yes
ca16be
		])
ca16be
	])
ca16be
ca16be
	AM_CONDITIONAL([VALGRIND_ENABLED],[test "$enable_valgrind" = "yes"])
ca16be
	AC_SUBST([VALGRIND_ENABLED],[$enable_valgrind])
ca16be
ca16be
	# Check for Valgrind tools we care about.
ca16be
	[valgrind_enabled_tools=]
ca16be
	m4_foreach([vgtool],[valgrind_tool_list],[
ca16be
		AC_ARG_ENABLE([valgrind-]vgtool,
ca16be
		    m4_if(m4_defn([en_dflt_valgrind_]vgtool),[off],dnl
ca16be
[AS_HELP_STRING([--enable-valgrind-]vgtool, [Whether to use ]vgtool[ during the Valgrind tests])],dnl
ca16be
[AS_HELP_STRING([--disable-valgrind-]vgtool, [Whether to skip ]vgtool[ during the Valgrind tests])]),
ca16be
		              [enable_valgrind_]vgtool[=$enableval],
ca16be
		              [enable_valgrind_]vgtool[=])
ca16be
		AS_IF([test "$enable_valgrind" = "no"],[
ca16be
			enable_valgrind_]vgtool[=no],
ca16be
		      [test "$enable_valgrind_]vgtool[" ]dnl
ca16be
m4_if(m4_defn([en_dflt_valgrind_]vgtool), [off], [= "yes"], [!= "no"]),[
ca16be
			AC_CACHE_CHECK([for Valgrind tool ]vgtool,
ca16be
			               [ax_cv_valgrind_tool_]vgtool,[
ca16be
				ax_cv_valgrind_tool_]vgtool[=no
ca16be
				m4_set_contains([valgrind_exp_tool_set],vgtool,
ca16be
				    [m4_define([vgtoolx],[exp-]vgtool)],
ca16be
				    [m4_define([vgtoolx],vgtool)])
ca16be
				AS_IF([`$VALGRIND --tool=]vgtoolx[ --help >/dev/null 2>&1`],[
ca16be
					ax_cv_valgrind_tool_]vgtool[=yes
ca16be
				])
ca16be
			])
ca16be
			AS_IF([test "$ax_cv_valgrind_tool_]vgtool[" = "no"],[
ca16be
				AS_IF([test "$enable_valgrind_]vgtool[" = "yes"],[
ca16be
					AC_MSG_ERROR([Valgrind does not support ]vgtool[; reconfigure with --disable-valgrind-]vgtool)
ca16be
				],[
ca16be
					enable_valgrind_]vgtool[=no
ca16be
				])
ca16be
			],[
ca16be
				enable_valgrind_]vgtool[=yes
ca16be
			])
ca16be
		])
ca16be
		AS_IF([test "$enable_valgrind_]vgtool[" = "yes"],[
ca16be
			valgrind_enabled_tools="$valgrind_enabled_tools ]m4_bpatsubst(vgtool,[^exp-])["
ca16be
		])
ca16be
		AC_SUBST([ENABLE_VALGRIND_]vgtool,[$enable_valgrind_]vgtool)
ca16be
	])
ca16be
	AC_SUBST([valgrind_tools],["]m4_join([ ], valgrind_tool_list)["])
ca16be
	AC_SUBST([valgrind_enabled_tools],[$valgrind_enabled_tools])
ca16be
ca16be
[VALGRIND_CHECK_RULES='
ca16be
# Valgrind check
ca16be
#
ca16be
# Optional:
ca16be
#  - VALGRIND_SUPPRESSIONS_FILES: Space-separated list of Valgrind suppressions
ca16be
#    files to load. (Default: empty)
ca16be
#  - VALGRIND_FLAGS: General flags to pass to all Valgrind tools.
ca16be
#    (Default: --num-callers=30)
ca16be
#  - VALGRIND_$toolname_FLAGS: Flags to pass to Valgrind $toolname (one of:
ca16be
#    memcheck, helgrind, drd, sgcheck). (Default: various)
ca16be
ca16be
# Optional variables
ca16be
VALGRIND_SUPPRESSIONS ?= $(addprefix --suppressions=,$(VALGRIND_SUPPRESSIONS_FILES))
ca16be
VALGRIND_FLAGS ?= --num-callers=30
ca16be
VALGRIND_memcheck_FLAGS ?= --leak-check=full --show-reachable=no
ca16be
VALGRIND_helgrind_FLAGS ?= --history-level=approx
ca16be
VALGRIND_drd_FLAGS ?=
ca16be
VALGRIND_sgcheck_FLAGS ?=
ca16be
ca16be
# Internal use
ca16be
valgrind_log_files = $(addprefix test-suite-,$(addsuffix .log,$(valgrind_tools)))
ca16be
ca16be
valgrind_memcheck_flags = --tool=memcheck $(VALGRIND_memcheck_FLAGS)
ca16be
valgrind_helgrind_flags = --tool=helgrind $(VALGRIND_helgrind_FLAGS)
ca16be
valgrind_drd_flags = --tool=drd $(VALGRIND_drd_FLAGS)
ca16be
valgrind_sgcheck_flags = --tool=exp-sgcheck $(VALGRIND_sgcheck_FLAGS)
ca16be
ca16be
valgrind_quiet = $(valgrind_quiet_$(V))
ca16be
valgrind_quiet_ = $(valgrind_quiet_$(AM_DEFAULT_VERBOSITY))
ca16be
valgrind_quiet_0 = --quiet
ca16be
valgrind_v_use   = $(valgrind_v_use_$(V))
ca16be
valgrind_v_use_  = $(valgrind_v_use_$(AM_DEFAULT_VERBOSITY))
ca16be
valgrind_v_use_0 = @echo "  USE   " $(patsubst check-valgrind-%,%,$''@):;
ca16be
ca16be
# Support running with and without libtool.
ca16be
ifneq ($(LIBTOOL),)
ca16be
valgrind_lt = $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=execute
ca16be
else
ca16be
valgrind_lt =
ca16be
endif
ca16be
ca16be
# Use recursive makes in order to ignore errors during check
ca16be
check-valgrind:
ca16be
ifeq ($(VALGRIND_ENABLED),yes)
ca16be
	$(A''M_V_at)$(MAKE) $(AM_MAKEFLAGS) -k \
ca16be
		$(foreach tool, $(valgrind_enabled_tools), check-valgrind-$(tool))
ca16be
else
ca16be
	@echo "Need to use GNU make and reconfigure with --enable-valgrind"
ca16be
endif
ca16be
ca16be
# Valgrind running
ca16be
VALGRIND_TESTS_ENVIRONMENT = \
ca16be
	$(TESTS_ENVIRONMENT) \
ca16be
	env VALGRIND=$(VALGRIND) \
ca16be
	G_SLICE=always-malloc,debug-blocks \
ca16be
	G_DEBUG=fatal-warnings,fatal-criticals,gc-friendly
ca16be
ca16be
VALGRIND_LOG_COMPILER = \
ca16be
	$(valgrind_lt) \
ca16be
	$(VALGRIND) $(VALGRIND_SUPPRESSIONS) --error-exitcode=1 $(VALGRIND_FLAGS)
ca16be
ca16be
define valgrind_tool_rule =
ca16be
check-valgrind-$(1):
ca16be
ifeq ($$(VALGRIND_ENABLED)-$$(ENABLE_VALGRIND_$(1)),yes-yes)
ca16be
	$$(valgrind_v_use)$$(MAKE) check-TESTS \
ca16be
		TESTS_ENVIRONMENT="$$(VALGRIND_TESTS_ENVIRONMENT)" \
ca16be
		LOG_COMPILER="$$(VALGRIND_LOG_COMPILER)" \
ca16be
		LOG_FLAGS="$$(valgrind_$(1)_flags)" \
ca16be
		TEST_SUITE_LOG=test-suite-$(1).log
ca16be
else ifeq ($$(VALGRIND_ENABLED),yes)
ca16be
	@echo "Need to reconfigure with --enable-valgrind-$(1)"
ca16be
else
ca16be
	@echo "Need to reconfigure with --enable-valgrind"
ca16be
endif
ca16be
endef
ca16be
ca16be
$(foreach tool,$(valgrind_tools),$(eval $(call valgrind_tool_rule,$(tool))))
ca16be
ca16be
A''M_DISTCHECK_CONFIGURE_FLAGS ?=
ca16be
A''M_DISTCHECK_CONFIGURE_FLAGS += --disable-valgrind
ca16be
ca16be
MOSTLYCLEANFILES ?=
ca16be
MOSTLYCLEANFILES += $(valgrind_log_files)
ca16be
ca16be
.PHONY: check-valgrind $(add-prefix check-valgrind-,$(valgrind_tools))
ca16be
']
ca16be
ca16be
	AS_IF([test "$enable_valgrind" != "yes"], [
ca16be
		VALGRIND_CHECK_RULES='
ca16be
check-valgrind:
ca16be
	@echo "Need to use GNU make and reconfigure with --enable-valgrind"'
ca16be
	])
ca16be
ca16be
	AC_SUBST([VALGRIND_CHECK_RULES])
ca16be
	m4_ifdef([_AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE([VALGRIND_CHECK_RULES])])
ca16be
])