Fixed Clang 3.7 + libc++ issues
[libcds.git] / test / unit / list / test_intrusive_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_LIST_TEST_INTRUSIVE_LAZY_LIST_RCU_H
31 #define CDSUNIT_LIST_TEST_INTRUSIVE_LAZY_LIST_RCU_H
32
33 #include "test_intrusive_list_rcu.h"
34 #include <cds/intrusive/lazy_list_rcu.h>
35
36 namespace ci = cds::intrusive;
37
38 template <class RCU>
39 class IntrusiveLazyList : public cds_test::intrusive_list_rcu
40 {
41     typedef cds_test::intrusive_list_rcu base_class;
42 public:
43     typedef cds::urcu::gc<RCU> rcu_type;
44     typedef typename base_class::base_item< ci::lazy_list::node< rcu_type >> base_item;
45     typedef typename base_class::member_item< ci::lazy_list::node< rcu_type >> member_item;
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( IntrusiveLazyList );
62
63 TYPED_TEST_P( IntrusiveLazyList, base_hook )
64 {
65     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::base_item,
66         typename ci::lazy_list::make_traits<
67             ci::opt::hook< ci::lazy_list::base_hook< cds::opt::gc< typename TestFixture::rcu_type >>>
68             , ci::opt::disposer< typename TestFixture::mock_disposer >
69             , cds::opt::less< typename TestFixture::template less< typename TestFixture::base_item >>
70         >::type
71     > list_type;
72
73     list_type l;
74     this->test_common( l );
75     this->test_ordered_iterator( l );
76     this->test_rcu( l );
77 }
78
79 TYPED_TEST_P( IntrusiveLazyList, base_hook_cmp )
80 {
81     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::base_item,
82         typename ci::lazy_list::make_traits<
83             ci::opt::hook< ci::lazy_list::base_hook< cds::opt::gc< typename TestFixture::rcu_type >>>
84             , ci::opt::disposer< typename TestFixture::mock_disposer >
85             , cds::opt::compare< typename TestFixture::template cmp< typename TestFixture::base_item >>
86         >::type
87     > list_type;
88
89     list_type l;
90     this->test_common( l );
91     this->test_ordered_iterator( l );
92     this->test_rcu( l );
93 }
94
95 TYPED_TEST_P( IntrusiveLazyList, base_hook_item_counting )
96 {
97     struct traits : public ci::lazy_list::traits {
98         typedef ci::lazy_list::base_hook< cds::opt::gc< typename TestFixture::rcu_type >> hook;
99         typedef typename TestFixture::mock_disposer disposer;
100         typedef typename TestFixture::template cmp< typename TestFixture::base_item > compare;
101         typedef typename TestFixture::template less< typename TestFixture::base_item > less;
102         typedef cds::atomicity::item_counter item_counter;
103     };
104     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::base_item, traits > list_type;
105
106     list_type l;
107     this->test_common( l );
108     this->test_ordered_iterator( l );
109     this->test_rcu( l );
110 }
111
112 TYPED_TEST_P( IntrusiveLazyList, base_hook_backoff )
113 {
114     struct traits : public ci::lazy_list::traits {
115         typedef ci::lazy_list::base_hook< cds::opt::gc< typename TestFixture::rcu_type >> hook;
116         typedef typename TestFixture::mock_disposer disposer;
117         typedef typename TestFixture::template cmp< typename TestFixture::base_item > compare;
118         typedef typename TestFixture::template less< typename TestFixture::base_item > less;
119         typedef cds::atomicity::item_counter item_counter;
120         typedef cds::backoff::pause back_off;
121     };
122     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::base_item, traits > list_type;
123
124     list_type l;
125     this->test_common( l );
126     this->test_ordered_iterator( l );
127     this->test_rcu( l );
128 }
129
130 TYPED_TEST_P( IntrusiveLazyList, base_hook_seqcst )
131 {
132     struct traits : public ci::lazy_list::traits {
133         typedef ci::lazy_list::base_hook< cds::opt::gc< typename TestFixture::rcu_type >> hook;
134         typedef typename TestFixture::mock_disposer disposer;
135         typedef typename TestFixture::template cmp< typename TestFixture::base_item > compare;
136         typedef cds::atomicity::item_counter item_counter;
137         typedef cds::opt::v::sequential_consistent memory_model;
138     };
139     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::base_item, traits > list_type;
140
141     list_type l;
142     this->test_common( l );
143     this->test_ordered_iterator( l );
144     this->test_rcu( l );
145 }
146
147 TYPED_TEST_P( IntrusiveLazyList, base_hook_stat )
148 {
149     struct traits: public ci::lazy_list::traits {
150         typedef ci::lazy_list::base_hook< cds::opt::gc< typename TestFixture::rcu_type >> hook;
151         typedef typename TestFixture::mock_disposer disposer;
152         typedef typename TestFixture::template cmp< typename TestFixture::base_item > compare;
153         typedef cds::atomicity::item_counter item_counter;
154         typedef cds::intrusive::lazy_list::stat<> stat;
155     };
156     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::base_item, traits > list_type;
157
158     list_type l;
159     this->test_common( l );
160     this->test_ordered_iterator( l );
161     this->test_rcu( l );
162 }
163
164 TYPED_TEST_P( IntrusiveLazyList, base_hook_wrapped_stat )
165 {
166     struct traits: public ci::lazy_list::traits {
167         typedef ci::lazy_list::base_hook< cds::opt::gc< typename TestFixture::rcu_type >> hook;
168         typedef typename TestFixture::mock_disposer disposer;
169         typedef typename TestFixture::template cmp< typename TestFixture::base_item > compare;
170         typedef cds::atomicity::item_counter item_counter;
171         typedef cds::intrusive::lazy_list::wrapped_stat<> stat;
172     };
173     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::base_item, traits > list_type;
174
175     cds::intrusive::lazy_list::stat<> st;
176     list_type l( st );
177     this->test_common( l );
178     this->test_ordered_iterator( l );
179     this->test_rcu( l );
180 }
181
182 TYPED_TEST_P( IntrusiveLazyList, member_hook )
183 {
184     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::member_item,
185         typename ci::lazy_list::make_traits< 
186             ci::opt::hook< ci::lazy_list::member_hook< offsetof( typename TestFixture::member_item, hMember ), cds::opt::gc< typename TestFixture::rcu_type >>>
187             ,ci::opt::disposer< typename TestFixture::mock_disposer >
188             ,cds::opt::less< typename TestFixture::template less< typename TestFixture::member_item >>
189         >::type 
190     > list_type;
191
192     list_type l;
193     this->test_common( l );
194     this->test_ordered_iterator( l );
195     this->test_rcu( l );
196 }
197
198 TYPED_TEST_P( IntrusiveLazyList, member_hook_cmp )
199 {
200     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::member_item,
201         typename ci::lazy_list::make_traits<
202             ci::opt::hook< ci::lazy_list::member_hook< offsetof( typename TestFixture::member_item, hMember ), cds::opt::gc< typename TestFixture::rcu_type >>>
203             ,ci::opt::disposer< typename TestFixture::mock_disposer >
204             ,cds::opt::compare< typename TestFixture::template cmp< typename TestFixture::member_item >>
205         >::type
206     > list_type;
207
208     list_type l;
209     this->test_common( l );
210     this->test_ordered_iterator( l );
211     this->test_rcu( l );
212 }
213
214 TYPED_TEST_P( IntrusiveLazyList, member_hook_item_counting )
215 {
216     struct traits : public ci::lazy_list::traits {
217         typedef ci::lazy_list::member_hook< offsetof( typename TestFixture::member_item, hMember ), cds::opt::gc< typename TestFixture::rcu_type >> hook;
218         typedef typename TestFixture::mock_disposer disposer;
219         typedef typename TestFixture::template cmp< typename TestFixture::member_item > compare;
220         typedef typename TestFixture::template less< typename TestFixture::member_item > less;
221         typedef cds::atomicity::item_counter item_counter;
222     };
223     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::member_item, traits > list_type;
224
225     list_type l;
226     this->test_common( l );
227     this->test_ordered_iterator( l );
228     this->test_rcu( l );
229 }
230
231 TYPED_TEST_P( IntrusiveLazyList, member_hook_seqcst )
232 {
233     struct traits : public ci::lazy_list::traits {
234         typedef ci::lazy_list::member_hook< offsetof( typename TestFixture::member_item, hMember ), cds::opt::gc< typename TestFixture::rcu_type >> hook;
235         typedef typename TestFixture::mock_disposer disposer;
236         typedef typename TestFixture::template less< typename TestFixture::member_item > less;
237         typedef cds::atomicity::item_counter item_counter;
238         typedef cds::opt::v::sequential_consistent memory_model;
239     };
240     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::member_item, traits > list_type;
241
242     list_type l;
243     this->test_common( l );
244     this->test_ordered_iterator( l );
245     this->test_rcu( l );
246 }
247
248 TYPED_TEST_P( IntrusiveLazyList, member_hook_back_off )
249 {
250     struct traits : public ci::lazy_list::traits {
251         typedef ci::lazy_list::member_hook< offsetof( typename TestFixture::member_item, hMember ), cds::opt::gc< typename TestFixture::rcu_type >> hook;
252         typedef typename TestFixture::mock_disposer disposer;
253         typedef typename TestFixture::template cmp< typename TestFixture::member_item > compare;
254         typedef typename TestFixture::template less< typename TestFixture::member_item > less;
255         typedef cds::atomicity::item_counter item_counter;
256         typedef cds::backoff::empty back_off;
257     };
258     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::member_item, traits > list_type;
259
260     list_type l;
261     this->test_common( l );
262     this->test_ordered_iterator( l );
263     this->test_rcu( l );
264 }
265
266 TYPED_TEST_P( IntrusiveLazyList, member_hook_stat )
267 {
268     struct traits: public ci::lazy_list::traits {
269         typedef ci::lazy_list::member_hook< offsetof( typename TestFixture::member_item, hMember ), cds::opt::gc< typename TestFixture::rcu_type >> hook;
270         typedef typename TestFixture::mock_disposer disposer;
271         typedef typename TestFixture::template cmp< typename TestFixture::member_item > compare;
272         typedef typename TestFixture::template less< typename TestFixture::member_item > less;
273         typedef cds::atomicity::item_counter item_counter;
274         typedef cds::intrusive::lazy_list::stat<> stat;
275     };
276     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::member_item, traits > list_type;
277
278     list_type l;
279     this->test_common( l );
280     this->test_ordered_iterator( l );
281     this->test_rcu( l );
282 }
283
284 TYPED_TEST_P( IntrusiveLazyList, member_hook_wrapped_stat )
285 {
286     struct traits: public ci::lazy_list::traits {
287         typedef ci::lazy_list::member_hook< offsetof( typename TestFixture::member_item, hMember ), cds::opt::gc< typename TestFixture::rcu_type >> hook;
288         typedef typename TestFixture::mock_disposer disposer;
289         typedef typename TestFixture::template cmp< typename TestFixture::member_item > compare;
290         typedef cds::atomicity::item_counter item_counter;
291         typedef cds::intrusive::lazy_list::wrapped_stat<> stat;
292     };
293     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::member_item, traits > list_type;
294
295     cds::intrusive::lazy_list::stat<> st;
296     list_type l( st );
297     this->test_common( l );
298     this->test_ordered_iterator( l );
299     this->test_rcu( l );
300 }
301
302 // GCC 5: All test names should be written on single line, otherwise a runtime error will be encountered like as
303 // "No test named <test_name> can be found in this test case"
304 REGISTER_TYPED_TEST_CASE_P( IntrusiveLazyList,
305     base_hook, base_hook_cmp, base_hook_item_counting, base_hook_backoff, base_hook_seqcst, base_hook_stat, base_hook_wrapped_stat, member_hook, member_hook_cmp, member_hook_item_counting, member_hook_seqcst, member_hook_back_off, member_hook_stat, member_hook_wrapped_stat
306 );
307
308
309 #endif // CDSUNIT_LIST_TEST_INTRUSIVE_LAZY_LIST_RCU_H 
310