Splitted up map_insdel_item_int test
authorkhizmax <khizmax@gmail.com>
Fri, 27 Mar 2015 08:32:42 +0000 (11:32 +0300)
committerkhizmax <khizmax@gmail.com>
Fri, 27 Mar 2015 08:32:42 +0000 (11:32 +0300)
14 files changed:
projects/Win/vc12/unit-map-insdel.vcxproj
projects/Win/vc12/unit-map-insdel.vcxproj.filters
projects/source.unit.map.mk
tests/unit/map2/map_insdel_int.h
tests/unit/map2/map_insdel_item_int.cpp
tests/unit/map2/map_insdel_item_int.h [new file with mode: 0644]
tests/unit/map2/map_insdel_item_int_bronsonavltree.cpp [new file with mode: 0644]
tests/unit/map2/map_insdel_item_int_cuckoo.cpp [new file with mode: 0644]
tests/unit/map2/map_insdel_item_int_ellentree.cpp [new file with mode: 0644]
tests/unit/map2/map_insdel_item_int_michael.cpp [new file with mode: 0644]
tests/unit/map2/map_insdel_item_int_refinable.cpp [new file with mode: 0644]
tests/unit/map2/map_insdel_item_int_skip.cpp [new file with mode: 0644]
tests/unit/map2/map_insdel_item_int_split.cpp [new file with mode: 0644]
tests/unit/map2/map_insdel_item_int_striped.cpp [new file with mode: 0644]

index 2ce3da97a481554016e3e15f36d279145ce7908b..d55cae75bdf9a98d0639398168ced4d937e119d8 100644 (file)
     <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_int_split.cpp" />\r
     <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_int_striped.cpp" />\r
     <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int.cpp" />\r
+    <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int_bronsonavltree.cpp" />\r
+    <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int_cuckoo.cpp" />\r
+    <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int_ellentree.cpp" />\r
+    <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int_michael.cpp" />\r
+    <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int_refinable.cpp" />\r
+    <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int_skip.cpp" />\r
+    <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int_split.cpp" />\r
+    <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int_striped.cpp" />\r
     <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_string.cpp" />\r
     <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_string.cpp" />\r
     <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_string_bronsonavltree.cpp" />\r
@@ -88,6 +96,7 @@
     <ClInclude Include="..\..\..\tests\unit\map2\map_insdelfind.h" />\r
     <ClInclude Include="..\..\..\tests\unit\map2\map_insdel_func.h" />\r
     <ClInclude Include="..\..\..\tests\unit\map2\map_insdel_int.h" />\r
+    <ClInclude Include="..\..\..\tests\unit\map2\map_insdel_item_int.h" />\r
     <ClInclude Include="..\..\..\tests\unit\map2\map_insdel_string.h" />\r
   </ItemGroup>\r
   <PropertyGroup Label="Globals">\r
index a4347fb308934ce0998c2b0dc1e4d62504acdd10..4e436272fe4f5c305d1bba644b4c0b91ec5d0801 100644 (file)
     <ClCompile Include="..\..\..\tests\unit\map2\map_insdelfind_striped.cpp">\r
       <Filter>map_insdelfind</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int_bronsonavltree.cpp">\r
+      <Filter>map_insdel_item_int</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int_cuckoo.cpp">\r
+      <Filter>map_insdel_item_int</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int_ellentree.cpp">\r
+      <Filter>map_insdel_item_int</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int_michael.cpp">\r
+      <Filter>map_insdel_item_int</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int_refinable.cpp">\r
+      <Filter>map_insdel_item_int</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int_skip.cpp">\r
+      <Filter>map_insdel_item_int</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int_split.cpp">\r
+      <Filter>map_insdel_item_int</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\tests\unit\map2\map_insdel_item_int_striped.cpp">\r
+      <Filter>map_insdel_item_int</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <Filter Include="map_insdel_func">\r
     <ClInclude Include="..\..\..\tests\unit\map2\map_insdelfind.h">\r
       <Filter>map_insdelfind</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="..\..\..\tests\unit\map2\map_insdel_item_int.h">\r
+      <Filter>map_insdel_item_int</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
 </Project>
\ No newline at end of file
index 622ac5a8a32758617b7d50a709f61a687d50b339..bbc33788aff039dad20d75fa2780390daa9bbf0c 100644 (file)
@@ -50,6 +50,14 @@ CDSUNIT_MAP_SOURCES := \
     tests/unit/map2/map_insdel_int_refinable.cpp \
     tests/unit/map2/map_insdel_int_cuckoo.cpp \
     tests/unit/map2/map_insdel_item_int.cpp \
