Updated copyright
[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-2017
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     class intrusive_fcstack_push_pop
42         : public cds_test::intrusive_stack_push_pop
43         , public ::testing::WithParamInterface< fc_param >
44     {
45         typedef cds_test::intrusive_stack_push_pop base_class;
46
47     public:
48
49         static std::vector< fc_param > get_test_parameters()
50         {
51             cds_test::config const& cfg = cds_test::stress_fixture::get_config( "IntrusiveStack_PushPop" );
52             bool bFCIterative = cfg.get_bool( "FCIterate", s_bFCIterative );
53             unsigned int nFCCombinePassCount = cfg.get_uint( "FCCombinePassCount", s_nFCCombinePassCount );
54             unsigned int nFCCompactFactor = cfg.get_uint( "FCCompactFactor", s_nFCCompactFactor );
55
56             std::vector< fc_param > args;
57             if ( bFCIterative ) {
58                 for ( unsigned int nCompactFactor = 1; nCompactFactor <= nFCCompactFactor; nCompactFactor *= 2 ) {
59                     for ( unsigned int nPass = 1; nPass <= nFCCombinePassCount; nPass *= 2 )
60                         args.push_back( { nCompactFactor, nPass } );
61                 }
62             }
63
64             if ( args.empty()) {
65                 if ( nFCCompactFactor && nFCCombinePassCount )
66                     args.push_back( { nFCCompactFactor, nFCCombinePassCount } );
67                 else
68                     args.push_back( { 0, 0 } );
69             }
70
71             return args;
72         }
73
74 #ifdef CDSTEST_GTEST_INSTANTIATE_TEST_CASE_P_HAS_4TH_ARG
75         static std::string get_test_parameter_name( testing::TestParamInfo<fc_param> const& p )
76         {
77             if ( p.param.nCombinePassCount ) {
78                 std::stringstream ss;
79                 ss << "compact_factor" << p.param.nCompactFactor
80                    << "__combine_pass_count" << p.param.nCombinePassCount
81 ;
82                 return ss.str();
83             }
84             else {
85                 return std::string( "with_defaults" );
86             }
87         }
88 #endif
89
90     protected:
91         typedef base_class::value_type<boost::intrusive::slist_base_hook<>> slist_value_type;
92         typedef base_class::value_type<boost::intrusive::list_base_hook<>>  list_value_type;
93
94         template <typename Stack>
95         void test()
96         {
97             value_array<typename Stack::value_type> arrValue( s_nStackSize );
98             if ( s_bFCIterative ) {
99                 fc_param arg = GetParam();
100                 if ( arg.nCombinePassCount ) {
101                     propout()
102                         << std::make_pair( "compact_factor", arg.nCompactFactor )
103                         << std::make_pair( "combine_pass_count", arg.nCombinePassCount );
104                     Stack stack( arg.nCompactFactor, arg.nCombinePassCount );
105                     do_test( stack, arrValue );
106                 }
107                 else {
108                     Stack stack;
109                     do_test( stack, arrValue );
110                 }
111             }
112             else {
113                 fc_param arg = GetParam();
114                 if ( arg.nCombinePassCount ) {
115                     propout()
116                         << std::make_pair( "compact_factor", arg.nCompactFactor )
117                         << std::make_pair( "combine_pass_count", arg.nCombinePassCount );
118                     Stack stack( arg.nCompactFactor, arg.nCombinePassCount );
119                     do_test( stack, arrValue );
120                 }
121                 else {
122                     Stack stack;
123                     do_test( stack, arrValue );
124                 }
125             }
126         }
127     };
128
129     // FCStack based on boost::intrusive::slist
130 #define CDSSTRESS_Stack_F( test_fixture, stack_impl ) \
131     TEST_P( test_fixture, stack_impl ) \
132     { \
133         typedef typename istack::Types<slist_value_type>::stack_impl stack_type; \
134         test< stack_type >(); \
135     }
136
137     CDSSTRESS_FCStack_slist( intrusive_fcstack_push_pop )
138
139 #undef CDSSTRESS_Stack_F
140
141     // FCStack based on boost::intrusive::list
142 #define CDSSTRESS_Stack_F( test_fixture, stack_impl ) \
143     TEST_P( test_fixture, stack_impl ) \
144     { \
145         typedef typename istack::Types<list_value_type>::stack_impl stack_type; \
146         test< stack_type >(); \
147     }
148
149     CDSSTRESS_FCStack_list( intrusive_fcstack_push_pop )
150
151 #undef CDSSTRESS_Stack_F
152
153 } // namespace
154
155 #ifdef CDSTEST_GTEST_INSTANTIATE_TEST_CASE_P_HAS_4TH_ARG
156 INSTANTIATE_TEST_CASE_P( FC,
157     intrusive_fcstack_push_pop,
158     ::testing::ValuesIn( intrusive_fcstack_push_pop::get_test_parameters()),
159     intrusive_fcstack_push_pop::get_test_parameter_name );
160 #else
161 INSTANTIATE_TEST_CASE_P( FC,
162     intrusive_fcstack_push_pop,
163     ::testing::ValuesIn( intrusive_fcstack_push_pop::get_test_parameters()));
164 #endif
165