abb70ce46daf20b965c9cc968efa64f1ec129756
[libcds.git] / test / stress / stack / intrusive_push_pop_fcstack.cpp
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8     
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
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.
18
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.     
29 */
30
31 #include "intrusive_stack_push_pop.h"
32
33 namespace {
34
35     struct fc_param
36     {
37         unsigned int nCompactFactor;
38         unsigned int nCombinePassCount;
39     };
40
41     static std::vector< fc_param > m_args;
42
43     class intrusive_fcstack_push_pop
44         : public cds_test::intrusive_stack_push_pop
45         , public ::testing::WithParamInterface< fc_param >
46     {
47         typedef cds_test::intrusive_stack_push_pop base_class;
48
49     public:
50         static void SetUpTestCase()
51         {
52             base_class::SetUpTestCase();
53
54             if ( s_bFCIterative ) {
55                 for ( unsigned int nCompactFactor = 1; nCompactFactor <= s_nFCCompactFactor; nCompactFactor *= 2 ) {
56                     for ( unsigned int nPass = 1; nPass <= s_nFCCombinePassCount; nPass *= 2 )
57                         m_args.push_back( { nCompactFactor, nPass } );
58                 }
59             }
60
61             if ( m_args.empty())
62                 m_args.push_back( { 1, 1 } );
63         }
64         static void TearDownTestCase()
65         {
66             m_args.clear();
67         }
68
69     protected:
70         typedef base_class::value_type<boost::intrusive::slist_base_hook<>> slist_value_type;
71         typedef base_class::value_type<boost::intrusive::list_base_hook<>>  list_value_type;
72
73
74         template <typename Stack>
75         void test()
76         {
77             value_array<typename Stack::value_type> arrValue( s_nStackSize );
78             if ( s_bFCIterative ) {
79                 fc_param arg = GetParam();
80                 propout() 
81                     << std::make_pair( "compact_factor", arg.nCompactFactor )
82                     << std::make_pair( "combine_pass_count", arg.nCombinePassCount );
83                 Stack stack( arg.nCompactFactor, arg.nCombinePassCount );
84                 do_test( stack, arrValue );
85             }
86             else {
87                 Stack stack;
88                 do_test( stack, arrValue );
89             }
90         }
91     };
92
93     // FCStack based on boost::intrusive::slist
94 #define CDSSTRESS_Stack_F( test_fixture, stack_impl ) \
95     TEST_P( test_fixture, stack_impl ) \
96     { \
97         typedef typename istack::Types<slist_value_type>::stack_impl stack_type; \
98         test< stack_type >(); \
99     }
100
101     CDSSTRESS_FCStack_slist( intrusive_fcstack_push_pop )
102
103 #undef CDSSTRESS_Stack_F
104
105     // FCStack based on boost::intrusive::list
106 #define CDSSTRESS_Stack_F( test_fixture, stack_impl ) \
107     TEST_P( test_fixture, stack_impl ) \
108     { \
109         typedef typename istack::Types<list_value_type>::stack_impl stack_type; \
110         test< stack_type >(); \
111     }
112
113     CDSSTRESS_FCStack_list( intrusive_fcstack_push_pop )
114
115 #undef CDSSTRESS_Stack_F
116
117 } // namespace
118
119 INSTANTIATE_TEST_CASE_P( FC, intrusive_fcstack_push_pop, ::testing::ValuesIn( m_args ));
120