Merged branch 'master' of https://github.com/Nemo1369/libcds
[libcds.git] / test / unit / tree / test_ellen_bintree_map_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_TREE_TEST_ELLEN_BINTREE_MAP_RCU_H
31 #define CDSUNIT_TREE_TEST_ELLEN_BINTREE_MAP_RCU_H
32
33 #include "test_tree_map_rcu.h"
34 #include <cds/container/ellen_bintree_map_rcu.h>
35 #include "test_ellen_bintree_update_desc_pool.h"
36
37 namespace {
38     namespace cc = cds::container;
39
40     template <class RCU>
41     class EllenBinTreeMap: public cds_test::container_tree_map_rcu
42     {
43         typedef cds_test::container_tree_map_rcu base_class;
44     public:
45         typedef cds::urcu::gc<RCU> rcu_type;
46
47     protected:
48
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( EllenBinTreeMap );
63
64     TYPED_TEST_P( EllenBinTreeMap, compare )
65     {
66         typedef typename TestFixture::rcu_type   rcu_type;
67         typedef typename TestFixture::key_type   key_type;
68         typedef typename TestFixture::value_type value_type;
69
70         typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type,
71             typename cc::ellen_bintree::make_map_traits<
72                 cds::opt::compare< typename TestFixture::cmp >
73             >::type
74         > map_type;
75
76         map_type m;
77         this->test( m );
78     }
79
80     TYPED_TEST_P( EllenBinTreeMap, less )
81     {
82         typedef typename TestFixture::rcu_type   rcu_type;
83         typedef typename TestFixture::key_type   key_type;
84         typedef typename TestFixture::value_type value_type;
85
86         typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type,
87             typename cc::ellen_bintree::make_map_traits<
88                 cds::opt::less< typename TestFixture::less >
89             >::type
90         > map_type;
91
92         map_type m;
93         this->test( m );
94     }
95
96     TYPED_TEST_P( EllenBinTreeMap, update_desc_pool )
97     {
98         typedef typename TestFixture::rcu_type   rcu_type;
99         typedef typename TestFixture::key_type   key_type;
100         typedef typename TestFixture::value_type value_type;
101
102         typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type,
103             typename cc::ellen_bintree::make_map_traits<
104                 cds::opt::less< typename TestFixture::less >
105                 ,cc::ellen_bintree::update_desc_allocator< cds::memory::pool_allocator<cds_test::update_desc, cds_test::pool_accessor>>
106             >::type
107         > map_type;
108
109         map_type m;
110         this->test( m );
111     }
112
113     TYPED_TEST_P( EllenBinTreeMap, update_desc_lazy_pool )
114     {
115         typedef typename TestFixture::rcu_type   rcu_type;
116         typedef typename TestFixture::key_type   key_type;
117         typedef typename TestFixture::value_type value_type;
118
119         typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type,
120             typename cc::ellen_bintree::make_map_traits<
121                 cds::opt::less< typename TestFixture::less >
122                 , cc::ellen_bintree::update_desc_allocator< cds::memory::pool_allocator<cds_test::update_desc, cds_test::lazy_pool_accessor>>
123             >::type
124         > map_type;
125
126             map_type m;
127             this->test( m );
128     }
129
130     TYPED_TEST_P( EllenBinTreeMap, cmpmix )
131     {
132         typedef typename TestFixture::rcu_type   rcu_type;
133         typedef typename TestFixture::key_type   key_type;
134         typedef typename TestFixture::value_type value_type;
135
136         typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type,
137             typename cc::ellen_bintree::make_map_traits<
138                 cds::opt::less< typename TestFixture::less >
139                 ,cds::opt::compare< typename TestFixture::cmp >
140             >::type
141         > map_type;
142
143         map_type m;
144         this->test( m );
145     }
146
147     TYPED_TEST_P( EllenBinTreeMap, item_counting )
148     {
149         typedef typename TestFixture::rcu_type   rcu_type;
150         typedef typename TestFixture::key_type   key_type;
151         typedef typename TestFixture::value_type value_type;
152
153         struct map_traits: public cc::ellen_bintree::traits
154         {
155             typedef typename TestFixture::cmp compare;
156             typedef typename TestFixture::less less;
157             typedef cds::atomicity::item_counter item_counter;
158             typedef cds::memory::pool_allocator<cds_test::update_desc, cds_test::pool_accessor> update_desc_allocator;
159         };
160         typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type, map_traits > map_type;
161
162         map_type m;
163         this->test( m );
164     }
165
166     TYPED_TEST_P( EllenBinTreeMap, backoff )
167     {
168         typedef typename TestFixture::rcu_type   rcu_type;
169         typedef typename TestFixture::key_type   key_type;
170         typedef typename TestFixture::value_type value_type;
171
172         struct map_traits: public cc::ellen_bintree::traits
173         {
174             typedef typename TestFixture::cmp compare;
175             typedef typename TestFixture::less less;
176             typedef cds::atomicity::item_counter item_counter;
177             typedef cds::backoff::yield back_off;
178             typedef cds::memory::pool_allocator<cds_test::update_desc, cds_test::lazy_pool_accessor> update_desc_allocator;
179         };
180         typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type, map_traits > map_type;
181
182         map_type m;
183         this->test( m );
184     }
185
186     TYPED_TEST_P( EllenBinTreeMap, stat )
187     {
188         typedef typename TestFixture::rcu_type   rcu_type;
189         typedef typename TestFixture::key_type   key_type;
190         typedef typename TestFixture::value_type value_type;
191
192         struct map_traits: public cc::ellen_bintree::traits
193         {
194             typedef typename TestFixture::less less;
195             typedef cds::atomicity::item_counter item_counter;
196             typedef cds::backoff::yield back_off;
197             typedef cc::ellen_bintree::stat<> stat;
198             typedef cds::memory::pool_allocator<cds_test::update_desc, cds_test::pool_accessor> update_desc_allocator;
199         };
200         typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type, map_traits > map_type;
201
202         map_type m;
203         this->test( m );
204     }
205
206     TYPED_TEST_P( EllenBinTreeMap, copy_policy )
207     {
208         typedef typename TestFixture::rcu_type   rcu_type;
209         typedef typename TestFixture::key_type   key_type;
210         typedef typename TestFixture::value_type value_type;
211
212         struct map_traits: public cc::ellen_bintree::traits
213         {
214             typedef typename TestFixture::less less;
215             typedef cds::atomicity::item_counter item_counter;
216             typedef cds::backoff::yield back_off;
217             typedef cc::ellen_bintree::stat<> stat;
218             typedef cds::memory::pool_allocator<cds_test::update_desc, cds_test::lazy_pool_accessor> update_desc_allocator;
219             typedef typename TestFixture::copy_key copy_policy;
220         };
221         typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type, map_traits > map_type;
222
223         map_type m;
224         this->test( m );
225     }
226
227     REGISTER_TYPED_TEST_CASE_P( EllenBinTreeMap,
228         compare, less, update_desc_pool, update_desc_lazy_pool, cmpmix, item_counting, backoff, stat, copy_policy
229     );
230
231 } // namespace
232
233 #endif // CDSUNIT_TREE_TEST_ELLEN_BINTREE_MAP_RCU_H
234