Migrated set unit tests to gtest framework
authorkhizmax <libcds.dev@gmail.com>
Thu, 10 Mar 2016 06:42:30 +0000 (09:42 +0300)
committerkhizmax <libcds.dev@gmail.com>
Thu, 10 Mar 2016 06:42:30 +0000 (09:42 +0300)
projects/Win/vc14/gtest-set.vcxproj
projects/Win/vc14/gtest-set.vcxproj.filters
test/unit/set/CMakeLists.txt
test/unit/set/intrusive_michael_lazy_dhp.cpp [new file with mode: 0644]
test/unit/set/intrusive_michael_lazy_hp.cpp [new file with mode: 0644]
test/unit/set/intrusive_michael_michael_dhp.cpp
test/unit/set/test_intrusive_set.h
test/unit/set/test_intrusive_set_rcu.h [new file with mode: 0644]

index a7e63cb168a927dcf7108756d66299f841a0d70c..82b5276fbf60694faaaf42b18b0e93466f68bf30 100644 (file)
   </ItemGroup>\r
   <ItemGroup>\r
     <ClCompile Include="..\..\..\test\unit\main.cpp" />\r
+    <ClCompile Include="..\..\..\test\unit\set\intrusive_michael_lazy_dhp.cpp" />\r
+    <ClCompile Include="..\..\..\test\unit\set\intrusive_michael_lazy_hp.cpp" />\r
     <ClCompile Include="..\..\..\test\unit\set\intrusive_michael_michael_dhp.cpp" />\r
     <ClCompile Include="..\..\..\test\unit\set\intrusive_michael_michael_hp.cpp" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="..\..\..\test\unit\set\test_intrusive_set.h" />\r
     <ClInclude Include="..\..\..\test\unit\set\test_intrusive_set_hp.h" />\r
+    <ClInclude Include="..\..\..\test\unit\set\test_intrusive_set_rcu.h" />\r
   </ItemGroup>\r
   <PropertyGroup Label="Globals">\r
     <ProjectGuid>{A589D3F1-A749-4268-ADEC-D0CE13D1E359}</ProjectGuid>\r
index 09bd836760ae89a0d1452eead27206e0640d825e..5048a8b2f8b72d1ef950276589c7bef7dd99ca71 100644 (file)
     <ClCompile Include="..\..\..\test\unit\set\intrusive_michael_michael_dhp.cpp">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\..\..\test\unit\set\intrusive_michael_lazy_hp.cpp">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\..\..\test\unit\set\intrusive_michael_lazy_dhp.cpp">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="..\..\..\test\unit\set\test_intrusive_set.h">\r
@@ -32,5 +38,8 @@
     <ClInclude Include="..\..\..\test\unit\set\test_intrusive_set_hp.h">\r
       <Filter>Header Files</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="..\..\..\test\unit\set\test_intrusive_set_rcu.h">\r
+      <Filter>Header Files</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
 </Project>
\ No newline at end of file
index 111ef264523fb4f0960ca0984b73f1a87d152513..7f9eb504d87f7df41a7d2e882f988f7bff9cf876 100644 (file)
@@ -2,6 +2,8 @@ set(PACKAGE_NAME unit-set)
 
 set(CDSGTEST_SET_SOURCES
     ../main.cpp
+    intrusive_michael_lazy_hp.cpp
+    intrusive_michael_lazy_dhp.cpp
     intrusive_michael_michael_hp.cpp
     intrusive_michael_michael_dhp.cpp
 )
