diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile.am | 37 | ||||
-rw-r--r-- | test/test_valgrind.c | 48 |
3 files changed, 86 insertions, 1 deletions
@@ -1,6 +1,7 @@ *.la *.lo *.log +*.memlog *.o *.swp *.tar.xz @@ -25,3 +26,4 @@ m4/ stamp-h1 test-suite.log test_htable +test_valgrind diff --git a/Makefile.am b/Makefile.am index 2c5388b..311e933 100644 --- a/Makefile.am +++ b/Makefile.am @@ -40,6 +40,7 @@ pkgconfig_DATA = TPHONY = TESTS = +MEMTESTS = check_PROGRAMS = lib_LTLIBRARIES = noinst_LTLIBRARIES = @@ -136,12 +137,22 @@ endif # # Tests +# We add a separate "memcheck" target which runs valgrind on all tests in +# MEMTESTS. Note that we fail if _any_ leak is detected by valgrind. Thus, you +# need to have valgrind installed and libcheck running properly (without leaks) +# to make memcheck succeed. +# A separate memcheck-verify actually runs a faulty test and verifies the +# valgrind tests work properly. # if BUILD_HAVE_CHECK check_PROGRAMS += \ - test_htable + test_htable \ + test_valgrind TESTS += \ + test_htable \ + test_valgrind +MEMTESTS += \ test_htable endif @@ -161,6 +172,30 @@ test_htable_CPPFLAGS = $(test_cflags) test_htable_LDADD = $(test_libs) test_htable_LDFLAGS = $(test_lflags) +test_valgrind_SOURCES = test/test_valgrind.c $(test_sources) +test_valgrind_CPPFLAGS = $(test_cflags) +test_valgrind_LDADD = $(test_libs) +test_valgrind_LDFLAGS = $(test_lflags) + +VALGRIND = CK_FORK=no valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --leak-resolution=high --error-exitcode=1 + +# verify that test_valgrind actually leaks data +memcheck-verify: check + $(AM_V_GEN)$(VALGRIND) --log-file=/dev/null ./test_valgrind >/dev/null ; test 1 = $$? + +TPHONY += memcheck-verify + +# run memcheck tests via valgrind +memcheck: memcheck-verify + $(AM_V_GEN)for i in $(MEMTESTS) ; do \ + $(VALGRIND) --log-file=$(top_builddir)/$$i.memlog \ + $(top_builddir)/$$i >/dev/null || (echo "memcheck failed on: $$i" ; exit 1) ; \ + done + +TPHONY += memcheck memcheck-verify + +distcheck-hook: memcheck + # # Phony targets # diff --git a/test/test_valgrind.c b/test/test_valgrind.c new file mode 100644 index 0000000..18156b9 --- /dev/null +++ b/test/test_valgrind.c @@ -0,0 +1,48 @@ +/* + * TSM - Valgrind Verification + * + * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com> + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* Dummy which just leaks memory. Used to verify valgrind memcheck. */ + +#include "test_common.h" + +START_TEST(test_valgrind) +{ + void *p; + + p = malloc(0x100); + ck_assert(!!p); +} +END_TEST + +TEST_DEFINE_CASE(misc) + TEST(test_valgrind) +TEST_END_CASE + +TEST_DEFINE( + TEST_SUITE(valgrind, + TEST_CASE(misc), + TEST_END + ) +) |