Improved output of stress test stat
[libcds.git] / test / stress / framework / stress_test.cpp
index b9e4d7d4d18afb8df32ce6365c0ac64e7ddced1a..220907922b1bb2671d8e8870fc881bdd4712feca 100644 (file)
@@ -1,41 +1,53 @@
-/*
-    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 <fstream>
-#include <iostream>
-#include <cds_test/stress_test.h>
+/*\r
+    This file is a part of libcds - Concurrent Data Structures library\r
+\r
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016\r
+\r
+    Source code repo: http://github.com/khizmax/libcds/\r
+    Download: http://sourceforge.net/projects/libcds/files/\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions are met:\r
+\r
+    * Redistributions of source code must retain the above copyright notice, this\r
+    list of conditions and the following disclaimer.\r
+\r
+    * Redistributions in binary form must reproduce the above copyright notice,\r
+    this list of conditions and the following disclaimer in the documentation\r
+    and/or other materials provided with the distribution.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
+    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
+    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+*/\r
+\r
+#include <fstream>\r
+#include <iostream>\r
+#include <cds_test/stress_test.h>\r
 \r
 namespace cds_test {\r
 \r
-    struct property_stream\r
-    {};\r
+    static std::string s_stat_prefix( "stat" );\r
+\r
+    /*static*/ std::string const& property_stream::stat_prefix()\r
+    {\r
+        return s_stat_prefix;\r
+    }\r
+\r
+    /*static*/ void property_stream::set_stat_prefix( char const* prefix )\r
+    {\r
+        if ( prefix && prefix[0] )\r
+            s_stat_prefix = prefix;\r
+        else\r
+            s_stat_prefix = "stat";\r
+    }\r
 \r
     /*static*/ property_stream& stress_fixture::propout()\r
     {\r
@@ -47,22 +59,22 @@ namespace cds_test {
     {\r
         std::vector<std::string> arrString;\r
 \r
-        std::ifstream s;
-        char const* filename = "./dictionary.txt";
-        s.open( filename );
-        if ( !s.is_open() ) {
-            std::cerr << "WARNING: Cannot open test file " << filename << std::endl;
-            return arrString;
-        }
+        std::ifstream s;\r
+        char const* filename = "./dictionary.txt";\r
+        s.open( filename );\r
+        if ( !s.is_open()) {\r
+            std::cerr << "WARNING: Cannot open test file " << filename << std::endl;\r
+            return arrString;\r
+        }\r
 \r
         std::string line;\r
         std::getline( s, line );\r
 \r
         arrString.reserve( std::stoul( line ));\r
 \r
-        while ( !s.eof() ) {\r
+        while ( !s.eof()) {\r
             std::getline( s, line );\r
-            if ( !line.empty() )\r
+            if ( !line.empty())\r
                 arrString.push_back( std::move( line ));\r
         }\r
 \r
@@ -71,4 +83,41 @@ namespace cds_test {
         return arrString;\r
     }\r
 \r
+\r
+    static int s_nDetailLevel = 0;\r
+\r
+    /*static*/ void stress_fixture::init_detail_level( int argc, char **argv )\r
+    {\r
+        bool found = false;\r
+        for ( int i = 0; i < argc; ++i ) {\r
+            char * arg = argv[i];\r
+            char * eq = strchr( arg, '=' );\r
+            if ( eq ) {\r
+                if ( strncmp( arg, "--detail_level", eq - arg ) == 0 || strncmp( arg, "--detail-level", eq - arg ) == 0 ) {\r
+                    s_nDetailLevel = atoi( eq + 1 );\r
+                    found = true;\r
+                }\r
+            }\r
+        }\r
+\r
+        if ( !found ) {\r
+            // Get detail level from environment variable\r
+            char const * env = getenv( "CDSTEST_DETAIL_LEVEL" );\r
+            if ( env && env[0] )\r
+                s_nDetailLevel = atoi( env );\r
+        }\r
+\r
+        std::cout << "Stress test detail level=" << s_nDetailLevel << std::endl;\r
+    }\r
+\r
+    /*static*/ bool stress_fixture::check_detail_level( int nLevel )\r
+    {\r
+        if ( nLevel <= s_nDetailLevel )\r
+            return true;\r
+\r
+        std::cout << "Skipped (detail level=" << nLevel << ")" << std::endl;\r
+        propout() << std::make_pair( "skipped", 1 );\r
+        return false;\r
+    }\r
+\r
 } // namespace\r