realloc-pool unit-test
authorRobin Gareus <robin@gareus.org>
Thu, 28 Jan 2016 01:40:59 +0000 (02:40 +0100)
committerRobin Gareus <robin@gareus.org>
Mon, 22 Feb 2016 21:06:47 +0000 (22:06 +0100)
libs/pbd/pbd/reallocpool.h
libs/pbd/test/reallocpool_test.cc [new file with mode: 0644]
libs/pbd/test/reallocpool_test.h [new file with mode: 0644]
libs/pbd/wscript

index e79cf9df9e07198139633e981cfb3a4ebb734651..e02250c41913203f2b7ae9e7d5496cae574e9b09 100644 (file)
@@ -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 (file)
index 0000000..7016d05
--- /dev/null
@@ -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 (file)
index 0000000..fe1d706
--- /dev/null
@@ -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:
+};
index e533921f599a5f71695f14ba16cd409f06e2226f..18b13e3054828a9e267bda2b07dd9e159f8ace41 100644 (file)
@@ -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()