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