diff --git a/configure.ac b/configure.ac
index 2cdee9518b990e0329163be411d8adbafaa2daf9..bd97d74c0cc6b5de41c38930ed9248282d060faa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -278,6 +278,10 @@ DBUS_GLIB_TOOL_LIBS="$XML_LIBS"
 AC_SUBST(DBUS_GLIB_TOOL_CFLAGS)
 AC_SUBST(DBUS_GLIB_TOOL_LIBS)
 
+AC_ARG_VAR([DBUS_RUN_SESSION],
+  [The dbus-run-session tool from dbus 1.8 or later])
+AC_PATH_PROG([DBUS_RUN_SESSION], [dbus-run-session], [dbus-run-session])
+
 ### gtk-doc Documentation
 GTK_DOC_CHECK([1.14], [--flavour no-tmpl])
 
@@ -297,7 +301,6 @@ test/interfaces/Makefile
 test/data/valid-service-files/debug-glib.service
 test/data/valid-service-files/debug-echo.service
 test/data/valid-service-files/interfaces-test.service
-test/lib/Makefile
 tools/Makefile
 dbus-glib-1.pc
 dbus-glib-1-uninstalled.pc
diff --git a/dbus-gmain/Makefile.am b/dbus-gmain/Makefile.am
index 4b4291e21d6a2ab8806d1ff05307a29fd3f37028..1863a1fbc258861da131e5212b0f4d73f4375ebc 100644
--- a/dbus-gmain/Makefile.am
+++ b/dbus-gmain/Makefile.am
@@ -5,7 +5,10 @@ AM_CPPFLAGS = \
 	$(DBUS_GLIB_CFLAGS) \
 	$(NULL)
 
-noinst_LTLIBRARIES = libdbus-gmain.la
+noinst_LTLIBRARIES = \
+	libdbus-gmain.la \
+	tests/libtest.la \
+	$(NULL)
 
 libdbus_gmain_la_SOURCES = \
 	dbus-gmain.c \
@@ -14,3 +17,57 @@ libdbus_gmain_la_SOURCES = \
 
 libdbus_gmain_la_LIBADD = $(DBUS_LIBS) $(DBUS_GLIB_LIBS)
 libdbus_gmain_la_LDFLAGS = -no-undefined
+
+tests_libtest_la_SOURCES = \
+	tests/util.c \
+	tests/util.h \
+	$(NULL)
+
+tests_libtest_la_LIBADD = $(DBUS_LIBS) $(DBUS_GLIB_LIBS)
+tests_libtest_la_LDFLAGS = -no-undefined
+
+TESTS = \
+	tests/test-30574 \
+	$(NULL)
+
+noinst_PROGRAMS = \
+	tests/test-30574 \
+	tests/test-thread-server \
+	tests/test-thread-client \
+	$(NULL)
+
+tests_test_thread_server_SOURCES = \
+	tests/test-thread-server.c \
+	tests/test-thread.h \
+	$(NULL)
+tests_test_thread_server_LDADD = \
+	libdbus-gmain.la \
+	tests/libtest.la \
+	$(DBUS_GLIB_THREADS_LIBS) \
+	$(DBUS_GLIB_LIBS) \
+	$(DBUS_LIBS) \
+	$(NULL)
+
+tests_test_thread_client_SOURCES = \
+	tests/test-thread-client.c \
+	tests/test-thread.h \
+	$(NULL)
+tests_test_thread_client_LDADD = \
+	libdbus-gmain.la \
+	tests/libtest.la \
+	$(DBUS_GLIB_THREADS_LIBS) \
+	$(DBUS_GLIB_LIBS) \
+	$(DBUS_LIBS) \
+	$(NULL)
+
+tests_test_30574_SOURCES = \
+	tests/30574.c \
+	$(NULL)
+tests_test_30574_LDADD = \
+	libdbus-gmain.la \
+	tests/libtest.la \
+	$(DBUS_GLIB_LIBS) \
+	$(DBUS_LIBS) \
+	$(NULL)
+
+LOG_COMPILER = $(DBUS_RUN_SESSION) --
diff --git a/test/core/30574.c b/dbus-gmain/tests/30574.c
similarity index 99%
rename from test/core/30574.c
rename to dbus-gmain/tests/30574.c
index 6fa1c88d9606624039ac8bdce72097a7dcc7a450..3c7e10941feaabda7def49744385610b944f2cea 100644
--- a/test/core/30574.c
+++ b/dbus-gmain/tests/30574.c
@@ -5,7 +5,7 @@
 #include <dbus/dbus.h>
 #include <glib.h>
 #include <dbus-gmain/dbus-gmain.h>
-#include "test/lib/util.h"
+#include "util.h"
 
 DBusConnection *bus;
 GMainContext *main_context;
