]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
Add a common test_init() for GLib tests which prevents hanging forever
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 3 Feb 2015 14:45:35 +0000 (14:45 +0000)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 4 Feb 2015 17:15:36 +0000 (17:15 +0000)
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=46787
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
17 files changed:
cmake/test/CMakeLists.txt
test/Makefile.am
test/corrupt.c
test/dbus-daemon-eavesdrop.c
test/dbus-daemon.c
test/fdpass.c
test/internals/refs.c
test/internals/syslog.c
test/loopback.c
test/marshal.c
test/monitor.c
test/relay.c
test/sd-activation.c
test/syntax.c
test/test-utils-glib.c
test/test-utils-glib.h
test/uid-permissions.c

index 42c56041237ef32bcbe2112019054727050675f2..477beb40bd72ac20b4e5f38fe10714ace3c852e7 100644 (file)
@@ -77,7 +77,7 @@ if(DBUS_WITH_GLIB)
         ${CMAKE_SOURCE_DIR}/../test/test-utils-glib.h
         ${CMAKE_SOURCE_DIR}/../test/test-utils-glib.c
     )
-    target_link_libraries(dbus-testutils-glib ${DBUS_INTERNAL_LIBRARIES})
+    target_link_libraries(dbus-testutils-glib dbus-testutils ${DBUS_INTERNAL_LIBRARIES})
 
     add_definitions(
         ${GLIB2_DEFINITIONS}
index 6d721856d83733cd3307fad8f4b4e17d61149646..ca2fb9dbf96aea6c7f3fb41f45894da25e852223 100644 (file)
@@ -242,7 +242,7 @@ test_sd_activation_LDADD = \
 
 test_marshal_SOURCES = marshal.c
 test_marshal_LDADD = \
-    $(top_builddir)/dbus/libdbus-1.la \
+    $(testutils_shared_if_possible_libs) \
     $(GLIB_LIBS) \
     $(NULL)
 
@@ -257,7 +257,7 @@ test_monitor_LDADD = \
 
 test_syntax_SOURCES = syntax.c
 test_syntax_LDADD = \
-    $(top_builddir)/dbus/libdbus-1.la \
+    $(testutils_shared_if_possible_libs) \
     $(GLIB_LIBS) \
     $(NULL)
 
index b0084fd3de120e437deffc13f064dd5856f41fe0..500cbeb7b2b711c8feda09728a7bf27f7a6ed8ba 100644 (file)
@@ -31,7 +31,7 @@
 
 #include <dbus/dbus.h>
 
-#include "test-utils.h"
+#include "test-utils-glib.h"
 
 typedef struct {
     DBusError e;
@@ -379,7 +379,7 @@ int
 main (int argc,
     char **argv)
 {
-  g_test_init (&argc, &argv, NULL);
+  test_init (&argc, &argv);
 
   g_test_add ("/corrupt/tcp", Fixture, "tcp:host=127.0.0.1", setup,
       test_corrupt, teardown);
index 686ccb35fbec72d65c738661872e0fa5085be249..419857878f952627a897e9d3c7e286e0484bdac2 100644 (file)
@@ -413,8 +413,7 @@ int
 main (int argc,
     char **argv)
 {
-  g_test_init (&argc, &argv, NULL);
-  g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
+  test_init (&argc, &argv);
 
   g_test_add ("/eavedrop/match_keyword/broadcast", Fixture, NULL,
       setup, test_eavesdrop_broadcast, teardown);
index 025909046d9922fa7567a397e90ef540d5e5d58a..6b0e9b8a98521b4580a8766420e3609eb39ce0ad 100644 (file)
@@ -608,8 +608,7 @@ int
 main (int argc,
     char **argv)
 {
-  g_test_init (&argc, &argv, NULL);
-  g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
+  test_init (&argc, &argv);
 
   g_test_add ("/echo/session", Fixture, NULL, setup, test_echo, teardown);
   g_test_add ("/echo/limited", Fixture, &limited_config,
index d41dac5f02286421404b920162f55cb85bf3d3c1..d7929a8f06945a9b7e11abd50626d4c9eab8d656 100644 (file)
@@ -807,8 +807,7 @@ int
 main (int argc,
     char **argv)
 {
-  g_test_init (&argc, &argv, NULL);
-  g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
+  test_init (&argc, &argv);
 
   g_test_add ("/relay", Fixture, NULL, setup,
       test_relay, teardown);
index 85cb3bc039ef0a1597dbfe2b8250e5c9ce37cbe0..7eae44e111fcabb42e49465f4b51cd96962ee374 100644 (file)
@@ -35,7 +35,7 @@
 #include <dbus/dbus-message-internal.h>
 #include <dbus/dbus-pending-call-internal.h>
 #include <dbus/dbus-server-protected.h>
-#include "test-utils.h"
+#include "test-utils-glib.h"
 
 static void
 assert_no_error (const DBusError *e)
@@ -585,8 +585,7 @@ int
 main (int argc,
     char **argv)
 {
-  g_test_init (&argc, &argv, NULL);
-  g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
+  test_init (&argc, &argv);
 
   g_test_add ("/refs/connection", Fixture, NULL, setup_connection,
       test_connection, teardown);
index 80a0cebbd5c77584c6266ba3713a37d10c784078..805c57840149bbba4163d6a257328c3fb98dfa9e 100644 (file)
@@ -33,6 +33,8 @@
 #include <dbus/dbus.h>
 #include <dbus/dbus-sysdeps.h>
 
+#include "test-utils-glib.h"
+
 typedef struct {
     int dummy;
 } Fixture;
@@ -93,8 +95,7 @@ int
 main (int argc,
     char **argv)
 {
-  g_test_init (&argc, &argv, NULL);
-  g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
+  test_init (&argc, &argv);
 
   g_test_add ("/syslog", Fixture, NULL, setup, test_syslog, teardown);
 
index 7526d8d2517a2fbf7071bb449ee0a636dc17588b..eeb0d65d59b9a26af0ddeaad41abcb2853333ac4 100644 (file)
@@ -32,7 +32,7 @@
 
 #include <string.h>
 
-#include "test-utils.h"
+#include "test-utils-glib.h"
 
 typedef struct {
     TestMainContext *ctx;
@@ -255,8 +255,7 @@ int
 main (int argc,
     char **argv)
 {
-  g_test_init (&argc, &argv, NULL);
-  g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
+  test_init (&argc, &argv);
 
   g_test_add ("/connect/tcp", Fixture, "tcp:host=127.0.0.1", setup,
       test_connect, teardown);
index d74e7671e96b16bbb92bce8d681227aeabe50cc8..3353ec0015a31b2762f119bdfe45f67f442fccd8 100644 (file)
@@ -31,6 +31,8 @@
 
 #include <dbus/dbus.h>
 
+#include "test-utils-glib.h"
+
 typedef struct {
     DBusError e;
 } Fixture;
@@ -248,7 +250,7 @@ main (int argc,
   char *aligned_le_blob;
   char *aligned_be_blob;
 
-  g_test_init (&argc, &argv, NULL);
+  test_init (&argc, &argv);
 
   /* We have to pass in a buffer that's at least "default aligned",
    * i.e.  on GNU systems to 8 or 16.  The linker may have only given
index 8f71da507ea8a2b37048ebee78782d743f1b8ffb..32b7b5dd3b75b080037b813d1336f3be7eba31cf 100644 (file)
@@ -1461,8 +1461,7 @@ int
 main (int argc,
     char **argv)
 {
-  g_test_init (&argc, &argv, NULL);
-  g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
+  test_init (&argc, &argv);
 
   g_test_add ("/monitor/become", Fixture, &side_effects_config,
       setup, test_become_monitor, teardown);
index ecfe4c82586327d160fc3e4d1cbd2d88a78e7f1a..a6ccb412a67e42bb8a90fd23fba32547ebdfd042 100644 (file)
@@ -30,7 +30,7 @@
 
 #include <dbus/dbus.h>
 
-#include "test-utils.h"
+#include "test-utils-glib.h"
 
 /* This is basically a miniature dbus-daemon. We relay messages from the client
  * on the left to the client on the right.
@@ -313,8 +313,7 @@ int
 main (int argc,
     char **argv)
 {
-  g_test_init (&argc, &argv, NULL);
-  g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
+  test_init (&argc, &argv);
 
   g_test_add ("/connect", Fixture, NULL, setup,
       test_connect, teardown);
index 14e4ae80c89f1a8918ed1426bada75ca76cdebc7..b9ea323fe0d951b9c134d69f384566be59da9750 100644 (file)
@@ -309,8 +309,7 @@ int
 main (int argc,
     char **argv)
 {
-  g_test_init (&argc, &argv, NULL);
-  g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
+  test_init (&argc, &argv);
 
   g_test_add ("/sd-activation", Fixture, NULL,
       setup, test_activation, teardown);
index e26b3643449452ccb457a2f8451190e70d67db26..bf960c9ea4000a99232bebeedcda64ed3f6646df 100644 (file)
@@ -30,6 +30,8 @@
 
 #include <dbus/dbus.h>
 
+#include "test-utils-glib.h"
+
 typedef struct {
     DBusError e;
 } Fixture;
@@ -269,7 +271,7 @@ int
 main (int argc,
     char **argv)
 {
-  g_test_init (&argc, &argv, NULL);
+  test_init (&argc, &argv);
 
   g_test_add ("/syntax/path", Fixture, &paths, setup, test_syntax, teardown);
   g_test_add ("/syntax/interface", Fixture, &interfaces,
index 286e7a547fc1986ce1adc8142281eaa3f869a1eb..6cffcb216ff700284350e49cebbd74f2ecc9f997 100644 (file)
@@ -385,3 +385,29 @@ test_kill_pid (GPid pid)
     kill (pid, SIGTERM);
 #endif
 }
+
+static gboolean
+time_out (gpointer data)
+{
+  g_error ("timed out");
+  return FALSE;
+}
+
+void
+test_init (int *argcp, char ***argvp)
+{
+  g_test_init (argcp, argvp, NULL);
+  g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
+
+  /* Prevent tests from hanging forever. This is intended to be long enough
+   * that any reasonable regression test on any reasonable hardware would
+   * have finished. */
+#define TIMEOUT 60
+
+  g_timeout_add_seconds (TIMEOUT, time_out, NULL);
+#ifdef G_OS_UNIX
+  /* The GLib main loop might not be running (we don't use it in every
+   * test). Die with SIGALRM shortly after if necessary. */
+  alarm (TIMEOUT + 10);
+#endif
+}
index 80a7c8d43d60359ce15ea97f34b92b9121f0fc21..fd14fd1f5d56a4ede9d2a84c90385632b2da7912 100644 (file)
@@ -79,4 +79,6 @@ DBusConnection *test_connect_to_bus_as_user (TestMainContext *ctx,
 
 void test_kill_pid (GPid pid);
 
+void test_init (int *argcp, char ***argvp);
+
 #endif
index 407b530ea7d56e6cfe72a93c871ab27c1399f872..2c62185a8d9733fa17213a90515251cd53a77436 100644 (file)
@@ -186,8 +186,7 @@ int
 main (int argc,
     char **argv)
 {
-  g_test_init (&argc, &argv, NULL);
-  g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
+  test_init (&argc, &argv);
 
   g_test_add ("/uid-permissions/uae/root", Fixture, &root_ok_config,
       setup, test_uae, teardown);