Removed trailing spaces
[libcds.git] / test / unit / set / test_split_michael_rcu.h
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 #ifndef CDSUNIT_SET_TEST_SPLIT_LIST_MICHAEL_RCU_H
31 #define CDSUNIT_SET_TEST_SPLIT_LIST_MICHAEL_RCU_H
32
33 #include "test_set_rcu.h"
34 #include <cds/container/michael_list_rcu.h>
35 #include <cds/container/split_list_set_rcu.h>
36
37 namespace cc = cds::container;
38
39 template <class RCU>
40 class SplitListMichaelSet: public cds_test::container_set_rcu
41 {
42     typedef cds_test::container_set_rcu base_class;
43 public:
44     typedef cds::urcu::gc<RCU> rcu_type;
45
46 protected:
47     void SetUp()
48     {
49         RCU::Construct();
50         cds::threading::Manager::attachThread();
51     }
52
53     void TearDown()
54     {
55         cds::threading::Manager::detachThread();
56         RCU::Destruct();
57     }
58 };
59
60 TYPED_TEST_CASE_P( SplitListMichaelSet );
61
62 TYPED_TEST_P( SplitListMichaelSet, compare )
63 {
64     typedef typename TestFixture::rcu_type rcu_type;
65     typedef typename TestFixture::int_item int_item;
66     typedef typename TestFixture::hash_int hash_int;
67
68     typedef cc::SplitListSet< rcu_type, int_item, 
69         typename cc::split_list::make_traits<
70             cc::split_list::ordered_list< cc::michael_list_tag >
71             , cds::opt::hash< hash_int >
72             , cc::split_list::ordered_list_traits< 
73                 typename cc::michael_list::make_traits<
74                     cds::opt::compare< typename TestFixture::cmp >
75                 >::type
76             >
77         >::type
78     > set_type;
79
80     set_type s( TestFixture::kSize, 2 );
81     this->test( s );
82 }
83
84 TYPED_TEST_P( SplitListMichaelSet, less )
85 {
86     typedef typename TestFixture::rcu_type rcu_type;
87     typedef typename TestFixture::int_item int_item;
88     typedef typename TestFixture::hash_int hash_int;
89
90     typedef cc::SplitListSet< rcu_type, int_item,
91         typename cc::split_list::make_traits<
92             cc::split_list::ordered_list< cc::michael_list_tag >
93             , cds::opt::hash< hash_int >
94             , cc::split_list::ordered_list_traits< 
95                 typename cc::michael_list::make_traits<
96                     cds::opt::less< typename TestFixture::less >
97                 >::type
98             >
99         >::type
100     > set_type;
101
102     set_type s( TestFixture::kSize, 2 );
103     this->test( s );
104 }
105
106 TYPED_TEST_P( SplitListMichaelSet, cmpmix )
107 {
108     typedef typename TestFixture::rcu_type rcu_type;
109     typedef typename TestFixture::int_item int_item;
110     typedef typename TestFixture::hash_int hash_int;
111
112     typedef cc::SplitListSet< rcu_type, int_item,
113         typename cc::split_list::make_traits<
114             cc::split_list::ordered_list< cc::michael_list_tag >
115             , cds::opt::hash< hash_int >
116             , cc::split_list::ordered_list_traits< 
117                 typename cc::michael_list::make_traits<
118                     cds::opt::less< typename TestFixture::less >
119                     , cds::opt::compare< typename TestFixture::cmp >
120                 >::type
121             >
122         >::type
123     > set_type;
124
125     set_type s( TestFixture::kSize, 3 );
126     this->test( s );
127 }
128
129 TYPED_TEST_P( SplitListMichaelSet, item_counting )
130 {
131     typedef typename TestFixture::rcu_type rcu_type;
132     typedef typename TestFixture::int_item int_item;
133     typedef typename TestFixture::hash_int hash_int;
134
135     struct set_traits: public cc::split_list::traits
136     {
137         typedef cc::michael_list_tag ordered_list;
138         typedef hash_int hash;
139         typedef cds::atomicity::item_counter item_counter;
140
141         struct ordered_list_traits: public cc::michael_list::traits
142         {
143             typedef typename TestFixture::cmp compare;
144             typedef typename TestFixture::less less;
145             typedef cds::backoff::empty back_off;
146         };
147     };
148     typedef cc::SplitListSet< rcu_type, int_item, set_traits > set_type;
149
150     set_type s( TestFixture::kSize, 8 );
151     this->test( s );
152 }
153
154 TYPED_TEST_P( SplitListMichaelSet, stat )
155 {
156     typedef typename TestFixture::rcu_type rcu_type;
157     typedef typename TestFixture::int_item int_item;
158     typedef typename TestFixture::hash_int hash_int;
159
160     struct set_traits: public cc::split_list::traits
161     {
162         typedef cc::michael_list_tag ordered_list;
163         typedef hash_int hash;
164         typedef cds::atomicity::item_counter item_counter;
165         typedef cc::split_list::stat<> stat;
166
167         struct ordered_list_traits: public cc::michael_list::traits
168         {
169             typedef typename TestFixture::less less;
170             typedef cds::opt::v::sequential_consistent memory_model;
171         };
172     };
173     typedef cc::SplitListSet< rcu_type, int_item, set_traits > set_type;
174
175     set_type s( TestFixture::kSize, 4 );
176     this->test( s );
177 }
178
179 TYPED_TEST_P( SplitListMichaelSet, back_off )
180 {
181     typedef typename TestFixture::rcu_type rcu_type;
182     typedef typename TestFixture::int_item int_item;
183     typedef typename TestFixture::hash_int hash_int;
184
185     struct set_traits: public cc::split_list::traits
186     {
187         typedef cc::michael_list_tag ordered_list;
188         typedef hash_int hash;
189         typedef cds::atomicity::item_counter item_counter;
190         typedef cds::backoff::yield back_off;
191         typedef cds::opt::v::sequential_consistent memory_model;
192
193         struct ordered_list_traits: public cc::michael_list::traits
194         {
195             typedef typename TestFixture::cmp compare;
196             typedef cds::backoff::pause back_off;
197         };
198     };
199     typedef cc::SplitListSet< rcu_type, int_item, set_traits > set_type;
200
201     set_type s( TestFixture::kSize, 2 );
202     this->test( s );
203 }
204
205 namespace {
206     struct set_static_traits: public cc::split_list::traits
207     {
208         static bool const dynamic_bucket_table = false;
209     };
210 }
211
212 TYPED_TEST_P( SplitListMichaelSet, static_bucket_table )
213 {
214     typedef typename TestFixture::rcu_type rcu_type;
215     typedef typename TestFixture::int_item int_item;
216     typedef typename TestFixture::hash_int hash_int;
217
218     struct set_traits: public set_static_traits
219     {
220         typedef cc::michael_list_tag ordered_list;
221         typedef hash_int hash;
222         typedef cds::atomicity::item_counter item_counter;
223
224         struct ordered_list_traits: public cc::michael_list::traits
225         {
226             typedef typename TestFixture::cmp compare;
227             typedef cds::backoff::pause back_off;
228         };
229     };
230     typedef cc::SplitListSet< rcu_type, int_item, set_traits > set_type;
231
232     set_type s( TestFixture::kSize, 4 );
233     this->test( s );
234 }
235
236
237 // GCC 5: All this->test names should be written on single line, otherwise a runtime error will be encountered like as
238 // "No this->test named <test_name> can be found in this this->test case"
239 REGISTER_TYPED_TEST_CASE_P( SplitListMichaelSet,
240     compare, less, cmpmix, item_counting, stat, back_off, static_bucket_table
241 );
242
243
244 #endif // CDSUNIT_SET_TEST_SPLIT_LIST_MICHAEL_RCU_H
245