[SkipList] Added random-lvel generators for max height 32/24/16
[libcds.git] / test / stress / pqueue / pop.cpp
index a5253195478e717d740cd53b926584db2f6dc279..f1d3d14b390e4360fbf08f2e2965c05d1bb73396 100644 (file)
@@ -1,11 +1,11 @@
 /*
     This file is a part of libcds - Concurrent Data Structures library
 
-    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
 
     Source code repo: http://github.com/khizmax/libcds/
     Download: http://sourceforge.net/projects/libcds/files/
-    
+
     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions are met:
 
@@ -70,17 +70,25 @@ namespace {
                     ++m_nPopSuccess;
                     nPrevKey = val.key;
 
+                    bool prevPopFailed = false;
                     while ( m_Queue.pop( val )) {
                         ++m_nPopSuccess;
                         if ( val.key > nPrevKey ) {
                             ++m_nPopError;
-                            m_arrFailedPops.emplace_back( failed_pops{ nPrevKey, val.key } );
+                            m_arrFailedPops.emplace_back( failed_pops{ nPrevKey, val.key, static_cast<size_t>(-1) } );
+                            prevPopFailed = true;
                         }
                         else if ( val.key == nPrevKey ) {
                             ++m_nPopErrorEq;
-                            m_arrFailedPops.emplace_back( failed_pops{ nPrevKey, val.key } );
+                            m_arrFailedPops.emplace_back( failed_pops{ nPrevKey, val.key, static_cast<size_t>(-1) } );
+                        }
+                        else {
+                            if ( prevPopFailed )
+                                m_arrFailedPops.back().next_key = val.key;
+                            prevPopFailed = false;
                         }
-                        nPrevKey = val.key;
+                        if ( nPrevKey > val.key )
+                            nPrevKey = val.key;
                     }
 
                 }
@@ -98,6 +106,7 @@ namespace {
             struct failed_pops {
                 size_t prev_key;
                 size_t popped_key;
+                size_t next_key;
             };
             std::vector< failed_pops > m_arrFailedPops;
         };
@@ -109,26 +118,26 @@ namespace {
         {
             cds_test::thread_pool& pool = get_pool();
 
-            propout() << std::make_pair( "thread_count", s_nThreadCount )
-                << std::make_pair( "push_count", s_nQueueSize );
-
             // push
             {
                 std::vector< size_t > arr;
                 arr.reserve( s_nQueueSize );
                 for ( size_t i = 0; i < s_nQueueSize; ++i )
                     arr.push_back( i );
-                shuffle( arr.begin(), arr.end() );
+                shuffle( arr.begin(), arr.end());
 
                 size_t nPushError = 0;
                 typedef typename PQueue::value_type value_type;
                 for ( auto it = arr.begin(); it != arr.end(); ++it ) {
-                    if ( !q.push( value_type( *it ) ))
+                    if ( !q.push( value_type( *it )))
                         ++nPushError;
                 }
                 s_nQueueSize -= nPushError;
             }
 
+            propout() << std::make_pair( "thread_count", s_nThreadCount )
+                << std::make_pair( "push_count", s_nQueueSize );
+
             // pop
             {
                 pool.add( new Consumer<PQueue>( pool, q ), s_nThreadCount );
@@ -149,10 +158,14 @@ namespace {
                     nTotalErrorEq += cons.m_nPopErrorEq;
                     nTotalFailed  += cons.m_nPopFailed;
 
-                    if ( !cons.m_arrFailedPops.empty() ) {
+                    if ( !cons.m_arrFailedPops.empty()) {
                         std::cerr << "Priority violations, thread " << i;
                         for ( size_t k = 0; k < cons.m_arrFailedPops.size(); ++k ) {
                             std::cerr << "\n    " << "prev_key=" << cons.m_arrFailedPops[k].prev_key << " popped_key=" << cons.m_arrFailedPops[k].popped_key;
+                            if ( cons.m_arrFailedPops[k].next_key != static_cast<size_t>(-1))
+                                std::cerr << " next_key=" << cons.m_arrFailedPops[k].next_key;
+                            else
+                                std::cerr << " next_key unspecified";
                         }
                         std::cerr << std::endl;
                     }
@@ -164,25 +177,25 @@ namespace {
                     << std::make_pair( "error_priority_violation", nTotalError );
 
                 EXPECT_EQ( nTotalPopped, s_nQueueSize );
-                EXPECT_EQ( nTotalError, 0 ) << "priority violations";
-                EXPECT_EQ( nTotalErrorEq, 0 ) << "double key";
+                EXPECT_EQ( nTotalError, 0u ) << "priority violations";
+                EXPECT_EQ( nTotalErrorEq, 0u ) << "double key";
             }
 
             propout() << q.statistics();
         }
 
     public:
-        static void SetUpTestCase()\r
-        {\r
-            cds_test::config const& cfg = get_config( "pqueue_pop" );\r
-\r
+        static void SetUpTestCase()
+        {
+            cds_test::config const& cfg = get_config( "pqueue_pop" );
+
             s_nThreadCount = cfg.get_size_t( "ThreadCount", s_nThreadCount );
             s_nQueueSize = cfg.get_size_t( "QueueSize", s_nQueueSize );
 
-            if ( s_nThreadCount == 0 )
+            if ( s_nThreadCount == 0u )
                 s_nThreadCount = 1;
-            if ( s_nQueueSize == 0 )
-                s_nQueueSize = 1000;\r
+            if ( s_nQueueSize == 0u )
+                s_nQueueSize = 1000;
         }
 
         //static void TearDownTestCase();
@@ -205,12 +218,12 @@ namespace {
     { \
         typedef pqueue::Types<pqueue::simple_value>::pqueue_t pqueue_type; \
         std::unique_ptr< pqueue_type > pq( new pqueue_type ); \
-        test( *pq.get() ); \
+        test( *pq.get()); \
     }
     //CDSSTRESS_MSPriorityQueue( pqueue_pop, MSPriorityQueue_static_less )
     //CDSSTRESS_MSPriorityQueue( pqueue_pop, MSPriorityQueue_static_less_stat )
     //CDSSTRESS_MSPriorityQueue( pqueue_pop, MSPriorityQueue_static_cmp )
-    //CDSSTRESS_MSPriorityQueue( pqueue_pop, 1MSPriorityQueue_static_mutex )
+    //CDSSTRESS_MSPriorityQueue( pqueue_pop, MSPriorityQueue_static_mutex )
 
 
 #define CDSSTRESS_PriorityQueue( fixture_t, pqueue_t ) \
@@ -254,31 +267,25 @@ namespace {
     CDSSTRESS_PriorityQueue( pqueue_pop, EllenBinTree_RCU_shb_max_stat )
     CDSSTRESS_PriorityQueue( pqueue_pop, EllenBinTree_RCU_shb_min )
     CDSSTRESS_PriorityQueue( pqueue_pop, EllenBinTree_RCU_shb_min_stat )
-    CDSSTRESS_PriorityQueue( pqueue_pop, EllenBinTree_RCU_sht_max )
-    CDSSTRESS_PriorityQueue( pqueue_pop, EllenBinTree_RCU_sht_max_stat )
-    CDSSTRESS_PriorityQueue( pqueue_pop, EllenBinTree_RCU_sht_min )
-    CDSSTRESS_PriorityQueue( pqueue_pop, EllenBinTree_RCU_sht_min_stat )
 #endif
 
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_HP_max )
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_HP_max_stat )
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_HP_min )
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_HP_min_stat )
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_DHP_max )
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_DHP_max_stat )
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_DHP_min )
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_DHP_min_stat )
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_RCU_gpi_max )
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_RCU_gpi_min )
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_RCU_gpb_max )
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_RCU_gpb_min )
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_RCU_gpt_max )
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_RCU_gpt_min )
+    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList32_HP_max )
+    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList32_HP_max_stat )
+    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList32_HP_min )
+    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList32_HP_min_stat )
+    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList32_DHP_max )
+    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList32_DHP_max_stat )
+    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList32_DHP_min )
+    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList32_DHP_min_stat )
+    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList32_RCU_gpi_max )
+    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList32_RCU_gpi_min )
+    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList32_RCU_gpb_max )
+    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList32_RCU_gpb_min )
+    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList32_RCU_gpt_max )
+    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList32_RCU_gpt_min )
 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_RCU_shb_max )
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_RCU_shb_min )
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_RCU_sht_max )
-    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList_RCU_sht_min )
+    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList32_RCU_shb_max )
+    CDSSTRESS_PriorityQueue( pqueue_pop, SkipList32_RCU_shb_min )
 #endif
 
     CDSSTRESS_PriorityQueue( pqueue_pop, StdPQueue_vector_spin )