diff --git a/test/unit/set/intrusive_michael_lazy_dhp.cpp b/test/unit/set/intrusive_michael_lazy_dhp.cpp
new file mode 100644 (file)
index 0000000..7244989
--- /dev/null
@@ -0,0 +1,253 @@
+/*
+    This file is a part of libcds - Concurrent Data Structures library
+
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+
+    Source code repo: http://github.com/khizmax/libcds/
+    Download: http://sourceforge.net/projects/libcds/files/
+    
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this
+      list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     
+*/
+
+#include "test_intrusive_set_hp.h"
+
+#include <cds/intrusive/lazy_list_dhp.h>
+#include <cds/intrusive/michael_set.h>
+
+#include <mutex>
+
+namespace {
+    namespace ci = cds::intrusive;
+    typedef cds::gc::DHP gc_type;
+
+    class IntrusiveMichaelLazySet_DHP : public cds_test::intrusive_set_hp
+    {
+        typedef cds_test::intrusive_set_hp base_class;
+
+    protected:
+        typedef typename base_class::base_int_item< ci::lazy_list::node<gc_type>>   base_item_type;
+        typedef typename base_class::base_int_item< ci::lazy_list::node<gc_type, std::mutex>>   base_mutex_item_type;
+        typedef typename base_class::member_int_item< ci::lazy_list::node<gc_type>> member_item_type;
+        typedef typename base_class::member_int_item< ci::lazy_list::node<gc_type, std::mutex>> member_mutex_item_type;
+
+        void SetUp()
+        {
+            struct list_traits : public ci::lazy_list::traits
+            {
+                typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
+            };
+            typedef ci::LazyList< gc_type, base_item_type, list_traits > list_type;
+            typedef ci::MichaelHashSet< gc_type, list_type >   set_type;
+
+            cds::gc::dhp::GarbageCollector::Construct( 16, set_type::c_nHazardPtrCount );
+            cds::threading::Manager::attachThread();
+        }
+
+        void TearDown()
+        {
+            cds::threading::Manager::detachThread();
+            cds::gc::dhp::GarbageCollector::Destruct();
+        }
+    };
+
+
+    TEST_F( IntrusiveMichaelLazySet_DHP, base_cmp )
+    {
+        typedef ci::LazyList< gc_type
+            , base_item_type
+            ,ci::lazy_list::make_traits<
+                ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type > > >
+                ,ci::opt::compare< cmp<base_item_type> >
+                ,ci::opt::disposer< mock_disposer >
+                ,ci::opt::back_off< cds::backoff::pause >
+            >::type
+        > bucket_type;
+
+        typedef ci::MichaelHashSet< gc_type, bucket_type,
+            ci::michael_set::make_traits<
+                ci::opt::hash< hash_int >
+            >::type
+        > set_type;
+
+        set_type s( kSize, 2 );
+        test( s );
+    }
+
+    TEST_F( IntrusiveMichaelLazySet_DHP, base_less )
+    {
+        typedef ci::LazyList< gc_type
+            , base_item_type
+            ,ci::lazy_list::make_traits<
+                ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type >>>
+                ,ci::opt::less< less<base_item_type> >
+                ,ci::opt::disposer< mock_disposer >
+            >::type
+        > bucket_type;
+
+        typedef ci::MichaelHashSet< gc_type, bucket_type,
+            ci::michael_set::make_traits<
+                ci::opt::hash< hash_int >
+            >::type
+        > set_type;
+
+        set_type s( kSize, 2 );
+        test( s );
+    }
+
+    TEST_F( IntrusiveMichaelLazySet_DHP, base_cmpmix )
+    {
+        struct list_traits : public ci::lazy_list::traits
+        {
+            typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
+            typedef base_class::less<base_item_type> less;
+            typedef cmp<base_item_type> compare;
+            typedef mock_disposer disposer;
+        };
+        typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
+
+        struct set_traits : public ci::michael_set::traits
+        {
+            typedef hash_int hash;
+            typedef simple_item_counter item_counter;
+        };
+        typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
+
+        set_type s( kSize, 2 );
+        test( s );
+    }
+
+    TEST_F( IntrusiveMichaelLazySet_DHP, base_mutex )
+    {
+        struct list_traits : public ci::lazy_list::traits
+        {
+            typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
+            typedef base_class::less<base_mutex_item_type> less;
+            typedef cmp<base_mutex_item_type> compare;
+            typedef mock_disposer disposer;
+        };
+        typedef ci::LazyList< gc_type, base_mutex_item_type, list_traits > bucket_type;
+
+        struct set_traits : public ci::michael_set::traits
+        {
+            typedef hash_int hash;
+            typedef simple_item_counter item_counter;
+        };
+        typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
+
+        set_type s( kSize, 2 );
+        test( s );
+    }
+
+
+    TEST_F( IntrusiveMichaelLazySet_DHP, member_cmp )
+    {
+        typedef ci::LazyList< gc_type
+            ,member_item_type
+            ,ci::lazy_list::make_traits<
+                ci::opt::hook< ci::lazy_list::member_hook<
+                    offsetof( member_item_type, hMember ),
+                    ci::opt::gc<gc_type>
+                > >
+                ,ci::opt::compare< cmp<member_item_type> >
+                ,ci::opt::disposer< mock_disposer >
+            >::type
+        >    bucket_type;
+
+        typedef ci::MichaelHashSet< gc_type, bucket_type,
+            ci::michael_set::make_traits<
+                ci::opt::hash< hash_int >
+            >::type
+        > set_type;
+
+        set_type s( kSize, 2 );
+        test( s );
+    }
+
+    TEST_F( IntrusiveMichaelLazySet_DHP, member_less )
+    {
+        typedef ci::LazyList< gc_type
+            , member_item_type
+            ,ci::lazy_list::make_traits<
+                ci::opt::hook< ci::lazy_list::member_hook<
+                    offsetof( member_item_type, hMember ),
+                    ci::opt::gc<gc_type>
+                > >
+                ,ci::opt::less< less<member_item_type> >
+                ,ci::opt::disposer< mock_disposer >
+            >::type
+        > bucket_type;
+
+        typedef ci::MichaelHashSet< gc_type, bucket_type,
+            ci::michael_set::make_traits<
+                ci::opt::hash< hash_int >
+            >::type
+        > set_type;
+
+        set_type s( kSize, 2 );
+        test( s );
+    }
+
+    TEST_F( IntrusiveMichaelLazySet_DHP, member_cmpmix )
+    {
+        struct list_traits : public ci::lazy_list::traits
+        {
+            typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
+            typedef base_class::less<member_item_type> less;
+            typedef cmp<member_item_type> compare;
+            typedef mock_disposer disposer;
+        };
+        typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
+
+        struct set_traits : public ci::michael_set::traits
+        {
+            typedef hash_int hash;
+            typedef simple_item_counter item_counter;
+        };
+        typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
+
+        set_type s( kSize, 2 );
+        test( s );
+    }
+
+    TEST_F( IntrusiveMichaelLazySet_DHP, member_mutex )
+    {
+        struct list_traits : public ci::lazy_list::traits
+        {
+            typedef ci::lazy_list::member_hook< offsetof( member_mutex_item_type, hMember ), ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
+            typedef base_class::less<member_mutex_item_type> less;
+            typedef cmp<member_mutex_item_type> compare;
+            typedef mock_disposer disposer;
+        };
+        typedef ci::LazyList< gc_type, member_mutex_item_type, list_traits > bucket_type;
+
+        struct set_traits : public ci::michael_set::traits
+        {
+            typedef hash_int hash;
+            typedef simple_item_counter item_counter;
+        };
+        typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
+
+        set_type s( kSize, 2 );
+        test( s );
+    }
+
+} // namespace
diff --git a/test/unit/set/intrusive_michael_lazy_hp.cpp b/test/unit/set/intrusive_michael_lazy_hp.cpp
new file mode 100644 (file)
index 0000000..ebcb94f
--- /dev/null
@@ -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.     
+*/
+
+#include "test_intrusive_set_hp.h"
+
+#include <cds/intrusive/lazy_list_hp.h>
+#include <cds/intrusive/michael_set.h>
+
+#include <mutex>
+
+namespace {
+    namespace ci = cds::intrusive;
+    typedef cds::gc::HP gc_type;
+
+    class IntrusiveMichaelLazySet_HP : public cds_test::intrusive_set_hp
+    {
+        typedef cds_test::intrusive_set_hp base_class;
+
+    protected:
+        typedef typename base_class::base_int_item< ci::lazy_list::node<gc_type>>   base_item_type;
+        typedef typename base_class::base_int_item< ci::lazy_list::node<gc_type, std::mutex>>   base_mutex_item_type;
+        typedef typename base_class::member_int_item< ci::lazy_list::node<gc_type>> member_item_type;
+        typedef typename base_class::member_int_item< ci::lazy_list::node<gc_type, std::mutex>> member_mutex_item_type;
+
+        void SetUp()
+        {
+            struct list_traits : public ci::lazy_list::traits
+            {
+                typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
+            };
+            typedef ci::LazyList< gc_type, base_item_type, list_traits > list_type;
+            typedef ci::MichaelHashSet< gc_type, list_type >   set_type;
+
+            // +1 - for guarded_ptr
+            cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 );
+            cds::threading::Manager::attachThread();
+        }
+
+        void TearDown()
+        {
+            cds::threading::Manager::detachThread();
+            cds::gc::hp::GarbageCollector::Destruct( true );
+        }
+    };
+
+
+    TEST_F( IntrusiveMichaelLazySet_HP, base_cmp )
+    {
+        typedef ci::LazyList< gc_type
+            , base_item_type
+            ,ci::lazy_list::make_traits<
+                ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type > > >
+                ,ci::opt::compare< cmp<base_item_type> >
+                ,ci::opt::disposer< mock_disposer >
+                ,ci::opt::back_off< cds::backoff::pause >
+            >::type
+        > bucket_type;
+
+        typedef ci::MichaelHashSet< gc_type, bucket_type,
+            ci::michael_set::make_traits<
+                ci::opt::hash< hash_int >
+            >::type
+        > set_type;
+
+        set_type s( kSize, 2 );
+        test( s );
+    }
+
+    TEST_F( IntrusiveMichaelLazySet_HP, base_less )
+    {
+        typedef ci::LazyList< gc_type
+            , base_item_type
+            ,ci::lazy_list::make_traits<
+                ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type >>>
+                ,ci::opt::less< less<base_item_type> >
+                ,ci::opt::disposer< mock_disposer >
+            >::type
+        > bucket_type;
+
+        typedef ci::MichaelHashSet< gc_type, bucket_type,
+            ci::michael_set::make_traits<
+                ci::opt::hash< hash_int >
+            >::type
+        > set_type;
+
+        set_type s( kSize, 2 );
+        test( s );
+    }
+
+    TEST_F( IntrusiveMichaelLazySet_HP, base_cmpmix )
+    {
+        struct list_traits : public ci::lazy_list::traits
+        {
+            typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
+            typedef base_class::less<base_item_type> less;
+            typedef cmp<base_item_type> compare;
+            typedef mock_disposer disposer;
+        };
+        typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
+
+        struct set_traits : public ci::michael_set::traits
+        {
+            typedef hash_int hash;
+            typedef simple_item_counter item_counter;
+        };
+        typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
+
+        set_type s( kSize, 2 );
+        test( s );
+    }
+
+    TEST_F( IntrusiveMichaelLazySet_HP, base_mutex )
+    {
+        struct list_traits : public ci::lazy_list::traits
+        {
+            typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
+            typedef base_class::less<base_mutex_item_type> less;
+            typedef cmp<base_mutex_item_type> compare;
+            typedef mock_disposer disposer;
+        };
+        typedef ci::LazyList< gc_type, base_mutex_item_type, list_traits > bucket_type;
+
+        struct set_traits : public ci::michael_set::traits
+        {
+            typedef hash_int hash;
+            typedef simple_item_counter item_counter;
+        };
+        typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
+
+        set_type s( kSize, 2 );
+        test( s );
+    }
+
+
+    TEST_F( IntrusiveMichaelLazySet_HP, member_cmp )
+    {
+        typedef ci::LazyList< gc_type
+            ,member_item_type
+            ,ci::lazy_list::make_traits<
+                ci::opt::hook< ci::lazy_list::member_hook<
+                    offsetof( member_item_type, hMember ),
+                    ci::opt::gc<gc_type>
+                > >
+                ,ci::opt::compare< cmp<member_item_type> >
+                ,ci::opt::disposer< mock_disposer >
+            >::type
+        >    bucket_type;
+
+        typedef ci::MichaelHashSet< gc_type, bucket_type,
+            ci::michael_set::make_traits<
+                ci::opt::hash< hash_int >
+            >::type
+        > set_type;
+
+        set_type s( kSize, 2 );
+        test( s );
+    }
+
+    TEST_F( IntrusiveMichaelLazySet_HP, member_less )
+    {
+        typedef ci::LazyList< gc_type
+            , member_item_type
+            ,ci::lazy_list::make_traits<
+                ci::opt::hook< ci::lazy_list::member_hook<
+                    offsetof( member_item_type, hMember ),
+                    ci::opt::gc<gc_type>
+                > >
+                ,ci::opt::less< less<member_item_type> >
+                ,ci::opt::disposer< mock_disposer >
+            >::type
+        > bucket_type;
+
+        typedef ci::MichaelHashSet< gc_type, bucket_type,
+            ci::michael_set::make_traits<
+                ci::opt::hash< hash_int >
+            >::type
+        > set_type;
+
+        set_type s( kSize, 2 );
+        test( s );
+    }
+
+    TEST_F( IntrusiveMichaelLazySet_HP, member_cmpmix )
+    {
+        struct list_traits : public ci::lazy_list::traits
+        {
+            typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
+            typedef base_class::less<member_item_type> less;
+            typedef cmp<member_item_type> compare;
+            typedef mock_disposer disposer;
+        };
+        typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
+
+        struct set_traits : public ci::michael_set::traits
+        {
+            typedef hash_int hash;
+            typedef simple_item_counter item_counter;
+        };
+        typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
+
+        set_type s( kSize, 2 );
+        test( s );
+    }
+
+    TEST_F( IntrusiveMichaelLazySet_HP, member_mutex )
+    {
+        struct list_traits : public ci::lazy_list::traits
+        {
+            typedef ci::lazy_list::member_hook< offsetof( member_mutex_item_type, hMember ), ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
+            typedef base_class::less<member_mutex_item_type> less;
+            typedef cmp<member_mutex_item_type> compare;
+            typedef mock_disposer disposer;
+        };
+        typedef ci::LazyList< gc_type, member_mutex_item_type, list_traits > bucket_type;
+
+        struct set_traits : public ci::michael_set::traits
+        {
+            typedef hash_int hash;
+            typedef simple_item_counter item_counter;
+        };
+        typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
+
+        set_type s( kSize, 2 );
+        test( s );
+    }
+
+} // namespace
index 0ce9bd8f54b8b8361083286e727c683dfc4296d6..9b5719f27002c42e2c3d59caaba3ce201f8c34e9 100644 (file)
@@ -61,7 +61,7 @@ namespace {
         void TearDown()
         {
             cds::threading::Manager::detachThread();
-            cds::gc::hp::GarbageCollector::Destruct();
+            cds::gc::dhp::GarbageCollector::Destruct();
         }
     };
 
