]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
bus: Silence most log messages when testing OOM handling
authorSimon McVittie <smcv@collabora.com>
Tue, 14 Nov 2017 16:06:05 +0000 (16:06 +0000)
committerSimon McVittie <smcv@collabora.com>
Wed, 15 Nov 2017 12:12:23 +0000 (12:12 +0000)
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

13 files changed:
bus/activation.c
bus/bus.c
bus/bus.h
bus/dispatch.c
bus/signals.c
bus/test-launch-helper.c
dbus/dbus-internals.c
dbus/dbus-internals.h
dbus/dbus-marshal-recursive-util.c
dbus/dbus-object-tree.c
dbus/dbus-spawn-test.c
test/internals/variant.c
test/message.c

index 2759f3957c2183291a45fa0b9a536ee101cad34f..8f3aab86e7084e9d0ac4de634c27e7894af652e6 100644 (file)
@@ -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");
index f0f07f6c4ab46e89110c7e93e449a9c13699dffd..bd2ab8bda054941b81e0a6f6ba6e936e7798734d 100644 (file)
--- 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
index 2e0de82559e2863f72eb86cb33e066014303ecaa..31af363b82e4d1f4d40f3d631445de7d62aa7b9f 100644 (file)
--- 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 */
index 812c5796a595622ad9085c0e5c9c898a76e539cb..94df7d451feea3b1c3db741d9ce7d15d4a15731d 100644 (file)
@@ -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
index b70dd353baec1111a95e6396c31420b080b9e179..c9a8f4537d83069a5cd2b2b0c060e65605f2f379 100644 (file)
@@ -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;
 
index 1d1985ae972ca5e2aa9a4f9e049c4b5dda99fa7f..3555958b800b684646a140ee85bbe1830e2ba973 100644 (file)
@@ -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);
index 267aef97f48d482cd13540bc0abf45c768adf857..a20a5395accb0623276acf5fa9decdc0b5f183d7 100644 (file)
@@ -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 ();
index e7649e1df79f2ca94ebc279d5b96f93bc0440720..b210d6157fa7c65da0bca70af559d42cd405ffd4 100644 (file)
@@ -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);
index a8584e2b5d4e02a8715b31bfaaaa9fe574fc8abf..e10b7a6f11b3e58e60962ea9d8dde4b8df7f770a 100644 (file)
@@ -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");
     }
 
index 6ac58ef3dcd609cb3082e07e9dd877549284b0e3..498d6158bdcb6c95332ea696f812beef38da6322 100644 (file)
@@ -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 };
index 2d9b6ec7fd105e85fd966176186078673249c02e..6bc6f025a81963c905ae666e500f1365c56587d1 100644 (file)
@@ -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;
index 67b633b9b4fb8f74a9b423e8172f402ae17c96c7..b8249fd1976ce73e756d38f616ec3fec48b9cb8e 100644 (file)
@@ -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)
index 75c441e5a37a835032b054abe04c884748df1ecc..7141e314ae58d1d70651736e61cf495523418c2f 100644 (file)
@@ -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;