Refactors sequential test cases
[libcds.git] / test / stress / sequential / sequential_freelist_put_get_single.cpp
index 9b7f68a22e81b66a190b3420782925115d6d1876..b8a00e3135723e3da8593a241be056dccdefa40f 100644 (file)
@@ -84,7 +84,6 @@ namespace {
                 for ( size_t pass = 0; pass < s_nPassCount; ++pass ) {
                     item_type* p;
                     while ( (p = static_cast<item_type*>( m_FreeList.get())) == nullptr );
-                    p->counter.fetch_add( 1, atomics::memory_order_relaxed );
                     m_FreeList.put( p );
                 }
             }
@@ -114,17 +113,9 @@ namespace {
             list.put( &item );
 
             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
-            EXPECT_EQ( item.counter.load( atomics::memory_order_relaxed ), s_nPassCount * s_nThreadCount );
-
+            std::unique_ptr<Worker<FreeList>> worker(
+                new Worker<FreeList>(pool, list));
+            worker->test();
             list.clear( []( typename FreeList::node* ) {} );
         }
     };
@@ -132,12 +123,11 @@ namespace {
     size_t put_get_single::s_nThreadCount = 1;
     size_t put_get_single::s_nPassCount = 100000;
 
-#define CDSSTRESS_FREELIST_F( name, freelist_type ) \
-    TEST_F( put_get_single, name ) \
-    { \
-        freelist_type fl; \
-        test( fl ); \
-    }
+#define CDSSTRESS_FREELIST_F(name, freelist_type)                              \
+  TEST_F(put_get_single, name) {                                               \
+    std::unique_ptr<freelist_type> fl(new freelist_type());                    \
+    test(*fl);                                                                 \
+  }
 
     CDSSTRESS_FREELIST_F( FreeList, cds::intrusive::FreeList )
 
@@ -154,8 +144,9 @@ namespace {
 
         atomics::atomic<tagged_ptr> tp;
         if ( tp.is_lock_free()) {
-            cds::intrusive::TaggedFreeList fl;
-            test( fl );
+            using FL = cds::intrusive::TaggedFreeList;
+            std::unique_ptr<FL> fl(new FL());
+            test( *fl );
         }
         else
             std::cout << "Double-width CAS is not supported\n";