X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=test%2Fstress%2Fqueue%2Fpush_pop.cpp;h=148fde4136b354c5e81f15bfe89cd3416eb1f16f;hb=1132246d5685f87a5b240e077b7e88d56e38b1ff;hp=20a3d39c78b5656a5ad76d8b7fc992bd30e984c2;hpb=f6a4db0477151d641ac2a89aa79cf537b620e154;p=libcds.git diff --git a/test/stress/queue/push_pop.cpp b/test/stress/queue/push_pop.cpp index 20a3d39c..148fde41 100644 --- a/test/stress/queue/push_pop.cpp +++ b/test/stress/queue/push_pop.cpp @@ -1,7 +1,7 @@ /* 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/ @@ -32,6 +32,7 @@ #include #include +#include // Multi-threaded queue push/pop test namespace { @@ -39,22 +40,23 @@ namespace { static size_t s_nConsumerThreadCount = 4; static size_t s_nProducerThreadCount = 4; static size_t s_nQueueSize = 4000000; + static size_t s_nHeavyValueSize = 100; static std::atomic s_nProducerDone( 0 ); struct old_value - { - size_t nNo; - size_t nWriterNo; - }; + { + size_t nNo; + size_t nWriterNo; + }; template class queue_push_pop: public cds_test::stress_fixture { protected: - using value_type = Value; + using value_type = Value; - enum { + enum { producer_thread, consumer_thread }; @@ -198,8 +200,8 @@ namespace { { cds_test::thread_pool& pool = get_pool(); - typedef Consumer Consumer; - typedef Producer Producer; + typedef Consumer consumer_type; + typedef Producer producer_type; size_t nPostTestPops = 0; { @@ -213,12 +215,12 @@ namespace { size_t nPoppedItems = 0; size_t nPushFailed = 0; - std::vector< Consumer * > arrConsumer; + std::vector< consumer_type * > arrConsumer; for ( size_t i = 0; i < pool.size(); ++i ) { cds_test::thread& thr = pool.get(i); if ( thr.type() == consumer_thread ) { - Consumer& consumer = static_cast( thr ); + consumer_type& consumer = static_cast( thr ); nTotalPops += consumer.m_nPopped; nPopFalse += consumer.m_nPopEmpty; arrConsumer.push_back( &consumer ); @@ -233,7 +235,7 @@ namespace { else { assert( thr.type() == producer_thread ); - Producer& producer = static_cast( thr ); + producer_type& producer = static_cast( thr ); nPushFailed += producer.m_nPushFailed; EXPECT_EQ( producer.m_nPushFailed, 0u ) << "producer_thread_no " << i; } @@ -301,6 +303,20 @@ namespace { propout() << q.statistics(); } + private: + static void set_array_size( size_t size ) { + const bool tmp = fc_test::has_set_array_size::value; + set_array_size(size, std::integral_constant()); + } + + static void set_array_size(size_t size, std::true_type){ + value_type::set_array_size(size); + } + + static void set_array_size(size_t, std::false_type) + { + } + public: static void SetUpTestCase() { @@ -309,6 +325,7 @@ namespace { s_nConsumerThreadCount = cfg.get_size_t( "ConsumerCount", s_nConsumerThreadCount ); s_nProducerThreadCount = cfg.get_size_t( "ProducerCount", s_nProducerThreadCount ); s_nQueueSize = cfg.get_size_t( "QueueSize", s_nQueueSize ); + s_nHeavyValueSize = cfg.get_size_t( "HeavyValueSize", s_nHeavyValueSize ); if ( s_nConsumerThreadCount == 0u ) s_nConsumerThreadCount = 1; @@ -316,35 +333,38 @@ namespace { s_nProducerThreadCount = 1; if ( s_nQueueSize == 0u ) s_nQueueSize = 1000; + if ( s_nHeavyValueSize == 0 ) + s_nHeavyValueSize = 1; + + set_array_size( s_nHeavyValueSize ); } //static void TearDownTestCase(); }; - using value_for_fc_with_heavy_value = queue_push_pop< HeavyValue<36000> >; - using old_queue_push_pop = queue_push_pop<>; + using fc_with_heavy_value = queue_push_pop< fc_test::heavy_value<36000> >; + using simple_queue_push_pop = queue_push_pop<>; -// CDSSTRESS_MSQueue( old_queue_push_pop ) -// CDSSTRESS_MoirQueue( old_queue_push_pop ) -// CDSSTRESS_BasketQueue( old_queue_push_pop ) -// CDSSTRESS_OptimsticQueue( old_queue_push_pop ) -// CDSSTRESS_FCQueue( old_queue_push_pop ) -// CDSSTRESS_FCDeque( old_queue_push_pop ) - CDSSTRESS_FCDeque_HeavyValue( value_for_fc_with_heavy_value ) -// CDSSTRESS_RWQueue( old_queue_push_pop ) -// CDSSTRESS_StdQueue( old_queue_push_pop ) + CDSSTRESS_MSQueue( simple_queue_push_pop ) + CDSSTRESS_MoirQueue( simple_queue_push_pop ) + CDSSTRESS_BasketQueue( simple_queue_push_pop ) + CDSSTRESS_OptimsticQueue( simple_queue_push_pop ) + CDSSTRESS_FCQueue( simple_queue_push_pop ) + CDSSTRESS_FCDeque( simple_queue_push_pop ) + CDSSTRESS_FCDeque_HeavyValue( fc_with_heavy_value ) + CDSSTRESS_RWQueue( simple_queue_push_pop ) + CDSSTRESS_StdQueue( simple_queue_push_pop ) #undef CDSSTRESS_Queue_F -#define CDSSTRESS_Queue_F( test_fixture, type_name, level ) \ +#define CDSSTRESS_Queue_F( test_fixture, type_name ) \ TEST_F( test_fixture, type_name ) \ { \ - if ( !check_detail_level( level )) return; \ typedef queue::Types< value_type >::type_name queue_type; \ queue_type queue( s_nQueueSize ); \ test( queue ); \ } - CDSSTRESS_VyukovQueue( old_queue_push_pop ) + CDSSTRESS_VyukovQueue( simple_queue_push_pop ) #undef CDSSTRESS_Queue_F @@ -383,8 +403,7 @@ namespace { if ( bIterative && quasi_factor > 4 ) { for ( size_t qf = 4; qf <= quasi_factor; qf *= 2 ) args.push_back( qf ); - } - else { + } else { if ( quasi_factor > 2 ) args.push_back( quasi_factor ); else @@ -395,18 +414,27 @@ namespace { } }; -#define CDSSTRESS_Queue_F( test_fixture, type_name, level ) \ +#define CDSSTRESS_Queue_F( test_fixture, type_name ) \ TEST_P( test_fixture, type_name ) \ { \ - if ( !check_detail_level( level )) return; \ typedef typename queue::Types::type_name queue_type; \ test< queue_type >(); \ } -// CDSSTRESS_SegmentedQueue( segmented_queue_push_pop ) + CDSSTRESS_SegmentedQueue( segmented_queue_push_pop ) +#ifdef CDSTEST_GTEST_INSTANTIATE_TEST_CASE_P_HAS_4TH_ARG + static std::string get_test_parameter_name( testing::TestParamInfo const& p ) + { + return std::to_string( p.param ); + } + INSTANTIATE_TEST_CASE_P( SQ, + segmented_queue_push_pop, + ::testing::ValuesIn( segmented_queue_push_pop::get_test_parameters()), get_test_parameter_name ); +#else INSTANTIATE_TEST_CASE_P( SQ, segmented_queue_push_pop, ::testing::ValuesIn( segmented_queue_push_pop::get_test_parameters())); +#endif } // namespace