tests: Add valgrind memcheck support

This adds the ability to build sdbusplus test cases and run them through
valgrind using the build system.

Simply run:
    `make check-valgrind`
and the test cases will be run through valgrind

NOTE: This leaves out drd, helgrind, and sgcheck support as they would
requires extensive test refactoring. We don't really use threading in
the library code anyway so they are really only useful for proving the
test cases don't have any races.

Tested:
    sdbusplus can still be built without valgrind and tests will still
    execute normally. If `./configure --enable-valgrind` is passed the
    configure script fails if valgrind is not present. Even with
    valgrind, tests are only run through valgrind with `make
    check-valgrind`. This succeeds as expected.

Change-Id: I08972feef2f32cf3ef912da4658e2d8920fb0275
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/configure.ac b/configure.ac
index 69da66f..ed927d4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -144,6 +144,15 @@
     AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
 ])
 
+# Check for valgrind
+m4_foreach([vgtool], [valgrind_tool_list],
+    [AX_VALGRIND_DFLT(vgtool, [off])])
+AX_VALGRIND_DFLT([memcheck], [on])
+AX_VALGRIND_CHECK
+AM_EXTRA_RECURSIVE_TARGETS([check-valgrind])
+m4_foreach([vgtool], [valgrind_tool_list],
+    [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)])
+
 # Code coverage
 AX_CODE_COVERAGE
 AM_EXTRA_RECURSIVE_TARGETS([check-code-coverage])
diff --git a/test/Makefile.am b/test/Makefile.am
index c0fc378..5848c67 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,3 +1,4 @@
+@VALGRIND_CHECK_RULES@
 @CODE_COVERAGE_RULES@
 
 if WANT_LIBSDBUSPLUS