Merge tests' cmake and autotools bus configuration
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 26 Sep 2011 16:37:20 +0000 (17:37 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 28 Sep 2011 18:00:56 +0000 (19:00 +0100)
In Unix, the tests listened on both debug-pipe (which is a socketpair,
or a TCP emulation of socketpair on Windows) and a Unix socket.

In the Windows port, the tests were hard-coded to listen on a particular
port, which allowed the dispatch test to connect to that port, as long
as no two tests ran simultaneously (which I don't think was ever guaranteed -
make -j can violate this). That's valid out-of-process, and also
fully-specified, so they only needed one <listen> directive, so the
CMake input only had one.

To make the tests work under CMake on Unix, there was a hack: the string
substituted for the content of the <listen> directive contained
</listen><listen> to get the other address in, which is pretty nasty.

Instead of doing that, I've made both build systems, on both Unix and
Windows, use both debug-pipe and a more normal transport (Unix or TCP).
debug-pipe has a Windows implementation and it's used in
dbus-spawn-win.c, so it'd better work. The use of debug-pipe is now
hard-coded rather than being a configure parameter (there's no reason
to vary it in different builds), and I used TEST_LISTEN as the name of the
Unix/TCP address, because it's a "vague" address (no specific Unix path, no
TCP port), that you can listen on but not connect to.

This in turn means that we can merge the Autoconf .in and CMake .cmake
files, similar to Bug #41033.

You might wonder why I've kept debug-pipe. I did try to get rid of it, but
it turns out that the tests in dispatch.c rely on
dbus_connection_open_private() not blocking, and normal socket
connections block on connect(). Until we fix that by adding an async
version of dbus_connection_open_private(), it won't be safe to have a
test like dispatch.c that "talks to itself", unless it uses a transport
as trivial as debug-pipe in which neither end has to block on the other.

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=41222

13 files changed:
bus/dispatch.c
cmake/CMakeLists.txt
cmake/config.h.cmake
cmake/test/CMakeLists.txt
configure.ac
test/data/valid-config-files-system/debug-allow-all-fail.conf.cmake [deleted file]
test/data/valid-config-files-system/debug-allow-all-fail.conf.in
test/data/valid-config-files-system/debug-allow-all-pass.conf.cmake [deleted file]
test/data/valid-config-files-system/debug-allow-all-pass.conf.in
test/data/valid-config-files/debug-allow-all-sha1.conf.cmake [deleted file]
test/data/valid-config-files/debug-allow-all-sha1.conf.in
test/data/valid-config-files/debug-allow-all.conf.cmake [deleted file]
test/data/valid-config-files/debug-allow-all.conf.in

index dfe6f74..7a96f9d 100644 (file)
 #include <unistd.h>
 #endif
 
