Added: stress test detail level for minimizing runtime
[libcds.git] / test / stress / main.cpp
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
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.
18
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.
29 */
30
31 #include <cds_test/stress_test.h>
32
33 #include <cds/init.h>
34 #include <cds/gc/hp.h>
35 #include <cds/gc/dhp.h>
36 #ifdef CDSUNIT_USE_URCU
37 #   include <cds/urcu/general_instant.h>
38 #   include <cds/urcu/general_buffered.h>
39 #   include <cds/urcu/general_threaded.h>
40 #   include <cds/urcu/signal_buffered.h>
41 #   include <cds/urcu/signal_threaded.h>
42 #endif
43
44 int main( int argc, char **argv ) \r
45 {\r
46     int result;\r
47     cds::Initialize();\r
48     {\r
49         // Read test config file\r
50         cds_test::init_config( argc, argv );\r
51 \r
52         // Get detail level for stress test\r
53         cds_test::stress_fixture::init_detail_level( argc, argv );\r
54 \r
55         // Init Google test\r
56         ::testing::InitGoogleTest( &argc, argv );\r
57 \r
58         cds_test::config const& general_cfg = cds_test::stress_fixture::get_config( "General" );\r
59 \r
60         // Init SMR
61         cds::gc::HP hzpGC( general_cfg.get_size_t( "hazard_pointer_count", 16 ));
62         hzpGC.setScanType( general_cfg.get( "HZP_scan_strategy", "inplace" ) == "inplace" ? cds::gc::HP::scan_type::inplace : cds::gc::HP::scan_type::classic );
63
64         cds::gc::DHP dhpGC(
65             general_cfg.get_size_t( "dhp_liberate_threshold", 1024 ),
66             general_cfg.get_size_t( "dhp_init_guard_count", 16 ),
67             general_cfg.get_size_t( "dhp_epoch_count", 16 )
68         );
69
70 #ifdef CDSUNIT_USE_URCU
71         size_t rcu_buffer_size = general_cfg.get_size_t( "rcu_buffer_size", 256 );
72
73         // RCU varieties
74         typedef cds::urcu::gc< cds::urcu::general_instant<> >    rcu_gpi;
75         rcu_gpi   gpiRCU;
76
77         typedef cds::urcu::gc< cds::urcu::general_buffered<> >    rcu_gpb;
78         rcu_gpb   gpbRCU( rcu_buffer_size );
79
80         typedef cds::urcu::gc< cds::urcu::general_threaded<> >    rcu_gpt;
81         rcu_gpt   gptRCU( rcu_buffer_size );
82
83 #   ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
84         typedef cds::urcu::gc< cds::urcu::signal_buffered<> >    rcu_shb;
85         rcu_shb   shbRCU( rcu_buffer_size, SIGUSR1 );
86
87         typedef cds::urcu::gc< cds::urcu::signal_threaded<> >    rcu_sht;
88         rcu_sht   shtRCU( rcu_buffer_size, SIGUSR2 );
89 #   endif
90 #endif // CDSUNIT_USE_URCU
91 \r
92         cds::threading::Manager::attachThread();\r
93 \r
94         result =  RUN_ALL_TESTS();\r
95 \r
96         cds::threading::Manager::detachThread();\r
97     }\r
98     cds::Terminate();\r
99     return result;\r
100 }