From d79fc96a90b8270c831ae89e076031a423993d64 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 3 Feb 2015 14:45:35 +0000 Subject: [PATCH 5/8] Add a common test_init() for GLib tests which prevents hanging forever --- test/Makefile.am | 4 ++-- test/corrupt.c | 4 ++-- test/dbus-daemon-eavesdrop.c | 3 +-- test/dbus-daemon.c | 3 +-- test/fdpass.c | 3 +-- test/internals/refs.c | 5 ++--- test/internals/syslog.c | 5 +++-- test/loopback.c | 5 ++--- test/marshal.c | 4 +++- test/monitor.c | 3 +-- test/relay.c | 5 ++--- test/sd-activation.c | 3 +-- test/syntax.c | 4 +++- test/test-utils-glib.c | 26 ++++++++++++++++++++++++++ test/test-utils-glib.h | 2 ++ test/uid-permissions.c | 3 +-- 16 files changed, 53 insertions(+), 29 deletions(-) diff --git a/test/Makefile.am b/test/Makefile.am index 6d72185..ca2fb9d 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 b0084fd..500cbeb 100644 --- a/test/corrupt.c +++ b/test/corrupt.c @@ -31,7 +31,7 @@ #include -#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 686ccb3..4198578 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 0259090..6b0e9b8 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 d41dac5..d7929a8 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 85cb3bc..7eae44e 100644 --- a/test/internals/refs.c +++ b/test/internals/refs.c @@ -35,7 +35,7 @@ #include #include #include -#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 80a0ceb..805c578 100644 --- a/test/internals/syslog.c +++ b/test/internals/syslog.c @@ -33,6 +33,8 @@ #include #include +#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 7526d8d..eeb0d65 100644 --- a/test/loopback.c +++ b/test/loopback.c @@ -32,7 +32,7 @@ #include -#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 d74e767..3353ec0 100644 --- a/test/marshal.c +++ b/test/marshal.c @@ -31,6 +31,8 @@ #include +#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 9dd3244..38f66d2 100644 --- a/test/monitor.c +++ b/test/monitor.c @@ -1439,8 +1439,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 ecfe4c8..a6ccb41 100644 --- a/test/relay.c +++ b/test/relay.c @@ -30,7 +30,7 @@ #include -#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 14e4ae8..b9ea323 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 e26b364..bf960c9 100644 --- a/test/syntax.c +++ b/test/syntax.c @@ -30,6 +30,8 @@ #include +#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 c9fb5c8..5f5d95e 100644 --- a/test/test-utils-glib.c +++ b/test/test-utils-glib.c @@ -395,3 +395,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 7b6eb74..6024a5f 100644 --- a/test/test-utils-glib.h +++ b/test/test-utils-glib.h @@ -80,4 +80,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 407b530..2c62185 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); -- 2.1.4