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_SKIPLIST_RCU_H
31 #define CDSUNIT_MAP_TEST_SKIPLIST_RCU_H
33 #include "test_map_rcu.h"
34 #include <cds/container/skip_list_map_rcu.h>
36 namespace cc = cds::container;
39 class SkipListMap: public cds_test::container_map_rcu
41 typedef cds_test::container_map_rcu base_class;
43 typedef cds::urcu::gc<RCU> rcu_type;
46 template <typename Map>
49 // Precondition: map is empty
50 // Postcondition: map is empty
52 base_class::test( m );
54 ASSERT_TRUE( m.empty());
55 ASSERT_CONTAINER_SIZE( m, 0 );
57 typedef typename Map::exempt_ptr exempt_ptr;
58 size_t const kkSize = base_class::kSize;
61 for ( int i = static_cast<int>(kkSize); i > 0; --i )
62 ASSERT_TRUE( m.insert( i ));
71 EXPECT_EQ( xp->first.nKey, nKey + 1 );
72 nKey = xp->first.nKey;
79 EXPECT_EQ( kkSize, nCount );
80 ASSERT_TRUE( m.empty());
81 ASSERT_CONTAINER_SIZE( m, 0 );
84 for ( int i = 0; i < static_cast<int>(kkSize); ++i )
85 ASSERT_TRUE( m.insert( i ));
92 EXPECT_EQ( xp->first.nKey, nKey - 1 );
93 nKey = xp->first.nKey;
100 EXPECT_EQ( kkSize, nCount );
101 ASSERT_TRUE( m.empty());
102 ASSERT_CONTAINER_SIZE( m, 0 );
108 cds::threading::Manager::attachThread();
113 cds::threading::Manager::detachThread();
118 TYPED_TEST_CASE_P( SkipListMap );
120 TYPED_TEST_P( SkipListMap, compare )
122 typedef typename TestFixture::rcu_type rcu_type;
123 typedef typename TestFixture::key_type key_type;
124 typedef typename TestFixture::value_type value_type;
126 typedef cc::SkipListMap< rcu_type, key_type, value_type,
127 typename cc::skip_list::make_traits<
128 cds::opt::compare< typename TestFixture::cmp >
136 TYPED_TEST_P( SkipListMap, less )
138 typedef typename TestFixture::rcu_type rcu_type;
139 typedef typename TestFixture::key_type key_type;
140 typedef typename TestFixture::value_type value_type;
142 typedef cc::SkipListMap< rcu_type, key_type, value_type,
143 typename cc::skip_list::make_traits<
144 cds::opt::less< typename TestFixture::less >
152 TYPED_TEST_P( SkipListMap, cmpmix )
154 typedef typename TestFixture::rcu_type rcu_type;
155 typedef typename TestFixture::key_type key_type;
156 typedef typename TestFixture::value_type value_type;
158 typedef cc::SkipListMap< rcu_type, key_type, value_type,
159 typename cc::skip_list::make_traits<
160 cds::opt::less< typename TestFixture::less >
161 ,cds::opt::compare< typename TestFixture::cmp >
169 TYPED_TEST_P( SkipListMap, item_counting )
171 typedef typename TestFixture::rcu_type rcu_type;
172 typedef typename TestFixture::key_type key_type;
173 typedef typename TestFixture::value_type value_type;
175 struct map_traits: public cc::skip_list::traits
177 typedef typename TestFixture::cmp compare;
178 typedef typename TestFixture::less less;
179 typedef cds::atomicity::item_counter item_counter;
181 typedef cc::SkipListMap< rcu_type, key_type, value_type, map_traits > map_type;
187 TYPED_TEST_P( SkipListMap, backoff )
189 typedef typename TestFixture::rcu_type rcu_type;
190 typedef typename TestFixture::key_type key_type;
191 typedef typename TestFixture::value_type value_type;
193 struct map_traits: public cc::skip_list::traits
195 typedef typename TestFixture::cmp compare;
196 typedef typename TestFixture::less less;
197 typedef cds::atomicity::item_counter item_counter;
198 typedef cds::backoff::yield back_off;
200 typedef cc::SkipListMap< rcu_type, key_type, value_type, map_traits > map_type;
206 TYPED_TEST_P( SkipListMap, stat )
208 typedef typename TestFixture::rcu_type rcu_type;
209 typedef typename TestFixture::key_type key_type;
210 typedef typename TestFixture::value_type value_type;
212 struct map_traits: public cc::skip_list::traits
214 typedef typename TestFixture::cmp compare;
215 typedef typename TestFixture::less less;
216 typedef cds::atomicity::item_counter item_counter;
217 typedef cds::backoff::yield back_off;
218 typedef cc::skip_list::stat<> stat;
220 typedef cc::SkipListMap< rcu_type, key_type, value_type, map_traits > map_type;
226 TYPED_TEST_P( SkipListMap, random_level_generator )
228 typedef typename TestFixture::rcu_type rcu_type;
229 typedef typename TestFixture::key_type key_type;
230 typedef typename TestFixture::value_type value_type;
232 struct map_traits: public cc::skip_list::traits
234 typedef typename TestFixture::cmp compare;
235 typedef typename TestFixture::less less;
236 typedef cds::atomicity::item_counter item_counter;
237 typedef cc::skip_list::stat<> stat;
238 typedef cc::skip_list::xorshift random_level_generator;
239 typedef cds::opt::v::rcu_assert_deadlock rcu_check_deadlock;
241 typedef cc::SkipListMap< rcu_type, key_type, value_type, map_traits > map_type;
248 REGISTER_TYPED_TEST_CASE_P( SkipListMap,
249 compare, less, cmpmix, item_counting, backoff, stat, random_level_generator
253 #endif // CDSUNIT_MAP_TEST_SKIPLIST_RCU_H