2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "intrusive_stack_push_pop.h"
34 /*static*/ size_t intrusive_stack_push_pop::s_nPushThreadCount = 4;
35 /*static*/ size_t intrusive_stack_push_pop::s_nPopThreadCount = 4;
36 /*static*/ size_t intrusive_stack_push_pop::s_nStackSize = 10000000;
37 /*static*/ size_t intrusive_stack_push_pop::s_nEliminationSize = 4;
38 /*static*/ bool intrusive_stack_push_pop::s_bFCIterative = false;
39 /*static*/ unsigned int intrusive_stack_push_pop::s_nFCCombinePassCount = 64;
40 /*static*/ unsigned int intrusive_stack_push_pop::s_nFCCompactFactor = 1024;
42 /*static*/ atomics::atomic<size_t> intrusive_stack_push_pop::s_nWorkingProducers( 0 );
44 /*static*/ void intrusive_stack_push_pop::SetUpTestCase()
46 cds_test::config const& cfg = get_config( "IntrusiveStack_PushPop" );
48 s_nPushThreadCount = cfg.get_size_t( "PushThreadCount", s_nPushThreadCount );
49 s_nPopThreadCount = cfg.get_size_t( "PopThreadCount", s_nPopThreadCount );
50 s_nStackSize = cfg.get_size_t( "StackSize", s_nStackSize );
51 s_nEliminationSize = cfg.get_size_t( "EliminationSize", s_nEliminationSize );
52 s_bFCIterative = cfg.get_bool( "FCIterate", s_bFCIterative );
53 s_nFCCombinePassCount = cfg.get_uint( "FCCombinePassCount", s_nFCCombinePassCount );
54 s_nFCCompactFactor = cfg.get_uint( "FCCompactFactor", s_nFCCompactFactor );
56 if ( s_nPushThreadCount == 0 )
57 s_nPushThreadCount = 1;
58 if ( s_nPopThreadCount == 0 )
59 s_nPopThreadCount = 1;
60 if ( s_nEliminationSize == 0 )
61 s_nEliminationSize = 1;
63 } // namespace cds_test
66 class intrusive_stack_push_pop : public cds_test::intrusive_stack_push_pop
68 typedef cds_test::intrusive_stack_push_pop base_class;
70 typedef base_class::value_type<> value_type;
71 typedef base_class::value_type< cds::intrusive::treiber_stack::node< cds::gc::HP >> hp_value_type;
72 typedef base_class::value_type< cds::intrusive::treiber_stack::node< cds::gc::DHP >> dhp_value_type;
74 template <typename Stack>
77 value_array<typename Stack::value_type> arrValue( s_nStackSize );
80 do_test( stack, arrValue );
82 Stack::gc::force_dispose();
85 void check_elimination_stat( cds::intrusive::treiber_stack::empty_stat const& )
88 void check_elimination_stat( cds::intrusive::treiber_stack::stat<> const& s )
90 EXPECT_EQ( s.m_PushCount.get() + s.m_ActivePushCollision.get() + s.m_PassivePushCollision.get(), s_nStackSize );
91 EXPECT_EQ( s.m_PopCount.get() + s.m_ActivePopCollision.get() + s.m_PassivePopCollision.get(), s_nStackSize );
92 EXPECT_EQ( s.m_PushCount.get(), s.m_PopCount.get());
93 EXPECT_EQ( s.m_ActivePopCollision.get(), s.m_PassivePushCollision.get());
94 EXPECT_EQ( s.m_ActivePushCollision.get(), s.m_PassivePopCollision.get());
97 template <typename Stack>
98 void test_elimination()
100 value_array<typename Stack::value_type> arrValue( s_nStackSize );
102 Stack stack( s_nEliminationSize );
103 do_test( stack, arrValue );
104 check_elimination_stat( stack.statistics());
106 Stack::gc::force_dispose();
109 template <typename Stack>
112 value_array<typename Stack::value_type> arrValue( s_nStackSize );
114 do_test( stack, arrValue );
118 // TreiberStack<cds::gc::HP>
119 #define CDSSTRESS_Stack_F( test_fixture, stack_impl ) \
120 TEST_F( test_fixture, stack_impl ) \
122 typedef typename istack::Types<hp_value_type>::stack_impl stack_type; \
123 test< stack_type >(); \
126 CDSSTRESS_TreiberStack_HP( intrusive_stack_push_pop )
128 #undef CDSSTRESS_Stack_F
130 // TreiberStack<cds::gc::DHP>
131 #define CDSSTRESS_Stack_F( test_fixture, stack_impl ) \
132 TEST_F( test_fixture, stack_impl ) \
134 typedef typename istack::Types<dhp_value_type>::stack_impl stack_type; \
135 test< stack_type >(); \
138 CDSSTRESS_TreiberStack_DHP( intrusive_stack_push_pop )
140 #undef CDSSTRESS_Stack_F
142 // TreiberStack<cds::gc::HP> + elimination enabled
143 #define CDSSTRESS_Stack_F( test_fixture, stack_impl ) \
144 TEST_F( test_fixture, stack_impl ) \
146 typedef typename istack::Types<hp_value_type>::stack_impl stack_type; \
147 test_elimination< stack_type >(); \
150 CDSSTRESS_EliminationStack_HP( intrusive_stack_push_pop )
152 #undef CDSSTRESS_Stack_F
155 // TreiberStack<cds::gc::DHP> + elimination enabled
156 #define CDSSTRESS_Stack_F( test_fixture, stack_impl ) \
157 TEST_F( test_fixture, stack_impl ) \
159 typedef typename istack::Types<dhp_value_type>::stack_impl stack_type; \
160 test_elimination< stack_type >(); \
163 CDSSTRESS_EliminationStack_DHP( intrusive_stack_push_pop )
165 #undef CDSSTRESS_Stack_F
169 #define CDSSTRESS_Stack_F( test_fixture, stack_impl ) \
170 TEST_F( test_fixture, stack_impl ) \
172 typedef typename istack::Types<value_type>::stack_impl stack_type; \
173 test_std< stack_type >(); \
176 CDSSTRESS_StdStack( intrusive_stack_push_pop )
178 #undef CDSSTRESS_Stack_F
180 //INSTANTIATE_TEST_CASE_P( a, intrusive_stack_push_pop, ::testing::Values(1));