-#ifndef TEST_CONNECTION
-/*
- TODO autotools:
-  move to build system as already done for cmake
-*/
-#ifdef DBUS_UNIX
-#define TEST_CONNECTION "debug-pipe:name=test-server"
-#else
-#define TEST_CONNECTION "tcp:host=localhost,port=1234"
-#endif
-#endif
+/* This is hard-coded in the files in valid-config-files-*. We have to use
+ * the debug-pipe transport because the tests in this file require that
+ * dbus_connection_open_private() does not block. */
+#define TEST_DEBUG_PIPE "debug-pipe:name=test-server"
 
 static dbus_bool_t
 send_one_message (DBusConnection *connection,
@@ -1532,7 +1525,7 @@ check_hello_connection (BusContext *context)
 
   dbus_error_init (&error);
 
-  connection = dbus_connection_open_private (TEST_CONNECTION, &error);
+  connection = dbus_connection_open_private (TEST_DEBUG_PIPE, &error);
   if (connection == NULL)
     {
       _DBUS_ASSERT_ERROR_IS_SET (&error);
@@ -4501,7 +4494,7 @@ bus_dispatch_test_conf (const DBusString *test_data_dir,
   if (context == NULL)
     return FALSE;
 
-  foo = dbus_connection_open_private (TEST_CONNECTION, &error);
+  foo = dbus_connection_open_private (TEST_DEBUG_PIPE, &error);
   if (foo == NULL)
     _dbus_assert_not_reached ("could not alloc connection");
 
@@ -4519,7 +4512,7 @@ bus_dispatch_test_conf (const DBusString *test_data_dir,
   if (!check_add_match_all (context, foo))
     _dbus_assert_not_reached ("AddMatch message failed");
 
-  bar = dbus_connection_open_private (TEST_CONNECTION, &error);
+  bar = dbus_connection_open_private (TEST_DEBUG_PIPE, &error);
   if (bar == NULL)
     _dbus_assert_not_reached ("could not alloc connection");
 
@@ -4534,7 +4527,7 @@ bus_dispatch_test_conf (const DBusString *test_data_dir,
   if (!check_add_match_all (context, bar))
     _dbus_assert_not_reached ("AddMatch message failed");
 
-  baz = dbus_connection_open_private (TEST_CONNECTION, &error);
+  baz = dbus_connection_open_private (TEST_DEBUG_PIPE, &error);
   if (baz == NULL)
     _dbus_assert_not_reached ("could not alloc connection");
 
@@ -4650,7 +4643,7 @@ bus_dispatch_test_conf_fail (const DBusString *test_data_dir,
   if (context == NULL)
     return FALSE;
 
-  foo = dbus_connection_open_private (TEST_CONNECTION, &error);
+  foo = dbus_connection_open_private (TEST_DEBUG_PIPE, &error);
   if (foo == NULL)
     _dbus_assert_not_reached ("could not alloc connection");
 
@@ -4733,7 +4726,7 @@ bus_dispatch_sha1_test (const DBusString *test_data_dir)
   if (context == NULL)
     return FALSE;
 
-  foo = dbus_connection_open_private (TEST_CONNECTION, &error);
+  foo = dbus_connection_open_private (TEST_DEBUG_PIPE, &error);
   if (foo == NULL)
     _dbus_assert_not_reached ("could not alloc connection");
 
@@ -4782,7 +4775,7 @@ bus_unix_fds_passing_test(const DBusString *test_data_dir)
   if (context == NULL)
     _dbus_assert_not_reached ("could not alloc context");
 
-  foo = dbus_connection_open_private (TEST_CONNECTION, &error);
+  foo = dbus_connection_open_private (TEST_DEBUG_PIPE, &error);
   if (foo == NULL)
     _dbus_assert_not_reached ("could not alloc connection");
 
@@ -4797,7 +4790,7 @@ bus_unix_fds_passing_test(const DBusString *test_data_dir)
   if (!check_add_match_all (context, foo))
     _dbus_assert_not_reached ("AddMatch message failed");
 
-  bar = dbus_connection_open_private (TEST_CONNECTION, &error);
+  bar = dbus_connection_open_private (TEST_DEBUG_PIPE, &error);
   if (bar == NULL)
     _dbus_assert_not_reached ("could not alloc connection");
 
index 10fc0ee..a0f7acd 100644 (file)
@@ -478,12 +478,10 @@ if (DBUS_BUILD_TESTS)
     set(TEST_SOCKET_DIR ${DBUS_SESSION_SOCKET_DIR} )
     set(TEST_LAUNCH_HELPER_BINARY ${EXECUTABLE_OUTPUT_PATH}/dbus-daemon-launch-helper-test)
     if (UNIX)
-        set (TEST_LISTEN "debug-pipe:name=test-server</listen><listen>unix:tmpdir=${TEST_SOCKET_DIR}")
-        set (TEST_CONNECTION "debug-pipe:name=test-server")
+        set (TEST_LISTEN "unix:tmpdir=${TEST_SOCKET_DIR}")
     endif (UNIX)
     if (WIN32)
-        set (TEST_LISTEN "tcp:host=localhost,port=12436")
-        set (TEST_CONNECTION "${TEST_LISTEN}")
+        set (TEST_LISTEN "tcp:host=localhost")
     endif (WIN32)
 endif  (DBUS_BUILD_TESTS)
 
index 768bf2d..6221c19 100644 (file)
@@ -30,7 +30,6 @@
 #define VERSION DBUS_VERSION_STRING
 
 #define TEST_LISTEN       "@TEST_LISTEN@"
-#define TEST_CONNECTION   "@TEST_CONNECTION@"
 
 // test binaries
 #define DBUS_TEST_EXEC "@DBUS_TEST_EXEC@"
index 4ec702d..263a18f 100644 (file)
@@ -128,10 +128,6 @@ FOREACH(FILE_TYPE *.conf.in *.service.in)
       GET_FILENAME_COMPONENT(FILENAME ${FILE} NAME)
       STRING(REGEX REPLACE "\\.in$" "" FILENAME ${FILENAME})
       SET (TARGET ${CMAKE_BINARY_DIR}/${DIR}/${FILENAME})
-      STRING(REGEX REPLACE "\\.in$" ".cmake" _file ${FILE})
-      IF (EXISTS ${_file})
-        SET (FILE ${_file})
-      ENDIF (EXISTS ${_file})
       configure_file(${FILE} ${TARGET} @ONLY IMMEDIATE)
       IF (CONFIG_VERBOSE)
         MESSAGE("${FILE}")
index 903a513..6579534 100644 (file)
@@ -1562,6 +1562,15 @@ fi
 AC_SUBST(TEST_SOCKET_DIR)
 AC_DEFINE_UNQUOTED(DBUS_TEST_SOCKET_DIR, "$TEST_SOCKET_DIR", [Where to put test sockets])
 
+if test "x$dbus_unix" = xyes; then
+  TEST_LISTEN="unix:tmpdir=$TEST_SOCKET_DIR"
+else
+  TEST_LISTEN="tcp:host=localhost"
+fi
+AC_SUBST([TEST_LISTEN])
+AC_DEFINE_UNQUOTED([TEST_LISTEN], ["$TEST_LISTEN"],
+  [Listening address for regression tests])
+
 if ! test -z "$with_session_socket_dir" ; then
    DBUS_SESSION_SOCKET_DIR="$with_session_socket_dir"
 else
diff --git a/test/data/valid-config-files-system/debug-allow-all-fail.conf.cmake b/test/data/valid-config-files-system/debug-allow-all-fail.conf.cmake
deleted file mode 100644 (file)
index 854bfe9..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<!-- Bus that listens on a debug pipe and doesn't create any restrictions -->
-
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
-  <listen>@TEST_LISTEN@</listen>
-  <type>system</type>
-  <servicehelper>@TEST_LAUNCH_HELPER_BINARY@</servicehelper>
-  <servicedir>@DBUS_TEST_DATA@/invalid-service-files-system</servicedir>
-  <policy context="default">
-    <allow send_interface="*"/>
-    <allow receive_interface="*"/>
-    <allow own="*"/>
-    <allow user="*"/>
-  </policy>
-</busconfig>
index a61244b..bab178f 100644 (file)
@@ -4,7 +4,7 @@
  "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
 <busconfig>
   <listen>debug-pipe:name=test-server</listen>
-  <listen>unix:tmpdir=@TEST_SOCKET_DIR@</listen>
+  <listen>@TEST_LISTEN@</listen>
   <type>system</type>
   <servicehelper>@TEST_LAUNCH_HELPER_BINARY@</servicehelper>
   <servicedir>@DBUS_TEST_DATA@/invalid-service-files-system</servicedir>
diff --git a/test/data/valid-config-files-system/debug-allow-all-pass.conf.cmake b/test/data/valid-config-files-system/debug-allow-all-pass.conf.cmake
deleted file mode 100644 (file)
index 1ac5c20..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<!-- Bus that listens on a debug pipe and doesn't create any restrictions -->
-
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
-  <listen>@TEST_LISTEN@</listen>
-  <type>system</type>
-  <servicehelper>@TEST_LAUNCH_HELPER_BINARY@</servicehelper>
-  <servicedir>@DBUS_TEST_DATA@/valid-service-files-system</servicedir>
-  <policy context="default">
-    <allow send_interface="*"/>
-    <allow receive_interface="*"/>
-    <allow own="*"/>
-    <allow user="*"/>
-  </policy>
-</busconfig>
index 6105d84..3836673 100644 (file)
@@ -4,7 +4,7 @@
  "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
 <busconfig>
   <listen>debug-pipe:name=test-server</listen>
-  <listen>unix:tmpdir=@TEST_SOCKET_DIR@</listen>
+  <listen>@TEST_LISTEN@</listen>
   <type>system</type>
   <servicehelper>@TEST_LAUNCH_HELPER_BINARY@</servicehelper>
   <servicedir>@DBUS_TEST_DATA@/valid-service-files-system</servicedir>
diff --git a/test/data/valid-config-files/debug-allow-all-sha1.conf.cmake b/test/data/valid-config-files/debug-allow-all-sha1.conf.cmake
deleted file mode 100644 (file)
index 0c66f2a..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<!-- Bus that listens on a debug pipe and requires SHA1 auth, used to test SHA1 -->
-
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
-  <listen>@TEST_LISTEN@</listen>
-  <servicedir>@DBUS_TEST_DATA@/valid-service-files</servicedir>
-  <auth>DBUS_COOKIE_SHA1</auth>
-  <policy context="default">
-    <allow send_interface="*"/>
-    <allow receive_interface="*"/>
-    <allow own="*"/>
-    <allow user="*"/>
-  </policy>
-</busconfig>
index ba68f45..8baee7d 100644 (file)
@@ -4,7 +4,7 @@
  "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
 <busconfig>
   <listen>debug-pipe:name=test-server</listen>
-  <listen>unix:tmpdir=@TEST_SOCKET_DIR@</listen>
+  <listen>@TEST_LISTEN@</listen>
   <servicedir>@DBUS_TEST_DATA@/valid-service-files</servicedir>
   <auth>DBUS_COOKIE_SHA1</auth>
   <policy context="default">
diff --git a/test/data/valid-config-files/debug-allow-all.conf.cmake b/test/data/valid-config-files/debug-allow-all.conf.cmake
deleted file mode 100644 (file)
index adc3aa5..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<!-- Bus that listens on a debug pipe and doesn't create any restrictions -->
-
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
-  <listen>@TEST_LISTEN@</listen>
-  <servicedir>@DBUS_TEST_DATA@/valid-service-files</servicedir>
-  <policy context="default">
-    <allow send_interface="*"/>
-    <allow receive_interface="*"/>
-    <allow own="*"/>
-    <allow user="*"/>
-  </policy>
-</busconfig>
index a086976..00df20d 100644 (file)
@@ -4,7 +4,7 @@
  "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
 <busconfig>
   <listen>debug-pipe:name=test-server</listen>
-  <listen>unix:tmpdir=@TEST_SOCKET_DIR@</listen>
+  <listen>@TEST_LISTEN@</listen>
   <servicedir>@DBUS_TEST_DATA@/valid-service-files</servicedir>
   <policy context="default">
     <allow send_interface="*"/>