diff --git a/test/core/test-thread-client.c b/dbus-gmain/tests/test-thread-client.c
similarity index 100%
rename from test/core/test-thread-client.c
rename to dbus-gmain/tests/test-thread-client.c
diff --git a/test/core/test-thread-server.c b/dbus-gmain/tests/test-thread-server.c
similarity index 100%
rename from test/core/test-thread-server.c
rename to dbus-gmain/tests/test-thread-server.c
diff --git a/test/core/test-thread.h b/dbus-gmain/tests/test-thread.h
similarity index 100%
rename from test/core/test-thread.h
rename to dbus-gmain/tests/test-thread.h
diff --git a/test/lib/util.c b/dbus-gmain/tests/util.c
similarity index 100%
rename from test/lib/util.c
rename to dbus-gmain/tests/util.c
diff --git a/test/lib/util.h b/dbus-gmain/tests/util.h
similarity index 100%
rename from test/lib/util.h
rename to dbus-gmain/tests/util.h
diff --git a/test/Makefile.am b/test/Makefile.am
index 14c5abf4bd81ac55d62646d1bb812e2417c626eb..e538f2d3bd97e0a8b638f9c703ea63512e0376ad 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,5 +1,5 @@
-SUBDIRS = lib . core interfaces
-DIST_SUBDIRS = lib core interfaces
+SUBDIRS = . core interfaces
+DIST_SUBDIRS = core interfaces
 
 AM_CPPFLAGS = \
 	-I$(top_srcdir)				\
diff --git a/test/core/Makefile.am b/test/core/Makefile.am
index 1381e739e337188dcdfe66f27e064cf1ad13fce5..314ff401f72de79dfc3ab0b4dbe5b7bdeacfa94b 100644
--- a/test/core/Makefile.am
+++ b/test/core/Makefile.am
@@ -12,7 +12,7 @@ LDADD = \
 	$(DBUS_GLIB_LIBS) \
 	$(DBUS_LIBS) \
 	$(top_builddir)/dbus/libdbus-glib-1.la \
-	$(top_builddir)/test/lib/libtest.la \
+	$(top_builddir)/dbus-gmain/tests/libtest.la \
 	$(NULL)
 
 tool_ldadd = \
@@ -55,42 +55,17 @@ EXTRA_DIST = \
 
 if DBUS_BUILD_TESTS
 
-THREAD_APPS=test-thread-server test-thread-client test-profile
-
-test_thread_server_SOURCES=				\
-	test-thread-server.c				\
-	test-thread.h
-test_thread_server_LDADD = \
-	$(DBUS_GLIB_THREADS_LIBS) \
-	$(DBUS_GLIB_LIBS) \
-	$(DBUS_LIBS) \
-	$(top_builddir)/dbus-gmain/libdbus-gmain.la \
-	$(top_builddir)/test/lib/libtest.la \
-	$(NULL)
-
-test_thread_client_SOURCES=				\
-	test-thread-client.c				\
-	test-thread.h
-test_thread_client_LDADD = \
-	$(DBUS_GLIB_THREADS_LIBS) \
-	$(DBUS_GLIB_LIBS) \
-	$(DBUS_LIBS) \
-	$(top_builddir)/dbus-gmain/libdbus-gmain.la \
-	$(top_builddir)/test/lib/libtest.la \
-	$(NULL)
-
 ## we use noinst_PROGRAMS not check_PROGRAMS for TESTS so that we
 ## build even when not doing "make check"
 noinst_PROGRAMS = \
 	test-dbus-glib \
 	test-error-mapping \
 	test-service-glib \
-	$(THREAD_APPS) \
+	test-profile \
 	manual/test-invalid-usage \
 	peer-server \
 	peer-client \
 	test-types \
-	test-30574 \
 	test-private \
 	test-peer-on-bus \
 	test-proxy-noc \
@@ -109,15 +84,6 @@ manual_test_invalid_usage_SOURCES = \
 	my-object.h \
 	$(NULL)
 
-test_30574_SOURCES = \
-	30574.c
-test_30574_LDADD = \
-	$(DBUS_GLIB_LIBS) \
-	$(DBUS_LIBS) \
-	$(top_builddir)/dbus-gmain/libdbus-gmain.la \
-	$(top_builddir)/test/lib/libtest.la \
-	$(NULL)
-
 test_private_SOURCES = \
 	my-object.c \
 	my-object.h \
diff --git a/test/core/peer-on-bus.c b/test/core/peer-on-bus.c
index 50a15b5d4700c26dc57ddf22d5a8c9f4992f356b..a1eb231bf3aa483efc6fa29c8e49e38dd7e5eb12 100644
--- a/test/core/peer-on-bus.c
+++ b/test/core/peer-on-bus.c
@@ -40,7 +40,7 @@
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
 
-#include "test/lib/util.h"
+#include "dbus-gmain/tests/util.h"
 
 GMainLoop *loop = NULL;
 
