mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-01-07 00:40:16 +01:00
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
This commit is contained in:
parent
13b640544d
commit
39ef65d07d
13 changed files with 90 additions and 33 deletions
|
|
@ -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");
|
||||
|
|
|
|||
23
bus/bus.c
23
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
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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 (! (* d->func) (d->context))
|
||||
return FALSE;
|
||||
if (!have_memory)
|
||||
bus_context_quiet_log_begin (d->context);
|
||||
|
||||
if (!check_no_leftovers (d->context))
|
||||
if (! (* d->func) (d->context))
|
||||
ret = FALSE;
|
||||
|
||||
if (!have_memory)
|
||||
bus_context_quiet_log_end (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 (! (* d->func) (d->context, d->connection))
|
||||
return FALSE;
|
||||
if (!have_memory)
|
||||
bus_context_quiet_log_begin (d->context);
|
||||
|
||||
if (!check_no_leftovers (d->context))
|
||||
if (! (* d->func) (d->context, d->connection))
|
||||
ret = FALSE;
|
||||
|
||||
if (!have_memory)
|
||||
bus_context_quiet_log_end (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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 ();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue