summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-01-28 02:40:59 +0100
committerRobin Gareus <robin@gareus.org>2016-02-22 22:06:47 +0100
commit3c87629c7e659ca5afe7d6e5961cfe834df17244 (patch)
treea76847857d5f8ffa6ebf771d05a547b27ebbd24a
parent6cf5e989c0fd5c55db5478fc6c6927bfb7d8c00d (diff)
realloc-pool unit-test
-rw-r--r--libs/pbd/pbd/reallocpool.h4
-rw-r--r--libs/pbd/test/reallocpool_test.cc40
-rw-r--r--libs/pbd/test/reallocpool_test.h16
-rw-r--r--libs/pbd/wscript1
4 files changed, 61 insertions, 0 deletions
diff --git a/libs/pbd/pbd/reallocpool.h b/libs/pbd/pbd/reallocpool.h
index e79cf9df9e..e02250c419 100644
--- a/libs/pbd/pbd/reallocpool.h
+++ b/libs/pbd/pbd/reallocpool.h
@@ -67,6 +67,10 @@ public:
void printstats ();
void dumpsegments ();
+#ifdef RAP_WITH_CALL_STATS
+ size_t mem_used () const { return _cur_used; }
+#endif
+
private:
std::string _name;
size_t _poolsize;
diff --git a/libs/pbd/test/reallocpool_test.cc b/libs/pbd/test/reallocpool_test.cc
new file mode 100644
index 0000000000..7016d05d5d
--- /dev/null
+++ b/libs/pbd/test/reallocpool_test.cc
@@ -0,0 +1,40 @@
+#include <string.h>
+#include "reallocpool_test.h"
+#include "pbd/reallocpool.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION (ReallocPoolTest);
+
+using namespace std;
+
+ReallocPoolTest::ReallocPoolTest ()
+{
+}
+
+void
+ReallocPoolTest::testBasic ()
+{
+ srand (0);
+ PBD::ReallocPool *m = new PBD::ReallocPool("TestPool", 256 * 1024);
+
+ for (int l = 0; l < 2 * 1024 * 1024; ++l) {
+ void *x[32];
+ size_t s[32];
+ int cnt = rand() % 32;
+ for (int i = 0; i < cnt; ++i) {
+ s[i] = rand() % 1024;
+ x[i] = m->malloc (s[i]);
+ }
+ for (int i = 0; i < cnt; ++i) {
+ if (x[i]) {
+ memset (x[i], 0xa5, s[i]);
+ }
+ }
+ for (int i = 0; i < cnt; ++i) {
+ m->free (x[i]);
+ }
+ }
+#ifdef RAP_WITH_CALL_STATS
+ CPPUNIT_ASSERT (m->mem_used() == 0);
+#endif
+ delete (m);
+}
diff --git a/libs/pbd/test/reallocpool_test.h b/libs/pbd/test/reallocpool_test.h
new file mode 100644
index 0000000000..fe1d706797
--- /dev/null
+++ b/libs/pbd/test/reallocpool_test.h
@@ -0,0 +1,16 @@
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include "glibmm/threads.h"
+
+class ReallocPoolTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE (ReallocPoolTest);
+ CPPUNIT_TEST (testBasic);
+ CPPUNIT_TEST_SUITE_END ();
+
+public:
+ ReallocPoolTest ();
+ void testBasic ();
+
+private:
+};
diff --git a/libs/pbd/wscript b/libs/pbd/wscript
index e533921f59..18b13e3054 100644
--- a/libs/pbd/wscript
+++ b/libs/pbd/wscript
@@ -164,6 +164,7 @@ def build(bld):
test/signals_test.cc
test/convert_test.cc
test/filesystem_test.cc
+ test/reallocpool_test.cc
test/xml_test.cc
test/test_common.cc
'''.split()