Added different bit_reversal algo to SplitListSet/Map stress test
[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         std::cout << "Hardware concurrency: " << std::thread::hardware_concurrency() << "\n";\r
59 \r
60         // Init Google test\r
61         ::testing::InitGoogleTest( &argc, argv );\r
62 \r
63         cds_test::config const& general_cfg = cds_test::stress_fixture::get_config( "General" );\r
64 \r
65         // Init SMR\r
66         cds::gc::HP hzpGC( \r
67             general_cfg.get_size_t( "hazard_pointer_count", 16 ),\r
68             general_cfg.get_size_t( "hp_max_thread_count", 0 ),\r
69             general_cfg.get_size_t( "hp_retired_ptr_count", 0 ),\r
70             general_cfg.get( "hp_scan_strategy", "inplace" ) == "inplace" ? cds::gc::HP::scan_type::inplace : cds::gc::HP::scan_type::classic\r
71         );\r
72 \r
73         cds::gc::DHP dhpGC(\r
74             general_cfg.get_size_t( "dhp_init_guard_count", 16 )\r
75         );\r
76 \r
77 #ifdef CDSUNIT_USE_URCU\r
78         size_t rcu_buffer_size = general_cfg.get_size_t( "rcu_buffer_size", 256 );\r
79 \r
80         // RCU varieties\r
81         typedef cds::urcu::gc< cds::urcu::general_instant<> >    rcu_gpi;\r
82         rcu_gpi   gpiRCU;\r
83 \r
84         typedef cds::urcu::gc< cds::urcu::general_buffered<> >    rcu_gpb;\r
85         rcu_gpb   gpbRCU( rcu_buffer_size );\r
86 \r
87         typedef cds::urcu::gc< cds::urcu::general_threaded<> >    rcu_gpt;\r
88         rcu_gpt   gptRCU( rcu_buffer_size );\r
89 \r
90 #   ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED\r
91         typedef cds::urcu::gc< cds::urcu::signal_buffered<> >    rcu_shb;\r
92         rcu_shb   shbRCU( rcu_buffer_size, SIGUSR1 );\r
93 \r
94         typedef cds::urcu::gc< cds::urcu::signal_threaded<> >    rcu_sht;\r
95         rcu_sht   shtRCU( rcu_buffer_size, SIGUSR2 );\r
96 #   endif\r
97 #endif // CDSUNIT_USE_URCU\r
98 \r
99         cds::threading::Manager::attachThread();\r
100 \r
101         result =  RUN_ALL_TESTS();\r
102 \r
103         cds::threading::Manager::detachThread();\r
104     }\r
105 \r
106 #ifdef CDS_ENABLE_HPSTAT\r
107     {\r
108         cds::gc::HP::stat const& st = cds::gc::HP::postmortem_statistics();\r
109         EXPECT_EQ( st.guard_allocated, st.guard_freed );\r
110         EXPECT_EQ( st.retired_count, st.free_count );\r
111         std::cout << st;\r
112     }\r
113     {\r
114         cds::gc::DHP::stat const& st = cds::gc::DHP::postmortem_statistics();\r
115         EXPECT_EQ( st.guard_allocated, st.guard_freed );\r
116         EXPECT_EQ( st.retired_count, st.free_count );\r
117         std::cout << st;\r
118     }\r
119 #endif\r
120 \r
121     cds::Terminate();\r
122 \r
123     return result;\r
124 }\r