index 2930596c3fad89d9776d1fb47e3ba58aa7ddcc6a..139c92a9e67c9a2bca93240c95ad45f25f11acf8 100644 (file)
@@ -409,22 +409,37 @@ namespace cds_test {
 
             // clear
             for ( auto& i : data ) {
-                i.nDisposeCount = 0;
+                i.clear_stat();
                 ASSERT_TRUE( s.insert( i ));
             }
             ASSERT_FALSE( s.empty() );
             ASSERT_CONTAINER_SIZE( s, kSize );
 
+            // Iterator test
+            for ( auto it = s.begin(); it != s.end(); ++it ) {
+                ++it->nFindCount;
+            }
+            for ( auto it = s.cbegin(); it != s.cend(); ++it ) {
+                EXPECT_EQ( it->nFindCount, 1 );
+            }
+            for ( auto& i : data ) {
+                EXPECT_EQ( i.nFindCount, 1 );
+            }
+
+            // clear test
             s.clear();
 
             ASSERT_TRUE( s.empty());
             ASSERT_CONTAINER_SIZE( s, 0 );
+            ASSERT_TRUE( s.begin() == s.end() );
+            ASSERT_TRUE( s.cbegin() == s.cend() );
 
             // Force retiring cycle
             Set::gc::force_dispose();
             for ( auto& i : data ) {
                 EXPECT_EQ( i.nDisposeCount, 1 );
             }
+
         }
     };
 