diff --git a/test/core/registrations.c b/test/core/registrations.c
index 29afb306945b02fdc527f6afe1031a7c98ebe81e..0eea4683a13bb60837c26216d13269b28e209be0 100644
--- a/test/core/registrations.c
+++ b/test/core/registrations.c
@@ -42,7 +42,7 @@
 
 #include "my-object.h"
 
-#include "test/lib/util.h"
+#include "dbus-gmain/tests/util.h"
 
 GMainLoop *loop = NULL;
 
diff --git a/test/core/run-test.sh b/test/core/run-test.sh
index fe4dc21df6b1cd61c8bfad0bcefd26098c119425..fe0d3f8bdc485ae2453cab45058fb82e31e3469a 100755
--- a/test/core/run-test.sh
+++ b/test/core/run-test.sh
@@ -49,7 +49,6 @@ else
   ${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/core/test-dbus-glib || die "test-dbus-glib failed"
   ${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/core/test-variant-recursion || die "test-variant-recursion failed"
   ${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/core/test-gvariant || die "test-gvariant failed"
-  ${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/core/test-30574 || die "test-30574 failed"
   ${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/core/test-private || die "test-private failed"
   ${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/core/test-error-mapping || die "test-error-mapping failed"
   ${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/core/test-peer-on-bus || die "test-peer-on-bus failed"
diff --git a/test/core/test-dbus-glib.c b/test/core/test-dbus-glib.c
index cd5506e37b9b917c346918bebc9ae23f26330780..1ae2ec792b4c25dd7d9ae0bfe292d8bc605e10ad 100644
--- a/test/core/test-dbus-glib.c
+++ b/test/core/test-dbus-glib.c
@@ -38,7 +38,7 @@
 #include <glib.h>
 #include <glib-object.h>
 #include "my-object.h"
-#include "test/lib/util.h"
+#include "dbus-gmain/tests/util.h"
 
 GMainLoop *loop = NULL;
 
diff --git a/test/core/test-variant-recursion.c b/test/core/test-variant-recursion.c
index dfb8e120be8fd6f82701c7e5fc0276b4761c3346..507ea4d2be122a4fee0ca52797b6f2cb50383b1a 100644
--- a/test/core/test-variant-recursion.c
+++ b/test/core/test-variant-recursion.c
@@ -11,7 +11,7 @@
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
 
-#include "test/lib/util.h"
+#include "dbus-gmain/tests/util.h"
 
 static gboolean
 make_recursive_stringify_call (int recursion_depth, 
diff --git a/test/interfaces/Makefile.am b/test/interfaces/Makefile.am
index 6171a545e80b66a9144b1f02da2faf03dbb64f22..fa5ae33d031388b2c1c032d811a9ad5155b60f97 100644
--- a/test/interfaces/Makefile.am
+++ b/test/interfaces/Makefile.am
@@ -9,7 +9,7 @@ AM_CPPFLAGS = \
 LDADD = $(DBUS_GLIB_LIBS) \
 	$(top_builddir)/dbus/libdbus-glib-1.la \
 	$(top_builddir)/dbus/libdbus-gtool.la \
-	$(top_builddir)/test/lib/libtest.la \
+	$(top_builddir)/dbus-gmain/tests/libtest.la \
 	$(NULL)
 
 ## note that TESTS has special meaning (stuff to use in make check)
diff --git a/test/interfaces/test-client.c b/test/interfaces/test-client.c
index dcd21a5206fb0ea0c7dd4da53b262702882a1b7a..c3348e464360b51287dfa6c2730ee3e2e682114e 100644
--- a/test/interfaces/test-client.c
+++ b/test/interfaces/test-client.c
@@ -13,7 +13,7 @@
 #include "test-dup-prop-a-bindings.h"
 #include "test-dup-prop-b-bindings.h"
 
-#include "test/lib/util.h"
+#include "dbus-gmain/tests/util.h"
 
 #define TEST_NAMESPACE "org.freedesktop.DBus.GLib.Test.Interfaces"
 #define TEST_OBJECT_PATH "/org/freedesktop/DBus/GLib/Test/Interfaces"
diff --git a/test/lib/Makefile.am b/test/lib/Makefile.am
deleted file mode 100644
index 8a2670bc4ec485f87a3bc1adae3ad26eb20bca76..0000000000000000000000000000000000000000
--- a/test/lib/Makefile.am
+++ /dev/null
@@ -1,19 +0,0 @@
-AM_CPPFLAGS = \
-	-I$(top_srcdir) \
-	-I$(top_builddir) \
-	$(DBUS_CFLAGS) \
-	$(DBUS_GLIB_CFLAGS) \
-	$(NULL)
-
-noinst_LTLIBRARIES = libtest.la
-
-libtest_la_SOURCES = \
-	util.c \
-	util.h \
-	$(NULL)
-
-libtest_la_LIBADD = \
-	$(top_builddir)/dbus/libdbus-glib-1.la \
-	$(DBUS_LIBS) \
-	$(DBUS_GLIB_LIBS) \
-	$(NULL)