From 71bc01900f436052b81f405046f8fc69aa26973f Mon Sep 17 00:00:00 2001 From: Peizhao Ou Date: Wed, 24 Jan 2018 22:57:46 -0800 Subject: [PATCH] Removes randomness in sequential map test case --- .../insdelfind/map_insdelfind.h | 85 ++++++++----------- 1 file changed, 35 insertions(+), 50 deletions(-) diff --git a/test/stress/sequential/sequential-map/insdelfind/map_insdelfind.h b/test/stress/sequential/sequential-map/insdelfind/map_insdelfind.h index f1b03bf8..8d692766 100644 --- a/test/stress/sequential/sequential-map/insdelfind/map_insdelfind.h +++ b/test/stress/sequential/sequential-map/insdelfind/map_insdelfind.h @@ -131,47 +131,44 @@ namespace map { virtual void test() { Map& rMap = m_Map; - Map_InsDelFind& fixture = pool().template fixture(); - size_t pass_count = fixture.s_nPassCount; - - unsigned int i = 0; - size_t const nNormalize = size_t(-1) / ( s_nMapSize * 2 ); - - size_t nRand = 0; - while ( pass_count-- ) { - nRand = cds::bitop::RandXorShift( nRand ); - size_t n = nRand / nNormalize; - switch ( s_arrShuffle[i] ) { - case do_find: - if ( rMap.contains( n )) - ++m_nFindSuccess; + size_t pass_count = Map_InsDelFind::s_nPassCount; + + for (size_t count = 0; count < pass_count; count++) { + bool shouldUpdate = true; + for (size_t i = 0; i < s_nMapSize; ++i) { + // The number to operate on the map. + size_t n = i; + // Insert + if (i % s_nInsertPercentage == 1) { + if (!shouldUpdate) { + if (rMap.insert(n, n)) + ++m_nInsertSuccess; else - ++m_nFindFailed; - break; - case do_insert: - if ( n % 2 ) { - if ( rMap.insert( n, n )) - ++m_nInsertSuccess; - else - ++m_nInsertFailed; - } - else { - if ( rMap.update( n, update_functor(), true ).first ) - ++m_nInsertSuccess; - else - ++m_nInsertFailed; - } - break; - case do_delete: - if ( rMap.erase( n )) - ++m_nDeleteSuccess; + ++m_nInsertFailed; + shouldUpdate = true; + } else { + if (rMap.update(n, update_functor(), true).first) + ++m_nInsertSuccess; else - ++m_nDeleteFailed; - break; + ++m_nInsertFailed; + shouldUpdate = false; + } } - - if ( ++i >= c_nShuffleSize ) - i = 0; + // Find + if (rMap.contains(n)) + ++m_nFindSuccess; + else + ++m_nFindFailed; + // Delete + if (i % s_nInsertPercentage == 1) { + + if (rMap.erase(n)) + ++m_nDeleteSuccess; + else + ++m_nDeleteFailed; + break; + } + } } } }; @@ -181,18 +178,6 @@ namespace map { void do_test( Map& testMap ) { typedef Worker worker; - - // fill map - only odd number - { - std::vector arr; - arr.reserve( s_nMapSize ); - for ( size_t i = 0; i < s_nMapSize; ++i ) - arr.push_back( i * 2 + 1); - shuffle( arr.begin(), arr.end()); - for ( size_t i = 0; i < s_nMapSize; ++i ) - testMap.insert( arr[i], arr[i] ); - } - cds_test::thread_pool& pool = get_pool(); std::unique_ptr worker_thrd(new worker(pool, testMap)); worker_thrd->test(); -- 2.34.1