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