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