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