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_MAP_TEST_MICHAEL_LAZY_RCU_H
31 #define CDSUNIT_MAP_TEST_MICHAEL_LAZY_RCU_H
33 #include "test_map_rcu.h"
34 #include <cds/container/lazy_kvlist_rcu.h>
35 #include <cds/container/michael_map_rcu.h>
38 namespace cc = cds::container;
41 class MichaelLazyMap: public cds_test::container_map_rcu
43 typedef cds_test::container_map_rcu base_class;
45 typedef cds::urcu::gc<RCU> rcu_type;
51 cds::threading::Manager::attachThread();
56 cds::threading::Manager::detachThread();
61 TYPED_TEST_CASE_P( MichaelLazyMap );
63 TYPED_TEST_P( MichaelLazyMap, compare )
65 typedef typename TestFixture::rcu_type rcu_type;
66 typedef typename TestFixture::key_type key_type;
67 typedef typename TestFixture::value_type value_type;
69 typedef cc::LazyKVList< rcu_type, key_type, value_type,
70 typename cc::lazy_list::make_traits<
71 cds::opt::compare< typename TestFixture::cmp >
75 typedef cc::MichaelHashMap< rcu_type, list_type,
76 typename cc::michael_map::make_traits<
77 cds::opt::hash< typename TestFixture::hash1 >
81 map_type m( TestFixture::kSize, 2 );
85 TYPED_TEST_P( MichaelLazyMap, less )
87 typedef typename TestFixture::rcu_type rcu_type;
88 typedef typename TestFixture::key_type key_type;
89 typedef typename TestFixture::value_type value_type;
91 typedef cc::LazyKVList< rcu_type, key_type, value_type,
92 typename cc::lazy_list::make_traits<
93 cds::opt::less< typename TestFixture::less >
97 typedef cc::MichaelHashMap< rcu_type, list_type,
98 typename cc::michael_map::make_traits<
99 cds::opt::hash< typename TestFixture::hash1 >
103 map_type m( TestFixture::kSize, 2 );
107 TYPED_TEST_P( MichaelLazyMap, cmpmix )
109 typedef typename TestFixture::rcu_type rcu_type;
110 typedef typename TestFixture::key_type key_type;
111 typedef typename TestFixture::value_type value_type;
113 struct list_traits : public cc::lazy_list::traits
115 typedef typename TestFixture::less less;
116 typedef typename TestFixture::cmp compare;
118 typedef cc::LazyKVList< rcu_type, key_type, value_type, list_traits > list_type;
120 typedef cc::MichaelHashMap< rcu_type, list_type,
121 typename cc::michael_map::make_traits<
122 cds::opt::hash< typename TestFixture::hash1 >
126 map_type m( TestFixture::kSize, 2 );
130 TYPED_TEST_P( MichaelLazyMap, backoff )
132 typedef typename TestFixture::rcu_type rcu_type;
133 typedef typename TestFixture::key_type key_type;
134 typedef typename TestFixture::value_type value_type;
136 struct list_traits : public cc::lazy_list::traits
138 typedef typename TestFixture::cmp compare;
139 typedef cds::backoff::make_exponential_t<cds::backoff::pause, cds::backoff::yield> back_off;
141 typedef cc::LazyKVList< rcu_type, key_type, value_type, list_traits > list_type;
143 struct set_traits : public cc::michael_map::traits
145 typedef typename TestFixture::hash1 hash;
146 typedef cds::atomicity::item_counter item_counter;
148 typedef cc::MichaelHashMap< rcu_type, list_type, set_traits >map_type;
150 map_type m( TestFixture::kSize, 4 );
154 TYPED_TEST_P( MichaelLazyMap, seq_cst )
156 typedef typename TestFixture::rcu_type rcu_type;
157 typedef typename TestFixture::key_type key_type;
158 typedef typename TestFixture::value_type value_type;
160 struct list_traits : public cc::lazy_list::traits
162 typedef typename TestFixture::less less;
163 typedef cds::backoff::pause back_off;
164 typedef cds::opt::v::sequential_consistent memory_model;
166 typedef cc::LazyKVList< rcu_type, key_type, value_type, list_traits > list_type;
168 struct set_traits : public cc::michael_map::traits
170 typedef typename TestFixture::hash1 hash;
171 typedef cds::atomicity::item_counter item_counter;
173 typedef cc::MichaelHashMap< rcu_type, list_type, set_traits >map_type;
175 map_type m( TestFixture::kSize, 4 );
179 TYPED_TEST_P( MichaelLazyMap, mutex )
181 typedef typename TestFixture::rcu_type rcu_type;
182 typedef typename TestFixture::key_type key_type;
183 typedef typename TestFixture::value_type value_type;
185 struct list_traits : public cc::lazy_list::traits
187 typedef typename TestFixture::less less;
188 typedef cds::backoff::pause back_off;
189 typedef std::mutex lock_type;
191 typedef cc::LazyKVList< rcu_type, key_type, value_type, list_traits > list_type;
193 struct set_traits : public cc::michael_map::traits
195 typedef typename TestFixture::hash1 hash;
196 typedef cds::atomicity::item_counter item_counter;
198 typedef cc::MichaelHashMap< rcu_type, list_type, set_traits >map_type;
200 map_type m( TestFixture::kSize, 4 );
204 TYPED_TEST_P( MichaelLazyMap, stat )
206 typedef typename TestFixture::rcu_type rcu_type;
207 typedef typename TestFixture::key_type key_type;
208 typedef typename TestFixture::value_type value_type;
210 struct list_traits: public cc::lazy_list::traits
212 typedef typename TestFixture::less less;
213 typedef cds::backoff::pause back_off;
214 typedef cc::lazy_list::stat<> stat;
216 typedef cc::LazyKVList< rcu_type, key_type, value_type, list_traits > list_type;
218 struct set_traits: public cc::michael_map::traits
220 typedef typename TestFixture::hash1 hash;
221 typedef cds::atomicity::item_counter item_counter;
223 typedef cc::MichaelHashMap< rcu_type, list_type, set_traits >map_type;
225 map_type m( TestFixture::kSize, 4 );
227 EXPECT_GE( m.statistics().m_nInsertSuccess, 0u );
230 TYPED_TEST_P( MichaelLazyMap, wrapped_stat )
232 typedef typename TestFixture::rcu_type rcu_type;
233 typedef typename TestFixture::key_type key_type;
234 typedef typename TestFixture::value_type value_type;
236 struct list_traits: public cc::lazy_list::traits
238 typedef typename TestFixture::less less;
239 typedef cds::backoff::pause back_off;
240 typedef cc::lazy_list::wrapped_stat<> stat;
242 typedef cc::LazyKVList< rcu_type, key_type, value_type, list_traits > list_type;
244 struct set_traits: public cc::michael_map::traits
246 typedef typename TestFixture::hash1 hash;
247 typedef cds::atomicity::item_counter item_counter;
249 typedef cc::MichaelHashMap< rcu_type, list_type, set_traits >map_type;
251 map_type m( TestFixture::kSize, 4 );
253 EXPECT_GE( m.statistics().m_nInsertSuccess, 0u );
257 // GCC 5: All test names should be written on single line, otherwise a runtime error will be encountered like as
258 // "No test named <test_name> can be found in this test case"
259 REGISTER_TYPED_TEST_CASE_P( MichaelLazyMap,
260 compare, less, cmpmix, backoff, seq_cst, mutex, stat, wrapped_stat
264 #endif // CDSUNIT_MAP_TEST_MICHAEL_LAZY_RCU_H