diff --git a/test/unit/set/test_intrusive_set_rcu.h b/test/unit/set/test_intrusive_set_rcu.h
new file mode 100644 (file)
index 0000000..416f3e9
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+    This file is a part of libcds - Concurrent Data Structures library
+
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+
+    Source code repo: http://github.com/khizmax/libcds/
+    Download: http://sourceforge.net/projects/libcds/files/
+    
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this
+      list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     
+*/
+
+#ifndef CDSUNIT_SET_TEST_INTRUSIVE_SET_RCU_H
+#define CDSUNIT_SET_TEST_INTRUSIVE_SET_RCU_H
+
+#include "test_intrusive_set.h"
+
+// forward declaration
+namespace cds { namespace intrusive {}}
+
+namespace cds_test {
+
+    namespace ci = cds::intrusive;
+    namespace co = cds::opt;
+
+    class intrusive_set_rcu: public intrusive_set
+    {
+        typedef intrusive_set base_class;
+
+    protected:
+
+        template <class Set>
+        void test( Set& s )
+        {
+            // Precondition: set is empty
+            // Postcondition: set is empty
+
+            base_class::test( s );
+
+            ASSERT_TRUE( s.empty() );
+            ASSERT_CONTAINER_SIZE( s, 0 );
+
+            typedef typename Set::value_type value_type;
+
+            std::vector< value_type > data;
+            std::vector< size_t> indices;
+            data.reserve( kSize );
+            indices.reserve( kSize );
+            for ( size_t key = 0; key < kSize; ++key ) {
+                data.push_back( value_type( static_cast<int>(key) ) );
+                indices.push_back( key );
+            }
+            shuffle( indices.begin(), indices.end() );
+
+            typename Set::exempt_ptr xp;
+            typename Set::raw_ptr rp;
+            typedef typename Set::rcu_lock rcu_lock;
+
+            // get/extract from empty set
+            for ( auto idx : indices ) {
+                auto& i = data[idx];
+
+                {
+                    rcu_lock l;
+                    rp = s.get( i );
+                    ASSERT_TRUE( !rp );
+                    rp = s.get( i.key() );
+                    ASSERT_TRUE( !rp );
+                    rp = s.get_with( other_item( i.key()), other_less());
+                    ASSERT_TRUE( !rp );
+                }
+
+                if ( Set::c_bExtractLockExternal ) {
+                    rcu_lock l;
+
+                    xp = s.extract( i );
+                    ASSERT_TRUE( !xp );
+                    xp = s.extract( i.key() );
+                    ASSERT_TRUE( !xp );
+                    xp = s.extract_with( other_item( i.key() ), other_less() );
+                    ASSERT_TRUE( !xp );
+                }
+                else {
+                    xp = s.extract( i );
+                    ASSERT_TRUE( !xp );
+                    xp = s.extract( i.key() );
+                    ASSERT_TRUE( !xp );
+                    xp = s.extract_with( other_item( i.key() ), other_less() );
+                    ASSERT_TRUE( !xp );
+                }
+            }
+
+            // fill set
+            for ( auto& i : data ) {
+                i.nDisposeCount = 0;
+                ASSERT_TRUE( s.insert( i ) );
+            }
+
+            // get/extract
+            for ( auto idx : indices ) {
+                auto& i = data[idx];
+
+                {
+                    rcu_lock l;
+                    EXPECT_EQ( i.nFindCount, 0 );
+                    rp = s.get( i );
+                    ASSERT_TRUE( rp );
+                    ++rp->nFindCount;
+                    EXPECT_EQ( i.nFindCount, 1 );
+
+                    rp = s.get( i.key() );
+                    ASSERT_TRUE( rp );
+                    ++rp->nFindCount;
+                    EXPECT_EQ( i.nFindCount, 2 );
+
+                    rp = s.get_with( other_item( i.key()), other_less());
+                    ASSERT_TRUE( rp );
+                    ++rp->nFindCount;
+                    EXPECT_EQ( i.nFindCount, 3 );
+                }
+
+                if ( Set::c_bExtractLockExternal ) {
+                    rcu_lock l;
+
+                    EXPECT_EQ( i.nEraseCount, 0 );
+                    switch ( i.key() % 3 ) {
+                    case 0:
+                        xp = s.extract( i.key());
+                        break;
+                    case 1:
+                        xp = s.extract( i );
+                        break;
+                    case 2:
+                        xp = s.extract_with( other_item( i.key() ), other_less() );
+                        break;
+                    }
+                    ASSERT_TRUE( xp );
+                    ++xp->nEraseCount;
+                    EXPECT_EQ( i.nEraseCount, 1 );
+
+                    xp = s.extract( i );
+                    ASSERT_TRUE( !xp );
+                    xp = s.extract( i.key() );
+                    ASSERT_TRUE( !xp );
+                    xp = s.extract_with( other_item( i.key() ), other_less() );
+                    ASSERT_TRUE( !xp );
+                }
+                else {
+                    EXPECT_EQ( i.nEraseCount, 0 );
+                    switch ( i.key() % 3 ) {
+                    case 0:
+                        xp = s.extract( i.key());
+                        break;
+                    case 1:
+                        xp = s.extract( i );
+                        break;
+                    case 2:
+                        xp = s.extract_with( other_item( i.key() ), other_less() );
+                        break;
+                    }
+                    ASSERT_TRUE( xp );
+                    ++xp->nEraseCount;
+                    EXPECT_EQ( i.nEraseCount, 1 );
+
+                    xp = s.extract( i );
+                    ASSERT_TRUE( !xp );
+                    xp = s.extract( i.key() );
+                    ASSERT_TRUE( !xp );
+                    xp = s.extract_with( other_item( i.key() ), other_less() );
+                    ASSERT_TRUE( !xp );
+                }
+            }
+
+            ASSERT_TRUE( s.empty() );
+            ASSERT_CONTAINER_SIZE( s, 0 );
+
+            // Force retiring cycle
+            Set::gc::force_dispose();
+            for ( auto& i : data ) {
+                EXPECT_EQ( i.nDisposeCount, 1 );
+            }
+        }
+    };
+
+} // namespace cds_test
+
+#endif // #ifndef CDSUNIT_SET_TEST_INTRUSIVE_SET_RCU_H