Splitted unit-list test
[libcds.git] / test / unit / intrusive-list / intrusive_michael_dhp.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-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
31 #include "test_intrusive_list_hp.h"
32 #include <cds/intrusive/michael_list_dhp.h>
33
34 namespace {
35     namespace ci = cds::intrusive;
36     typedef cds::gc::DHP gc_type;
37
38     class IntrusiveMichaelList_DHP : public cds_test::intrusive_list_hp
39     {
40     public:
41         typedef cds_test::intrusive_list_hp::base_item< ci::michael_list::node< gc_type>> base_item;
42         typedef cds_test::intrusive_list_hp::member_item< ci::michael_list::node< gc_type>> member_item;
43
44     protected:
45         void SetUp()
46         {
47             struct traits: public ci::michael_list::traits
48             {
49                 typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
50             };
51             typedef ci::MichaelList< gc_type, base_item, traits > list_type;
52
53             cds::gc::dhp::GarbageCollector::Construct( 16, list_type::c_nHazardPtrCount );
54             cds::threading::Manager::attachThread();
55         }
56
57         void TearDown()
58         {
59             cds::threading::Manager::detachThread();
60             cds::gc::dhp::GarbageCollector::Destruct();
61         }
62     };
63
64     TEST_F( IntrusiveMichaelList_DHP, base_hook )
65     {
66         typedef ci::MichaelList< gc_type, base_item,
67             typename ci::michael_list::make_traits< 
68                 ci::opt::hook< ci::michael_list::base_hook< cds::opt::gc< gc_type >>>
69                 ,ci::opt::disposer< mock_disposer >
70                 ,cds::opt::less< less< base_item >>
71             >::type 
72        > list_type;
73
74        list_type l;
75        test_common( l );
76        test_ordered_iterator( l );
77        test_hp( l );
78     }
79
80     TEST_F( IntrusiveMichaelList_DHP, base_hook_cmp )
81     {
82         typedef ci::MichaelList< gc_type, base_item,
83             typename ci::michael_list::make_traits<
84                 ci::opt::hook< ci::michael_list::base_hook< cds::opt::gc< gc_type >>>
85                 , ci::opt::disposer< mock_disposer >
86                 , cds::opt::compare< cmp< base_item >>
87             >::type
88         > list_type;
89
90         list_type l;
91         test_common( l );
92         test_ordered_iterator( l );
93         test_hp( l );
94     }
95
96     TEST_F( IntrusiveMichaelList_DHP, base_hook_item_counting )
97     {
98         struct traits : public ci::michael_list::traits {
99             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
100             typedef mock_disposer disposer;
101             typedef cmp< base_item > compare;
102             typedef intrusive_list_common::less< base_item > less;
103             typedef cds::atomicity::item_counter item_counter;
104         };
105         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
106
107         list_type l;
108         test_common( l );
109         test_ordered_iterator( l );
110         test_hp( l );
111     }
112
113     TEST_F( IntrusiveMichaelList_DHP, base_hook_backoff )
114     {
115         struct traits : public ci::michael_list::traits {
116             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
117             typedef mock_disposer disposer;
118             typedef cmp< base_item > compare;
119             typedef intrusive_list_common::less< base_item > less;
120             typedef cds::atomicity::item_counter item_counter;
121             typedef cds::backoff::pause back_off;
122         };
123         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
124
125         list_type l;
126         test_common( l );
127         test_ordered_iterator( l );
128         test_hp( l );
129     }
130
131     TEST_F( IntrusiveMichaelList_DHP, base_hook_seqcst )
132     {
133         struct traits : public ci::michael_list::traits {
134             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
135             typedef mock_disposer disposer;
136             typedef cmp< base_item > compare;
137             typedef intrusive_list_common::less< base_item > less;
138             typedef cds::atomicity::item_counter item_counter;
139             typedef cds::opt::v::sequential_consistent memory_model;
140         };
141         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
142
143         list_type l;
144         test_common( l );
145         test_ordered_iterator( l );
146         test_hp( l );
147     }
148     TEST_F( IntrusiveMichaelList_DHP, base_hook_stat )
149     {
150         struct traits: public ci::michael_list::traits {
151             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
152             typedef mock_disposer disposer;
153             typedef cmp< base_item > compare;
154             typedef intrusive_list_common::less< base_item > less;
155             typedef cds::intrusive::michael_list::stat<> stat;
156         };
157         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
158
159         list_type l;
160         test_common( l );
161         test_ordered_iterator( l );
162         test_hp( l );
163     }
164
165     TEST_F( IntrusiveMichaelList_DHP, base_hook_wrapped_stat )
166     {
167         struct traits: public ci::michael_list::traits {
168             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
169             typedef mock_disposer disposer;
170             typedef cmp< base_item > compare;
171             typedef cds::intrusive::michael_list::wrapped_stat<> stat;
172         };
173         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
174
175         cds::intrusive::michael_list::stat<> st;
176         list_type l( st );
177         test_common( l );
178         test_ordered_iterator( l );
179         test_hp( l );
180     }
181
182
183     TEST_F( IntrusiveMichaelList_DHP, member_hook )
184     {
185         typedef ci::MichaelList< gc_type, member_item,
186             typename ci::michael_list::make_traits< 
187                 ci::opt::hook< ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >>>
188                 ,ci::opt::disposer< mock_disposer >
189                 ,cds::opt::less< less< member_item >>
190             >::type 
191        > list_type;
192
193        list_type l;
194        test_common( l );
195        test_ordered_iterator( l );
196        test_hp( l );
197     }
198
199     TEST_F( IntrusiveMichaelList_DHP, member_hook_cmp )
200     {
201         typedef ci::MichaelList< gc_type, member_item,
202             typename ci::michael_list::make_traits<
203                 ci::opt::hook< ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >>>
204                 ,ci::opt::disposer< mock_disposer >
205                 ,cds::opt::compare< cmp< member_item >>
206             >::type
207         > list_type;
208
209         list_type l;
210         test_common( l );
211         test_ordered_iterator( l );
212         test_hp( l );
213     }
214
215     TEST_F( IntrusiveMichaelList_DHP, member_hook_item_counting )
216     {
217         struct traits : public ci::michael_list::traits {
218             typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
219             typedef mock_disposer disposer;
220             typedef cmp< member_item > compare;
221             typedef intrusive_list_common::less< member_item > less;
222             typedef cds::atomicity::item_counter item_counter;
223         };
224         typedef ci::MichaelList< gc_type, member_item, traits > list_type;
225
226         list_type l;
227         test_common( l );
228         test_ordered_iterator( l );
229         test_hp( l );
230     }
231
232     TEST_F( IntrusiveMichaelList_DHP, member_hook_seqcst )
233     {
234         struct traits : public ci::michael_list::traits {
235             typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
236             typedef mock_disposer disposer;
237             typedef cmp< member_item > compare;
238             typedef intrusive_list_common::less< member_item > less;
239             typedef cds::atomicity::item_counter item_counter;
240             typedef cds::opt::v::sequential_consistent memory_model;
241         };
242         typedef ci::MichaelList< gc_type, member_item, traits > list_type;
243
244         list_type l;
245         test_common( l );
246         test_ordered_iterator( l );
247         test_hp( l );
248     }
249
250     TEST_F( IntrusiveMichaelList_DHP, member_hook_back_off )
251     {
252         struct traits : public ci::michael_list::traits {
253             typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
254             typedef mock_disposer disposer;
255             typedef cmp< member_item > compare;
256             typedef intrusive_list_common::less< member_item > less;
257             typedef cds::atomicity::item_counter item_counter;
258             typedef cds::backoff::empty back_off;
259         };
260         typedef ci::MichaelList< gc_type, member_item, traits > list_type;
261
262         list_type l;
263         test_common( l );
264         test_ordered_iterator( l );
265         test_hp( l );
266     }
267
268     TEST_F( IntrusiveMichaelList_DHP, member_hook_stat )
269     {
270         struct traits: public ci::michael_list::traits {
271             typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
272             typedef mock_disposer disposer;
273             typedef cmp< member_item > compare;
274             typedef intrusive_list_common::less< member_item > less;
275             typedef cds::intrusive::michael_list::stat<> stat;
276         };
277         typedef ci::MichaelList< gc_type, member_item, traits > list_type;
278
279         list_type l;
280         test_common( l );
281         test_ordered_iterator( l );
282         test_hp( l );
283     }
284
285     TEST_F( IntrusiveMichaelList_DHP, member_hook_wrapped_stat )
286     {
287         struct traits: public ci::michael_list::traits {
288             typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
289             typedef mock_disposer disposer;
290             typedef cmp< member_item > compare;
291             typedef cds::intrusive::michael_list::wrapped_stat<> stat;
292         };
293         typedef ci::MichaelList< gc_type, member_item, traits > list_type;
294
295         cds::intrusive::michael_list::stat<> st;
296         list_type l( st );
297         test_common( l );
298         test_ordered_iterator( l );
299         test_hp( l );
300     }
301
302 } // namespace