+    tests/unit/map2/map_insdel_item_int_michael.cpp \
+    tests/unit/map2/map_insdel_item_int_split.cpp \
+    tests/unit/map2/map_insdel_item_int_skip.cpp \
+    tests/unit/map2/map_insdel_item_int_ellentree.cpp \
+    tests/unit/map2/map_insdel_item_int_bronsonavltree.cpp \
+    tests/unit/map2/map_insdel_item_int_striped.cpp \
+    tests/unit/map2/map_insdel_item_int_refinable.cpp \
+    tests/unit/map2/map_insdel_item_int_cuckoo.cpp \
     tests/unit/map2/map_insdel_string.cpp \
     tests/unit/map2/map_insdel_string_michael.cpp \
     tests/unit/map2/map_insdel_string_split.cpp \
index dd1cdf03e011c7226afa3774dcc3645abf0f8cf3..c1b825dba3820bed8c3acbcf6074819599520935 100644 (file)
@@ -267,6 +267,6 @@ namespace map2 {
         CDSUNIT_DECLARE_StripedMap
         CDSUNIT_DECLARE_RefinableMap
         CDSUNIT_DECLARE_CuckooMap
-        CDSUNIT_DECLARE_StdMap
+        //CDSUNIT_DECLARE_StdMap
     };
 } // namespace map2
index ad80499c13bc36437985b6037e2df1219485bb76..cfb7d8c2b014d1b8962f87363876d0badbbf038b 100644 (file)
 //$$CDS-header$$
 
