47713fe4b1e32032db3df266006f892b225cf7e3
[libcds.git] / test / unit / map / test_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_MAP_TEST_SPLIT_LIST_MICHAEL_RCU_H
31 #define CDSUNIT_MAP_TEST_SPLIT_LIST_MICHAEL_RCU_H
32
33 #include "test_map_rcu.h"
34 #include <cds/container/michael_list_rcu.h>
35 #include <cds/container/split_list_map_rcu.h>
36
37 namespace cc = cds::container;
38
39 template <class RCU>
40 class SplitListMichaelMap: public cds_test::container_map_rcu
41 {
42     typedef cds_test::container_map_rcu base_class;
43 public:
44     typedef cds::urcu::gc<RCU> rcu_type;
45
46 protected:
47     void SetUp()
48     {
49         RCU::Construct();
50         cds::threading::Manager::attachThread();
51     }
52
53     void TearDown()
54     {
55         cds::threading::Manager::detachThread();
56         RCU::Destruct();
57     }
58 };
59
60 TYPED_TEST_CASE_P( SplitListMichaelMap );
61
62 TYPED_TEST_P( SplitListMichaelMap, compare )
63 {
64     typedef typename TestFixture::rcu_type   rcu_type;
65     typedef typename TestFixture::key_type   key_type;
66     typedef typename TestFixture::value_type value_type;
67     typedef typename TestFixture::hash1      hash1;
68
69     typedef cc::SplitListMap< rcu_type, key_type, value_type, 
70         typename cc::split_list::make_traits<
71             cc::split_list::ordered_list< cc::michael_list_tag >
72             , cds::opt::hash< hash1 >
73             , cc::split_list::ordered_list_traits< 
74                 typename cc::michael_list::make_traits<
75                     cds::opt::compare< typename TestFixture::cmp >
76                 >::type
77             >
78         >::type
79     > map_type;
80
81     map_type m( TestFixture::kSize, 2 );
82     this->test( m );
83 }
84
85 TYPED_TEST_P( SplitListMichaelMap, less )
86 {
87     typedef typename TestFixture::rcu_type   rcu_type;
88     typedef typename TestFixture::key_type   key_type;
89     typedef typename TestFixture::value_type value_type;
90     typedef typename TestFixture::hash1      hash1;
91
92     typedef cc::SplitListMap< rcu_type, key_type, value_type,
93         typename cc::split_list::make_traits<
94             cc::split_list::ordered_list< cc::michael_list_tag >
95             , cds::opt::hash< hash1 >
96             , cc::split_list::ordered_list_traits< 
97                 typename cc::michael_list::make_traits<
98                     cds::opt::less< typename TestFixture::less >
99                 >::type
100             >
101         >::type
102     > map_type;
103
104     map_type m( TestFixture::kSize, 2 );
105     this->test( m );
106 }
107
108 TYPED_TEST_P( SplitListMichaelMap, cmpmix )
109 {
110     typedef typename TestFixture::rcu_type   rcu_type;
111     typedef typename TestFixture::key_type   key_type;
112     typedef typename TestFixture::value_type value_type;
113     typedef typename TestFixture::hash1      hash1;
114
115     typedef cc::SplitListMap< rcu_type, key_type, value_type,
116         typename cc::split_list::make_traits<
117             cc::split_list::ordered_list< cc::michael_list_tag >
118             , cds::opt::hash< hash1 >
119             , cc::split_list::ordered_list_traits< 
120                 typename cc::michael_list::make_traits<
121                     cds::opt::less< typename TestFixture::less >
122                     , cds::opt::compare< typename TestFixture::cmp >
123                 >::type
124             >
125         >::type
126     > map_type;
127
128     map_type m( TestFixture::kSize, 3 );
129     this->test( m );
130 }
131
132 TYPED_TEST_P( SplitListMichaelMap, item_counting )
133 {
134     typedef typename TestFixture::rcu_type   rcu_type;
135     typedef typename TestFixture::key_type   key_type;
136     typedef typename TestFixture::value_type value_type;
137     typedef typename TestFixture::hash1      hash1;
138
139     struct map_traits: public cc::split_list::traits
140     {
141         typedef cc::michael_list_tag ordered_list;
142         typedef hash1 hash;
143         typedef cds::atomicity::item_counter item_counter;
144
145         struct ordered_list_traits: public cc::michael_list::traits
146         {
147             typedef typename TestFixture::cmp compare;
148             typedef typename TestFixture::less less;
149             typedef cds::backoff::empty back_off;
150         };
151     };
152     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
153
154     map_type m( TestFixture::kSize, 8 );
155     this->test( m );
156 }
157
158 TYPED_TEST_P( SplitListMichaelMap, stat )
159 {
160     typedef typename TestFixture::rcu_type   rcu_type;
161     typedef typename TestFixture::key_type   key_type;
162     typedef typename TestFixture::value_type value_type;
163     typedef typename TestFixture::hash1      hash1;
164
165     struct map_traits: public cc::split_list::traits
166     {
167         typedef cc::michael_list_tag ordered_list;
168         typedef hash1 hash;
169         typedef cds::atomicity::item_counter item_counter;
170         typedef cc::split_list::stat<> stat;
171
172         struct ordered_list_traits: public cc::michael_list::traits
173         {
174             typedef typename TestFixture::less less;
175             typedef cds::opt::v::sequential_consistent memory_model;
176         };
177     };
178     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
179
180     map_type m( TestFixture::kSize, 4 );
181     this->test( m );
182 }
183
184 TYPED_TEST_P( SplitListMichaelMap, back_off )
185 {
186     typedef typename TestFixture::rcu_type   rcu_type;
187     typedef typename TestFixture::key_type   key_type;
188     typedef typename TestFixture::value_type value_type;
189     typedef typename TestFixture::hash1      hash1;
190
191     struct map_traits: public cc::split_list::traits
192     {
193         typedef cc::michael_list_tag ordered_list;
194         typedef hash1 hash;
195         typedef cds::atomicity::item_counter item_counter;
196         typedef cds::backoff::yield back_off;
197         typedef cds::opt::v::sequential_consistent memory_model;
198
199         struct ordered_list_traits: public cc::michael_list::traits
200         {
201             typedef typename TestFixture::cmp compare;
202             typedef cds::backoff::pause back_off;
203         };
204     };
205     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
206
207     map_type m( TestFixture::kSize, 2 );
208     this->test( m );
209 }
210
211 namespace {
212     struct set_static_traits: public cc::split_list::traits
213     {
214         static bool const dynamic_bucket_table = false;
215     };
216 }
217
218 TYPED_TEST_P( SplitListMichaelMap, static_bucket_table )
219 {
220     typedef typename TestFixture::rcu_type   rcu_type;
221     typedef typename TestFixture::key_type   key_type;
222     typedef typename TestFixture::value_type value_type;
223     typedef typename TestFixture::hash1      hash1;
224
225     struct map_traits: public set_static_traits
226     {
227         typedef cc::michael_list_tag ordered_list;
228         typedef hash1 hash;
229         typedef cds::atomicity::item_counter item_counter;
230
231         struct ordered_list_traits: public cc::michael_list::traits
232         {
233             typedef typename TestFixture::cmp compare;
234             typedef cds::backoff::pause back_off;
235         };
236     };
237     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
238
239     map_type m( TestFixture::kSize, 4 );
240     this->test( m );
241 }
242
243 REGISTER_TYPED_TEST_CASE_P( SplitListMichaelMap,
244     compare, less, cmpmix, item_counting, stat, back_off, static_bucket_table
245 );
246
247
248 #endif // CDSUNIT_MAP_TEST_SPLIT_LIST_MICHAEL_RCU_H
249