2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
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.
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.
30 #ifndef CDSUNIT_SET_TEST_MICHAEL_LAZY_RCU_H
31 #define CDSUNIT_SET_TEST_MICHAEL_LAZY_RCU_H
33 #include "test_set_rcu.h"
34 #include <cds/container/lazy_list_rcu.h>
35 #include <cds/container/michael_set_rcu.h>
37 namespace cc = cds::container;
40 class MichaelLazySet: public cds_test::container_set_rcu
42 typedef cds_test::container_set_rcu base_class;
44 typedef cds::urcu::gc<RCU> rcu_type;
50 cds::threading::Manager::attachThread();
55 cds::threading::Manager::detachThread();
60 TYPED_TEST_CASE_P( MichaelLazySet );
62 TYPED_TEST_P( MichaelLazySet, compare )
64 typedef typename TestFixture::rcu_type rcu_type;
65 typedef typename TestFixture::int_item int_item;
67 typedef cc::LazyList< rcu_type, int_item,
68 typename cc::lazy_list::make_traits<
69 cds::opt::compare< typename TestFixture::cmp >
73 typedef cc::MichaelHashSet< rcu_type, list_type,
74 typename cc::michael_set::make_traits<
75 cds::opt::hash< typename TestFixture::hash_int >
79 set_type s( TestFixture::kSize, 2 );
83 TYPED_TEST_P( MichaelLazySet, less )
85 typedef typename TestFixture::rcu_type rcu_type;
86 typedef typename TestFixture::int_item int_item;
88 typedef cc::LazyList< rcu_type, int_item,
89 typename cc::lazy_list::make_traits<
90 cds::opt::less< typename TestFixture::less >
94 typedef cc::MichaelHashSet< rcu_type, list_type,
95 typename cc::michael_set::make_traits<
96 cds::opt::hash< typename TestFixture::hash_int >
100 set_type s( TestFixture::kSize, 2 );
104 TYPED_TEST_P( MichaelLazySet, cmpmix )
106 typedef typename TestFixture::rcu_type rcu_type;
107 typedef typename TestFixture::int_item int_item;
109 struct list_traits : public cc::lazy_list::traits
111 typedef typename TestFixture::less less;
112 typedef typename TestFixture::cmp compare;
114 typedef cc::LazyList< rcu_type, int_item, list_traits > list_type;
116 typedef cc::MichaelHashSet< rcu_type, list_type,
117 typename cc::michael_set::make_traits<
118 cds::opt::hash< typename TestFixture::hash_int >
122 set_type s( TestFixture::kSize, 2 );
126 TYPED_TEST_P( MichaelLazySet, item_counting )
128 typedef typename TestFixture::rcu_type rcu_type;
129 typedef typename TestFixture::int_item int_item;
131 struct list_traits : public cc::lazy_list::traits
133 typedef typename TestFixture::cmp compare;
135 typedef cc::LazyList< rcu_type, int_item, list_traits > list_type;
137 struct set_traits: public cc::michael_set::traits
139 typedef typename TestFixture::hash_int hash;
140 typedef typename TestFixture::simple_item_counter item_counter;
142 typedef cc::MichaelHashSet< rcu_type, list_type, set_traits >set_type;
144 set_type s( TestFixture::kSize, 3 );
148 TYPED_TEST_P( MichaelLazySet, backoff )
150 typedef typename TestFixture::rcu_type rcu_type;
151 typedef typename TestFixture::int_item int_item;
153 struct list_traits : public cc::lazy_list::traits
155 typedef typename TestFixture::cmp compare;
156 typedef cds::backoff::exponential<cds::backoff::pause, cds::backoff::yield> back_off;
158 typedef cc::LazyList< rcu_type, int_item, list_traits > list_type;
160 struct set_traits : public cc::michael_set::traits
162 typedef typename TestFixture::hash_int hash;
163 typedef cds::atomicity::item_counter item_counter;
165 typedef cc::MichaelHashSet< rcu_type, list_type, set_traits >set_type;
167 set_type s( TestFixture::kSize, 4 );
171 TYPED_TEST_P( MichaelLazySet, seq_cst )
173 typedef typename TestFixture::rcu_type rcu_type;
174 typedef typename TestFixture::int_item int_item;
176 struct list_traits : public cc::lazy_list::traits
178 typedef typename TestFixture::less less;
179 typedef cds::backoff::pause back_off;
180 typedef cds::opt::v::sequential_consistent memory_model;
182 typedef cc::LazyList< rcu_type, int_item, list_traits > list_type;
184 struct set_traits : public cc::michael_set::traits
186 typedef typename TestFixture::hash_int hash;
187 typedef cds::atomicity::item_counter item_counter;
189 typedef cc::MichaelHashSet< rcu_type, list_type, set_traits >set_type;
191 set_type s( TestFixture::kSize, 4 );
195 TYPED_TEST_P( MichaelLazySet, mutex )
197 typedef typename TestFixture::rcu_type rcu_type;
198 typedef typename TestFixture::int_item int_item;
200 struct list_traits : public cc::lazy_list::traits
202 typedef typename TestFixture::less less;
203 typedef cds::backoff::pause back_off;
204 typedef std::mutex lock_type;
206 typedef cc::LazyList< rcu_type, int_item, list_traits > list_type;
208 struct set_traits : public cc::michael_set::traits
210 typedef typename TestFixture::hash_int hash;
211 typedef cds::atomicity::item_counter item_counter;
213 typedef cc::MichaelHashSet< rcu_type, list_type, set_traits >set_type;
215 set_type s( TestFixture::kSize, 4 );
219 TYPED_TEST_P( MichaelLazySet, stat )
221 typedef typename TestFixture::rcu_type rcu_type;
222 typedef typename TestFixture::int_item int_item;
224 struct list_traits: public cc::lazy_list::traits
226 typedef typename TestFixture::less less;
227 typedef cds::backoff::pause back_off;
228 typedef cc::lazy_list::stat<> stat;
230 typedef cc::LazyList< rcu_type, int_item, list_traits > list_type;
232 struct set_traits: public cc::michael_set::traits
234 typedef typename TestFixture::hash_int hash;
235 typedef cds::atomicity::item_counter item_counter;
237 typedef cc::MichaelHashSet< rcu_type, list_type, set_traits >set_type;
239 set_type s( TestFixture::kSize, 4 );
241 EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
244 TYPED_TEST_P( MichaelLazySet, wrapped_stat )
246 typedef typename TestFixture::rcu_type rcu_type;
247 typedef typename TestFixture::int_item int_item;
249 struct list_traits: public cc::lazy_list::traits
251 typedef typename TestFixture::less less;
252 typedef cds::backoff::pause back_off;
253 typedef cc::lazy_list::wrapped_stat<> stat;
255 typedef cc::LazyList< rcu_type, int_item, list_traits > list_type;
257 struct set_traits: public cc::michael_set::traits
259 typedef typename TestFixture::hash_int hash;
260 typedef cds::atomicity::item_counter item_counter;
262 typedef cc::MichaelHashSet< rcu_type, list_type, set_traits >set_type;
264 set_type s( TestFixture::kSize, 4 );
266 EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
269 // GCC 5: All test names should be written on single line, otherwise a runtime error will be encountered like as
270 // "No test named <test_name> can be found in this test case"
271 REGISTER_TYPED_TEST_CASE_P( MichaelLazySet,
272 compare, less, cmpmix, item_counting, backoff, seq_cst, mutex, stat, wrapped_stat
276 #endif // CDSUNIT_SET_TEST_INTRUSIVE_MICHAEL_LAZY_RCU_H