Improved value-parameterized test f intrusive stack
authorkhizmax <libcds.dev@gmail.com>
Fri, 26 Feb 2016 21:58:48 +0000 (00:58 +0300)
committerkhizmax <libcds.dev@gmail.com>
Fri, 26 Feb 2016 21:58:48 +0000 (00:58 +0300)
projects/Win/vc14/cds.sln
test/include/cds_test/fixture.h
test/stress/main.cpp
test/stress/stack/intrusive_push_pop_fcstack.cpp
test/stress/stack/intrusive_stack_push_pop.h

index 3195f4a9fb9b27854dbd536c5646b9a541247d90..dd3385d2e504e0502a38f5845b60d21d9f90fd1a 100644 (file)
@@ -176,6 +176,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cds_test", "cds_test", "{3A
        ProjectSection(SolutionItems) = preProject\r
                ..\..\..\test\include\cds_test\check_size.h = ..\..\..\test\include\cds_test\check_size.h\r
                ..\..\..\test\include\cds_test\fixture.h = ..\..\..\test\include\cds_test\fixture.h\r
        ProjectSection(SolutionItems) = preProject\r
                ..\..\..\test\include\cds_test\check_size.h = ..\..\..\test\include\cds_test\check_size.h\r
                ..\..\..\test\include\cds_test\fixture.h = ..\..\..\test\include\cds_test\fixture.h\r
+               ..\..\..\test\include\cds_test\stress_test.h = ..\..\..\test\include\cds_test\stress_test.h\r
                ..\..\..\test\include\cds_test\thread.h = ..\..\..\test\include\cds_test\thread.h\r
        EndProjectSection\r
 EndProject\r
                ..\..\..\test\include\cds_test\thread.h = ..\..\..\test\include\cds_test\thread.h\r
        EndProjectSection\r
 EndProject\r
index aa9fcffe358916ce09be49dc240eb3c49c0015b2..f8835e3a969658ecba9d029ba04a807259db783e 100644 (file)
 #include <algorithm>
 #include <random>
 
 #include <algorithm>
 #include <random>
 
+// earlier version of gtest do not support 4th parameter in INSTANTIATE_TEST_CASE_P macro
+//TODO: how to known gtest version?..
+//#define CDSTEST_GTEST_INSTANTIATE_TEST_CASE_P_HAS_4TH_ARG
+
 namespace cds_test {
 
     class fixture : public ::testing::Test
 namespace cds_test {
 
     class fixture : public ::testing::Test
index 1b15a13026d71b1bd4523ad003dde63467e75bdc..ce60231ee997ebdc4a8538dee5594b365ab9c528 100644 (file)
@@ -46,11 +46,12 @@ int main( int argc, char **argv )
     int result;\r
     cds::Initialize();\r
     {\r
     int result;\r
     cds::Initialize();\r
     {\r
-        ::testing::InitGoogleTest( &argc, argv );\r
-\r
         // Read test config file\r
         cds_test::init_config( argc, argv );\r
 \r
         // Read test config file\r
         cds_test::init_config( argc, argv );\r
 \r
+        // Init Google test\r
+        ::testing::InitGoogleTest( &argc, argv );\r
+\r
         cds_test::config const& general_cfg = cds_test::stress_fixture::get_config( "General" );\r
 \r
         // Init SMR
         cds_test::config const& general_cfg = cds_test::stress_fixture::get_config( "General" );\r
 \r
         // Init SMR
index abb70ce46daf20b965c9cc968efa64f1ec129756..cc5f5e99c34d10b7d7f9b5e1b0e8934735714f57 100644 (file)
@@ -38,8 +38,6 @@ namespace {
         unsigned int nCombinePassCount;
     };
 
         unsigned int nCombinePassCount;
     };
 
-    static std::vector< fc_param > m_args;
-
     class intrusive_fcstack_push_pop
         : public cds_test::intrusive_stack_push_pop
         , public ::testing::WithParamInterface< fc_param >
     class intrusive_fcstack_push_pop
         : public cds_test::intrusive_stack_push_pop
         , public ::testing::WithParamInterface< fc_param >
@@ -47,45 +45,83 @@ namespace {
         typedef cds_test::intrusive_stack_push_pop base_class;
 
     public:
         typedef cds_test::intrusive_stack_push_pop base_class;
 
     public:
-        static void SetUpTestCase()
-        {
-            base_class::SetUpTestCase();
 
 
-            if ( s_bFCIterative ) {
-                for ( unsigned int nCompactFactor = 1; nCompactFactor <= s_nFCCompactFactor; nCompactFactor *= 2 ) {
-                    for ( unsigned int nPass = 1; nPass <= s_nFCCombinePassCount; nPass *= 2 )
-                        m_args.push_back( { nCompactFactor, nPass } );
+        static std::vector< fc_param > get_test_parameters()
+        {
+            cds_test::config const& cfg = cds_test::stress_fixture::get_config( "IntrusiveStack_PushPop" );
+            bool bFCIterative = cfg.get_bool( "FCIterate", s_bFCIterative );
+            unsigned int nFCCombinePassCount = cfg.get_uint( "FCCombinePassCount", s_nFCCombinePassCount );
+            unsigned int nFCCompactFactor = cfg.get_uint( "FCCompactFactor", s_nFCCompactFactor );
+
+            std::vector< fc_param > args;
+            if ( bFCIterative ) {
+                for ( unsigned int nCompactFactor = 1; nCompactFactor <= nFCCompactFactor; nCompactFactor *= 2 ) {
+                    for ( unsigned int nPass = 1; nPass <= nFCCombinePassCount; nPass *= 2 )
+                        args.push_back( { nCompactFactor, nPass } );
                 }
             }
 
                 }
             }
 
-            if ( m_args.empty())
-                m_args.push_back( { 1, 1 } );
+            if ( args.empty() ) {
+                if ( nFCCompactFactor && nFCCombinePassCount )
+                    args.push_back( { nFCCompactFactor, nFCCombinePassCount } );
+                else
+                    args.push_back( { 0, 0 } );
+            }
+
+            return args;
         }
         }
-        static void TearDownTestCase()
+
+#ifdef CDSTEST_GTEST_INSTANTIATE_TEST_CASE_P_HAS_4TH_ARG
+        static std::string get_test_parameter_name( testing::TestParamInfo<fc_param> const& p )
         {
         {
-            m_args.clear();
+            if ( p.param.nCombinePassCount ) {
+                std::stringstream ss;
+                ss << "compact_factor" << p.param.nCompactFactor
+                   << "__combine_pass_count" << p.param.nCombinePassCount
+                   ;
+                return ss.str();
+            }
+            else {
+                return std::string( "with_defaults" );
+            }
         }
         }
+#endif
 
     protected:
         typedef base_class::value_type<boost::intrusive::slist_base_hook<>> slist_value_type;
         typedef base_class::value_type<boost::intrusive::list_base_hook<>>  list_value_type;
 
 
     protected:
         typedef base_class::value_type<boost::intrusive::slist_base_hook<>> slist_value_type;
         typedef base_class::value_type<boost::intrusive::list_base_hook<>>  list_value_type;
 
-
         template <typename Stack>
         void test()
         {
             value_array<typename Stack::value_type> arrValue( s_nStackSize );
             if ( s_bFCIterative ) {
                 fc_param arg = GetParam();
         template <typename Stack>
         void test()
         {
             value_array<typename Stack::value_type> arrValue( s_nStackSize );
             if ( s_bFCIterative ) {
                 fc_param arg = GetParam();
-                propout() 
-                    << std::make_pair( "compact_factor", arg.nCompactFactor )
-                    << std::make_pair( "combine_pass_count", arg.nCombinePassCount );
-                Stack stack( arg.nCompactFactor, arg.nCombinePassCount );
-                do_test( stack, arrValue );
+                if ( arg.nCombinePassCount ) {
+                    propout() 
+                        << std::make_pair( "compact_factor", arg.nCompactFactor )
+                        << std::make_pair( "combine_pass_count", arg.nCombinePassCount );
+                    Stack stack( arg.nCompactFactor, arg.nCombinePassCount );
+                    do_test( stack, arrValue );
+                }
+                else {
+                    Stack stack;
+                    do_test( stack, arrValue );
+                }
             }
             else {
             }
             else {
-                Stack stack;
-                do_test( stack, arrValue );
+                fc_param arg = GetParam();
+                if ( arg.nCombinePassCount ) {
+                    propout()
+                        << std::make_pair( "compact_factor", arg.nCompactFactor )
+                        << std::make_pair( "combine_pass_count", arg.nCombinePassCount );
+                    Stack stack( arg.nCompactFactor, arg.nCombinePassCount );
+                    do_test( stack, arrValue );
+                }
+                else {
+                    Stack stack;
+                    do_test( stack, arrValue );
+                }
             }
         }
     };
             }
         }
     };
@@ -116,5 +152,14 @@ namespace {
 
 } // namespace
 
 
 } // namespace
 
-INSTANTIATE_TEST_CASE_P( FC, intrusive_fcstack_push_pop, ::testing::ValuesIn( m_args ));
+#ifdef CDSTEST_GTEST_INSTANTIATE_TEST_CASE_P_HAS_4TH_ARG
+INSTANTIATE_TEST_CASE_P( FC,
+    intrusive_fcstack_push_pop,
+    ::testing::ValuesIn( intrusive_fcstack_push_pop::get_test_parameters()),
+    intrusive_fcstack_push_pop::get_test_parameter_name );
+#else
+INSTANTIATE_TEST_CASE_P( FC,
+    intrusive_fcstack_push_pop,
+    ::testing::ValuesIn( intrusive_fcstack_push_pop::get_test_parameters()));
+#endif
 
 
index 58538e172148507d6103ba701feb9b43a6c7f1b4..7770d479f2126bc3ad36513dbc9004b93d038bee 100644 (file)
@@ -193,10 +193,11 @@ namespace cds_test {
             T * get() const { return m_pArr.get(); }
         };
 
             T * get() const { return m_pArr.get(); }
         };
 
-    protected:
+    public:
         static void SetUpTestCase();
         //static void TearDownTestCase();
 
         static void SetUpTestCase();
         //static void TearDownTestCase();
 
+    protected:
         template <class Stack>
         void analyze( Stack& stack )
         {
         template <class Stack>
         void analyze( Stack& stack )
         {