]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
tests: Move mempool test out of libdbus
authorSimon McVittie <smcv@collabora.com>
Wed, 3 Jul 2019 09:58:06 +0000 (10:58 +0100)
committerSimon McVittie <smcv@collabora.com>
Wed, 3 Jul 2019 10:19:47 +0000 (11:19 +0100)
All the functions under test turn out to be DBUS_PRIVATE_EXPORT already.

Signed-off-by: Simon McVittie <smcv@collabora.com>
dbus/dbus-mempool.c
dbus/dbus-test.h
test/CMakeLists.txt
test/Makefile.am
test/internals/mempool.c [new file with mode: 0644]
test/internals/misc-internals.h

index 638799e15e5783a494cb94e93e5cbb8b1d0f36b3..83aa2722aacb1c3cd2aaa91eae5e47462010e366 100644 (file)
@@ -2,6 +2,8 @@
 /* dbus-mempool.h Memory pools
  *
  * Copyright (C) 2002, 2003  Red Hat, Inc.
+ * Copyright (C) 2003  CodeFactory AB
+ * Copyright (C) 2011-2012  Collabora Ltd.
  *
  * Licensed under the Academic Free License version 2.1
  *
@@ -448,200 +450,3 @@ _dbus_mem_pool_get_stats (DBusMemPool   *pool,
 #endif /* DBUS_ENABLE_STATS */
 
 /** @} */
-
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
-#include "dbus-test.h"
-#include <stdio.h>
-#include <time.h>
-
-static void
-time_for_size (int size)
-{
-  int i;
-  int j;
-#ifdef DBUS_ENABLE_VERBOSE_MODE
-  clock_t start;
-  clock_t end;
-#endif
-#define FREE_ARRAY_SIZE 512
-#define N_ITERATIONS FREE_ARRAY_SIZE * 512
-  void *to_free[FREE_ARRAY_SIZE];
-  DBusMemPool *pool;
-
-  _dbus_verbose ("Timings for size %d\n", size);
-  
-  _dbus_verbose (" malloc\n");
-  
-#ifdef DBUS_ENABLE_VERBOSE_MODE
-  start = clock ();
-#endif
-
-  i = 0;
-  j = 0;
-  while (i < N_ITERATIONS)
-    {
-      to_free[j] = dbus_malloc (size);
-      _dbus_assert (to_free[j] != NULL); /* in a real app of course this is wrong */
-
-      ++j;
-
-      if (j == FREE_ARRAY_SIZE)
-        {
-          j = 0;
-          while (j < FREE_ARRAY_SIZE)
-            {
-              dbus_free (to_free[j]);
-              ++j;
-            }
-
-          j = 0;
-        }
-      
-      ++i;
-    }
-
-#ifdef DBUS_ENABLE_VERBOSE_MODE
-  end = clock ();
-
-  _dbus_verbose ("  created/destroyed %d elements in %g seconds\n",
-                 N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC);
-
-
-
-  _dbus_verbose (" mempools\n");
-  
-  start = clock ();
-#endif
-
-  pool = _dbus_mem_pool_new (size, FALSE);
-  
-  i = 0;
-  j = 0;
-  while (i < N_ITERATIONS)
-    {
-      to_free[j] = _dbus_mem_pool_alloc (pool); 
-      _dbus_assert (to_free[j] != NULL);  /* in a real app of course this is wrong */
-
-      ++j;
-
-      if (j == FREE_ARRAY_SIZE)
-        {
-          j = 0;
-          while (j < FREE_ARRAY_SIZE)
-            {
-              _dbus_mem_pool_dealloc (pool, to_free[j]);
-              ++j;
-            }
-
-          j = 0;
-        }
-      
-      ++i;
-    }
-
-  _dbus_mem_pool_free (pool);
-  
-#ifdef DBUS_ENABLE_VERBOSE_MODE
-  end = clock ();
-
-  _dbus_verbose ("  created/destroyed %d elements in %g seconds\n",
-                 N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC);
-
-  _dbus_verbose (" zeroed malloc\n");
-    
-  start = clock ();
-#endif
-  
-  i = 0;
-  j = 0;
-  while (i < N_ITERATIONS)
-    {
-      to_free[j] = dbus_malloc0 (size);
-      _dbus_assert (to_free[j] != NULL); /* in a real app of course this is wrong */
-
-      ++j;
-
-      if (j == FREE_ARRAY_SIZE)
-        {
-          j = 0;
-          while (j < FREE_ARRAY_SIZE)
-            {
-              dbus_free (to_free[j]);
-              ++j;
-            }
-
-          j = 0;
-        }
-      
-      ++i;
-    }
-
-#ifdef DBUS_ENABLE_VERBOSE_MODE
-  end = clock ();
-
-  _dbus_verbose ("  created/destroyed %d elements in %g seconds\n",
-                 N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC);
-  
-  _dbus_verbose (" zeroed mempools\n");
-  
-  start = clock ();
-#endif
-
-  pool = _dbus_mem_pool_new (size, TRUE);
-  
-  i = 0;
-  j = 0;
-  while (i < N_ITERATIONS)
-    {
-      to_free[j] = _dbus_mem_pool_alloc (pool); 
-      _dbus_assert (to_free[j] != NULL);  /* in a real app of course this is wrong */
-
-      ++j;
-
-      if (j == FREE_ARRAY_SIZE)
-        {
-          j = 0;
-          while (j < FREE_ARRAY_SIZE)
-            {
-              _dbus_mem_pool_dealloc (pool, to_free[j]);
-              ++j;
-            }
-
-          j = 0;
-        }
-      
-      ++i;
-    }
-
-  _dbus_mem_pool_free (pool);
-  
-#ifdef DBUS_ENABLE_VERBOSE_MODE
-  end = clock ();
-
-  _dbus_verbose ("  created/destroyed %d elements in %g seconds\n",
-                 N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC);
-#endif
-}
-
-/**
- * @ingroup DBusMemPoolInternals
- * Unit test for DBusMemPool
- * @returns #TRUE on success.
- */
-dbus_bool_t
-_dbus_mem_pool_test (const char *test_data_dir _DBUS_GNUC_UNUSED)
-{
-  int i;
-  int element_sizes[] = { 4, 8, 16, 50, 124 };
-  
-  i = 0;
-  while (i < _DBUS_N_ELEMENTS (element_sizes))
-    {
-      time_for_size (element_sizes[i]);
-      ++i;
-    }
-  
-  return TRUE;
-}
-
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
index e3d4645e73e23768c0a56e7dff6740d47e90c0e8..dd99c9a434496e7be07beadde7137890043a6e56 100644 (file)
@@ -40,9 +40,6 @@
 DBUS_PRIVATE_EXPORT
 dbus_bool_t _dbus_marshal_test           (const char *test_data_dir);
 
