From 9a843a736459818f073f320121057053c8d25d15 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 27 Sep 2017 13:14:39 +0100 Subject: [PATCH 2/2] tests: In slower tests, make the timeout per-test-case Some test-cases in the dbus-daemon and relay tests spam the bus with thousands of messages, which can take 25 seconds on slower CPUs like MIPS. Similarly, the refs test spams millions of refcount operations, which it appears might take more than a minute on PA-RISC (HPPA). To get an idea of how close we are to having a problem on other architectures, log a message and start a timer when we reset the timeout in setup(), and log the elapsed time when we reach teardown(). Signed-off-by: Simon McVittie --- test/dbus-daemon.c | 3 +++ test/internals/refs.c | 3 +++ test/relay.c | 2 ++ test/test-utils-glib.c | 41 ++++++++++++++++++++++++++++++++++++----- test/test-utils-glib.h | 2 ++ 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c index deba3b53..f9d8f923 100644 --- a/test/dbus-daemon.c +++ b/test/dbus-daemon.c @@ -158,6 +158,9 @@ setup (Fixture *f, { const Config *config = context; + /* Some tests are fairly slow, so make the test timeout per-test */ + test_timeout_reset (); + f->ctx = test_main_context_get (); f->ge = NULL; dbus_error_init (&f->e); diff --git a/test/internals/refs.c b/test/internals/refs.c index f9776378..3c6b438d 100644 --- a/test/internals/refs.c +++ b/test/internals/refs.c @@ -201,6 +201,9 @@ setup (Fixture *f, if (!dbus_threads_init_default ()) g_error ("OOM"); + /* This can be fairly slow, so make the test timeout per-test */ + test_timeout_reset (); + f->n_threads = N_THREADS; f->n_refs = N_REFS; diff --git a/test/relay.c b/test/relay.c index e275c167..d7c453ab 100644 --- a/test/relay.c +++ b/test/relay.c @@ -122,6 +122,8 @@ static void setup (Fixture *f, gconstpointer data G_GNUC_UNUSED) { + test_timeout_reset (); + f->ctx = test_main_context_get (); dbus_error_init (&f->e); g_queue_init (&f->messages); diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c index 2d005ad9..6a77a909 100644 --- a/test/test-utils-glib.c +++ b/test/test-utils-glib.c @@ -484,18 +484,20 @@ wrap_abort (int signal) } #endif -void -test_init (int *argcp, char ***argvp) +static void +set_timeout (void) { - g_test_init (argcp, argvp, NULL); - g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id="); + static guint timeout = 0; /* 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); + if (timeout != 0) + g_source_remove (timeout); + + timeout = 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. */ @@ -512,6 +514,35 @@ test_init (int *argcp, char ***argvp) #endif } +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="); + set_timeout (); +} + +static void +report_and_destroy (gpointer p) +{ + GTimer *timer = p; + + g_test_message ("Time since timeout reset %p: %.3f seconds", + timer, g_timer_elapsed (timer, NULL)); + g_timer_destroy (timer); +} + +void +test_timeout_reset (void) +{ + GTimer *timer = g_timer_new (); + + g_test_message ("Resetting test timeout (reference: %p)", timer); + set_timeout (); + + g_test_queue_destroy (report_and_destroy, timer); +} + void test_progress (char symbol) { diff --git a/test/test-utils-glib.h b/test/test-utils-glib.h index 2e1073f0..f2f167ca 100644 --- a/test/test-utils-glib.h +++ b/test/test-utils-glib.h @@ -89,4 +89,6 @@ void test_rmdir_must_exist (const gchar *path); void test_rmdir_if_exists (const gchar *path); void test_mkdir (const gchar *path, gint mode); +void test_timeout_reset (void); + #endif -- 2.14.2