Migrated intrusive FeldmanHashSet unit test to gtest framework
[libcds.git] / test / unit / set / test_intrusive_split_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-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_SET_TEST_INTRUSIVE_SPLIT_MICHAEL_RCU_H
31 #define CDSUNIT_SET_TEST_INTRUSIVE_SPLIT_MICHAEL_RCU_H
32
33 #include "test_intrusive_set_rcu.h"
34 #include <cds/intrusive/michael_list_rcu.h>
35 #include <cds/intrusive/split_list_rcu.h>
36
37 namespace ci = cds::intrusive;
38
39 template <class RCU>
40 class IntrusiveSplitMichaelSet: 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::split_list::node<ci::michael_list::node<rcu_type>>>   base_item_type;
46     typedef typename base_class::member_int_item< ci::split_list::node<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( IntrusiveSplitMichaelSet );
63
64 TYPED_TEST_P( IntrusiveSplitMichaelSet, 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::SplitListSet< rcu_type, bucket_type,
82         typename ci::split_list::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( IntrusiveSplitMichaelSet, 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::SplitListSet< rcu_type, bucket_type,
109         typename ci::split_list::make_traits<
110             ci::opt::hash< hash_int >
111             , ci::opt::item_counter< cds::atomicity::item_counter >
112         >::type
113     > set_type;
114
115     set_type s( TestFixture::kSize, 2 );
116     this->test( s );
117 }
118
119 TYPED_TEST_P( IntrusiveSplitMichaelSet, base_cmpmix )
120 {
121     typedef typename TestFixture::rcu_type rcu_type;
122     typedef typename TestFixture::base_item_type base_item_type;
123     typedef typename TestFixture::mock_disposer mock_disposer;
124     typedef typename TestFixture::hash_int hash_int;
125
126     struct list_traits : public ci::michael_list::traits
127     {
128         typedef ci::michael_list::base_hook< ci::opt::gc<rcu_type>> hook;
129         typedef typename TestFixture::template less<base_item_type> less;
130         typedef typename TestFixture::template cmp<base_item_type> compare;
131         typedef mock_disposer disposer;
132     };
133     typedef ci::MichaelList< rcu_type, base_item_type, list_traits > bucket_type;
134
135     struct set_traits : public ci::split_list::traits
136     {
137         typedef hash_int hash;
138         typedef typename TestFixture::simple_item_counter item_counter;
139         typedef ci::split_list::stat<> stat;
140     };
141     typedef ci::SplitListSet< rcu_type, bucket_type, set_traits > set_type;
142
143     set_type s( TestFixture::kSize, 2 );
144     this->test( s );
145 }
146
147
148 TYPED_TEST_P( IntrusiveSplitMichaelSet, member_cmp )
149 {
150     typedef typename TestFixture::rcu_type rcu_type;
151     typedef typename TestFixture::member_item_type member_item_type;
152     typedef typename TestFixture::mock_disposer mock_disposer;
153     typedef typename TestFixture::template cmp<member_item_type> cmp;
154     typedef typename TestFixture::hash_int hash_int;
155
156     typedef ci::MichaelList< rcu_type
157         , member_item_type
158         , typename ci::michael_list::make_traits<
159             ci::opt::hook< ci::michael_list::member_hook<
160                 offsetof( member_item_type, hMember ),
161                 ci::opt::gc<rcu_type>
162             >>
163             , ci::opt::compare< cmp >
164             , ci::opt::disposer< mock_disposer >
165         >::type
166     >    bucket_type;
167
168     typedef ci::SplitListSet< rcu_type, bucket_type,
169         typename ci::split_list::make_traits<
170             ci::opt::hash< hash_int >
171         >::type
172     > set_type;
173
174     set_type s( TestFixture::kSize, 2 );
175     this->test( s );
176 }
177
178 TYPED_TEST_P( IntrusiveSplitMichaelSet, member_less )
179 {
180     typedef typename TestFixture::rcu_type rcu_type;
181     typedef typename TestFixture::member_item_type member_item_type;
182     typedef typename TestFixture::mock_disposer mock_disposer;
183     typedef typename TestFixture::template less<member_item_type> less;
184     typedef typename TestFixture::hash_int hash_int;
185
186     typedef ci::MichaelList< rcu_type
187         , member_item_type
188         , typename ci::michael_list::make_traits<
189             ci::opt::hook< ci::michael_list::member_hook<
190                 offsetof( member_item_type, hMember ),
191                 ci::opt::gc<rcu_type>
192             > >
193             , ci::opt::less< less >
194             , ci::opt::disposer< mock_disposer >
195         >::type
196     > bucket_type;
197
198     typedef ci::SplitListSet< rcu_type, bucket_type,
199         typename ci::split_list::make_traits<
200             ci::opt::hash< hash_int >
201             , ci::opt::back_off< cds::backoff::pause >
202         >::type
203     > set_type;
204
205     set_type s( TestFixture::kSize, 2 );
206     this->test( s );
207 }
208
209 TYPED_TEST_P( IntrusiveSplitMichaelSet, member_cmpmix )
210 {
211     typedef typename TestFixture::rcu_type rcu_type;
212     typedef typename TestFixture::member_item_type member_item_type;
213     typedef typename TestFixture::mock_disposer mock_disposer;
214     typedef typename TestFixture::hash_int hash_int;
215
216     struct list_traits : public ci::michael_list::traits
217     {
218         typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<rcu_type>> hook;
219         typedef typename TestFixture::template less<member_item_type> less;
220         typedef typename TestFixture::template cmp<member_item_type> compare;
221         typedef mock_disposer disposer;
222     };
223     typedef ci::MichaelList< rcu_type, member_item_type, list_traits > bucket_type;
224
225     struct set_traits : public ci::split_list::traits
226     {
227         typedef hash_int hash;
228         typedef typename TestFixture::simple_item_counter item_counter;
229     };
230     typedef ci::SplitListSet< rcu_type, bucket_type, set_traits > set_type;
231
232     set_type s( TestFixture::kSize, 2 );
233     this->test( s );
234 }
235
236
237
238 // GCC 5: All test names should be written on single line, otherwise a runtime error will be encountered like as
239 // "No test named <test_name> can be found in this test case"
240 REGISTER_TYPED_TEST_CASE_P( IntrusiveSplitMichaelSet,
241     base_cmp, base_less, base_cmpmix, member_cmp, member_less, member_cmpmix
242 );
243
244
245 #endif // CDSUNIT_SET_TEST_INTRUSIVE_SPLIT_MICHAEL_RCU_H
246