summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2015-02-03 14:45:35 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2015-02-04 17:15:36 +0000
commit94610d7de6c9a00729a53c4bc9f6517c62696732 (patch)
tree5ae63202bb93d0f500b5194cd13942fc6a3e4f51
parent1a28f82926c31ae17b8688bdeb6d68f29d628592 (diff)
downloaddbus-94610d7de6c9a00729a53c4bc9f6517c62696732.tar.gz
Add a common test_init() for GLib tests which prevents hanging forever
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=46787 Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
-rw-r--r--cmake/test/CMakeLists.txt2
-rw-r--r--test/Makefile.am4
-rw-r--r--test/corrupt.c4
-rw-r--r--test/dbus-daemon-eavesdrop.c3
-rw-r--r--test/dbus-daemon.c3
-rw-r--r--test/fdpass.c3
-rw-r--r--test/internals/refs.c5
-rw-r--r--test/internals/syslog.c5
-rw-r--r--test/loopback.c5
-rw-r--r--test/marshal.c4
-rw-r--r--test/monitor.c3
-rw-r--r--test/relay.c5
-rw-r--r--test/sd-activation.c3
-rw-r--r--test/syntax.c4
-rw-r--r--test/test-utils-glib.c26
-rw-r--r--test/test-utils-glib.h2
-rw-r--r--test/uid-permissions.c3
17 files changed, 54 insertions, 30 deletions
diff --git a/cmake/test/CMakeLists.txt b/cmake/test/CMakeLists.txt
index 42c56041..477beb40 100644
--- a/cmake/test/CMakeLists.txt
+++ b/cmake/test/CMakeLists.txt
@@ -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}
diff --git a/test/Makefile.am b/test/Makefile.am
index 6d721856..ca2fb9db 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -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)
diff --git a/test/corrupt.c b/test/corrupt.c
index b0084fd3..500cbeb7 100644
--- a/test/corrupt.c
+++ b/test/corrupt.c
@@ -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);
diff --git a/test/dbus-daemon-eavesdrop.c b/test/dbus-daemon-eavesdrop.c
index 686ccb35..41985787 100644
--- a/test/dbus-daemon-eavesdrop.c
+++ b/test/dbus-daemon-eavesdrop.c
@@ -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);
diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c
index 02590904..6b0e9b8a 100644
--- a/test/dbus-daemon.c
+++ b/test/dbus-daemon.c
@@ -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,
diff --git a/test/fdpass.c b/test/fdpass.c
index d41dac5f..d7929a8f 100644
--- a/test/fdpass.c
+++ b/test/fdpass.c
@@ -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);
diff --git a/test/internals/refs.c b/test/internals/refs.c
index 85cb3bc0..7eae44e1 100644
--- a/test/internals/refs.c
+++ b/test/internals/refs.c
@@ -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);
diff --git a/test/internals/syslog.c b/test/internals/syslog.c
index 80a0cebb..805c5784 100644
--- a/test/internals/syslog.c
+++ b/test/internals/syslog.c
@@ -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);
diff --git a/test/loopback.c b/test/loopback.c
index 7526d8d2..eeb0d65d 100644
--- a/test/loopback.c
+++ b/test/loopback.c
@@ -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);
diff --git a/test/marshal.c b/test/marshal.c
index d74e7671..3353ec00 100644
--- a/test/marshal.c
+++ b/test/marshal.c
@@ -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
diff --git a/test/monitor.c b/test/monitor.c
index 8f71da50..32b7b5dd 100644
--- a/test/monitor.c
+++ b/test/monitor.c
@@ -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);
diff --git a/test/relay.c b/test/relay.c
index ecfe4c82..a6ccb412 100644
--- a/test/relay.c
+++ b/test/relay.c
@@ -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);
diff --git a/test/sd-activation.c b/test/sd-activation.c
index 14e4ae80..b9ea323f 100644
--- a/test/sd-activation.c
+++ b/test/sd-activation.c
@@ -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);
diff --git a/test/syntax.c b/test/syntax.c
index e26b3643..bf960c9e 100644
--- a/test/syntax.c
+++ b/test/syntax.c
@@ -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,
diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c
index 286e7a54..6cffcb21 100644
--- a/test/test-utils-glib.c
+++ b/test/test-utils-glib.c
@@ -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
+}
diff --git a/test/test-utils-glib.h b/test/test-utils-glib.h
index 80a7c8d4..fd14fd1f 100644
--- a/test/test-utils-glib.h
+++ b/test/test-utils-glib.h
@@ -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
diff --git a/test/uid-permissions.c b/test/uid-permissions.c
index 407b530e..2c62185a 100644
--- a/test/uid-permissions.c
+++ b/test/uid-permissions.c
@@ -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);