From: khizmax Date: Sat, 16 Apr 2016 15:58:09 +0000 (+0300) Subject: Migrated EllenBinTreeMap unit test to gtest framework X-Git-Tag: v2.2.0~274 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=feddb1211ac87d4cb587f2550d3d04cf5592a868;p=libcds.git Migrated EllenBinTreeMap unit test to gtest framework --- diff --git a/projects/Win/vc14/gtest-tree.vcxproj b/projects/Win/vc14/gtest-tree.vcxproj index 72712306..26d458ba 100644 --- a/projects/Win/vc14/gtest-tree.vcxproj +++ b/projects/Win/vc14/gtest-tree.vcxproj @@ -28,8 +28,36 @@ - - + + + + 4503 + 4503 + 4503 + 4503 + 4503 + 4503 + + + 4503 + 4503 + 4503 + 4503 + 4503 + 4503 + + + 4503 + 4503 + 4503 + 4503 + 4503 + 4503 + + + + + 4503 4503 @@ -87,12 +115,17 @@ + + + + + diff --git a/projects/Win/vc14/gtest-tree.vcxproj.filters b/projects/Win/vc14/gtest-tree.vcxproj.filters index ebec5344..04681082 100644 --- a/projects/Win/vc14/gtest-tree.vcxproj.filters +++ b/projects/Win/vc14/gtest-tree.vcxproj.filters @@ -19,6 +19,9 @@ {9fc83943-2620-4528-a704-d3765f52522b} + + {5e8e3c4d-563e-41fd-91ed-52f61f4b7d24} + @@ -42,18 +45,12 @@ Source Files\intrusive.EllenBinTree - - Source Files\EllenBinTreeSet - Source Files Source Files - - Source Files\EllenBinTreeSet - Source Files\EllenBinTreeSet @@ -69,6 +66,33 @@ Source Files\EllenBinTreeSet + + Source Files\EllenBinTreeSet + + + Source Files\EllenBinTreeSet + + + Source Files\EllenBinTreeMap + + + Source Files\EllenBinTreeMap + + + Source Files\EllenBinTreeMap + + + Source Files\EllenBinTreeMap + + + Source Files\EllenBinTreeMap + + + Source Files\EllenBinTreeMap + + + Source Files\EllenBinTreeMap + @@ -98,5 +122,20 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/test/unit/tree/CMakeLists.txt b/test/unit/tree/CMakeLists.txt index 2406a48b..c1c066d9 100644 --- a/test/unit/tree/CMakeLists.txt +++ b/test/unit/tree/CMakeLists.txt @@ -5,8 +5,15 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof") set(CDSGTEST_TREE_SOURCES ../main.cpp ellen_bintree_update_desc_pool.cpp - ellenbintree_set_dhp.cpp - ellenbintree_set_hp.cpp + ellen_bintree_map_hp.cpp + ellen_bintree_map_dhp.cpp + ellen_bintree_map_rcu_gpb.cpp + ellen_bintree_map_rcu_gpi.cpp + ellen_bintree_map_rcu_gpt.cpp + ellen_bintree_map_rcu_shb.cpp + ellen_bintree_map_rcu_sht.cpp + ellen_bintree_set_dhp.cpp + ellen_bintree_set_hp.cpp ellen_bintree_set_rcu_gpb.cpp ellen_bintree_set_rcu_gpi.cpp ellen_bintree_set_rcu_gpt.cpp diff --git a/test/unit/tree/ellen_bintree_map_dhp.cpp b/test/unit/tree/ellen_bintree_map_dhp.cpp new file mode 100644 index 00000000..5f717cb9 --- /dev/null +++ b/test/unit/tree/ellen_bintree_map_dhp.cpp @@ -0,0 +1,202 @@ +/* + 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_tree_map_hp.h" + +#include +#include "test_ellen_bintree_update_desc_pool.h" + +namespace { + namespace cc = cds::container; + typedef cds::gc::DHP gc_type; + + class EllenBinTreeMap_DHP : public cds_test::container_tree_map_hp + { + protected: + typedef cds_test::container_tree_map_hp base_class; + + void SetUp() + { + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type > map_type; + + cds::gc::dhp::GarbageCollector::Construct( 16, map_type::c_nHazardPtrCount ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::dhp::GarbageCollector::Destruct(); + } + }; + + + TEST_F( EllenBinTreeMap_DHP, compare ) + { + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, + typename cc::ellen_bintree::make_map_traits< + cds::opt::compare< cmp > + >::type + > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_DHP, less ) + { + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, + typename cc::ellen_bintree::make_map_traits< + cds::opt::less< base_class::less > + >::type + > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_DHP, cmpmix ) + { + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, + typename cc::ellen_bintree::make_map_traits< + cds::opt::less< base_class::less > + ,cds::opt::compare< cmp > + >::type + > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_DHP, update_desc_pool ) + { + struct map_traits: public cc::ellen_bintree::traits + { + typedef cmp compare; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_DHP, update_desc_lazy_pool ) + { + struct map_traits: public cc::ellen_bintree::traits + { + typedef cmp compare; + typedef cds::memory::pool_allocator< cds_test::update_desc, cds_test::lazy_pool_accessor> update_desc_allocator; + }; + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_DHP, item_counting ) + { + struct map_traits: public cc::ellen_bintree::traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_DHP, backoff ) + { + struct map_traits: public cc::ellen_bintree::traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_DHP, stat ) + { + struct map_traits: public cc::ellen_bintree::traits + { + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cc::ellen_bintree::stat<> stat; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_DHP, copy_policy ) + { + struct map_traits: public cc::ellen_bintree::traits + { + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::memory::pool_allocator update_desc_allocator; + typedef copy_key copy_policy; + }; + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_DHP, seq_cst ) + { + struct map_traits: public cc::ellen_bintree::traits + { + typedef cmp compare; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cds::memory::pool_allocator update_desc_allocator; + typedef cds::opt::v::sequential_consistent memory_model; + }; + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + +} // namespace diff --git a/test/unit/tree/ellen_bintree_map_hp.cpp b/test/unit/tree/ellen_bintree_map_hp.cpp new file mode 100644 index 00000000..07e0b5e9 --- /dev/null +++ b/test/unit/tree/ellen_bintree_map_hp.cpp @@ -0,0 +1,203 @@ +/* + 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_tree_map_hp.h" + +#include +#include "test_ellen_bintree_update_desc_pool.h" + +namespace { + namespace cc = cds::container; + typedef cds::gc::HP gc_type; + + class EllenBinTreeMap_HP : public cds_test::container_tree_map_hp + { + protected: + typedef cds_test::container_tree_map_hp base_class; + + void SetUp() + { + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type > map_type; + + // +1 - for guarded_ptr + cds::gc::hp::GarbageCollector::Construct( map_type::c_nHazardPtrCount + 1, 1, 16 ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::hp::GarbageCollector::Destruct( true ); + } + }; + + + TEST_F( EllenBinTreeMap_HP, compare ) + { + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, + typename cc::ellen_bintree::make_map_traits< + cds::opt::compare< cmp > + >::type + > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_HP, less ) + { + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, + typename cc::ellen_bintree::make_map_traits< + cds::opt::less< base_class::less > + >::type + > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_HP, cmpmix ) + { + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, + typename cc::ellen_bintree::make_map_traits< + cds::opt::less< base_class::less > + ,cds::opt::compare< cmp > + >::type + > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_HP, update_desc_pool ) + { + struct map_traits: public cc::ellen_bintree::traits + { + typedef cmp compare; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_HP, update_desc_lazy_pool ) + { + struct map_traits: public cc::ellen_bintree::traits + { + typedef cmp compare; + typedef cds::memory::pool_allocator< cds_test::update_desc, cds_test::lazy_pool_accessor> update_desc_allocator; + }; + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_HP, item_counting ) + { + struct map_traits: public cc::ellen_bintree::traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_HP, backoff ) + { + struct map_traits: public cc::ellen_bintree::traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_HP, stat ) + { + struct map_traits: public cc::ellen_bintree::traits + { + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cc::ellen_bintree::stat<> stat; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_HP, copy_policy ) + { + struct map_traits: public cc::ellen_bintree::traits + { + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::memory::pool_allocator update_desc_allocator; + typedef copy_key copy_policy; + }; + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + + TEST_F( EllenBinTreeMap_HP, seq_cst ) + { + struct map_traits: public cc::ellen_bintree::traits + { + typedef cmp compare; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cds::memory::pool_allocator update_desc_allocator; + typedef cds::opt::v::sequential_consistent memory_model; + }; + typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, map_traits > map_type; + + map_type m; + test( m ); + } + +} // namespace diff --git a/test/unit/tree/ellen_bintree_map_rcu_gpb.cpp b/test/unit/tree/ellen_bintree_map_rcu_gpb.cpp new file mode 100644 index 00000000..d844cad2 --- /dev/null +++ b/test/unit/tree/ellen_bintree_map_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_ellen_bintree_map_rcu.h" + +namespace { + + typedef cds::urcu::general_buffered<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPB, EllenBinTreeMap, rcu_implementation ); diff --git a/test/unit/tree/ellen_bintree_map_rcu_gpi.cpp b/test/unit/tree/ellen_bintree_map_rcu_gpi.cpp new file mode 100644 index 00000000..077f98fa --- /dev/null +++ b/test/unit/tree/ellen_bintree_map_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_ellen_bintree_map_rcu.h" + +namespace { + + typedef cds::urcu::general_instant<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPI, EllenBinTreeMap, rcu_implementation ); diff --git a/test/unit/tree/ellen_bintree_map_rcu_gpt.cpp b/test/unit/tree/ellen_bintree_map_rcu_gpt.cpp new file mode 100644 index 00000000..fc9b9a11 --- /dev/null +++ b/test/unit/tree/ellen_bintree_map_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_ellen_bintree_map_rcu.h" + +namespace { + + typedef cds::urcu::general_threaded<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_GPT, EllenBinTreeMap, rcu_implementation ); diff --git a/test/unit/tree/ellen_bintree_map_rcu_shb.cpp b/test/unit/tree/ellen_bintree_map_rcu_shb.cpp new file mode 100644 index 00000000..3466a1ca --- /dev/null +++ b/test/unit/tree/ellen_bintree_map_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_ellen_bintree_map_rcu.h" + +namespace { + + typedef cds::urcu::signal_buffered<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_SHB, EllenBinTreeMap, rcu_implementation ); + +#endif // CDS_URCU_SIGNAL_HANDLING_ENABLED diff --git a/test/unit/tree/ellen_bintree_map_rcu_sht.cpp b/test/unit/tree/ellen_bintree_map_rcu_sht.cpp new file mode 100644 index 00000000..c284c27e --- /dev/null +++ b/test/unit/tree/ellen_bintree_map_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_ellen_bintree_map_rcu.h" + +namespace { + + typedef cds::urcu::signal_threaded<> rcu_implementation; + +} // namespace + +INSTANTIATE_TYPED_TEST_CASE_P( RCU_SHT, EllenBinTreeMap, rcu_implementation ); + +#endif // CDS_URCU_SIGNAL_HANDLING_ENABLED diff --git a/test/unit/tree/ellen_bintree_set_dhp.cpp b/test/unit/tree/ellen_bintree_set_dhp.cpp new file mode 100644 index 00000000..1e7dc06a --- /dev/null +++ b/test/unit/tree/ellen_bintree_set_dhp.cpp @@ -0,0 +1,180 @@ +/* + 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_tree_set_hp.h" + +#include +#include "test_ellen_bintree_update_desc_pool.h" + +namespace { + namespace cc = cds::container; + typedef cds::gc::DHP gc_type; + + class EllenBinTreeSet_DHP : public cds_test::container_tree_set_hp + { + protected: + typedef cds_test::container_tree_set_hp base_class; + typedef int key_type; + + struct generic_traits: public cc::ellen_bintree::traits + { + typedef base_class::key_extractor key_extractor; + }; + + void SetUp() + { + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item > set_type; + + cds::gc::dhp::GarbageCollector::Construct( 16, set_type::c_nHazardPtrCount ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::hp::GarbageCollector::Destruct(); + } + }; + + + TEST_F( EllenBinTreeSet_DHP, compare ) + { + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, + typename cc::ellen_bintree::make_set_traits< + cc::opt::type_traits< generic_traits > + ,cds::opt::compare< cmp > + >::type + > set_type; + + set_type s; + test( s ); + } + + TEST_F( EllenBinTreeSet_DHP, less ) + { + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, + typename cc::ellen_bintree::make_set_traits< + cc::opt::type_traits< generic_traits > + ,cds::opt::less< base_class::less > + >::type + > set_type; + + set_type s; + test( s ); + } + + TEST_F( EllenBinTreeSet_DHP, cmpmix ) + { + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, + typename cc::ellen_bintree::make_set_traits< + cc::opt::type_traits< generic_traits > + ,cds::opt::less< base_class::less > + ,cds::opt::compare< cmp > + >::type + > set_type; + + set_type s; + test( s ); + } + + TEST_F( EllenBinTreeSet_DHP, update_desc_pool ) + { + struct set_traits: public generic_traits + { + typedef cmp compare; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; + + set_type s; + test( s ); + } + + TEST_F( EllenBinTreeSet_DHP, update_desc_lazy_pool ) + { + struct set_traits: public generic_traits + { + typedef cmp compare; + typedef cds::memory::pool_allocator< cds_test::update_desc, cds_test::lazy_pool_accessor> update_desc_allocator; + }; + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; + + set_type s; + test( s ); + } + + TEST_F( EllenBinTreeSet_DHP, item_counting ) + { + struct set_traits: public generic_traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; + + set_type s; + test( s ); + } + + TEST_F( EllenBinTreeSet_DHP, backoff ) + { + struct set_traits: public generic_traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; + + set_type s; + test( s ); + } + + TEST_F( EllenBinTreeSet_DHP, stat ) + { + struct set_traits: public generic_traits + { + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cc::ellen_bintree::stat<> stat; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; + + set_type s; + test( s ); + } + +} // namespace diff --git a/test/unit/tree/ellen_bintree_set_hp.cpp b/test/unit/tree/ellen_bintree_set_hp.cpp new file mode 100644 index 00000000..1152288b --- /dev/null +++ b/test/unit/tree/ellen_bintree_set_hp.cpp @@ -0,0 +1,181 @@ +/* + 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_tree_set_hp.h" + +#include +#include "test_ellen_bintree_update_desc_pool.h" + +namespace { + namespace cc = cds::container; + typedef cds::gc::HP gc_type; + + class EllenBinTreeSet_HP : public cds_test::container_tree_set_hp + { + protected: + typedef cds_test::container_tree_set_hp base_class; + typedef int key_type; + + struct generic_traits: public cc::ellen_bintree::traits + { + typedef base_class::key_extractor key_extractor; + }; + + void SetUp() + { + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item > set_type; + + // +1 - for guarded_ptr + cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::hp::GarbageCollector::Destruct( true ); + } + }; + + + TEST_F( EllenBinTreeSet_HP, compare ) + { + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, + typename cc::ellen_bintree::make_set_traits< + cc::opt::type_traits< generic_traits > + ,cds::opt::compare< cmp > + >::type + > set_type; + + set_type s; + test( s ); + } + + TEST_F( EllenBinTreeSet_HP, less ) + { + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, + typename cc::ellen_bintree::make_set_traits< + cc::opt::type_traits< generic_traits > + ,cds::opt::less< base_class::less > + >::type + > set_type; + + set_type s; + test( s ); + } + + TEST_F( EllenBinTreeSet_HP, cmpmix ) + { + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, + typename cc::ellen_bintree::make_set_traits< + cc::opt::type_traits< generic_traits > + ,cds::opt::less< base_class::less > + ,cds::opt::compare< cmp > + >::type + > set_type; + + set_type s; + test( s ); + } + + TEST_F( EllenBinTreeSet_HP, update_desc_pool ) + { + struct set_traits: public generic_traits + { + typedef cmp compare; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; + + set_type s; + test( s ); + } + + TEST_F( EllenBinTreeSet_HP, update_desc_lazy_pool ) + { + struct set_traits: public generic_traits + { + typedef cmp compare; + typedef cds::memory::pool_allocator< cds_test::update_desc, cds_test::lazy_pool_accessor> update_desc_allocator; + }; + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; + + set_type s; + test( s ); + } + + TEST_F( EllenBinTreeSet_HP, item_counting ) + { + struct set_traits: public generic_traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; + + set_type s; + test( s ); + } + + TEST_F( EllenBinTreeSet_HP, backoff ) + { + struct set_traits: public generic_traits + { + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; + + set_type s; + test( s ); + } + + TEST_F( EllenBinTreeSet_HP, stat ) + { + struct set_traits: public generic_traits + { + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cc::ellen_bintree::stat<> stat; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; + + set_type s; + test( s ); + } + +} // namespace diff --git a/test/unit/tree/ellenbintree_set_dhp.cpp b/test/unit/tree/ellenbintree_set_dhp.cpp deleted file mode 100644 index 1e7dc06a..00000000 --- a/test/unit/tree/ellenbintree_set_dhp.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/* - This file is a part of libcds - Concurrent Data Structures library - - (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 - - Source code repo: http://github.com/khizmax/libcds/ - Download: http://sourceforge.net/projects/libcds/files/ - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include "test_tree_set_hp.h" - -#include -#include "test_ellen_bintree_update_desc_pool.h" - -namespace { - namespace cc = cds::container; - typedef cds::gc::DHP gc_type; - - class EllenBinTreeSet_DHP : public cds_test::container_tree_set_hp - { - protected: - typedef cds_test::container_tree_set_hp base_class; - typedef int key_type; - - struct generic_traits: public cc::ellen_bintree::traits - { - typedef base_class::key_extractor key_extractor; - }; - - void SetUp() - { - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item > set_type; - - cds::gc::dhp::GarbageCollector::Construct( 16, set_type::c_nHazardPtrCount ); - cds::threading::Manager::attachThread(); - } - - void TearDown() - { - cds::threading::Manager::detachThread(); - cds::gc::hp::GarbageCollector::Destruct(); - } - }; - - - TEST_F( EllenBinTreeSet_DHP, compare ) - { - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, - typename cc::ellen_bintree::make_set_traits< - cc::opt::type_traits< generic_traits > - ,cds::opt::compare< cmp > - >::type - > set_type; - - set_type s; - test( s ); - } - - TEST_F( EllenBinTreeSet_DHP, less ) - { - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, - typename cc::ellen_bintree::make_set_traits< - cc::opt::type_traits< generic_traits > - ,cds::opt::less< base_class::less > - >::type - > set_type; - - set_type s; - test( s ); - } - - TEST_F( EllenBinTreeSet_DHP, cmpmix ) - { - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, - typename cc::ellen_bintree::make_set_traits< - cc::opt::type_traits< generic_traits > - ,cds::opt::less< base_class::less > - ,cds::opt::compare< cmp > - >::type - > set_type; - - set_type s; - test( s ); - } - - TEST_F( EllenBinTreeSet_DHP, update_desc_pool ) - { - struct set_traits: public generic_traits - { - typedef cmp compare; - typedef cds::memory::pool_allocator update_desc_allocator; - }; - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; - - set_type s; - test( s ); - } - - TEST_F( EllenBinTreeSet_DHP, update_desc_lazy_pool ) - { - struct set_traits: public generic_traits - { - typedef cmp compare; - typedef cds::memory::pool_allocator< cds_test::update_desc, cds_test::lazy_pool_accessor> update_desc_allocator; - }; - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; - - set_type s; - test( s ); - } - - TEST_F( EllenBinTreeSet_DHP, item_counting ) - { - struct set_traits: public generic_traits - { - typedef cmp compare; - typedef base_class::less less; - typedef cds::atomicity::item_counter item_counter; - typedef cds::memory::pool_allocator update_desc_allocator; - }; - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; - - set_type s; - test( s ); - } - - TEST_F( EllenBinTreeSet_DHP, backoff ) - { - struct set_traits: public generic_traits - { - typedef cmp compare; - typedef base_class::less less; - typedef cds::atomicity::item_counter item_counter; - typedef cds::backoff::yield back_off; - typedef cds::memory::pool_allocator update_desc_allocator; - }; - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; - - set_type s; - test( s ); - } - - TEST_F( EllenBinTreeSet_DHP, stat ) - { - struct set_traits: public generic_traits - { - typedef base_class::less less; - typedef cds::atomicity::item_counter item_counter; - typedef cds::backoff::yield back_off; - typedef cc::ellen_bintree::stat<> stat; - typedef cds::memory::pool_allocator update_desc_allocator; - }; - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; - - set_type s; - test( s ); - } - -} // namespace diff --git a/test/unit/tree/ellenbintree_set_hp.cpp b/test/unit/tree/ellenbintree_set_hp.cpp deleted file mode 100644 index 1152288b..00000000 --- a/test/unit/tree/ellenbintree_set_hp.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* - This file is a part of libcds - Concurrent Data Structures library - - (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 - - Source code repo: http://github.com/khizmax/libcds/ - Download: http://sourceforge.net/projects/libcds/files/ - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include "test_tree_set_hp.h" - -#include -#include "test_ellen_bintree_update_desc_pool.h" - -namespace { - namespace cc = cds::container; - typedef cds::gc::HP gc_type; - - class EllenBinTreeSet_HP : public cds_test::container_tree_set_hp - { - protected: - typedef cds_test::container_tree_set_hp base_class; - typedef int key_type; - - struct generic_traits: public cc::ellen_bintree::traits - { - typedef base_class::key_extractor key_extractor; - }; - - void SetUp() - { - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item > set_type; - - // +1 - for guarded_ptr - cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 ); - cds::threading::Manager::attachThread(); - } - - void TearDown() - { - cds::threading::Manager::detachThread(); - cds::gc::hp::GarbageCollector::Destruct( true ); - } - }; - - - TEST_F( EllenBinTreeSet_HP, compare ) - { - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, - typename cc::ellen_bintree::make_set_traits< - cc::opt::type_traits< generic_traits > - ,cds::opt::compare< cmp > - >::type - > set_type; - - set_type s; - test( s ); - } - - TEST_F( EllenBinTreeSet_HP, less ) - { - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, - typename cc::ellen_bintree::make_set_traits< - cc::opt::type_traits< generic_traits > - ,cds::opt::less< base_class::less > - >::type - > set_type; - - set_type s; - test( s ); - } - - TEST_F( EllenBinTreeSet_HP, cmpmix ) - { - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, - typename cc::ellen_bintree::make_set_traits< - cc::opt::type_traits< generic_traits > - ,cds::opt::less< base_class::less > - ,cds::opt::compare< cmp > - >::type - > set_type; - - set_type s; - test( s ); - } - - TEST_F( EllenBinTreeSet_HP, update_desc_pool ) - { - struct set_traits: public generic_traits - { - typedef cmp compare; - typedef cds::memory::pool_allocator update_desc_allocator; - }; - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; - - set_type s; - test( s ); - } - - TEST_F( EllenBinTreeSet_HP, update_desc_lazy_pool ) - { - struct set_traits: public generic_traits - { - typedef cmp compare; - typedef cds::memory::pool_allocator< cds_test::update_desc, cds_test::lazy_pool_accessor> update_desc_allocator; - }; - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; - - set_type s; - test( s ); - } - - TEST_F( EllenBinTreeSet_HP, item_counting ) - { - struct set_traits: public generic_traits - { - typedef cmp compare; - typedef base_class::less less; - typedef cds::atomicity::item_counter item_counter; - typedef cds::memory::pool_allocator update_desc_allocator; - }; - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; - - set_type s; - test( s ); - } - - TEST_F( EllenBinTreeSet_HP, backoff ) - { - struct set_traits: public generic_traits - { - typedef cmp compare; - typedef base_class::less less; - typedef cds::atomicity::item_counter item_counter; - typedef cds::backoff::yield back_off; - typedef cds::memory::pool_allocator update_desc_allocator; - }; - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; - - set_type s; - test( s ); - } - - TEST_F( EllenBinTreeSet_HP, stat ) - { - struct set_traits: public generic_traits - { - typedef base_class::less less; - typedef cds::atomicity::item_counter item_counter; - typedef cds::backoff::yield back_off; - typedef cc::ellen_bintree::stat<> stat; - typedef cds::memory::pool_allocator update_desc_allocator; - }; - typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type; - - set_type s; - test( s ); - } - -} // namespace diff --git a/test/unit/tree/test_ellen_bintree_map_rcu.h b/test/unit/tree/test_ellen_bintree_map_rcu.h new file mode 100644 index 00000000..746cac62 --- /dev/null +++ b/test/unit/tree/test_ellen_bintree_map_rcu.h @@ -0,0 +1,234 @@ +/* + 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_TREE_TEST_ELLEN_BINTREE_MAP_RCU_H +#define CDSUNIT_TREE_TEST_ELLEN_BINTREE_MAP_RCU_H + +#include "test_tree_map_rcu.h" +#include +#include "test_ellen_bintree_update_desc_pool.h" + +namespace { + namespace cc = cds::container; + + template + class EllenBinTreeMap: public cds_test::container_tree_map_rcu + { + typedef cds_test::container_tree_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( EllenBinTreeMap ); + + TYPED_TEST_P( EllenBinTreeMap, compare ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type, + typename cc::ellen_bintree::make_map_traits< + cds::opt::compare< typename TestFixture::cmp > + >::type + > map_type; + + map_type m; + this->test( m ); + } + + TYPED_TEST_P( EllenBinTreeMap, less ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type, + typename cc::ellen_bintree::make_map_traits< + cds::opt::less< typename TestFixture::less > + >::type + > map_type; + + map_type m; + this->test( m ); + } + + TYPED_TEST_P( EllenBinTreeMap, update_desc_pool ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type, + typename cc::ellen_bintree::make_map_traits< + cds::opt::less< typename TestFixture::less > + ,cc::ellen_bintree::update_desc_allocator< cds::memory::pool_allocator> + >::type + > map_type; + + map_type m; + this->test( m ); + } + + TYPED_TEST_P( EllenBinTreeMap, update_desc_lazy_pool ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type, + typename cc::ellen_bintree::make_map_traits< + cds::opt::less< typename TestFixture::less > + , cc::ellen_bintree::update_desc_allocator< cds::memory::pool_allocator> + >::type + > map_type; + + map_type m; + this->test( m ); + } + + TYPED_TEST_P( EllenBinTreeMap, cmpmix ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type, + typename cc::ellen_bintree::make_map_traits< + cds::opt::less< typename TestFixture::less > + ,cds::opt::compare< typename TestFixture::cmp > + >::type + > map_type; + + map_type m; + this->test( m ); + } + + TYPED_TEST_P( EllenBinTreeMap, item_counting ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + struct map_traits: public cc::ellen_bintree::traits + { + typedef typename TestFixture::cmp compare; + typedef typename TestFixture::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type, map_traits > map_type; + + map_type m; + this->test( m ); + } + + TYPED_TEST_P( EllenBinTreeMap, backoff ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + struct map_traits: public cc::ellen_bintree::traits + { + typedef typename TestFixture::cmp compare; + typedef typename TestFixture::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type, map_traits > map_type; + + map_type m; + this->test( m ); + } + + TYPED_TEST_P( EllenBinTreeMap, stat ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + struct map_traits: public cc::ellen_bintree::traits + { + typedef typename TestFixture::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cc::ellen_bintree::stat<> stat; + typedef cds::memory::pool_allocator update_desc_allocator; + }; + typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type, map_traits > map_type; + + map_type m; + this->test( m ); + } + + TYPED_TEST_P( EllenBinTreeMap, copy_policy ) + { + typedef typename TestFixture::rcu_type rcu_type; + typedef typename TestFixture::key_type key_type; + typedef typename TestFixture::value_type value_type; + + struct map_traits: public cc::ellen_bintree::traits + { + typedef typename TestFixture::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + typedef cc::ellen_bintree::stat<> stat; + typedef cds::memory::pool_allocator update_desc_allocator; + typedef typename TestFixture::copy_key copy_policy; + }; + typedef cc::EllenBinTreeMap< rcu_type, key_type, value_type, map_traits > map_type; + + map_type m; + this->test( m ); + } + + REGISTER_TYPED_TEST_CASE_P( EllenBinTreeMap, + compare, less, update_desc_pool, update_desc_lazy_pool, cmpmix, item_counting, backoff, stat, copy_policy + ); + +} // namespace + +#endif // CDSUNIT_TREE_TEST_ELLEN_BINTREE_MAP_RCU_H + \ No newline at end of file diff --git a/test/unit/tree/test_tree_map.h b/test/unit/tree/test_tree_map.h new file mode 100644 index 00000000..1733c98b --- /dev/null +++ b/test/unit/tree/test_tree_map.h @@ -0,0 +1,388 @@ +/* + 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_TREE_TEST_TREE_MAP_H +#define CDSUNIT_TREE_TEST_TREE_MAP_H + +#include "test_tree_map_data.h" + +// forward declaration +namespace cds { namespace container {} } + +namespace cds_test { + + class container_tree_map: public tree_map_fixture + { + public: + static size_t const kSize = 1000; + + protected: + template + void test( Map& m ) + { + // Precondition: map is empty + // Postcondition: map is empty + + ASSERT_TRUE( m.empty()); + ASSERT_CONTAINER_SIZE( m, 0 ); + + typedef typename Map::value_type map_pair; + size_t const kkSize = 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 ); + } + + // insert/find + for ( auto const& i : arrKeys ) { + value_type const& val( arrVals.at( i.nKey )); + + ASSERT_FALSE( m.contains( i.nKey )); + ASSERT_FALSE( m.contains( i )); + ASSERT_FALSE( m.contains( other_item( i.nKey ), other_less())); + ASSERT_FALSE( m.find( i, []( map_pair const& ) { + ASSERT_TRUE( false ); + } )); + ASSERT_FALSE( m.find( i.nKey, []( map_pair const& ) { + EXPECT_TRUE( false ); + } )); + ASSERT_FALSE( m.find_with( other_item( i.nKey ), other_less(), []( map_pair const& ) { + EXPECT_TRUE( false ); + } )); + + std::pair< bool, bool > updResult; + + switch ( i.nKey % 16 ) { + case 0: + ASSERT_TRUE( m.insert( i )); + ASSERT_FALSE( m.insert( i )); + ASSERT_TRUE( m.find( i.nKey, []( map_pair& v ) { + v.second.nVal = v.first.nKey; + v.second.strVal = std::to_string( v.first.nKey ); + } )); + break; + case 1: + ASSERT_TRUE( m.insert( i.nKey )); + ASSERT_FALSE( m.insert( i.nKey )); + ASSERT_TRUE( m.find( i.nKey, []( map_pair& v ) { + v.second.nVal = v.first.nKey; + v.second.strVal = std::to_string( v.first.nKey ); + } )); + break; + case 2: + ASSERT_TRUE( m.insert( std::to_string( i.nKey ))); + ASSERT_FALSE( m.insert( std::to_string( i.nKey ))); + ASSERT_TRUE( m.find( i.nKey, []( map_pair& v ) { + v.second.nVal = v.first.nKey; + v.second.strVal = std::to_string( v.first.nKey ); + } )); + break; + case 3: + ASSERT_TRUE( m.insert( i, val )); + ASSERT_FALSE( m.insert( i, val )); + break; + case 4: + ASSERT_TRUE( m.insert( i.nKey, val.strVal )); + ASSERT_FALSE( m.insert( i.nKey, val.strVal )); + break; + case 5: + ASSERT_TRUE( m.insert( val.strVal, i.nKey )); + ASSERT_FALSE( m.insert( val.strVal, i.nKey )); + break; + case 6: + ASSERT_TRUE( m.insert_with( i, []( map_pair& v ) { + v.second.nVal = v.first.nKey; + v.second.strVal = std::to_string( v.first.nKey ); + } )); + ASSERT_FALSE( m.insert_with( i, []( map_pair& v ) { + EXPECT_TRUE( false ); + } )); + break; + case 7: + ASSERT_TRUE( m.insert_with( i.nKey, []( map_pair& v ) { + v.second.nVal = v.first.nKey; + v.second.strVal = std::to_string( v.first.nKey ); + } )); + ASSERT_FALSE( m.insert_with( i.nKey, []( map_pair& v ) { + EXPECT_TRUE( false ); + } )); + break; + case 8: + ASSERT_TRUE( m.insert_with( val.strVal, []( map_pair& v ) { + v.second.nVal = v.first.nKey; + v.second.strVal = std::to_string( v.first.nKey ); + } )); + ASSERT_FALSE( m.insert_with( val.strVal, []( map_pair& v ) { + EXPECT_TRUE( false ); + } )); + break; + case 9: + updResult = m.update( i.nKey, []( bool, map_pair& ) { + EXPECT_TRUE( false ); + }, false ); + ASSERT_FALSE( updResult.first ); + ASSERT_FALSE( updResult.second ); + + updResult = m.update( i.nKey, []( bool bNew, map_pair& v ) { + EXPECT_TRUE( bNew ); + v.second.nVal = v.first.nKey; + }); + ASSERT_TRUE( updResult.first ); + ASSERT_TRUE( updResult.second ); + + updResult = m.update( i.nKey, []( bool bNew, map_pair& v ) { + EXPECT_FALSE( bNew ); + EXPECT_EQ( v.first.nKey, v.second.nVal ); + v.second.strVal = std::to_string( v.second.nVal ); + } ); + ASSERT_TRUE( updResult.first ); + ASSERT_FALSE( updResult.second ); + break; + case 10: + updResult = m.update( i, []( bool, map_pair& ) { + EXPECT_TRUE( false ); + }, false ); + ASSERT_FALSE( updResult.first ); + ASSERT_FALSE( updResult.second ); + + updResult = m.update( i, []( bool bNew, map_pair& v ) { + EXPECT_TRUE( bNew ); + v.second.nVal = v.first.nKey; + }); + ASSERT_TRUE( updResult.first ); + ASSERT_TRUE( updResult.second ); + + updResult = m.update( i, []( bool bNew, map_pair& v ) { + EXPECT_FALSE( bNew ); + EXPECT_EQ( v.first.nKey, v.second.nVal ); + v.second.strVal = std::to_string( v.second.nVal ); + } ); + ASSERT_TRUE( updResult.first ); + ASSERT_FALSE( updResult.second ); + break; + case 11: + updResult = m.update( val.strVal, []( bool, map_pair& ) { + EXPECT_TRUE( false ); + }, false ); + ASSERT_FALSE( updResult.first ); + ASSERT_FALSE( updResult.second ); + + updResult = m.update( val.strVal, []( bool bNew, map_pair& v ) { + EXPECT_TRUE( bNew ); + v.second.nVal = v.first.nKey; + }); + ASSERT_TRUE( updResult.first ); + ASSERT_TRUE( updResult.second ); + + updResult = m.update( val.strVal, []( bool bNew, map_pair& v ) { + EXPECT_FALSE( bNew ); + EXPECT_EQ( v.first.nKey, v.second.nVal ); + v.second.strVal = std::to_string( v.second.nVal ); + } ); + ASSERT_TRUE( updResult.first ); + ASSERT_FALSE( updResult.second ); + break; + case 12: + ASSERT_TRUE( m.emplace( i.nKey )); + ASSERT_FALSE( m.emplace( i.nKey )); + ASSERT_TRUE( m.find( i.nKey, []( map_pair& v ) { + v.second.nVal = v.first.nKey; + v.second.strVal = std::to_string( v.first.nKey ); + } )); + break; + case 13: + ASSERT_TRUE( m.emplace( i, i.nKey )); + ASSERT_FALSE( m.emplace( i, i.nKey )); + break; + case 14: + { + std::string str = val.strVal; + ASSERT_TRUE( m.emplace( i, std::move( str ))); + ASSERT_TRUE( str.empty()); + str = val.strVal; + ASSERT_FALSE( m.emplace( i, std::move( str ))); + ASSERT_TRUE( str.empty()); + } + break; + case 15: + { + std::string str = val.strVal; + ASSERT_TRUE( m.emplace( i, i.nKey, std::move( str ))); + ASSERT_TRUE( str.empty()); + str = val.strVal; + ASSERT_FALSE( m.emplace( i, i.nKey, std::move( str ))); + ASSERT_TRUE( str.empty()); + } + break; + } + + ASSERT_TRUE( m.contains( i.nKey )); + ASSERT_TRUE( m.contains( i )); + ASSERT_TRUE( m.contains( other_item( i.nKey ), other_less())); + ASSERT_TRUE( m.find( i, []( map_pair const& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + } )); + ASSERT_TRUE( m.find( i.nKey, []( map_pair const& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + } )); + ASSERT_TRUE( m.find_with( other_item( i.nKey ), other_less(), []( map_pair const& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + } )); + } + ASSERT_FALSE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, kkSize ); + + ASSERT_TRUE( m.check_consistency()); + + shuffle( arrKeys.begin(), arrKeys.end() ); + + // erase/find + for ( auto const& i : arrKeys ) { + value_type const& val( arrVals.at( i.nKey ) ); + + ASSERT_TRUE( m.contains( i.nKey )); + ASSERT_TRUE( m.contains( val.strVal ) ); + ASSERT_TRUE( m.contains( i )); + ASSERT_TRUE( m.contains( other_item( i.nKey ), other_less())); + ASSERT_TRUE( m.find( i, []( map_pair const& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + } )); + ASSERT_TRUE( m.find( i.nKey, []( map_pair const& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + } )); + ASSERT_TRUE( m.find_with( other_item( i.nKey ), other_less(), []( map_pair const& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + } )); + + + switch ( i.nKey % 8 ) { + case 0: + ASSERT_TRUE( m.erase( i )); + ASSERT_FALSE( m.erase( i )); + break; + case 1: + ASSERT_TRUE( m.erase( i.nKey )); + ASSERT_FALSE( m.erase( i.nKey )); + break; + case 2: + ASSERT_TRUE( m.erase( val.strVal )); + ASSERT_FALSE( m.erase( val.strVal )); + break; + case 3: + ASSERT_TRUE( m.erase_with( other_item( i.nKey ), other_less())); + ASSERT_FALSE( m.erase_with( other_item( i.nKey ), other_less())); + break; + case 4: + ASSERT_TRUE( m.erase( i, []( map_pair& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + })); + ASSERT_FALSE( m.erase( i, []( map_pair& ) { + EXPECT_TRUE( false ); + })); + break; + case 5: + ASSERT_TRUE( m.erase( i.nKey, []( map_pair& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + })); + ASSERT_FALSE( m.erase( i.nKey, []( map_pair& ) { + EXPECT_TRUE( false ); + })); + break; + case 6: + ASSERT_TRUE( m.erase( val.strVal, []( map_pair& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + })); + ASSERT_FALSE( m.erase( val.strVal, []( map_pair& ) { + EXPECT_TRUE( false ); + })); + break; + case 7: + ASSERT_TRUE( m.erase_with( other_item( i.nKey ), other_less(), []( map_pair& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + })); + ASSERT_FALSE( m.erase_with( other_item( i.nKey ), other_less(), []( map_pair& ) { + EXPECT_TRUE( false ); + })); + break; + } + + ASSERT_FALSE( m.contains( i.nKey )); + ASSERT_FALSE( m.contains( i )); + ASSERT_FALSE( m.contains( val.strVal )); + ASSERT_FALSE( m.contains( other_item( i.nKey ), other_less())); + ASSERT_FALSE( m.find( i, []( map_pair const& ) { + ASSERT_TRUE( false ); + } )); + ASSERT_FALSE( m.find( i.nKey, []( map_pair const& ) { + EXPECT_TRUE( false ); + } )); + ASSERT_FALSE( m.find_with( other_item( i.nKey ), other_less(), []( map_pair const& ) { + EXPECT_TRUE( false ); + } )); + } + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + + // clear + for ( auto const& i : arrKeys ) + ASSERT_TRUE( m.insert( i )); + + ASSERT_FALSE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, kkSize ); + + m.clear(); + + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + } + }; + +} // namespace cds_test + +#endif // #ifndef CDSUNIT_TREE_TEST_TREE_MAP_H diff --git a/test/unit/tree/test_tree_map_data.h b/test/unit/tree/test_tree_map_data.h new file mode 100644 index 00000000..236f4b82 --- /dev/null +++ b/test/unit/tree/test_tree_map_data.h @@ -0,0 +1,254 @@ +/* + 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_TREE_TEST_TREE_MAP_DATA_H +#define CDSUNIT_TREE_TEST_TREE_MAP_DATA_H + +#include +#include + +#include + +namespace cds_test { + + class tree_map_fixture: public fixture + { + public: + struct key_type { + int nKey; + + key_type() + {} + + explicit key_type( int n ) + : nKey( n ) + {} + + explicit key_type( std::string const& str ) + : nKey( std::stoi( str )) + {} + + key_type( key_type const& s ) + : nKey( s.nKey ) + {} + }; + + struct value_type { + int nVal; + std::string strVal; + + value_type() + : nVal( 0 ) + {} + + explicit value_type( int n ) + : nVal( n ) + , strVal( std::to_string( n )) + {} + + explicit value_type( std::string const& str ) + : nVal( std::stoi( str )) + , strVal( str ) + {} + + explicit value_type( std::string&& str ) + : nVal( std::stoi( str )) + , strVal( std::move( str )) + {} + + value_type( int n, std::string const& str ) + : nVal( n ) + , strVal( str ) + {} + + value_type( int n, std::string&& str ) + : nVal( n ) + , strVal( std::move( str )) + {} + + value_type( value_type&& v ) + : nVal( v.nVal ) + , strVal( std::move( v.strVal )) + {} + + value_type( value_type const& v ) + : nVal( v.nVal ) + , strVal( v.strVal ) + {} + + value_type& operator=( value_type const& v ) + { + if ( this != &v ) { + nVal = v.nVal; + strVal = v.strVal; + } + return *this; + } + + value_type& operator=( value_type&& v ) + { + if ( this != &v ) { + nVal = v.nVal; + strVal = std::move( v.strVal ); + } + return *this; + } + + value_type& operator=( int i ) + { + nVal = i; + strVal = std::to_string( i ); + return *this; + } + + value_type& operator=( std::string const& s ) + { + nVal = std::stoi( s ); + strVal = s; + return *this; + } + }; + + typedef std::pair pair_type; + + struct copy_key { + void operator()( key_type& dest, key_type const& src ) const + { + dest.nKey = src.nKey; + } + }; + struct less + { + bool operator ()( key_type const& v1, key_type const& v2 ) const + { + return v1.nKey < v2.nKey; + } + + bool operator ()( key_type const& v1, int v2 ) const + { + return v1.nKey < v2; + } + + bool operator ()( int v1, key_type const& v2 ) const + { + return v1 < v2.nKey; + } + + bool operator ()( key_type const& v1, std::string const& v2 ) const + { + return v1.nKey < std::stoi(v2 ); + } + + bool operator ()( std::string const& v1, key_type const& v2 ) const + { + return std::stoi( v1 ) < v2.nKey; + } + }; + + struct cmp { + int operator ()( key_type const& v1, key_type const& v2 ) const + { + if ( v1.nKey < v2.nKey ) + return -1; + return v1.nKey > v2.nKey ? 1 : 0; + } + + int operator ()( key_type const& v1, int v2 ) const + { + if ( v1.nKey < v2 ) + return -1; + return v1.nKey > v2 ? 1 : 0; + } + + int operator ()( int v1, key_type const& v2 ) const + { + if ( v1 < v2.nKey ) + return -1; + return v1 > v2.nKey ? 1 : 0; + } + + int operator ()( key_type const& v1, std::string const& v2 ) const + { + int n2 = std::stoi( v2 ); + if ( v1.nKey < n2 ) + return -1; + return v1.nKey > n2 ? 1 : 0; + } + + int operator ()( std::string const& v1, key_type const& v2 ) const + { + int n1 = std::stoi( v1 ); + if ( n1 < v2.nKey ) + return -1; + return n1 > v2.nKey ? 1 : 0; + } + }; + + struct hash1 { + size_t operator()( int i ) const + { + return cds::opt::v::hash()( i ); + } + + size_t operator()( std::string const& str ) const + { + return cds::opt::v::hash()( std::stoi( str )); + } + + template + size_t operator()( T const& i ) const + { + return cds::opt::v::hash()(i.nKey); + } + }; + + struct other_item { + int nKey; + + other_item( int key ) + : nKey( key ) + {} + }; + + struct other_less + { + bool operator ()( key_type const& v1, other_item const& v2 ) const + { + return v1.nKey < v2.nKey; + } + bool operator ()( other_item const& v1, key_type const& v2 ) const + { + return v1.nKey < v2.nKey; + } + }; + }; +} // namespace cds_test + +#endif // CDSUNIT_TREE_TEST_TREE_MAP_DATA_H diff --git a/test/unit/tree/test_tree_map_hp.h b/test/unit/tree/test_tree_map_hp.h new file mode 100644 index 00000000..831d0cd7 --- /dev/null +++ b/test/unit/tree/test_tree_map_hp.h @@ -0,0 +1,171 @@ +/* + 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_TREE_TEST_TREE_MAP_HP_H +#define CDSUNIT_TREE_TEST_TREE_MAP_HP_H + +#include "test_tree_map.h" + +namespace cds_test { + + class container_tree_map_hp: public container_tree_map + { + typedef container_tree_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 ); + + // get/extract + typedef typename Map::guarded_ptr guarded_ptr; + guarded_ptr gp; + + for ( auto const& i : arrKeys ) { + value_type const& val = arrVals.at( i.nKey ); + + gp = m.get( i.nKey ); + ASSERT_FALSE( !gp ); + ASSERT_EQ( gp->first.nKey, i.nKey ); + gp.release(); + gp = m.get( i ); + ASSERT_FALSE( !gp ); + ASSERT_EQ( gp->first.nKey, i.nKey ); + gp.release(); + gp = m.get_with( other_item( i.nKey ), other_less()); + ASSERT_FALSE( !gp ); + ASSERT_EQ( gp->first.nKey, i.nKey ); + + switch ( i.nKey % 4 ) { + case 0: + gp = m.extract( i.nKey ); + break; + case 1: + gp = m.extract( i ); + break; + case 2: + gp = m.extract( val.strVal ); + break; + case 3: + gp = m.extract_with( other_item( i.nKey ), other_less()); + break; + } + ASSERT_FALSE( !gp ); + ASSERT_EQ( gp->first.nKey, i.nKey ); + gp.release(); + + gp = m.get( i.nKey ); + ASSERT_TRUE( !gp ); + gp = m.get( i ); + ASSERT_TRUE( !gp ); + gp = m.get_with( other_item( i.nKey ), other_less()); + ASSERT_TRUE( !gp ); + } + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + + gp = m.extract_min(); + EXPECT_TRUE( !gp ); + gp = m.extract_max(); + EXPECT_TRUE( !gp ); + + for ( auto const& i : arrKeys ) + ASSERT_TRUE( m.insert( i ) ); + ASSERT_FALSE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, kkSize ); + + // extract_min + int nKey = -1; + size_t nCount = 0; + while ( !m.empty() ) { + gp = m.extract_min(); + ASSERT_FALSE( !gp ); + EXPECT_EQ( gp->first.nKey, nKey + 1 ); + nKey = gp->first.nKey; + ++nCount; + } + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + EXPECT_EQ( nCount, kkSize ); + + // extract_max + for ( auto const& i : arrKeys ) + ASSERT_TRUE( m.insert( i ) ); + ASSERT_FALSE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, kkSize ); + + nKey = kkSize; + nCount = 0; + while ( !m.empty() ) { + gp = m.extract_max(); + ASSERT_FALSE( !gp ); + EXPECT_EQ( gp->first.nKey, nKey - 1 ); + nKey = gp->first.nKey; + ++nCount; + } + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + EXPECT_EQ( nCount, kkSize ); + + ASSERT_TRUE( m.check_consistency()); + } + }; + +} // namespace cds_test + +#endif // #ifndef CDSUNIT_TREE_TEST_TREE_MAP_HP_H diff --git a/test/unit/tree/test_tree_map_rcu.h b/test/unit/tree/test_tree_map_rcu.h new file mode 100644 index 00000000..113a25ec --- /dev/null +++ b/test/unit/tree/test_tree_map_rcu.h @@ -0,0 +1,257 @@ +/* + 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_TREE_TEST_TREE_MAP_RCU_H +#define CDSUNIT_TREE_TEST_TREE_MAP_RCU_H + +#include "test_tree_map.h" + +namespace cds_test { + + class container_tree_map_rcu: public container_tree_map + { + typedef container_tree_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 ); + + typedef typename Map::exempt_ptr exempt_ptr; + typedef typename Map::value_type * raw_ptr; + typedef typename Map::rcu_lock rcu_lock; + + // get/extract + shuffle( arrKeys.begin(), arrKeys.end() ); + + exempt_ptr xp; + 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; + } + + 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 ); + + + // extract_min + for ( auto const& i : arrKeys ) + ASSERT_TRUE( m.insert( i ) ); + + size_t nCount = 0; + int nKey = -1; + while ( !m.empty() ) { + xp = m.extract_min(); + ASSERT_FALSE( !xp ); + EXPECT_EQ( xp->first.nKey, nKey + 1 ); + nKey = xp->first.nKey; + ++nCount; + } + xp = m.extract_min(); + ASSERT_TRUE( !xp ); + xp = m.extract_max(); + ASSERT_TRUE( !xp ); + EXPECT_EQ( kkSize, nCount ); + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + + // extract_max + xp = m.extract_min(); + EXPECT_TRUE( !xp ); + xp = m.extract_max(); + EXPECT_TRUE( !xp ); + + for ( auto const& i : arrKeys ) + ASSERT_TRUE( m.insert( i ) ); + + nKey = kkSize; + nCount = 0; + while ( !m.empty() ) { + xp = m.extract_max(); + ASSERT_FALSE( !xp ); + EXPECT_EQ( xp->first.nKey, nKey - 1 ); + nKey = xp->first.nKey; + ++nCount; + } + + xp = m.extract_min(); + ASSERT_TRUE( !xp ); + xp = m.extract_max(); + ASSERT_TRUE( !xp ); + EXPECT_EQ( kkSize, nCount ); + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + } + }; + +} // namespace cds_test + +#endif // #ifndef CDSUNIT_TREE_TEST_TREE_MAP_RCU_H diff --git a/test/unit/tree/test_tree_set.h b/test/unit/tree/test_tree_set.h index bc92bd6e..0c5ce9e4 100644 --- a/test/unit/tree/test_tree_set.h +++ b/test/unit/tree/test_tree_set.h @@ -407,6 +407,8 @@ namespace cds_test { ASSERT_FALSE( s.empty() ); ASSERT_CONTAINER_SIZE( s, nSetSize ); + ASSERT_TRUE( s.check_consistency()); + // erase shuffle( indices.begin(), indices.end() ); for ( auto idx : indices ) {