Stress tests: removed command line parameter --detail-level and envvar CDSTEST_DETAIL...
[libcds.git] / test / include / cds_test / stress_test.h
index eac2b7e3dc5b0477274fa0eea0f50e6105580233..e985fc44d71ef5e753203395dd846fa37b65573a 100644 (file)
@@ -1,7 +1,7 @@
 /*
     This file is a part of libcds - Concurrent Data Structures library
 
-    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
 
     Source code repo: http://github.com/khizmax/libcds/
     Download: http://sourceforge.net/projects/libcds/files/
@@ -45,7 +45,7 @@ namespace cds_test {
         {
             std::string strParamName( pszParamName );
             auto it = m_Cfg.find( strParamName );
-            if ( it == m_Cfg.end() )
+            if ( it == m_Cfg.end())
                 return std::string( pszDefVal ); // param not found -> returns default value
             return it->second;
         }
@@ -54,7 +54,7 @@ namespace cds_test {
         {
             std::string strParamName( pszParamName );
             cfg_map::const_iterator it = m_Cfg.find( strParamName );
-            if ( it == m_Cfg.end() )
+            if ( it == m_Cfg.end())
                 return defVal; // param not found -> returns default value
             return atoi( it->second.c_str());
         }
@@ -63,7 +63,7 @@ namespace cds_test {
         {
             std::string strParamName( pszParamName );
             cfg_map::const_iterator it = m_Cfg.find( strParamName );
-            if ( it == m_Cfg.end() )
+            if ( it == m_Cfg.end())
                 return defVal; // param not found -> returns default value
             return static_cast<unsigned int>( strtoul( it->second.c_str(), NULL, 10 ));
         }
@@ -72,7 +72,7 @@ namespace cds_test {
         {
             std::string strParamName( pszParamName );
             cfg_map::const_iterator it = m_Cfg.find( strParamName );
-            if ( it == m_Cfg.end() )
+            if ( it == m_Cfg.end())
                 return defVal; // param not found -> returns default value
             return strtol( it->second.c_str(), NULL, 10 );
         }
@@ -81,7 +81,7 @@ namespace cds_test {
         {
             std::string strParamName( pszParamName );
             cfg_map::const_iterator it = m_Cfg.find( strParamName );
-            if ( it == m_Cfg.end() )
+            if ( it == m_Cfg.end())
                 return defVal; // param not found -> returns default value
             return strtoul( it->second.c_str(), NULL, 10 );
         }
@@ -90,7 +90,7 @@ namespace cds_test {
         {
             std::string strParamName( pszParamName );
             cfg_map::const_iterator it = m_Cfg.find( strParamName );
-            if ( it == m_Cfg.end() )
+            if ( it == m_Cfg.end())
                 return defVal; // param not found -> returns default value
             return static_cast<size_t>( strtoul( it->second.c_str(), NULL, 10 ));
         }
@@ -99,10 +99,10 @@ namespace cds_test {
         {
             std::string strParamName( pszParamName );
             cfg_map::const_iterator it = m_Cfg.find( strParamName );
-            if ( it == m_Cfg.end() )
+            if ( it == m_Cfg.end())
                 return defVal; // param not found -> returns default value
-            return !( it->second.empty() 
-                   || it->second == "0" 
+            return !( it->second.empty()
+                   || it->second == "0"
                    || it->second == "false"
                    || it->second == "no"
                    );
@@ -115,10 +115,34 @@ namespace cds_test {
         friend class config_file;
     };
 
-    struct property_stream;
+    class property_stream
+    {
+    public:
+        static std::string const& stat_prefix();
+        static void set_stat_prefix( char const* prefix );
+    };
+
+    struct stat_prefix
+    {
+        char const* prefix_;
+
+        stat_prefix()
+            : prefix_( nullptr )
+        {}
+
+        stat_prefix( char const* prefix )
+            : prefix_( prefix )
+        {}
+    };
+
+    static inline property_stream& operator<<( property_stream& s, stat_prefix&& prefix )
+    {
+        s.set_stat_prefix( prefix.prefix_ );
+        return s;
+    }
 
     template <typename T>
-    static inline property_stream& operator <<( property_stream& s, std::pair<char const *, T > prop )
+    static inline property_stream& operator <<( property_stream& s, std::pair<char const*, T > prop )
     {
         std::stringstream ss;
         ss << prop.second;
@@ -126,40 +150,60 @@ namespace cds_test {
         return s;
     }
 
-    static inline property_stream& operator <<( property_stream& s, std::pair<char const *, std::chrono::milliseconds > prop )
+    template <typename T>
+    static inline property_stream& operator <<( property_stream& s, std::pair<std::string, T > prop )
+    {
+        std::stringstream ss;
+        ss << prop.second;
+        ::testing::Test::RecordProperty( prop.first.c_str(), ss.str().c_str());
+        return s;
+    }
+
+    static inline property_stream& operator <<( property_stream& s, std::pair<char const*, std::chrono::milliseconds > prop )
     {
         std::stringstream ss;
         ss << prop.second.count();
-        ::testing::Test::RecordProperty( prop.first, ss.str().c_str() );
+        ::testing::Test::RecordProperty( prop.first, ss.str().c_str());
         return s;
     }
 
 #define CDSSTRESS_STAT_OUT_( name, val ) std::make_pair( name, val )
-#define CDSSTRESS_STAT_OUT( s, field ) CDSSTRESS_STAT_OUT_( "stat." #field, s.field.get())
+#define CDSSTRESS_STAT_OUT( s, field ) CDSSTRESS_STAT_OUT_( property_stream::stat_prefix() + "." #field, s.field.get())
 
     class stress_fixture : public fixture
     {
+        typedef fixture base_class;
+
     protected:
         stress_fixture()
             : m_thread_pool( *this )
         {}
 
-        //static void SetUpTestCase();\r
-        //static void TearDownTestCase();\r
-\r
-        thread_pool& get_pool()\r
-        {\r
-            return m_thread_pool;\r
-        }\r
-\r
-        static property_stream& propout();\r
-\r
-    public:\r
-        static config const& get_config( char const * slot );\r
-        static config const& get_config( std::string const& slot );\r
-\r
-    private:\r
-        thread_pool     m_thread_pool;\r
+        //static void SetUpTestCase();
+        //static void TearDownTestCase();
+        void TearDown()
+        {
+            print_hp_stat();
+            base_class::TearDown();
+        }
+
+        thread_pool& get_pool()
+        {
+            return m_thread_pool;
+        }
+
+        static void print_hp_stat();
+
+    public:
+        static config const& get_config( char const * slot );
+        static config const& get_config( std::string const& slot );
+
+        static std::vector<std::string> load_dictionary();
+
+        static property_stream& propout();
+
+    private:
+        thread_pool     m_thread_pool;
     };