From c8d8213bcd15a4f473d48ea26d0e86dec86a15c5 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 11 Jul 2018 16:41:01 +0100 Subject: [PATCH] WIP: Use AX_VALGRIND_CHECK to set up partial valgrind test coverage Signed-off-by: Simon McVittie --- README.valgrind | 38 +++++++++++++++++++++++++++++++++++++ configure.ac | 12 ++++++++++++ test/Makefile.am | 10 ++++++++++ test/dbus.supp | 39 ++++++++++++++++++++++++++++++++++++++ test/name-test/Makefile.am | 7 +++++++ 5 files changed, 106 insertions(+) create mode 100644 test/dbus.supp diff --git a/README.valgrind b/README.valgrind index c13f5304..3b945d5a 100644 --- a/README.valgrind +++ b/README.valgrind @@ -22,3 +22,41 @@ Your Valgrind log should now be free of any (spurious) libdbus-related leaks. For the curious, the DBUS_MESSAGE_CACHE=0 is required because by default, libdbus uses a recyclable pool of message structs. These help performance a bit. + +Running tests on dbus itself with Valgrind +==== + +You need debug symbols available for at least libc and GLib, otherwise +you will get false positives. + +Make sure to configure dbus with both --enable-valgrind (to set up +Valgrind testing) and --with-valgrind (to add Valgrind instrumentation) +or you will get more false positives. This configure command line might +be useful: + + ./configure \ + --enable-asserts \ + --enable-embedded-tests \ + --enable-installed-tests \ + --enable-valgrind \ + --enable-verbose-mode \ + --with-valgrind \ + CFLAGS="-Og -g" + +When diagnosing memory leaks, it can be useful to set an environment +variable DBUS_MESSAGE_TRACE, DBUS_SERVER_TRACE, etc. to 1 according to +the type of object that was leaked (this only works when compiled with +verbose mode support, and either running under Valgrind or with +DBUS_VERBOSE=1). + +Useful valgrind options include: + + make -C test check-valgrind-memcheck-am \ + VALGRIND_FLAGS="\ + --num-callers=30 \ + --gen-suppressions=all \ + --show-leak-kinds=all \ + --leak-check=full \ + --track-origins=yes \ + --read-var-info=yes \ + " diff --git a/configure.ac b/configure.ac index 917279d3..341618f9 100644 --- a/configure.ac +++ b/configure.ac @@ -1199,6 +1199,18 @@ fi AC_SUBST([NETWORK_libs]) +# Add check-valgrind, etc. targets +AX_VALGRIND_DFLT([memcheck], [on]) +AX_VALGRIND_DFLT([helgrind], [off]) +AX_VALGRIND_DFLT([drd], [off]) +AX_VALGRIND_DFLT([sgcheck], [off]) +AX_VALGRIND_CHECK +AM_EXTRA_RECURSIVE_TARGETS([check-valgrind]) +AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-memcheck]) +AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-helgrind]) +AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-drd]) +AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-sgcheck]) + AC_ARG_WITH([valgrind], [AS_HELP_STRING([--with-valgrind], [Add instrumentation to help valgrind to understand our allocator])], diff --git a/test/Makefile.am b/test/Makefile.am index 2f338913..a2c65b8d 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -655,3 +655,13 @@ $(installable_test_meta_with_config): %_with_config.test: %$(EXEEXT) Makefile # Add rules for code-coverage testing, as defined by AX_CODE_COVERAGE @CODE_COVERAGE_RULES@ + +# Add rules for valgrind testing, as defined by AX_VALGRIND_CHECK + +# Potentially useful additions: +#VALGRIND_FLAGS = --num-callers=30 --gen-suppressions=all --read-var-info=yes +#VALGRIND_memcheck_FLAGS = --show-leak-kinds=all --errors-for-leak-kinds=definite,possible --leak-check=full + +@VALGRIND_CHECK_RULES@ +VALGRIND_SUPPRESSIONS_FILES = $(srcdir)/dbus.supp +EXTRA_DIST += dbus.supp diff --git a/test/dbus.supp b/test/dbus.supp new file mode 100644 index 00000000..0dd68afc --- /dev/null +++ b/test/dbus.supp @@ -0,0 +1,39 @@ +{ + GObject fundamental types + Memcheck:Leak + ... + fun:g_type_register_fundamental +} +{ + gobject_init + Memcheck:Leak + ... + fun:gobject_init +} +{ + GLib worker thread + Memcheck:Leak + ... + fun:g_thread_new + fun:g_get_worker_context +} +{ + GDBus worker thread + Memcheck:Leak + ... + fun:g_thread_new + ... + fun:_g_dbus_worker_new +} +{ + GObject classes + Memcheck:Leak + ... + fun:g_type_class_ref +} +{ + GObject static types + Memcheck:Leak + ... + fun:g_type_register_static +} diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am index dd7f82a8..68e6993f 100644 --- a/test/name-test/Makefile.am +++ b/test/name-test/Makefile.am @@ -89,3 +89,10 @@ test_privserver_client_LDADD=../libdbus-testutils.la test_autolaunch_LDADD=../libdbus-testutils.la endif + +# Add rules for code-coverage testing, as defined by AX_CODE_COVERAGE +@CODE_COVERAGE_RULES@ + +# Add rules for valgrind testing, as defined by AX_VALGRIND_CHECK +@VALGRIND_CHECK_RULES@ +VALGRIND_SUPPRESSIONS_FILES = $(top_srcdir)/test/dbus.supp -- 2.18.0