From 7494864886f031629eae22b9d93106ac0264d69d Mon Sep 17 00:00:00 2001 From: khizmax Date: Sat, 19 Mar 2016 19:00:20 +0300 Subject: [PATCH] Migrated FeldmanHashSet unit test to gtest framework --- projects/Win/vc14/gtest-set.vcxproj | 10 + projects/Win/vc14/gtest-set.vcxproj.filters | 33 ++ test/unit/set/CMakeLists.txt | 7 + test/unit/set/feldman_hashset_dhp.cpp | 159 ++++++++ test/unit/set/feldman_hashset_hp.cpp | 160 ++++++++ test/unit/set/feldman_hashset_rcu_gpb.cpp | 41 ++ test/unit/set/feldman_hashset_rcu_gpi.cpp | 41 ++ test/unit/set/feldman_hashset_rcu_gpt.cpp | 41 ++ test/unit/set/feldman_hashset_rcu_shb.cpp | 45 +++ test/unit/set/feldman_hashset_rcu_sht.cpp | 45 +++ test/unit/set/test_feldman_hashset.h | 424 ++++++++++++++++++++ test/unit/set/test_feldman_hashset_hp.h | 149 +++++++ test/unit/set/test_feldman_hashset_rcu.h | 290 +++++++++++++ 13 files changed, 1445 insertions(+) create mode 100644 test/unit/set/feldman_hashset_dhp.cpp create mode 100644 test/unit/set/feldman_hashset_hp.cpp create mode 100644 test/unit/set/feldman_hashset_rcu_gpb.cpp create mode 100644 test/unit/set/feldman_hashset_rcu_gpi.cpp create mode 100644 test/unit/set/feldman_hashset_rcu_gpt.cpp create mode 100644 test/unit/set/feldman_hashset_rcu_shb.cpp create mode 100644 test/unit/set/feldman_hashset_rcu_sht.cpp create mode 100644 test/unit/set/test_feldman_hashset.h create mode 100644 test/unit/set/test_feldman_hashset_hp.h create mode 100644 test/unit/set/test_feldman_hashset_rcu.h diff --git a/projects/Win/vc14/gtest-set.vcxproj b/projects/Win/vc14/gtest-set.vcxproj index df5b23b6..4aacc470 100644 --- a/projects/Win/vc14/gtest-set.vcxproj +++ b/projects/Win/vc14/gtest-set.vcxproj @@ -28,6 +28,13 @@ + + + + + + + 4503 4503 @@ -196,6 +203,9 @@ + + + diff --git a/projects/Win/vc14/gtest-set.vcxproj.filters b/projects/Win/vc14/gtest-set.vcxproj.filters index aad25aaa..e86e1df2 100644 --- a/projects/Win/vc14/gtest-set.vcxproj.filters +++ b/projects/Win/vc14/gtest-set.vcxproj.filters @@ -22,6 +22,9 @@ {5c30de7f-5e68-4ef5-b9a5-63a1ec626010} + + {0f6f4b41-97bc-411f-b24e-790ff162e314} + @@ -147,6 +150,27 @@ Source Files\SkipList + + Source Files\FeldmanHashSet + + + Source Files\FeldmanHashSet + + + Source Files\FeldmanHashSet + + + Source Files\FeldmanHashSet + + + Source Files\FeldmanHashSet + + + Source Files\FeldmanHashSet + + + Source Files\FeldmanHashSet + @@ -176,5 +200,14 @@ Header Files + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/test/unit/set/CMakeLists.txt b/test/unit/set/CMakeLists.txt index 0dae6f46..dcd684a1 100644 --- a/test/unit/set/CMakeLists.txt +++ b/test/unit/set/CMakeLists.txt @@ -2,6 +2,13 @@ set(PACKAGE_NAME unit-set) set(CDSGTEST_SET_SOURCES ../main.cpp + feldman_hashset_hp.cpp + feldman_hashset_dhp.cpp + feldman_hashset_rcu_gpb.cpp + feldman_hashset_rcu_gpi.cpp + feldman_hashset_rcu_gpt.cpp + feldman_hashset_rcu_shb.cpp + feldman_hashset_rcu_sht.cpp michael_lazy_hp.cpp michael_lazy_dhp.cpp michael_lazy_nogc.cpp diff --git a/test/unit/set/feldman_hashset_dhp.cpp b/test/unit/set/feldman_hashset_dhp.cpp new file mode 100644 index 00000000..af80c861 --- /dev/null +++ b/test/unit/set/feldman_hashset_dhp.cpp @@ -0,0 +1,159 @@ +/* + 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_feldman_hashset_hp.h" + +#include + +namespace { + namespace cc = cds::container; + typedef cds::gc::DHP gc_type; + + class FeldmanHashSet_DHP : public cds_test::feldman_hashset_hp + { + protected: + typedef cds_test::feldman_hashset_hp base_class; + + void SetUp() + { + struct set_traits: public cc::feldman_hashset::traits + { + typedef get_hash hash_accessor; + }; + typedef cc::FeldmanHashSet< gc_type, int_item, set_traits > set_type; + + cds::gc::dhp::GarbageCollector::Construct( 16, set_type::c_nHazardPtrCount ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::dhp::GarbageCollector::Destruct(); + } + }; + + TEST_F( FeldmanHashSet_DHP, defaulted ) + { + typedef cc::FeldmanHashSet< gc_type, int_item, + typename cc::feldman_hashset::make_traits< + cc::feldman_hashset::hash_accessor< get_hash > + >::type + > set_type; + + set_type s; + test( s ); + } + + TEST_F( FeldmanHashSet_DHP, compare ) + { + typedef cc::FeldmanHashSet< gc_type, int_item, + typename cc::feldman_hashset::make_traits< + cc::feldman_hashset::hash_accessor< get_hash > + ,cds::opt::compare< cmp > + >::type + > set_type; + + set_type s( 4, 5 ); + test( s ); + } + + TEST_F( FeldmanHashSet_DHP, less ) + { + typedef cc::FeldmanHashSet< gc_type, int_item, + typename cc::feldman_hashset::make_traits< + cc::feldman_hashset::hash_accessor< get_hash > + ,cds::opt::less< std::less > + >::type + > set_type; + + set_type s( 3, 2 ); + test( s ); + } + + TEST_F( FeldmanHashSet_DHP, cmpmix ) + { + typedef cc::FeldmanHashSet< gc_type, int_item, + typename cc::feldman_hashset::make_traits< + cc::feldman_hashset::hash_accessor< get_hash > + , cds::opt::less< std::less > + ,cds::opt::compare< cmp > + >::type + > set_type; + + set_type s( 4, 4 ); + test( s ); + } + + TEST_F( FeldmanHashSet_DHP, item_counting ) + { + struct set_traits: public cc::feldman_hashset::traits + { + typedef get_hash hash_accessor; + typedef cmp compare; + typedef std::less less; + typedef simple_item_counter item_counter; + }; + typedef cc::FeldmanHashSet< gc_type, int_item, set_traits > set_type; + + set_type s( 3, 3 ); + test( s ); + } + + TEST_F( FeldmanHashSet_DHP, backoff ) + { + struct set_traits: public cc::feldman_hashset::traits + { + typedef get_hash hash_accessor; + typedef cmp compare; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + }; + typedef cc::FeldmanHashSet< gc_type, int_item, set_traits > set_type; + + set_type s( 8, 2 ); + test( s ); + } + + TEST_F( FeldmanHashSet_DHP, stat ) + { + struct set_traits: public cc::feldman_hashset::traits + { + typedef get_hash hash_accessor; + typedef cds::backoff::yield back_off; + typedef cc::feldman_hashset::stat<> stat; + }; + typedef cc::FeldmanHashSet< gc_type, int_item, set_traits > set_type; + + set_type s( 1, 1 ); + test( s ); + } + +} // namespace diff --git a/test/unit/set/feldman_hashset_hp.cpp b/test/unit/set/feldman_hashset_hp.cpp new file mode 100644 index 00000000..d5f6e185 --- /dev/null +++ b/test/unit/set/feldman_hashset_hp.cpp @@ -0,0 +1,160 @@ +/* + 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_feldman_hashset_hp.h" + +#include + +namespace { + namespace cc = cds::container; + typedef cds::gc::HP gc_type; + + class FeldmanHashSet_HP : public cds_test::feldman_hashset_hp + { + protected: + typedef cds_test::feldman_hashset_hp base_class; + + void SetUp() + { + struct set_traits: public cc::feldman_hashset::traits + { + typedef get_hash hash_accessor; + }; + typedef cc::FeldmanHashSet< gc_type, int_item, set_traits > set_type; + + // +1 - for guarded_ptr + cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::hp::GarbageCollector::Destruct( true ); + } + }; + + TEST_F( FeldmanHashSet_HP, defaulted ) + { + typedef cc::FeldmanHashSet< gc_type, int_item, + typename cc::feldman_hashset::make_traits< + cc::feldman_hashset::hash_accessor< get_hash > + >::type + > set_type; + + set_type s; + test( s ); + } + + TEST_F( FeldmanHashSet_HP, compare ) + { + typedef cc::FeldmanHashSet< gc_type, int_item, + typename cc::feldman_hashset::make_traits< + cc::feldman_hashset::hash_accessor< get_hash > + ,cds::opt::compare< cmp > + >::type + > set_type; + + set_type s( 4, 5 ); + test( s ); + } + + TEST_F( FeldmanHashSet_HP, less ) + { + typedef cc::FeldmanHashSet< gc_type, int_item, + typename cc::feldman_hashset::make_traits< + cc::feldman_hashset::hash_accessor< get_hash > + ,cds::opt::less< std::less > + >::type + > set_type; + + set_type s( 3, 2 ); + test( s ); + } + + TEST_F( FeldmanHashSet_HP, cmpmix ) + { + typedef cc::FeldmanHashSet< gc_type, int_item, + typename cc::feldman_hashset::make_traits< + cc::feldman_hashset::hash_accessor< get_hash > + , cds::opt::less< std::less > + ,cds::opt::compare< cmp > + >::type + > set_type; + + set_type s( 4, 4 ); + test( s ); + } + + TEST_F( FeldmanHashSet_HP, item_counting ) + { + struct set_traits: public cc::feldman_hashset::traits + { + typedef get_hash hash_accessor; + typedef cmp compare; + typedef std::less less; + typedef simple_item_counter item_counter; + }; + typedef cc::FeldmanHashSet< gc_type, int_item, set_traits > set_type; + + set_type s( 3, 3 ); + test( s ); + } + + TEST_F( FeldmanHashSet_HP, backoff ) + { + struct set_traits: public cc::feldman_hashset::traits + { + typedef get_hash hash_accessor; + typedef cmp compare; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + }; + typedef cc::FeldmanHashSet< gc_type, int_item, set_traits > set_type; + + set_type s( 8, 2 ); + test( s ); + } + + TEST_F( FeldmanHashSet_HP, stat ) + { + struct set_traits: public cc::feldman_hashset::traits + { + typedef get_hash hash_accessor; + typedef cds::backoff::yield back_off; + typedef cc::feldman_hashset::stat<> stat; + }; + typedef cc::FeldmanHashSet< gc_type, int_item, set_traits > set_type; + + set_type s( 1, 1 ); + test( s ); + } + +} // namespace diff --git a/test/unit/set/feldman_hashset_rcu_gpb.cpp b/test/unit/set/feldman_hashset_rcu_gpb.cpp new file mode 100644 index 00000000..9e01f1d8 --- /dev/null +++ b/test/unit/set/feldman_hashset_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_feldman_hashset_rcu.h" + +namespace { + + typedef cds::urcu::general_buffered<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPB, FeldmanHashSet, rcu_implementation ); diff --git a/test/unit/set/feldman_hashset_rcu_gpi.cpp b/test/unit/set/feldman_hashset_rcu_gpi.cpp new file mode 100644 index 00000000..478c69b8 --- /dev/null +++ b/test/unit/set/feldman_hashset_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_feldman_hashset_rcu.h" + +namespace { + + typedef cds::urcu::general_instant<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPI, FeldmanHashSet, rcu_implementation ); diff --git a/test/unit/set/feldman_hashset_rcu_gpt.cpp b/test/unit/set/feldman_hashset_rcu_gpt.cpp new file mode 100644 index 00000000..33c4fb76 --- /dev/null +++ b/test/unit/set/feldman_hashset_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_feldman_hashset_rcu.h" + +namespace { + + typedef cds::urcu::general_threaded<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPT, FeldmanHashSet, rcu_implementation ); diff --git a/test/unit/set/feldman_hashset_rcu_shb.cpp b/test/unit/set/feldman_hashset_rcu_shb.cpp new file mode 100644 index 00000000..bacf8305 --- /dev/null +++ b/test/unit/set/feldman_hashset_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_feldman_hashset_rcu.h" + +namespace { + + typedef cds::urcu::signal_buffered<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_SHB, FeldmanHashSet, rcu_implementation ); + +#endif // CDS_URCU_SIGNAL_HANDLING_ENABLED diff --git a/test/unit/set/feldman_hashset_rcu_sht.cpp b/test/unit/set/feldman_hashset_rcu_sht.cpp new file mode 100644 index 00000000..e169b41b --- /dev/null +++ b/test/unit/set/feldman_hashset_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_feldman_hashset_rcu.h" + +namespace { + + typedef cds::urcu::signal_threaded<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_SHT, FeldmanHashSet, rcu_implementation ); + +#endif // CDS_URCU_SIGNAL_HANDLING_ENABLED diff --git a/test/unit/set/test_feldman_hashset.h b/test/unit/set/test_feldman_hashset.h new file mode 100644 index 00000000..1bfbe3a0 --- /dev/null +++ b/test/unit/set/test_feldman_hashset.h @@ -0,0 +1,424 @@ +/* + 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_SET_TEST_FELDMAN_HASHSET_H +#define CDSUNIT_SET_TEST_FELDMAN_HASHSET_H + +#include +#include + +#include + +// forward declaration +namespace cds { namespace container {}} +namespace co = cds::opt; +namespace cc = cds::container; + +namespace cds_test { + + class feldman_hashset : public fixture + { + public: + static size_t const kSize = 1000; + + struct stat + { + unsigned int nFindCount; + unsigned int nUpdateNewCount; + unsigned int nUpdateCount; + + stat() + { + clear_stat(); + } + + void clear_stat() + { + memset( this, 0, sizeof( *this ) ); + } + }; + + struct other_item { + int nKey; + + explicit other_item( int k ) + : nKey( k ) + {} + + int key() const + { + return nKey; + } + }; + + struct int_item: public stat + { + int nKey; + int nVal; + std::string strVal; + + int_item() + : nKey( 0 ) + , nVal( 0 ) + {} + + explicit int_item( int k ) + : nKey( k ) + , nVal( k * 2 ) + {} + + template + explicit int_item( Q const& src ) + : nKey( src.key() ) + , nVal( 0 ) + {} + + int_item( int_item const& src ) + : nKey( src.nKey ) + , nVal( src.nVal ) + , strVal( src.strVal ) + {} + + int_item( int_item&& src ) + : nKey( src.nKey ) + , nVal( src.nVal ) + , strVal( std::move( src.strVal ) ) + {} + + int_item( int k, std::string&& s ) + : nKey( k ) + , nVal( k * 2 ) + , strVal( std::move( s ) ) + {} + + explicit int_item( other_item const& s ) + : nKey( s.key() ) + , nVal( s.key() * 2 ) + {} + + int key() const + { + return nKey; + } + }; + + struct get_hash { + int operator()( int_item const& i ) const + { + return i.key(); + } + + int operator()( other_item const& i ) const + { + return i.key(); + } + + int operator()( int i ) const + { + return i; + } + }; + + struct simple_item_counter { + size_t m_nCount; + + simple_item_counter() + : m_nCount( 0 ) + {} + + size_t operator ++() + { + return ++m_nCount; + } + + size_t operator --() + { + return --m_nCount; + } + + void reset() + { + m_nCount = 0; + } + + operator size_t() const + { + return m_nCount; + } + + }; + + struct cmp { + int operator ()( int v1, int v2 ) const + { + if ( v1 < v2 ) + return -1; + return v1 > v2 ? 1 : 0; + } + }; + + struct other_less { + template + bool operator()( Q const& lhs, T const& rhs ) const + { + return lhs.key() < rhs.key(); + } + }; + + protected: + template + void test( Set& s ) + { + // Precondition: set is empty + // Postcondition: set is empty + + ASSERT_TRUE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, 0 ); + size_t const nSetSize = kSize; + + typedef typename Set::value_type value_type; + + std::vector< value_type > data; + std::vector< size_t> indices; + data.reserve( kSize ); + indices.reserve( kSize ); + for ( size_t key = 0; key < kSize; ++key ) { + data.push_back( value_type( static_cast(key) ) ); + indices.push_back( key ); + } + shuffle( indices.begin(), indices.end() ); + + // insert/find + for ( auto idx : indices ) { + auto& i = data[idx]; + + ASSERT_FALSE( s.contains( i.nKey ) ); + ASSERT_FALSE( s.find( i.nKey, []( value_type& ) {} )); + + std::pair updResult; + + std::string str; + updResult = s.update( i.key(), []( value_type&, value_type * ) + { + ASSERT_TRUE( false ); + }, false ); + EXPECT_FALSE( updResult.first ); + EXPECT_FALSE( updResult.second ); + + switch ( idx % 8 ) { + case 0: + ASSERT_TRUE( s.insert( i )); + ASSERT_FALSE( s.insert( i )); + updResult = s.update( i, []( value_type& val, value_type * prev ) + { + ASSERT_TRUE( prev != nullptr ); + EXPECT_EQ( val.key(), prev->key() ); + }, false ); + EXPECT_TRUE( updResult.first ); + EXPECT_FALSE( updResult.second ); + break; + case 1: + ASSERT_TRUE( s.insert( i.key() )); + ASSERT_FALSE( s.insert( i.key() )); + updResult = s.update( i.key(), []( value_type& val, value_type * prev ) + { + ASSERT_TRUE( prev != nullptr ); + EXPECT_EQ( val.key(), prev->key() ); + }, false ); + EXPECT_TRUE( updResult.first ); + EXPECT_FALSE( updResult.second ); + break; + case 2: + ASSERT_TRUE( s.insert( i, []( value_type& v ) { ++v.nFindCount; } )); + ASSERT_FALSE( s.insert( i, []( value_type& v ) { ++v.nFindCount; } )); + ASSERT_TRUE( s.find( i.nKey, []( value_type const& v ) + { + EXPECT_EQ( v.nFindCount, 1 ); + })); + break; + case 3: + ASSERT_TRUE( s.insert( i.key(), []( value_type& v ) { ++v.nFindCount; } )); + ASSERT_FALSE( s.insert( i.key(), []( value_type& v ) { ++v.nFindCount; } )); + ASSERT_TRUE( s.find( i.nKey, []( value_type const& v ) + { + EXPECT_EQ( v.nFindCount, 1 ); + })); + break; + case 4: + updResult = s.update( i, []( value_type& v, value_type * prev ) + { + EXPECT_TRUE( prev == nullptr ); + ++v.nUpdateNewCount; + }); + EXPECT_TRUE( updResult.first ); + EXPECT_TRUE( updResult.second ); + + updResult = s.update( i, []( value_type& v, value_type * prev ) + { + ASSERT_TRUE( prev != nullptr ); + EXPECT_EQ( prev->nUpdateNewCount, 1 ); + EXPECT_EQ( v.key(), prev->key() ); + ++v.nUpdateCount; + }, false ); + EXPECT_TRUE( updResult.first ); + EXPECT_FALSE( updResult.second ); + + ASSERT_TRUE( s.find( i.nKey, []( value_type const& v ) + { + EXPECT_EQ( v.nUpdateCount, 1 ); + EXPECT_EQ( v.nUpdateNewCount, 0 ); + })); + break; + case 5: + updResult = s.update( i.key(), []( value_type& v, value_type * prev ) + { + EXPECT_TRUE( prev == nullptr ); + ++v.nUpdateNewCount; + }); + EXPECT_TRUE( updResult.first ); + EXPECT_TRUE( updResult.second ); + + updResult = s.update( i.key(), []( value_type& v, value_type * prev ) + { + ASSERT_TRUE( prev != nullptr ); + EXPECT_EQ( v.key(), prev->key() ); + EXPECT_EQ( prev->nUpdateNewCount, 1 ); + EXPECT_EQ( v.nUpdateNewCount, 0 ); + ++v.nUpdateNewCount; + }, false ); + EXPECT_TRUE( updResult.first ); + EXPECT_FALSE( updResult.second ); + + ASSERT_TRUE( s.find( i.key(), []( value_type const& v ) + { + EXPECT_EQ( v.nUpdateNewCount, 1 ); + } ) ); + break; + case 6: + ASSERT_TRUE( s.emplace( i.key() ) ); + ASSERT_TRUE( s.contains( i.key() ) ); + break; + case 7: + str = "Hello!"; + ASSERT_TRUE( s.emplace( i.key(), std::move( str ) ) ); + EXPECT_TRUE( str.empty() ); + ASSERT_TRUE( s.find( i.key(), []( value_type const& v ) + { + EXPECT_EQ( v.strVal, std::string( "Hello!" ) ); + } ) ); + break; + default: + // forgot anything?.. + ASSERT_TRUE( false ); + } + + ASSERT_TRUE( s.contains( i.nKey ) ); + ASSERT_TRUE( s.find( i.nKey, []( value_type& ) {} ) ); + } + + ASSERT_FALSE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, nSetSize ); + + // erase + shuffle( indices.begin(), indices.end() ); + for ( auto idx : indices ) { + auto& i = data[idx]; + + ASSERT_TRUE( s.contains( i.nKey ) ); + ASSERT_TRUE( s.find( i.nKey, []( value_type& v ) + { + v.nFindCount = 1; + } ) ); + + int nKey = i.key() - 1; + switch ( idx % 2 ) { + case 0: + ASSERT_TRUE( s.erase( i.key() ) ); + ASSERT_FALSE( s.erase( i.key() ) ); + break; + case 1: + ASSERT_TRUE( s.erase( i.key(), [&nKey]( value_type const& v ) + { + EXPECT_EQ( v.nFindCount, 1 ); + nKey = v.key(); + } ) ); + EXPECT_EQ( i.key(), nKey ); + + nKey = i.key() - 1; + ASSERT_FALSE( s.erase( i.key(), [&nKey]( value_type const& v ) + { + nKey = v.key(); + } ) ); + EXPECT_EQ( i.key(), nKey + 1 ); + break; + } + + ASSERT_FALSE( s.contains( i.nKey ) ); + ASSERT_FALSE( s.find( i.nKey, []( value_type const& ) {} ) ); + } + ASSERT_TRUE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, 0 ); + + + // clear + for ( auto& i : data ) { + ASSERT_TRUE( s.insert( i ) ); + } + + { + typename Set::stat const& statistics = s.statistics(); + CDS_UNUSED( statistics ); + + std::vector< typename Set::level_statistics > lstat; + s.get_level_statistics( lstat ); + EXPECT_EQ( lstat[0].node_capacity, s.head_size() ); + for ( size_t i = 1; i < lstat.size(); ++i ) { + EXPECT_EQ( lstat[i].node_capacity, s.array_node_size()); + } + } + + ASSERT_FALSE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, nSetSize ); + + s.clear(); + + ASSERT_TRUE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, 0 ); + + ASSERT_TRUE( s.begin() == s.end() ); + ASSERT_TRUE( s.cbegin() == s.cend() ); + ASSERT_TRUE( s.rbegin() == s.rend() ); + ASSERT_TRUE( s.crbegin() == s.crend() ); + } + }; + +} // namespace cds_test + +#endif // CDSUNIT_SET_TEST_FELDMAN_HASHSET_H diff --git a/test/unit/set/test_feldman_hashset_hp.h b/test/unit/set/test_feldman_hashset_hp.h new file mode 100644 index 00000000..aa06b343 --- /dev/null +++ b/test/unit/set/test_feldman_hashset_hp.h @@ -0,0 +1,149 @@ +/* + 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_SET_TEST_FELDMAN_HASHSET_HP_H +#define CDSUNIT_SET_TEST_FELDMAN_HASHSET_HP_H + +#include "test_feldman_hashset.h" + +namespace cds_test { + + class feldman_hashset_hp: public feldman_hashset + { + typedef feldman_hashset base_class; + + protected: + template + void test( Set& s ) + { + // Precondition: set is empty + // Postcondition: set is empty + + ASSERT_TRUE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, 0 ); + + base_class::test( s ); + + typedef typename Set::value_type value_type; + + size_t const nSetSize = kSize; + std::vector< value_type > data; + std::vector< size_t> indices; + data.reserve( kSize ); + indices.reserve( kSize ); + for ( size_t key = 0; key < kSize; ++key ) { + data.push_back( value_type( static_cast(key) ) ); + indices.push_back( key ); + } + shuffle( indices.begin(), indices.end() ); + + for ( auto& i : data ) { + ASSERT_TRUE( s.insert( i ) ); + } + ASSERT_FALSE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, nSetSize ); + + // iterator test + for ( auto it = s.begin(); it != s.end(); ++it ) { + it->nFindCount = it->key() * 3; + it.release(); + } + + for ( auto it = s.cbegin(); it != s.cend(); ++it ) { + EXPECT_EQ( it->nFindCount, it->key() * 3 ); + } + + // reverse iterator set + for ( auto it = s.rbegin(); it != s.rend(); ++it ) { + it->nFindCount = it->key() * 2; + } + + for ( auto it = s.crbegin(); it != s.crend(); ++it ) { + EXPECT_EQ( it->nFindCount, it->key() * 2 ); + } + + typedef typename Set::guarded_ptr guarded_ptr; + guarded_ptr gp; + + // get() + for ( auto idx : indices ) { + auto& i = data[idx]; + + ASSERT_TRUE( !gp ); + + gp = s.get( i.key()); + ASSERT_FALSE( !gp ); + EXPECT_EQ( gp->key(), i.key() ); + EXPECT_EQ( gp->nFindCount, i.key() * 2 ); + gp->nFindCount *= 2; + + gp.release(); + } + + // extract() + for ( auto idx : indices ) { + auto& i = data[idx]; + + ASSERT_TRUE( !gp ); + gp = s.extract( i.key() ); + ASSERT_FALSE( !gp ); + EXPECT_EQ( gp->key(), i.key() ); + EXPECT_EQ( gp->nFindCount, i.key() * 4 ); + + gp = s.extract( i.key() ); + ASSERT_TRUE( !gp ); + } + + ASSERT_TRUE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, 0 ); + + // erase_at() + for ( auto& i : data ) { + ASSERT_TRUE( s.insert( i ) ); + } + ASSERT_FALSE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, nSetSize ); + + for ( auto it = s.begin(); it != s.end(); ++it ) { + int key = it->key(); + ASSERT_TRUE( s.erase_at( it )); + ASSERT_TRUE( &*it != nullptr ); + EXPECT_EQ( it->key(), key ); + ASSERT_FALSE( s.erase_at( it ) ); + } + + ASSERT_TRUE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, 0 ); + } + + }; +} // namespace cds_test + +#endif // CDSUNIT_SET_TEST_FELDMAN_HASHSET_HP_H diff --git a/test/unit/set/test_feldman_hashset_rcu.h b/test/unit/set/test_feldman_hashset_rcu.h new file mode 100644 index 00000000..b5afb6af --- /dev/null +++ b/test/unit/set/test_feldman_hashset_rcu.h @@ -0,0 +1,290 @@ +/* + 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_SET_TEST_FELDMAN_HASHSET_RCU_H +#define CDSUNIT_SET_TEST_FELDMAN_HASHSET_RCU_H + +#include "test_feldman_hashset.h" + +#include + +namespace { + + namespace cc = cds::container; + + template + class FeldmanHashSet: public cds_test::feldman_hashset + { + typedef cds_test::feldman_hashset base_class; + + protected: + typedef cds::urcu::gc rcu_type; + + template + void test( Set& s ) + { + // Precondition: set is empty + // Postcondition: set is empty + + ASSERT_TRUE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, 0 ); + + base_class::test( s ); + + typedef typename Set::value_type value_type; + + size_t const nSetSize = kSize; + std::vector< value_type > data; + std::vector< size_t> indices; + data.reserve( kSize ); + indices.reserve( kSize ); + for ( size_t key = 0; key < kSize; ++key ) { + data.push_back( value_type( static_cast(key) ) ); + indices.push_back( key ); + } + shuffle( indices.begin(), indices.end() ); + + for ( auto& i : data ) { + ASSERT_TRUE( s.insert( i ) ); + } + ASSERT_FALSE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, nSetSize ); + + typedef typename Set::rcu_lock rcu_lock; + + // iterator test + { + rcu_lock l; + + for ( auto it = s.begin(); it != s.end(); ++it ) { + it->nFindCount = it->key() * 3; + } + + for ( auto it = s.cbegin(); it != s.cend(); ++it ) { + EXPECT_EQ( it->nFindCount, it->key() * 3 ); + } + + for ( auto it = s.rbegin(); it != s.rend(); ++it ) { + it->nFindCount = it->key() * 2; + } + + for ( auto it = s.crbegin(); it != s.crend(); ++it ) { + EXPECT_EQ( it->nFindCount, it->key() * 2 ); + } + } + + typedef typename Set::exempt_ptr exempt_ptr; + + // get() + for ( auto idx : indices ) { + auto& i = data[idx]; + + { + rcu_lock l; + value_type * p = s.get( i.key()); + ASSERT_TRUE( p != nullptr ); + EXPECT_EQ( p->key(), i.key() ); + EXPECT_EQ( p->nFindCount, i.key() * 2 ); + p->nFindCount *= 2; + } + } + + // extract() + exempt_ptr xp; + for ( auto idx : indices ) { + auto& i = data[idx]; + + ASSERT_TRUE( !xp ); + xp = s.extract( i.key() ); + ASSERT_FALSE( !xp ); + EXPECT_EQ( xp->key(), i.key() ); + EXPECT_EQ( xp->nFindCount, i.key() * 4 ); + + xp = s.extract( i.key() ); + ASSERT_TRUE( !xp ); + + { + rcu_lock l; + value_type * p = s.get( i.key() ); + EXPECT_TRUE( p == nullptr ); + } + } + + ASSERT_TRUE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, 0 ); + } + + void SetUp() + { + RCU::Construct(); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + RCU::Destruct(); + } + }; + + TYPED_TEST_CASE_P( FeldmanHashSet ); + + TYPED_TEST_P( FeldmanHashSet, defaulted ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::int_item int_item; + typedef typename TestFixture::get_hash get_hash; + + typedef cc::FeldmanHashSet< rcu_type, int_item, + typename cc::feldman_hashset::make_traits< + cc::feldman_hashset::hash_accessor< get_hash > + >::type + > set_type; + + set_type s; + this->test( s ); + } + + TYPED_TEST_P( FeldmanHashSet, compare ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::int_item int_item; + typedef typename TestFixture::get_hash get_hash; + + typedef cc::FeldmanHashSet< rcu_type, int_item, + typename cc::feldman_hashset::make_traits< + cc::feldman_hashset::hash_accessor< get_hash > + , cds::opt::compare< typename TestFixture::cmp > + >::type + > set_type; + + set_type s( 4, 5 ); + this->test( s ); + } + + TYPED_TEST_P( FeldmanHashSet, less ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::int_item int_item; + typedef typename TestFixture::get_hash get_hash; + + typedef cc::FeldmanHashSet< rcu_type, int_item, + typename cc::feldman_hashset::make_traits< + cc::feldman_hashset::hash_accessor< get_hash > + , cds::opt::less< std::less > + >::type + > set_type; + + set_type s( 3, 2 ); + this->test( s ); + } + + TYPED_TEST_P( FeldmanHashSet, cmpmix ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::int_item int_item; + typedef typename TestFixture::get_hash get_hash; + + typedef cc::FeldmanHashSet< rcu_type, int_item, + typename cc::feldman_hashset::make_traits< + cc::feldman_hashset::hash_accessor< get_hash > + , cds::opt::less< std::less > + , cds::opt::compare< typename TestFixture::cmp > + >::type + > set_type; + + set_type s( 4, 4 ); + this->test( s ); + } + + TYPED_TEST_P( FeldmanHashSet, item_counting ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::int_item int_item; + typedef typename TestFixture::get_hash get_hash; + + struct set_traits: public cc::feldman_hashset::traits + { + typedef get_hash hash_accessor; + typedef typename TestFixture::cmp compare; + typedef std::less less; + typedef typename TestFixture::simple_item_counter item_counter; + }; + typedef cc::FeldmanHashSet< rcu_type, int_item, set_traits > set_type; + + set_type s( 3, 3 ); + this->test( s ); + } + + TYPED_TEST_P( FeldmanHashSet, backoff ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::int_item int_item; + typedef typename TestFixture::get_hash get_hash; + + struct set_traits: public cc::feldman_hashset::traits + { + typedef get_hash hash_accessor; + typedef typename TestFixture::cmp compare; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + }; + typedef cc::FeldmanHashSet< rcu_type, int_item, set_traits > set_type; + + set_type s( 8, 2 ); + this->test( s ); + } + + TYPED_TEST_P( FeldmanHashSet, stat ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::int_item int_item; + typedef typename TestFixture::get_hash get_hash; + + struct set_traits: public cc::feldman_hashset::traits + { + typedef get_hash hash_accessor; + typedef cds::backoff::yield back_off; + typedef cc::feldman_hashset::stat<> stat; + }; + typedef cc::FeldmanHashSet< rcu_type, int_item, set_traits > set_type; + + set_type s( 1, 1 ); + this->test( s ); + } + + // GCC 5: All test names should be written on single line, otherwise a runtime error will be encountered like as + // "No test named can be found in this test case" + REGISTER_TYPED_TEST_CASE_P( FeldmanHashSet, + defaulted, compare, less, cmpmix, item_counting, backoff, stat + ); +} // namespace + +#endif // CDSUNIT_SET_TEST_FELDMAN_HASHSET_RCU_H -- 2.34.1