From: khizmax Date: Sat, 2 Apr 2016 16:01:59 +0000 (+0300) Subject: Migrated SkipListMap unit test to gtest framework X-Git-Tag: v2.2.0~303 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=e952061fe74f479be0f80c37acb7a0f262f54b96;p=libcds.git Migrated SkipListMap unit test to gtest framework --- diff --git a/projects/Win/vc14/gtest-map.vcxproj b/projects/Win/vc14/gtest-map.vcxproj index 1d1b6d8e..f8d1cefb 100644 --- a/projects/Win/vc14/gtest-map.vcxproj +++ b/projects/Win/vc14/gtest-map.vcxproj @@ -65,6 +65,28 @@ + + + + + 4503 + 4503 + 4503 + 4503 + 4503 + 4503 + + + + 4503 + 4503 + 4503 + 4503 + 4503 + 4503 + + + 4503 4503 @@ -173,6 +195,8 @@ + + diff --git a/projects/Win/vc14/gtest-map.vcxproj.filters b/projects/Win/vc14/gtest-map.vcxproj.filters index d09f3f90..ef768c7c 100644 --- a/projects/Win/vc14/gtest-map.vcxproj.filters +++ b/projects/Win/vc14/gtest-map.vcxproj.filters @@ -19,6 +19,9 @@ {3f37c15c-de68-4230-9c59-bc3a2e059950} + + {1e70af02-0389-402a-bb6e-e1a399628288} + @@ -120,6 +123,30 @@ Source Files\SplitListMap + + Source Files\SkipListMap + + + Source Files\SkipListMap + + + Source Files\SkipListMap + + + Source Files\SkipListMap + + + Source Files\SkipListMap + + + Source Files\SkipListMap + + + Source Files\SkipListMap + + + Source Files\SkipListMap + @@ -146,5 +173,11 @@ Header Files + + Header Files + + + Header Files + \ No newline at end of file diff --git a/test/unit/map/CMakeLists.txt b/test/unit/map/CMakeLists.txt index c1b9a80b..96d4ad13 100644 --- a/test/unit/map/CMakeLists.txt +++ b/test/unit/map/CMakeLists.txt @@ -18,6 +18,14 @@ set(CDSGTEST_MAP_SOURCES michael_michael_rcu_gpt.cpp michael_michael_rcu_shb.cpp michael_michael_rcu_sht.cpp + skiplist_hp.cpp + skiplist_dhp.cpp + skiplist_nogc.cpp + skiplist_rcu_gpb.cpp + skiplist_rcu_gpi.cpp + skiplist_rcu_gpt.cpp + skiplist_rcu_shb.cpp + skiplist_rcu_sht.cpp split_lazy_hp.cpp split_lazy_dhp.cpp split_lazy_nogc.cpp diff --git a/test/unit/map/skiplist_dhp.cpp b/test/unit/map/skiplist_dhp.cpp new file mode 100644 index 00000000..626ed2b4 --- /dev/null +++ b/test/unit/map/skiplist_dhp.cpp @@ -0,0 +1,161 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "test_skiplist_hp.h" + +#include + +namespace { + namespace cc = cds::container; + typedef cds::gc::DHP gc_type; + + class SkipListMap_DHP : public cds_test::skiplist_map_hp + { + protected: + typedef cds_test::skiplist_map_hp base_class; + + void SetUp() + { + struct map_traits: public cc::skip_list::traits + { + typedef cmp compare; + }; + typedef cc::SkipListMap< gc_type, key_type, value_type > map_type; + + cds::gc::dhp::GarbageCollector::Construct( 16, map_type::c_nHazardPtrCount ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::dhp::GarbageCollector::Destruct(); + } + }; + + TEST_F( SkipListMap_DHP, compare ) + { + typedef cc::SkipListMap< gc_type, key_type, value_type, + typename cc::skip_list::make_traits< + cds::opt::compare< cmp > + >::type + > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_DHP, less ) + { + typedef cc::SkipListMap< gc_type, key_type, value_type, + typename cc::skip_list::make_traits< + cds::opt::less< base_class::less > + >::type + > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_DHP, cmpmix ) + { + typedef cc::SkipListMap< gc_type, key_type, value_type, + typename cc::skip_list::make_traits< + cds::opt::less< base_class::less > + ,cds::opt::compare< cmp > + >::type + > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_DHP, item_counting ) + { + struct map_traits: public cc::skip_list::traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::SkipListMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_DHP, backoff ) + { + struct map_traits: public cc::skip_list::traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + }; + typedef cc::SkipListMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_DHP, stat ) + { + struct map_traits: public cc::skip_list::traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cc::skip_list::stat<> stat; + }; + typedef cc::SkipListMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_DHP, random_level_generator ) + { + struct map_traits: public cc::skip_list::traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cc::skip_list::stat<> stat; + typedef cc::skip_list::xorshift random_level_generator; + }; + typedef cc::SkipListMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + +} // namespace diff --git a/test/unit/map/skiplist_hp.cpp b/test/unit/map/skiplist_hp.cpp new file mode 100644 index 00000000..31668129 --- /dev/null +++ b/test/unit/map/skiplist_hp.cpp @@ -0,0 +1,162 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "test_skiplist_hp.h" + +#include + +namespace { + namespace cc = cds::container; + typedef cds::gc::HP gc_type; + + class SkipListMap_HP : public cds_test::skiplist_map_hp + { + protected: + typedef cds_test::skiplist_map_hp base_class; + + void SetUp() + { + struct map_traits: public cc::skip_list::traits + { + typedef cmp compare; + }; + typedef cc::SkipListMap< gc_type, key_type, value_type > map_type; + + // +1 - for guarded_ptr + cds::gc::hp::GarbageCollector::Construct( map_type::c_nHazardPtrCount + 1, 1, 16 ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::hp::GarbageCollector::Destruct( true ); + } + }; + + TEST_F( SkipListMap_HP, compare ) + { + typedef cc::SkipListMap< gc_type, key_type, value_type, + typename cc::skip_list::make_traits< + cds::opt::compare< cmp > + >::type + > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_HP, less ) + { + typedef cc::SkipListMap< gc_type, key_type, value_type, + typename cc::skip_list::make_traits< + cds::opt::less< base_class::less > + >::type + > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_HP, cmpmix ) + { + typedef cc::SkipListMap< gc_type, key_type, value_type, + typename cc::skip_list::make_traits< + cds::opt::less< base_class::less > + ,cds::opt::compare< cmp > + >::type + > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_HP, item_counting ) + { + struct map_traits: public cc::skip_list::traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::SkipListMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_HP, backoff ) + { + struct map_traits: public cc::skip_list::traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + }; + typedef cc::SkipListMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_HP, stat ) + { + struct map_traits: public cc::skip_list::traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cc::skip_list::stat<> stat; + }; + typedef cc::SkipListMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_HP, random_level_generator ) + { + struct map_traits: public cc::skip_list::traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cc::skip_list::stat<> stat; + typedef cc::skip_list::xorshift random_level_generator; + }; + typedef cc::SkipListMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + +} // namespace diff --git a/test/unit/map/skiplist_nogc.cpp b/test/unit/map/skiplist_nogc.cpp new file mode 100644 index 00000000..a2f79572 --- /dev/null +++ b/test/unit/map/skiplist_nogc.cpp @@ -0,0 +1,196 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "test_map_nogc.h" + +#include + +namespace { + namespace cc = cds::container; + typedef cds::gc::nogc gc_type; + + class SkipListMap_NoGC : public cds_test::container_map_nogc + { + protected: + typedef cds_test::container_map_nogc base_class; + + template + void test( Map& m ) + { + // Precondition: map is empty + // Postcondition: map is empty + + base_class::test( m ); + + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + + typedef typename Map::value_type map_pair; + size_t const kkSize = base_class::kSize; + + // get_min + for ( int i = static_cast( kkSize ); i > 0; --i ) { + ASSERT_TRUE( m.insert( i ) != m.end()); + + map_pair * p = m.get_min(); + ASSERT_TRUE( p != nullptr ); + EXPECT_EQ( p->first.nKey, i ); + + p = m.get_max(); + ASSERT_TRUE( p != nullptr ); + EXPECT_EQ( p->first.nKey, kkSize ); + } + + m.clear(); + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + + // get_max + for ( int i = 0; i < static_cast( kkSize ); ++i ) { + ASSERT_TRUE( m.insert( i ) != m.end()); + + map_pair * p = m.get_max(); + ASSERT_TRUE( p != nullptr ); + EXPECT_EQ( p->first.nKey, i ); + + p = m.get_min(); + ASSERT_TRUE( p != nullptr ); + EXPECT_EQ( p->first.nKey, 0 ); + } + + m.clear(); + } + + //void SetUp() + //{} + + //void TearDown() + //{} + }; + + TEST_F( SkipListMap_NoGC, compare ) + { + typedef cc::SkipListMap< gc_type, key_type, value_type, + typename cc::skip_list::make_traits< + cds::opt::compare< cmp > + >::type + > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_NoGC, less ) + { + typedef cc::SkipListMap< gc_type, key_type, value_type, + typename cc::skip_list::make_traits< + cds::opt::less< base_class::less > + >::type + > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_NoGC, cmpmix ) + { + typedef cc::SkipListMap< gc_type, key_type, value_type, + typename cc::skip_list::make_traits< + cds::opt::less< base_class::less > + ,cds::opt::compare< cmp > + >::type + > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_NoGC, item_counting ) + { + struct map_traits: public cc::skip_list::traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::SkipListMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_NoGC, backoff ) + { + struct map_traits: public cc::skip_list::traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + }; + typedef cc::SkipListMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_NoGC, stat ) + { + struct map_traits: public cc::skip_list::traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cc::skip_list::stat<> stat; + }; + typedef cc::SkipListMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( SkipListMap_NoGC, random_level_generator ) + { + struct map_traits: public cc::skip_list::traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cc::skip_list::stat<> stat; + typedef cc::skip_list::xorshift random_level_generator; + }; + typedef cc::SkipListMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + +} // namespace diff --git a/test/unit/map/skiplist_rcu_gpb.cpp b/test/unit/map/skiplist_rcu_gpb.cpp new file mode 100644 index 00000000..cfb4fa51 --- /dev/null +++ b/test/unit/map/skiplist_rcu_gpb.cpp @@ -0,0 +1,41 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include + +#include "test_skiplist_rcu.h" + +namespace { + + typedef cds::urcu::general_buffered<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPB, SkipListMap, rcu_implementation ); diff --git a/test/unit/map/skiplist_rcu_gpi.cpp b/test/unit/map/skiplist_rcu_gpi.cpp new file mode 100644 index 00000000..deacc8db --- /dev/null +++ b/test/unit/map/skiplist_rcu_gpi.cpp @@ -0,0 +1,41 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include + +#include "test_skiplist_rcu.h" + +namespace { + + typedef cds::urcu::general_instant<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPI, SkipListMap, rcu_implementation ); diff --git a/test/unit/map/skiplist_rcu_gpt.cpp b/test/unit/map/skiplist_rcu_gpt.cpp new file mode 100644 index 00000000..b9220d35 --- /dev/null +++ b/test/unit/map/skiplist_rcu_gpt.cpp @@ -0,0 +1,41 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include + +#include "test_skiplist_rcu.h" + +namespace { + + typedef cds::urcu::general_threaded<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPT, SkipListMap, rcu_implementation ); diff --git a/test/unit/map/skiplist_rcu_shb.cpp b/test/unit/map/skiplist_rcu_shb.cpp new file mode 100644 index 00000000..b214dc37 --- /dev/null +++ b/test/unit/map/skiplist_rcu_shb.cpp @@ -0,0 +1,45 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include + +#ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED + +#include "test_skiplist_rcu.h" + +namespace { + + typedef cds::urcu::signal_buffered<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_SHB, SkipListMap, rcu_implementation ); + +#endif // CDS_URCU_SIGNAL_HANDLING_ENABLED diff --git a/test/unit/map/skiplist_rcu_sht.cpp b/test/unit/map/skiplist_rcu_sht.cpp new file mode 100644 index 00000000..f1bccdce --- /dev/null +++ b/test/unit/map/skiplist_rcu_sht.cpp @@ -0,0 +1,45 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include + +#ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED + +#include "test_skiplist_rcu.h" + +namespace { + + typedef cds::urcu::signal_threaded<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_SHT, SkipListMap, rcu_implementation ); + +#endif // CDS_URCU_SIGNAL_HANDLING_ENABLED diff --git a/test/unit/map/test_map.h b/test/unit/map/test_map.h index 8caa8fb1..4ae9fe62 100644 --- a/test/unit/map/test_map.h +++ b/test/unit/map/test_map.h @@ -122,6 +122,20 @@ namespace cds_test { } return *this; } + + value_type& operator=( int i ) + { + nVal = i; + strVal = std::to_string( i ); + return *this; + } + + value_type& operator=( std::string const& s ) + { + nVal = std::stoi( s ); + strVal = s; + return *this; + } }; typedef std::pair pair_type; diff --git a/test/unit/map/test_skiplist_hp.h b/test/unit/map/test_skiplist_hp.h new file mode 100644 index 00000000..59e4d598 --- /dev/null +++ b/test/unit/map/test_skiplist_hp.h @@ -0,0 +1,107 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef CDSUNIT_MAP_TEST_SKIPLIST_HP_H +#define CDSUNIT_MAP_TEST_SKIPLIST_HP_H + +#include "test_map_hp.h" + +namespace cds_test { + + class skiplist_map_hp: public container_map_hp + { + typedef container_map_hp base_class; + + protected: + template + void test( Map& m ) + { + // Precondition: map is empty + // Postcondition: map is empty + + base_class::test( m ); + + ASSERT_TRUE( m.empty()); + ASSERT_CONTAINER_SIZE( m, 0 ); + + typedef typename Map::value_type map_pair; + size_t const kkSize = base_class::kSize; + + std::vector arrKeys; + for ( int i = 0; i < static_cast(kkSize); ++i ) + arrKeys.push_back( key_type( i )); + shuffle( arrKeys.begin(), arrKeys.end()); + + for ( auto const& i : arrKeys ) + ASSERT_TRUE( m.insert( i ) ); + ASSERT_FALSE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, kkSize ); + + // extract_min + typedef typename Map::guarded_ptr guarded_ptr; + guarded_ptr gp; + + int nKey = -1; + size_t nCount = 0; + while ( !m.empty() ) { + gp = m.extract_min(); + ASSERT_FALSE( !gp ); + EXPECT_EQ( gp->first.nKey, nKey + 1 ); + nKey = gp->first.nKey; + ++nCount; + } + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + EXPECT_EQ( nCount, kkSize ); + + // extract_max + for ( auto const& i : arrKeys ) + ASSERT_TRUE( m.insert( i ) ); + ASSERT_FALSE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, kkSize ); + + nKey = kkSize; + nCount = 0; + while ( !m.empty() ) { + gp = m.extract_max(); + ASSERT_FALSE( !gp ); + EXPECT_EQ( gp->first.nKey, nKey - 1 ); + nKey = gp->first.nKey; + ++nCount; + } + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + EXPECT_EQ( nCount, kkSize ); + } + }; + +} // namespace cds_test + +#endif // #ifndef CDSUNIT_MAP_TEST_SKIPLIST_HP_H diff --git a/test/unit/map/test_skiplist_rcu.h b/test/unit/map/test_skiplist_rcu.h new file mode 100644 index 00000000..ea0d3edb --- /dev/null +++ b/test/unit/map/test_skiplist_rcu.h @@ -0,0 +1,255 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef CDSUNIT_MAP_TEST_SKIPLIST_RCU_H +#define CDSUNIT_MAP_TEST_SKIPLIST_RCU_H + +#include "test_map_rcu.h" +#include + +namespace cc = cds::container; + +template +class SkipListMap: public cds_test::container_map_rcu +{ + typedef cds_test::container_map_rcu base_class; +public: + typedef cds::urcu::gc rcu_type; + +protected: + template + void test( Map& m ) + { + // Precondition: map is empty + // Postcondition: map is empty + + base_class::test( m ); + + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + + typedef typename Map::value_type map_pair; + typedef typename Map::exempt_ptr exempt_ptr; + size_t const kkSize = base_class::kSize; + + // get_min + for ( int i = static_cast(kkSize); i > 0; --i ) + ASSERT_TRUE( m.insert( i )); + + exempt_ptr xp; + + size_t nCount = 0; + int nKey = 0; + while ( !m.empty() ) { + xp = m.extract_min(); + ASSERT_FALSE( !xp ); + EXPECT_EQ( xp->first.nKey, nKey + 1 ); + nKey = xp->first.nKey; + ++nCount; + } + xp = m.extract_min(); + ASSERT_TRUE( !xp ); + xp = m.extract_max(); + ASSERT_TRUE( !xp ); + EXPECT_EQ( kkSize, nCount ); + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + + // get_max + for ( int i = 0; i < static_cast(kkSize); ++i ) + ASSERT_TRUE( m.insert( i )); + + nKey = kkSize; + nCount = 0; + while ( !m.empty() ) { + xp = m.extract_max(); + ASSERT_FALSE( !xp ); + EXPECT_EQ( xp->first.nKey, nKey - 1 ); + nKey = xp->first.nKey; + ++nCount; + } + xp = m.extract_min(); + ASSERT_TRUE( !xp ); + xp = m.extract_max(); + ASSERT_TRUE( !xp ); + EXPECT_EQ( kkSize, nCount ); + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + } + + void SetUp() + { + RCU::Construct(); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + RCU::Destruct(); + } +}; + +TYPED_TEST_CASE_P( SkipListMap ); + +TYPED_TEST_P( SkipListMap, compare ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + typedef cc::SkipListMap< rcu_type, key_type, value_type, + typename cc::skip_list::make_traits< + cds::opt::compare< typename TestFixture::cmp > + >::type + > map_type; + + map_type m; + this->test( m ); +} + +TYPED_TEST_P( SkipListMap, less ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + typedef cc::SkipListMap< rcu_type, key_type, value_type, + typename cc::skip_list::make_traits< + cds::opt::less< typename TestFixture::less > + >::type + > map_type; + + map_type m; + this->test( m ); +} + +TYPED_TEST_P( SkipListMap, cmpmix ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + typedef cc::SkipListMap< rcu_type, key_type, value_type, + typename cc::skip_list::make_traits< + cds::opt::less< typename TestFixture::less > + ,cds::opt::compare< typename TestFixture::cmp > + >::type + > map_type; + + map_type m; + this->test( m ); +} + +TYPED_TEST_P( SkipListMap, item_counting ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + struct map_traits: public cc::skip_list::traits + { + typedef typename TestFixture::cmp compare; + typedef typename TestFixture::less less; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::SkipListMap< rcu_type, key_type, value_type, map_traits > map_type; + + map_type m; + this->test( m ); +} + +TYPED_TEST_P( SkipListMap, backoff ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + struct map_traits: public cc::skip_list::traits + { + typedef typename TestFixture::cmp compare; + typedef typename TestFixture::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + }; + typedef cc::SkipListMap< rcu_type, key_type, value_type, map_traits > map_type; + + map_type m; + this->test( m ); +} + +TYPED_TEST_P( SkipListMap, stat ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + struct map_traits: public cc::skip_list::traits + { + typedef typename TestFixture::cmp compare; + typedef typename TestFixture::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cc::skip_list::stat<> stat; + }; + typedef cc::SkipListMap< rcu_type, key_type, value_type, map_traits > map_type; + + map_type m; + this->test( m ); +} + +TYPED_TEST_P( SkipListMap, random_level_generator ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + struct map_traits: public cc::skip_list::traits + { + typedef typename TestFixture::cmp compare; + typedef typename TestFixture::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cc::skip_list::stat<> stat; + typedef cc::skip_list::xorshift random_level_generator; + typedef cds::opt::v::rcu_assert_deadlock rcu_check_deadlock; + }; + typedef cc::SkipListMap< rcu_type, key_type, value_type, map_traits > map_type; + + map_type m; + this->test( m ); +} + + +REGISTER_TYPED_TEST_CASE_P( SkipListMap, + compare, less, cmpmix, item_counting, backoff, stat, random_level_generator +); + + +#endif // CDSUNIT_MAP_TEST_SKIPLIST_RCU_H + \ No newline at end of file