2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <cds_test/stress_test.h>
40 std::map< std::string, config> m_cfg;
44 void load( const char * fileName );
46 config const& operator[]( const std::string& testName ) const
48 auto it = m_cfg.find( testName );
49 if ( it != m_cfg.end() )
55 void config_file::load( const char * fileName )
60 std::cerr << "WARNING: Cannot open test cfg file " << fileName
61 << "\n\tUse default settings"
66 std::cout << "Using test config file: " << fileName << std::endl;
70 config * pMap = nullptr;
72 s.getline( buf, sizeof( buf ) / sizeof( buf[0] ) );
75 while ( *pszStr != 0 && (*pszStr == ' ' || *pszStr == '\t') ) ++pszStr;
77 char * pszEnd = strchr( pszStr, 0 );
78 if ( pszEnd == pszStr ) // empty srtring
81 while ( pszEnd != pszStr && (*pszEnd == ' ' || *pszEnd == '\t' || *pszEnd == '\n' || *pszEnd == '\r') ) --pszEnd;
83 if ( pszStr == pszEnd ) // empty string
88 if ( *pszStr == '#' ) // comment
91 if ( *pszStr == '[' && *pszEnd == ']' ) { // chapter header
93 pMap = &(m_cfg[pszStr + 1]);
100 char * pszEq = strchr( pszStr, '=' );
103 if ( pszEq == pszStr )
107 while ( pszStr <= --pszEnd && (*pszEnd == ' ' || *pszEnd == '\t' || *pszEnd == '\n' || *pszEnd == '\r') );
109 if ( pszEnd <= pszStr )
112 pMap->m_Cfg[pszStr] = pszEq + 1;
117 static config_file s_cfg;
119 void init_config( int argc, char **argv )
121 #if defined(_DEBUG) || !defined(NDEBUG)
122 char const * default_cfg_file = "./test-debug.conf";
124 char const * default_cfg_file = "./test.conf";
126 char const * cfg_file = NULL;
127 for ( int i = 0; i < argc; ++i ) {
128 char * arg = argv[i];
129 char * eq = strchr( arg, '=' );
131 if ( strncmp( arg, "--cfg", eq - arg ) == 0 )
137 // Get cfg filename from environment variable
138 cfg_file = getenv( "CDSTEST_CFG" );
141 if ( !cfg_file || *cfg_file == 0 )
142 cfg_file = default_cfg_file;
144 ::testing::Test::RecordProperty( "config_file", cfg_file );
145 s_cfg.load( cfg_file );
148 /*static*/ config const& stress_fixture::get_config( char const * slot )
\r
150 return s_cfg[std::string( slot )];
\r
153 /*static*/ config const& stress_fixture::get_config( std::string const& slot )
\r
155 return s_cfg[ slot ];
\r
158 } // namespace cds_test