memcheck: Add a 'make memcheck' target that runs valgrind

Checks for memory errors and leaks

https://bugzilla.gnome.org/show_bug.cgi?id=711744
This commit is contained in:
Stef Walter
2013-11-09 22:56:04 +01:00
parent fc1a1cd681
commit b9c11b1a85
4 changed files with 46 additions and 2 deletions

16
build/glib-test.supp Normal file
View File

@@ -0,0 +1,16 @@
{
glibc-tls-allocation
Memcheck:Leak
fun:calloc
fun:_dl_allocate_tls
fun:pthread_create@@GLIBC_2.2.5
...
}
{
pthread-exit
Memcheck:Leak
...
fun:pthread_exit
...
}

View File

@@ -65,6 +65,7 @@ cflags_set=${CFLAGS+set}
AM_INIT_AUTOMAKE([1.11 -Wno-portability no-define no-dist-gzip dist-xz tar-ustar]) AM_INIT_AUTOMAKE([1.11 -Wno-portability no-define no-dist-gzip dist-xz tar-ustar])
AM_MAINTAINER_MODE([enable]) AM_MAINTAINER_MODE([enable])
AM_EXTRA_RECURSIVE_TARGETS([memcheck])
# Support silent build rules. Disable # Support silent build rules. Disable
# by either passing --disable-silent-rules to configure or passing V=1 # by either passing --disable-silent-rules to configure or passing V=1

View File

@@ -1,9 +1,9 @@
# GLIB - Library of useful C routines # GLIB - Library of useful C routines
TESTS_ENVIRONMENT= \ AM_TESTS_ENVIRONMENT= \
G_TEST_SRCDIR="$(abs_srcdir)" \ G_TEST_SRCDIR="$(abs_srcdir)" \
G_TEST_BUILDDIR="$(abs_builddir)" \ G_TEST_BUILDDIR="$(abs_builddir)" \
G_DEBUG=gc-friendly \ G_DEBUG="gc-friendly cleanup" \
MALLOC_CHECK_=2 \ MALLOC_CHECK_=2 \
MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256)) MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256))
TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/tap-driver.sh TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/tap-driver.sh
@@ -132,3 +132,17 @@ installed_test_meta_DATA = $(installed_testcases:=.test)
CLEANFILES += $(installed_test_meta_DATA) CLEANFILES += $(installed_test_meta_DATA)
endif endif
VALGRIND_ARGS = \
--leak-check=full \
--show-leak-kinds=all \
--child-silent-after-fork=yes \
--suppressions=$(abs_top_srcdir)/build/glib-test.supp \
--num-callers=18 \
$(NULL)
memcheck-local: $(all_test_programs)
$(MAKE) check-am TESTS="$(all_test_programs)" \
TESTS_ENVIRONMENT="G_DEBUG='gc-friendly cleanup'" \
LOG_COMPILER="libtool --mode=execute valgrind $(VALGRIND_ARGS) --quiet --log-fd=7" \
AM_TESTS_FD_REDIRECT="7>&2"

13
glib.mk
View File

@@ -168,3 +168,16 @@ installed_test_meta_DATA = $(installed_testcases:=.test)
CLEANFILES += $(installed_test_meta_DATA) CLEANFILES += $(installed_test_meta_DATA)
endif endif
VALGRIND_ARGS = \
--leak-check=full \
--show-leak-kinds=all \
--child-silent-after-fork=yes \
--suppressions=$(abs_top_srcdir)/build/glib-test.supp \
$(NULL)
memcheck-local: $(all_test_programs)
$(MAKE) check-am TESTS="$(all_test_programs)" \
TESTS_ENVIRONMENT="G_DEBUG='gc-friendly cleanup'" \
LOG_COMPILER="libtool --mode=execute valgrind $(VALGRIND_ARGS) --quiet --log-fd=7" \
AM_TESTS_FD_REDIRECT="7>&2"