From 90487a95d25e8c9479fef0282b4d20d11f7ad804 Mon Sep 17 00:00:00 2001 From: khizmax Date: Sat, 12 Mar 2016 11:51:10 +0300 Subject: [PATCH] Migrated intrusive::MichaelSet unit tests to gtest framework --- projects/Win/vc14/cds.sln | 6 + projects/Win/vc14/gtest-set.vcxproj | 43 ++ projects/Win/vc14/gtest-set.vcxproj.filters | 45 +++ test/unit/set/CMakeLists.txt | 14 + test/unit/set/intrusive_michael_lazy_dhp.cpp | 1 + test/unit/set/intrusive_michael_lazy_hp.cpp | 1 + test/unit/set/intrusive_michael_lazy_nogc.cpp | 241 +++++++++++ .../set/intrusive_michael_lazy_rcu_gpb.cpp | 41 ++ .../set/intrusive_michael_lazy_rcu_gpi.cpp | 41 ++ .../set/intrusive_michael_lazy_rcu_gpt.cpp | 41 ++ .../set/intrusive_michael_lazy_rcu_shb.cpp | 46 +++ .../set/intrusive_michael_lazy_rcu_sht.cpp | 46 +++ .../set/intrusive_michael_michael_dhp.cpp | 1 + .../unit/set/intrusive_michael_michael_hp.cpp | 1 + .../set/intrusive_michael_michael_nogc.cpp | 192 +++++++++ .../set/intrusive_michael_michael_rcu_gpb.cpp | 41 ++ .../set/intrusive_michael_michael_rcu_gpi.cpp | 41 ++ .../set/intrusive_michael_michael_rcu_gpt.cpp | 41 ++ .../set/intrusive_michael_michael_rcu_shb.cpp | 46 +++ .../set/intrusive_michael_michael_rcu_sht.cpp | 46 +++ .../set/test_intrusive_michael_lazy_rcu.h | 298 ++++++++++++++ .../set/test_intrusive_michael_michael_rcu.h | 243 ++++++++++++ test/unit/set/test_intrusive_set.h | 8 +- test/unit/set/test_intrusive_set_hp.h | 8 +- test/unit/set/test_intrusive_set_nogc.h | 374 ++++++++++++++++++ test/unit/set/test_intrusive_set_rcu.h | 55 +-- 26 files changed, 1930 insertions(+), 31 deletions(-) create mode 100644 test/unit/set/intrusive_michael_lazy_nogc.cpp create mode 100644 test/unit/set/intrusive_michael_lazy_rcu_gpb.cpp create mode 100644 test/unit/set/intrusive_michael_lazy_rcu_gpi.cpp create mode 100644 test/unit/set/intrusive_michael_lazy_rcu_gpt.cpp create mode 100644 test/unit/set/intrusive_michael_lazy_rcu_shb.cpp create mode 100644 test/unit/set/intrusive_michael_lazy_rcu_sht.cpp create mode 100644 test/unit/set/intrusive_michael_michael_nogc.cpp create mode 100644 test/unit/set/intrusive_michael_michael_rcu_gpb.cpp create mode 100644 test/unit/set/intrusive_michael_michael_rcu_gpi.cpp create mode 100644 test/unit/set/intrusive_michael_michael_rcu_gpt.cpp create mode 100644 test/unit/set/intrusive_michael_michael_rcu_shb.cpp create mode 100644 test/unit/set/intrusive_michael_michael_rcu_sht.cpp create mode 100644 test/unit/set/test_intrusive_michael_lazy_rcu.h create mode 100644 test/unit/set/test_intrusive_michael_michael_rcu.h create mode 100644 test/unit/set/test_intrusive_set_nogc.h diff --git a/projects/Win/vc14/cds.sln b/projects/Win/vc14/cds.sln index 162f9b23..a21acd60 100644 --- a/projects/Win/vc14/cds.sln +++ b/projects/Win/vc14/cds.sln @@ -148,6 +148,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unit-set-insdelfind", "unit EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "unit", "unit", "{810490B7-31E5-49AE-8455-CAF99A9658B6}" + ProjectSection(SolutionItems) = preProject + ..\..\..\tests\test-hdr\size_check.h = ..\..\..\tests\test-hdr\size_check.h + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest-stack", "gtest-stack.vcxproj", "{5407E9D2-67D9-4266-976E-7A90BDE2541D}" ProjectSection(ProjectDependencies) = postProject @@ -203,6 +206,9 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "stress-pqueue", "stress-pqueue.vcxproj", "{51AC349E-B365-4FCF-8778-17A1534E4584}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest-set", "gtest-set.vcxproj", "{A589D3F1-A749-4268-ADEC-D0CE13D1E359}" + 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 82b5276f..60f94b2e 100644 --- a/projects/Win/vc14/gtest-set.vcxproj +++ b/projects/Win/vc14/gtest-set.vcxproj @@ -30,12 +30,55 @@ + + + 4503 + 4503 + 4503 + 4503 + 4503 + 4503 + + + + 4503 + 4503 + 4503 + 4503 + 4503 + 4503 + + + + + + 4503 + 4503 + 4503 + 4503 + 4503 + 4503 + + + + 4503 + 4503 + 4503 + 4503 + 4503 + 4503 + + + + + + diff --git a/projects/Win/vc14/gtest-set.vcxproj.filters b/projects/Win/vc14/gtest-set.vcxproj.filters index 5048a8b2..9bef3570 100644 --- a/projects/Win/vc14/gtest-set.vcxproj.filters +++ b/projects/Win/vc14/gtest-set.vcxproj.filters @@ -30,6 +30,42 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + @@ -41,5 +77,14 @@ Header Files + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/test/unit/set/CMakeLists.txt b/test/unit/set/CMakeLists.txt index 7f9eb504..61228a43 100644 --- a/test/unit/set/CMakeLists.txt +++ b/test/unit/set/CMakeLists.txt @@ -1,11 +1,25 @@ set(PACKAGE_NAME unit-set) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof") + set(CDSGTEST_SET_SOURCES ../main.cpp intrusive_michael_lazy_hp.cpp intrusive_michael_lazy_dhp.cpp + intrusive_michael_lazy_nogc.cpp + intrusive_michael_lazy_rcu_gpb.cpp + intrusive_michael_lazy_rcu_gpi.cpp + intrusive_michael_lazy_rcu_gpt.cpp + intrusive_michael_lazy_rcu_shb.cpp + intrusive_michael_lazy_rcu_sht.cpp intrusive_michael_michael_hp.cpp intrusive_michael_michael_dhp.cpp + intrusive_michael_michael_nogc.cpp + intrusive_michael_michael_rcu_gpb.cpp + intrusive_michael_michael_rcu_gpi.cpp + intrusive_michael_michael_rcu_gpt.cpp + intrusive_michael_michael_rcu_shb.cpp + intrusive_michael_michael_rcu_sht.cpp ) include_directories( diff --git a/test/unit/set/intrusive_michael_lazy_dhp.cpp b/test/unit/set/intrusive_michael_lazy_dhp.cpp index 72449894..633001a0 100644 --- a/test/unit/set/intrusive_michael_lazy_dhp.cpp +++ b/test/unit/set/intrusive_michael_lazy_dhp.cpp @@ -41,6 +41,7 @@ namespace { class IntrusiveMichaelLazySet_DHP : public cds_test::intrusive_set_hp { + protected: typedef cds_test::intrusive_set_hp base_class; protected: diff --git a/test/unit/set/intrusive_michael_lazy_hp.cpp b/test/unit/set/intrusive_michael_lazy_hp.cpp index ebcb94f9..6583d32d 100644 --- a/test/unit/set/intrusive_michael_lazy_hp.cpp +++ b/test/unit/set/intrusive_michael_lazy_hp.cpp @@ -41,6 +41,7 @@ namespace { class IntrusiveMichaelLazySet_HP : public cds_test::intrusive_set_hp { + protected: typedef cds_test::intrusive_set_hp base_class; protected: diff --git a/test/unit/set/intrusive_michael_lazy_nogc.cpp b/test/unit/set/intrusive_michael_lazy_nogc.cpp new file mode 100644 index 00000000..c183de4f --- /dev/null +++ b/test/unit/set/intrusive_michael_lazy_nogc.cpp @@ -0,0 +1,241 @@ +/* + 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_intrusive_set_nogc.h" + +#include +#include + +#include + +namespace { + namespace ci = cds::intrusive; + typedef cds::gc::nogc gc_type; + + class IntrusiveMichaelLazySet_NoGC : public cds_test::intrusive_set_nogc + { + protected: + typedef cds_test::intrusive_set_nogc base_class; + + protected: + typedef typename base_class::base_int_item< ci::lazy_list::node> base_item_type; + typedef typename base_class::base_int_item< ci::lazy_list::node> base_mutex_item_type; + typedef typename base_class::member_int_item< ci::lazy_list::node> member_item_type; + typedef typename base_class::member_int_item< ci::lazy_list::node> member_mutex_item_type; + + //void SetUp() + //{} + + //void TearDown() + //{} + }; + + + TEST_F( IntrusiveMichaelLazySet_NoGC, base_cmp ) + { + typedef ci::LazyList< gc_type + , base_item_type + ,ci::lazy_list::make_traits< + ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type > > > + ,ci::opt::compare< cmp > + ,ci::opt::disposer< mock_disposer > + ,ci::opt::back_off< cds::backoff::pause > + >::type + > bucket_type; + + typedef ci::MichaelHashSet< gc_type, bucket_type, + ci::michael_set::make_traits< + ci::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( IntrusiveMichaelLazySet_NoGC, base_less ) + { + typedef ci::LazyList< gc_type + , base_item_type + ,ci::lazy_list::make_traits< + ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type >>> + ,ci::opt::less< less > + ,ci::opt::disposer< mock_disposer > + >::type + > bucket_type; + + typedef ci::MichaelHashSet< gc_type, bucket_type, + ci::michael_set::make_traits< + ci::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( IntrusiveMichaelLazySet_NoGC, base_cmpmix ) + { + struct list_traits : public ci::lazy_list::traits + { + typedef ci::lazy_list::base_hook< ci::opt::gc> hook; + typedef base_class::less less; + typedef cmp compare; + typedef mock_disposer disposer; + }; + typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type; + + struct set_traits : public ci::michael_set::traits + { + typedef hash_int hash; + typedef simple_item_counter item_counter; + }; + typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( IntrusiveMichaelLazySet_NoGC, base_mutex ) + { + struct list_traits : public ci::lazy_list::traits + { + typedef ci::lazy_list::base_hook< ci::opt::gc, ci::opt::lock_type> hook; + typedef base_class::less less; + typedef cmp compare; + typedef mock_disposer disposer; + }; + typedef ci::LazyList< gc_type, base_mutex_item_type, list_traits > bucket_type; + + struct set_traits : public ci::michael_set::traits + { + typedef hash_int hash; + typedef simple_item_counter item_counter; + }; + typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + + TEST_F( IntrusiveMichaelLazySet_NoGC, member_cmp ) + { + typedef ci::LazyList< gc_type + ,member_item_type + ,ci::lazy_list::make_traits< + ci::opt::hook< ci::lazy_list::member_hook< + offsetof( member_item_type, hMember ), + ci::opt::gc + > > + ,ci::opt::compare< cmp > + ,ci::opt::disposer< mock_disposer > + >::type + > bucket_type; + + typedef ci::MichaelHashSet< gc_type, bucket_type, + ci::michael_set::make_traits< + ci::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( IntrusiveMichaelLazySet_NoGC, member_less ) + { + typedef ci::LazyList< gc_type + , member_item_type + ,ci::lazy_list::make_traits< + ci::opt::hook< ci::lazy_list::member_hook< + offsetof( member_item_type, hMember ), + ci::opt::gc + > > + ,ci::opt::less< less > + ,ci::opt::disposer< mock_disposer > + >::type + > bucket_type; + + typedef ci::MichaelHashSet< gc_type, bucket_type, + ci::michael_set::make_traits< + ci::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( IntrusiveMichaelLazySet_NoGC, member_cmpmix ) + { + struct list_traits : public ci::lazy_list::traits + { + typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc> hook; + typedef base_class::less less; + typedef cmp compare; + typedef mock_disposer disposer; + }; + typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type; + + struct set_traits : public ci::michael_set::traits + { + typedef hash_int hash; + typedef simple_item_counter item_counter; + }; + typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( IntrusiveMichaelLazySet_NoGC, member_mutex ) + { + struct list_traits : public ci::lazy_list::traits + { + typedef ci::lazy_list::member_hook< offsetof( member_mutex_item_type, hMember ), ci::opt::gc, ci::opt::lock_type> hook; + typedef base_class::less less; + typedef cmp compare; + typedef mock_disposer disposer; + }; + typedef ci::LazyList< gc_type, member_mutex_item_type, list_traits > bucket_type; + + struct set_traits : public ci::michael_set::traits + { + typedef hash_int hash; + typedef simple_item_counter item_counter; + }; + typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + +} // namespace diff --git a/test/unit/set/intrusive_michael_lazy_rcu_gpb.cpp b/test/unit/set/intrusive_michael_lazy_rcu_gpb.cpp new file mode 100644 index 00000000..f2662d23 --- /dev/null +++ b/test/unit/set/intrusive_michael_lazy_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_intrusive_michael_lazy_rcu.h" + +namespace { + + typedef cds::urcu::general_buffered<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPB, IntrusiveMichaelLazySet, rcu_implementation ); diff --git a/test/unit/set/intrusive_michael_lazy_rcu_gpi.cpp b/test/unit/set/intrusive_michael_lazy_rcu_gpi.cpp new file mode 100644 index 00000000..b35171ae --- /dev/null +++ b/test/unit/set/intrusive_michael_lazy_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_intrusive_michael_lazy_rcu.h" + +namespace { + + typedef cds::urcu::general_instant<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPI, IntrusiveMichaelLazySet, rcu_implementation ); diff --git a/test/unit/set/intrusive_michael_lazy_rcu_gpt.cpp b/test/unit/set/intrusive_michael_lazy_rcu_gpt.cpp new file mode 100644 index 00000000..76ff2f07 --- /dev/null +++ b/test/unit/set/intrusive_michael_lazy_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_intrusive_michael_lazy_rcu.h" + +namespace { + + typedef cds::urcu::general_threaded<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPT, IntrusiveMichaelLazySet, rcu_implementation ); diff --git a/test/unit/set/intrusive_michael_lazy_rcu_shb.cpp b/test/unit/set/intrusive_michael_lazy_rcu_shb.cpp new file mode 100644 index 00000000..a7728a2e --- /dev/null +++ b/test/unit/set/intrusive_michael_lazy_rcu_shb.cpp @@ -0,0 +1,46 @@ +/* + 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_intrusive_michael_lazy_rcu.h" + +namespace { + + typedef cds::urcu::signal_buffered<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_SHB, IntrusiveMichaelLazySet, rcu_implementation ); + +#endif // #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED + diff --git a/test/unit/set/intrusive_michael_lazy_rcu_sht.cpp b/test/unit/set/intrusive_michael_lazy_rcu_sht.cpp new file mode 100644 index 00000000..16c00ba1 --- /dev/null +++ b/test/unit/set/intrusive_michael_lazy_rcu_sht.cpp @@ -0,0 +1,46 @@ +/* + 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_intrusive_michael_lazy_rcu.h" + +namespace { + + typedef cds::urcu::signal_threaded<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_SHT, IntrusiveMichaelLazySet, rcu_implementation ); + +#endif // #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED + diff --git a/test/unit/set/intrusive_michael_michael_dhp.cpp b/test/unit/set/intrusive_michael_michael_dhp.cpp index 9b5719f2..035c21f1 100644 --- a/test/unit/set/intrusive_michael_michael_dhp.cpp +++ b/test/unit/set/intrusive_michael_michael_dhp.cpp @@ -39,6 +39,7 @@ namespace { class IntrusiveMichaelSet_DHP : public cds_test::intrusive_set_hp { + protected: typedef cds_test::intrusive_set_hp base_class; protected: diff --git a/test/unit/set/intrusive_michael_michael_hp.cpp b/test/unit/set/intrusive_michael_michael_hp.cpp index 7aca853a..a97824d3 100644 --- a/test/unit/set/intrusive_michael_michael_hp.cpp +++ b/test/unit/set/intrusive_michael_michael_hp.cpp @@ -39,6 +39,7 @@ namespace { class IntrusiveMichaelSet_HP : public cds_test::intrusive_set_hp { + protected: typedef cds_test::intrusive_set_hp base_class; protected: diff --git a/test/unit/set/intrusive_michael_michael_nogc.cpp b/test/unit/set/intrusive_michael_michael_nogc.cpp new file mode 100644 index 00000000..2ce9e2b2 --- /dev/null +++ b/test/unit/set/intrusive_michael_michael_nogc.cpp @@ -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. +*/ + +#include "test_intrusive_set_nogc.h" + +#include +#include + +namespace { + namespace ci = cds::intrusive; + typedef cds::gc::nogc gc_type; + + class IntrusiveMichaelSet_NoGC : public cds_test::intrusive_set_nogc + { + protected: + typedef cds_test::intrusive_set_nogc base_class; + + protected: + typedef typename base_class::base_int_item< ci::michael_list::node> base_item_type; + typedef typename base_class::member_int_item< ci::michael_list::node> member_item_type; + + //void SetUp() + //{} + + //void TearDown() + //{} + }; + + + TEST_F( IntrusiveMichaelSet_NoGC, base_cmp ) + { + typedef ci::MichaelList< gc_type + , base_item_type + ,ci::michael_list::make_traits< + ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< gc_type > > > + ,ci::opt::compare< cmp > + ,ci::opt::disposer< mock_disposer > + >::type + > bucket_type; + + typedef ci::MichaelHashSet< gc_type, bucket_type, + ci::michael_set::make_traits< + ci::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( IntrusiveMichaelSet_NoGC, base_less ) + { + typedef ci::MichaelList< gc_type + , base_item_type + ,ci::michael_list::make_traits< + ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< gc_type >>> + ,ci::opt::less< less > + ,ci::opt::disposer< mock_disposer > + >::type + > bucket_type; + + typedef ci::MichaelHashSet< gc_type, bucket_type, + ci::michael_set::make_traits< + ci::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( IntrusiveMichaelSet_NoGC, base_cmpmix ) + { + struct list_traits : public ci::michael_list::traits + { + typedef ci::michael_list::base_hook< ci::opt::gc> hook; + typedef base_class::less less; + typedef cmp compare; + typedef mock_disposer disposer; + }; + typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type; + + struct set_traits : public ci::michael_set::traits + { + typedef hash_int hash; + typedef simple_item_counter item_counter; + }; + typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + + TEST_F( IntrusiveMichaelSet_NoGC, member_cmp ) + { + typedef ci::MichaelList< gc_type + ,member_item_type + ,ci::michael_list::make_traits< + ci::opt::hook< ci::michael_list::member_hook< + offsetof( member_item_type, hMember ), + ci::opt::gc + > > + ,ci::opt::compare< cmp > + ,ci::opt::disposer< mock_disposer > + >::type + > bucket_type; + + typedef ci::MichaelHashSet< gc_type, bucket_type, + ci::michael_set::make_traits< + ci::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( IntrusiveMichaelSet_NoGC, member_less ) + { + typedef ci::MichaelList< gc_type + , member_item_type + ,ci::michael_list::make_traits< + ci::opt::hook< ci::michael_list::member_hook< + offsetof( member_item_type, hMember ), + ci::opt::gc + > > + ,ci::opt::less< less > + ,ci::opt::disposer< mock_disposer > + >::type + > bucket_type; + + typedef ci::MichaelHashSet< gc_type, bucket_type, + ci::michael_set::make_traits< + ci::opt::hash< hash_int > + >::type + > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + + TEST_F( IntrusiveMichaelSet_NoGC, member_cmpmix ) + { + struct list_traits : public ci::michael_list::traits + { + typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc> hook; + typedef base_class::less less; + typedef cmp compare; + typedef mock_disposer disposer; + }; + typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type; + + struct set_traits : public ci::michael_set::traits + { + typedef hash_int hash; + typedef simple_item_counter item_counter; + }; + typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type; + + set_type s( kSize, 2 ); + test( s ); + } + +} // namespace diff --git a/test/unit/set/intrusive_michael_michael_rcu_gpb.cpp b/test/unit/set/intrusive_michael_michael_rcu_gpb.cpp new file mode 100644 index 00000000..e8d6f68d --- /dev/null +++ b/test/unit/set/intrusive_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_intrusive_michael_michael_rcu.h" + +namespace { + + typedef cds::urcu::general_buffered<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPB, IntrusiveMichaelSet, rcu_implementation ); diff --git a/test/unit/set/intrusive_michael_michael_rcu_gpi.cpp b/test/unit/set/intrusive_michael_michael_rcu_gpi.cpp new file mode 100644 index 00000000..3e65ce11 --- /dev/null +++ b/test/unit/set/intrusive_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_intrusive_michael_michael_rcu.h" + +namespace { + + typedef cds::urcu::general_instant<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPI, IntrusiveMichaelSet, rcu_implementation ); diff --git a/test/unit/set/intrusive_michael_michael_rcu_gpt.cpp b/test/unit/set/intrusive_michael_michael_rcu_gpt.cpp new file mode 100644 index 00000000..b397529a --- /dev/null +++ b/test/unit/set/intrusive_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_intrusive_michael_michael_rcu.h" + +namespace { + + typedef cds::urcu::general_threaded<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPT, IntrusiveMichaelSet, rcu_implementation ); diff --git a/test/unit/set/intrusive_michael_michael_rcu_shb.cpp b/test/unit/set/intrusive_michael_michael_rcu_shb.cpp new file mode 100644 index 00000000..6f5be5a9 --- /dev/null +++ b/test/unit/set/intrusive_michael_michael_rcu_shb.cpp @@ -0,0 +1,46 @@ +/* + 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_intrusive_michael_michael_rcu.h" + +namespace { + + typedef cds::urcu::signal_buffered<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_SHB, IntrusiveMichaelSet, rcu_implementation ); + +#endif // #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED + diff --git a/test/unit/set/intrusive_michael_michael_rcu_sht.cpp b/test/unit/set/intrusive_michael_michael_rcu_sht.cpp new file mode 100644 index 00000000..a2e76b5f --- /dev/null +++ b/test/unit/set/intrusive_michael_michael_rcu_sht.cpp @@ -0,0 +1,46 @@ +/* + 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_intrusive_michael_michael_rcu.h" + +namespace { + + typedef cds::urcu::signal_threaded<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_SHT, IntrusiveMichaelSet, rcu_implementation ); + +#endif // #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED + diff --git a/test/unit/set/test_intrusive_michael_lazy_rcu.h b/test/unit/set/test_intrusive_michael_lazy_rcu.h new file mode 100644 index 00000000..c32fdb65 --- /dev/null +++ b/test/unit/set/test_intrusive_michael_lazy_rcu.h @@ -0,0 +1,298 @@ +/* + 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_INTRUSIVE_MICHAEL_LAZY_RCU_H +#define CDSUNIT_SET_TEST_INTRUSIVE_MICHAEL_LAZY_RCU_H + +#include "test_intrusive_set_rcu.h" +#include +#include + +namespace ci = cds::intrusive; + +template +class IntrusiveMichaelLazySet: public cds_test::intrusive_set_rcu +{ + typedef cds_test::intrusive_set_rcu base_class; +public: + typedef cds::urcu::gc rcu_type; + typedef typename base_class::base_int_item< ci::lazy_list::node> base_item_type; + typedef typename base_class::base_int_item< ci::lazy_list::node> base_mutex_item_type; + typedef typename base_class::member_int_item< ci::lazy_list::node> member_item_type; + typedef typename base_class::member_int_item< ci::lazy_list::node> member_mutex_item_type; + +protected: + void SetUp() + { + RCU::Construct(); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + RCU::Destruct(); + } +}; + +TYPED_TEST_CASE_P( IntrusiveMichaelLazySet ); + +TYPED_TEST_P( IntrusiveMichaelLazySet, base_cmp ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::base_item_type base_item_type; + typedef typename TestFixture::mock_disposer mock_disposer; + typedef typename TestFixture::template cmp cmp; + typedef typename TestFixture::hash_int hash_int; + + typedef ci::LazyList< rcu_type + , base_item_type + , typename ci::lazy_list::make_traits< + ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< rcu_type > > > + , ci::opt::compare< cmp > + , ci::opt::disposer< mock_disposer > + >::type + > bucket_type; + + typedef ci::MichaelHashSet< rcu_type, bucket_type, + typename ci::michael_set::make_traits< + ci::opt::hash< hash_int > + >::type + > set_type; + + set_type s( TestFixture::kSize, 2 ); + this->test( s ); +} + +TYPED_TEST_P( IntrusiveMichaelLazySet, base_less ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::base_item_type base_item_type; + typedef typename TestFixture::mock_disposer mock_disposer; + typedef typename TestFixture::template less less; + typedef typename TestFixture::hash_int hash_int; + + typedef ci::LazyList< rcu_type + , base_item_type + , typename ci::lazy_list::make_traits< + ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< rcu_type >>> + , ci::opt::less< less > + , ci::opt::disposer< mock_disposer > + >::type + > bucket_type; + + typedef ci::MichaelHashSet< rcu_type, bucket_type, + typename ci::michael_set::make_traits< + ci::opt::hash< hash_int > + >::type + > set_type; + + set_type s( TestFixture::kSize, 2 ); + this->test( s ); +} + +TYPED_TEST_P( IntrusiveMichaelLazySet, base_cmpmix ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::base_item_type base_item_type; + typedef typename TestFixture::mock_disposer mock_disposer; + typedef typename TestFixture::hash_int hash_int; + + struct list_traits : public ci::lazy_list::traits + { + typedef ci::lazy_list::base_hook< ci::opt::gc> hook; + typedef typename TestFixture::template less less; + typedef typename TestFixture::template cmp compare; + typedef mock_disposer disposer; + }; + typedef ci::LazyList< rcu_type, base_item_type, list_traits > bucket_type; + + struct set_traits : public ci::michael_set::traits + { + typedef hash_int hash; + typedef typename TestFixture::simple_item_counter item_counter; + }; + typedef ci::MichaelHashSet< rcu_type, bucket_type, set_traits > set_type; + + set_type s( TestFixture::kSize, 2 ); + this->test( s ); +} + +TYPED_TEST_P( IntrusiveMichaelLazySet, base_mutex ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::base_mutex_item_type base_mutex_item_type; + typedef typename TestFixture::mock_disposer mock_disposer; + typedef typename TestFixture::hash_int hash_int; + + struct list_traits : public ci::lazy_list::traits + { + typedef ci::lazy_list::base_hook< ci::opt::gc, ci::opt::lock_type> hook; + typedef typename TestFixture::template less less; + typedef typename TestFixture::template cmp compare; + typedef mock_disposer disposer; + }; + typedef ci::LazyList< rcu_type, base_mutex_item_type, list_traits > bucket_type; + + struct set_traits : public ci::michael_set::traits + { + typedef hash_int hash; + typedef typename TestFixture::simple_item_counter item_counter; + }; + typedef ci::MichaelHashSet< rcu_type, bucket_type, set_traits > set_type; + + set_type s( TestFixture::kSize, 2 ); + this->test( s ); +} + + +TYPED_TEST_P( IntrusiveMichaelLazySet, member_cmp ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::member_item_type member_item_type; + typedef typename TestFixture::mock_disposer mock_disposer; + typedef typename TestFixture::template cmp cmp; + typedef typename TestFixture::hash_int hash_int; + + typedef ci::LazyList< rcu_type + , member_item_type + , typename ci::lazy_list::make_traits< + ci::opt::hook< ci::lazy_list::member_hook< + offsetof( member_item_type, hMember ), + ci::opt::gc + >> + , ci::opt::compare< cmp > + , ci::opt::disposer< mock_disposer > + >::type + > bucket_type; + + typedef ci::MichaelHashSet< rcu_type, bucket_type, + typename ci::michael_set::make_traits< + ci::opt::hash< hash_int > + >::type + > set_type; + + set_type s( TestFixture::kSize, 2 ); + this->test( s ); +} + +TYPED_TEST_P( IntrusiveMichaelLazySet, member_less ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::member_item_type member_item_type; + typedef typename TestFixture::mock_disposer mock_disposer; + typedef typename TestFixture::template less less; + typedef typename TestFixture::hash_int hash_int; + + typedef ci::LazyList< rcu_type + , member_item_type + , typename ci::lazy_list::make_traits< + ci::opt::hook< ci::lazy_list::member_hook< + offsetof( member_item_type, hMember ), + ci::opt::gc + > > + , ci::opt::less< less > + , ci::opt::disposer< mock_disposer > + >::type + > bucket_type; + + typedef ci::MichaelHashSet< rcu_type, bucket_type, + typename ci::michael_set::make_traits< + ci::opt::hash< hash_int > + >::type + > set_type; + + set_type s( TestFixture::kSize, 2 ); + this->test( s ); +} + +TYPED_TEST_P( IntrusiveMichaelLazySet, member_cmpmix ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::member_item_type member_item_type; + typedef typename TestFixture::mock_disposer mock_disposer; + typedef typename TestFixture::hash_int hash_int; + + struct list_traits : public ci::lazy_list::traits + { + typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc> hook; + typedef typename TestFixture::template less less; + typedef typename TestFixture::template cmp compare; + typedef mock_disposer disposer; + }; + typedef ci::LazyList< rcu_type, member_item_type, list_traits > bucket_type; + + struct set_traits : public ci::michael_set::traits + { + typedef hash_int hash; + typedef typename TestFixture::simple_item_counter item_counter; + }; + typedef ci::MichaelHashSet< rcu_type, bucket_type, set_traits > set_type; + + set_type s( TestFixture::kSize, 2 ); + this->test( s ); +} + +TYPED_TEST_P( IntrusiveMichaelLazySet, member_mutex ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::member_mutex_item_type member_mutex_item_type; + typedef typename TestFixture::mock_disposer mock_disposer; + typedef typename TestFixture::hash_int hash_int; + + struct list_traits : public ci::lazy_list::traits + { + typedef ci::lazy_list::member_hook< offsetof( member_mutex_item_type, hMember ), ci::opt::gc, ci::opt::lock_type> hook; + typedef typename TestFixture::template less less; + typedef typename TestFixture::template cmp compare; + typedef mock_disposer disposer; + }; + typedef ci::LazyList< rcu_type, member_mutex_item_type, list_traits > bucket_type; + + struct set_traits : public ci::michael_set::traits + { + typedef hash_int hash; + typedef typename TestFixture::simple_item_counter item_counter; + }; + typedef ci::MichaelHashSet< rcu_type, bucket_type, set_traits > set_type; + + set_type s( TestFixture::kSize, 2 ); + 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( IntrusiveMichaelLazySet, + base_cmp, base_less, base_cmpmix, base_mutex, member_cmp, member_less, member_cmpmix, member_mutex +); + + +#endif // CDSUNIT_SET_TEST_INTRUSIVE_MICHAEL_LAZY_RCU_H + \ No newline at end of file diff --git a/test/unit/set/test_intrusive_michael_michael_rcu.h b/test/unit/set/test_intrusive_michael_michael_rcu.h new file mode 100644 index 00000000..199fef5c --- /dev/null +++ b/test/unit/set/test_intrusive_michael_michael_rcu.h @@ -0,0 +1,243 @@ +/* + 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_INTRUSIVE_MICHAEL_MICHAEL_RCU_H +#define CDSUNIT_SET_TEST_INTRUSIVE_MICHAEL_MICHAEL_RCU_H + +#include "test_intrusive_set_rcu.h" +#include +#include + +namespace ci = cds::intrusive; + +template +class IntrusiveMichaelSet: public cds_test::intrusive_set_rcu +{ + typedef cds_test::intrusive_set_rcu base_class; +public: + typedef cds::urcu::gc rcu_type; + typedef typename base_class::base_int_item< ci::michael_list::node> base_item_type; + typedef typename base_class::member_int_item< ci::michael_list::node> member_item_type; + +protected: + void SetUp() + { + RCU::Construct(); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + RCU::Destruct(); + } +}; + +TYPED_TEST_CASE_P( IntrusiveMichaelSet ); + +TYPED_TEST_P( IntrusiveMichaelSet, base_cmp ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::base_item_type base_item_type; + typedef typename TestFixture::mock_disposer mock_disposer; + typedef typename TestFixture::template cmp cmp; + typedef typename TestFixture::hash_int hash_int; + + typedef ci::MichaelList< rcu_type + , base_item_type + , typename ci::michael_list::make_traits< + ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< rcu_type > > > + , ci::opt::compare< cmp > + , ci::opt::disposer< mock_disposer > + >::type + > bucket_type; + + typedef ci::MichaelHashSet< rcu_type, bucket_type, + typename ci::michael_set::make_traits< + ci::opt::hash< hash_int > + >::type + > set_type; + + set_type s( TestFixture::kSize, 2 ); + this->test( s ); +} + +TYPED_TEST_P( IntrusiveMichaelSet, base_less ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::base_item_type base_item_type; + typedef typename TestFixture::mock_disposer mock_disposer; + typedef typename TestFixture::template less less; + typedef typename TestFixture::hash_int hash_int; + + typedef ci::MichaelList< rcu_type + , base_item_type + , typename ci::michael_list::make_traits< + ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< rcu_type >>> + , ci::opt::less< less > + , ci::opt::disposer< mock_disposer > + >::type + > bucket_type; + + typedef ci::MichaelHashSet< rcu_type, bucket_type, + typename ci::michael_set::make_traits< + ci::opt::hash< hash_int > + >::type + > set_type; + + set_type s( TestFixture::kSize, 2 ); + this->test( s ); +} + +TYPED_TEST_P( IntrusiveMichaelSet, base_cmpmix ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::base_item_type base_item_type; + typedef typename TestFixture::mock_disposer mock_disposer; + typedef typename TestFixture::hash_int hash_int; + + struct list_traits : public ci::michael_list::traits + { + typedef ci::michael_list::base_hook< ci::opt::gc> hook; + typedef typename TestFixture::template less less; + typedef typename TestFixture::template cmp compare; + typedef mock_disposer disposer; + }; + typedef ci::MichaelList< rcu_type, base_item_type, list_traits > bucket_type; + + struct set_traits : public ci::michael_set::traits + { + typedef hash_int hash; + typedef typename TestFixture::simple_item_counter item_counter; + }; + typedef ci::MichaelHashSet< rcu_type, bucket_type, set_traits > set_type; + + set_type s( TestFixture::kSize, 2 ); + this->test( s ); +} + + +TYPED_TEST_P( IntrusiveMichaelSet, member_cmp ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::member_item_type member_item_type; + typedef typename TestFixture::mock_disposer mock_disposer; + typedef typename TestFixture::template cmp cmp; + typedef typename TestFixture::hash_int hash_int; + + typedef ci::MichaelList< rcu_type + , member_item_type + , typename ci::michael_list::make_traits< + ci::opt::hook< ci::michael_list::member_hook< + offsetof( member_item_type, hMember ), + ci::opt::gc + >> + , ci::opt::compare< cmp > + , ci::opt::disposer< mock_disposer > + >::type + > bucket_type; + + typedef ci::MichaelHashSet< rcu_type, bucket_type, + typename ci::michael_set::make_traits< + ci::opt::hash< hash_int > + >::type + > set_type; + + set_type s( TestFixture::kSize, 2 ); + this->test( s ); +} + +TYPED_TEST_P( IntrusiveMichaelSet, member_less ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::member_item_type member_item_type; + typedef typename TestFixture::mock_disposer mock_disposer; + typedef typename TestFixture::template less less; + typedef typename TestFixture::hash_int hash_int; + + typedef ci::MichaelList< rcu_type + , member_item_type + , typename ci::michael_list::make_traits< + ci::opt::hook< ci::michael_list::member_hook< + offsetof( member_item_type, hMember ), + ci::opt::gc + > > + , ci::opt::less< less > + , ci::opt::disposer< mock_disposer > + >::type + > bucket_type; + + typedef ci::MichaelHashSet< rcu_type, bucket_type, + typename ci::michael_set::make_traits< + ci::opt::hash< hash_int > + >::type + > set_type; + + set_type s( TestFixture::kSize, 2 ); + this->test( s ); +} + +TYPED_TEST_P( IntrusiveMichaelSet, member_cmpmix ) +{ + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::member_item_type member_item_type; + typedef typename TestFixture::mock_disposer mock_disposer; + typedef typename TestFixture::hash_int hash_int; + + struct list_traits : public ci::michael_list::traits + { + typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc> hook; + typedef typename TestFixture::template less less; + typedef typename TestFixture::template cmp compare; + typedef mock_disposer disposer; + }; + typedef ci::MichaelList< rcu_type, member_item_type, list_traits > bucket_type; + + struct set_traits : public ci::michael_set::traits + { + typedef hash_int hash; + typedef typename TestFixture::simple_item_counter item_counter; + }; + typedef ci::MichaelHashSet< rcu_type, bucket_type, set_traits > set_type; + + set_type s( TestFixture::kSize, 2 ); + 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( IntrusiveMichaelSet, + base_cmp, base_less, base_cmpmix, member_cmp, member_less, member_cmpmix +); + + +#endif // CDSUNIT_SET_TEST_INTRUSIVE_MICHAEL_MICHAEL_RCU_H + \ No newline at end of file diff --git a/test/unit/set/test_intrusive_set.h b/test/unit/set/test_intrusive_set.h index 139c92a9..d4ed3035 100644 --- a/test/unit/set/test_intrusive_set.h +++ b/test/unit/set/test_intrusive_set.h @@ -47,7 +47,7 @@ namespace cds_test { class intrusive_set: public fixture { - protected: + public: static size_t const kSize = 100; struct stat @@ -258,6 +258,7 @@ namespace cds_test { } }; + protected: template void test( Set& s ) { @@ -266,6 +267,7 @@ namespace cds_test { ASSERT_TRUE( s.empty() ); ASSERT_CONTAINER_SIZE( s, 0 ); + size_t const nSetSize = kSize; typedef typename Set::value_type value_type; @@ -339,7 +341,7 @@ namespace cds_test { EXPECT_EQ( i.nFindCount, 2 ); } ASSERT_FALSE( s.empty() ); - ASSERT_CONTAINER_SIZE( s, kSize ); + ASSERT_CONTAINER_SIZE( s, nSetSize ); std::for_each( data.begin(), data.end(), []( value_type& v ) { v.clear_stat(); }); @@ -413,7 +415,7 @@ namespace cds_test { ASSERT_TRUE( s.insert( i )); } ASSERT_FALSE( s.empty() ); - ASSERT_CONTAINER_SIZE( s, kSize ); + ASSERT_CONTAINER_SIZE( s, nSetSize ); // Iterator test for ( auto it = s.begin(); it != s.end(); ++it ) { diff --git a/test/unit/set/test_intrusive_set_hp.h b/test/unit/set/test_intrusive_set_hp.h index 7c122c52..7ae09c73 100644 --- a/test/unit/set/test_intrusive_set_hp.h +++ b/test/unit/set/test_intrusive_set_hp.h @@ -103,17 +103,17 @@ namespace cds_test { EXPECT_EQ( i.nFindCount, 0 ); gp = s.get( i ); - ASSERT_TRUE( gp ); + ASSERT_FALSE( !gp ); ++gp->nFindCount; EXPECT_EQ( i.nFindCount, 1 ); gp = s.get( i.key() ); - ASSERT_TRUE( gp ); + ASSERT_FALSE( !gp ); ++gp->nFindCount; EXPECT_EQ( i.nFindCount, 2 ); gp = s.get_with( other_item( i.key()), other_less()); - ASSERT_TRUE( gp ); + ASSERT_FALSE( !gp ); ++gp->nFindCount; EXPECT_EQ( i.nFindCount, 3 ); @@ -129,7 +129,7 @@ namespace cds_test { gp = s.extract_with( other_item( i.key() ), other_less() ); break; } - ASSERT_TRUE( gp ); + ASSERT_FALSE( !gp ); ++gp->nEraseCount; EXPECT_EQ( i.nEraseCount, 1 ); diff --git a/test/unit/set/test_intrusive_set_nogc.h b/test/unit/set/test_intrusive_set_nogc.h new file mode 100644 index 00000000..46e06a55 --- /dev/null +++ b/test/unit/set/test_intrusive_set_nogc.h @@ -0,0 +1,374 @@ +/* + 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_INTRUSIVE_SET_NOGC_H +#define CDSUNIT_SET_TEST_INTRUSIVE_SET_NOGC_H + +#include +#include + +#include +#include // ref + +// forward declaration +namespace cds { namespace intrusive {}} + +namespace cds_test { + + namespace ci = cds::intrusive; + namespace co = cds::opt; + + class intrusive_set_nogc: public fixture + { + public: + static size_t const kSize = 100; + + struct stat + { + unsigned int nFindCount ; // count of find-functor calling + unsigned int nUpdateNewCount; + unsigned int nUpdateCount; + unsigned int nDisposeCount; + + stat() + { + clear_stat(); + } + + void clear_stat() + { + memset( this, 0, sizeof( *this ) ); + } + }; + + template + struct base_int_item + : public Node + , public stat + + { + int nKey; + int nVal; + + base_int_item() + {} + + explicit base_int_item( int key ) + : nKey( key ) + , nVal( key ) + {} + + base_int_item(int key, int val) + : nKey( key ) + , nVal(val) + {} + + base_int_item( base_int_item const& v ) + : Node() + , stat() + , nKey( v.nKey ) + , nVal( v.nVal ) + {} + + int key() const + { + return nKey; + } + }; + + template + struct member_int_item: public stat + { + int nKey; + int nVal; + + Node hMember; + + stat s; + + member_int_item() + {} + + explicit member_int_item( int key ) + : nKey( key ) + , nVal( key ) + {} + + member_int_item(int key, int val) + : nKey( key ) + , nVal(val) + {} + + member_int_item(member_int_item const& v ) + : stat() + , nKey( v.nKey ) + , nVal( v.nVal ) + {} + + 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; + } + + }; + + + template + struct less + { + bool operator ()(const T& v1, const T& v2 ) const + { + return v1.key() < v2.key(); + } + + template + bool operator ()(const T& v1, const Q& v2 ) const + { + return v1.key() < v2; + } + + template + bool operator ()(const Q& v1, const T& v2 ) const + { + return v1 < v2.key(); + } + }; + + template + struct cmp { + int operator ()(const T& v1, const T& v2 ) const + { + if ( v1.key() < v2.key() ) + return -1; + return v1.key() > v2.key() ? 1 : 0; + } + + template + int operator ()(const T& v1, const Q& v2 ) const + { + if ( v1.key() < v2 ) + return -1; + return v1.key() > v2 ? 1 : 0; + } + + template + int operator ()(const Q& v1, const T& v2 ) const + { + if ( v1 < v2.key() ) + return -1; + return v1 > v2.key() ? 1 : 0; + } + }; + + struct other_item { + int nKey; + + explicit other_item( int k ) + : nKey( k ) + {} + + int key() const + { + return nKey; + } + }; + + struct other_less { + template + bool operator()( Q const& lhs, T const& rhs ) const + { + return lhs.key() < rhs.key(); + } + }; + + struct mock_disposer + { + template + void operator ()( T * p ) + { + ++p->nDisposeCount; + } + }; + + 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_TRUE( s.contains( i.nKey ) == nullptr ); + ASSERT_TRUE( s.contains( i ) == nullptr ); + ASSERT_TRUE( s.contains( other_item( i.key()), other_less()) == nullptr ); + ASSERT_FALSE( s.find( i.nKey, []( value_type&, int ) {} )); + ASSERT_FALSE( s.find_with( other_item( i.key()), other_less(), []( value_type&, other_item const& ) {} )); + + std::pair updResult; + + updResult = s.update( i, []( bool bNew, value_type&, value_type& ) + { + ASSERT_TRUE( false ); + }, false ); + EXPECT_FALSE( updResult.first ); + EXPECT_FALSE( updResult.second ); + + switch ( i.key() % 2 ) { + case 0: + ASSERT_TRUE( s.insert( i )); + ASSERT_FALSE( s.insert( i )); + EXPECT_EQ( i.nUpdateCount, 0 ); + updResult = s.update( i, []( bool bNew, value_type& val, value_type& arg) + { + EXPECT_FALSE( bNew ); + EXPECT_EQ( &val, &arg ); + ++val.nUpdateCount; + }, false ); + EXPECT_TRUE( updResult.first ); + EXPECT_FALSE( updResult.second ); + EXPECT_EQ( i.nUpdateCount, 1 ); + break; + case 1: + EXPECT_EQ( i.nUpdateNewCount, 0 ); + updResult = s.update( i, []( bool bNew, value_type& val, value_type& arg ) + { + EXPECT_TRUE( bNew ); + EXPECT_EQ( &val, &arg ); + ++val.nUpdateNewCount; + }); + EXPECT_TRUE( updResult.first ); + EXPECT_TRUE( updResult.second ); + EXPECT_EQ( i.nUpdateNewCount, 1 ); + break; + } + + ASSERT_TRUE( s.contains( i.nKey ) == &i ); + ASSERT_TRUE( s.contains( i ) == &i ); + ASSERT_TRUE( s.contains( other_item( i.key() ), other_less()) == &i ); + EXPECT_EQ( i.nFindCount, 0 ); + ASSERT_TRUE( s.find( i.nKey, []( value_type& v, int ) { ++v.nFindCount; } )); + EXPECT_EQ( i.nFindCount, 1 ); + ASSERT_TRUE( s.find_with( other_item( i.key() ), other_less(), []( value_type& v, other_item const& ) { ++v.nFindCount; } )); + EXPECT_EQ( i.nFindCount, 2 ); + } + ASSERT_FALSE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, nSetSize ); + + std::for_each( data.begin(), data.end(), []( value_type& v ) { v.clear_stat(); }); + + // Iterator test + for ( auto it = s.begin(); it != s.end(); ++it ) { + ++it->nFindCount; + } + for ( auto it = s.cbegin(); it != s.cend(); ++it ) { + EXPECT_EQ( it->nFindCount, 1 ); + } + for ( auto& i : data ) { + EXPECT_EQ( i.nFindCount, 1 ); + } + + // clear test + for ( auto& i : data ) { + EXPECT_EQ( i.nDisposeCount, 0 ); + } + s.clear(); + for ( auto& i : data ) { + EXPECT_EQ( i.nDisposeCount, 1 ); + } + + 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 // #ifndef CDSUNIT_SET_TEST_INTRUSIVE_SET_NOGC_H diff --git a/test/unit/set/test_intrusive_set_rcu.h b/test/unit/set/test_intrusive_set_rcu.h index 416f3e94..ff28bef3 100644 --- a/test/unit/set/test_intrusive_set_rcu.h +++ b/test/unit/set/test_intrusive_set_rcu.h @@ -122,46 +122,53 @@ namespace cds_test { rcu_lock l; EXPECT_EQ( i.nFindCount, 0 ); rp = s.get( i ); - ASSERT_TRUE( rp ); + ASSERT_FALSE( !rp ); ++rp->nFindCount; EXPECT_EQ( i.nFindCount, 1 ); rp = s.get( i.key() ); - ASSERT_TRUE( rp ); + ASSERT_FALSE( !rp ); ++rp->nFindCount; EXPECT_EQ( i.nFindCount, 2 ); rp = s.get_with( other_item( i.key()), other_less()); - ASSERT_TRUE( rp ); + ASSERT_FALSE( !rp ); ++rp->nFindCount; EXPECT_EQ( i.nFindCount, 3 ); } if ( Set::c_bExtractLockExternal ) { - rcu_lock l; + { + rcu_lock l; + + EXPECT_EQ( i.nEraseCount, 0 ); + switch ( i.key() % 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_FALSE( !xp ); + ++xp->nEraseCount; + } + EXPECT_EQ( i.nEraseCount, 1 ); + xp.release(); + + { + rcu_lock l; - EXPECT_EQ( i.nEraseCount, 0 ); - switch ( i.key() % 3 ) { - case 0: - xp = s.extract( i.key()); - break; - case 1: xp = s.extract( i ); - break; - case 2: + ASSERT_TRUE( !xp ); + xp = s.extract( i.key() ); + ASSERT_TRUE( !xp ); xp = s.extract_with( other_item( i.key() ), other_less() ); - break; + ASSERT_TRUE( !xp ); } - ASSERT_TRUE( xp ); - ++xp->nEraseCount; - EXPECT_EQ( i.nEraseCount, 1 ); - - xp = s.extract( i ); - ASSERT_TRUE( !xp ); - xp = s.extract( i.key() ); - ASSERT_TRUE( !xp ); - xp = s.extract_with( other_item( i.key() ), other_less() ); - ASSERT_TRUE( !xp ); } else { EXPECT_EQ( i.nEraseCount, 0 ); @@ -176,7 +183,7 @@ namespace cds_test { xp = s.extract_with( other_item( i.key() ), other_less() ); break; } - ASSERT_TRUE( xp ); + ASSERT_FALSE( !xp ); ++xp->nEraseCount; EXPECT_EQ( i.nEraseCount, 1 ); -- 2.34.1