Modifies more sequential test cases for sets
[libcds.git] / test / stress / sequential / sequential-set / insdel_string / set_insdel_string.h
index ad1a1b6..83cb473 100644 (file)
@@ -41,6 +41,8 @@ namespace set {
         static size_t s_nInsertThreadCount;     // count of insertion thread
         static size_t s_nDeleteThreadCount;     // count of deletion thread
         static size_t s_nThreadPassCount;       // pass count for each thread
+        static size_t s_nFeldmanThreadPassCount;       // pass count for Feldman
+        static size_t s_nSkiplistThreadPassCount;       // pass count for Skiplist 
         static size_t s_nMaxLoadFactor;         // maximum load factor
 
         static size_t s_nCuckooInitialSize;     // initial size for CuckooSet
@@ -103,25 +105,14 @@ namespace set {
                 size_t const nSetSize = fixture.s_nSetSize;
                 size_t const nPassCount = fixture.s_nThreadPassCount;
 
-                if ( id() & 1 ) {
-                    for ( size_t nPass = 0; nPass < nPassCount; ++nPass ) {
-                        for ( size_t nItem = 0; nItem < nSetSize; ++nItem ) {
-                            if ( rSet.insert( keyval_type( m_arrString[nItem % nArrSize], nItem * 8 )))
-                                ++m_nInsertSuccess;
-                            else
-                                ++m_nInsertFailed;
-                        }
-                    }
-                }
-                else {
-                    for ( size_t nPass = 0; nPass < nPassCount; ++nPass ) {
-                        for ( size_t nItem = nSetSize; nItem > 0; --nItem ) {
-                            if ( rSet.insert( keyval_type( m_arrString[nItem % nArrSize], nItem * 8 )))
-                                ++m_nInsertSuccess;
-                            else
-                                ++m_nInsertFailed;
-                        }
-                    }
+                for (size_t nPass = 0; nPass < nPassCount; ++nPass) {
+                  for (size_t nItem = 0; nItem < nSetSize; ++nItem) {
+                    if (rSet.insert(keyval_type(m_arrString[nItem % nArrSize],
+                                                nItem * 8)))
+                      ++m_nInsertSuccess;
+                    else
+                      ++m_nInsertFailed;
+                  }
                 }
             }
         };
@@ -161,25 +152,13 @@ namespace set {
                 size_t const nSetSize = fixture.s_nSetSize;
                 size_t const nPassCount = fixture.s_nThreadPassCount;
 
-                if ( id() & 1 ) {
-                    for ( size_t nPass = 0; nPass < nPassCount; ++nPass ) {
-                        for ( size_t nItem = 0; nItem < nSetSize; ++nItem ) {
-                            if ( rSet.erase( m_arrString[nItem % nArrSize] ))
-                                ++m_nDeleteSuccess;
-                            else
-                                ++m_nDeleteFailed;
-                        }
-                    }
-                }
-                else {
-                    for ( size_t nPass = 0; nPass < nPassCount; ++nPass ) {
-                        for ( size_t nItem = nSetSize; nItem > 0; --nItem ) {
-                            if ( rSet.erase( m_arrString[nItem % nArrSize] ))
-                                ++m_nDeleteSuccess;
-                            else
-                                ++m_nDeleteFailed;
-                        }
-                    }
+                for (size_t nPass = 0; nPass < nPassCount; ++nPass) {
+                  for (size_t nItem = 0; nItem < nSetSize; ++nItem) {
+                    if (rSet.erase(m_arrString[nItem % nArrSize]))
+                      ++m_nDeleteSuccess;
+                    else
+                      ++m_nDeleteFailed;
+                  }
                 }
             }
         };
@@ -221,29 +200,15 @@ namespace set {
                 size_t const nSetSize = fixture.s_nSetSize;
                 size_t const nPassCount = fixture.s_nThreadPassCount;
 
-                if ( id() & 1 ) {
-                    for ( size_t nPass = 0; nPass < nPassCount; ++nPass ) {
-                        for ( size_t nItem = 0; nItem < nSetSize; ++nItem ) {
-                            gp = rSet.extract( m_arrString[nItem % nArrSize] );
-                            if ( gp )
-                                ++m_nDeleteSuccess;
-                            else
-                                ++m_nDeleteFailed;
-                            gp.release();
-                        }
-                    }
-                }
-                else {
-                    for ( size_t nPass = 0; nPass < nPassCount; ++nPass ) {
-                        for ( size_t nItem = nSetSize; nItem > 0; --nItem ) {
-                            gp = rSet.extract( m_arrString[nItem % nArrSize] );
-                            if ( gp )
-                                ++m_nDeleteSuccess;
-                            else
-                                ++m_nDeleteFailed;
-                            gp.release();
-                        }
-                    }
+                for (size_t nPass = 0; nPass < nPassCount; ++nPass) {
+                  for (size_t nItem = 0; nItem < nSetSize; ++nItem) {
+                    gp = rSet.extract(m_arrString[nItem % nArrSize]);
+                    if (gp)
+                      ++m_nDeleteSuccess;
+                    else
+                      ++m_nDeleteFailed;
+                    gp.release();
+                  }
                 }
             }
         };
@@ -403,77 +368,23 @@ namespace set {
             typedef Deleter<Set>  DeleterThread;
             typedef Extractor<typename Set::gc, Set> ExtractThread;
 
-            size_t const nDelThreadCount = s_nDeleteThreadCount / 2;
-            size_t const nExtractThreadCount = s_nDeleteThreadCount - nDelThreadCount;
-
             cds_test::thread_pool& pool = get_pool();
-            pool.add( new InserterThread( pool, testSet ), s_nInsertThreadCount );
-            pool.add( new DeleterThread( pool, testSet ), nDelThreadCount );
-            pool.add( new ExtractThread( pool, testSet ), nExtractThreadCount );
-
-            propout() << std::make_pair( "insert_thread_count", s_nInsertThreadCount )
-                << std::make_pair( "delete_thread_count", nDelThreadCount )
-                << std::make_pair( "extract_thread_count", nExtractThreadCount )
-                << std::make_pair( "thread_pass_count", s_nThreadPassCount )
-                << std::make_pair( "set_size", s_nSetSize );
-
-            std::chrono::milliseconds duration = pool.run();
-
-            propout() << std::make_pair( "duration", duration );
-
-            size_t nInsertSuccess = 0;
-            size_t nInsertFailed = 0;
-            size_t nDeleteSuccess = 0;
-            size_t nDeleteFailed = 0;
-            size_t nExtractSuccess = 0;
-            size_t nExtractFailed = 0;
-            for ( size_t i = 0; i < pool.size(); ++i ) {
-                cds_test::thread& thr = pool.get( i );
-                switch ( thr.type()) {
-                case insert_thread:
-                    {
-                        InserterThread& inserter = static_cast<InserterThread&>(thr);
-                        nInsertSuccess += inserter.m_nInsertSuccess;
-                        nInsertFailed += inserter.m_nInsertFailed;
-                    }
-                    break;
-                case delete_thread:
-                    {
-                        DeleterThread& deleter = static_cast<DeleterThread&>(thr);
-                        nDeleteSuccess += deleter.m_nDeleteSuccess;
-                        nDeleteFailed += deleter.m_nDeleteFailed;
-                    }
-                    break;
-                case extract_thread:
-                    {
-                        ExtractThread& extractor = static_cast<ExtractThread&>(thr);
-                        nExtractSuccess += extractor.m_nDeleteSuccess;
-                        nExtractFailed += extractor.m_nDeleteFailed;
-                    }
-                    break;
-                default:
-                    assert( false ); // Forgot anything?..
-                }
-            }
-
-            propout()
-                << std::make_pair( "insert_success", nInsertSuccess )
-                << std::make_pair( "delete_success", nDeleteSuccess )
-                << std::make_pair( "extract_success", nExtractSuccess )
-                << std::make_pair( "insert_failed",  nInsertFailed )
-                << std::make_pair( "delete_failed",  nDeleteFailed )
-                << std::make_pair( "extract_failed", nExtractFailed )
-                << std::make_pair( "final_set_size", testSet.size());
-
-            //testSet.clear();
-            for ( auto const& str : m_arrString )
-                testSet.erase( str );
-            EXPECT_TRUE( testSet.empty());
-            EXPECT_EQ( testSet.size(), 0u );
 
-            additional_check( testSet );
-            print_stat( propout(), testSet );
-            additional_cleanup( testSet );
+            std::unique_ptr<InserterThread> inserter(
+                new InserterThread(pool, testSet));
+            std::unique_ptr<DeleterThread> deleter(
+                new DeleterThread(pool, testSet));
+            std::unique_ptr<ExtractThread> extractor(
+                new ExtractThread(pool, testSet));
+
+           inserter->test();
+           deleter->test();
+           inserter->test();
+           extractor->test();
+
+           for (auto const &str : m_arrString)
+             testSet.erase(str);
+           additional_cleanup(testSet);
         }
 
         template <class Set>
@@ -493,6 +404,22 @@ namespace set {
             Set s( *this );
             do_test_extract( s );
         }
+
+        template <class Set>
+        void run_feldman()
+        {
+          Set_InsDel_string::s_nThreadPassCount =
+              Set_InsDel_string::s_nFeldmanThreadPassCount;
+          run_test_extract<Set>();
+        }
+
+        template <class Set>
+        void run_skiplist()
+        {
+          Set_InsDel_string::s_nThreadPassCount =
+              Set_InsDel_string::s_nSkiplistThreadPassCount;
+          run_test_extract<Set>();
+        }
     };
 
     class Set_InsDel_string_LF: public Set_InsDel_string