From: khizmax Date: Mon, 28 Mar 2016 21:49:23 +0000 (+0300) Subject: Migrated MichaelMap unit test to gtest X-Git-Tag: v2.2.0~314 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=bb5bf5f69210ca40bdf9a24a4037949d6b923054;p=libcds.git Migrated MichaelMap unit test to gtest --- diff --git a/projects/Win/vc14/gtest-map.vcxproj b/projects/Win/vc14/gtest-map.vcxproj index 5f73f337..535d34ae 100644 --- a/projects/Win/vc14/gtest-map.vcxproj +++ b/projects/Win/vc14/gtest-map.vcxproj @@ -28,12 +28,48 @@ + + + + + + 4503 + 4503 + 4503 + 4503 + 4503 + 4503 + + + + + 4503 + 4503 + 4503 + 4503 + 4503 + 4503 + + + + 4503 + 4503 + 4503 + 4503 + 4503 + 4503 + + + + + + {42B7E892-DDDA-4D00-9AB7-378E0E7E9433} diff --git a/projects/Win/vc14/gtest-map.vcxproj.filters b/projects/Win/vc14/gtest-map.vcxproj.filters index 69cfb7d1..3d8dbfa0 100644 --- a/projects/Win/vc14/gtest-map.vcxproj.filters +++ b/projects/Win/vc14/gtest-map.vcxproj.filters @@ -27,6 +27,42 @@ Source Files\MichaelMap + + Source Files\MichaelMap + + + Source Files\MichaelMap + + + Source Files\MichaelMap + + + Source Files\MichaelMap + + + Source Files\MichaelMap + + + Source Files\MichaelMap + + + Source Files\MichaelMap + + + Source Files\MichaelMap + + + Source Files\MichaelMap + + + Source Files\MichaelMap + + + Source Files\MichaelMap + + + Source Files\MichaelMap + @@ -35,5 +71,14 @@ Header Files + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/test/unit/map/CMakeLists.txt b/test/unit/map/CMakeLists.txt index f62bf96f..c10feb1b 100644 --- a/test/unit/map/CMakeLists.txt +++ b/test/unit/map/CMakeLists.txt @@ -2,8 +2,20 @@ set(PACKAGE_NAME unit-map) set(CDSGTEST_MAP_SOURCES ../main.cpp + michael_lazy_hp.cpp + michael_lazy_dhp.cpp + michael_lazy_rcu_gpb.cpp + michael_lazy_rcu_gpi.cpp + michael_lazy_rcu_gpt.cpp + michael_lazy_rcu_shb.cpp + michael_lazy_rcu_sht.cpp michael_michael_hp.cpp michael_michael_dhp.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/map/michael_lazy_dhp.cpp b/test/unit/map/michael_lazy_dhp.cpp new file mode 100644 index 00000000..02b535e8 --- /dev/null +++ b/test/unit/map/michael_lazy_dhp.cpp @@ -0,0 +1,178 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "test_map_hp.h" + +#include +#include + +namespace { + + namespace cc = cds::container; + typedef cds::gc::DHP gc_type; + + class MichaelLazyMap_DHP: public cds_test::container_map_hp + { + protected: + typedef cds_test::container_map_hp base_class; + + void SetUp() + { + typedef cc::LazyKVList< gc_type, key_type, value_type > list_type; + typedef cc::MichaelHashMap< gc_type, list_type > map_type; + + cds::gc::dhp::GarbageCollector::Construct( 16, map_type::c_nHazardPtrCount ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::dhp::GarbageCollector::Destruct(); + } + }; + + TEST_F( MichaelLazyMap_DHP, compare ) + { + typedef cc::LazyKVList< gc_type, key_type, value_type, + typename cc::lazy_list::make_traits< + cds::opt::compare< cmp > + >::type + > list_type; + + typedef cc::MichaelHashMap< gc_type, list_type, + typename cc::michael_map::make_traits< + cds::opt::hash< hash1 > + >::type + > map_type; + + map_type m( kSize, 2 ); + test( m ); + } + + TEST_F( MichaelLazyMap_DHP, less ) + { + typedef cc::LazyKVList< gc_type, key_type, value_type, + typename cc::lazy_list::make_traits< + cds::opt::less< less > + >::type + > list_type; + + typedef cc::MichaelHashMap< gc_type, list_type, + typename cc::michael_map::make_traits< + cds::opt::hash< hash1 > + >::type + > map_type; + + map_type m( kSize, 1 ); + test( m ); + } + + TEST_F( MichaelLazyMap_DHP, cmpmix ) + { + typedef cc::LazyKVList< gc_type, key_type, value_type, + typename cc::lazy_list::make_traits< + cds::opt::less< less > + ,cds::opt::compare< cmp > + >::type + > list_type; + + typedef cc::MichaelHashMap< gc_type, list_type, + typename cc::michael_map::make_traits< + cds::opt::hash< hash1 > + >::type + > map_type; + + map_type m( kSize, 2 ); + test( m ); + } + + TEST_F( MichaelLazyMap_DHP, backoff ) + { + struct list_traits: public cc::lazy_list::traits + { + typedef cmp compare; + typedef cds::backoff::exponential back_off; + }; + typedef cc::LazyKVList< gc_type, key_type, value_type, list_traits > list_type; + + struct map_traits: public cc::michael_map::traits + { + typedef hash1 hash; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type; + + map_type m( kSize, 4 ); + test( m ); + } + + TEST_F( MichaelLazyMap_DHP, seq_cst ) + { + struct list_traits: public cc::lazy_list::traits + { + typedef cmp compare; + typedef cds::backoff::yield back_off; + typedef cds::opt::v::sequential_consistent memory_model; + }; + typedef cc::LazyKVList< gc_type, key_type, value_type, list_traits > list_type; + + struct map_traits: public cc::michael_map::traits + { + typedef hash1 hash; + }; + typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type; + + map_type m( kSize, 8 ); + test( m ); + } + + TEST_F( MichaelLazyMap_DHP, mutex ) + { + struct list_traits: public cc::lazy_list::traits + { + typedef cmp compare; + typedef cds::backoff::yield back_off; + typedef std::mutex lock_type; + }; + typedef cc::LazyKVList< gc_type, key_type, value_type, list_traits > list_type; + + struct map_traits: public cc::michael_map::traits + { + typedef hash1 hash; + }; + typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type; + + map_type m( kSize, 2 ); + test( m ); + } + +} // namespace + diff --git a/test/unit/map/michael_lazy_hp.cpp b/test/unit/map/michael_lazy_hp.cpp new file mode 100644 index 00000000..5376a2e8 --- /dev/null +++ b/test/unit/map/michael_lazy_hp.cpp @@ -0,0 +1,179 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "test_map_hp.h" + +#include +#include + +namespace { + + namespace cc = cds::container; + typedef cds::gc::HP gc_type; + + class MichaelLazyMap_HP: public cds_test::container_map_hp + { + protected: + typedef cds_test::container_map_hp base_class; + + void SetUp() + { + typedef cc::LazyKVList< gc_type, key_type, value_type > list_type; + typedef cc::MichaelHashMap< gc_type, list_type > map_type; + + // +1 - for guarded_ptr and iterator + cds::gc::hp::GarbageCollector::Construct( map_type::c_nHazardPtrCount + 1, 1, 16 ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::hp::GarbageCollector::Destruct( true ); + } + }; + + TEST_F( MichaelLazyMap_HP, compare ) + { + typedef cc::LazyKVList< gc_type, key_type, value_type, + typename cc::lazy_list::make_traits< + cds::opt::compare< cmp > + >::type + > list_type; + + typedef cc::MichaelHashMap< gc_type, list_type, + typename cc::michael_map::make_traits< + cds::opt::hash< hash1 > + >::type + > map_type; + + map_type m( kSize, 2 ); + test( m ); + } + + TEST_F( MichaelLazyMap_HP, less ) + { + typedef cc::LazyKVList< gc_type, key_type, value_type, + typename cc::lazy_list::make_traits< + cds::opt::less< less > + >::type + > list_type; + + typedef cc::MichaelHashMap< gc_type, list_type, + typename cc::michael_map::make_traits< + cds::opt::hash< hash1 > + >::type + > map_type; + + map_type m( kSize, 1 ); + test( m ); + } + + TEST_F( MichaelLazyMap_HP, cmpmix ) + { + typedef cc::LazyKVList< gc_type, key_type, value_type, + typename cc::lazy_list::make_traits< + cds::opt::less< less > + ,cds::opt::compare< cmp > + >::type + > list_type; + + typedef cc::MichaelHashMap< gc_type, list_type, + typename cc::michael_map::make_traits< + cds::opt::hash< hash1 > + >::type + > map_type; + + map_type m( kSize, 2 ); + test( m ); + } + + TEST_F( MichaelLazyMap_HP, backoff ) + { + struct list_traits: public cc::lazy_list::traits + { + typedef cmp compare; + typedef cds::backoff::exponential back_off; + }; + typedef cc::LazyKVList< gc_type, key_type, value_type, list_traits > list_type; + + struct map_traits: public cc::michael_map::traits + { + typedef hash1 hash; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type; + + map_type m( kSize, 4 ); + test( m ); + } + + TEST_F( MichaelLazyMap_HP, seq_cst ) + { + struct list_traits: public cc::lazy_list::traits + { + typedef cmp compare; + typedef cds::backoff::yield back_off; + typedef cds::opt::v::sequential_consistent memory_model; + }; + typedef cc::LazyKVList< gc_type, key_type, value_type, list_traits > list_type; + + struct map_traits: public cc::michael_map::traits + { + typedef hash1 hash; + }; + typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type; + + map_type m( kSize, 8 ); + test( m ); + } + + TEST_F( MichaelLazyMap_HP, mutex ) + { + struct list_traits: public cc::lazy_list::traits + { + typedef cmp compare; + typedef cds::backoff::yield back_off; + typedef std::mutex lock_type; + }; + typedef cc::LazyKVList< gc_type, key_type, value_type, list_traits > list_type; + + struct map_traits: public cc::michael_map::traits + { + typedef hash1 hash; + }; + typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type; + + map_type m( kSize, 2 ); + test( m ); + } + +} // namespace + diff --git a/test/unit/map/michael_lazy_rcu_gpb.cpp b/test/unit/map/michael_lazy_rcu_gpb.cpp new file mode 100644 index 00000000..fa22f17b --- /dev/null +++ b/test/unit/map/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_michael_lazy_rcu.h" + +namespace { + + typedef cds::urcu::general_buffered<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPB, MichaelLazyMap, rcu_implementation ); diff --git a/test/unit/map/michael_lazy_rcu_gpi.cpp b/test/unit/map/michael_lazy_rcu_gpi.cpp new file mode 100644 index 00000000..bebd11ab --- /dev/null +++ b/test/unit/map/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_michael_lazy_rcu.h" + +namespace { + + typedef cds::urcu::general_instant<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPI, MichaelLazyMap, rcu_implementation ); diff --git a/test/unit/map/michael_lazy_rcu_gpt.cpp b/test/unit/map/michael_lazy_rcu_gpt.cpp new file mode 100644 index 00000000..a9d41f56 --- /dev/null +++ b/test/unit/map/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_michael_lazy_rcu.h" + +namespace { + + typedef cds::urcu::general_threaded<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPT, MichaelLazyMap, rcu_implementation ); diff --git a/test/unit/map/michael_lazy_rcu_shb.cpp b/test/unit/map/michael_lazy_rcu_shb.cpp new file mode 100644 index 00000000..85430bb2 --- /dev/null +++ b/test/unit/map/michael_lazy_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_lazy_rcu.h" + +namespace { + + typedef cds::urcu::signal_buffered<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_SHB, MichaelLazyMap, rcu_implementation ); + +#endif // CDS_URCU_SIGNAL_HANDLING_ENABLED diff --git a/test/unit/map/michael_lazy_rcu_sht.cpp b/test/unit/map/michael_lazy_rcu_sht.cpp new file mode 100644 index 00000000..546e57be --- /dev/null +++ b/test/unit/map/michael_lazy_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_lazy_rcu.h" + +namespace { + + typedef cds::urcu::signal_threaded<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_SHT, MichaelLazyMap, rcu_implementation ); + +#endif // CDS_URCU_SIGNAL_HANDLING_ENABLED diff --git a/test/unit/map/michael_michael_rcu_gpb.cpp b/test/unit/map/michael_michael_rcu_gpb.cpp new file mode 100644 index 00000000..39e68a1c --- /dev/null +++ b/test/unit/map/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, MichaelMap, rcu_implementation ); diff --git a/test/unit/map/michael_michael_rcu_gpi.cpp b/test/unit/map/michael_michael_rcu_gpi.cpp new file mode 100644 index 00000000..c5ad3f65 --- /dev/null +++ b/test/unit/map/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, MichaelMap, rcu_implementation ); diff --git a/test/unit/map/michael_michael_rcu_gpt.cpp b/test/unit/map/michael_michael_rcu_gpt.cpp new file mode 100644 index 00000000..95896fa6 --- /dev/null +++ b/test/unit/map/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, MichaelMap, rcu_implementation ); diff --git a/test/unit/map/michael_michael_rcu_shb.cpp b/test/unit/map/michael_michael_rcu_shb.cpp new file mode 100644 index 00000000..fb5c32a8 --- /dev/null +++ b/test/unit/map/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, MichaelMap, rcu_implementation ); + +#endif // CDS_URCU_SIGNAL_HANDLING_ENABLED diff --git a/test/unit/map/michael_michael_rcu_sht.cpp b/test/unit/map/michael_michael_rcu_sht.cpp new file mode 100644 index 00000000..b998848c --- /dev/null +++ b/test/unit/map/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, MichaelMap, rcu_implementation ); + +#endif // CDS_URCU_SIGNAL_HANDLING_ENABLED diff --git a/test/unit/map/test_map.h b/test/unit/map/test_map.h index 3253705f..43bd2bdf 100644 --- a/test/unit/map/test_map.h +++ b/test/unit/map/test_map.h @@ -237,15 +237,16 @@ namespace cds_test { ASSERT_TRUE( m.empty()); ASSERT_CONTAINER_SIZE( m, 0 ); - typedef Map::value_type map_pair; + typedef typename Map::value_type map_pair; + size_t const kkSize = kSize; std::vector arrKeys; - for ( int i = 0; i < static_cast(kSize); ++i ) + for ( int i = 0; i < static_cast(kkSize); ++i ) arrKeys.push_back( key_type( i )); shuffle( arrKeys.begin(), arrKeys.end()); std::vector< value_type > arrVals; - for ( size_t i = 0; i < kSize; ++i ) { + for ( size_t i = 0; i < kkSize; ++i ) { value_type val; val.nVal = static_cast( i ); val.strVal = std::to_string( i ); @@ -452,7 +453,7 @@ namespace cds_test { } )); } ASSERT_FALSE( m.empty() ); - ASSERT_CONTAINER_SIZE( m, kSize ); + ASSERT_CONTAINER_SIZE( m, kkSize ); ASSERT_FALSE( m.begin() == m.end() ); ASSERT_FALSE( m.cbegin() == m.cend() ); @@ -560,7 +561,7 @@ namespace cds_test { ASSERT_TRUE( m.insert( i )); ASSERT_FALSE( m.empty() ); - ASSERT_CONTAINER_SIZE( m, kSize ); + ASSERT_CONTAINER_SIZE( m, kkSize ); m.clear(); diff --git a/test/unit/map/test_map_hp.h b/test/unit/map/test_map_hp.h index 7b4bd05e..22095115 100644 --- a/test/unit/map/test_map_hp.h +++ b/test/unit/map/test_map_hp.h @@ -51,15 +51,16 @@ namespace cds_test { ASSERT_TRUE( m.empty()); ASSERT_CONTAINER_SIZE( m, 0 ); - typedef Map::value_type map_pair; + typedef typename Map::value_type map_pair; + size_t const kkSize = base_class::kSize; std::vector arrKeys; - for ( int i = 0; i < static_cast(kSize); ++i ) + for ( int i = 0; i < static_cast(kkSize); ++i ) arrKeys.push_back( key_type( i )); shuffle( arrKeys.begin(), arrKeys.end()); std::vector< value_type > arrVals; - for ( size_t i = 0; i < kSize; ++i ) { + for ( size_t i = 0; i < kkSize; ++i ) { value_type val; val.nVal = static_cast( i ); val.strVal = std::to_string( i ); @@ -69,23 +70,23 @@ namespace cds_test { for ( auto const& i : arrKeys ) ASSERT_TRUE( m.insert( i ) ); ASSERT_FALSE( m.empty() ); - ASSERT_CONTAINER_SIZE( m, kSize ); + ASSERT_CONTAINER_SIZE( m, kkSize ); // iterators size_t nCount = 0; for ( auto it = m.begin(); it != m.end(); ++it ) { EXPECT_EQ( it->second.nVal, 0 ); - it->second.nVal = it->first.nKey; + it->second.nVal = it->first.nKey * 2; ++nCount; } - EXPECT_EQ( nCount, kSize ); + EXPECT_EQ( nCount, kkSize ); nCount = 0; for ( auto it = m.cbegin(); it != m.cend(); ++it ) { - EXPECT_EQ( it->second.nVal, it->first.nKey ); + EXPECT_EQ( it->second.nVal, it->first.nKey * 2 ); ++nCount; } - EXPECT_EQ( nCount, kSize ); + EXPECT_EQ( nCount, kkSize ); // get/extract typedef typename Map::guarded_ptr guarded_ptr; diff --git a/test/unit/map/test_map_rcu.h b/test/unit/map/test_map_rcu.h new file mode 100644 index 00000000..f05bac5f --- /dev/null +++ b/test/unit/map/test_map_rcu.h @@ -0,0 +1,224 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef CDSUNIT_MAP_TEST_MAP_RCU_H +#define CDSUNIT_MAP_TEST_MAP_RCU_H + +#include "test_map.h" + +namespace cds_test { + + class container_map_rcu: public container_map + { + typedef container_map base_class; + + protected: + template + void test( Map& m ) + { + // Precondition: map is empty + // Postcondition: map is empty + + base_class::test( m ); + + ASSERT_TRUE( m.empty()); + ASSERT_CONTAINER_SIZE( m, 0 ); + + typedef typename Map::value_type map_pair; + size_t const kkSize = base_class::kSize; + + std::vector arrKeys; + for ( int i = 0; i < static_cast(kkSize); ++i ) + arrKeys.push_back( key_type( i )); + shuffle( arrKeys.begin(), arrKeys.end()); + + std::vector< value_type > arrVals; + for ( size_t i = 0; i < kkSize; ++i ) { + value_type val; + val.nVal = static_cast( i ); + val.strVal = std::to_string( i ); + arrVals.push_back( val ); + } + + for ( auto const& i : arrKeys ) + ASSERT_TRUE( m.insert( i ) ); + ASSERT_FALSE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, kkSize ); + + // iterators + size_t nCount = 0; + for ( auto it = m.begin(); it != m.end(); ++it ) { + EXPECT_EQ( it->second.nVal, 0 ); + it->second.nVal = it->first.nKey * 2; + ++nCount; + } + EXPECT_EQ( nCount, kkSize ); + + nCount = 0; + for ( auto it = m.cbegin(); it != m.cend(); ++it ) { + EXPECT_EQ( it->second.nVal, it->first.nKey * 2 ); + ++nCount; + } + EXPECT_EQ( nCount, kkSize ); + + typedef typename Map::exempt_ptr exempt_ptr; + typedef typename Map::raw_ptr raw_ptr; + typedef typename Map::rcu_lock rcu_lock; + + // get/extract + shuffle( arrKeys.begin(), arrKeys.end() ); + + for ( auto const& i : arrKeys ) { + value_type const& val = arrVals.at( i.nKey ); + + { + rcu_lock l; + raw_ptr rp; + + rp = m.get( i.nKey ); + ASSERT_FALSE( !rp ); + EXPECT_EQ( rp->first.nKey, i.nKey ); + rp->second.nVal = rp->first.nKey * 2; + + rp = m.get( i ); + ASSERT_FALSE( !rp ); + EXPECT_EQ( rp->first.nKey, i.nKey ); + EXPECT_EQ( rp->second.nVal, rp->first.nKey * 2 ); + rp->second.nVal = rp->first.nKey * 3; + + rp = m.get_with( other_item( i.nKey ), other_less()); + ASSERT_FALSE( !rp ); + EXPECT_EQ( rp->first.nKey, i.nKey ); + EXPECT_EQ( rp->second.nVal, rp->first.nKey * 3 ); + rp->second.nVal = rp->first.nKey; + } + + exempt_ptr xp; + if ( Map::c_bExtractLockExternal ) { + { + rcu_lock l; + + switch ( i.nKey % 4 ) { + case 0: + xp = m.extract( i.nKey ); + break; + case 1: + xp = m.extract( i ); + break; + case 2: + xp = m.extract( val.strVal ); + break; + case 3: + xp = m.extract_with( other_item( i.nKey ), other_less() ); + break; + } + ASSERT_FALSE( !xp ); + EXPECT_EQ( xp->first.nKey, i.nKey ); + EXPECT_EQ( xp->second.nVal, xp->first.nKey ); + } + xp.release(); + + { + rcu_lock l; + + switch ( i.nKey % 4 ) { + case 0: + xp = m.extract( i.nKey ); + break; + case 1: + xp = m.extract( i ); + break; + case 2: + xp = m.extract( val.strVal ); + break; + case 3: + xp = m.extract_with( other_item( i.nKey ), other_less() ); + break; + } + EXPECT_TRUE( !xp ); + } + } + else { + switch ( i.nKey % 4 ) { + case 0: + xp = m.extract( i.nKey ); + break; + case 1: + xp = m.extract( i ); + break; + case 2: + xp = m.extract( val.strVal ); + break; + case 3: + xp = m.extract_with( other_item( i.nKey ), other_less()); + break; + } + ASSERT_FALSE( !xp ); + EXPECT_EQ( xp->first.nKey, i.nKey ); + EXPECT_EQ( xp->second.nVal, xp->first.nKey ); + + switch ( i.nKey % 4 ) { + case 0: + xp = m.extract( i.nKey ); + break; + case 1: + xp = m.extract( i ); + break; + case 2: + xp = m.extract( val.strVal ); + break; + case 3: + xp = m.extract_with( other_item( i.nKey ), other_less() ); + break; + } + EXPECT_TRUE( !xp ); + } + + { + rcu_lock l; + raw_ptr rp; + + rp = m.get( i.nKey ); + ASSERT_TRUE( !rp ); + rp = m.get( i ); + ASSERT_TRUE( !rp ); + rp = m.get_with( other_item( i.nKey ), other_less() ); + ASSERT_TRUE( !rp ); + } + } + + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + } + }; + +} // namespace cds_test + +#endif // #ifndef CDSUNIT_MAP_TEST_MAP_H diff --git a/test/unit/map/test_michael_lazy_rcu.h b/test/unit/map/test_michael_lazy_rcu.h new file mode 100644 index 00000000..db97971f --- /dev/null +++ b/test/unit/map/test_michael_lazy_rcu.h @@ -0,0 +1,213 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef CDSUNIT_MAP_TEST_MICHAEL_LAZY_RCU_H +#define CDSUNIT_MAP_TEST_MICHAEL_LAZY_RCU_H + +#include "test_map_rcu.h" +#include +#include + +namespace { + namespace cc = cds::container; + + template + class MichaelLazyMap: public cds_test::container_map_rcu + { + typedef cds_test::container_map_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( MichaelLazyMap ); + + TYPED_TEST_P( MichaelLazyMap, compare ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + typedef cc::LazyKVList< rcu_type, key_type, value_type, + typename cc::lazy_list::make_traits< + cds::opt::compare< typename TestFixture::cmp > + >::type + > list_type; + + typedef cc::MichaelHashMap< rcu_type, list_type, + typename cc::michael_map::make_traits< + cds::opt::hash< typename TestFixture::hash1 > + >::type + > map_type; + + map_type m( TestFixture::kSize, 2 ); + this->test( m ); + } + + TYPED_TEST_P( MichaelLazyMap, less ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + typedef cc::LazyKVList< rcu_type, key_type, value_type, + typename cc::lazy_list::make_traits< + cds::opt::less< typename TestFixture::less > + >::type + > list_type; + + typedef cc::MichaelHashMap< rcu_type, list_type, + typename cc::michael_map::make_traits< + cds::opt::hash< typename TestFixture::hash1 > + >::type + > map_type; + + map_type m( TestFixture::kSize, 2 ); + this->test( m ); + } + + TYPED_TEST_P( MichaelLazyMap, cmpmix ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + struct list_traits : public cc::lazy_list::traits + { + typedef typename TestFixture::less less; + typedef typename TestFixture::cmp compare; + }; + typedef cc::LazyKVList< rcu_type, key_type, value_type, list_traits > list_type; + + typedef cc::MichaelHashMap< rcu_type, list_type, + typename cc::michael_map::make_traits< + cds::opt::hash< typename TestFixture::hash1 > + >::type + > map_type; + + map_type m( TestFixture::kSize, 2 ); + this->test( m ); + } + + TYPED_TEST_P( MichaelLazyMap, backoff ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + struct list_traits : public cc::lazy_list::traits + { + typedef typename TestFixture::cmp compare; + typedef cds::backoff::exponential back_off; + }; + typedef cc::LazyKVList< rcu_type, key_type, value_type, list_traits > list_type; + + struct set_traits : public cc::michael_map::traits + { + typedef typename TestFixture::hash1 hash; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::MichaelHashMap< rcu_type, list_type, set_traits >map_type; + + map_type m( TestFixture::kSize, 4 ); + this->test( m ); + } + + TYPED_TEST_P( MichaelLazyMap, seq_cst ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + struct list_traits : public cc::lazy_list::traits + { + typedef typename TestFixture::less less; + typedef cds::backoff::pause back_off; + typedef cds::opt::v::sequential_consistent memory_model; + }; + typedef cc::LazyKVList< rcu_type, key_type, value_type, list_traits > list_type; + + struct set_traits : public cc::michael_map::traits + { + typedef typename TestFixture::hash1 hash; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::MichaelHashMap< rcu_type, list_type, set_traits >map_type; + + map_type m( TestFixture::kSize, 4 ); + this->test( m ); + } + + TYPED_TEST_P( MichaelLazyMap, mutex ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + struct list_traits : public cc::lazy_list::traits + { + typedef typename TestFixture::less less; + typedef cds::backoff::pause back_off; + typedef std::mutex lock_type; + }; + typedef cc::LazyKVList< rcu_type, key_type, value_type, list_traits > list_type; + + struct set_traits : public cc::michael_map::traits + { + typedef typename TestFixture::hash1 hash; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::MichaelHashMap< rcu_type, list_type, set_traits >map_type; + + map_type m( TestFixture::kSize, 4 ); + this->test( m ); + } + + + // 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( MichaelLazyMap, + compare, less, cmpmix, backoff, seq_cst, mutex + ); +} // namespace + +#endif // CDSUNIT_MAP_TEST_MICHAEL_LAZY_RCU_H + \ No newline at end of file diff --git a/test/unit/map/test_michael_michael_rcu.h b/test/unit/map/test_michael_michael_rcu.h new file mode 100644 index 00000000..dc66ad82 --- /dev/null +++ b/test/unit/map/test_michael_michael_rcu.h @@ -0,0 +1,186 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef CDSUNIT_MAP_TEST_MICHAEL_MICHAEL_RCU_H +#define CDSUNIT_MAP_TEST_MICHAEL_MICHAEL_RCU_H + +#include "test_map_rcu.h" +#include +#include + +namespace { + namespace cc = cds::container; + + template + class MichaelMap: public cds_test::container_map_rcu + { + typedef cds_test::container_map_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( MichaelMap ); + + TYPED_TEST_P( MichaelMap, compare ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + typedef cc::MichaelKVList< rcu_type, key_type, value_type, + typename cc::michael_list::make_traits< + cds::opt::compare< typename TestFixture::cmp > + >::type + > list_type; + + typedef cc::MichaelHashMap< rcu_type, list_type, + typename cc::michael_map::make_traits< + cds::opt::hash< typename TestFixture::hash1 > + >::type + > map_type; + + map_type m( TestFixture::kSize, 2 ); + this->test( m ); + } + + TYPED_TEST_P( MichaelMap, less ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + typedef cc::MichaelKVList< rcu_type, key_type, value_type, + typename cc::michael_list::make_traits< + cds::opt::less< typename TestFixture::less > + >::type + > list_type; + + typedef cc::MichaelHashMap< rcu_type, list_type, + typename cc::michael_map::make_traits< + cds::opt::hash< typename TestFixture::hash1 > + >::type + > map_type; + + map_type m( TestFixture::kSize, 2 ); + this->test( m ); + } + + TYPED_TEST_P( MichaelMap, cmpmix ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + struct list_traits : public cc::michael_list::traits + { + typedef typename TestFixture::less less; + typedef typename TestFixture::cmp compare; + }; + typedef cc::MichaelKVList< rcu_type, key_type, value_type, list_traits > list_type; + + typedef cc::MichaelHashMap< rcu_type, list_type, + typename cc::michael_map::make_traits< + cds::opt::hash< typename TestFixture::hash1 > + >::type + > map_type; + + map_type m( TestFixture::kSize, 2 ); + this->test( m ); + } + + TYPED_TEST_P( MichaelMap, backoff ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + struct list_traits : public cc::michael_list::traits + { + typedef typename TestFixture::cmp compare; + typedef cds::backoff::exponential back_off; + }; + typedef cc::MichaelKVList< rcu_type, key_type, value_type, list_traits > list_type; + + struct map_traits : public cc::michael_map::traits + { + typedef typename TestFixture::hash1 hash; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::MichaelHashMap< rcu_type, list_type, map_traits >map_type; + + map_type m( TestFixture::kSize, 4 ); + this->test( m ); + } + + TYPED_TEST_P( MichaelMap, seq_cst ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + 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::MichaelKVList< rcu_type, key_type, value_type, list_traits > list_type; + + struct map_traits : public cc::michael_map::traits + { + typedef typename TestFixture::hash1 hash; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cc::MichaelHashMap< rcu_type, list_type, map_traits >map_type; + + map_type m( TestFixture::kSize, 4 ); + this->test( m ); + } + + + REGISTER_TYPED_TEST_CASE_P( MichaelMap, + compare, less, cmpmix, backoff, seq_cst + ); +} + +#endif // CDSUNIT_MAP_TEST_MICHAEL_MICHAEL_RCU_H + \ No newline at end of file