Removed trailing spaces
[libcds.git] / test / unit / set / test_split_lazy_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_LAZY_RCU_H
31 #define CDSUNIT_SET_TEST_SPLIT_LIST_LAZY_RCU_H
32
33 #include "test_set_rcu.h"
34 #include <cds/container/lazy_list_rcu.h>
35 #include <cds/container/split_list_set_rcu.h>
36 #include <cds/intrusive/free_list.h>
37
38 namespace cc = cds::container;
39
40 template <class RCU>
41 class SplitListLazySet: public cds_test::container_set_rcu
42 {
43     typedef cds_test::container_set_rcu base_class;
44 public:
45     typedef cds::urcu::gc<RCU> rcu_type;
46
47 protected:
48     void SetUp()
49     {
50         RCU::Construct();
51         cds::threading::Manager::attachThread();
52     }
53
54     void TearDown()
55     {
56         cds::threading::Manager::detachThread();
57         RCU::Destruct();
58     }
59 };
60
61 TYPED_TEST_CASE_P( SplitListLazySet );
62
63 //TYPED_TEST_P( SplitListLazySet, compare )
64 TYPED_TEST_P( SplitListLazySet, compare )
65 {
66     typedef typename TestFixture::rcu_type rcu_type;
67     typedef typename TestFixture::int_item int_item;
68     typedef typename TestFixture::hash_int hash_int;
69
70     typedef cc::SplitListSet< rcu_type, int_item,
71         typename cc::split_list::make_traits<
72             cc::split_list::ordered_list< cc::lazy_list_tag >
73             , cds::opt::hash< hash_int >
74             , cc::split_list::ordered_list_traits<
75                 typename cc::lazy_list::make_traits<
76                     cds::opt::compare< typename TestFixture::cmp >
77                 >::type
78             >
79         >::type
80     > set_type;
81
82     set_type s( TestFixture::kSize, 2 );
83     this->test( s );
84 }
85
86 TYPED_TEST_P( SplitListLazySet, less )
87 {
88     typedef typename TestFixture::rcu_type rcu_type;
89     typedef typename TestFixture::int_item int_item;
90     typedef typename TestFixture::hash_int hash_int;
91
92     typedef cc::SplitListSet< rcu_type, int_item,
93         typename cc::split_list::make_traits<
94             cc::split_list::ordered_list< cc::lazy_list_tag >
95             , cds::opt::hash< hash_int >
96             , cc::split_list::ordered_list_traits<
97                 typename cc::lazy_list::make_traits<
98                     cds::opt::less< typename TestFixture::less >
99                 >::type
100             >
101         >::type
102     > set_type;
103
104     set_type s( TestFixture::kSize, 4 );
105     this->test( s );
106 }
107
108 TYPED_TEST_P( SplitListLazySet, cmpmix )
109 {
110     typedef typename TestFixture::rcu_type rcu_type;
111     typedef typename TestFixture::int_item int_item;
112     typedef typename TestFixture::hash_int hash_int;
113
114     typedef cc::SplitListSet< rcu_type, int_item,
115         typename cc::split_list::make_traits<
116             cc::split_list::ordered_list< cc::lazy_list_tag >
117             , cds::opt::hash< hash_int >
118             , cc::split_list::ordered_list_traits<
119                 typename cc::lazy_list::make_traits<
120                     cds::opt::less< typename TestFixture::less >
121                     , cds::opt::compare< typename TestFixture::cmp >
122                 >::type
123             >
124         >::type
125     > set_type;
126
127     set_type s( TestFixture::kSize, 2 );
128     this->test( s );
129 }
130
131 TYPED_TEST_P( SplitListLazySet, item_counting )
132 {
133     typedef typename TestFixture::rcu_type rcu_type;
134     typedef typename TestFixture::int_item int_item;
135     typedef typename TestFixture::hash_int hash_int;
136
137     struct set_traits: public cc::split_list::traits
138     {
139         typedef cc::lazy_list_tag ordered_list;
140         typedef hash_int hash;
141         typedef cds::atomicity::item_counter item_counter;
142
143         struct ordered_list_traits: public cc::lazy_list::traits
144         {
145             typedef typename TestFixture::cmp compare;
146             typedef typename TestFixture::less less;
147             typedef cds::backoff::empty back_off;
148         };
149     };
150     typedef cc::SplitListSet< rcu_type, int_item, set_traits > set_type;
151
152     set_type s( TestFixture::kSize, 1 );
153     this->test( s );
154 }
155
156 TYPED_TEST_P( SplitListLazySet, stat )
157 {
158     typedef typename TestFixture::rcu_type rcu_type;
159     typedef typename TestFixture::int_item int_item;
160     typedef typename TestFixture::hash_int hash_int;
161
162     struct set_traits: public cc::split_list::traits
163     {
164         typedef cc::lazy_list_tag ordered_list;
165         typedef hash_int hash;
166         typedef cds::atomicity::item_counter item_counter;
167         typedef cc::split_list::stat<> stat;
168
169         struct ordered_list_traits: public cc::lazy_list::traits
170         {
171             typedef typename TestFixture::less less;
172             typedef cds::opt::v::sequential_consistent memory_model;
173         };
174     };
175     typedef cc::SplitListSet< rcu_type, int_item, set_traits > set_type;
176
177     set_type s( TestFixture::kSize, 3 );
178     this->test( s );
179 }
180
181 TYPED_TEST_P( SplitListLazySet, back_off )
182 {
183     typedef typename TestFixture::rcu_type rcu_type;
184     typedef typename TestFixture::int_item int_item;
185     typedef typename TestFixture::hash_int hash_int;
186
187     struct set_traits: public cc::split_list::traits
188     {
189         typedef cc::lazy_list_tag ordered_list;
190         typedef hash_int hash;
191         typedef cds::atomicity::item_counter item_counter;
192         typedef cds::backoff::yield back_off;
193         typedef cds::opt::v::sequential_consistent memory_model;
194
195         struct ordered_list_traits: public cc::lazy_list::traits
196         {
197             typedef typename TestFixture::cmp compare;
198             typedef cds::backoff::pause back_off;
199         };
200     };
201     typedef cc::SplitListSet< rcu_type, int_item, set_traits > set_type;
202
203     set_type s( TestFixture::kSize, 2 );
204     this->test( s );
205 }
206
207 TYPED_TEST_P( SplitListLazySet, mutex )
208 {
209     typedef typename TestFixture::rcu_type rcu_type;
210     typedef typename TestFixture::int_item int_item;
211     typedef typename TestFixture::hash_int hash_int;
212
213     struct set_traits: public cc::split_list::traits
214     {
215         typedef cc::lazy_list_tag ordered_list;
216         typedef hash_int hash;
217         typedef cds::atomicity::item_counter item_counter;
218         typedef cds::backoff::yield back_off;
219         typedef cds::opt::v::sequential_consistent memory_model;
220
221         struct ordered_list_traits: public cc::lazy_list::traits
222         {
223             typedef typename TestFixture::cmp compare;
224             typedef cds::backoff::pause back_off;
225             typedef std::mutex lock_type;
226         };
227     };
228     typedef cc::SplitListSet< rcu_type, int_item, set_traits > set_type;
229
230     set_type s( TestFixture::kSize, 2 );
231     this->test( s );
232 }
233
234 namespace {
235     struct set_static_traits: public cc::split_list::traits
236     {
237         static bool const dynamic_bucket_table = false;
238     };
239 }
240
241 TYPED_TEST_P( SplitListLazySet, static_bucket_table )
242 {
243     typedef typename TestFixture::rcu_type rcu_type;
244     typedef typename TestFixture::int_item int_item;
245     typedef typename TestFixture::hash_int hash_int;
246
247     struct set_traits: public set_static_traits
248     {
249         typedef cc::lazy_list_tag ordered_list;
250         typedef hash_int hash;
251         typedef cds::atomicity::item_counter item_counter;
252
253         struct ordered_list_traits: public cc::lazy_list::traits
254         {
255             typedef typename TestFixture::cmp compare;
256             typedef cds::backoff::pause back_off;
257         };
258     };
259     typedef cc::SplitListSet< rcu_type, int_item, set_traits > set_type;
260
261     set_type s( TestFixture::kSize, 4 );
262     this->test( s );
263 }
264
265 TYPED_TEST_P( SplitListLazySet, free_list )
266 {
267     typedef typename TestFixture::rcu_type rcu_type;
268     typedef typename TestFixture::int_item int_item;
269     typedef typename TestFixture::hash_int hash_int;
270
271     typedef cc::SplitListSet< rcu_type, int_item,
272         typename cc::split_list::make_traits<
273             cc::split_list::ordered_list< cc::lazy_list_tag >
274             , cds::opt::hash< hash_int >
275             , cc::split_list::ordered_list_traits<
276                 typename cc::lazy_list::make_traits<
277                     cds::opt::less< typename TestFixture::less >
278                 >::type
279             >
280             , cds::opt::free_list< cds::intrusive::FreeList >
281         >::type
282     > set_type;
283
284     set_type s( TestFixture::kSize, 4 );
285     this->test( s );
286 }
287
288 TYPED_TEST_P( SplitListLazySet, static_bucket_table_free_list )
289 {
290     typedef typename TestFixture::rcu_type rcu_type;
291     typedef typename TestFixture::int_item int_item;
292     typedef typename TestFixture::hash_int hash_int;
293
294     struct set_traits: public set_static_traits
295     {
296         typedef cc::lazy_list_tag ordered_list;
297         typedef hash_int hash;
298         typedef cds::atomicity::item_counter item_counter;
299         typedef cds::intrusive::FreeList free_list;
300
301         struct ordered_list_traits: public cc::lazy_list::traits
302         {
303             typedef typename TestFixture::cmp compare;
304             typedef cds::backoff::pause back_off;
305         };
306     };
307     typedef cc::SplitListSet< rcu_type, int_item, set_traits > set_type;
308
309     set_type s( TestFixture::kSize, 2 );
310     this->test( s );
311 }
312
313 // GCC 5: All this->test names should be written on single line, otherwise a runtime error will be encountered like as
314 // "No this->test named <test_name> can be found in this this->test case"
315 REGISTER_TYPED_TEST_CASE_P( SplitListLazySet,
316     compare, less, cmpmix, item_counting, stat, back_off, mutex, static_bucket_table, free_list, static_bucket_table_free_list
317 );
318
319
320 #endif // CDSUNIT_SET_TEST_SPLIT_LIST_LAZY_RCU_H
321