From ec4a9176ad763b1a1bc6dd6f71e842d76d329c14 Mon Sep 17 00:00:00 2001 From: khizmax Date: Mon, 11 Apr 2016 21:56:40 +0300 Subject: [PATCH] Migrated intrusive EllenBinTree unit test to gtest --- projects/Win/vc14/gtest-tree.vcxproj | 1 + projects/Win/vc14/gtest-tree.vcxproj.filters | 3 + test/unit/tree/CMakeLists.txt | 3 + test/unit/tree/intrusive_ellenbintree_dhp.cpp | 240 ++++++++++++++++++ test/unit/tree/intrusive_ellenbintree_hp.cpp | 84 +++++- 5 files changed, 329 insertions(+), 2 deletions(-) create mode 100644 test/unit/tree/intrusive_ellenbintree_dhp.cpp diff --git a/projects/Win/vc14/gtest-tree.vcxproj b/projects/Win/vc14/gtest-tree.vcxproj index df2a8b97..758664db 100644 --- a/projects/Win/vc14/gtest-tree.vcxproj +++ b/projects/Win/vc14/gtest-tree.vcxproj @@ -28,6 +28,7 @@ + diff --git a/projects/Win/vc14/gtest-tree.vcxproj.filters b/projects/Win/vc14/gtest-tree.vcxproj.filters index 77abf64a..8d91cb0d 100644 --- a/projects/Win/vc14/gtest-tree.vcxproj.filters +++ b/projects/Win/vc14/gtest-tree.vcxproj.filters @@ -21,6 +21,9 @@ Source Files + + Source Files + diff --git a/test/unit/tree/CMakeLists.txt b/test/unit/tree/CMakeLists.txt index d64b4f46..7488df23 100644 --- a/test/unit/tree/CMakeLists.txt +++ b/test/unit/tree/CMakeLists.txt @@ -1,8 +1,11 @@ set(PACKAGE_NAME unit-tree) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof") + set(CDSGTEST_TREE_SOURCES ../main.cpp intrusive_ellenbintree_hp.cpp + intrusive_ellenbintree_dhp.cpp ) include_directories( diff --git a/test/unit/tree/intrusive_ellenbintree_dhp.cpp b/test/unit/tree/intrusive_ellenbintree_dhp.cpp new file mode 100644 index 00000000..58a82134 --- /dev/null +++ b/test/unit/tree/intrusive_ellenbintree_dhp.cpp @@ -0,0 +1,240 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "test_intrusive_tree_hp.h" + +#include +//#include +//#include + +namespace { + namespace ci = cds::intrusive; + typedef cds::gc::DHP gc_type; + + class IntrusiveEllenBinTree_DHP : public cds_test::intrusive_tree_hp + { + protected: + typedef cds_test::intrusive_tree_hp base_class; + + protected: + typedef base_class::key_type key_type; + + typedef typename base_class::base_int_item< ci::ellen_bintree::node> base_item_type; + typedef ci::ellen_bintree::internal_node< key_type, base_item_type > internal_base_node; + typedef ci::ellen_bintree::update_desc< base_item_type, internal_base_node > update_base_desc; + + typedef typename base_class::member_int_item< ci::ellen_bintree::node> member_item_type; + typedef ci::ellen_bintree::internal_node< key_type, member_item_type > internal_member_node; + typedef ci::ellen_bintree::update_desc< member_item_type, internal_member_node > update_member_desc; + + void SetUp() + { + struct list_traits : public ci::ellen_bintree::traits + { + typedef ci::ellen_bintree::base_hook< ci::opt::gc> hook; + }; + typedef ci::EllenBinTree< gc_type, key_type, base_item_type > tree_type; + + cds::gc::dhp::GarbageCollector::Construct( 16, tree_type::c_nHazardPtrCount ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::dhp::GarbageCollector::Destruct(); + } + + struct generic_traits: public ci::ellen_bintree::traits + { + typedef base_class::key_extractor key_extractor; + typedef mock_disposer disposer; + }; + }; + + + TEST_F( IntrusiveEllenBinTree_DHP, base_cmp ) + { + typedef ci::EllenBinTree< gc_type, key_type, base_item_type, + ci::ellen_bintree::make_traits< + ci::opt::type_traits< generic_traits > + ,ci::opt::hook< ci::ellen_bintree::base_hook< ci::opt::gc< gc_type >>> + ,ci::opt::compare< cmp> + >::type + > tree_type; + + tree_type t; + test( t ); + } + + TEST_F( IntrusiveEllenBinTree_DHP, base_less ) + { + typedef ci::EllenBinTree< gc_type, key_type, base_item_type, + ci::ellen_bintree::make_traits< + ci::opt::type_traits< generic_traits > + ,ci::opt::hook< ci::ellen_bintree::base_hook< ci::opt::gc< gc_type >>> + ,ci::opt::less< less> + >::type + > tree_type; + + tree_type t; + test( t ); + } + + TEST_F( IntrusiveEllenBinTree_DHP, base_item_counter ) + { + typedef ci::EllenBinTree< gc_type, key_type, base_item_type, + ci::ellen_bintree::make_traits< + ci::opt::type_traits< generic_traits > + ,ci::opt::hook< ci::ellen_bintree::base_hook< ci::opt::gc< gc_type >>> + ,ci::opt::compare< cmp> + ,ci::opt::item_counter< simple_item_counter > + >::type + > tree_type; + + tree_type t; + test( t ); + } + + TEST_F( IntrusiveEllenBinTree_DHP, base_backoff ) + { + struct tree_traits: public generic_traits + { + typedef ci::ellen_bintree::base_hook< ci::opt::gc< gc_type >> hook; + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + }; + + typedef ci::EllenBinTree< gc_type, key_type, base_item_type, tree_traits > tree_type; + + tree_type t; + test( t ); + } + + TEST_F( IntrusiveEllenBinTree_DHP, base_seq_cst ) + { + struct tree_traits: public generic_traits + { + typedef ci::ellen_bintree::base_hook< ci::opt::gc< gc_type >> hook; + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::pause back_off; + typedef ci::opt::v::sequential_consistent memory_model; + }; + + typedef ci::EllenBinTree< gc_type, key_type, base_item_type, tree_traits > tree_type; + + tree_type t; + test( t ); + } + + // member hook + TEST_F( IntrusiveEllenBinTree_DHP, member_cmp ) + { + typedef ci::EllenBinTree< gc_type, key_type, member_item_type, + ci::ellen_bintree::make_traits< + ci::opt::type_traits< generic_traits > + ,ci::opt::hook< ci::ellen_bintree::member_hook< offsetof( member_item_type, hMember), ci::opt::gc< gc_type >>> + ,ci::opt::compare< cmp> + >::type + > tree_type; + + tree_type t; + test( t ); + } + + TEST_F( IntrusiveEllenBinTree_DHP, member_less ) + { + typedef ci::EllenBinTree< gc_type, key_type, member_item_type, + ci::ellen_bintree::make_traits< + ci::opt::type_traits< generic_traits > + ,ci::opt::hook< ci::ellen_bintree::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >>> + ,ci::opt::less< less> + >::type + > tree_type; + + tree_type t; + test( t ); + } + + TEST_F( IntrusiveEllenBinTree_DHP, member_item_counter ) + { + typedef ci::EllenBinTree< gc_type, key_type, member_item_type, + ci::ellen_bintree::make_traits< + ci::opt::type_traits< generic_traits > + ,ci::opt::hook< ci::ellen_bintree::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >>> + ,ci::opt::compare< cmp> + ,ci::opt::item_counter< simple_item_counter > + >::type + > tree_type; + + tree_type t; + test( t ); + } + + TEST_F( IntrusiveEllenBinTree_DHP, member_backoff ) + { + struct tree_traits: public generic_traits + { + typedef ci::ellen_bintree::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook; + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + }; + + typedef ci::EllenBinTree< gc_type, key_type, member_item_type, tree_traits > tree_type; + + tree_type t; + test( t ); + } + + TEST_F( IntrusiveEllenBinTree_DHP, member_seq_cst ) + { + struct tree_traits: public generic_traits + { + typedef ci::ellen_bintree::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook; + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::pause back_off; + typedef ci::opt::v::sequential_consistent memory_model; + }; + + typedef ci::EllenBinTree< gc_type, key_type, member_item_type, tree_traits > tree_type; + + tree_type t; + test( t ); + } + +} // namespace diff --git a/test/unit/tree/intrusive_ellenbintree_hp.cpp b/test/unit/tree/intrusive_ellenbintree_hp.cpp index b55ed62e..9b676f33 100644 --- a/test/unit/tree/intrusive_ellenbintree_hp.cpp +++ b/test/unit/tree/intrusive_ellenbintree_hp.cpp @@ -31,6 +31,8 @@ #include "test_intrusive_tree_hp.h" #include +//#include +//#include namespace { namespace ci = cds::intrusive; @@ -58,10 +60,10 @@ namespace { { typedef ci::ellen_bintree::base_hook< ci::opt::gc> hook; }; - typedef ci::EllenBinTree< gc_type, key_type, base_item_type > set_type; + typedef ci::EllenBinTree< gc_type, key_type, base_item_type > tree_type; // +1 - for guarded_ptr - cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 ); + cds::gc::hp::GarbageCollector::Construct( tree_type::c_nHazardPtrCount + 1, 1, 16 ); cds::threading::Manager::attachThread(); } @@ -157,5 +159,83 @@ namespace { test( t ); } + // member hook + TEST_F( IntrusiveEllenBinTree_HP, member_cmp ) + { + typedef ci::EllenBinTree< gc_type, key_type, member_item_type, + ci::ellen_bintree::make_traits< + ci::opt::type_traits< generic_traits > + ,ci::opt::hook< ci::ellen_bintree::member_hook< offsetof( member_item_type, hMember), ci::opt::gc< gc_type >>> + ,ci::opt::compare< cmp> + >::type + > tree_type; + + tree_type t; + test( t ); + } + + TEST_F( IntrusiveEllenBinTree_HP, member_less ) + { + typedef ci::EllenBinTree< gc_type, key_type, member_item_type, + ci::ellen_bintree::make_traits< + ci::opt::type_traits< generic_traits > + ,ci::opt::hook< ci::ellen_bintree::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >>> + ,ci::opt::less< less> + >::type + > tree_type; + + tree_type t; + test( t ); + } + + TEST_F( IntrusiveEllenBinTree_HP, member_item_counter ) + { + typedef ci::EllenBinTree< gc_type, key_type, member_item_type, + ci::ellen_bintree::make_traits< + ci::opt::type_traits< generic_traits > + ,ci::opt::hook< ci::ellen_bintree::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >>> + ,ci::opt::compare< cmp> + ,ci::opt::item_counter< simple_item_counter > + >::type + > tree_type; + + tree_type t; + test( t ); + } + + TEST_F( IntrusiveEllenBinTree_HP, member_backoff ) + { + struct tree_traits: public generic_traits + { + typedef ci::ellen_bintree::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook; + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::yield back_off; + }; + + typedef ci::EllenBinTree< gc_type, key_type, member_item_type, tree_traits > tree_type; + + tree_type t; + test( t ); + } + + TEST_F( IntrusiveEllenBinTree_HP, member_seq_cst ) + { + struct tree_traits: public generic_traits + { + typedef ci::ellen_bintree::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook; + typedef cmp compare; + typedef base_class::less less; + typedef cds::atomicity::item_counter item_counter; + typedef cds::backoff::pause back_off; + typedef ci::opt::v::sequential_consistent memory_model; + }; + + typedef ci::EllenBinTree< gc_type, key_type, member_item_type, tree_traits > tree_type; + + tree_type t; + test( t ); + } } // namespace -- 2.34.1