-DBUS_PRIVATE_EXPORT
-dbus_bool_t _dbus_mem_pool_test          (const char *test_data_dir);
-
 DBUS_PRIVATE_EXPORT
 dbus_bool_t _dbus_keyring_test           (const char *test_data_dir);
 
index 83b161ba58eea75a9695c880a437f8814fb88b87..08e7a8b0cc607ee5f594afec833688db599c538b 100644 (file)
@@ -127,6 +127,7 @@ if(DBUS_ENABLE_EMBEDDED_TESTS)
         internals/dbus-marshal-validate-util.c
         internals/dbus-string-util.c
         internals/dbus-sysdeps-util.c
+        internals/mempool.c
         internals/misc-internals.c
         internals/misc-internals.h
         internals/sha.c
index 2819c5f9ee23591c6b64e556f9e01fed24d34b0f..28be5cddd8a426526262401bdf7a7a4e55d37a1c 100644 (file)
@@ -248,6 +248,7 @@ test_misc_internals_SOURCES = \
        internals/dbus-marshal-validate-util.c \
        internals/dbus-string-util.c \
        internals/dbus-sysdeps-util.c \
+       internals/mempool.c \
        internals/misc-internals.c \
        internals/misc-internals.h \
        internals/sha.c \
diff --git a/test/internals/mempool.c b/test/internals/mempool.c
new file mode 100644 (file)
index 0000000..53a606f
--- /dev/null
@@ -0,0 +1,223 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-mempool.h Memory pools
+ *
+ * Copyright (C) 2002, 2003  Red Hat, Inc.
+ * Copyright (C) 2003  CodeFactory AB
+ * Copyright (C) 2013  Chengwei Yang / Intel
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <config.h>
+#include "misc-internals.h"
+
+#include <stdio.h>
+#include <time.h>
+
+#include <dbus/dbus-mempool.h>
+#include <dbus/dbus-internals.h>
+
+static void
+time_for_size (int size)
+{
+  int i;
+  int j;
+#ifdef DBUS_ENABLE_VERBOSE_MODE
+  clock_t start;
+  clock_t end;
+#endif
+#define FREE_ARRAY_SIZE 512
+#define N_ITERATIONS FREE_ARRAY_SIZE * 512
+  void *to_free[FREE_ARRAY_SIZE];
+  DBusMemPool *pool;
+
+  _dbus_verbose ("Timings for size %d\n", size);
+
+  _dbus_verbose (" malloc\n");
+
+#ifdef DBUS_ENABLE_VERBOSE_MODE
+  start = clock ();
+#endif
+
+  i = 0;
+  j = 0;
+  while (i < N_ITERATIONS)
+    {
+      to_free[j] = dbus_malloc (size);
+      _dbus_assert (to_free[j] != NULL); /* in a real app of course this is wrong */
+
+      ++j;
+
+      if (j == FREE_ARRAY_SIZE)
+        {
+          j = 0;
+          while (j < FREE_ARRAY_SIZE)
+            {
+              dbus_free (to_free[j]);
+              ++j;
+            }
+
+          j = 0;
+        }
+
+      ++i;
+    }
+
+#ifdef DBUS_ENABLE_VERBOSE_MODE
+  end = clock ();
+
+  _dbus_verbose ("  created/destroyed %d elements in %g seconds\n",
+                 N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC);
+
+
+
+  _dbus_verbose (" mempools\n");
+
+  start = clock ();
+#endif
+
+  pool = _dbus_mem_pool_new (size, FALSE);
+
+  i = 0;
+  j = 0;
+  while (i < N_ITERATIONS)
+    {
+      to_free[j] = _dbus_mem_pool_alloc (pool);
+      _dbus_assert (to_free[j] != NULL);  /* in a real app of course this is wrong */
+
+      ++j;
+
+      if (j == FREE_ARRAY_SIZE)
+        {
+          j = 0;
+          while (j < FREE_ARRAY_SIZE)
+            {
+              _dbus_mem_pool_dealloc (pool, to_free[j]);
+              ++j;
+            }
+
+          j = 0;
+        }
+
+      ++i;
+    }
+
+  _dbus_mem_pool_free (pool);
+
+#ifdef DBUS_ENABLE_VERBOSE_MODE
+  end = clock ();
+
+  _dbus_verbose ("  created/destroyed %d elements in %g seconds\n",
+                 N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC);
+
+  _dbus_verbose (" zeroed malloc\n");
+
+  start = clock ();
+#endif
+
+  i = 0;
+  j = 0;
+  while (i < N_ITERATIONS)
+    {
+      to_free[j] = dbus_malloc0 (size);
+      _dbus_assert (to_free[j] != NULL); /* in a real app of course this is wrong */
+
+      ++j;
+
+      if (j == FREE_ARRAY_SIZE)
+        {
+          j = 0;
+          while (j < FREE_ARRAY_SIZE)
+            {
+              dbus_free (to_free[j]);
+              ++j;
+            }
+
+          j = 0;
+        }
+
+      ++i;
+    }
+
+#ifdef DBUS_ENABLE_VERBOSE_MODE
+  end = clock ();
+
+  _dbus_verbose ("  created/destroyed %d elements in %g seconds\n",
+                 N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC);
+
+  _dbus_verbose (" zeroed mempools\n");
+
+  start = clock ();
+#endif
+
+  pool = _dbus_mem_pool_new (size, TRUE);
+
+  i = 0;
+  j = 0;
+  while (i < N_ITERATIONS)
+    {
+      to_free[j] = _dbus_mem_pool_alloc (pool);
+      _dbus_assert (to_free[j] != NULL);  /* in a real app of course this is wrong */
+
+      ++j;
+
+      if (j == FREE_ARRAY_SIZE)
+        {
+          j = 0;
+          while (j < FREE_ARRAY_SIZE)
+            {
+              _dbus_mem_pool_dealloc (pool, to_free[j]);
+              ++j;
+            }
+
+          j = 0;
+        }
+
+      ++i;
+    }
+
+  _dbus_mem_pool_free (pool);
+
+#ifdef DBUS_ENABLE_VERBOSE_MODE
+  end = clock ();
+
+  _dbus_verbose ("  created/destroyed %d elements in %g seconds\n",
+                 N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC);
+#endif
+}
+
+/**
+ * @ingroup DBusMemPoolInternals
+ * Unit test for DBusMemPool
+ * @returns #TRUE on success.
+ */
+dbus_bool_t
+_dbus_mem_pool_test (const char *test_data_dir _DBUS_GNUC_UNUSED)
+{
+  int i;
+  int element_sizes[] = { 4, 8, 16, 50, 124 };
+
+  i = 0;
+  while (i < _DBUS_N_ELEMENTS (element_sizes))
+    {
+      time_for_size (element_sizes[i]);
+      ++i;
+    }
+
+  return TRUE;
+}
index d207ae9f382ab2c9d713674d83dfae6cc2b59459..7f4d2cdf37b772fe576bfc5983528fda6c92c3af 100644 (file)
@@ -31,6 +31,7 @@ dbus_bool_t _dbus_auth_test              (const char *test_data_dir);
 dbus_bool_t _dbus_credentials_test       (const char *test_data_dir);
 dbus_bool_t _dbus_marshal_byteswap_test  (const char *test_data_dir);
 dbus_bool_t _dbus_marshal_validate_test  (const char *test_data_dir);
+dbus_bool_t _dbus_mem_pool_test          (const char *test_data_dir);
 dbus_bool_t _dbus_string_test            (const char *test_data_dir);
 dbus_bool_t _dbus_sysdeps_test           (const char *test_data_dir);
 dbus_bool_t _dbus_sha_test               (const char *test_data_dir);