From: khizmax Date: Thu, 17 Mar 2016 18:28:16 +0000 (+0300) Subject: Split unit set project to intrusive and non-intrusive ones X-Git-Tag: v2.2.0~341 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c7d36d7c48741bbaff1d661fb52e26e8a5b6f69e;p=libcds.git Split unit set project to intrusive and non-intrusive ones --- diff --git a/.gitignore b/.gitignore index 06a16f57..eb8ee396 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ /.project /projects/Win/vc14/*.opendb /test/stress/data/dictionary.txt +/projects/Win/vc14/cds.VC.db diff --git a/projects/Win/vc14/cds.sln b/projects/Win/vc14/cds.sln index e201294d..4ccf4b30 100644 --- a/projects/Win/vc14/cds.sln +++ b/projects/Win/vc14/cds.sln @@ -211,6 +211,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest-set", "gtest-set.vcxp EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest-intrusive-set", "gtest-intrusive-set.vcxproj", "{EC1EF263-7E34-4867-9ED9-77AA7963CD4A}" + ProjectSection(ProjectDependencies) = postProject + {408FE9BC-44F0-4E6A-89FA-D6F952584239} = {408FE9BC-44F0-4E6A-89FA-D6F952584239} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/projects/Win/vc14/gtest-set.vcxproj b/projects/Win/vc14/gtest-set.vcxproj index c7bdd9a9..b4a380e8 100644 --- a/projects/Win/vc14/gtest-set.vcxproj +++ b/projects/Win/vc14/gtest-set.vcxproj @@ -28,10 +28,10 @@ - - - - + + + + 4503 4503 4503 @@ -39,8 +39,8 @@ 4503 4503 - - + + 4503 4503 4503 @@ -48,14 +48,14 @@ 4503 4503 - - + + - - - - + + + + {A589D3F1-A749-4268-ADEC-D0CE13D1E359} diff --git a/projects/Win/vc14/gtest-set.vcxproj.filters b/projects/Win/vc14/gtest-set.vcxproj.filters index 258217f1..df7f8752 100644 --- a/projects/Win/vc14/gtest-set.vcxproj.filters +++ b/projects/Win/vc14/gtest-set.vcxproj.filters @@ -21,42 +21,42 @@ Source Files - + Source Files\MichaelSet - + Source Files\MichaelSet - + Source Files\MichaelSet - + Source Files\MichaelSet - + Source Files\MichaelSet - + Source Files\MichaelSet - + Source Files\MichaelSet - + Source Files\MichaelSet - + Header Files - + Header Files - + Header Files - + Header Files diff --git a/test/unit/intrusive-set/CMakeLists.txt b/test/unit/intrusive-set/CMakeLists.txt index c01513ef..a05cce67 100644 --- a/test/unit/intrusive-set/CMakeLists.txt +++ b/test/unit/intrusive-set/CMakeLists.txt @@ -51,14 +51,6 @@ set(CDSGTEST_SET_SOURCES intrusive_split_michael_rcu_gpt.cpp intrusive_split_michael_rcu_shb.cpp intrusive_split_michael_rcu_sht.cpp - michael_michael_hp.cpp - michael_michael_dhp.cpp - michael_michael_nogc.cpp - michael_michael_rcu_gpb.cpp - michael_michael_rcu_gpi.cpp - michael_michael_rcu_gpt.cpp - michael_michael_rcu_shb.cpp - michael_michael_rcu_sht.cpp ) include_directories( diff --git a/test/unit/intrusive-set/michael_michael_dhp.cpp b/test/unit/intrusive-set/michael_michael_dhp.cpp deleted file mode 100644 index fa386635..00000000 --- a/test/unit/intrusive-set/michael_michael_dhp.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - 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_set_hp.h" - -#include -#include - -namespace { - namespace cc = cds::container; - typedef cds::gc::DHP gc_type; - - class MichaelSet_DHP : public cds_test::container_set_hp - { - protected: - typedef cds_test::container_set_hp base_class; - - void SetUp() - { - typedef cc::MichaelList< gc_type, int_item > list_type; - typedef cc::MichaelHashSet< gc_type, list_type > set_type; - - // +1 - for guarded_ptr - 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( MichaelSet_DHP, compare ) - { - typedef cc::MichaelList< gc_type, int_item, - typename cc::michael_list::make_traits< - cds::opt::compare< cmp > - >::type - > list_type; - - typedef cc::MichaelHashSet< gc_type, list_type, - typename cc::michael_set::make_traits< - cds::opt::hash< hash_int > - >::type - > set_type; - - set_type s( kSize, 2 ); - test( s ); - } - - TEST_F( MichaelSet_DHP, less ) - { - typedef cc::MichaelList< gc_type, int_item, - typename cc::michael_list::make_traits< - cds::opt::less< base_class::less > - >::type - > list_type; - - typedef cc::MichaelHashSet< gc_type, list_type, - typename cc::michael_set::make_traits< - cds::opt::hash< hash_int > - >::type - > set_type; - - set_type s( kSize, 2 ); - test( s ); - } - - TEST_F( MichaelSet_DHP, cmpmix ) - { - struct list_traits : public cc::michael_list::traits - { - typedef base_class::less less; - typedef cmp compare; - }; - typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; - - typedef cc::MichaelHashSet< gc_type, list_type, - typename cc::michael_set::make_traits< - cds::opt::hash< hash_int > - >::type - > set_type; - - set_type s( kSize, 2 ); - test( s ); - } - - TEST_F( MichaelSet_DHP, item_counting ) - { - struct list_traits : public cc::michael_list::traits - { - typedef cmp compare; - }; - typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; - - struct set_traits: public cc::michael_set::traits - { - typedef hash_int hash; - typedef simple_item_counter item_counter; - }; - typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; - - set_type s( kSize, 3 ); - test( s ); - } - - TEST_F( MichaelSet_DHP, backoff ) - { - struct list_traits : public cc::michael_list::traits - { - typedef cmp compare; - typedef cds::backoff::exponential back_off; - }; - typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; - - struct set_traits : public cc::michael_set::traits - { - typedef hash_int hash; - typedef cds::atomicity::item_counter item_counter; - }; - typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; - - set_type s( kSize, 4 ); - test( s ); - } - - TEST_F( MichaelSet_DHP, seq_cst ) - { - struct list_traits : public cc::michael_list::traits - { - typedef base_class::less less; - typedef cds::backoff::pause back_off; - typedef cds::opt::v::sequential_consistent memory_model; - }; - typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; - - struct set_traits : public cc::michael_set::traits - { - typedef hash_int hash; - typedef cds::atomicity::item_counter item_counter; - }; - typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; - - set_type s( kSize, 4 ); - test( s ); - } - -} // namespace diff --git a/test/unit/intrusive-set/michael_michael_hp.cpp b/test/unit/intrusive-set/michael_michael_hp.cpp deleted file mode 100644 index 3483b8f9..00000000 --- a/test/unit/intrusive-set/michael_michael_hp.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - 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_set_hp.h" - -#include -#include - -namespace { - namespace cc = cds::container; - typedef cds::gc::HP gc_type; - - class MichaelSet_HP : public cds_test::container_set_hp - { - protected: - typedef cds_test::container_set_hp base_class; - - void SetUp() - { - typedef cc::MichaelList< gc_type, int_item > list_type; - typedef cc::MichaelHashSet< gc_type, list_type > 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( MichaelSet_HP, compare ) - { - typedef cc::MichaelList< gc_type, int_item, - typename cc::michael_list::make_traits< - cds::opt::compare< cmp > - >::type - > list_type; - - typedef cc::MichaelHashSet< gc_type, list_type, - typename cc::michael_set::make_traits< - cds::opt::hash< hash_int > - >::type - > set_type; - - set_type s( kSize, 2 ); - test( s ); - } - - TEST_F( MichaelSet_HP, less ) - { - typedef cc::MichaelList< gc_type, int_item, - typename cc::michael_list::make_traits< - cds::opt::less< base_class::less > - >::type - > list_type; - - typedef cc::MichaelHashSet< gc_type, list_type, - typename cc::michael_set::make_traits< - cds::opt::hash< hash_int > - >::type - > set_type; - - set_type s( kSize, 2 ); - test( s ); - } - - TEST_F( MichaelSet_HP, cmpmix ) - { - struct list_traits : public cc::michael_list::traits - { - typedef base_class::less less; - typedef cmp compare; - }; - typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; - - typedef cc::MichaelHashSet< gc_type, list_type, - typename cc::michael_set::make_traits< - cds::opt::hash< hash_int > - >::type - > set_type; - - set_type s( kSize, 2 ); - test( s ); - } - - TEST_F( MichaelSet_HP, item_counting ) - { - struct list_traits : public cc::michael_list::traits - { - typedef cmp compare; - }; - typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; - - struct set_traits: public cc::michael_set::traits - { - typedef hash_int hash; - typedef simple_item_counter item_counter; - }; - typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; - - set_type s( kSize, 3 ); - test( s ); - } - - TEST_F( MichaelSet_HP, backoff ) - { - struct list_traits : public cc::michael_list::traits - { - typedef cmp compare; - typedef cds::backoff::exponential back_off; - }; - typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; - - struct set_traits : public cc::michael_set::traits - { - typedef hash_int hash; - typedef cds::atomicity::item_counter item_counter; - }; - typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; - - set_type s( kSize, 4 ); - test( s ); - } - - TEST_F( MichaelSet_HP, seq_cst ) - { - struct list_traits : public cc::michael_list::traits - { - typedef base_class::less less; - typedef cds::backoff::pause back_off; - typedef cds::opt::v::sequential_consistent memory_model; - }; - typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; - - struct set_traits : public cc::michael_set::traits - { - typedef hash_int hash; - typedef cds::atomicity::item_counter item_counter; - }; - typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; - - set_type s( kSize, 4 ); - test( s ); - } - -} // namespace diff --git a/test/unit/intrusive-set/michael_michael_nogc.cpp b/test/unit/intrusive-set/michael_michael_nogc.cpp deleted file mode 100644 index 0f493ff0..00000000 --- a/test/unit/intrusive-set/michael_michael_nogc.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - 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_set_nogc.h" - -#include -#include - -namespace { - namespace cc = cds::container; - typedef cds::gc::nogc gc_type; - - class MichaelSet_NoGC : public cds_test::container_set_nogc - { - protected: - typedef cds_test::container_set_nogc base_class; - - //void SetUp() - //{} - - //void TearDown() - //{} - }; - - TEST_F( MichaelSet_NoGC, compare ) - { - typedef cc::MichaelList< gc_type, int_item, - typename cc::michael_list::make_traits< - cds::opt::compare< cmp > - >::type - > list_type; - - typedef cc::MichaelHashSet< gc_type, list_type, - typename cc::michael_set::make_traits< - cds::opt::hash< hash_int > - >::type - > set_type; - - set_type s( kSize, 2 ); - test( s ); - } - - TEST_F( MichaelSet_NoGC, less ) - { - typedef cc::MichaelList< gc_type, int_item, - typename cc::michael_list::make_traits< - cds::opt::less< base_class::less > - >::type - > list_type; - - typedef cc::MichaelHashSet< gc_type, list_type, - typename cc::michael_set::make_traits< - cds::opt::hash< hash_int > - >::type - > set_type; - - set_type s( kSize, 2 ); - test( s ); - } - - TEST_F( MichaelSet_NoGC, cmpmix ) - { - struct list_traits : public cc::michael_list::traits - { - typedef base_class::less less; - typedef cmp compare; - }; - typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; - - typedef cc::MichaelHashSet< gc_type, list_type, - typename cc::michael_set::make_traits< - cds::opt::hash< hash_int > - >::type - > set_type; - - set_type s( kSize, 2 ); - test( s ); - } - - TEST_F( MichaelSet_NoGC, item_counting ) - { - struct list_traits : public cc::michael_list::traits - { - typedef cmp compare; - }; - typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; - - struct set_traits: public cc::michael_set::traits - { - typedef hash_int hash; - typedef simple_item_counter item_counter; - }; - typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; - - set_type s( kSize, 3 ); - test( s ); - } - - TEST_F( MichaelSet_NoGC, backoff ) - { - struct list_traits : public cc::michael_list::traits - { - typedef cmp compare; - typedef cds::backoff::exponential back_off; - }; - typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; - - struct set_traits : public cc::michael_set::traits - { - typedef hash_int hash; - typedef cds::atomicity::item_counter item_counter; - }; - typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; - - set_type s( kSize, 4 ); - test( s ); - } - - TEST_F( MichaelSet_NoGC, seq_cst ) - { - struct list_traits : public cc::michael_list::traits - { - typedef base_class::less less; - typedef cds::backoff::pause back_off; - typedef cds::opt::v::sequential_consistent memory_model; - }; - typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; - - struct set_traits : public cc::michael_set::traits - { - typedef hash_int hash; - typedef cds::atomicity::item_counter item_counter; - }; - typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; - - set_type s( kSize, 4 ); - test( s ); - } - -} // namespace diff --git a/test/unit/intrusive-set/michael_michael_rcu_gpb.cpp b/test/unit/intrusive-set/michael_michael_rcu_gpb.cpp deleted file mode 100644 index 9b2a1881..00000000 --- a/test/unit/intrusive-set/michael_michael_rcu_gpb.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - 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_michael_michael_rcu.h" - -namespace { - - typedef cds::urcu::general_buffered<> rcu_implementation; - -} // namespace - -INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPB, MichaelSet, rcu_implementation ); diff --git a/test/unit/intrusive-set/michael_michael_rcu_gpi.cpp b/test/unit/intrusive-set/michael_michael_rcu_gpi.cpp deleted file mode 100644 index a907d591..00000000 --- a/test/unit/intrusive-set/michael_michael_rcu_gpi.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - 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_michael_michael_rcu.h" - -namespace { - - typedef cds::urcu::general_instant<> rcu_implementation; - -} // namespace - -INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPI, MichaelSet, rcu_implementation ); diff --git a/test/unit/intrusive-set/michael_michael_rcu_gpt.cpp b/test/unit/intrusive-set/michael_michael_rcu_gpt.cpp deleted file mode 100644 index f2a61a68..00000000 --- a/test/unit/intrusive-set/michael_michael_rcu_gpt.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - 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_michael_michael_rcu.h" - -namespace { - - typedef cds::urcu::general_threaded<> rcu_implementation; - -} // namespace - -INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPT, MichaelSet, rcu_implementation ); diff --git a/test/unit/intrusive-set/michael_michael_rcu_shb.cpp b/test/unit/intrusive-set/michael_michael_rcu_shb.cpp deleted file mode 100644 index be796351..00000000 --- a/test/unit/intrusive-set/michael_michael_rcu_shb.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - 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_michael_michael_rcu.h" - -namespace { - - typedef cds::urcu::signal_buffered<> rcu_implementation; - -} // namespace - -INSTANTIATE_TYPED_TEST_CASE_P( RCU_SHB, MichaelSet, rcu_implementation ); - -#endif // CDS_URCU_SIGNAL_HANDLING_ENABLED diff --git a/test/unit/intrusive-set/michael_michael_rcu_sht.cpp b/test/unit/intrusive-set/michael_michael_rcu_sht.cpp deleted file mode 100644 index 58cf7f69..00000000 --- a/test/unit/intrusive-set/michael_michael_rcu_sht.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - 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_michael_michael_rcu.h" - -namespace { - - typedef cds::urcu::signal_threaded<> rcu_implementation; - -} // namespace - -INSTANTIATE_TYPED_TEST_CASE_P( RCU_SHT, MichaelSet, rcu_implementation ); - -#endif // CDS_URCU_SIGNAL_HANDLING_ENABLED diff --git a/test/unit/intrusive-set/test_michael_michael_rcu.h b/test/unit/intrusive-set/test_michael_michael_rcu.h deleted file mode 100644 index 99f75ee6..00000000 --- a/test/unit/intrusive-set/test_michael_michael_rcu.h +++ /dev/null @@ -1,204 +0,0 @@ -/* - 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_MICHAEL_MICHAEL_RCU_H -#define CDSUNIT_SET_TEST_MICHAEL_MICHAEL_RCU_H - -#include "test_set_rcu.h" -#include -#include - -namespace cc = cds::container; - -template -class MichaelSet: public cds_test::container_set_rcu -{ - typedef cds_test::container_set_rcu base_class; -public: - typedef cds::urcu::gc rcu_type; - -protected: - void SetUp() - { - RCU::Construct(); - cds::threading::Manager::attachThread(); - } - - void TearDown() - { - cds::threading::Manager::detachThread(); - RCU::Destruct(); - } -}; - -TYPED_TEST_CASE_P( MichaelSet ); - -TYPED_TEST_P( MichaelSet, compare ) -{ - typedef typename TestFixture::rcu_type rcu_type; - typedef typename TestFixture::int_item int_item; - - typedef cc::MichaelList< rcu_type, int_item, - typename cc::michael_list::make_traits< - cds::opt::compare< typename TestFixture::cmp > - >::type - > list_type; - - typedef cc::MichaelHashSet< rcu_type, list_type, - typename cc::michael_set::make_traits< - cds::opt::hash< typename TestFixture::hash_int > - >::type - > set_type; - - set_type s( TestFixture::kSize, 2 ); - this->test( s ); -} - -TYPED_TEST_P( MichaelSet, less ) -{ - typedef typename TestFixture::rcu_type rcu_type; - typedef typename TestFixture::int_item int_item; - - typedef cc::MichaelList< rcu_type, int_item, - typename cc::michael_list::make_traits< - cds::opt::less< typename TestFixture::less > - >::type - > list_type; - - typedef cc::MichaelHashSet< rcu_type, list_type, - typename cc::michael_set::make_traits< - cds::opt::hash< typename TestFixture::hash_int > - >::type - > set_type; - - set_type s( TestFixture::kSize, 2 ); - this->test( s ); -} - -TYPED_TEST_P( MichaelSet, cmpmix ) -{ - typedef typename TestFixture::rcu_type rcu_type; - typedef typename TestFixture::int_item int_item; - - struct list_traits : public cc::michael_list::traits - { - typedef typename TestFixture::less less; - typedef typename TestFixture::cmp compare; - }; - typedef cc::MichaelList< rcu_type, int_item, list_traits > list_type; - - typedef cc::MichaelHashSet< rcu_type, list_type, - typename cc::michael_set::make_traits< - cds::opt::hash< typename TestFixture::hash_int > - >::type - > set_type; - - set_type s( TestFixture::kSize, 2 ); - this->test( s ); -} - -TYPED_TEST_P( MichaelSet, item_counting ) -{ - typedef typename TestFixture::rcu_type rcu_type; - typedef typename TestFixture::int_item int_item; - - struct list_traits : public cc::michael_list::traits - { - typedef typename TestFixture::cmp compare; - }; - typedef cc::MichaelList< rcu_type, int_item, list_traits > list_type; - - struct set_traits: public cc::michael_set::traits - { - typedef typename TestFixture::hash_int hash; - typedef typename TestFixture::simple_item_counter item_counter; - }; - typedef cc::MichaelHashSet< rcu_type, list_type, set_traits >set_type; - - set_type s( TestFixture::kSize, 3 ); - this->test( s ); -} - -TYPED_TEST_P( MichaelSet, backoff ) -{ - typedef typename TestFixture::rcu_type rcu_type; - typedef typename TestFixture::int_item int_item; - - struct list_traits : public cc::michael_list::traits - { - typedef typename TestFixture::cmp compare; - typedef cds::backoff::exponential back_off; - }; - typedef cc::MichaelList< rcu_type, int_item, list_traits > list_type; - - struct set_traits : public cc::michael_set::traits - { - typedef typename TestFixture::hash_int hash; - typedef cds::atomicity::item_counter item_counter; - }; - typedef cc::MichaelHashSet< rcu_type, list_type, set_traits >set_type; - - set_type s( TestFixture::kSize, 4 ); - this->test( s ); -} - -TYPED_TEST_P( MichaelSet, seq_cst ) -{ - typedef typename TestFixture::rcu_type rcu_type; - typedef typename TestFixture::int_item int_item; - - struct list_traits : public cc::michael_list::traits - { - typedef typename TestFixture::less less; - typedef cds::backoff::pause back_off; - typedef cds::opt::v::sequential_consistent memory_model; - }; - typedef cc::MichaelList< rcu_type, int_item, list_traits > list_type; - - struct set_traits : public cc::michael_set::traits - { - typedef typename TestFixture::hash_int hash; - typedef cds::atomicity::item_counter item_counter; - }; - typedef cc::MichaelHashSet< rcu_type, list_type, set_traits >set_type; - - set_type s( TestFixture::kSize, 4 ); - 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( MichaelSet, - compare, less, cmpmix, item_counting, backoff, seq_cst -); - - -#endif // CDSUNIT_SET_TEST_INTRUSIVE_MICHAEL_MICHAEL_RCU_H - \ No newline at end of file diff --git a/test/unit/intrusive-set/test_set.h b/test/unit/intrusive-set/test_set.h deleted file mode 100644 index 1f6e142a..00000000 --- a/test/unit/intrusive-set/test_set.h +++ /dev/null @@ -1,507 +0,0 @@ -/* - 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_SET_H -#define CDSUNIT_SET_TEST_SET_H - -#include -#include - -#include -#include // ref - -// forward declaration -namespace cds { namespace container {}} - -namespace cds_test { - namespace co = cds::opt; - - class container_set : public fixture - { - public: - static size_t const kSize = 100; - - struct stat - { - unsigned int nFindCount; - unsigned int nUpdateNewCount; - unsigned int nUpdateCount; - mutable unsigned int nEraseCount; - - 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 hash_int { - size_t operator()( int i ) const - { - return co::v::hash()(i); - } - template - size_t operator()( const Item& i ) const - { - return (*this)(i.key()); - } - }; - - 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 less - { - bool operator ()( int_item const& v1, int_item const& v2 ) const - { - return v1.key() < v2.key(); - } - - template - bool operator ()( int_item const& v1, const Q& v2 ) const - { - return v1.key() < v2; - } - - template - bool operator ()( const Q& v1, int_item const& v2 ) const - { - return v1 < v2.key(); - } - }; - - struct cmp { - int operator ()( int_item const& v1, int_item const& v2 ) const - { - if ( v1.key() < v2.key() ) - return -1; - return v1.key() > v2.key() ? 1 : 0; - } - - template - int operator ()( T const& v1, int v2 ) const - { - if ( v1.key() < v2 ) - return -1; - return v1.key() > v2 ? 1 : 0; - } - - template - int operator ()( int v1, T const& v2 ) const - { - if ( v1 < v2.key() ) - return -1; - return v1 > v2.key() ? 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.contains( i ) ); - ASSERT_FALSE( s.contains( other_item( i.key() ), other_less())); - ASSERT_FALSE( s.find( i.nKey, []( value_type&, int ) {} )); - ASSERT_FALSE( s.find( i, []( value_type&, value_type const& ) {} )); - ASSERT_FALSE( s.find_with( other_item( i.key()), other_less(), []( value_type&, other_item const& ) {} )); - - std::pair updResult; - - std::string str; - updResult = s.update( i.key(), []( bool bNew, value_type&, int ) - { - 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, []( bool bNew, value_type& val, value_type const& arg) - { - EXPECT_FALSE( bNew ); - EXPECT_EQ( val.key(), arg.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(), []( bool bNew, value_type& val, int arg) - { - EXPECT_FALSE( bNew ); - EXPECT_EQ( val.key(), arg ); - }, 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, int key ) - { - EXPECT_EQ( v.key(), key ); - 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, int key ) - { - EXPECT_EQ( v.key(), key ); - EXPECT_EQ( v.nFindCount, 1 ); - })); - break; - case 4: - updResult = s.update( i, []( bool bNew, value_type& v, value_type const& arg ) - { - EXPECT_TRUE( bNew ); - EXPECT_EQ( v.key(), arg.key() ); - ++v.nUpdateNewCount; - }); - EXPECT_TRUE( updResult.first ); - EXPECT_TRUE( updResult.second ); - - updResult = s.update( i, []( bool bNew, value_type& v, value_type const& arg ) - { - EXPECT_FALSE( bNew ); - EXPECT_EQ( v.key(), arg.key() ); - ++v.nUpdateNewCount; - }, false ); - EXPECT_TRUE( updResult.first ); - EXPECT_FALSE( updResult.second ); - - ASSERT_TRUE( s.find( i.nKey, []( value_type const& v, int key ) - { - EXPECT_EQ( v.key(), key ); - EXPECT_EQ( v.nUpdateNewCount, 2 ); - })); - break; - case 5: - updResult = s.update( i.key(), []( bool bNew, value_type& v, int arg ) - { - EXPECT_TRUE( bNew ); - EXPECT_EQ( v.key(), arg ); - ++v.nUpdateNewCount; - }); - EXPECT_TRUE( updResult.first ); - EXPECT_TRUE( updResult.second ); - - updResult = s.update( i.key(), []( bool bNew, value_type& v, int arg ) - { - EXPECT_FALSE( bNew ); - EXPECT_EQ( v.key(), arg ); - ++v.nUpdateNewCount; - }, false ); - EXPECT_TRUE( updResult.first ); - EXPECT_FALSE( updResult.second ); - - ASSERT_TRUE( s.find( i, []( value_type const& v, value_type const& arg ) - { - EXPECT_EQ( v.key(), arg.key() ); - EXPECT_EQ( v.nUpdateNewCount, 2 ); - })); - break; - case 6: - ASSERT_TRUE( s.emplace( i.key())); - ASSERT_TRUE( s.find( i, []( value_type const& v, value_type const& arg ) - { - EXPECT_EQ( v.key(), arg.key() ); - EXPECT_EQ( v.nVal, arg.nVal ); - })); - break; - case 7: - str = "Hello!"; - ASSERT_TRUE( s.emplace( i.key(), std::move( str ))); - EXPECT_TRUE( str.empty()); - ASSERT_TRUE( s.find( i, []( value_type const& v, value_type const& arg ) - { - EXPECT_EQ( v.key(), arg.key() ); - EXPECT_EQ( v.nVal, arg.nVal ); - EXPECT_EQ( v.strVal, std::string( "Hello!" )); - } ) ); - break; - default: - // forgot anything?.. - ASSERT_TRUE( false ); - } - - ASSERT_TRUE( s.contains( i.nKey ) ); - ASSERT_TRUE( s.contains( i ) ); - ASSERT_TRUE( s.contains( other_item( i.key() ), other_less() ) ); - ASSERT_TRUE( s.find( i.nKey, []( value_type&, int ) {} ) ); - ASSERT_TRUE( s.find( i, []( value_type&, value_type const& ) {} ) ); - ASSERT_TRUE( s.find_with( other_item( i.key() ), other_less(), []( value_type&, other_item const& ) {} ) ); - } - - 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.contains( i ) ); - ASSERT_TRUE( s.contains( other_item( i.key() ), other_less() ) ); - ASSERT_TRUE( s.find( i.nKey, []( value_type& v, int ) - { - v.nFindCount = 1; - })); - ASSERT_TRUE( s.find( i, []( value_type& v, value_type const& ) - { - EXPECT_EQ( ++v.nFindCount, 2 ); - })); - ASSERT_TRUE( s.find_with( other_item( i.key() ), other_less(), []( value_type& v, other_item const& ) - { - EXPECT_EQ( ++v.nFindCount, 3 ); - })); - - int nKey = i.key() - 1; - switch ( idx % 6 ) { - case 0: - ASSERT_TRUE( s.erase( i.key())); - ASSERT_FALSE( s.erase( i.key())); - break; - case 1: - ASSERT_TRUE( s.erase( i )); - ASSERT_FALSE( s.erase( i )); - break; - case 2: - ASSERT_TRUE( s.erase_with( other_item( i.key()), other_less())); - ASSERT_FALSE( s.erase_with( other_item( i.key() ), other_less() ) ); - break; - case 3: - ASSERT_TRUE( s.erase( i.key(), [&nKey]( value_type const& v ) - { - 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; - case 4: - ASSERT_TRUE( s.erase( i, [&nKey]( value_type const& v ) - { - nKey = v.key(); - } )); - EXPECT_EQ( i.key(), nKey ); - - nKey = i.key() - 1; - ASSERT_FALSE( s.erase( i, [&nKey]( value_type const& v ) - { - nKey = v.key(); - } )); - EXPECT_EQ( i.key(), nKey + 1 ); - break; - case 5: - ASSERT_TRUE( s.erase_with( other_item( i.key()), other_less(), [&nKey]( value_type const& v ) - { - nKey = v.key(); - } )); - EXPECT_EQ( i.key(), nKey ); - - nKey = i.key() - 1; - ASSERT_FALSE( s.erase_with( other_item( i.key()), other_less(), [&nKey]( value_type const& v ) - { - nKey = v.key(); - } )); - EXPECT_EQ( i.key(), nKey + 1 ); - break; - } - - ASSERT_FALSE( s.contains( i.nKey ) ); - ASSERT_FALSE( s.contains( i ) ); - ASSERT_FALSE( s.contains( other_item( i.key() ), other_less())); - ASSERT_FALSE( s.find( i.nKey, []( value_type&, int ) {} )); - ASSERT_FALSE( s.find( i, []( value_type&, value_type const& ) {} )); - ASSERT_FALSE( s.find_with( other_item( i.key()), other_less(), []( value_type&, other_item const& ) {} )); - } - ASSERT_TRUE( s.empty() ); - ASSERT_CONTAINER_SIZE( s, 0 ); - - - // clear - for ( auto& i : data ) { - ASSERT_TRUE( s.insert( i ) ); - } - - 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() ); - } - }; - -} // namespace cds_test - -#endif // CDSUNIT_SET_TEST_SET_H diff --git a/test/unit/intrusive-set/test_set_hp.h b/test/unit/intrusive-set/test_set_hp.h deleted file mode 100644 index dd5b3513..00000000 --- a/test/unit/intrusive-set/test_set_hp.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - 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_SET_HP_H -#define CDSUNIT_SET_TEST_SET_HP_H - -#include "test_set.h" - -namespace cds_test { - - class container_set_hp: public container_set - { - typedef container_set 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; - } - - for ( auto it = s.cbegin(); it != s.cend(); ++it ) { - EXPECT_EQ( it->nFindCount, it->key() * 3 ); - } - - typedef typename Set::guarded_ptr guarded_ptr; - guarded_ptr gp; - - // get() - for ( auto idx : indices ) { - auto& i = data[idx]; - - ASSERT_TRUE( !gp ); - switch ( idx % 3 ) { - case 0: - gp = s.get( i.key() ); - ASSERT_FALSE( !gp ); - break; - case 1: - gp = s.get( i ); - ASSERT_FALSE( !gp ); - break; - case 2: - gp = s.get_with( other_item( i.key() ), other_less() ); - ASSERT_FALSE( !gp ); - } - EXPECT_EQ( gp->key(), i.key() ); - EXPECT_EQ( gp->nFindCount, i.key() * 3 ); - gp->nFindCount *= 2; - - gp.release(); - } - - // extract() - for ( auto idx : indices ) { - auto& i = data[idx]; - - ASSERT_TRUE( !gp ); - switch ( idx % 3 ) { - case 0: - gp = s.extract( i.key() ); - ASSERT_FALSE( !gp ); - break; - case 1: - gp = s.extract( i ); - ASSERT_FALSE( !gp ); - break; - case 2: - gp = s.extract_with( other_item( i.key() ), other_less() ); - ASSERT_FALSE( !gp ); - break; - } - EXPECT_EQ( gp->key(), i.key() ); - EXPECT_EQ( gp->nFindCount, i.key() * 6 ); - - switch ( idx % 3 ) { - case 0: - gp = s.extract( i.key() ); - break; - case 1: - gp = s.extract( i ); - break; - case 2: - gp = s.extract_with( other_item( i.key() ), other_less() ); - break; - } - ASSERT_TRUE( !gp ); - } - - ASSERT_TRUE( s.empty() ); - ASSERT_CONTAINER_SIZE( s, 0 ); - } - - }; -} // namespace cds_test - -#endif // CDSUNIT_SET_TEST_SET_HP_H diff --git a/test/unit/intrusive-set/test_set_nogc.h b/test/unit/intrusive-set/test_set_nogc.h deleted file mode 100644 index 8fbcbdfb..00000000 --- a/test/unit/intrusive-set/test_set_nogc.h +++ /dev/null @@ -1,349 +0,0 @@ -/* - 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_SET_NOGC_H -#define CDSUNIT_SET_TEST_SET_NOGC_H - -#include -#include - -#include - -// forward declaration -namespace cds { namespace container {}} - -namespace cds_test { - namespace co = cds::opt; - - class container_set_nogc : public fixture - { - public: - static size_t const kSize = 100; - - 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 hash_int { - size_t operator()( int i ) const - { - return co::v::hash()(i); - } - template - size_t operator()( const Item& i ) const - { - return (*this)(i.key()); - } - }; - - 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 less - { - bool operator ()( int_item const& v1, int_item const& v2 ) const - { - return v1.key() < v2.key(); - } - - template - bool operator ()( int_item const& v1, const Q& v2 ) const - { - return v1.key() < v2; - } - - template - bool operator ()( const Q& v1, int_item const& v2 ) const - { - return v1 < v2.key(); - } - }; - - struct cmp { - int operator ()( int_item const& v1, int_item const& v2 ) const - { - if ( v1.key() < v2.key() ) - return -1; - return v1.key() > v2.key() ? 1 : 0; - } - - template - int operator ()( T const& v1, int v2 ) const - { - if ( v1.key() < v2 ) - return -1; - return v1.key() > v2 ? 1 : 0; - } - - template - int operator ()( int v1, T const& v2 ) const - { - if ( v1 < v2.key() ) - return -1; - return v1 > v2.key() ? 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 ) != s.end() ); - ASSERT_FALSE( s.contains( i ) != s.end() ); - ASSERT_FALSE( s.contains( other_item( i.key() ), other_less()) != s.end()); - - std::pair updResult; - - std::string str; - updResult = s.update( i.key(), false ); - EXPECT_TRUE( updResult.first == s.end()); - EXPECT_FALSE( updResult.second ); - - typename Set::iterator it; - switch ( idx % 6 ) { - case 0: - it = s.insert( i ); - ASSERT_TRUE( it != s.end() ); - it->nFindCount = it->nKey; - ASSERT_TRUE( s.insert( i ) == s.end()); - updResult = s.update( i, false ); - EXPECT_TRUE( updResult.first == it ); - EXPECT_FALSE( updResult.second ); - break; - case 1: - it = s.insert( i.key() ); - ASSERT_TRUE( it != s.end()); - ASSERT_TRUE( s.insert( i.key() ) == s.end()); - it->nFindCount = it->nKey; - updResult = s.update( i.key(), false ); - EXPECT_TRUE( updResult.first == it ); - EXPECT_FALSE( updResult.second ); - break; - case 2: - updResult = s.update( i ); - EXPECT_TRUE( updResult.first != s.end()); - EXPECT_TRUE( updResult.second ); - updResult.first->nFindCount = updResult.first->nKey; - break; - case 3: - updResult = s.update( i.key()); - EXPECT_TRUE( updResult.first != s.end() ); - EXPECT_TRUE( updResult.second ); - updResult.first->nFindCount = updResult.first->nKey; - break; - case 4: - it = s.emplace( i.key()); - ASSERT_TRUE( it != s.end()); - it->nFindCount = it->nKey; - ASSERT_FALSE( s.emplace( i.key() ) != s.end()); - break; - case 5: - str = "Hello!"; - it = s.emplace( i.key(), std::move( str )); - ASSERT_TRUE( it != s.end() ); - EXPECT_TRUE( str.empty()); - it->nFindCount = it->nKey; - str = "Hello!"; - ASSERT_TRUE( s.emplace( i.key(), std::move( str )) == s.end()); - EXPECT_TRUE( str.empty() ); // yes, that's is :( - break; - default: - // forgot anything?.. - ASSERT_TRUE( false ); - } - - it = s.contains( i.nKey ); - ASSERT_TRUE( it != s.end() ); - EXPECT_EQ( it->nFindCount, it->nKey ); - ASSERT_TRUE( s.contains( i ) != s.end() ); - ASSERT_TRUE( s.contains( other_item( i.key() ), other_less() ) != s.end()); - } - - ASSERT_FALSE( s.empty() ); - ASSERT_CONTAINER_SIZE( s, nSetSize ); - - // iterators - 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 ); - } - - // clear - - s.clear(); - - ASSERT_TRUE( s.empty() ); - ASSERT_CONTAINER_SIZE( s, 0 ); - - ASSERT_TRUE( s.begin() == s.end() ); - ASSERT_TRUE( s.cbegin() == s.cend() ); - } - }; - -} // namespace cds_test - -#endif // CDSUNIT_SET_TEST_SET_NOGC_H diff --git a/test/unit/intrusive-set/test_set_rcu.h b/test/unit/intrusive-set/test_set_rcu.h deleted file mode 100644 index d819278a..00000000 --- a/test/unit/intrusive-set/test_set_rcu.h +++ /dev/null @@ -1,192 +0,0 @@ -/* - 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_SET_RCU_H -#define CDSUNIT_SET_TEST_SET_RCU_H - -#include "test_set.h" - -namespace cds_test { - - class container_set_rcu: public container_set - { - typedef container_set 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; - } - - for ( auto it = s.cbegin(); it != s.cend(); ++it ) { - EXPECT_EQ( it->nFindCount, it->key() * 3 ); - } - - typedef typename Set::exempt_ptr exempt_ptr; - typedef typename Set::raw_ptr raw_ptr; - typedef typename Set::rcu_lock rcu_lock; - - // get() - for ( auto idx : indices ) { - auto& i = data[idx]; - - { - rcu_lock l; - raw_ptr rp; - ASSERT_TRUE( !rp ); - switch ( idx % 3 ) { - case 0: - rp = s.get( i.key() ); - ASSERT_FALSE( !rp ); - break; - case 1: - rp = s.get( i ); - ASSERT_FALSE( !rp ); - break; - case 2: - rp = s.get_with( other_item( i.key() ), other_less() ); - ASSERT_FALSE( !rp ); - } - EXPECT_EQ( rp->key(), i.key() ); - EXPECT_EQ( rp->nFindCount, i.key() * 3 ); - rp->nFindCount *= 2; - } - } - - // extract() - exempt_ptr xp; - for ( auto idx : indices ) { - auto& i = data[idx]; - - ASSERT_TRUE( !xp ); - if ( Set::c_bExtractLockExternal ) { - rcu_lock l; - - switch ( idx % 3 ) { - case 0: - xp = s.extract( i.key() ); - ASSERT_FALSE( !xp ); - break; - case 1: - xp = s.extract( i ); - ASSERT_FALSE( !xp ); - break; - case 2: - xp = s.extract_with( other_item( i.key() ), other_less() ); - ASSERT_FALSE( !xp ); - break; - } - EXPECT_EQ( xp->key(), i.key() ); - EXPECT_EQ( xp->nFindCount, i.key() * 6 ); - - switch ( idx % 3 ) { - case 0: - xp = s.extract( i.key() ); - break; - case 1: - xp = s.extract( i ); - break; - case 2: - xp = s.extract_with( other_item( i.key() ), other_less() ); - break; - } - ASSERT_TRUE( !xp ); - } - else { - switch ( idx % 3 ) { - case 0: - xp = s.extract( i.key() ); - ASSERT_FALSE( !xp ); - break; - case 1: - xp = s.extract( i ); - ASSERT_FALSE( !xp ); - break; - case 2: - xp = s.extract_with( other_item( i.key() ), other_less() ); - ASSERT_FALSE( !xp ); - break; - } - EXPECT_EQ( xp->key(), i.key() ); - EXPECT_EQ( xp->nFindCount, i.key() * 6 ); - - switch ( idx % 3 ) { - case 0: - xp = s.extract( i.key() ); - break; - case 1: - xp = s.extract( i ); - break; - case 2: - xp = s.extract_with( other_item( i.key() ), other_less() ); - break; - } - ASSERT_TRUE( !xp ); - } - } - - ASSERT_TRUE( s.empty() ); - ASSERT_CONTAINER_SIZE( s, 0 ); - } - - }; -} // namespace cds_test - -#endif // CDSUNIT_SET_TEST_SET_RCU_H diff --git a/test/unit/set/CMakeLists.txt b/test/unit/set/CMakeLists.txt new file mode 100644 index 00000000..8691e718 --- /dev/null +++ b/test/unit/set/CMakeLists.txt @@ -0,0 +1,28 @@ +set(PACKAGE_NAME unit-set) + +set(CDSGTEST_SET_SOURCES + ../main.cpp + michael_michael_hp.cpp + michael_michael_dhp.cpp + michael_michael_nogc.cpp + michael_michael_rcu_gpb.cpp + michael_michael_rcu_gpi.cpp + michael_michael_rcu_gpt.cpp + michael_michael_rcu_shb.cpp + michael_michael_rcu_sht.cpp +) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_executable(${PACKAGE_NAME} ${CDSGTEST_SET_SOURCES}) +target_link_libraries(${PACKAGE_NAME} + ${CDS_SHARED_LIBRARY} + ${GTEST_LIBRARY} + ${Boost_THREAD_LIBRARY} + ${Boost_SYSTEM_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} +) + +add_test(NAME ${PACKAGE_NAME} COMMAND ${PACKAGE_NAME} WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) \ No newline at end of file diff --git a/test/unit/set/michael_michael_dhp.cpp b/test/unit/set/michael_michael_dhp.cpp new file mode 100644 index 00000000..fa386635 --- /dev/null +++ b/test/unit/set/michael_michael_dhp.cpp @@ -0,0 +1,177 @@ +/* + 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_set_hp.h" + +#include +#include + +namespace { + namespace cc = cds::container; + typedef cds::gc::DHP gc_type; + + class MichaelSet_DHP : public cds_test::container_set_hp + { + protected: + typedef cds_test::container_set_hp base_class; + + void SetUp() + { + typedef cc::MichaelList< gc_type, int_item > list_type; + typedef cc::MichaelHashSet< gc_type, list_type > set_type; + + // +1 - for guarded_ptr + 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( MichaelSet_DHP, compare ) + { + typedef cc::MichaelList< gc_type, int_item, + typename cc::michael_list::make_traits< + cds::opt::compare< cmp > + >::type + > list_type; + + typedef cc::MichaelHashSet< gc_type, list_type, + typename cc::michael_set::make_traits< + cds::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( MichaelSet_DHP, less ) + { + typedef cc::MichaelList< gc_type, int_item, + typename cc::michael_list::make_traits< + cds::opt::less< base_class::less > + >::type + > list_type; + + typedef cc::MichaelHashSet< gc_type, list_type, + typename cc::michael_set::make_traits< + cds::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( MichaelSet_DHP, cmpmix ) + { + struct list_traits : public cc::michael_list::traits + { + typedef base_class::less less; + typedef cmp compare; + }; + typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; + + typedef cc::MichaelHashSet< gc_type, list_type, + typename cc::michael_set::make_traits< + cds::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( MichaelSet_DHP, item_counting ) + { + struct list_traits : public cc::michael_list::traits + { + typedef cmp compare; + }; + typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; + + struct set_traits: public cc::michael_set::traits + { + typedef hash_int hash; + typedef simple_item_counter item_counter; + }; + typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; + + set_type s( kSize, 3 ); + test( s ); + } + + TEST_F( MichaelSet_DHP, backoff ) + { + struct list_traits : public cc::michael_list::traits + { + typedef cmp compare; + typedef cds::backoff::exponential back_off; + }; + typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; + + struct set_traits : public cc::michael_set::traits + { + typedef hash_int hash; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; + + set_type s( kSize, 4 ); + test( s ); + } + + TEST_F( MichaelSet_DHP, seq_cst ) + { + struct list_traits : public cc::michael_list::traits + { + typedef base_class::less less; + typedef cds::backoff::pause back_off; + typedef cds::opt::v::sequential_consistent memory_model; + }; + typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; + + struct set_traits : public cc::michael_set::traits + { + typedef hash_int hash; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; + + set_type s( kSize, 4 ); + test( s ); + } + +} // namespace diff --git a/test/unit/set/michael_michael_hp.cpp b/test/unit/set/michael_michael_hp.cpp new file mode 100644 index 00000000..3483b8f9 --- /dev/null +++ b/test/unit/set/michael_michael_hp.cpp @@ -0,0 +1,177 @@ +/* + 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_set_hp.h" + +#include +#include + +namespace { + namespace cc = cds::container; + typedef cds::gc::HP gc_type; + + class MichaelSet_HP : public cds_test::container_set_hp + { + protected: + typedef cds_test::container_set_hp base_class; + + void SetUp() + { + typedef cc::MichaelList< gc_type, int_item > list_type; + typedef cc::MichaelHashSet< gc_type, list_type > 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( MichaelSet_HP, compare ) + { + typedef cc::MichaelList< gc_type, int_item, + typename cc::michael_list::make_traits< + cds::opt::compare< cmp > + >::type + > list_type; + + typedef cc::MichaelHashSet< gc_type, list_type, + typename cc::michael_set::make_traits< + cds::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( MichaelSet_HP, less ) + { + typedef cc::MichaelList< gc_type, int_item, + typename cc::michael_list::make_traits< + cds::opt::less< base_class::less > + >::type + > list_type; + + typedef cc::MichaelHashSet< gc_type, list_type, + typename cc::michael_set::make_traits< + cds::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( MichaelSet_HP, cmpmix ) + { + struct list_traits : public cc::michael_list::traits + { + typedef base_class::less less; + typedef cmp compare; + }; + typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; + + typedef cc::MichaelHashSet< gc_type, list_type, + typename cc::michael_set::make_traits< + cds::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( MichaelSet_HP, item_counting ) + { + struct list_traits : public cc::michael_list::traits + { + typedef cmp compare; + }; + typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; + + struct set_traits: public cc::michael_set::traits + { + typedef hash_int hash; + typedef simple_item_counter item_counter; + }; + typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; + + set_type s( kSize, 3 ); + test( s ); + } + + TEST_F( MichaelSet_HP, backoff ) + { + struct list_traits : public cc::michael_list::traits + { + typedef cmp compare; + typedef cds::backoff::exponential back_off; + }; + typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; + + struct set_traits : public cc::michael_set::traits + { + typedef hash_int hash; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; + + set_type s( kSize, 4 ); + test( s ); + } + + TEST_F( MichaelSet_HP, seq_cst ) + { + struct list_traits : public cc::michael_list::traits + { + typedef base_class::less less; + typedef cds::backoff::pause back_off; + typedef cds::opt::v::sequential_consistent memory_model; + }; + typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; + + struct set_traits : public cc::michael_set::traits + { + typedef hash_int hash; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; + + set_type s( kSize, 4 ); + test( s ); + } + +} // namespace diff --git a/test/unit/set/michael_michael_nogc.cpp b/test/unit/set/michael_michael_nogc.cpp new file mode 100644 index 00000000..0f493ff0 --- /dev/null +++ b/test/unit/set/michael_michael_nogc.cpp @@ -0,0 +1,167 @@ +/* + 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_set_nogc.h" + +#include +#include + +namespace { + namespace cc = cds::container; + typedef cds::gc::nogc gc_type; + + class MichaelSet_NoGC : public cds_test::container_set_nogc + { + protected: + typedef cds_test::container_set_nogc base_class; + + //void SetUp() + //{} + + //void TearDown() + //{} + }; + + TEST_F( MichaelSet_NoGC, compare ) + { + typedef cc::MichaelList< gc_type, int_item, + typename cc::michael_list::make_traits< + cds::opt::compare< cmp > + >::type + > list_type; + + typedef cc::MichaelHashSet< gc_type, list_type, + typename cc::michael_set::make_traits< + cds::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( MichaelSet_NoGC, less ) + { + typedef cc::MichaelList< gc_type, int_item, + typename cc::michael_list::make_traits< + cds::opt::less< base_class::less > + >::type + > list_type; + + typedef cc::MichaelHashSet< gc_type, list_type, + typename cc::michael_set::make_traits< + cds::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( MichaelSet_NoGC, cmpmix ) + { + struct list_traits : public cc::michael_list::traits + { + typedef base_class::less less; + typedef cmp compare; + }; + typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; + + typedef cc::MichaelHashSet< gc_type, list_type, + typename cc::michael_set::make_traits< + cds::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( MichaelSet_NoGC, item_counting ) + { + struct list_traits : public cc::michael_list::traits + { + typedef cmp compare; + }; + typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; + + struct set_traits: public cc::michael_set::traits + { + typedef hash_int hash; + typedef simple_item_counter item_counter; + }; + typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; + + set_type s( kSize, 3 ); + test( s ); + } + + TEST_F( MichaelSet_NoGC, backoff ) + { + struct list_traits : public cc::michael_list::traits + { + typedef cmp compare; + typedef cds::backoff::exponential back_off; + }; + typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; + + struct set_traits : public cc::michael_set::traits + { + typedef hash_int hash; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; + + set_type s( kSize, 4 ); + test( s ); + } + + TEST_F( MichaelSet_NoGC, seq_cst ) + { + struct list_traits : public cc::michael_list::traits + { + typedef base_class::less less; + typedef cds::backoff::pause back_off; + typedef cds::opt::v::sequential_consistent memory_model; + }; + typedef cc::MichaelList< gc_type, int_item, list_traits > list_type; + + struct set_traits : public cc::michael_set::traits + { + typedef hash_int hash; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type; + + set_type s( kSize, 4 ); + test( s ); + } + +} // namespace diff --git a/test/unit/set/michael_michael_rcu_gpb.cpp b/test/unit/set/michael_michael_rcu_gpb.cpp new file mode 100644 index 00000000..9b2a1881 --- /dev/null +++ b/test/unit/set/michael_michael_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_michael_michael_rcu.h" + +namespace { + + typedef cds::urcu::general_buffered<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPB, MichaelSet, rcu_implementation ); diff --git a/test/unit/set/michael_michael_rcu_gpi.cpp b/test/unit/set/michael_michael_rcu_gpi.cpp new file mode 100644 index 00000000..a907d591 --- /dev/null +++ b/test/unit/set/michael_michael_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_michael_michael_rcu.h" + +namespace { + + typedef cds::urcu::general_instant<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPI, MichaelSet, rcu_implementation ); diff --git a/test/unit/set/michael_michael_rcu_gpt.cpp b/test/unit/set/michael_michael_rcu_gpt.cpp new file mode 100644 index 00000000..f2a61a68 --- /dev/null +++ b/test/unit/set/michael_michael_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_michael_michael_rcu.h" + +namespace { + + typedef cds::urcu::general_threaded<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPT, MichaelSet, rcu_implementation ); diff --git a/test/unit/set/michael_michael_rcu_shb.cpp b/test/unit/set/michael_michael_rcu_shb.cpp new file mode 100644 index 00000000..be796351 --- /dev/null +++ b/test/unit/set/michael_michael_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_michael_michael_rcu.h" + +namespace { + + typedef cds::urcu::signal_buffered<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_SHB, MichaelSet, rcu_implementation ); + +#endif // CDS_URCU_SIGNAL_HANDLING_ENABLED diff --git a/test/unit/set/michael_michael_rcu_sht.cpp b/test/unit/set/michael_michael_rcu_sht.cpp new file mode 100644 index 00000000..58cf7f69 --- /dev/null +++ b/test/unit/set/michael_michael_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_michael_michael_rcu.h" + +namespace { + + typedef cds::urcu::signal_threaded<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_SHT, MichaelSet, rcu_implementation ); + +#endif // CDS_URCU_SIGNAL_HANDLING_ENABLED diff --git a/test/unit/set/test_michael_michael_rcu.h b/test/unit/set/test_michael_michael_rcu.h new file mode 100644 index 00000000..99f75ee6 --- /dev/null +++ b/test/unit/set/test_michael_michael_rcu.h @@ -0,0 +1,204 @@ +/* + 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_MICHAEL_MICHAEL_RCU_H +#define CDSUNIT_SET_TEST_MICHAEL_MICHAEL_RCU_H + +#include "test_set_rcu.h" +#include +#include + +namespace cc = cds::container; + +template +class MichaelSet: public cds_test::container_set_rcu +{ + typedef cds_test::container_set_rcu base_class; +public: + typedef cds::urcu::gc rcu_type; + +protected: + void SetUp() + { + RCU::Construct(); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + RCU::Destruct(); + } +}; + +TYPED_TEST_CASE_P( MichaelSet ); + +TYPED_TEST_P( MichaelSet, compare ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::int_item int_item; + + typedef cc::MichaelList< rcu_type, int_item, + typename cc::michael_list::make_traits< + cds::opt::compare< typename TestFixture::cmp > + >::type + > list_type; + + typedef cc::MichaelHashSet< rcu_type, list_type, + typename cc::michael_set::make_traits< + cds::opt::hash< typename TestFixture::hash_int > + >::type + > set_type; + + set_type s( TestFixture::kSize, 2 ); + this->test( s ); +} + +TYPED_TEST_P( MichaelSet, less ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::int_item int_item; + + typedef cc::MichaelList< rcu_type, int_item, + typename cc::michael_list::make_traits< + cds::opt::less< typename TestFixture::less > + >::type + > list_type; + + typedef cc::MichaelHashSet< rcu_type, list_type, + typename cc::michael_set::make_traits< + cds::opt::hash< typename TestFixture::hash_int > + >::type + > set_type; + + set_type s( TestFixture::kSize, 2 ); + this->test( s ); +} + +TYPED_TEST_P( MichaelSet, cmpmix ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::int_item int_item; + + struct list_traits : public cc::michael_list::traits + { + typedef typename TestFixture::less less; + typedef typename TestFixture::cmp compare; + }; + typedef cc::MichaelList< rcu_type, int_item, list_traits > list_type; + + typedef cc::MichaelHashSet< rcu_type, list_type, + typename cc::michael_set::make_traits< + cds::opt::hash< typename TestFixture::hash_int > + >::type + > set_type; + + set_type s( TestFixture::kSize, 2 ); + this->test( s ); +} + +TYPED_TEST_P( MichaelSet, item_counting ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::int_item int_item; + + struct list_traits : public cc::michael_list::traits + { + typedef typename TestFixture::cmp compare; + }; + typedef cc::MichaelList< rcu_type, int_item, list_traits > list_type; + + struct set_traits: public cc::michael_set::traits + { + typedef typename TestFixture::hash_int hash; + typedef typename TestFixture::simple_item_counter item_counter; + }; + typedef cc::MichaelHashSet< rcu_type, list_type, set_traits >set_type; + + set_type s( TestFixture::kSize, 3 ); + this->test( s ); +} + +TYPED_TEST_P( MichaelSet, backoff ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::int_item int_item; + + struct list_traits : public cc::michael_list::traits + { + typedef typename TestFixture::cmp compare; + typedef cds::backoff::exponential back_off; + }; + typedef cc::MichaelList< rcu_type, int_item, list_traits > list_type; + + struct set_traits : public cc::michael_set::traits + { + typedef typename TestFixture::hash_int hash; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::MichaelHashSet< rcu_type, list_type, set_traits >set_type; + + set_type s( TestFixture::kSize, 4 ); + this->test( s ); +} + +TYPED_TEST_P( MichaelSet, seq_cst ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::int_item int_item; + + struct list_traits : public cc::michael_list::traits + { + typedef typename TestFixture::less less; + typedef cds::backoff::pause back_off; + typedef cds::opt::v::sequential_consistent memory_model; + }; + typedef cc::MichaelList< rcu_type, int_item, list_traits > list_type; + + struct set_traits : public cc::michael_set::traits + { + typedef typename TestFixture::hash_int hash; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::MichaelHashSet< rcu_type, list_type, set_traits >set_type; + + set_type s( TestFixture::kSize, 4 ); + 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( MichaelSet, + compare, less, cmpmix, item_counting, backoff, seq_cst +); + + +#endif // CDSUNIT_SET_TEST_INTRUSIVE_MICHAEL_MICHAEL_RCU_H + \ No newline at end of file diff --git a/test/unit/set/test_set.h b/test/unit/set/test_set.h new file mode 100644 index 00000000..1f6e142a --- /dev/null +++ b/test/unit/set/test_set.h @@ -0,0 +1,507 @@ +/* + 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_SET_H +#define CDSUNIT_SET_TEST_SET_H + +#include +#include + +#include +#include // ref + +// forward declaration +namespace cds { namespace container {}} + +namespace cds_test { + namespace co = cds::opt; + + class container_set : public fixture + { + public: + static size_t const kSize = 100; + + struct stat + { + unsigned int nFindCount; + unsigned int nUpdateNewCount; + unsigned int nUpdateCount; + mutable unsigned int nEraseCount; + + 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 hash_int { + size_t operator()( int i ) const + { + return co::v::hash()(i); + } + template + size_t operator()( const Item& i ) const + { + return (*this)(i.key()); + } + }; + + 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 less + { + bool operator ()( int_item const& v1, int_item const& v2 ) const + { + return v1.key() < v2.key(); + } + + template + bool operator ()( int_item const& v1, const Q& v2 ) const + { + return v1.key() < v2; + } + + template + bool operator ()( const Q& v1, int_item const& v2 ) const + { + return v1 < v2.key(); + } + }; + + struct cmp { + int operator ()( int_item const& v1, int_item const& v2 ) const + { + if ( v1.key() < v2.key() ) + return -1; + return v1.key() > v2.key() ? 1 : 0; + } + + template + int operator ()( T const& v1, int v2 ) const + { + if ( v1.key() < v2 ) + return -1; + return v1.key() > v2 ? 1 : 0; + } + + template + int operator ()( int v1, T const& v2 ) const + { + if ( v1 < v2.key() ) + return -1; + return v1 > v2.key() ? 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.contains( i ) ); + ASSERT_FALSE( s.contains( other_item( i.key() ), other_less())); + ASSERT_FALSE( s.find( i.nKey, []( value_type&, int ) {} )); + ASSERT_FALSE( s.find( i, []( value_type&, value_type const& ) {} )); + ASSERT_FALSE( s.find_with( other_item( i.key()), other_less(), []( value_type&, other_item const& ) {} )); + + std::pair updResult; + + std::string str; + updResult = s.update( i.key(), []( bool bNew, value_type&, int ) + { + 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, []( bool bNew, value_type& val, value_type const& arg) + { + EXPECT_FALSE( bNew ); + EXPECT_EQ( val.key(), arg.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(), []( bool bNew, value_type& val, int arg) + { + EXPECT_FALSE( bNew ); + EXPECT_EQ( val.key(), arg ); + }, 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, int key ) + { + EXPECT_EQ( v.key(), key ); + 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, int key ) + { + EXPECT_EQ( v.key(), key ); + EXPECT_EQ( v.nFindCount, 1 ); + })); + break; + case 4: + updResult = s.update( i, []( bool bNew, value_type& v, value_type const& arg ) + { + EXPECT_TRUE( bNew ); + EXPECT_EQ( v.key(), arg.key() ); + ++v.nUpdateNewCount; + }); + EXPECT_TRUE( updResult.first ); + EXPECT_TRUE( updResult.second ); + + updResult = s.update( i, []( bool bNew, value_type& v, value_type const& arg ) + { + EXPECT_FALSE( bNew ); + EXPECT_EQ( v.key(), arg.key() ); + ++v.nUpdateNewCount; + }, false ); + EXPECT_TRUE( updResult.first ); + EXPECT_FALSE( updResult.second ); + + ASSERT_TRUE( s.find( i.nKey, []( value_type const& v, int key ) + { + EXPECT_EQ( v.key(), key ); + EXPECT_EQ( v.nUpdateNewCount, 2 ); + })); + break; + case 5: + updResult = s.update( i.key(), []( bool bNew, value_type& v, int arg ) + { + EXPECT_TRUE( bNew ); + EXPECT_EQ( v.key(), arg ); + ++v.nUpdateNewCount; + }); + EXPECT_TRUE( updResult.first ); + EXPECT_TRUE( updResult.second ); + + updResult = s.update( i.key(), []( bool bNew, value_type& v, int arg ) + { + EXPECT_FALSE( bNew ); + EXPECT_EQ( v.key(), arg ); + ++v.nUpdateNewCount; + }, false ); + EXPECT_TRUE( updResult.first ); + EXPECT_FALSE( updResult.second ); + + ASSERT_TRUE( s.find( i, []( value_type const& v, value_type const& arg ) + { + EXPECT_EQ( v.key(), arg.key() ); + EXPECT_EQ( v.nUpdateNewCount, 2 ); + })); + break; + case 6: + ASSERT_TRUE( s.emplace( i.key())); + ASSERT_TRUE( s.find( i, []( value_type const& v, value_type const& arg ) + { + EXPECT_EQ( v.key(), arg.key() ); + EXPECT_EQ( v.nVal, arg.nVal ); + })); + break; + case 7: + str = "Hello!"; + ASSERT_TRUE( s.emplace( i.key(), std::move( str ))); + EXPECT_TRUE( str.empty()); + ASSERT_TRUE( s.find( i, []( value_type const& v, value_type const& arg ) + { + EXPECT_EQ( v.key(), arg.key() ); + EXPECT_EQ( v.nVal, arg.nVal ); + EXPECT_EQ( v.strVal, std::string( "Hello!" )); + } ) ); + break; + default: + // forgot anything?.. + ASSERT_TRUE( false ); + } + + ASSERT_TRUE( s.contains( i.nKey ) ); + ASSERT_TRUE( s.contains( i ) ); + ASSERT_TRUE( s.contains( other_item( i.key() ), other_less() ) ); + ASSERT_TRUE( s.find( i.nKey, []( value_type&, int ) {} ) ); + ASSERT_TRUE( s.find( i, []( value_type&, value_type const& ) {} ) ); + ASSERT_TRUE( s.find_with( other_item( i.key() ), other_less(), []( value_type&, other_item const& ) {} ) ); + } + + 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.contains( i ) ); + ASSERT_TRUE( s.contains( other_item( i.key() ), other_less() ) ); + ASSERT_TRUE( s.find( i.nKey, []( value_type& v, int ) + { + v.nFindCount = 1; + })); + ASSERT_TRUE( s.find( i, []( value_type& v, value_type const& ) + { + EXPECT_EQ( ++v.nFindCount, 2 ); + })); + ASSERT_TRUE( s.find_with( other_item( i.key() ), other_less(), []( value_type& v, other_item const& ) + { + EXPECT_EQ( ++v.nFindCount, 3 ); + })); + + int nKey = i.key() - 1; + switch ( idx % 6 ) { + case 0: + ASSERT_TRUE( s.erase( i.key())); + ASSERT_FALSE( s.erase( i.key())); + break; + case 1: + ASSERT_TRUE( s.erase( i )); + ASSERT_FALSE( s.erase( i )); + break; + case 2: + ASSERT_TRUE( s.erase_with( other_item( i.key()), other_less())); + ASSERT_FALSE( s.erase_with( other_item( i.key() ), other_less() ) ); + break; + case 3: + ASSERT_TRUE( s.erase( i.key(), [&nKey]( value_type const& v ) + { + 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; + case 4: + ASSERT_TRUE( s.erase( i, [&nKey]( value_type const& v ) + { + nKey = v.key(); + } )); + EXPECT_EQ( i.key(), nKey ); + + nKey = i.key() - 1; + ASSERT_FALSE( s.erase( i, [&nKey]( value_type const& v ) + { + nKey = v.key(); + } )); + EXPECT_EQ( i.key(), nKey + 1 ); + break; + case 5: + ASSERT_TRUE( s.erase_with( other_item( i.key()), other_less(), [&nKey]( value_type const& v ) + { + nKey = v.key(); + } )); + EXPECT_EQ( i.key(), nKey ); + + nKey = i.key() - 1; + ASSERT_FALSE( s.erase_with( other_item( i.key()), other_less(), [&nKey]( value_type const& v ) + { + nKey = v.key(); + } )); + EXPECT_EQ( i.key(), nKey + 1 ); + break; + } + + ASSERT_FALSE( s.contains( i.nKey ) ); + ASSERT_FALSE( s.contains( i ) ); + ASSERT_FALSE( s.contains( other_item( i.key() ), other_less())); + ASSERT_FALSE( s.find( i.nKey, []( value_type&, int ) {} )); + ASSERT_FALSE( s.find( i, []( value_type&, value_type const& ) {} )); + ASSERT_FALSE( s.find_with( other_item( i.key()), other_less(), []( value_type&, other_item const& ) {} )); + } + ASSERT_TRUE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, 0 ); + + + // clear + for ( auto& i : data ) { + ASSERT_TRUE( s.insert( i ) ); + } + + 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() ); + } + }; + +} // namespace cds_test + +#endif // CDSUNIT_SET_TEST_SET_H diff --git a/test/unit/set/test_set_hp.h b/test/unit/set/test_set_hp.h new file mode 100644 index 00000000..dd5b3513 --- /dev/null +++ b/test/unit/set/test_set_hp.h @@ -0,0 +1,153 @@ +/* + 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_SET_HP_H +#define CDSUNIT_SET_TEST_SET_HP_H + +#include "test_set.h" + +namespace cds_test { + + class container_set_hp: public container_set + { + typedef container_set 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; + } + + for ( auto it = s.cbegin(); it != s.cend(); ++it ) { + EXPECT_EQ( it->nFindCount, it->key() * 3 ); + } + + typedef typename Set::guarded_ptr guarded_ptr; + guarded_ptr gp; + + // get() + for ( auto idx : indices ) { + auto& i = data[idx]; + + ASSERT_TRUE( !gp ); + switch ( idx % 3 ) { + case 0: + gp = s.get( i.key() ); + ASSERT_FALSE( !gp ); + break; + case 1: + gp = s.get( i ); + ASSERT_FALSE( !gp ); + break; + case 2: + gp = s.get_with( other_item( i.key() ), other_less() ); + ASSERT_FALSE( !gp ); + } + EXPECT_EQ( gp->key(), i.key() ); + EXPECT_EQ( gp->nFindCount, i.key() * 3 ); + gp->nFindCount *= 2; + + gp.release(); + } + + // extract() + for ( auto idx : indices ) { + auto& i = data[idx]; + + ASSERT_TRUE( !gp ); + switch ( idx % 3 ) { + case 0: + gp = s.extract( i.key() ); + ASSERT_FALSE( !gp ); + break; + case 1: + gp = s.extract( i ); + ASSERT_FALSE( !gp ); + break; + case 2: + gp = s.extract_with( other_item( i.key() ), other_less() ); + ASSERT_FALSE( !gp ); + break; + } + EXPECT_EQ( gp->key(), i.key() ); + EXPECT_EQ( gp->nFindCount, i.key() * 6 ); + + switch ( idx % 3 ) { + case 0: + gp = s.extract( i.key() ); + break; + case 1: + gp = s.extract( i ); + break; + case 2: + gp = s.extract_with( other_item( i.key() ), other_less() ); + break; + } + ASSERT_TRUE( !gp ); + } + + ASSERT_TRUE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, 0 ); + } + + }; +} // namespace cds_test + +#endif // CDSUNIT_SET_TEST_SET_HP_H diff --git a/test/unit/set/test_set_nogc.h b/test/unit/set/test_set_nogc.h new file mode 100644 index 00000000..8fbcbdfb --- /dev/null +++ b/test/unit/set/test_set_nogc.h @@ -0,0 +1,349 @@ +/* + 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_SET_NOGC_H +#define CDSUNIT_SET_TEST_SET_NOGC_H + +#include +#include + +#include + +// forward declaration +namespace cds { namespace container {}} + +namespace cds_test { + namespace co = cds::opt; + + class container_set_nogc : public fixture + { + public: + static size_t const kSize = 100; + + 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 hash_int { + size_t operator()( int i ) const + { + return co::v::hash()(i); + } + template + size_t operator()( const Item& i ) const + { + return (*this)(i.key()); + } + }; + + 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 less + { + bool operator ()( int_item const& v1, int_item const& v2 ) const + { + return v1.key() < v2.key(); + } + + template + bool operator ()( int_item const& v1, const Q& v2 ) const + { + return v1.key() < v2; + } + + template + bool operator ()( const Q& v1, int_item const& v2 ) const + { + return v1 < v2.key(); + } + }; + + struct cmp { + int operator ()( int_item const& v1, int_item const& v2 ) const + { + if ( v1.key() < v2.key() ) + return -1; + return v1.key() > v2.key() ? 1 : 0; + } + + template + int operator ()( T const& v1, int v2 ) const + { + if ( v1.key() < v2 ) + return -1; + return v1.key() > v2 ? 1 : 0; + } + + template + int operator ()( int v1, T const& v2 ) const + { + if ( v1 < v2.key() ) + return -1; + return v1 > v2.key() ? 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 ) != s.end() ); + ASSERT_FALSE( s.contains( i ) != s.end() ); + ASSERT_FALSE( s.contains( other_item( i.key() ), other_less()) != s.end()); + + std::pair updResult; + + std::string str; + updResult = s.update( i.key(), false ); + EXPECT_TRUE( updResult.first == s.end()); + EXPECT_FALSE( updResult.second ); + + typename Set::iterator it; + switch ( idx % 6 ) { + case 0: + it = s.insert( i ); + ASSERT_TRUE( it != s.end() ); + it->nFindCount = it->nKey; + ASSERT_TRUE( s.insert( i ) == s.end()); + updResult = s.update( i, false ); + EXPECT_TRUE( updResult.first == it ); + EXPECT_FALSE( updResult.second ); + break; + case 1: + it = s.insert( i.key() ); + ASSERT_TRUE( it != s.end()); + ASSERT_TRUE( s.insert( i.key() ) == s.end()); + it->nFindCount = it->nKey; + updResult = s.update( i.key(), false ); + EXPECT_TRUE( updResult.first == it ); + EXPECT_FALSE( updResult.second ); + break; + case 2: + updResult = s.update( i ); + EXPECT_TRUE( updResult.first != s.end()); + EXPECT_TRUE( updResult.second ); + updResult.first->nFindCount = updResult.first->nKey; + break; + case 3: + updResult = s.update( i.key()); + EXPECT_TRUE( updResult.first != s.end() ); + EXPECT_TRUE( updResult.second ); + updResult.first->nFindCount = updResult.first->nKey; + break; + case 4: + it = s.emplace( i.key()); + ASSERT_TRUE( it != s.end()); + it->nFindCount = it->nKey; + ASSERT_FALSE( s.emplace( i.key() ) != s.end()); + break; + case 5: + str = "Hello!"; + it = s.emplace( i.key(), std::move( str )); + ASSERT_TRUE( it != s.end() ); + EXPECT_TRUE( str.empty()); + it->nFindCount = it->nKey; + str = "Hello!"; + ASSERT_TRUE( s.emplace( i.key(), std::move( str )) == s.end()); + EXPECT_TRUE( str.empty() ); // yes, that's is :( + break; + default: + // forgot anything?.. + ASSERT_TRUE( false ); + } + + it = s.contains( i.nKey ); + ASSERT_TRUE( it != s.end() ); + EXPECT_EQ( it->nFindCount, it->nKey ); + ASSERT_TRUE( s.contains( i ) != s.end() ); + ASSERT_TRUE( s.contains( other_item( i.key() ), other_less() ) != s.end()); + } + + ASSERT_FALSE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, nSetSize ); + + // iterators + 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 ); + } + + // clear + + s.clear(); + + ASSERT_TRUE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, 0 ); + + ASSERT_TRUE( s.begin() == s.end() ); + ASSERT_TRUE( s.cbegin() == s.cend() ); + } + }; + +} // namespace cds_test + +#endif // CDSUNIT_SET_TEST_SET_NOGC_H diff --git a/test/unit/set/test_set_rcu.h b/test/unit/set/test_set_rcu.h new file mode 100644 index 00000000..d819278a --- /dev/null +++ b/test/unit/set/test_set_rcu.h @@ -0,0 +1,192 @@ +/* + 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_SET_RCU_H +#define CDSUNIT_SET_TEST_SET_RCU_H + +#include "test_set.h" + +namespace cds_test { + + class container_set_rcu: public container_set + { + typedef container_set 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; + } + + for ( auto it = s.cbegin(); it != s.cend(); ++it ) { + EXPECT_EQ( it->nFindCount, it->key() * 3 ); + } + + typedef typename Set::exempt_ptr exempt_ptr; + typedef typename Set::raw_ptr raw_ptr; + typedef typename Set::rcu_lock rcu_lock; + + // get() + for ( auto idx : indices ) { + auto& i = data[idx]; + + { + rcu_lock l; + raw_ptr rp; + ASSERT_TRUE( !rp ); + switch ( idx % 3 ) { + case 0: + rp = s.get( i.key() ); + ASSERT_FALSE( !rp ); + break; + case 1: + rp = s.get( i ); + ASSERT_FALSE( !rp ); + break; + case 2: + rp = s.get_with( other_item( i.key() ), other_less() ); + ASSERT_FALSE( !rp ); + } + EXPECT_EQ( rp->key(), i.key() ); + EXPECT_EQ( rp->nFindCount, i.key() * 3 ); + rp->nFindCount *= 2; + } + } + + // extract() + exempt_ptr xp; + for ( auto idx : indices ) { + auto& i = data[idx]; + + ASSERT_TRUE( !xp ); + if ( Set::c_bExtractLockExternal ) { + rcu_lock l; + + switch ( idx % 3 ) { + case 0: + xp = s.extract( i.key() ); + ASSERT_FALSE( !xp ); + break; + case 1: + xp = s.extract( i ); + ASSERT_FALSE( !xp ); + break; + case 2: + xp = s.extract_with( other_item( i.key() ), other_less() ); + ASSERT_FALSE( !xp ); + break; + } + EXPECT_EQ( xp->key(), i.key() ); + EXPECT_EQ( xp->nFindCount, i.key() * 6 ); + + switch ( idx % 3 ) { + case 0: + xp = s.extract( i.key() ); + break; + case 1: + xp = s.extract( i ); + break; + case 2: + xp = s.extract_with( other_item( i.key() ), other_less() ); + break; + } + ASSERT_TRUE( !xp ); + } + else { + switch ( idx % 3 ) { + case 0: + xp = s.extract( i.key() ); + ASSERT_FALSE( !xp ); + break; + case 1: + xp = s.extract( i ); + ASSERT_FALSE( !xp ); + break; + case 2: + xp = s.extract_with( other_item( i.key() ), other_less() ); + ASSERT_FALSE( !xp ); + break; + } + EXPECT_EQ( xp->key(), i.key() ); + EXPECT_EQ( xp->nFindCount, i.key() * 6 ); + + switch ( idx % 3 ) { + case 0: + xp = s.extract( i.key() ); + break; + case 1: + xp = s.extract( i ); + break; + case 2: + xp = s.extract_with( other_item( i.key() ), other_less() ); + break; + } + ASSERT_TRUE( !xp ); + } + } + + ASSERT_TRUE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, 0 ); + } + + }; +} // namespace cds_test + +#endif // CDSUNIT_SET_TEST_SET_RCU_H