3 #include "map2/map_type.h"
4 #include "cppunit/thread.h"
6 #include <cds/os/topology.h>
11 #define TEST_CASE(TAG, X) void X();
13 class Map_InsFind_int: public CppUnitMini::TestCase
16 size_t c_nThreadCount = 8; // thread count
17 size_t c_nMapSize = 5000; // map size (count of searching item)
18 size_t c_nMaxLoadFactor = 8; // maximum load factor
19 bool c_bPrintGCState = true;
21 size_t c_nCuckooInitialSize = 1024;// initial size for CuckooMap
22 size_t c_nCuckooProbesetSize = 16; // CuckooMap probeset size (only for list-based probeset)
23 size_t c_nCuckooProbesetThreshold = 0; // CUckooMap probeset threshold (o - use default)
25 size_t c_nFeldmanMap_HeadBits = 10;
26 size_t c_nFeldmanMap_ArrayBits = 4;
28 size_t c_nLoadFactor = 2; // current load factor
31 typedef size_t key_type;
32 typedef size_t value_type;
34 template <typename Iterator, typename Map>
35 static bool check_result( Iterator const& it, Map const& map )
37 return it != map.end();
39 template <typename Map>
40 static bool check_result( bool b, Map const& )
46 class Inserter: public CppUnitMini::TestThread
49 std::vector<size_t> m_arrVal;
51 virtual Inserter * clone()
53 return new Inserter( *this );
58 size_t const nThreadCount = getTest().c_nThreadCount;
59 size_t const nSize = getTest().c_nMapSize / nThreadCount + 1;
60 m_arrVal.resize( nSize );
61 size_t nItem = m_nThreadNo;
62 for ( size_t i = 0; i < nSize; nItem += nThreadCount, ++i )
64 shuffle( m_arrVal.begin(), m_arrVal.end() );
67 size_t m_nInsertSuccess;
68 size_t m_nInsertFailed;
69 size_t m_nFindSuccess;
73 Inserter( CppUnitMini::ThreadPool& pool, Map& rMap )
74 : CppUnitMini::TestThread( pool )
77 Inserter( Inserter& src )
78 : CppUnitMini::TestThread( src )
82 Map_InsFind_int& getTest()
84 return reinterpret_cast<Map_InsFind_int&>( m_Pool.m_Test );
89 cds::threading::Manager::attachThread();
92 virtual void fini() { cds::threading::Manager::detachThread() ; }
103 size_t const nArrSize = m_arrVal.size();
104 for ( size_t i = 0; i < nArrSize; ++i ) {
105 size_t const nItem = m_arrVal[i];
106 if ( check_result( rMap.insert( nItem, nItem * 8 ), rMap ))
111 for ( size_t k = 0; k <= i; ++k ) {
112 if ( check_result( rMap.contains( m_arrVal[k] ), rMap ))
124 void do_test( Map& testMap )
126 typedef Inserter<Map> InserterThread;
127 cds::OS::Timer timer;
129 CppUnitMini::ThreadPool pool( *this );
130 pool.add( new InserterThread( pool, testMap ), c_nThreadCount );
132 CPPUNIT_MSG( " Duration=" << pool.avgDuration() );
134 size_t nInsertSuccess = 0;
135 size_t nInsertFailed = 0;
136 size_t nFindSuccess = 0;
137 size_t nFindFailed = 0;
138 for ( CppUnitMini::ThreadPool::iterator it = pool.begin(); it != pool.end(); ++it ) {
139 InserterThread * pThread = static_cast<InserterThread *>( *it );
141 nInsertSuccess += pThread->m_nInsertSuccess;
142 nInsertFailed += pThread->m_nInsertFailed;
143 nFindSuccess += pThread->m_nFindSuccess;
144 nFindFailed += pThread->m_nFindFail;
147 CPPUNIT_MSG( " Totals: Ins succ=" << nInsertSuccess << " fail=" << nInsertFailed << "\n"
148 << " Find succ=" << nFindSuccess << " fail=" << nFindFailed
151 CPPUNIT_CHECK( nInsertFailed == 0 );
152 CPPUNIT_CHECK( nFindFailed == 0 );
154 check_before_cleanup( testMap );
157 additional_check( testMap );
158 print_stat( testMap );
159 additional_cleanup( testMap );
165 static_assert( (!std::is_same< typename Map::item_counter, cds::atomicity::empty_item_counter >::value),
166 "Empty item counter is not suitable for this test");
168 CPPUNIT_MSG( "Thread count: " << c_nThreadCount
169 << " map size=" << c_nMapSize
172 if ( Map::c_bLoadFactorDepended ) {
173 for ( c_nLoadFactor = 1; c_nLoadFactor <= c_nMaxLoadFactor; c_nLoadFactor *= 2 ) {
174 CPPUNIT_MSG( "Load factor=" << c_nLoadFactor );
175 Map testMap( *this );
177 if ( c_bPrintGCState )
182 Map testMap( *this );
184 if ( c_bPrintGCState )
189 void setUpParams( const CppUnitMini::TestCfg& cfg );
191 # include "map2/map_defs.h"
192 CDSUNIT_DECLARE_MichaelMap
193 CDSUNIT_DECLARE_MichaelMap_nogc
194 CDSUNIT_DECLARE_SplitList
195 CDSUNIT_DECLARE_SplitList_nogc
196 CDSUNIT_DECLARE_SkipListMap
197 CDSUNIT_DECLARE_SkipListMap_nogc
198 CDSUNIT_DECLARE_EllenBinTreeMap
199 CDSUNIT_DECLARE_BronsonAVLTreeMap
200 CDSUNIT_DECLARE_FeldmanHashMap_fixed
201 CDSUNIT_DECLARE_FeldmanHashMap_city
202 CDSUNIT_DECLARE_StripedMap
203 CDSUNIT_DECLARE_RefinableMap
204 CDSUNIT_DECLARE_CuckooMap
205 CDSUNIT_DECLARE_StdMap
206 CDSUNIT_DECLARE_StdMap_NoLock
208 CPPUNIT_TEST_SUITE(Map_InsFind_int)
209 CDSUNIT_TEST_MichaelMap
210 CDSUNIT_TEST_MichaelMap_nogc
211 CDSUNIT_TEST_SplitList
212 CDSUNIT_TEST_SplitList_nogc
213 CDSUNIT_TEST_SkipListMap
214 CDSUNIT_TEST_SkipListMap_nogc
215 CDSUNIT_TEST_EllenBinTreeMap
216 CDSUNIT_TEST_BronsonAVLTreeMap
217 CDSUNIT_TEST_FeldmanHashMap_fixed
218 CDSUNIT_TEST_FeldmanHashMap_city
219 CDSUNIT_TEST_CuckooMap
220 CDSUNIT_TEST_StripedMap
221 CDSUNIT_TEST_RefinableMap
223 CDSUNIT_TEST_StdMap_NoLock
224 CPPUNIT_TEST_SUITE_END();