fixed adding file problem
[c11concurrency-benchmarks.git] / gdax-orderbook-hpp / demo / dependencies / libcds-2.3.2 / test / stress / framework / config.cpp
diff --git a/gdax-orderbook-hpp/demo/dependencies/libcds-2.3.2/test/stress/framework/config.cpp b/gdax-orderbook-hpp/demo/dependencies/libcds-2.3.2/test/stress/framework/config.cpp
new file mode 100644 (file)
index 0000000..b0ad4e7
--- /dev/null
@@ -0,0 +1,158 @@
+/*\r
+    This file is a part of libcds - Concurrent Data Structures library\r
+\r
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017\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
+    }\r
+\r
+    /*static*/ config const& stress_fixture::get_config( std::string const& slot )\r
+    {\r
+        return s_cfg[ slot ];\r
+    }\r
+\r
+} // namespace cds_test\r