-#include "map2/map_types.h"
-#include "cppunit/thread.h"
-
-#include <vector>
-#include <algorithm>    // random_shuffle
+#include "map2/map_insdel_item_int.h"
 
 namespace map2 {
+    CPPUNIT_TEST_SUITE_REGISTRATION( Map_InsDel_Item_int );
 
-#   define TEST_MAP(X)         void X() { test<MapTypes<key_type, value_type>::X >()    ; }
-#   define TEST_MAP_NOLF(X)    void X() { test_nolf<MapTypes<key_type, value_type>::X >()    ; }
-#   define TEST_MAP_EXTRACT(X)  TEST_MAP(X)
-#   define TEST_MAP_NOLF_EXTRACT(X) TEST_MAP_NOLF(X)
+    size_t Map_InsDel_Item_int::c_nMapSize = 1000000    ;  // map size
+    size_t Map_InsDel_Item_int::c_nThreadCount = 4      ;  // thread count
+    size_t Map_InsDel_Item_int::c_nGoalItem = Map_InsDel_Item_int::c_nMapSize / 2;
+    size_t Map_InsDel_Item_int::c_nAttemptCount = 100000       ;   // count of SUCCESS insert/delete for each thread
+    size_t Map_InsDel_Item_int::c_nMaxLoadFactor = 8    ;  // maximum load factor
+    bool   Map_InsDel_Item_int::c_bPrintGCState = true;
 
-    namespace {
-        static size_t  c_nMapSize = 1000000    ;  // map size
-        static size_t  c_nThreadCount = 4      ;  // thread count
-        static size_t  c_nGoalItem = c_nMapSize / 2;
-        static size_t  c_nAttemptCount = 100000       ;   // count of SUCCESS insert/delete for each thread
-        static size_t  c_nMaxLoadFactor = 8    ;  // maximum load factor
-        static bool    c_bPrintGCState = true;
+    void Map_InsDel_Item_int::setUpParams( const CppUnitMini::TestCfg& cfg )
+    {
+        c_nThreadCount = cfg.getSizeT("ThreadCount", c_nThreadCount );
+        c_nMapSize = cfg.getSizeT("MapSize", c_nMapSize );
+        c_nGoalItem = cfg.getSizeT("GoalItem", c_nGoalItem );
+        c_nAttemptCount = cfg.getSizeT("AttemptCount", c_nAttemptCount );
+        c_nMaxLoadFactor = cfg.getSizeT("MaxLoadFactor", c_nMaxLoadFactor );
+        c_bPrintGCState = cfg.getBool("PrintGCStateFlag", true );
     }
 
-    class Map_InsDel_Item_int: public CppUnitMini::TestCase
+    void Map_InsDel_Item_int::myRun(const char *in_name, bool invert /*= false*/)
     {
-        typedef size_t  key_type;
-        typedef size_t  value_type;
-
-        template <class MAP>
-        class Inserter: public CppUnitMini::TestThread
-        {
-            MAP&     m_Map;
-
-            virtual Inserter *    clone()
-            {
-                return new Inserter( *this );
-            }
-
-            struct ensure_func
-            {
-                void operator()( bool bNew, std::pair<key_type const, value_type>& item )
-                {
-                    if ( bNew )
-                        item.second = item.first;
-                }
-                // for boost::container::flat_map
-                void operator()( bool bNew, std::pair<key_type, value_type>& item )
-                {
-                    if ( bNew )
-                        item.second = item.first;
-                }
-
-                // for BronsonAVLTreeMap
-                void operator()( bool bNew, key_type key, value_type& val )
-                {
-                    if ( bNew )
-                        val = key;
-                }
-            };
-
-        public:
-            size_t  m_nInsertSuccess;
-            size_t  m_nInsertFailed;
-
-        public:
-            Inserter( CppUnitMini::ThreadPool& pool, MAP& rMap )
-                : CppUnitMini::TestThread( pool )
-                , m_Map( rMap )
-            {}
-            Inserter( Inserter& src )
-                : CppUnitMini::TestThread( src )
-                , m_Map( src.m_Map )
-            {}
-
-            Map_InsDel_Item_int&  getTest()
-            {
-                return reinterpret_cast<Map_InsDel_Item_int&>( m_Pool.m_Test );
-            }
-
-            virtual void init() { cds::threading::Manager::attachThread()   ; }
-            virtual void fini() { cds::threading::Manager::detachThread()   ; }
-
-            virtual void test()
-            {
-                MAP& rMap = m_Map;
-
-                m_nInsertSuccess =
-                    m_nInsertFailed = 0;
-
-                size_t nGoalItem = c_nGoalItem;
-                for ( size_t nAttempt = 0; nAttempt < c_nAttemptCount; ) {
-                    if ( nAttempt % 2  == 0 ) {
-                        if ( rMap.insert( nGoalItem, nGoalItem )) {
-                            ++m_nInsertSuccess;
-                            ++nAttempt;
-                        }
-                        else
-                            ++m_nInsertFailed;
-                    }
-                    else {
-                        std::pair<bool, bool> ensureResult = rMap.ensure( nGoalItem, ensure_func() );
-                        if ( ensureResult.second ) {
-                            ++m_nInsertSuccess;
-                            ++nAttempt;
-                        }
-                        else
-                            ++m_nInsertFailed;
-                    }
-                }
-            }
-        };
-
-        template <class MAP>
-        class Deleter: public CppUnitMini::TestThread
-        {
-            MAP&     m_Map;
-
-            virtual Deleter *    clone()
-            {
-                return new Deleter( *this );
-            }
-        public:
-            size_t  m_nDeleteSuccess;
-            size_t  m_nDeleteFailed;
-
-        public:
-            Deleter( CppUnitMini::ThreadPool& pool, MAP& rMap )
-                : CppUnitMini::TestThread( pool )
-                , m_Map( rMap )
-            {}
-            Deleter( Deleter& src )
-                : CppUnitMini::TestThread( src )
-                , m_Map( src.m_Map )
-            {}
-
-            Map_InsDel_Item_int&  getTest()
-            {
-                return reinterpret_cast<Map_InsDel_Item_int&>( m_Pool.m_Test );
-            }
-
-            virtual void init() { cds::threading::Manager::attachThread()   ; }
-            virtual void fini() { cds::threading::Manager::detachThread()   ; }
-
-            virtual void test()
-            {
-                MAP& rMap = m_Map;
-
-                m_nDeleteSuccess =
-                    m_nDeleteFailed = 0;
-
-                size_t nGoalItem = c_nGoalItem;
-                for ( size_t nAttempt = 0; nAttempt < c_nAttemptCount; ) {
-                    if ( rMap.erase( nGoalItem )) {
-                        ++m_nDeleteSuccess;
-                        ++nAttempt;
-                    }
-                    else
-                        ++m_nDeleteFailed;
-                }
-            }
-        };
-
-    protected:
-
-        template <class MAP>
-        void do_test( MAP& testMap )
-        {
-            typedef Inserter<MAP>       InserterThread;
-            typedef Deleter<MAP>        DeleterThread;
-            cds::OS::Timer    timer;
-
-            // Fill the map
-            CPPUNIT_MSG( "  Fill map (" << c_nMapSize << " items)...");
-            timer.reset();
-            {
-                std::vector<key_type>   v;
-                v.reserve( c_nMapSize );
-                for ( size_t i = 0; i < c_nMapSize; ++i )
-                    v.push_back( i );
-                std::random_shuffle( v.begin(), v.end() );
-                for ( size_t i = 0; i < v.size(); ++i ) {
-                    CPPUNIT_ASSERT( testMap.insert( v[i], v[i] ));
-                }
-            }
-            CPPUNIT_MSG( "   Duration=" << timer.duration() );
-
-            CPPUNIT_MSG( "  Insert/delete the key " << c_nGoalItem << " (" << c_nAttemptCount << " successful times)...");
-            CppUnitMini::ThreadPool pool( *this );
-            pool.add( new InserterThread( pool, testMap ), (c_nThreadCount + 1) / 2 );
-            pool.add( new DeleterThread( pool, testMap ), (c_nThreadCount + 1) / 2 );
-            pool.run();
-            CPPUNIT_MSG( "   Duration=" << pool.avgDuration() );
-
-            size_t nInsertSuccess = 0;
-            size_t nInsertFailed = 0;
-            size_t nDeleteSuccess = 0;
-            size_t nDeleteFailed = 0;
-            for ( CppUnitMini::ThreadPool::iterator it = pool.begin(); it != pool.end(); ++it ) {
-                InserterThread * pThread = dynamic_cast<InserterThread *>( *it );
-                if ( pThread ) {
-                    CPPUNIT_CHECK( pThread->m_nInsertSuccess == c_nAttemptCount );
-                    nInsertSuccess += pThread->m_nInsertSuccess;
-                    nInsertFailed += pThread->m_nInsertFailed;
-                }
-                else {
-                    DeleterThread * p = static_cast<DeleterThread *>( *it );
-                    CPPUNIT_CHECK( p->m_nDeleteSuccess == c_nAttemptCount );
-                    nDeleteSuccess += p->m_nDeleteSuccess;
-                    nDeleteFailed += p->m_nDeleteFailed;
-                }
-            }
-            CPPUNIT_CHECK( nInsertSuccess == nDeleteSuccess );
-            size_t nGoalItem = c_nGoalItem;
-            CPPUNIT_CHECK( testMap.find( nGoalItem ));
-
-
-            CPPUNIT_MSG( "    Totals: Ins fail=" << nInsertFailed << " Del fail=" << nDeleteFailed );
-
-            // Check if the map contains all items
-            CPPUNIT_MSG( "    Check if the map contains all items" );
-            timer.reset();
-            for ( size_t i = 0; i < c_nMapSize; ++i ) {
-                CPPUNIT_CHECK_EX( testMap.find( i ), "key " << i );
-            }
-            CPPUNIT_MSG( "    Duration=" << timer.duration() );
-
-            check_before_cleanup( testMap );
-
-            testMap.clear();
-            additional_check( testMap );
-            print_stat( testMap );
-            additional_cleanup( testMap );
-        }
-
-        template <class MAP>
-        void test()
-        {
-            for ( size_t nLoadFactor = 1; nLoadFactor <= c_nMaxLoadFactor; nLoadFactor *= 2 ) {
-                CPPUNIT_MSG( "Load factor=" << nLoadFactor );
-                MAP testMap( c_nMapSize, nLoadFactor );
-                do_test( testMap );
-                if ( c_bPrintGCState )
-                    print_gc_state();
-            }
-        }
-
-        template <class MAP>
-        void test_nolf()
-        {
-            MAP testMap;
-            do_test<MAP>( testMap );
-            if ( c_bPrintGCState )
-                print_gc_state();
-        }
-
-        void setUpParams( const CppUnitMini::TestCfg& cfg ) {
-            c_nThreadCount = cfg.getULong("ThreadCount", 8 )        ; // thread count
-            c_nMapSize = cfg.getULong("MapSize", 1000000 );
-            c_nGoalItem = cfg.getULong("GoalItem", (unsigned long) (c_nMapSize / 2) );
-            c_nAttemptCount = cfg.getULong("AttemptCount", 100000 );
-            c_nMaxLoadFactor = cfg.getULong("MaxLoadFactor", 8 );
-            c_bPrintGCState = cfg.getBool("PrintGCStateFlag", true );
-        }
-
-#   include "map2/map_defs.h"
-        CDSUNIT_DECLARE_MichaelMap
-        CDSUNIT_DECLARE_SplitList
-        CDSUNIT_DECLARE_SkipListMap
-        CDSUNIT_DECLARE_EllenBinTreeMap
-        CDSUNIT_DECLARE_BronsonAVLTreeMap
-        CDSUNIT_DECLARE_StripedMap
-        CDSUNIT_DECLARE_RefinableMap
-        CDSUNIT_DECLARE_CuckooMap
-        CDSUNIT_DECLARE_StdMap
-
-        CPPUNIT_TEST_SUITE( Map_InsDel_Item_int )
-            CDSUNIT_TEST_MichaelMap
-            CDSUNIT_TEST_SplitList
-            CDSUNIT_TEST_SkipListMap
-            CDSUNIT_TEST_EllenBinTreeMap
-            CDSUNIT_TEST_BronsonAVLTreeMap
-            CDSUNIT_TEST_StripedMap
-            CDSUNIT_TEST_RefinableMap
-            CDSUNIT_TEST_CuckooMap
-            //CDSUNIT_TEST_StdMap       // very slow!!!
-        CPPUNIT_TEST_SUITE_END()
-
-    };
-
-    CPPUNIT_TEST_SUITE_REGISTRATION( Map_InsDel_Item_int );
+        setUpParams( m_Cfg.get( "Map_InsDel_Item_int" ));
+
+        run_MichaelMap(in_name, invert);
+        run_SplitList(in_name, invert);
+        run_SkipListMap(in_name, invert);
+        run_EllenBinTreeMap(in_name, invert);
+        run_BronsonAVLTreeMap(in_name, invert);
+        run_StripedMap(in_name, invert);
+        run_RefinableMap(in_name, invert);
+        run_CuckooMap(in_name, invert);
+
+        endTestCase();
+    }
 } // namespace map2
