Modifies more sequential test cases for sets
[libcds.git] / test / stress / sequential / sequential-set / iteration / set_iteration.h
index 2be247d..6f47b39 100644 (file)
@@ -133,28 +133,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 ) {
-                            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;
+                  }
                 }
-                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;
-                        }
-                    }
-                }
-
-                fixture.on_modifier_done();
             }
         };
 
@@ -193,28 +180,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.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;
+                  }
                 }
-                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;
-                        }
-                    }
-                }
-
-                fixture.on_modifier_done();
             }
         };
 
@@ -255,32 +228,16 @@ 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();
-                        }
-                    }
+                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();
-                        }
-                    }
-                }
-
-                fixture.on_modifier_done();
             }
         };
 
@@ -403,19 +360,16 @@ namespace set {
                 Set& rSet = m_Set;
 
                 Set_Iteration& fixture = pool().template fixture<Set_Iteration>();
-                while ( !fixture.all_modifiers_done()) {
-                    ++m_nPassCount;
-                    typename Set::iterator it;
-                    typename Set::iterator itEnd;
-                    itEnd = rSet.end();
-                    for ( it = rSet.begin(); it != itEnd; ++it ) {
+                typename Set::iterator it;
+                typename Set::iterator itEnd;
+                itEnd = rSet.end();
+                for (it = rSet.begin(); it != itEnd; ++it) {
 #if CDS_BUILD_BITS == 64
-                        it->val.hash = CityHash64( it->key.c_str(), it->key.length());
+                  it->val.hash = CityHash64(it->key.c_str(), it->key.length());
 #else
-                        it->val.hash = std::hash<std::string>()( it->key );
+                  it->val.hash = std::hash<std::string>()(it->key);
 #endif
-                        ++m_nVisitCount;
-                    }
+                  ++m_nVisitCount;
                 }
             }
         };
@@ -453,19 +407,16 @@ namespace set {
                 Set& rSet = m_Set;
 
                 Set_Iteration& fixture = pool().template fixture<Set_Iteration>();
-                while ( !fixture.all_modifiers_done()) {
-                    ++m_nPassCount;
-                    typename Set::rcu_lock l;
-                    for ( auto it = rSet.begin(); it != rSet.end(); ++it ) {
+                typename Set::rcu_lock l;
+                for (auto it = rSet.begin(); it != rSet.end(); ++it) {
 #if CDS_BUILD_BITS == 64
-                        it->val.hash = CityHash64( it->key.c_str(), it->key.length());
+                  it->val.hash = CityHash64(it->key.c_str(), it->key.length());
 #else
-                        it->val.hash = std::hash<std::string>()(it->key);
+                  it->val.hash = std::hash<std::string>()(it->key);
 #endif
-                        ++m_nVisitCount;
-                    }
+                  ++m_nVisitCount;
                 }
-            }
+        }
         };
 
     protected:
@@ -552,87 +503,25 @@ namespace set {
             typedef Extractor<typename Set::gc, Set> ExtractThread;
             typedef Iterator<typename Set::gc, Set> IteratorThread;
 
-            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 );
 
-            m_nModifierCount.store( pool.size(), atomics::memory_order_relaxed );
-            pool.add( new IteratorThread( pool, testSet ), 1 );
-
-            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;
-            size_t nIteratorPassCount = 0;
-            size_t nIteratorVisitCount = 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;
-                case iterator_thread:
-                    {
-                        IteratorThread& iter = static_cast<IteratorThread&>(thr);
-                        nIteratorPassCount += iter.m_nPassCount;
-                        nIteratorVisitCount += iter.m_nVisitCount;
-                    }
-                    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( "iterator_pass_count", nIteratorPassCount )
-                << std::make_pair( "iterator_visit_count", nIteratorVisitCount )
-                << std::make_pair( "final_set_size", testSet.size());
+            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));
+            std::unique_ptr<IteratorThread> iterator(
+                new IteratorThread(pool, testSet));
+
+            inserter->test();
+            iterator->test();
+            deleter->test();
+            iterator->test();
+            extractor->test();
+            iterator->test();
 
             testSet.clear();
-            EXPECT_TRUE( testSet.empty());
-
-            additional_check( testSet );
-            print_stat( propout(), testSet );
             additional_cleanup( testSet );
         }