From: khizmax Date: Thu, 21 Jan 2016 06:35:13 +0000 (+0300) Subject: Moved queue unit test to gtest framework X-Git-Tag: v2.2.0~420 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=libcds.git;a=commitdiff_plain;h=54df1a9e6cca339ea521cd0fc28ef8116d9d5746 Moved queue unit test to gtest framework --- diff --git a/projects/Win/vc14/cds.sln b/projects/Win/vc14/cds.sln index f827d9ab..b400e54a 100644 --- a/projects/Win/vc14/cds.sln +++ b/projects/Win/vc14/cds.sln @@ -184,18 +184,18 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest-stack", "gtest-stack. {408FE9BC-44F0-4E6A-89FA-D6F952584239} = {408FE9BC-44F0-4E6A-89FA-D6F952584239} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest-pqueue", "gtest-pqueue.vcxproj", "{EAD522BF-E7DA-4A20-94FF-4D3EAF0A540A}" - ProjectSection(ProjectDependencies) = postProject - {408FE9BC-44F0-4E6A-89FA-D6F952584239} = {408FE9BC-44F0-4E6A-89FA-D6F952584239} - EndProjectSection -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cds_test", "cds_test", "{3A510E45-180B-4ADC-AFCD-D75774B68580}" ProjectSection(SolutionItems) = preProject + ..\..\..\test\include\cds_test\check_size.h = ..\..\..\test\include\cds_test\check_size.h ..\..\..\test\include\cds_test\fixture.h = ..\..\..\test\include\cds_test\fixture.h ..\..\..\test\include\cds_test\thread.h = ..\..\..\test\include\cds_test\thread.h EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest-deque", "gtest-deque.vcxproj", "{20A9F084-D01F-47E5-B775-4F4B48504FCC}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest-deque", "gtest-deque.vcxproj", "{EA5D825A-83A4-4A36-83C1-3D048D21D55B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest-pqueue", "gtest-pqueue.vcxproj", "{ED94B1D1-2442-43C2-A71C-A757122408A6}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest-queue", "gtest-queue.vcxproj", "{9EB8FAB6-78E8-48B6-9589-85985CE8D33D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -471,30 +471,42 @@ Global {5407E9D2-67D9-4266-976E-7A90BDE2541D}.Release|Win32.Build.0 = Release|Win32 {5407E9D2-67D9-4266-976E-7A90BDE2541D}.Release|x64.ActiveCfg = Release|x64 {5407E9D2-67D9-4266-976E-7A90BDE2541D}.Release|x64.Build.0 = Release|x64 - {EAD522BF-E7DA-4A20-94FF-4D3EAF0A540A}.Debug|Win32.ActiveCfg = Debug|Win32 - {EAD522BF-E7DA-4A20-94FF-4D3EAF0A540A}.Debug|Win32.Build.0 = Debug|Win32 - {EAD522BF-E7DA-4A20-94FF-4D3EAF0A540A}.Debug|x64.ActiveCfg = Debug|x64 - {EAD522BF-E7DA-4A20-94FF-4D3EAF0A540A}.Debug|x64.Build.0 = Debug|x64 - {EAD522BF-E7DA-4A20-94FF-4D3EAF0A540A}.DebugVLD|Win32.ActiveCfg = DebugVLD|Win32 - {EAD522BF-E7DA-4A20-94FF-4D3EAF0A540A}.DebugVLD|Win32.Build.0 = DebugVLD|Win32 - {EAD522BF-E7DA-4A20-94FF-4D3EAF0A540A}.DebugVLD|x64.ActiveCfg = DebugVLD|x64 - {EAD522BF-E7DA-4A20-94FF-4D3EAF0A540A}.DebugVLD|x64.Build.0 = DebugVLD|x64 - {EAD522BF-E7DA-4A20-94FF-4D3EAF0A540A}.Release|Win32.ActiveCfg = Release|Win32 - {EAD522BF-E7DA-4A20-94FF-4D3EAF0A540A}.Release|Win32.Build.0 = Release|Win32 - {EAD522BF-E7DA-4A20-94FF-4D3EAF0A540A}.Release|x64.ActiveCfg = Release|x64 - {EAD522BF-E7DA-4A20-94FF-4D3EAF0A540A}.Release|x64.Build.0 = Release|x64 - {20A9F084-D01F-47E5-B775-4F4B48504FCC}.Debug|Win32.ActiveCfg = Debug|Win32 - {20A9F084-D01F-47E5-B775-4F4B48504FCC}.Debug|Win32.Build.0 = Debug|Win32 - {20A9F084-D01F-47E5-B775-4F4B48504FCC}.Debug|x64.ActiveCfg = Debug|x64 - {20A9F084-D01F-47E5-B775-4F4B48504FCC}.Debug|x64.Build.0 = Debug|x64 - {20A9F084-D01F-47E5-B775-4F4B48504FCC}.DebugVLD|Win32.ActiveCfg = DebugVLD|Win32 - {20A9F084-D01F-47E5-B775-4F4B48504FCC}.DebugVLD|Win32.Build.0 = DebugVLD|Win32 - {20A9F084-D01F-47E5-B775-4F4B48504FCC}.DebugVLD|x64.ActiveCfg = DebugVLD|x64 - {20A9F084-D01F-47E5-B775-4F4B48504FCC}.DebugVLD|x64.Build.0 = DebugVLD|x64 - {20A9F084-D01F-47E5-B775-4F4B48504FCC}.Release|Win32.ActiveCfg = Release|Win32 - {20A9F084-D01F-47E5-B775-4F4B48504FCC}.Release|Win32.Build.0 = Release|Win32 - {20A9F084-D01F-47E5-B775-4F4B48504FCC}.Release|x64.ActiveCfg = Release|x64 - {20A9F084-D01F-47E5-B775-4F4B48504FCC}.Release|x64.Build.0 = Release|x64 + {EA5D825A-83A4-4A36-83C1-3D048D21D55B}.Debug|Win32.ActiveCfg = Debug|Win32 + {EA5D825A-83A4-4A36-83C1-3D048D21D55B}.Debug|Win32.Build.0 = Debug|Win32 + {EA5D825A-83A4-4A36-83C1-3D048D21D55B}.Debug|x64.ActiveCfg = Debug|x64 + {EA5D825A-83A4-4A36-83C1-3D048D21D55B}.Debug|x64.Build.0 = Debug|x64 + {EA5D825A-83A4-4A36-83C1-3D048D21D55B}.DebugVLD|Win32.ActiveCfg = DebugVLD|Win32 + {EA5D825A-83A4-4A36-83C1-3D048D21D55B}.DebugVLD|Win32.Build.0 = DebugVLD|Win32 + {EA5D825A-83A4-4A36-83C1-3D048D21D55B}.DebugVLD|x64.ActiveCfg = DebugVLD|x64 + {EA5D825A-83A4-4A36-83C1-3D048D21D55B}.DebugVLD|x64.Build.0 = DebugVLD|x64 + {EA5D825A-83A4-4A36-83C1-3D048D21D55B}.Release|Win32.ActiveCfg = Release|Win32 + {EA5D825A-83A4-4A36-83C1-3D048D21D55B}.Release|Win32.Build.0 = Release|Win32 + {EA5D825A-83A4-4A36-83C1-3D048D21D55B}.Release|x64.ActiveCfg = Release|x64 + {EA5D825A-83A4-4A36-83C1-3D048D21D55B}.Release|x64.Build.0 = Release|x64 + {ED94B1D1-2442-43C2-A71C-A757122408A6}.Debug|Win32.ActiveCfg = Debug|Win32 + {ED94B1D1-2442-43C2-A71C-A757122408A6}.Debug|Win32.Build.0 = Debug|Win32 + {ED94B1D1-2442-43C2-A71C-A757122408A6}.Debug|x64.ActiveCfg = Debug|x64 + {ED94B1D1-2442-43C2-A71C-A757122408A6}.Debug|x64.Build.0 = Debug|x64 + {ED94B1D1-2442-43C2-A71C-A757122408A6}.DebugVLD|Win32.ActiveCfg = DebugVLD|Win32 + {ED94B1D1-2442-43C2-A71C-A757122408A6}.DebugVLD|Win32.Build.0 = DebugVLD|Win32 + {ED94B1D1-2442-43C2-A71C-A757122408A6}.DebugVLD|x64.ActiveCfg = DebugVLD|x64 + {ED94B1D1-2442-43C2-A71C-A757122408A6}.DebugVLD|x64.Build.0 = DebugVLD|x64 + {ED94B1D1-2442-43C2-A71C-A757122408A6}.Release|Win32.ActiveCfg = Release|Win32 + {ED94B1D1-2442-43C2-A71C-A757122408A6}.Release|Win32.Build.0 = Release|Win32 + {ED94B1D1-2442-43C2-A71C-A757122408A6}.Release|x64.ActiveCfg = Release|x64 + {ED94B1D1-2442-43C2-A71C-A757122408A6}.Release|x64.Build.0 = Release|x64 + {9EB8FAB6-78E8-48B6-9589-85985CE8D33D}.Debug|Win32.ActiveCfg = Debug|Win32 + {9EB8FAB6-78E8-48B6-9589-85985CE8D33D}.Debug|Win32.Build.0 = Debug|Win32 + {9EB8FAB6-78E8-48B6-9589-85985CE8D33D}.Debug|x64.ActiveCfg = Debug|x64 + {9EB8FAB6-78E8-48B6-9589-85985CE8D33D}.Debug|x64.Build.0 = Debug|x64 + {9EB8FAB6-78E8-48B6-9589-85985CE8D33D}.DebugVLD|Win32.ActiveCfg = DebugVLD|Win32 + {9EB8FAB6-78E8-48B6-9589-85985CE8D33D}.DebugVLD|Win32.Build.0 = DebugVLD|Win32 + {9EB8FAB6-78E8-48B6-9589-85985CE8D33D}.DebugVLD|x64.ActiveCfg = DebugVLD|x64 + {9EB8FAB6-78E8-48B6-9589-85985CE8D33D}.DebugVLD|x64.Build.0 = DebugVLD|x64 + {9EB8FAB6-78E8-48B6-9589-85985CE8D33D}.Release|Win32.ActiveCfg = Release|Win32 + {9EB8FAB6-78E8-48B6-9589-85985CE8D33D}.Release|Win32.Build.0 = Release|Win32 + {9EB8FAB6-78E8-48B6-9589-85985CE8D33D}.Release|x64.ActiveCfg = Release|x64 + {9EB8FAB6-78E8-48B6-9589-85985CE8D33D}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -523,8 +535,9 @@ Global {CA6F0834-0628-4CD7-8800-AEABCD636360} = {6BB7A27F-FC59-4267-B6FA-D034176D1459} {DE256E91-EE96-412E-82EE-DD7BD1A1130D} = {A64449B7-90FB-4E2B-A686-9EFC0E298644} {5407E9D2-67D9-4266-976E-7A90BDE2541D} = {810490B7-31E5-49AE-8455-CAF99A9658B6} - {EAD522BF-E7DA-4A20-94FF-4D3EAF0A540A} = {810490B7-31E5-49AE-8455-CAF99A9658B6} - {20A9F084-D01F-47E5-B775-4F4B48504FCC} = {810490B7-31E5-49AE-8455-CAF99A9658B6} + {EA5D825A-83A4-4A36-83C1-3D048D21D55B} = {810490B7-31E5-49AE-8455-CAF99A9658B6} + {ED94B1D1-2442-43C2-A71C-A757122408A6} = {810490B7-31E5-49AE-8455-CAF99A9658B6} + {9EB8FAB6-78E8-48B6-9589-85985CE8D33D} = {810490B7-31E5-49AE-8455-CAF99A9658B6} EndGlobalSection GlobalSection(DPCodeReviewSolutionGUID) = preSolution DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} diff --git a/projects/Win/vc14/gtest-deque.vcxproj b/projects/Win/vc14/gtest-deque.vcxproj index 2aaeadba..7861f82b 100644 --- a/projects/Win/vc14/gtest-deque.vcxproj +++ b/projects/Win/vc14/gtest-deque.vcxproj @@ -31,7 +31,7 @@ - {20A9F084-D01F-47E5-B775-4F4B48504FCC} + {EA5D825A-83A4-4A36-83C1-3D048D21D55B} Win32Proj stack 8.1 diff --git a/projects/Win/vc14/gtest-pqueue.vcxproj b/projects/Win/vc14/gtest-pqueue.vcxproj index 1348a782..cb3ddb69 100644 --- a/projects/Win/vc14/gtest-pqueue.vcxproj +++ b/projects/Win/vc14/gtest-pqueue.vcxproj @@ -39,7 +39,7 @@ - {EAD522BF-E7DA-4A20-94FF-4D3EAF0A540A} + {ED94B1D1-2442-43C2-A71C-A757122408A6} Win32Proj stack 8.1 diff --git a/projects/Win/vc14/gtest-queue.vcxproj b/projects/Win/vc14/gtest-queue.vcxproj new file mode 100644 index 00000000..f4d2a7f5 --- /dev/null +++ b/projects/Win/vc14/gtest-queue.vcxproj @@ -0,0 +1,255 @@ + + + + + DebugVLD + Win32 + + + DebugVLD + x64 + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + {9EB8FAB6-78E8-48B6-9589-85985CE8D33D} + Win32Proj + stack + 8.1 + + + + Application + true + v140 + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + true + v140 + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)..\..\..\bin\vc.$(PlatformToolset)\$(Platform)\ + $(SolutionDir)..\..\..\obj\vc.$(PlatformToolset)\$(Platform)\$(ProjectName)\$(Configuration)\ + $(ProjectName)_d + + + true + $(SolutionDir)..\..\..\bin\vc.$(PlatformToolset)\$(Platform)\ + $(SolutionDir)..\..\..\obj\vc.$(PlatformToolset)\$(Platform)\$(ProjectName)\$(Configuration)\ + $(ProjectName)_d + + + true + $(SolutionDir)..\..\..\bin\vc.$(PlatformToolset)\$(Platform)\ + $(SolutionDir)..\..\..\obj\vc.$(PlatformToolset)\$(Platform)\$(ProjectName)\$(Configuration)\ + $(ProjectName)_d + + + true + $(SolutionDir)..\..\..\bin\vc.$(PlatformToolset)\$(Platform)\ + $(SolutionDir)..\..\..\obj\vc.$(PlatformToolset)\$(Platform)\$(ProjectName)\$(Configuration)\ + $(ProjectName)_d + + + false + $(SolutionDir)..\..\..\bin\vc.$(PlatformToolset)\$(Platform)-release\ + $(SolutionDir)..\..\..\obj\vc.$(PlatformToolset)\$(Platform)\$(ProjectName)\$(Configuration)\ + + + false + $(SolutionDir)..\..\..\bin\vc.$(PlatformToolset)\$(Platform)-release\ + $(SolutionDir)..\..\..\obj\vc.$(PlatformToolset)\$(Platform)\$(ProjectName)\$(Configuration)\ + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(SolutionDir)..\..\..;$(GTEST_ROOT)/include;$(SolutionDir)..\..\..\test\include;$(BOOST_PATH);%(AdditionalIncludeDirectories) + + + Console + true + $(GTEST_LIB32);$(GTEST_ROOT)/lib/x86;$(BOOST_PATH)/stage32/lib;$(BOOST_PATH)/stage/lib;$(BOOST_PATH)/bin;%(AdditionalLibraryDirectories);$(OutDir) + gtestd.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(SolutionDir)..\..\..;$(GTEST_ROOT)/include;$(SolutionDir)..\..\..\test\include;$(BOOST_PATH);%(AdditionalIncludeDirectories) + + + Console + true + $(GTEST_LIB32);$(GTEST_ROOT)/lib/x86;$(BOOST_PATH)/stage32/lib;$(BOOST_PATH)/stage/lib;$(BOOST_PATH)/bin;%(AdditionalLibraryDirectories);$(OutDir) + gtestd.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(SolutionDir)..\..\..;$(GTEST_ROOT)/include;$(SolutionDir)..\..\..\test\include;$(BOOST_PATH);%(AdditionalIncludeDirectories) + + + Console + true + $(GTEST_LIB64);$(GTEST_ROOT)/lib/x64;$(BOOST_PATH)/stage64/lib;$(BOOST_PATH)/bin;%(AdditionalLibraryDirectories);$(OutDir) + gtestd.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(SolutionDir)..\..\..;$(GTEST_ROOT)/include;$(SolutionDir)..\..\..\test\include;$(BOOST_PATH);%(AdditionalIncludeDirectories) + + + Console + true + $(GTEST_LIB64);$(GTEST_ROOT)/lib/x64;$(BOOST_PATH)/stage64/lib;$(BOOST_PATH)/bin;%(AdditionalLibraryDirectories);$(OutDir) + gtestd.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(SolutionDir)..\..\..;$(GTEST_ROOT)/include;$(SolutionDir)..\..\..\test\include;$(BOOST_PATH);%(AdditionalIncludeDirectories) + + + Console + true + true + true + $(GTEST_LIB32);$(GTEST_ROOT)/lib/x86;$(BOOST_PATH)/stage32/lib;$(BOOST_PATH)/stage/lib;$(BOOST_PATH)/bin;%(AdditionalLibraryDirectories);$(OutDir) + gtest.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(SolutionDir)..\..\..;$(GTEST_ROOT)/include;$(SolutionDir)..\..\..\test\include;$(BOOST_PATH);%(AdditionalIncludeDirectories) + + + Console + true + true + true + $(GTEST_LIB64);$(GTEST_ROOT)/lib/x64;$(BOOST_PATH)/stage64/lib;$(BOOST_PATH)/bin;%(AdditionalLibraryDirectories);$(OutDir) + gtest.lib;%(AdditionalDependencies) + + + + + + \ No newline at end of file diff --git a/projects/Win/vc14/gtest-queue.vcxproj.filters b/projects/Win/vc14/gtest-queue.vcxproj.filters new file mode 100644 index 00000000..b766f092 --- /dev/null +++ b/projects/Win/vc14/gtest-queue.vcxproj.filters @@ -0,0 +1,57 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/projects/Win/vc14/hdr-test-queue.vcxproj b/projects/Win/vc14/hdr-test-queue.vcxproj index 7f3741ba..b604c0bf 100644 --- a/projects/Win/vc14/hdr-test-queue.vcxproj +++ b/projects/Win/vc14/hdr-test-queue.vcxproj @@ -332,7 +332,6 @@ - @@ -360,7 +359,6 @@ - diff --git a/projects/Win/vc14/hdr-test-queue.vcxproj.filters b/projects/Win/vc14/hdr-test-queue.vcxproj.filters index d75ac5e6..c99471b3 100644 --- a/projects/Win/vc14/hdr-test-queue.vcxproj.filters +++ b/projects/Win/vc14/hdr-test-queue.vcxproj.filters @@ -1,9 +1,6 @@  - - container - intrusive @@ -94,9 +91,6 @@ container - - container - container diff --git a/test/include/cds_test/check_size.h b/test/include/cds_test/check_size.h new file mode 100644 index 00000000..34a3b990 --- /dev/null +++ b/test/include/cds_test/check_size.h @@ -0,0 +1,71 @@ +/* + 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 CDSTEST_CHECK_SIZE_H +#define CDSTEST_CHECK_SIZE_H + +#include +#include + +namespace cds_test { + + template + struct size_checker { + template + bool operator()( Container const& c, size_t nSize ) const + { + return c.size() == nSize; + } + }; + + template<> + struct size_checker< cds::atomicity::empty_item_counter > { + template + bool operator()( Container const& /*c*/, size_t /*nSize*/ ) const + { + return true; + } + }; + + template + static inline bool check_size( Container const& cont, size_t nSize ) + { + return size_checker()( cont, nSize ); + } + +} // namespace cds_test + +#define ASSERT_CONTAINER_SIZE( container, expected ) \ + ASSERT_TRUE( cds_test::check_size(container, expected)) << "container size=" << container.size() << ", expected=" << expected + +#define EXPECT_CONTAINER_SIZE( container, expected ) \ + EXPECT_TRUE( cds_test::check_size(container, expected)) << "container size=" << container.size() << ", expected=" << expected + +#endif // #ifndef CDSTEST_CHECK_SIZE_H diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 8fe813be..236e738e 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deque) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/pqueue) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/queue) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/stack) diff --git a/test/unit/queue/CMakeLists.txt b/test/unit/queue/CMakeLists.txt new file mode 100644 index 00000000..947edc37 --- /dev/null +++ b/test/unit/queue/CMakeLists.txt @@ -0,0 +1,30 @@ +set(PACKAGE_NAME unit-queue) + +set(CDSGTEST_QUEUE_SOURCES + ../main.cpp + basket_queue_hp.cpp + basket_queue_dhp.cpp + fcqueue.cpp + moirqueue_hp.cpp + moirqueue_dhp.cpp + msqueue_hp.cpp + msqueue_dhp.cpp + optimistic_queue_hp.cpp + optimistic_queue_dhp.cpp + rwqueue.cpp +) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_executable(${PACKAGE_NAME} ${CDSGTEST_QUEUE_SOURCES}) +target_link_libraries(${PACKAGE_NAME} + ${CDS_SHARED_LIBRARY} + ${GTEST_LIBRARY} + ${Boost_THREAD_LIBRARY} + ${Boost_SYSTEM_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} +) + +add_test(NAME ${PACKAGE_NAME} COMMAND ${PACKAGE_NAME} WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) \ No newline at end of file diff --git a/test/unit/queue/basket_queue_dhp.cpp b/test/unit/queue/basket_queue_dhp.cpp new file mode 100644 index 00000000..e08838d9 --- /dev/null +++ b/test/unit/queue/basket_queue_dhp.cpp @@ -0,0 +1,140 @@ +/* + 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_generic_queue.h" + +#include +#include + +namespace { + namespace cc = cds::container; + typedef cds::gc::DHP gc_type; + + + class BasketQueue_DHP : public cds_test::generic_queue + { + protected: + void SetUp() + { + typedef cc::BasketQueue< gc_type, int > queue_type; + + cds::gc::dhp::GarbageCollector::Construct( 16, queue_type::c_nHazardPtrCount ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::dhp::GarbageCollector::Destruct(); + } + }; + + TEST_F( BasketQueue_DHP, defaulted ) + { + typedef cds::container::BasketQueue< gc_type, int > test_queue; + + test_queue q; + test(q); + } + + TEST_F( BasketQueue_DHP, item_counting ) + { + typedef cds::container::BasketQueue < gc_type, int, + typename cds::container::basket_queue::make_traits < + cds::opt::item_counter < cds::atomicity::item_counter > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( BasketQueue_DHP, relaxed ) + { + typedef cds::container::BasketQueue < gc_type, int, + typename cds::container::basket_queue::make_traits < + cds::opt::item_counter< cds::atomicity::item_counter > + , cds::opt::memory_model < cds::opt::v::relaxed_ordering > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( BasketQueue_DHP, aligned ) + { + typedef cds::container::BasketQueue < gc_type, int, + typename cds::container::basket_queue::make_traits < + cds::opt::memory_model< cds::opt::v::relaxed_ordering> + , cds::opt::padding < 32 > + >::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( BasketQueue_DHP, seq_cst ) + { + struct traits : public cc::basket_queue::traits + { + typedef cds::opt::v::sequential_consistent memory_model; + typedef cds::atomicity::item_counter item_counter; + enum { padding = 64 }; + }; + typedef cds::container::BasketQueue < gc_type, int, traits > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( BasketQueue_DHP, move ) + { + typedef cds::container::BasketQueue< gc_type, std::string > test_queue; + + test_queue q; + test_string( q ); + } + + TEST_F( BasketQueue_DHP, move_item_counting ) + { + struct traits : public cc::basket_queue::traits + { + typedef cds::atomicity::item_counter item_counter; + }; + typedef cds::container::BasketQueue< gc_type, std::string, traits > test_queue; + + test_queue q; + test_string( q ); + } + +} // namespace + diff --git a/test/unit/queue/basket_queue_hp.cpp b/test/unit/queue/basket_queue_hp.cpp new file mode 100644 index 00000000..7587bc7d --- /dev/null +++ b/test/unit/queue/basket_queue_hp.cpp @@ -0,0 +1,140 @@ +/* + 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_generic_queue.h" + +#include +#include + +namespace { + namespace cc = cds::container; + typedef cds::gc::HP gc_type; + + + class BasketQueue_HP : public cds_test::generic_queue + { + protected: + void SetUp() + { + typedef cc::BasketQueue< gc_type, int > queue_type; + + cds::gc::hp::GarbageCollector::Construct( queue_type::c_nHazardPtrCount, 1, 16 ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::hp::GarbageCollector::Destruct( true ); + } + }; + + TEST_F( BasketQueue_HP, defaulted ) + { + typedef cds::container::BasketQueue< gc_type, int > test_queue; + + test_queue q; + test(q); + } + + TEST_F( BasketQueue_HP, item_counting ) + { + typedef cds::container::BasketQueue < gc_type, int, + typename cds::container::basket_queue::make_traits < + cds::opt::item_counter < cds::atomicity::item_counter > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( BasketQueue_HP, relaxed ) + { + typedef cds::container::BasketQueue < gc_type, int, + typename cds::container::basket_queue::make_traits < + cds::opt::item_counter< cds::atomicity::item_counter > + , cds::opt::memory_model < cds::opt::v::relaxed_ordering > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( BasketQueue_HP, aligned ) + { + typedef cds::container::BasketQueue < gc_type, int, + typename cds::container::basket_queue::make_traits < + cds::opt::memory_model< cds::opt::v::relaxed_ordering> + , cds::opt::padding < 32 > + >::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( BasketQueue_HP, seq_cst ) + { + struct traits : public cc::basket_queue::traits + { + typedef cds::opt::v::sequential_consistent memory_model; + typedef cds::atomicity::item_counter item_counter; + enum { padding = 64 }; + }; + typedef cds::container::BasketQueue < gc_type, int, traits > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( BasketQueue_HP, move ) + { + typedef cds::container::BasketQueue< gc_type, std::string > test_queue; + + test_queue q; + test_string( q ); + } + + TEST_F( BasketQueue_HP, move_item_counting ) + { + struct traits : public cc::basket_queue::traits + { + typedef cds::atomicity::item_counter item_counter; + }; + typedef cds::container::BasketQueue< gc_type, std::string, traits > test_queue; + + test_queue q; + test_string( q ); + } + +} // namespace + diff --git a/test/unit/queue/fcqueue.cpp b/test/unit/queue/fcqueue.cpp new file mode 100644 index 00000000..7681ddeb --- /dev/null +++ b/test/unit/queue/fcqueue.cpp @@ -0,0 +1,245 @@ +/* + 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 + +#include + +namespace { + + class FCQueue: public ::testing::Test + { + protected: + template + void test( Queue& q ) + { + typedef typename Queue::value_type value_type; + value_type it; + + const size_t nSize = 100; + + ASSERT_TRUE( q.empty() ); + ASSERT_EQ( q.size(), 0 ); + + // enqueue/dequeue + for ( size_t i = 0; i < nSize; ++i ) { + ASSERT_TRUE( q.enqueue( static_cast(i))); + ASSERT_EQ( q.size(), i + 1 ); + } + ASSERT_FALSE( q.empty() ); + ASSERT_EQ( q.size(), nSize ); + + for ( size_t i = 0; i < nSize; ++i ) { + it = -1; + ASSERT_TRUE( q.dequeue( it )); + ASSERT_EQ( it, i ); + ASSERT_EQ( q.size(), nSize - i - 1 ); + } + ASSERT_TRUE( q.empty() ); + ASSERT_EQ( q.size(), 0 ); + + // push/pop + for ( size_t i = 0; i < nSize; ++i ) { + ASSERT_TRUE( q.push( static_cast(i))); + ASSERT_EQ( q.size(), i + 1 ); + } + ASSERT_FALSE( q.empty() ); + ASSERT_EQ( q.size(), nSize ); + + for ( size_t i = 0; i < nSize; ++i ) { + it = -1; + ASSERT_TRUE( q.pop( it ) ); + ASSERT_EQ( it, i ); + ASSERT_EQ( q.size(), nSize - i - 1 ); + } + ASSERT_TRUE( q.empty() ); + ASSERT_EQ( q.size(), 0 ); + + // clear + for ( size_t i = 0; i < nSize; ++i ) { + ASSERT_TRUE( q.push( static_cast( i ))); + } + ASSERT_FALSE( q.empty() ); + ASSERT_EQ( q.size(), nSize ); + + q.clear(); + ASSERT_TRUE( q.empty() ); + ASSERT_EQ( q.size(), 0 ); + + // pop from empty queue + it = nSize * 2; + ASSERT_FALSE( q.pop( it )); + ASSERT_EQ( it, nSize * 2 ); + ASSERT_TRUE( q.empty() ); + ASSERT_EQ( q.size(), 0 ); + + ASSERT_FALSE( q.dequeue( it ) ); + ASSERT_EQ( it, nSize * 2 ); + ASSERT_TRUE( q.empty() ); + ASSERT_EQ( q.size(), 0 ); + } + + template + void test_string( Queue& q ) + { + std::string str[3]; + str[0] = "one"; + str[1] = "two"; + str[2] = "three"; + const size_t nSize = sizeof( str ) / sizeof( str[0] ); + + // move push + for ( size_t i = 0; i < nSize; ++i ) { + std::string s = str[i]; + ASSERT_FALSE( s.empty()); + ASSERT_TRUE( q.enqueue( std::move( s ))); + ASSERT_FALSE( s.empty()); + ASSERT_EQ( q.size(), i + 1 ); + } + ASSERT_FALSE( q.empty() ); + ASSERT_EQ( q.size(), nSize ); + + for ( size_t i = 0; i < nSize; ++i ) { + std::string s; + ASSERT_TRUE( q.pop( s )); + ASSERT_EQ( q.size(), nSize - i - 1 ); + ASSERT_EQ( s, str[i] ); + } + ASSERT_TRUE( q.empty() ); + ASSERT_EQ( q.size(), 0 ); + } + }; + + TEST_F( FCQueue, std_deque ) + { + typedef cds::container::FCQueue queue_type; + + queue_type q; + test( q ); + } + + TEST_F( FCQueue, std_deque_move ) + { + typedef cds::container::FCQueue queue_type; + + queue_type q; + test_string( q ); + } + + TEST_F( FCQueue, std_deque_elimination ) + { + typedef cds::container::FCQueue>, + cds::container::fcqueue::make_traits< + cds::opt::enable_elimination< true > + >::type + > queue_type; + + queue_type q; + test( q ); + } + + TEST_F( FCQueue, std_deque_elimination_move ) + { + typedef cds::container::FCQueue>, + cds::container::fcqueue::make_traits< + cds::opt::enable_elimination< true > + >::type + > queue_type; + + queue_type q; + test_string( q ); + } + + TEST_F( FCQueue, std_deque_mutex ) + { + typedef cds::container::FCQueue>, + cds::container::fcqueue::make_traits< + cds::opt::lock_type< std::mutex > + >::type + > queue_type; + + queue_type q; + test( q ); + } + + TEST_F( FCQueue, std_list ) + { + typedef cds::container::FCQueue>> queue_type; + + queue_type q; + test( q ); + } + + TEST_F( FCQueue, std_list_move ) + { + typedef cds::container::FCQueue>> queue_type; + + queue_type q; + test_string( q ); + } + + TEST_F( FCQueue, std_list_elimination ) + { + typedef cds::container::FCQueue >, + cds::container::fcqueue::make_traits< + cds::opt::enable_elimination< true > + >::type + > queue_type; + + queue_type q; + test( q ); + } + + TEST_F( FCQueue, std_list_elimination_move ) + { + typedef cds::container::FCQueue >, + cds::container::fcqueue::make_traits< + cds::opt::enable_elimination< true > + >::type + > queue_type; + + queue_type q; + test_string( q ); + } + + TEST_F( FCQueue, std_list_mutex ) + { + typedef cds::container::FCQueue >, + cds::container::fcqueue::make_traits< + cds::opt::lock_type< std::mutex > + >::type + > queue_type; + + queue_type q; + test( q ); + } + +} // namespace diff --git a/test/unit/queue/moirqueue_dhp.cpp b/test/unit/queue/moirqueue_dhp.cpp new file mode 100644 index 00000000..e9c5b294 --- /dev/null +++ b/test/unit/queue/moirqueue_dhp.cpp @@ -0,0 +1,140 @@ +/* + 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_generic_queue.h" + +#include +#include + +namespace { + namespace cc = cds::container; + typedef cds::gc::DHP gc_type; + + + class MoirQueue_DHP : public cds_test::generic_queue + { + protected: + void SetUp() + { + typedef cc::MoirQueue< gc_type, int > queue_type; + + cds::gc::dhp::GarbageCollector::Construct( 16, queue_type::c_nHazardPtrCount ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::dhp::GarbageCollector::Destruct(); + } + }; + + TEST_F( MoirQueue_DHP, defaulted ) + { + typedef cds::container::MoirQueue< gc_type, int > test_queue; + + test_queue q; + test(q); + } + + TEST_F( MoirQueue_DHP, item_counting ) + { + typedef cds::container::MoirQueue < gc_type, int, + typename cds::container::msqueue::make_traits < + cds::opt::item_counter < cds::atomicity::item_counter > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( MoirQueue_DHP, relaxed ) + { + typedef cds::container::MoirQueue < gc_type, int, + typename cds::container::msqueue::make_traits < + cds::opt::item_counter< cds::atomicity::item_counter > + , cds::opt::memory_model < cds::opt::v::relaxed_ordering > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( MoirQueue_DHP, aligned ) + { + typedef cds::container::MoirQueue < gc_type, int, + typename cds::container::msqueue::make_traits < + cds::opt::memory_model< cds::opt::v::relaxed_ordering> + , cds::opt::padding < 32 > + >::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( MoirQueue_DHP, seq_cst ) + { + struct traits : public cc::msqueue::traits + { + typedef cds::opt::v::sequential_consistent memory_model; + typedef cds::atomicity::item_counter item_counter; + enum { padding = 64 }; + }; + typedef cds::container::MoirQueue < gc_type, int, traits > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( MoirQueue_DHP, move ) + { + typedef cds::container::MoirQueue< gc_type, std::string > test_queue; + + test_queue q; + test_string( q ); + } + + TEST_F( MoirQueue_DHP, move_item_counting ) + { + struct traits : public cc::msqueue::traits + { + typedef cds::atomicity::item_counter item_counter; + }; + typedef cds::container::MoirQueue< gc_type, std::string, traits > test_queue; + + test_queue q; + test_string( q ); + } + +} // namespace + diff --git a/test/unit/queue/moirqueue_hp.cpp b/test/unit/queue/moirqueue_hp.cpp new file mode 100644 index 00000000..3d29c36b --- /dev/null +++ b/test/unit/queue/moirqueue_hp.cpp @@ -0,0 +1,140 @@ +/* + 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_generic_queue.h" + +#include +#include + +namespace { + namespace cc = cds::container; + typedef cds::gc::HP gc_type; + + + class MoirQueue_HP : public cds_test::generic_queue + { + protected: + void SetUp() + { + typedef cc::MoirQueue< gc_type, int > queue_type; + + cds::gc::hp::GarbageCollector::Construct( queue_type::c_nHazardPtrCount, 1, 16 ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::hp::GarbageCollector::Destruct( true ); + } + }; + + TEST_F( MoirQueue_HP, defaulted ) + { + typedef cds::container::MoirQueue< gc_type, int > test_queue; + + test_queue q; + test(q); + } + + TEST_F( MoirQueue_HP, item_counting ) + { + typedef cds::container::MoirQueue < gc_type, int, + typename cds::container::msqueue::make_traits < + cds::opt::item_counter < cds::atomicity::item_counter > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( MoirQueue_HP, relaxed ) + { + typedef cds::container::MoirQueue < gc_type, int, + typename cds::container::msqueue::make_traits < + cds::opt::item_counter< cds::atomicity::item_counter > + , cds::opt::memory_model < cds::opt::v::relaxed_ordering > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( MoirQueue_HP, aligned ) + { + typedef cds::container::MoirQueue < gc_type, int, + typename cds::container::msqueue::make_traits < + cds::opt::memory_model< cds::opt::v::relaxed_ordering> + , cds::opt::padding < 32 > + >::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( MoirQueue_HP, seq_cst ) + { + struct traits : public cc::msqueue::traits + { + typedef cds::opt::v::sequential_consistent memory_model; + typedef cds::atomicity::item_counter item_counter; + enum { padding = 64 }; + }; + typedef cds::container::MoirQueue < gc_type, int, traits > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( MoirQueue_HP, move ) + { + typedef cds::container::MoirQueue< gc_type, std::string > test_queue; + + test_queue q; + test_string( q ); + } + + TEST_F( MoirQueue_HP, move_item_counting ) + { + struct traits : public cc::msqueue::traits + { + typedef cds::atomicity::item_counter item_counter; + }; + typedef cds::container::MoirQueue< gc_type, std::string, traits > test_queue; + + test_queue q; + test_string( q ); + } + +} // namespace + diff --git a/test/unit/queue/msqueue_dhp.cpp b/test/unit/queue/msqueue_dhp.cpp new file mode 100644 index 00000000..88e4e571 --- /dev/null +++ b/test/unit/queue/msqueue_dhp.cpp @@ -0,0 +1,140 @@ +/* + 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_generic_queue.h" + +#include +#include + +namespace { + namespace cc = cds::container; + typedef cds::gc::DHP gc_type; + + + class MSQueue_DHP : public cds_test::generic_queue + { + protected: + void SetUp() + { + typedef cc::MSQueue< gc_type, int > queue_type; + + cds::gc::dhp::GarbageCollector::Construct( 16, queue_type::c_nHazardPtrCount ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::dhp::GarbageCollector::Destruct(); + } + }; + + TEST_F( MSQueue_DHP, defaulted ) + { + typedef cds::container::MSQueue< gc_type, int > test_queue; + + test_queue q; + test(q); + } + + TEST_F( MSQueue_DHP, item_counting ) + { + typedef cds::container::MSQueue < gc_type, int, + typename cds::container::msqueue::make_traits < + cds::opt::item_counter < cds::atomicity::item_counter > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( MSQueue_DHP, relaxed ) + { + typedef cds::container::MSQueue < gc_type, int, + typename cds::container::msqueue::make_traits < + cds::opt::item_counter< cds::atomicity::item_counter > + , cds::opt::memory_model < cds::opt::v::relaxed_ordering > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( MSQueue_DHP, aligned ) + { + typedef cds::container::MSQueue < gc_type, int, + typename cds::container::msqueue::make_traits < + cds::opt::memory_model< cds::opt::v::relaxed_ordering> + , cds::opt::padding < 32 > + >::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( MSQueue_DHP, seq_cst ) + { + struct traits : public cc::msqueue::traits + { + typedef cds::opt::v::sequential_consistent memory_model; + typedef cds::atomicity::item_counter item_counter; + enum { padding = 64 }; + }; + typedef cds::container::MSQueue < gc_type, int, traits > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( MSQueue_DHP, move ) + { + typedef cds::container::MSQueue< gc_type, std::string > test_queue; + + test_queue q; + test_string( q ); + } + + TEST_F( MSQueue_DHP, move_item_counting ) + { + struct traits : public cc::msqueue::traits + { + typedef cds::atomicity::item_counter item_counter; + }; + typedef cds::container::MSQueue< gc_type, std::string, traits > test_queue; + + test_queue q; + test_string( q ); + } + +} // namespace + diff --git a/test/unit/queue/msqueue_hp.cpp b/test/unit/queue/msqueue_hp.cpp new file mode 100644 index 00000000..9c8f0ddc --- /dev/null +++ b/test/unit/queue/msqueue_hp.cpp @@ -0,0 +1,140 @@ +/* + 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_generic_queue.h" + +#include +#include + +namespace { + namespace cc = cds::container; + typedef cds::gc::HP gc_type; + + + class MSQueue_HP : public cds_test::generic_queue + { + protected: + void SetUp() + { + typedef cc::MSQueue< gc_type, int > queue_type; + + cds::gc::hp::GarbageCollector::Construct( queue_type::c_nHazardPtrCount, 1, 16 ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::hp::GarbageCollector::Destruct( true ); + } + }; + + TEST_F( MSQueue_HP, defaulted ) + { + typedef cds::container::MSQueue< gc_type, int > test_queue; + + test_queue q; + test(q); + } + + TEST_F( MSQueue_HP, item_counting ) + { + typedef cds::container::MSQueue < gc_type, int, + typename cds::container::msqueue::make_traits < + cds::opt::item_counter < cds::atomicity::item_counter > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( MSQueue_HP, relaxed ) + { + typedef cds::container::MSQueue < gc_type, int, + typename cds::container::msqueue::make_traits < + cds::opt::item_counter< cds::atomicity::item_counter > + , cds::opt::memory_model < cds::opt::v::relaxed_ordering > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( MSQueue_HP, aligned ) + { + typedef cds::container::MSQueue < gc_type, int, + typename cds::container::msqueue::make_traits < + cds::opt::memory_model< cds::opt::v::relaxed_ordering> + , cds::opt::padding < 32 > + >::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( MSQueue_HP, seq_cst ) + { + struct traits : public cc::msqueue::traits + { + typedef cds::opt::v::sequential_consistent memory_model; + typedef cds::atomicity::item_counter item_counter; + enum { padding = 64 }; + }; + typedef cds::container::MSQueue < gc_type, int, traits > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( MSQueue_HP, move ) + { + typedef cds::container::MSQueue< gc_type, std::string > test_queue; + + test_queue q; + test_string( q ); + } + + TEST_F( MSQueue_HP, move_item_counting ) + { + struct traits : public cc::msqueue::traits + { + typedef cds::atomicity::item_counter item_counter; + }; + typedef cds::container::MSQueue< gc_type, std::string, traits > test_queue; + + test_queue q; + test_string( q ); + } + +} // namespace + diff --git a/test/unit/queue/optimistic_queue_dhp.cpp b/test/unit/queue/optimistic_queue_dhp.cpp new file mode 100644 index 00000000..eb359973 --- /dev/null +++ b/test/unit/queue/optimistic_queue_dhp.cpp @@ -0,0 +1,140 @@ +/* + 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_generic_queue.h" + +#include +#include + +namespace { + namespace cc = cds::container; + typedef cds::gc::DHP gc_type; + + + class OptimisticQueue_DHP : public cds_test::generic_queue + { + protected: + void SetUp() + { + typedef cc::OptimisticQueue< gc_type, int > queue_type; + + cds::gc::dhp::GarbageCollector::Construct( 16, queue_type::c_nHazardPtrCount ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::dhp::GarbageCollector::Destruct(); + } + }; + + TEST_F( OptimisticQueue_DHP, defaulted ) + { + typedef cds::container::OptimisticQueue< gc_type, int > test_queue; + + test_queue q; + test(q); + } + + TEST_F( OptimisticQueue_DHP, item_counting ) + { + typedef cds::container::OptimisticQueue < gc_type, int, + typename cds::container::optimistic_queue::make_traits < + cds::opt::item_counter < cds::atomicity::item_counter > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( OptimisticQueue_DHP, relaxed ) + { + typedef cds::container::OptimisticQueue < gc_type, int, + typename cds::container::optimistic_queue::make_traits < + cds::opt::item_counter< cds::atomicity::item_counter > + , cds::opt::memory_model < cds::opt::v::relaxed_ordering > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( OptimisticQueue_DHP, aligned ) + { + typedef cds::container::OptimisticQueue < gc_type, int, + typename cds::container::optimistic_queue::make_traits < + cds::opt::memory_model< cds::opt::v::relaxed_ordering> + , cds::opt::padding < 32 > + >::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( OptimisticQueue_DHP, seq_cst ) + { + struct traits : public cc::optimistic_queue::traits + { + typedef cds::opt::v::sequential_consistent memory_model; + typedef cds::atomicity::item_counter item_counter; + enum { padding = 64 }; + }; + typedef cds::container::OptimisticQueue < gc_type, int, traits > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( OptimisticQueue_DHP, move ) + { + typedef cds::container::OptimisticQueue< gc_type, std::string > test_queue; + + test_queue q; + test_string( q ); + } + + TEST_F( OptimisticQueue_DHP, move_item_counting ) + { + struct traits : public cc::optimistic_queue::traits + { + typedef cds::atomicity::item_counter item_counter; + }; + typedef cds::container::OptimisticQueue< gc_type, std::string, traits > test_queue; + + test_queue q; + test_string( q ); + } + +} // namespace + diff --git a/test/unit/queue/optimistic_queue_hp.cpp b/test/unit/queue/optimistic_queue_hp.cpp new file mode 100644 index 00000000..7ab2de2c --- /dev/null +++ b/test/unit/queue/optimistic_queue_hp.cpp @@ -0,0 +1,140 @@ +/* + 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_generic_queue.h" + +#include +#include + +namespace { + namespace cc = cds::container; + typedef cds::gc::HP gc_type; + + + class OPtimisticQueue_HP : public cds_test::generic_queue + { + protected: + void SetUp() + { + typedef cc::OptimisticQueue< gc_type, int > queue_type; + + cds::gc::hp::GarbageCollector::Construct( queue_type::c_nHazardPtrCount, 1, 16 ); + cds::threading::Manager::attachThread(); + } + + void TearDown() + { + cds::threading::Manager::detachThread(); + cds::gc::hp::GarbageCollector::Destruct( true ); + } + }; + + TEST_F( OPtimisticQueue_HP, defaulted ) + { + typedef cds::container::OptimisticQueue< gc_type, int > test_queue; + + test_queue q; + test(q); + } + + TEST_F( OPtimisticQueue_HP, item_counting ) + { + typedef cds::container::OptimisticQueue < gc_type, int, + typename cds::container::optimistic_queue::make_traits < + cds::opt::item_counter < cds::atomicity::item_counter > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( OPtimisticQueue_HP, relaxed ) + { + typedef cds::container::OptimisticQueue < gc_type, int, + typename cds::container::optimistic_queue::make_traits < + cds::opt::item_counter< cds::atomicity::item_counter > + , cds::opt::memory_model < cds::opt::v::relaxed_ordering > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( OPtimisticQueue_HP, aligned ) + { + typedef cds::container::OptimisticQueue < gc_type, int, + typename cds::container::optimistic_queue::make_traits < + cds::opt::memory_model< cds::opt::v::relaxed_ordering> + , cds::opt::padding < 32 > + >::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( OPtimisticQueue_HP, seq_cst ) + { + struct traits : public cc::optimistic_queue::traits + { + typedef cds::opt::v::sequential_consistent memory_model; + typedef cds::atomicity::item_counter item_counter; + enum { padding = 64 }; + }; + typedef cds::container::OptimisticQueue < gc_type, int, traits > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( OPtimisticQueue_HP, move ) + { + typedef cds::container::OptimisticQueue< gc_type, std::string > test_queue; + + test_queue q; + test_string( q ); + } + + TEST_F( OPtimisticQueue_HP, move_item_counting ) + { + struct traits : public cc::optimistic_queue::traits + { + typedef cds::atomicity::item_counter item_counter; + }; + typedef cds::container::OptimisticQueue< gc_type, std::string, traits > test_queue; + + test_queue q; + test_string( q ); + } + +} // namespace + diff --git a/test/unit/queue/rwqueue.cpp b/test/unit/queue/rwqueue.cpp new file mode 100644 index 00000000..25ddfcb2 --- /dev/null +++ b/test/unit/queue/rwqueue.cpp @@ -0,0 +1,107 @@ +/* + 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_generic_queue.h" + +#include + +namespace { + namespace cc = cds::container; + + class RWQueue: public cds_test::generic_queue + {}; + + TEST_F( RWQueue, defaulted ) + { + typedef cds::container::RWQueue< int > test_queue; + + test_queue q; + test(q); + } + + TEST_F( RWQueue, item_counting ) + { + typedef cds::container::RWQueue< int, + typename cds::container::rwqueue::make_traits < + cds::opt::item_counter< cds::atomicity::item_counter > + > ::type + > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( RWQueue, mutex ) + { + struct traits : public cds::container::rwqueue::traits + { + typedef std::mutex lock_type; + }; + typedef cds::container::RWQueue< int, traits > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( RWQueue, padding ) + { + struct traits : public cds::container::rwqueue::traits + { + typedef cds::atomicity::item_counter item_counter; + enum { padding = 64 }; + }; + typedef cds::container::RWQueue< int, traits > test_queue; + + test_queue q; + test( q ); + } + + TEST_F( RWQueue, move ) + { + typedef cds::container::RWQueue< std::string > test_queue; + + test_queue q; + test_string( q ); + } + + TEST_F( RWQueue, move_item_counting ) + { + struct traits : public cc::rwqueue::traits + { + typedef cds::atomicity::item_counter item_counter; + }; + typedef cds::container::RWQueue< std::string, traits > test_queue; + + test_queue q; + test_string( q ); + } + +} // namespace + diff --git a/test/unit/queue/test_generic_queue.h b/test/unit/queue/test_generic_queue.h new file mode 100644 index 00000000..28554f06 --- /dev/null +++ b/test/unit/queue/test_generic_queue.h @@ -0,0 +1,206 @@ +/* + 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_QUEUE_TEST_GENERIC_QUEUE_H +#define CDSUNIT_QUEUE_TEST_GENERIC_QUEUE_H + +#include + +namespace cds_test { + + class generic_queue : public ::testing::Test + { + protected: + template + void test( Queue& q ) + { + typedef typename Queue::value_type value_type; + value_type it; + + const size_t nSize = 100; + + ASSERT_TRUE( q.empty() ); + ASSERT_CONTAINER_SIZE( q, 0 ); + + // enqueue/dequeue + for ( size_t i = 0; i < nSize; ++i ) { + it = static_cast(i); + ASSERT_TRUE( q.enqueue( it )); + ASSERT_CONTAINER_SIZE( q, i + 1 ); + } + ASSERT_FALSE( q.empty() ); + ASSERT_CONTAINER_SIZE( q, nSize ); + + for ( size_t i = 0; i < nSize; ++i ) { + it = -1; + ASSERT_TRUE( q.dequeue( it ) ); + ASSERT_EQ( it, i ); + ASSERT_CONTAINER_SIZE( q, nSize - i - 1 ); + } + ASSERT_TRUE( q.empty() ); + ASSERT_CONTAINER_SIZE( q, 0 ); + + // push/pop + for ( size_t i = 0; i < nSize; ++i ) { + it = static_cast(i); + ASSERT_TRUE( q.push( it )); + ASSERT_CONTAINER_SIZE( q, i + 1 ); + } + ASSERT_FALSE( q.empty() ); + ASSERT_CONTAINER_SIZE( q, nSize ); + + for ( size_t i = 0; i < nSize; ++i ) { + it = -1; + ASSERT_TRUE( q.pop( it ) ); + ASSERT_EQ( it, i ); + ASSERT_CONTAINER_SIZE( q, nSize - i - 1 ); + } + ASSERT_TRUE( q.empty() ); + ASSERT_CONTAINER_SIZE( q, 0 ); + + // push/pop with lambda + for ( size_t i = 0; i < nSize; ++i ) { + it = static_cast(i); + ASSERT_NE( it, -1 ); + auto f = [&it]( value_type& dest ) { dest = it; it = -1; }; + if ( i & 1 ) + ASSERT_TRUE( q.enqueue_with( f )); + else + ASSERT_TRUE( q.push_with( f )); + ASSERT_EQ( it, -1 ); + ASSERT_CONTAINER_SIZE( q, i + 1 ); + } + ASSERT_FALSE( q.empty() ); + ASSERT_CONTAINER_SIZE( q, nSize ); + + for ( size_t i = 0; i < nSize; ++i ) { + it = -1; + auto f = [&it]( value_type& src ) { it = src; src = -1; }; + if ( i & 1 ) + ASSERT_TRUE( q.pop_with( f )); + else + ASSERT_TRUE( q.dequeue_with( f )); + ASSERT_EQ( it, i ); + ASSERT_CONTAINER_SIZE( q, nSize - i - 1 ); + } + ASSERT_TRUE( q.empty() ); + ASSERT_CONTAINER_SIZE( q, 0 ); + + // clear + for ( size_t i = 0; i < nSize; ++i ) { + ASSERT_TRUE( q.push( static_cast(i) ) ); + } + ASSERT_FALSE( q.empty() ); + ASSERT_CONTAINER_SIZE( q, nSize ); + + q.clear(); + ASSERT_TRUE( q.empty() ); + ASSERT_CONTAINER_SIZE( q, 0 ); + + // pop from empty queue + it = nSize * 2; + ASSERT_FALSE( q.pop( it ) ); + ASSERT_EQ( it, nSize * 2 ); + ASSERT_TRUE( q.empty() ); + ASSERT_CONTAINER_SIZE( q, 0 ); + + ASSERT_FALSE( q.dequeue( it ) ); + ASSERT_EQ( it, nSize * 2 ); + ASSERT_TRUE( q.empty() ); + ASSERT_CONTAINER_SIZE( q, 0 ); + } + + template + void test_string( Queue& q ) + { + std::string str[3]; + str[0] = "one"; + str[1] = "two"; + str[2] = "three"; + const size_t nSize = sizeof( str ) / sizeof( str[0] ); + + // emplace + for ( size_t i = 0; i < nSize; ++i ) { + ASSERT_TRUE( q.emplace( str[i].c_str())); + ASSERT_CONTAINER_SIZE( q, i + 1 ); + } + ASSERT_FALSE( q.empty() ); + ASSERT_CONTAINER_SIZE( q, nSize ); + + { + std::string s; + auto f = [&s]( std::string& src ) { + ASSERT_FALSE( src.empty() ); + s = std::move( src ); + ASSERT_TRUE( src.empty() ); + }; + for ( size_t i = 0; i < nSize; ++i ) { + if ( i & 1 ) + ASSERT_TRUE( q.pop_with( f )); + else + ASSERT_TRUE( q.dequeue_with( f )); + + ASSERT_CONTAINER_SIZE( q, nSize - i - 1 ); + ASSERT_EQ( s, str[i] ); + } + } + ASSERT_TRUE( q.empty() ); + ASSERT_CONTAINER_SIZE( q, 0 ); + + + // move push + for ( size_t i = 0; i < nSize; ++i ) { + std::string s = str[i]; + ASSERT_FALSE( s.empty() ); + if ( i & 1 ) + ASSERT_TRUE( q.enqueue( std::move( s ))); + else + ASSERT_TRUE( q.push( std::move( s ))); + ASSERT_TRUE( s.empty() ); + ASSERT_CONTAINER_SIZE( q, i + 1 ); + } + ASSERT_FALSE( q.empty() ); + ASSERT_CONTAINER_SIZE( q, nSize ); + + for ( size_t i = 0; i < nSize; ++i ) { + std::string s; + ASSERT_TRUE( q.pop( s ) ); + ASSERT_CONTAINER_SIZE( q, nSize - i - 1 ); + ASSERT_EQ( s, str[i] ); + } + ASSERT_TRUE( q.empty() ); + ASSERT_CONTAINER_SIZE( q, 0 ); + } + + }; + +} // namespace cds_test + +#endif // CDSUNIT_QUEUE_TEST_GENERIC_QUEUE_H