m4/ax_valgrind_check.m4
author J. Ali Harlow <ali@juiblex.co.uk>
Sat Jul 16 11:07:18 2016 +0100 (2016-07-16)
changeset 61 31fb35727621
permissions -rw-r--r--
Support parallel installations. The idea is that for CAD screener, we want
to be able to install this on the same machine as a standard AVOT setup
(most notably for John's laptop). To allow for the possibility of a second
application that might have the same requirements, we add the concept of
vendor-specific distributions. Thus we can have one distribution for CAD
screener and one for The Next Big Thing. It doesn't seem trivial to have
both CAD screener and AVOT under the same vendor tag so we'll have to have
AVOT under "City Occupational" and CAD screener under "City Occupational Ltd"
or some such kludge.

Most of this is done although we are very short of test cases (in particular
we don't test that it's actually possible to install CAD screener in parallel
with AVOT or to update either of them once installed, which is fundamental).

We also have a lot of baggage left over, including an intercept of razor_set.
The problem that this was introduced to debug has been fixed but it looks
like there are a number of memory leaks which it might be useful to help
track down so it has been left in place for now.

There is still a lot of confusion in plover between path-based and URI-based
API. We should review the API, decide what we want and have a general clear up.

There is also confusion as to the purpose of RAZOR_ROOT (and meaning; path or
URI). This is not used at all in librazor (although it is used in razor.exe).
Ideally we shouldn't use it in plover or plover-gtk either although again, we
might want to support it or an equivalent in (some of) the various executables.

Work that would still to nice to do for CAD screener:

- uninstall (ideally as an installed program that hooks into Add/Remove programs
but even re-running the installer would be acceptable).
- xz support (smaller packages).
- repomd.xml and xml:base (would be needed for an Internet installer).
- graphical installer.
ali@38
     1
# ===========================================================================
ali@38
     2
#     http://www.gnu.org/software/autoconf-archive/ax_valgrind_check.html
ali@38
     3
# ===========================================================================
ali@38
     4
#
ali@38
     5
# SYNOPSIS
ali@38
     6
#
ali@38
     7
#   AX_VALGRIND_CHECK()
ali@38
     8
#
ali@38
     9
# DESCRIPTION
ali@38
    10
#
ali@38
    11
#   Checks whether Valgrind is present and, if so, allows running `make
ali@38
    12
#   check` under a variety of Valgrind tools to check for memory and
ali@38
    13
#   threading errors.
ali@38
    14
#
ali@38
    15
#   Defines VALGRIND_CHECK_RULES which should be substituted in your
ali@38
    16
#   Makefile; and $enable_valgrind which can be used in subsequent configure
ali@38
    17
#   output. VALGRIND_ENABLED is defined and substituted, and corresponds to
ali@38
    18
#   the value of the --enable-valgrind option, which defaults to being
ali@38
    19
#   enabled if Valgrind is installed and disabled otherwise.
ali@38
    20
#
ali@38
    21
#   If unit tests are written using a shell script and automake's
ali@38
    22
#   LOG_COMPILER system, the $(VALGRIND) variable can be used within the
ali@38
    23
#   shell scripts to enable Valgrind, as described here:
ali@38
    24
#
ali@38
    25
#     https://www.gnu.org/software/gnulib/manual/html_node/Running-self_002dtests-under-valgrind.html
ali@38
    26
#
ali@38
    27
#   Usage example:
ali@38
    28
#
ali@38
    29
#   configure.ac:
ali@38
    30
#
ali@38
    31
#     AX_VALGRIND_CHECK
ali@38
    32
#
ali@38
    33
#   Makefile.am:
ali@38
    34
#
ali@38
    35
#     @VALGRIND_CHECK_RULES@
ali@38
    36
#     VALGRIND_SUPPRESSIONS_FILES = my-project.supp
ali@38
    37
#     EXTRA_DIST = my-project.supp
ali@38
    38
#
ali@38
    39
#   This results in a "check-valgrind" rule being added to any Makefile.am
ali@38
    40
#   which includes "@VALGRIND_CHECK_RULES@" (assuming the module has been
ali@38
    41
#   configured with --enable-valgrind). Running `make check-valgrind` in
ali@38
    42
#   that directory will run the module's test suite (`make check`) once for
ali@38
    43
#   each of the available Valgrind tools (out of memcheck, helgrind, drd and
ali@38
    44
#   sgcheck), and will output results to test-suite-$toolname.log for each.
ali@38
    45
#   The target will succeed if there are zero errors and fail otherwise.
ali@38
    46
#
ali@38
    47
#   Alternatively, a "check-valgrind-$TOOL" rule will be added, for $TOOL in
ali@38
    48
#   memcheck, helgrind, drd and sgcheck. These are useful because often only
ali@38
    49
#   some of those tools can be ran cleanly on a codebase.
ali@38
    50
#
ali@38
    51
#   The macro supports running with and without libtool.
ali@38
    52
#
ali@38
    53
# LICENSE
ali@38
    54
#
ali@38
    55
#   Copyright (c) 2014, 2015, 2016 Philip Withnall <philip.withnall@collabora.co.uk>
ali@38
    56
#
ali@38
    57
#   Copying and distribution of this file, with or without modification, are
ali@38
    58
#   permitted in any medium without royalty provided the copyright notice
ali@38
    59
#   and this notice are preserved.  This file is offered as-is, without any
ali@38
    60
#   warranty.
ali@38
    61
ali@38
    62
#serial 9
ali@38
    63
ali@38
    64
AC_DEFUN([AX_VALGRIND_CHECK],[
ali@38
    65
	dnl Check for --enable-valgrind
ali@38
    66
	AC_ARG_ENABLE([valgrind],
ali@38
    67
	              [AS_HELP_STRING([--enable-valgrind], [Whether to enable Valgrind on the unit tests])],
ali@38
    68
	              [enable_valgrind=$enableval],[enable_valgrind=])
ali@38
    69
ali@38
    70
	AS_IF([test "$enable_valgrind" != "no"],[
ali@38
    71
		# Check for Valgrind.
ali@38
    72
		AC_CHECK_PROG([VALGRIND],[valgrind],[valgrind])
ali@38
    73
		AS_IF([test "$VALGRIND" = ""],[
ali@38
    74
			AS_IF([test "$enable_valgrind" = "yes"],[
ali@38
    75
				AC_MSG_ERROR([Could not find valgrind; either install it or reconfigure with --disable-valgrind])
ali@38
    76
			],[
ali@38
    77
				enable_valgrind=no
ali@38
    78
			])
ali@38
    79
		],[
ali@38
    80
			enable_valgrind=yes
ali@38
    81
		])
ali@38
    82
	])
ali@38
    83
ali@38
    84
	AM_CONDITIONAL([VALGRIND_ENABLED],[test "$enable_valgrind" = "yes"])
ali@38
    85
	AC_SUBST([VALGRIND_ENABLED],[$enable_valgrind])
ali@38
    86
ali@38
    87
	# Check for Valgrind tools we care about.
ali@38
    88
	m4_define([valgrind_tool_list],[[memcheck], [helgrind], [drd], [exp-sgcheck]])
ali@38
    89
ali@38
    90
	AS_IF([test "$VALGRIND" != ""],[
ali@38
    91
		m4_foreach([vgtool],[valgrind_tool_list],[
ali@38
    92
			m4_define([vgtooln],AS_TR_SH(vgtool))
ali@38
    93
			m4_define([ax_cv_var],[ax_cv_valgrind_tool_]vgtooln)
ali@38
    94
			AC_CACHE_CHECK([for Valgrind tool ]vgtool,ax_cv_var,[
ali@38
    95
				ax_cv_var=
ali@38
    96
				AS_IF([`$VALGRIND --tool=vgtool --help >/dev/null 2>&1`],[
ali@38
    97
					ax_cv_var="vgtool"
ali@38
    98
				])
ali@38
    99
			])
ali@38
   100
ali@38
   101
			AC_SUBST([VALGRIND_HAVE_TOOL_]vgtooln,[$ax_cv_var])
ali@38
   102
		])
ali@38
   103
	])
ali@38
   104
ali@38
   105
[VALGRIND_CHECK_RULES='
ali@38
   106
# Valgrind check
ali@38
   107
#
ali@38
   108
# Optional:
ali@38
   109
#  - VALGRIND_SUPPRESSIONS_FILES: Space-separated list of Valgrind suppressions
ali@38
   110
#    files to load. (Default: empty)
ali@38
   111
#  - VALGRIND_FLAGS: General flags to pass to all Valgrind tools.
ali@38
   112
#    (Default: --num-callers=30)
ali@38
   113
#  - VALGRIND_$toolname_FLAGS: Flags to pass to Valgrind $toolname (one of:
ali@38
   114
#    memcheck, helgrind, drd, sgcheck). (Default: various)
ali@38
   115
ali@38
   116
# Optional variables
ali@38
   117
VALGRIND_SUPPRESSIONS ?= $(addprefix --suppressions=,$(VALGRIND_SUPPRESSIONS_FILES))
ali@38
   118
VALGRIND_FLAGS ?= --num-callers=30
ali@38
   119
VALGRIND_memcheck_FLAGS ?= --leak-check=full --show-reachable=no
ali@38
   120
VALGRIND_helgrind_FLAGS ?= --history-level=approx
ali@38
   121
VALGRIND_drd_FLAGS ?=
ali@38
   122
VALGRIND_sgcheck_FLAGS ?=
ali@38
   123
ali@38
   124
# Internal use
ali@38
   125
valgrind_tools = memcheck helgrind drd sgcheck
ali@38
   126
valgrind_log_files = $(addprefix test-suite-,$(addsuffix .log,$(valgrind_tools)))
ali@38
   127
ali@38
   128
valgrind_memcheck_flags = --tool=memcheck $(VALGRIND_memcheck_FLAGS)
ali@38
   129
valgrind_helgrind_flags = --tool=helgrind $(VALGRIND_helgrind_FLAGS)
ali@38
   130
valgrind_drd_flags = --tool=drd $(VALGRIND_drd_FLAGS)
ali@38
   131
valgrind_sgcheck_flags = --tool=exp-sgcheck $(VALGRIND_sgcheck_FLAGS)
ali@38
   132
ali@38
   133
valgrind_quiet = $(valgrind_quiet_$(V))
ali@38
   134
valgrind_quiet_ = $(valgrind_quiet_$(AM_DEFAULT_VERBOSITY))
ali@38
   135
valgrind_quiet_0 = --quiet
ali@38
   136
ali@38
   137
# Support running with and without libtool.
ali@38
   138
ifneq ($(LIBTOOL),)
ali@38
   139
valgrind_lt = $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=execute
ali@38
   140
else
ali@38
   141
valgrind_lt =
ali@38
   142
endif
ali@38
   143
ali@38
   144
# Use recursive makes in order to ignore errors during check
ali@38
   145
check-valgrind:
ali@38
   146
ifeq ($(VALGRIND_ENABLED),yes)
ali@38
   147
	-$(foreach tool,$(valgrind_tools), \
ali@38
   148
		$(if $(VALGRIND_HAVE_TOOL_$(tool))$(VALGRIND_HAVE_TOOL_exp_$(tool)), \
ali@38
   149
			$(MAKE) $(AM_MAKEFLAGS) -k check-valgrind-tool VALGRIND_TOOL=$(tool); \
ali@38
   150
		) \
ali@38
   151
	)
ali@38
   152
else
ali@38
   153
	@echo "Need to reconfigure with --enable-valgrind"
ali@38
   154
endif
ali@38
   155
ali@38
   156
# Valgrind running
ali@38
   157
VALGRIND_TESTS_ENVIRONMENT = \
ali@38
   158
	$(TESTS_ENVIRONMENT) \
ali@38
   159
	env VALGRIND=$(VALGRIND) \
ali@38
   160
	G_SLICE=always-malloc,debug-blocks \
ali@38
   161
	G_DEBUG=fatal-warnings,fatal-criticals,gc-friendly
ali@38
   162
ali@38
   163
VALGRIND_LOG_COMPILER = \
ali@38
   164
	$(valgrind_lt) \
ali@38
   165
	$(VALGRIND) $(VALGRIND_SUPPRESSIONS) --error-exitcode=1 $(VALGRIND_FLAGS)
ali@38
   166
ali@38
   167
check-valgrind-tool:
ali@38
   168
ifeq ($(VALGRIND_ENABLED),yes)
ali@38
   169
	$(MAKE) check-TESTS \
ali@38
   170
		TESTS_ENVIRONMENT="$(VALGRIND_TESTS_ENVIRONMENT)" \
ali@38
   171
		LOG_COMPILER="$(VALGRIND_LOG_COMPILER)" \
ali@38
   172
		LOG_FLAGS="$(valgrind_$(VALGRIND_TOOL)_flags)" \
ali@38
   173
		TEST_SUITE_LOG=test-suite-$(VALGRIND_TOOL).log
ali@38
   174
else
ali@38
   175
	@echo "Need to reconfigure with --enable-valgrind"
ali@38
   176
endif
ali@38
   177
ali@38
   178
check-valgrind-memcheck:
ali@38
   179
ifeq ($(VALGRIND_ENABLED),yes)
ali@38
   180
	$(MAKE) check-TESTS \
ali@38
   181
		TESTS_ENVIRONMENT="$(VALGRIND_TESTS_ENVIRONMENT)" \
ali@38
   182
		LOG_COMPILER="$(VALGRIND_LOG_COMPILER)" \
ali@38
   183
		LOG_FLAGS="$(valgrind_memcheck_flags)" \
ali@38
   184
		TEST_SUITE_LOG=test-suite-memcheck.log
ali@38
   185
else
ali@38
   186
	@echo "Need to reconfigure with --enable-valgrind"
ali@38
   187
endif
ali@38
   188
ali@38
   189
check-valgrind-helgrind:
ali@38
   190
ifeq ($(VALGRIND_ENABLED),yes)
ali@38
   191
	$(MAKE) check-TESTS \
ali@38
   192
		TESTS_ENVIRONMENT="$(VALGRIND_TESTS_ENVIRONMENT)" \
ali@38
   193
		LOG_COMPILER="$(VALGRIND_LOG_COMPILER)" \
ali@38
   194
		LOG_FLAGS="$(valgrind_helgrind_flags)" \
ali@38
   195
		TEST_SUITE_LOG=test-suite-helgrind.log
ali@38
   196
else
ali@38
   197
	@echo "Need to reconfigure with --enable-valgrind"
ali@38
   198
endif
ali@38
   199
ali@38
   200
check-valgrind-drd:
ali@38
   201
ifeq ($(VALGRIND_ENABLED),yes)
ali@38
   202
	$(MAKE) check-TESTS \
ali@38
   203
		TESTS_ENVIRONMENT="$(VALGRIND_TESTS_ENVIRONMENT)" \
ali@38
   204
		LOG_COMPILER="$(VALGRIND_LOG_COMPILER)" \
ali@38
   205
		LOG_FLAGS="$(valgrind_drd_flags)" \
ali@38
   206
		TEST_SUITE_LOG=test-suite-drd.log
ali@38
   207
else
ali@38
   208
	@echo "Need to reconfigure with --enable-valgrind"
ali@38
   209
endif
ali@38
   210
ali@38
   211
check-valgrind-sgcheck:
ali@38
   212
ifeq ($(VALGRIND_ENABLED),yes)
ali@38
   213
	$(MAKE) check-TESTS \
ali@38
   214
		TESTS_ENVIRONMENT="$(VALGRIND_TESTS_ENVIRONMENT)" \
ali@38
   215
		LOG_COMPILER="$(VALGRIND_LOG_COMPILER)" \
ali@38
   216
		LOG_FLAGS="$(valgrind_sgcheck_flags)" \
ali@38
   217
		TEST_SUITE_LOG=test-suite-sgcheck.log
ali@38
   218
else
ali@38
   219
	@echo "Need to reconfigure with --enable-valgrind"
ali@38
   220
endif
ali@38
   221
ali@38
   222
A''M_DISTCHECK_CONFIGURE_FLAGS ?=
ali@38
   223
A''M_DISTCHECK_CONFIGURE_FLAGS += --disable-valgrind
ali@38
   224
ali@38
   225
MOSTLYCLEANFILES ?=
ali@38
   226
MOSTLYCLEANFILES += $(valgrind_log_files)
ali@38
   227
ali@38
   228
.PHONY: check-valgrind check-valgrind-tool
ali@38
   229
']
ali@38
   230
ali@38
   231
	AC_SUBST([VALGRIND_CHECK_RULES])
ali@38
   232
	m4_ifdef([_AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE([VALGRIND_CHECK_RULES])])
ali@38
   233
])