X-Git-Url: http://plrg.eecs.uci.edu/git/?p=libcds.git;a=blobdiff_plain;f=test%2Fstress%2Fstack%2Fpush_pop.cpp;h=56917927cfa9686cf7000dceeb16a1bc0c667a04;hp=1246ea44b8bfd0d10eea4a9da7850e04d8d9dfed;hb=c159cc3d0234c94a4084deb036cf974481a5bfe4;hpb=305da3404a293d5e5c4e76eb6660eeda5a7d4413 diff --git a/test/stress/stack/push_pop.cpp b/test/stress/stack/push_pop.cpp index 1246ea44..56917927 100644 --- a/test/stress/stack/push_pop.cpp +++ b/test/stress/stack/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/ @@ -29,12 +29,14 @@ */ #include "stack_type.h" +#include "../misc/common.h" namespace { static size_t s_nPushThreadCount = 4; static size_t s_nPopThreadCount = 4; static size_t s_nStackSize = 1000000; + static size_t s_nEliminationStackSize = 500000; static size_t s_nEliminationSize = 4; static atomics::atomic s_nWorkingProducers( 0 ); @@ -91,13 +93,13 @@ namespace { virtual void test() { - memset( m_arrPush, 0, sizeof( m_arrPush ) ); + memset( m_arrPush, 0, sizeof( m_arrPush )); value_type v; v.nThread = id(); for ( size_t i = 0; i < m_nItemCount; ++i ) { v.nNo = i % c_nValArraySize; - if ( m_stack.push( v ) ) + if ( m_stack.push( v )) ++m_arrPush[v.nNo]; else ++m_nPushError; @@ -142,13 +144,13 @@ namespace { virtual void test() { - memset( m_arrPop, 0, sizeof( m_arrPop ) ); + memset( m_arrPop, 0, sizeof( m_arrPop )); value_type v; - while ( !( s_nWorkingProducers.load( atomics::memory_order_acquire ) == 0 && m_stack.empty()) ) { - if ( m_stack.pop( v ) ) { + while ( !( s_nWorkingProducers.load( atomics::memory_order_acquire ) == 0 && m_stack.empty())) { + if ( m_stack.pop( v )) { ++m_nPopCount; - if ( v.nNo < sizeof( m_arrPop ) / sizeof( m_arrPop[0] ) ) + if ( v.nNo < sizeof( m_arrPop ) / sizeof( m_arrPop[0] )) ++m_arrPop[v.nNo]; else ++m_nDirtyPop; @@ -174,6 +176,8 @@ namespace { s_nPushThreadCount = cfg.get_size_t( "PushThreadCount", s_nPushThreadCount ); s_nPopThreadCount = cfg.get_size_t( "PopThreadCount", s_nPopThreadCount ); s_nStackSize = cfg.get_size_t( "StackSize", s_nStackSize ); + s_nEliminationStackSize = + cfg.get_size_t("EliminationStackSize", s_nEliminationStackSize); s_nEliminationSize = cfg.get_size_t( "EliminationSize", s_nEliminationSize ); if ( s_nPushThreadCount == 0 ) @@ -205,7 +209,7 @@ namespace { propout() << std::make_pair( "duration", duration ); - analyze( stack ); + DEBUG(analyze( stack )); propout() << stack.statistics(); } @@ -214,7 +218,7 @@ namespace { void test_elimination( Stack& stack ) { test( stack ); - check_elimination_stat( stack.statistics() ); + check_elimination_stat( stack.statistics()); } void check_elimination_stat( cds::container::treiber_stack::empty_stat const& ) @@ -224,9 +228,9 @@ namespace { { EXPECT_EQ( s.m_PushCount.get() + s.m_ActivePushCollision.get() + s.m_PassivePushCollision.get(), s_nStackSize ); EXPECT_EQ( s.m_PopCount.get() + s.m_ActivePopCollision.get() + s.m_PassivePopCollision.get(), s_nStackSize ); - EXPECT_EQ( s.m_PushCount.get(), s.m_PopCount.get() ); - EXPECT_EQ( s.m_ActivePopCollision.get(), s.m_PassivePushCollision.get() ); - EXPECT_EQ( s.m_ActivePushCollision.get(), s.m_PassivePopCollision.get() ); + EXPECT_EQ( s.m_PushCount.get(), s.m_PopCount.get()); + EXPECT_EQ( s.m_ActivePopCollision.get(), s.m_PassivePushCollision.get()); + EXPECT_EQ( s.m_ActivePushCollision.get(), s.m_PassivePopCollision.get()); } template< class Stack> @@ -238,7 +242,7 @@ namespace { size_t nPopEmpty = 0; size_t nPopCount = 0; size_t arrVal[c_nValArraySize]; - memset( arrVal, 0, sizeof( arrVal ) ); + memset( arrVal, 0, sizeof( arrVal )); size_t nDirtyPop = 0; for ( size_t threadNo = 0; threadNo < pool.size(); ++threadNo ) { @@ -278,9 +282,20 @@ namespace { }; CDSSTRESS_TreiberStack( stack_push_pop ) + + #undef CDSSTRESS_EliminationStack_F + + #define CDSSTRESS_EliminationStack_F( test_fixture, type_name ) \ + TEST_F( test_fixture, type_name ) \ + { \ + typedef stack::Types< value_type >::type_name stack_type; \ + s_nStackSize = s_nEliminationStackSize; \ + stack_type stack( s_nEliminationSize ); \ + test_elimination( stack ); \ + } + CDSSTRESS_EliminationStack( stack_push_pop ) - CDSSTRESS_FCStack( stack_push_pop ) - CDSSTRESS_FCDeque( stack_push_pop ) - CDSSTRESS_StdStack( stack_push_pop ) + //CDSSTRESS_FCStack( stack_push_pop ) + //CDSSTRESS_FCDeque( stack_push_pop ) } // namespace