summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2017-11-14 16:06:05 +0000
committerSimon McVittie <smcv@collabora.com>2017-11-15 12:12:23 +0000
commit39ef65d07d2475c43ae6d46e251cc62010d4c27f (patch)
treeb4b9f449acfd150c1604c16f75211177aedc3bdb
parent13b640544dae99cfa851f3bbe9338ca58844aea8 (diff)
bus: Silence most log messages when testing OOM handling
In parts of the OOM testing, our logging produces multiple megabytes of output. Let's not do that. Reviewed-by: Philip Withnall <withnall@endlessm.com> Signed-off-by: Simon McVittie <smcv@collabora.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
-rw-r--r--bus/activation.c5
-rw-r--r--bus/bus.c23
-rw-r--r--bus/bus.h5
-rw-r--r--bus/dispatch.c36
-rw-r--r--bus/signals.c3
-rw-r--r--bus/test-launch-helper.c4
-rw-r--r--dbus/dbus-internals.c4
-rw-r--r--dbus/dbus-internals.h5
-rw-r--r--dbus/dbus-marshal-recursive-util.c5
-rw-r--r--dbus/dbus-object-tree.c3
-rw-r--r--dbus/dbus-spawn-test.c12
-rw-r--r--test/internals/variant.c5
-rw-r--r--test/message.c9
13 files changed, 88 insertions, 31 deletions
diff --git a/bus/activation.c b/bus/activation.c
index 2759f3957..8f3aab86e 100644
--- a/bus/activation.c
+++ b/bus/activation.c
@@ -2531,7 +2531,8 @@ typedef struct
} CheckData;
static dbus_bool_t
-check_func (void *data)
+check_func (void *data,
+ dbus_bool_t have_memory)
{
CheckData *d;
BusActivationEntry *entry;
@@ -2575,7 +2576,7 @@ do_test (const char *description, dbus_bool_t oom_test, CheckData *data)
if (oom_test)
err = !_dbus_test_oom_handling (description, check_func, data);
else
- err = !check_func (data);
+ err = !check_func (data, TRUE);
if (err)
_dbus_test_fatal ("Test failed");
diff --git a/bus/bus.c b/bus/bus.c
index f0f07f6c4..bd2ab8bda 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -74,6 +74,9 @@ struct BusContext
unsigned int keep_umask : 1;
unsigned int allow_anonymous : 1;
unsigned int systemd_activation : 1;
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+ unsigned int quiet_log : 1;
+#endif
dbus_bool_t watches_enabled;
};
@@ -1386,7 +1389,11 @@ bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char
if (!_dbus_string_append_printf_valist (&full_msg, msg, args))
goto oom_out;
- _dbus_log (severity, "%s", _dbus_string_get_const_data (&full_msg));
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+ if (severity > DBUS_SYSTEM_LOG_WARNING || !context->quiet_log)
+#endif
+ _dbus_log (severity, "%s", _dbus_string_get_const_data (&full_msg));
+
oom_out:
_dbus_string_free (&full_msg);
}
@@ -1828,3 +1835,17 @@ bus_context_check_all_watches (BusContext *context)
_dbus_server_toggle_all_watches (server, enabled);
}
}
+
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+void
+bus_context_quiet_log_begin (BusContext *context)
+{
+ context->quiet_log = TRUE;
+}
+
+void
+bus_context_quiet_log_end (BusContext *context)
+{
+ context->quiet_log = FALSE;
+}
+#endif
diff --git a/bus/bus.h b/bus/bus.h
index 2e0de8255..31af363b8 100644
--- a/bus/bus.h
+++ b/bus/bus.h
@@ -146,4 +146,9 @@ dbus_bool_t bus_context_check_security_policy (BusContext
DBusError *error);
void bus_context_check_all_watches (BusContext *context);
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+void bus_context_quiet_log_begin (BusContext *context);
+void bus_context_quiet_log_end (BusContext *context);
+#endif
+
#endif /* BUS_BUS_H */
diff --git a/bus/dispatch.c b/bus/dispatch.c
index 812c5796a..94df7d451 100644
--- a/bus/dispatch.c
+++ b/bus/dispatch.c
@@ -4371,20 +4371,28 @@ typedef struct
} Check1Data;
static dbus_bool_t
-check_oom_check1_func (void *data)
+check_oom_check1_func (void *data,
+ dbus_bool_t have_memory)
{
+ dbus_bool_t ret = TRUE;
Check1Data *d = data;
+ if (!have_memory)
+ bus_context_quiet_log_begin (d->context);
+
if (! (* d->func) (d->context))
- return FALSE;
+ ret = FALSE;
+
+ if (!have_memory)
+ bus_context_quiet_log_end (d->context);
- if (!check_no_leftovers (d->context))
+ if (ret && !check_no_leftovers (d->context))
{
_dbus_warn ("Messages were left over, should be covered by test suite");
- return FALSE;
+ ret = FALSE;
}
- return TRUE;
+ return ret;
}
static void
@@ -4754,20 +4762,28 @@ typedef struct
} Check2Data;
static dbus_bool_t
-check_oom_check2_func (void *data)
+check_oom_check2_func (void *data,
+ dbus_bool_t have_memory)
{
+ dbus_bool_t ret = TRUE;
Check2Data *d = data;
+ if (!have_memory)
+ bus_context_quiet_log_begin (d->context);
+
if (! (* d->func) (d->context, d->connection))
- return FALSE;
+ ret = FALSE;
+
+ if (!have_memory)
+ bus_context_quiet_log_end (d->context);
- if (!check_no_leftovers (d->context))
+ if (ret && !check_no_leftovers (d->context))
{
_dbus_warn ("Messages were left over, should be covered by test suite");
- return FALSE;
+ ret = FALSE;
}
- return TRUE;
+ return ret;
}
static void
diff --git a/bus/signals.c b/bus/signals.c
index b70dd353b..c9a8f4537 100644
--- a/bus/signals.c
+++ b/bus/signals.c
@@ -2245,7 +2245,8 @@ assert_large_rule (BusMatchRule *rule)
}
static dbus_bool_t
-test_parsing (void *data)
+test_parsing (void *data,
+ dbus_bool_t have_memory)
{
BusMatchRule *rule;
diff --git a/bus/test-launch-helper.c b/bus/test-launch-helper.c
index 1d1985ae9..3555958b8 100644
--- a/bus/test-launch-helper.c
+++ b/bus/test-launch-helper.c
@@ -58,7 +58,8 @@ test_post_hook (const char *name)
/* returns true if good things happen, or if we get OOM */
static dbus_bool_t
-bus_activation_helper_oom_test (void *data)
+bus_activation_helper_oom_test (void *data,
+ dbus_bool_t have_memory)
{
const char *service;
DBusError error;
@@ -68,6 +69,7 @@ bus_activation_helper_oom_test (void *data)
retval = TRUE;
dbus_error_init (&error);
+
if (!run_launch_helper (service, &error))
{
_DBUS_ASSERT_ERROR_IS_SET (&error);
diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c
index 267aef97f..a20a5395a 100644
--- a/dbus/dbus-internals.c
+++ b/dbus/dbus-internals.c
@@ -1006,7 +1006,7 @@ run_failing_each_malloc (int n_mallocs,
description, n_mallocs,
_dbus_get_fail_alloc_failures ());
- if (!(* func) (data))
+ if (!(* func) (data, FALSE))
return FALSE;
n_mallocs -= 1;
@@ -1046,7 +1046,7 @@ _dbus_test_oom_handling (const char *description,
_dbus_verbose ("Running once to count mallocs\n");
- if (!(* func) (data))
+ if (!(* func) (data, TRUE))
return FALSE;
approx_mallocs = _DBUS_INT_MAX - _dbus_get_fail_alloc_counter ();
diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h
index e7649e1df..b210d6157 100644
--- a/dbus/dbus-internals.h
+++ b/dbus/dbus-internals.h
@@ -301,7 +301,8 @@ void _dbus_set_error_valist (DBusError *error,
const char *format,
va_list args) _DBUS_GNUC_PRINTF (3, 0);
-typedef dbus_bool_t (* DBusTestMemoryFunction) (void *data);
+typedef dbus_bool_t (* DBusTestMemoryFunction) (void *data,
+ dbus_bool_t have_memory);
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
/* Memory debugging */
@@ -329,7 +330,7 @@ dbus_bool_t _dbus_test_oom_handling (const char *description,
#define _dbus_disable_mem_pools() (FALSE)
#define _dbus_get_malloc_blocks_outstanding() (0)
-#define _dbus_test_oom_handling(description, func, data) ((*func) (data))
+#define _dbus_test_oom_handling(description, func, data) ((*func) (data, TRUE))
#endif /* !DBUS_ENABLE_EMBEDDED_TESTS */
typedef void (* DBusShutdownFunction) (void *data);
diff --git a/dbus/dbus-marshal-recursive-util.c b/dbus/dbus-marshal-recursive-util.c
index a8584e2b5..e10b7a6f1 100644
--- a/dbus/dbus-marshal-recursive-util.c
+++ b/dbus/dbus-marshal-recursive-util.c
@@ -1357,7 +1357,8 @@ run_test_delete_values (NodeIterationData *nid)
}
static dbus_bool_t
-run_test_nodes_iteration (void *data)
+run_test_nodes_iteration (void *data,
+ dbus_bool_t have_memory)
{
NodeIterationData *nid = data;
DBusTypeReader reader;
@@ -1478,7 +1479,7 @@ run_test_nodes_in_one_configuration (TestTypeNode **nodes,
}
else
{
- if (!run_test_nodes_iteration (&nid))
+ if (!run_test_nodes_iteration (&nid, TRUE))
_dbus_test_fatal ("no memory");
}
diff --git a/dbus/dbus-object-tree.c b/dbus/dbus-object-tree.c
index 6ac58ef3d..498d6158b 100644
--- a/dbus/dbus-object-tree.c
+++ b/dbus/dbus-object-tree.c
@@ -1674,7 +1674,8 @@ find_subtree_registered_or_unregistered (DBusObjectTree *tree,
/* Returns TRUE if the right thing happens, but the right thing might
* be OOM. */
static dbus_bool_t
-object_tree_test_iteration (void *data)
+object_tree_test_iteration (void *data,
+ dbus_bool_t have_memory)
{
const char *path0[] = { NULL };
const char *path1[] = { "foo", NULL };
diff --git a/dbus/dbus-spawn-test.c b/dbus/dbus-spawn-test.c
index 2d9b6ec7f..6bc6f025a 100644
--- a/dbus/dbus-spawn-test.c
+++ b/dbus/dbus-spawn-test.c
@@ -54,7 +54,8 @@ get_test_exec (const char *exe,
}
static dbus_bool_t
-check_spawn_nonexistent (void *data)
+check_spawn_nonexistent (void *data,
+ dbus_bool_t have_memory)
{
static const char arg_does_not_exist[] = "/this/does/not/exist/32542sdgafgafdg";
@@ -98,7 +99,8 @@ check_spawn_nonexistent (void *data)
}
static dbus_bool_t
-check_spawn_segfault (void *data)
+check_spawn_segfault (void *data,
+ dbus_bool_t have_memory)
{
char *argv[4] = { NULL, NULL, NULL, NULL };
DBusBabysitter *sitter = NULL;
@@ -153,7 +155,8 @@ check_spawn_segfault (void *data)
}
static dbus_bool_t
-check_spawn_exit (void *data)
+check_spawn_exit (void *data,
+ dbus_bool_t have_memory)
{
char *argv[4] = { NULL, NULL, NULL, NULL };
DBusBabysitter *sitter = NULL;
@@ -204,7 +207,8 @@ check_spawn_exit (void *data)
}
static dbus_bool_t
-check_spawn_and_kill (void *data)
+check_spawn_and_kill (void *data,
+ dbus_bool_t have_memory)
{
char *argv[4] = { NULL, NULL, NULL, NULL };
DBusBabysitter *sitter = NULL;
diff --git a/test/internals/variant.c b/test/internals/variant.c
index 67b633b9b..b8249fd19 100644
--- a/test/internals/variant.c
+++ b/test/internals/variant.c
@@ -474,7 +474,8 @@ assert_message_as_expected (DBusMessage *m)
/* Return TRUE on success or OOM, as per DBusTestMemoryFunction signature */
static dbus_bool_t
-test_once (void *data)
+test_once (void *data,
+ dbus_bool_t have_memory)
{
gboolean *really_succeeded = data;
Fixture fixture = { NULL, NULL };
@@ -545,7 +546,7 @@ test_simple (void)
{
gboolean really_succeeded = FALSE;
- if (!test_once (&really_succeeded))
+ if (!test_once (&really_succeeded, TRUE))
g_error ("Test failed");
if (!really_succeeded)
diff --git a/test/message.c b/test/message.c
index 75c441e5a..7141e314a 100644
--- a/test/message.c
+++ b/test/message.c
@@ -37,7 +37,8 @@
/* Return TRUE if the right thing happens, but the right thing might include
* OOM. */
static dbus_bool_t
-test_array (void *contained_signature)
+test_array (void *contained_signature,
+ dbus_bool_t have_memory)
{
DBusMessage *m;
DBusMessageIter iter;
@@ -149,7 +150,8 @@ out:
/* Return TRUE if the right thing happens, but the right thing might include
* OOM or inability to pass fds. */
static dbus_bool_t
-test_fd (void *ignored)
+test_fd (void *ignored,
+ dbus_bool_t have_memory)
{
DBusMessage *m = NULL;
DBusPipe pipe;
@@ -182,7 +184,8 @@ out:
* Return TRUE if the right thing happens, but the right thing might include
* OOM. */
static dbus_bool_t
-test_zero_iter (void *ignored)
+test_zero_iter (void *ignored,
+ dbus_bool_t have_memory)
{
DBusMessage *m;
DBusMessageIter iter = DBUS_MESSAGE_ITER_INIT_CLOSED;