Refactors some of existing cds multi-threaded stress test cases
[libcds.git] / test / stress / parallel / parallel_freelist_put_get.cpp
index 04308c9..8e7a546 100644 (file)
@@ -105,11 +105,13 @@ namespace {
     public:
         static void SetUpTestCase()
         {
-            cds_test::config const& cfg = get_config( "SequentialFreeList" );
+            cds_test::config const& cfg = get_config( "ParallelFreeList" );
 
+            s_nThreadCount = cfg.get_size_t( "ThreadCount", s_nThreadCount );
             s_nPassCount = cfg.get_size_t( "PassCount", s_nPassCount );
 
-            s_nThreadCount = 1;
+            if ( s_nThreadCount == 0 )
+                s_nThreadCount = 1;
             if ( s_nPassCount == 0 )
                 s_nPassCount = 1000;
         }
@@ -127,29 +129,39 @@ namespace {
             for ( auto& i : arr )
                 list.put( &i );
 
-            std::unique_ptr<Worker<FreeList>> worker(
-                new Worker<FreeList>(pool, list));
-            worker->test();
+            pool.add( new Worker<FreeList>( pool, list ), s_nThreadCount );
+
+            propout() << std::make_pair( "work_thread", s_nThreadCount )
+                      << std::make_pair( "pass_count", s_nPassCount );
+
+            std::chrono::milliseconds duration = pool.run();
+
+            propout() << std::make_pair( "duration", duration );
 
             // analyze result
             size_t nTotal = 0;
             for ( auto const& i : arr )
                 nTotal += i.counter;
 
-            EXPECT_EQ( worker->m_nSuccess, nTotal );
+            size_t nSuccess = 0;
+            for ( size_t threadNo = 0; threadNo < pool.size(); ++threadNo )
+                nSuccess += static_cast<Worker<FreeList>&>( pool.get( threadNo )).m_nSuccess;
+
+            EXPECT_EQ( nSuccess, nTotal );
 
             list.clear( []( typename FreeList::node* ) {} );
         }
     };
 
-    size_t put_get::s_nThreadCount = 1;
+    size_t put_get::s_nThreadCount = 4;
     size_t put_get::s_nPassCount = 100000;
 
-#define CDSSTRESS_FREELIST_F(name, freelist_type)                              \
-  TEST_F(put_get, name) {                                                      \
-    std::unique_ptr<freelist_type> fl(new freelist_type());                    \
-    test(*fl);                                                                 \
-  }
+#define CDSSTRESS_FREELIST_F( name, freelist_type ) \
+    TEST_F( put_get, name ) \
+    { \
+        freelist_type fl; \
+        test( fl ); \
+    }
 
     CDSSTRESS_FREELIST_F( FreeList, cds::intrusive::FreeList )
 
@@ -166,9 +178,8 @@ namespace {
 
         atomics::atomic<tagged_ptr> tp;
         if ( tp.is_lock_free()) {
-            using FL = cds::intrusive::TaggedFreeList;
-            std::unique_ptr<FL> fl(new FL());
-            test( *fl );
+            cds::intrusive::TaggedFreeList fl;
+            test( fl );
         }
         else
             std::cout << "Double-width CAS is not supported\n";