Removes randomness in sequential map test case
authorPeizhao Ou <peizhaoo@uci.edu>
Thu, 25 Jan 2018 06:57:46 +0000 (22:57 -0800)
committerPeizhao Ou <peizhaoo@uci.edu>
Thu, 25 Jan 2018 06:57:46 +0000 (22:57 -0800)
test/stress/sequential/sequential-map/insdelfind/map_insdelfind.h

index f1b03bf..8d69276 100644 (file)
@@ -131,47 +131,44 @@ namespace map {
             virtual void test()
             {
                 Map& rMap = m_Map;
-                Map_InsDelFind& fixture = pool().template fixture<Map_InsDelFind>();
-                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<Map> worker;
-
-            // fill map - only odd number
-            {
-                std::vector<size_t> 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> worker_thrd(new worker(pool, testMap));
             worker_thrd->test();