Fixed gcc 4.8 incompatibility
[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, member_hook )
148 {
149     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::member_item,
150         typename ci::lazy_list::make_traits< 
151             ci::opt::hook< ci::lazy_list::member_hook< offsetof( typename TestFixture::member_item, hMember ), cds::opt::gc< typename TestFixture::rcu_type >>>
152             ,ci::opt::disposer< typename TestFixture::mock_disposer >
153             ,cds::opt::less< typename TestFixture::template less< typename TestFixture::member_item >>
154         >::type 
155     > list_type;
156
157     list_type l;
158     this->test_common( l );
159     this->test_ordered_iterator( l );
160     this->test_rcu( l );
161 }
162
163 TYPED_TEST_P( IntrusiveLazyList, member_hook_cmp )
164 {
165     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::member_item,
166         typename ci::lazy_list::make_traits<
167             ci::opt::hook< ci::lazy_list::member_hook< offsetof( typename TestFixture::member_item, hMember ), cds::opt::gc< typename TestFixture::rcu_type >>>
168             ,ci::opt::disposer< typename TestFixture::mock_disposer >
169             ,cds::opt::compare< typename TestFixture::template cmp< typename TestFixture::member_item >>
170         >::type
171     > list_type;
172
173     list_type l;
174     this->test_common( l );
175     this->test_ordered_iterator( l );
176     this->test_rcu( l );
177 }
178
179 TYPED_TEST_P( IntrusiveLazyList, member_hook_item_counting )
180 {
181     struct traits : public ci::lazy_list::traits {
182         typedef ci::lazy_list::member_hook< offsetof( typename TestFixture::member_item, hMember ), cds::opt::gc< typename TestFixture::rcu_type >> hook;
183         typedef typename TestFixture::mock_disposer disposer;
184         typedef typename TestFixture::template cmp< typename TestFixture::member_item > compare;
185         typedef typename TestFixture::template less< typename TestFixture::member_item > less;
186         typedef cds::atomicity::item_counter item_counter;
187     };
188     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::member_item, traits > list_type;
189
190     list_type l;
191     this->test_common( l );
192     this->test_ordered_iterator( l );
193     this->test_rcu( l );
194 }
195
196 TYPED_TEST_P( IntrusiveLazyList, member_hook_seqcst )
197 {
198     struct traits : public ci::lazy_list::traits {
199         typedef ci::lazy_list::member_hook< offsetof( typename TestFixture::member_item, hMember ), cds::opt::gc< typename TestFixture::rcu_type >> hook;
200         typedef typename TestFixture::mock_disposer disposer;
201         typedef typename TestFixture::template less< typename TestFixture::member_item > less;
202         typedef cds::atomicity::item_counter item_counter;
203         typedef cds::opt::v::sequential_consistent memory_model;
204     };
205     typedef ci::LazyList< typename TestFixture::rcu_type, typename TestFixture::member_item, traits > list_type;
206
207     list_type l;
208     this->test_common( l );
209     this->test_ordered_iterator( l );
210     this->test_rcu( l );
211 }
212
213 TYPED_TEST_P( IntrusiveLazyList, member_hook_back_off )
214 {
215     struct traits : public ci::lazy_list::traits {
216         typedef ci::lazy_list::member_hook< offsetof( typename TestFixture::member_item, hMember ), cds::opt::gc< typename TestFixture::rcu_type >> hook;
217         typedef typename TestFixture::mock_disposer disposer;
218         typedef typename TestFixture::template cmp< typename TestFixture::member_item > compare;
219         typedef typename TestFixture::template less< typename TestFixture::member_item > less;
220         typedef cds::atomicity::item_counter item_counter;
221         typedef cds::backoff::empty back_off;
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
232 // GCC 5: All test names should be written on single line, otherwise a runtime error will be encountered like as
233 // "No test named <test_name> can be found in this test case"
234 REGISTER_TYPED_TEST_CASE_P( IntrusiveLazyList,
235     base_hook, base_hook_cmp, base_hook_item_counting, base_hook_backoff, base_hook_seqcst, member_hook, member_hook_cmp, member_hook_item_counting, member_hook_seqcst, member_hook_back_off
236 );
237
238
239 #endif // CDSUNIT_LIST_TEST_INTRUSIVE_LAZY_LIST_RCU_H 
240