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_SKIPLIST_RCU_H
31 #define CDSUNIT_SET_TEST_SKIPLIST_RCU_H
33 #include "test_set_rcu.h"
34 #include <cds/container/skip_list_set_rcu.h>
36 namespace cc = cds::container;
39 class SkipListSet: public cds_test::container_set_rcu
41 typedef cds_test::container_set_rcu base_class;
43 typedef cds::urcu::gc<RCU> rcu_type;
46 template <typename Set>
49 // Precondition: set is empty
50 // Postcondition: set is empty
52 base_class::test( s );
54 ASSERT_TRUE( s.empty());
55 ASSERT_CONTAINER_SIZE( s, 0 );
57 typedef typename Set::value_type value_type;
59 size_t const nSetSize = base_class::kSize;
60 std::vector< value_type > data;
61 std::vector< size_t> indices;
62 data.reserve( nSetSize );
63 indices.reserve( nSetSize );
64 for ( size_t key = 0; key < nSetSize; ++key ) {
65 data.push_back( value_type( static_cast<int>(key)));
66 indices.push_back( key );
68 shuffle( indices.begin(), indices.end());
70 for ( auto i : indices ) {
71 ASSERT_TRUE( s.insert( data[i] ));
73 ASSERT_FALSE( s.empty());
74 ASSERT_CONTAINER_SIZE( s, nSetSize );
76 typedef typename Set::exempt_ptr exempt_ptr;
85 EXPECT_EQ( nKey + 1, xp->key());
90 EXPECT_EQ( nCount, nSetSize );
92 ASSERT_TRUE( s.empty());
93 ASSERT_CONTAINER_SIZE( s, 0 );
96 for ( auto i : indices ) {
97 ASSERT_TRUE( s.insert( data[i] ));
99 ASSERT_FALSE( s.empty());
100 ASSERT_CONTAINER_SIZE( s, nSetSize );
104 while ( !s.empty()) {
105 xp = s.extract_max();
107 EXPECT_EQ( nKey - 1, xp->key());
112 EXPECT_EQ( nCount, nSetSize );
114 ASSERT_TRUE( s.empty());
115 ASSERT_CONTAINER_SIZE( s, 0 );
121 cds::threading::Manager::attachThread();
126 cds::threading::Manager::detachThread();
131 TYPED_TEST_CASE_P( SkipListSet );
133 //TYPED_TEST_P( SkipListSet, compare )
134 TYPED_TEST_P( SkipListSet, compare )
136 typedef typename TestFixture::rcu_type rcu_type;
137 typedef typename TestFixture::int_item int_item;
139 typedef cc::SkipListSet< rcu_type, int_item,
140 typename cc::skip_list::make_traits<
141 cds::opt::compare< typename TestFixture::cmp >
149 TYPED_TEST_P( SkipListSet, less )
151 typedef typename TestFixture::rcu_type rcu_type;
152 typedef typename TestFixture::int_item int_item;
154 typedef cc::SkipListSet< rcu_type, int_item,
155 typename cc::skip_list::make_traits<
156 cds::opt::less< typename TestFixture::less >
164 TYPED_TEST_P( SkipListSet, cmpmix )
166 typedef typename TestFixture::rcu_type rcu_type;
167 typedef typename TestFixture::int_item int_item;
169 typedef cc::SkipListSet< rcu_type, int_item,
170 typename cc::skip_list::make_traits<
171 cds::opt::less< typename TestFixture::less >
172 ,cds::opt::compare< typename TestFixture::cmp >
180 TYPED_TEST_P( SkipListSet, item_counting )
182 typedef typename TestFixture::rcu_type rcu_type;
183 typedef typename TestFixture::int_item int_item;
185 struct set_traits: public cc::skip_list::traits
187 typedef typename TestFixture::cmp compare;
188 typedef typename TestFixture::less less;
189 typedef cds::atomicity::item_counter item_counter;
191 typedef cc::SkipListSet< rcu_type, int_item, set_traits >set_type;
197 TYPED_TEST_P( SkipListSet, backoff )
199 typedef typename TestFixture::rcu_type rcu_type;
200 typedef typename TestFixture::int_item int_item;
202 struct set_traits: public cc::skip_list::traits
204 typedef typename TestFixture::cmp compare;
205 typedef typename TestFixture::less less;
206 typedef cds::atomicity::item_counter item_counter;
207 typedef cds::backoff::yield back_off;
209 typedef cc::SkipListSet< rcu_type, int_item, set_traits >set_type;
215 TYPED_TEST_P( SkipListSet, stat )
217 typedef typename TestFixture::rcu_type rcu_type;
218 typedef typename TestFixture::int_item int_item;
220 struct set_traits: public cc::skip_list::traits
222 typedef typename TestFixture::cmp compare;
223 typedef typename TestFixture::less less;
224 typedef cds::atomicity::item_counter item_counter;
225 typedef cds::backoff::yield back_off;
226 typedef cc::skip_list::stat<> stat;
228 typedef cc::SkipListSet< rcu_type, int_item, set_traits >set_type;
234 TYPED_TEST_P( SkipListSet, xorshift32 )
236 typedef typename TestFixture::rcu_type rcu_type;
237 typedef typename TestFixture::int_item int_item;
239 struct set_traits: public cc::skip_list::traits
241 typedef typename TestFixture::less less;
242 typedef cds::atomicity::item_counter item_counter;
243 typedef cc::skip_list::xorshift32 random_level_generator;
244 typedef cds::opt::v::rcu_assert_deadlock rcu_check_deadlock;
246 typedef cc::SkipListSet< rcu_type, int_item, set_traits >set_type;
252 TYPED_TEST_P( SkipListSet, xorshift24 )
254 typedef typename TestFixture::rcu_type rcu_type;
255 typedef typename TestFixture::int_item int_item;
257 struct set_traits: public cc::skip_list::traits
259 typedef typename TestFixture::less less;
260 typedef cds::atomicity::item_counter item_counter;
261 typedef cc::skip_list::xorshift24 random_level_generator;
262 typedef cds::opt::v::rcu_assert_deadlock rcu_check_deadlock;
264 typedef cc::SkipListSet< rcu_type, int_item, set_traits >set_type;
270 TYPED_TEST_P( SkipListSet, xorshift16 )
272 typedef typename TestFixture::rcu_type rcu_type;
273 typedef typename TestFixture::int_item int_item;
275 struct set_traits: public cc::skip_list::traits
277 typedef typename TestFixture::less less;
278 typedef cds::atomicity::item_counter item_counter;
279 typedef cc::skip_list::xorshift16 random_level_generator;
280 typedef cds::opt::v::rcu_assert_deadlock rcu_check_deadlock;
282 typedef cc::SkipListSet< rcu_type, int_item, set_traits >set_type;
288 TYPED_TEST_P( SkipListSet, turbo32 )
290 typedef typename TestFixture::rcu_type rcu_type;
291 typedef typename TestFixture::int_item int_item;
293 struct set_traits: public cc::skip_list::traits
295 typedef typename TestFixture::less less;
296 typedef cds::atomicity::item_counter item_counter;
297 typedef cc::skip_list::turbo32 random_level_generator;
298 typedef cds::opt::v::rcu_assert_deadlock rcu_check_deadlock;
300 typedef cc::SkipListSet< rcu_type, int_item, set_traits >set_type;
306 TYPED_TEST_P( SkipListSet, turbo24 )
308 typedef typename TestFixture::rcu_type rcu_type;
309 typedef typename TestFixture::int_item int_item;
311 struct set_traits: public cc::skip_list::traits
313 typedef typename TestFixture::less less;
314 typedef cds::atomicity::item_counter item_counter;
315 typedef cc::skip_list::turbo24 random_level_generator;
316 typedef cds::opt::v::rcu_assert_deadlock rcu_check_deadlock;
318 typedef cc::SkipListSet< rcu_type, int_item, set_traits >set_type;
324 TYPED_TEST_P( SkipListSet, turbo16 )
326 typedef typename TestFixture::rcu_type rcu_type;
327 typedef typename TestFixture::int_item int_item;
329 struct set_traits: public cc::skip_list::traits
331 typedef typename TestFixture::less less;
332 typedef cds::atomicity::item_counter item_counter;
333 typedef cc::skip_list::turbo16 random_level_generator;
334 typedef cds::opt::v::rcu_assert_deadlock rcu_check_deadlock;
336 typedef cc::SkipListSet< rcu_type, int_item, set_traits >set_type;
342 // All this->test names should be written on single line, otherwise a runtime error will be encountered like as
343 // "No this->test named <test_name> can be found in this this->test case"
344 REGISTER_TYPED_TEST_CASE_P( SkipListSet,
345 compare, less, cmpmix, item_counting, backoff, stat, xorshift32, xorshift24, xorshift16, turbo32, turbo24, turbo16
349 #endif // CDSUNIT_SET_TEST_SKIPLIST_RCU_H