diff --git a/tests/unit/map2/map_insdel_item_int.h b/tests/unit/map2/map_insdel_item_int.h
new file mode 100644 (file)
index 0000000..1b4cf43
--- /dev/null
@@ -0,0 +1,281 @@
+//$$CDS-header$$
+
+#include "map2/map_types.h"
+#include "cppunit/thread.h"
+
+#include <vector>
+#include <algorithm>    // random_shuffle
+
+namespace map2 {
+
+#   define TEST_MAP(X)         void X() { test<MapTypes<key_type, value_type>::X >()    ; }
+#   define TEST_MAP_NOLF(X)    void X() { test_nolf<MapTypes<key_type, value_type>::X >()    ; }
+#   define TEST_MAP_EXTRACT(X)  TEST_MAP(X)
+#   define TEST_MAP_NOLF_EXTRACT(X) TEST_MAP_NOLF(X)
+
+    class Map_InsDel_Item_int: public CppUnitMini::TestCase
+    {
+        static size_t  c_nMapSize;        // map size
+        static size_t  c_nThreadCount;    // thread count
+        static size_t  c_nGoalItem;
+        static size_t  c_nAttemptCount;   // count of SUCCESS insert/delete for each thread
+        static size_t  c_nMaxLoadFactor;  // maximum load factor
+        static bool    c_bPrintGCState;
+
+        typedef CppUnitMini::TestCase Base;
+        typedef size_t  key_type;
+        typedef size_t  value_type;
+
+        template <class MAP>
+        class Inserter: public CppUnitMini::TestThread
+        {
+            MAP&     m_Map;
+
+            virtual Inserter *    clone()
+            {
+                return new Inserter( *this );
+            }
+
+            struct ensure_func
+            {
+                void operator()( bool bNew, std::pair<key_type const, value_type>& item )
+                {
+                    if ( bNew )
+                        item.second = item.first;
+                }
+                // for boost::container::flat_map
+                void operator()( bool bNew, std::pair<key_type, value_type>& item )
+                {
+                    if ( bNew )
+                        item.second = item.first;
+                }
+
+                // for BronsonAVLTreeMap
+                void operator()( bool bNew, key_type key, value_type& val )
+                {
+                    if ( bNew )
+                        val = key;
+                }
+            };
+
+        public:
+            size_t  m_nInsertSuccess;
+            size_t  m_nInsertFailed;
+
+        public:
+            Inserter( CppUnitMini::ThreadPool& pool, MAP& rMap )
+                : CppUnitMini::TestThread( pool )
+                , m_Map( rMap )
+            {}
+            Inserter( Inserter& src )
+                : CppUnitMini::TestThread( src )
+                , m_Map( src.m_Map )
+            {}
+
+            Map_InsDel_Item_int&  getTest()
+            {
+                return reinterpret_cast<Map_InsDel_Item_int&>( m_Pool.m_Test );
+            }
+
+            virtual void init() { cds::threading::Manager::attachThread()   ; }
+            virtual void fini() { cds::threading::Manager::detachThread()   ; }
+
+            virtual void test()
+            {
+                MAP& rMap = m_Map;
+
+                m_nInsertSuccess =
+                    m_nInsertFailed = 0;
+
+                size_t nGoalItem = c_nGoalItem;
+                for ( size_t nAttempt = 0; nAttempt < c_nAttemptCount; ) {
+                    if ( nAttempt % 2  == 0 ) {
+                        if ( rMap.insert( nGoalItem, nGoalItem )) {
+                            ++m_nInsertSuccess;
+                            ++nAttempt;
+                        }
+                        else
+                            ++m_nInsertFailed;
+                    }
+                    else {
+                        std::pair<bool, bool> ensureResult = rMap.ensure( nGoalItem, ensure_func() );
+                        if ( ensureResult.second ) {
+                            ++m_nInsertSuccess;
+                            ++nAttempt;
+                        }
+                        else
+                            ++m_nInsertFailed;
+                    }
+                }
+            }
+        };
+
+        template <class MAP>
+        class Deleter: public CppUnitMini::TestThread
+        {
+            MAP&     m_Map;
+
+            virtual Deleter *    clone()
+            {
+                return new Deleter( *this );
+            }
+        public:
+            size_t  m_nDeleteSuccess;
+            size_t  m_nDeleteFailed;
+
+        public:
+            Deleter( CppUnitMini::ThreadPool& pool, MAP& rMap )
+                : CppUnitMini::TestThread( pool )
+                , m_Map( rMap )
+            {}
+            Deleter( Deleter& src )
+                : CppUnitMini::TestThread( src )
+                , m_Map( src.m_Map )
+            {}
+
+            Map_InsDel_Item_int&  getTest()
+            {
+                return reinterpret_cast<Map_InsDel_Item_int&>( m_Pool.m_Test );
+            }
+
+            virtual void init() { cds::threading::Manager::attachThread()   ; }
+            virtual void fini() { cds::threading::Manager::detachThread()   ; }
+
+            virtual void test()
+            {
+                MAP& rMap = m_Map;
+
+                m_nDeleteSuccess =
+                    m_nDeleteFailed = 0;
+
+                size_t nGoalItem = c_nGoalItem;
+                for ( size_t nAttempt = 0; nAttempt < c_nAttemptCount; ) {
+                    if ( rMap.erase( nGoalItem )) {
+                        ++m_nDeleteSuccess;
+                        ++nAttempt;
+                    }
+                    else
+                        ++m_nDeleteFailed;
+                }
+            }
+        };
+
+    protected:
+
+        template <class MAP>
+        void do_test( MAP& testMap )
+        {
+            typedef Inserter<MAP>       InserterThread;
+            typedef Deleter<MAP>        DeleterThread;
+            cds::OS::Timer    timer;
+
+            // Fill the map
+            CPPUNIT_MSG( "  Fill map (" << c_nMapSize << " items)...");
+            timer.reset();
+            {
+                std::vector<key_type>   v;
+                v.reserve( c_nMapSize );
+                for ( size_t i = 0; i < c_nMapSize; ++i )
+                    v.push_back( i );
+                std::random_shuffle( v.begin(), v.end() );
+                for ( size_t i = 0; i < v.size(); ++i ) {
+                    CPPUNIT_ASSERT( testMap.insert( v[i], v[i] ));
+                }
+            }
+            CPPUNIT_MSG( "   Duration=" << timer.duration() );
+
+            CPPUNIT_MSG( "  Insert/delete the key " << c_nGoalItem << " (" << c_nAttemptCount << " successful times)...");
+            CppUnitMini::ThreadPool pool( *this );
+            pool.add( new InserterThread( pool, testMap ), (c_nThreadCount + 1) / 2 );
+            pool.add( new DeleterThread( pool, testMap ), (c_nThreadCount + 1) / 2 );
+            pool.run();
+            CPPUNIT_MSG( "   Duration=" << pool.avgDuration() );
+
+            size_t nInsertSuccess = 0;
+            size_t nInsertFailed = 0;
+            size_t nDeleteSuccess = 0;
+            size_t nDeleteFailed = 0;
+            for ( CppUnitMini::ThreadPool::iterator it = pool.begin(); it != pool.end(); ++it ) {
+                InserterThread * pThread = dynamic_cast<InserterThread *>( *it );
+                if ( pThread ) {
+                    CPPUNIT_CHECK( pThread->m_nInsertSuccess == c_nAttemptCount );
+                    nInsertSuccess += pThread->m_nInsertSuccess;
+                    nInsertFailed += pThread->m_nInsertFailed;
+                }
+                else {
+                    DeleterThread * p = static_cast<DeleterThread *>( *it );
+                    CPPUNIT_CHECK( p->m_nDeleteSuccess == c_nAttemptCount );
+                    nDeleteSuccess += p->m_nDeleteSuccess;
+                    nDeleteFailed += p->m_nDeleteFailed;
+                }
+            }
+            CPPUNIT_CHECK( nInsertSuccess == nDeleteSuccess );
+            size_t nGoalItem = c_nGoalItem;
+            CPPUNIT_CHECK( testMap.find( nGoalItem ));
+
+
+            CPPUNIT_MSG( "    Totals: Ins fail=" << nInsertFailed << " Del fail=" << nDeleteFailed );
+
+            // Check if the map contains all items
+            CPPUNIT_MSG( "    Check if the map contains all items" );
+            timer.reset();
+            for ( size_t i = 0; i < c_nMapSize; ++i ) {
+                CPPUNIT_CHECK_EX( testMap.find( i ), "key " << i );
+            }
+            CPPUNIT_MSG( "    Duration=" << timer.duration() );
+
+            check_before_cleanup( testMap );
+
+            testMap.clear();
+            additional_check( testMap );
+            print_stat( testMap );
+            additional_cleanup( testMap );
+        }
+
+        template <class MAP>
+        void test()
+        {
+            for ( size_t nLoadFactor = 1; nLoadFactor <= c_nMaxLoadFactor; nLoadFactor *= 2 ) {
+                CPPUNIT_MSG( "Load factor=" << nLoadFactor );
+                MAP testMap( c_nMapSize, nLoadFactor );
+                do_test( testMap );
+                if ( c_bPrintGCState )
+                    print_gc_state();
+            }
+        }
+
+        template <class MAP>
+        void test_nolf()
+        {
+            MAP testMap;
+            do_test<MAP>( testMap );
+            if ( c_bPrintGCState )
+                print_gc_state();
+        }
+
+        void setUpParams( const CppUnitMini::TestCfg& cfg );
+
+        void run_MichaelMap(const char *in_name, bool invert = false);
+        void run_SplitList(const char *in_name, bool invert = false);
+        void run_SkipListMap(const char *in_name, bool invert = false);
+        void run_StripedMap(const char *in_name, bool invert = false);
+        void run_RefinableMap(const char *in_name, bool invert = false);
+        void run_CuckooMap(const char *in_name, bool invert = false);
+        void run_EllenBinTreeMap(const char *in_name, bool invert = false);
+        void run_BronsonAVLTreeMap(const char *in_name, bool invert = false);
+
+        virtual void myRun(const char *in_name, bool invert = false);
+
+
+#   include "map2/map_defs.h"
+        CDSUNIT_DECLARE_MichaelMap
+        CDSUNIT_DECLARE_SplitList
+        CDSUNIT_DECLARE_SkipListMap
+        CDSUNIT_DECLARE_EllenBinTreeMap
+        CDSUNIT_DECLARE_BronsonAVLTreeMap
+        CDSUNIT_DECLARE_StripedMap
+        CDSUNIT_DECLARE_RefinableMap
+        CDSUNIT_DECLARE_CuckooMap
+        //CDSUNIT_DECLARE_StdMap    // very slow!
+    };
+} // namespace map2
diff --git a/tests/unit/map2/map_insdel_item_int_bronsonavltree.cpp b/tests/unit/map2/map_insdel_item_int_bronsonavltree.cpp
new file mode 100644 (file)
index 0000000..a2be151
--- /dev/null
@@ -0,0 +1,9 @@
+//$$CDS-header$$
+
+#include "map2/map_insdel_item_int.h"
+
+namespace map2 {
+    CPPUNIT_TEST_SUITE_PART( Map_InsDel_Item_int, run_BronsonAVLTreeMap )
+        CDSUNIT_TEST_BronsonAVLTreeMap
+    CPPUNIT_TEST_SUITE_END_PART()
+} // namespace map2
diff --git a/tests/unit/map2/map_insdel_item_int_cuckoo.cpp b/tests/unit/map2/map_insdel_item_int_cuckoo.cpp
new file mode 100644 (file)
index 0000000..6213c6f
--- /dev/null
@@ -0,0 +1,9 @@
+//$$CDS-header$$
+
+#include "map2/map_insdel_item_int.h"
+
+namespace map2 {
+    CPPUNIT_TEST_SUITE_PART( Map_InsDel_Item_int, run_CuckooMap )
+        CDSUNIT_TEST_CuckooMap
+    CPPUNIT_TEST_SUITE_END_PART()
+} // namespace map2
diff --git a/tests/unit/map2/map_insdel_item_int_ellentree.cpp b/tests/unit/map2/map_insdel_item_int_ellentree.cpp
new file mode 100644 (file)
index 0000000..dc810ae
--- /dev/null
@@ -0,0 +1,9 @@
+//$$CDS-header$$
+
+#include "map2/map_insdel_item_int.h"
+
+namespace map2 {
+    CPPUNIT_TEST_SUITE_PART( Map_InsDel_Item_int, run_EllenBinTreeMap )
+        CDSUNIT_TEST_EllenBinTreeMap
+    CPPUNIT_TEST_SUITE_END_PART()
+} // namespace map2
diff --git a/tests/unit/map2/map_insdel_item_int_michael.cpp b/tests/unit/map2/map_insdel_item_int_michael.cpp
new file mode 100644 (file)
index 0000000..578462f
--- /dev/null
@@ -0,0 +1,9 @@
+//$$CDS-header$$
+
+#include "map2/map_insdel_item_int.h"
+
+namespace map2 {
+    CPPUNIT_TEST_SUITE_PART( Map_InsDel_Item_int, run_MichaelMap )
+        CDSUNIT_TEST_MichaelMap
+    CPPUNIT_TEST_SUITE_END_PART()
+} // namespace map2
diff --git a/tests/unit/map2/map_insdel_item_int_refinable.cpp b/tests/unit/map2/map_insdel_item_int_refinable.cpp
new file mode 100644 (file)
index 0000000..5fc0aee
--- /dev/null
@@ -0,0 +1,9 @@
+//$$CDS-header$$
+
+#include "map2/map_insdel_item_int.h"
+
+namespace map2 {
+    CPPUNIT_TEST_SUITE_PART( Map_InsDel_Item_int, run_RefinableMap )
+        CDSUNIT_TEST_RefinableMap
+    CPPUNIT_TEST_SUITE_END_PART()
+} // namespace map2
diff --git a/tests/unit/map2/map_insdel_item_int_skip.cpp b/tests/unit/map2/map_insdel_item_int_skip.cpp
new file mode 100644 (file)
index 0000000..97bb844
--- /dev/null
@@ -0,0 +1,9 @@
+//$$CDS-header$$
+
+#include "map2/map_insdel_item_int.h"
+
+namespace map2 {
+    CPPUNIT_TEST_SUITE_PART( Map_InsDel_Item_int, run_SkipListMap )
+        CDSUNIT_TEST_SkipListMap
+    CPPUNIT_TEST_SUITE_END_PART()
+} // namespace map2
diff --git a/tests/unit/map2/map_insdel_item_int_split.cpp b/tests/unit/map2/map_insdel_item_int_split.cpp
new file mode 100644 (file)
index 0000000..8d6b5fc
--- /dev/null
@@ -0,0 +1,9 @@
+//$$CDS-header$$
+
+#include "map2/map_insdel_item_int.h"
+
+namespace map2 {
+    CPPUNIT_TEST_SUITE_PART( Map_InsDel_Item_int, run_SplitList )
+        CDSUNIT_TEST_SplitList
+    CPPUNIT_TEST_SUITE_END_PART()
+} // namespace map2
diff --git a/tests/unit/map2/map_insdel_item_int_striped.cpp b/tests/unit/map2/map_insdel_item_int_striped.cpp
new file mode 100644 (file)
index 0000000..6c7ce65
--- /dev/null
@@ -0,0 +1,9 @@
+//$$CDS-header$$
+
+#include "map2/map_insdel_item_int.h"
+
+namespace map2 {
+    CPPUNIT_TEST_SUITE_PART( Map_InsDel_Item_int, run_StripedMap )
+        CDSUNIT_TEST_StripedMap
+    CPPUNIT_TEST_SUITE_END_PART()
+} // namespace map2