From 64ee374d0b1cb670533fbc9fb4d94a1d61f521ff Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 14 Nov 2017 16:06:05 +0000 Subject: [PATCH 09/13] 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. Signed-off-by: Simon McVittie --- bus/activation.c | 5 +++-- bus/bus.c | 23 ++++++++++++++++++++++- bus/bus.h | 5 +++++ bus/dispatch.c | 36 ++++++++++++++++++++++++++---------- bus/signals.c | 3 ++- bus/test-launch-helper.c | 4 +++- dbus/dbus-internals.c | 4 ++-- dbus/dbus-internals.h | 5 +++-- dbus/dbus-marshal-recursive-util.c | 5 +++-- dbus/dbus-object-tree.c | 3 ++- dbus/dbus-spawn-test.c | 12 ++++++++---- test/internals/variant.c | 5 +++-- test/message.c | 9 ++++++--- 13 files changed, 88 insertions(+), 31 deletions(-) diff --git a/bus/activation.c b/bus/activation.c index 2759f395..8f3aab86 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 f0f07f6c..bd2ab8bd 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 2e0de825..31af363b 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 812c5796..94df7d45 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 b70dd353..c9a8f453 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 1d1985ae..3555958b 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 267aef97..a20a5395 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 e7649e1d..b210d615 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 a8584e2b..e10b7a6f 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 6ac58ef3..498d6158 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 2d9b6ec7..6bc6f025 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 67b633b9..b8249fd1 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 75c441e5..7141e314 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; -- 2.15.0