Removed trailing spaces
[libcds.git] / test / stress / framework / config.cpp
index 2ba8ce222b51158af3088449a77b6e350f1a41a1..f414c0da29dfdfc7ae3c091aca76617076a1228c 100644 (file)
-/*
-    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>
-
-namespace cds_test {
-
-    class config_file
-    {
-        std::map< std::string, config>  m_cfg;
-        config                          m_emptyCfg;
-
-    public:
-        void load( const char * fileName );
-
-        config const& operator[]( const std::string& testName ) const
-        {
-            auto it = m_cfg.find( testName );
-            if ( it != m_cfg.end() )
-                return it->second;
-            return m_emptyCfg;
-        }
-    };
-
-    void config_file::load( const char * fileName )
-    {
-        std::ifstream s;
-        s.open( fileName );
-        if ( !s.is_open() ) {
-            std::cerr << "WARNING: Cannot open test cfg file " << fileName
-                << "\n\tUse default settings"
-                << std::endl;
-            return;
-        }
-
-        std::cout << "Using test config file: " << fileName << std::endl;
-
-        char buf[4096];
-
-        config * pMap = nullptr;
-        while ( !s.eof() ) {
-            s.getline( buf, sizeof( buf ) / sizeof( buf[0] ) );
-            char * pszStr = buf;
-            // trim left
-            while ( *pszStr != 0 && (*pszStr == ' ' || *pszStr == '\t') ) ++pszStr;
-            // trim right
-            char * pszEnd = strchr( pszStr, 0 );
-            if ( pszEnd == pszStr )    // empty srtring
-                continue;
-            --pszEnd;
-            while ( pszEnd != pszStr && (*pszEnd == ' ' || *pszEnd == '\t' || *pszEnd == '\n' || *pszEnd == '\r') ) --pszEnd;
-
-            if ( pszStr == pszEnd )    // empty string
-                continue;
-
-            pszEnd[1] = 0;
-
-            if ( *pszStr == '#' )    // comment
-                continue;
-
-            if ( *pszStr == '[' && *pszEnd == ']' ) {    // chapter header
-                *pszEnd = 0;
-                pMap = &(m_cfg[pszStr + 1]);
-                continue;
-            }
-
-            if ( !pMap )
-                continue;
-
-            char * pszEq = strchr( pszStr, '=' );
-            if ( !pszEq )
-                continue;
-            if ( pszEq == pszStr )
-                continue;
-
-            pszEnd = pszEq;
-            while ( pszStr <= --pszEnd && (*pszEnd == ' ' || *pszEnd == '\t' || *pszEnd == '\n' || *pszEnd == '\r') );
-
-            if ( pszEnd <= pszStr )
-                continue;
-            pszEnd[1] = 0;
-            pMap->m_Cfg[pszStr] = pszEq + 1;
-        }
-        s.close();
-    }
-
-    static config_file s_cfg;
-
-    void init_config( int argc, char **argv )
-    {
-#if defined(_DEBUG) || !defined(NDEBUG)
-        char const * default_cfg_file = "./test-debug.conf";
-#else
-        char const * default_cfg_file = "./test.conf";
-#endif
-        char const * cfg_file = NULL;
-        for ( int i = 0; i < argc; ++i ) {
-            char * arg = argv[i];
-            char * eq = strchr( arg, '=' );
-            if ( eq ) {
-                if ( strncmp( arg, "--cfg", eq - arg ) == 0 )
-                    cfg_file = eq + 1;
-            }
-        }
-
-        if ( !cfg_file ) {
-            // Get cfg filename from environment variable
-            cfg_file = getenv( "CDSTEST_CFG" );
-        }
-
-        if ( !cfg_file || *cfg_file == 0 )
-            cfg_file = default_cfg_file;
-
-        ::testing::Test::RecordProperty( "config_file", cfg_file );
-        s_cfg.load( cfg_file );
-    }
-
+/*\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
+\r
+#include <cds_test/stress_test.h>\r
+\r
+namespace cds_test {\r
+\r
+    class config_file\r
+    {\r
+        std::map< std::string, config>  m_cfg;\r
+        config                          m_emptyCfg;\r
+\r
+    public:\r
+        void load( const char * fileName );\r
+\r
+        config const& operator[]( const std::string& testName ) const\r
+        {\r
+            auto it = m_cfg.find( testName );\r
+            if ( it != m_cfg.end() )\r
+                return it->second;\r
+            return m_emptyCfg;\r
+        }\r
+    };\r
+\r
+    void config_file::load( const char * fileName )\r
+    {\r
+        std::ifstream s;\r
+        s.open( fileName );\r
+        if ( !s.is_open() ) {\r
+            std::cerr << "WARNING: Cannot open test cfg file " << fileName\r
+                << "\n\tUse default settings"\r
+                << std::endl;\r
+            return;\r
+        }\r
+\r
+        std::cout << "Using test config file: " << fileName << std::endl;\r
+\r
+        char buf[4096];\r
+\r
+        config * pMap = nullptr;\r
+        while ( !s.eof() ) {\r
+            s.getline( buf, sizeof( buf ) / sizeof( buf[0] ) );\r
+            char * pszStr = buf;\r
+            // trim left\r
+            while ( *pszStr != 0 && (*pszStr == ' ' || *pszStr == '\t') ) ++pszStr;\r
+            // trim right\r
+            char * pszEnd = strchr( pszStr, 0 );\r
+            if ( pszEnd == pszStr )    // empty srtring\r
+                continue;\r
+            --pszEnd;\r
+            while ( pszEnd != pszStr && (*pszEnd == ' ' || *pszEnd == '\t' || *pszEnd == '\n' || *pszEnd == '\r') ) --pszEnd;\r
+\r
+            if ( pszStr == pszEnd )    // empty string\r
+                continue;\r
+\r
+            pszEnd[1] = 0;\r
+\r
+            if ( *pszStr == '#' )    // comment\r
+                continue;\r
+\r
+            if ( *pszStr == '[' && *pszEnd == ']' ) {    // chapter header\r
+                *pszEnd = 0;\r
+                pMap = &(m_cfg[pszStr + 1]);\r
+                continue;\r
+            }\r
+\r
+            if ( !pMap )\r
+                continue;\r
+\r
+            char * pszEq = strchr( pszStr, '=' );\r
+            if ( !pszEq )\r
+                continue;\r
+            if ( pszEq == pszStr )\r
+                continue;\r
+\r
+            pszEnd = pszEq;\r
+            while ( pszStr <= --pszEnd && (*pszEnd == ' ' || *pszEnd == '\t' || *pszEnd == '\n' || *pszEnd == '\r') );\r
+\r
+            if ( pszEnd <= pszStr )\r
+                continue;\r
+            pszEnd[1] = 0;\r
+            pMap->m_Cfg[pszStr] = pszEq + 1;\r
+        }\r
+        s.close();\r
+    }\r
+\r
+    static config_file s_cfg;\r
+\r
+    void init_config( int argc, char **argv )\r
+    {\r
+#if defined(_DEBUG) || !defined(NDEBUG)\r
+        char const * default_cfg_file = "./test-debug.conf";\r
+#else\r
+        char const * default_cfg_file = "./test.conf";\r
+#endif\r
+        char const * cfg_file = NULL;\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, "--cfg", eq - arg ) == 0 )\r
+                    cfg_file = eq + 1;\r
+            }\r
+        }\r
+\r
+        if ( !cfg_file ) {\r
+            // Get cfg filename from environment variable\r
+            cfg_file = getenv( "CDSTEST_CFG" );\r
+        }\r
+\r
+        if ( !cfg_file || *cfg_file == 0 )\r
+            cfg_file = default_cfg_file;\r
+\r
+        ::testing::Test::RecordProperty( "config_file", cfg_file );\r
+        s_cfg.load( cfg_file );\r
+    }\r
+\r
     /*static*/ config const& stress_fixture::get_config( char const * slot )\r
     {\r
         return s_cfg[std::string( slot )];\r
@@ -154,5 +154,5 @@ namespace cds_test {
     {\r
         return s_cfg[ slot ];\r
     }\r
-
-} // namespace cds_test
+\r
+} // namespace cds_test\r