Merged branch 'master' of https://github.com/Nemo1369/libcds
[libcds.git] / test / unit / intrusive-set / test_intrusive_michael_michael_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-2017
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_INTRUSIVE_MICHAEL_MICHAEL_RCU_H
31 #define CDSUNIT_SET_TEST_INTRUSIVE_MICHAEL_MICHAEL_RCU_H
32
33 #include "test_intrusive_set_rcu.h"
34 #include <cds/intrusive/michael_list_rcu.h>
35 #include <cds/intrusive/michael_set_rcu.h>
36
37 namespace ci = cds::intrusive;
38
39 template <class RCU>
40 class IntrusiveMichaelSet: public cds_test::intrusive_set_rcu
41 {
42     typedef cds_test::intrusive_set_rcu base_class;
43 public:
44     typedef cds::urcu::gc<RCU> rcu_type;
45     typedef typename base_class::base_int_item< ci::michael_list::node<rcu_type>>   base_item_type;
46     typedef typename base_class::member_int_item< ci::michael_list::node<rcu_type>> member_item_type;
47
48 protected:
49     void SetUp()
50     {
51         RCU::Construct();
52         cds::threading::Manager::attachThread();
53     }
54
55     void TearDown()
56     {
57         cds::threading::Manager::detachThread();
58         RCU::Destruct();
59     }
60 };
61
62 TYPED_TEST_CASE_P( IntrusiveMichaelSet );
63
64 TYPED_TEST_P( IntrusiveMichaelSet, base_cmp )
65 {
66     typedef typename TestFixture::rcu_type rcu_type;
67     typedef typename TestFixture::base_item_type base_item_type;
68     typedef typename TestFixture::mock_disposer mock_disposer;
69     typedef typename TestFixture::template cmp<base_item_type> cmp;
70     typedef typename TestFixture::hash_int hash_int;
71
72     typedef ci::MichaelList< rcu_type
73         , base_item_type
74         , typename ci::michael_list::make_traits<
75             ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< rcu_type > > >
76             , ci::opt::compare< cmp >
77             , ci::opt::disposer< mock_disposer >
78         >::type
79     > bucket_type;
80
81     typedef ci::MichaelHashSet< rcu_type, bucket_type,
82         typename ci::michael_set::make_traits<
83             ci::opt::hash< hash_int >
84         >::type
85     > set_type;
86
87     set_type s( TestFixture::kSize, 2 );
88     this->test( s );
89 }
90
91 TYPED_TEST_P( IntrusiveMichaelSet, base_less )
92 {
93     typedef typename TestFixture::rcu_type rcu_type;
94     typedef typename TestFixture::base_item_type base_item_type;
95     typedef typename TestFixture::mock_disposer mock_disposer;
96     typedef typename TestFixture::template less<base_item_type> less;
97     typedef typename TestFixture::hash_int hash_int;
98
99     typedef ci::MichaelList< rcu_type
100         , base_item_type
101         , typename ci::michael_list::make_traits<
102             ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< rcu_type >>>
103             , ci::opt::less< less >
104             , ci::opt::disposer< mock_disposer >
105         >::type
106     > bucket_type;
107
108     typedef ci::MichaelHashSet< rcu_type, bucket_type,
109         typename ci::michael_set::make_traits<
110             ci::opt::hash< hash_int >
111         >::type
112     > set_type;
113
114     set_type s( TestFixture::kSize, 2 );
115     this->test( s );
116 }
117
118 TYPED_TEST_P( IntrusiveMichaelSet, base_cmpmix )
119 {
120     typedef typename TestFixture::rcu_type rcu_type;
121     typedef typename TestFixture::base_item_type base_item_type;
122     typedef typename TestFixture::mock_disposer mock_disposer;
123     typedef typename TestFixture::hash_int hash_int;
124
125     struct list_traits : public ci::michael_list::traits
126     {
127         typedef ci::michael_list::base_hook< ci::opt::gc<rcu_type>> hook;
128         typedef typename TestFixture::template less<base_item_type> less;
129         typedef typename TestFixture::template cmp<base_item_type> compare;
130         typedef mock_disposer disposer;
131     };
132     typedef ci::MichaelList< rcu_type, base_item_type, list_traits > bucket_type;
133
134     struct set_traits : public ci::michael_set::traits
135     {
136         typedef hash_int hash;
137         typedef typename TestFixture::simple_item_counter item_counter;
138     };
139     typedef ci::MichaelHashSet< rcu_type, bucket_type, set_traits > set_type;
140
141     set_type s( TestFixture::kSize, 2 );
142     this->test( s );
143 }
144
145 TYPED_TEST_P( IntrusiveMichaelSet, base_stat )
146 {
147     typedef typename TestFixture::rcu_type rcu_type;
148     typedef typename TestFixture::base_item_type base_item_type;
149     typedef typename TestFixture::mock_disposer mock_disposer;
150     typedef typename TestFixture::hash_int hash_int;
151
152     struct list_traits: public ci::michael_list::traits
153     {
154         typedef ci::michael_list::base_hook< ci::opt::gc<rcu_type>> hook;
155         typedef typename TestFixture::template less<base_item_type> less;
156         typedef typename TestFixture::template cmp<base_item_type> compare;
157         typedef mock_disposer disposer;
158         typedef ci::michael_list::stat<> stat;
159     };
160     typedef ci::MichaelList< rcu_type, base_item_type, list_traits > bucket_type;
161
162     struct set_traits: public ci::michael_set::traits
163     {
164         typedef hash_int hash;
165         typedef typename TestFixture::simple_item_counter item_counter;
166     };
167     typedef ci::MichaelHashSet< rcu_type, bucket_type, set_traits > set_type;
168
169     set_type s( TestFixture::kSize, 2 );
170     this->test( s );
171     EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
172 }
173
174 TYPED_TEST_P( IntrusiveMichaelSet, base_wrapped_stat )
175 {
176     typedef typename TestFixture::rcu_type rcu_type;
177     typedef typename TestFixture::base_item_type base_item_type;
178     typedef typename TestFixture::mock_disposer mock_disposer;
179     typedef typename TestFixture::hash_int hash_int;
180
181     struct list_traits: public ci::michael_list::traits
182     {
183         typedef ci::michael_list::base_hook< ci::opt::gc<rcu_type>> hook;
184         typedef typename TestFixture::template less<base_item_type> less;
185         typedef typename TestFixture::template cmp<base_item_type> compare;
186         typedef mock_disposer disposer;
187         typedef ci::michael_list::wrapped_stat<> stat;
188     };
189     typedef ci::MichaelList< rcu_type, base_item_type, list_traits > bucket_type;
190
191     struct set_traits: public ci::michael_set::traits
192     {
193         typedef hash_int hash;
194         typedef typename TestFixture::simple_item_counter item_counter;
195     };
196     typedef ci::MichaelHashSet< rcu_type, bucket_type, set_traits > set_type;
197
198     set_type s( TestFixture::kSize, 2 );
199     this->test( s );
200     EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
201 }
202
203 TYPED_TEST_P( IntrusiveMichaelSet, member_cmp )
204 {
205     typedef typename TestFixture::rcu_type rcu_type;
206     typedef typename TestFixture::member_item_type member_item_type;
207     typedef typename TestFixture::mock_disposer mock_disposer;
208     typedef typename TestFixture::template cmp<member_item_type> cmp;
209     typedef typename TestFixture::hash_int hash_int;
210
211     typedef ci::MichaelList< rcu_type
212         , member_item_type
213         , typename ci::michael_list::make_traits<
214             ci::opt::hook< ci::michael_list::member_hook<
215                 offsetof( member_item_type, hMember ),
216                 ci::opt::gc<rcu_type>
217             >>
218             , ci::opt::compare< cmp >
219             , ci::opt::disposer< mock_disposer >
220         >::type
221     >    bucket_type;
222
223     typedef ci::MichaelHashSet< rcu_type, bucket_type,
224         typename ci::michael_set::make_traits<
225             ci::opt::hash< hash_int >
226         >::type
227     > set_type;
228
229     set_type s( TestFixture::kSize, 2 );
230     this->test( s );
231 }
232
233 TYPED_TEST_P( IntrusiveMichaelSet, member_less )
234 {
235     typedef typename TestFixture::rcu_type rcu_type;
236     typedef typename TestFixture::member_item_type member_item_type;
237     typedef typename TestFixture::mock_disposer mock_disposer;
238     typedef typename TestFixture::template less<member_item_type> less;
239     typedef typename TestFixture::hash_int hash_int;
240
241     typedef ci::MichaelList< rcu_type
242         , member_item_type
243         , typename ci::michael_list::make_traits<
244             ci::opt::hook< ci::michael_list::member_hook<
245                 offsetof( member_item_type, hMember ),
246                 ci::opt::gc<rcu_type>
247             > >
248             , ci::opt::less< less >
249             , ci::opt::disposer< mock_disposer >
250         >::type
251     > bucket_type;
252
253     typedef ci::MichaelHashSet< rcu_type, bucket_type,
254         typename ci::michael_set::make_traits<
255             ci::opt::hash< hash_int >
256         >::type
257     > set_type;
258
259     set_type s( TestFixture::kSize, 2 );
260     this->test( s );
261 }
262
263 TYPED_TEST_P( IntrusiveMichaelSet, member_cmpmix )
264 {
265     typedef typename TestFixture::rcu_type rcu_type;
266     typedef typename TestFixture::member_item_type member_item_type;
267     typedef typename TestFixture::mock_disposer mock_disposer;
268     typedef typename TestFixture::hash_int hash_int;
269
270     struct list_traits : public ci::michael_list::traits
271     {
272         typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<rcu_type>> hook;
273         typedef typename TestFixture::template less<member_item_type> less;
274         typedef typename TestFixture::template cmp<member_item_type> compare;
275         typedef mock_disposer disposer;
276     };
277     typedef ci::MichaelList< rcu_type, member_item_type, list_traits > bucket_type;
278
279     struct set_traits : public ci::michael_set::traits
280     {
281         typedef hash_int hash;
282         typedef typename TestFixture::simple_item_counter item_counter;
283     };
284     typedef ci::MichaelHashSet< rcu_type, bucket_type, set_traits > set_type;
285
286     set_type s( TestFixture::kSize, 2 );
287     this->test( s );
288 }
289
290 TYPED_TEST_P( IntrusiveMichaelSet, member_stat )
291 {
292     typedef typename TestFixture::rcu_type rcu_type;
293     typedef typename TestFixture::member_item_type member_item_type;
294     typedef typename TestFixture::mock_disposer mock_disposer;
295     typedef typename TestFixture::hash_int hash_int;
296
297     struct list_traits: public ci::michael_list::traits
298     {
299         typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<rcu_type>> hook;
300         typedef typename TestFixture::template cmp<member_item_type> compare;
301         typedef mock_disposer disposer;
302         typedef ci::michael_list::stat<> stat;
303     };
304     typedef ci::MichaelList< rcu_type, member_item_type, list_traits > bucket_type;
305
306     struct set_traits: public ci::michael_set::traits
307     {
308         typedef hash_int hash;
309         typedef typename TestFixture::simple_item_counter item_counter;
310     };
311     typedef ci::MichaelHashSet< rcu_type, bucket_type, set_traits > set_type;
312
313     set_type s( TestFixture::kSize, 2 );
314     this->test( s );
315     EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
316 }
317
318 TYPED_TEST_P( IntrusiveMichaelSet, member_wrapped_stat )
319 {
320     typedef typename TestFixture::rcu_type rcu_type;
321     typedef typename TestFixture::member_item_type member_item_type;
322     typedef typename TestFixture::mock_disposer mock_disposer;
323     typedef typename TestFixture::hash_int hash_int;
324
325     struct list_traits: public ci::michael_list::traits
326     {
327         typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<rcu_type>> hook;
328         typedef typename TestFixture::template cmp<member_item_type> compare;
329         typedef mock_disposer disposer;
330         typedef ci::michael_list::wrapped_stat<> stat;
331     };
332     typedef ci::MichaelList< rcu_type, member_item_type, list_traits > bucket_type;
333
334     struct set_traits: public ci::michael_set::traits
335     {
336         typedef hash_int hash;
337         typedef typename TestFixture::simple_item_counter item_counter;
338     };
339     typedef ci::MichaelHashSet< rcu_type, bucket_type, set_traits > set_type;
340
341     set_type s( TestFixture::kSize, 2 );
342     this->test( s );
343     EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
344 }
345
346 // GCC 5: All test names should be written on single line, otherwise a runtime error will be encountered like as
347 // "No test named <test_name> can be found in this test case"
348 REGISTER_TYPED_TEST_CASE_P( IntrusiveMichaelSet,
349     base_cmp, base_less, base_cmpmix, base_stat, base_wrapped_stat, member_cmp, member_less, member_cmpmix, member_stat, member_wrapped_stat
350 );
351
352
353 #endif // CDSUNIT_SET_TEST_INTRUSIVE_MICHAEL_MICHAEL_RCU_H
354