ax_valgrind_check
=================

Synopsis
********

     AX_VALGRIND_DFLT(memcheck|helgrind|drd|sgcheck, on|off)
     AX_VALGRIND_CHECK()

Description
***********

AX_VALGRIND_CHECK checks whether Valgrind is present and, if so, allows running `make check` under a variety of Valgrind tools to check for memory and threading errors.

Defines VALGRIND_CHECK_RULES which should be substituted in your Makefile; and $enable_valgrind which can be used in subsequent configure output. VALGRIND_ENABLED is defined and substituted, and corresponds to the value of the --enable-valgrind option, which defaults to being enabled if Valgrind is installed and disabled otherwise. Individual Valgrind tools can be disabled via --disable-valgrind-<tool>, the default is configurable via the AX_VALGRIND_DFLT command or is to use all commands not disabled via AX_VALGRIND_DFLT. All AX_VALGRIND_DFLT calls must be made before the call to AX_VALGRIND_CHECK.

If unit tests are written using a shell script and automake's LOG_COMPILER system, the $(VALGRIND) variable can be used within the shell scripts to enable Valgrind, as described here:

       https://www.gnu.org/software/gnulib/manual/html_node/Running-self_002dtests-under-valgrind.html

Usage example:

configure.ac:

       AX_VALGRIND_DFLT([sgcheck], [off])
       AX_VALGRIND_CHECK

in each Makefile.am with tests:

       @VALGRIND_CHECK_RULES@
       VALGRIND_SUPPRESSIONS_FILES = my-project.supp
       EXTRA_DIST = my-project.supp

This results in a "check-valgrind" rule being added. Running `make check-valgrind` in that directory will recursively run the module's test suite (`make check`) once for each of the available Valgrind tools (out of memcheck, helgrind and drd) while the sgcheck will be skipped unless enabled again on the commandline with --enable-valgrind-sgcheck. The results for each check will be output to test-suite-$toolname.log. The target will succeed if there are zero errors and fail otherwise.

Alternatively, a "check-valgrind-$TOOL" rule will be added, for $TOOL in memcheck, helgrind, drd and sgcheck. These are useful because often only some of those tools can be ran cleanly on a codebase.

The macro supports running with and without libtool.

Source Code
***********

Download the latest version of ax_valgrind_check.m4 (http://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=blob_plain;f=m4/ax_valgrind_check.m4) or browse the macro's revision history (http://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=history;f=m4/ax_valgrind_check.m4).

License
*******

Copyright © 2014, 2015, 2016 Philip Withnall philip.withnall@collabora.co.uk

Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved.  This file is offered as-is, without any warranty.