[SkipList] Added random-lvel generators for max height 32/24/16
[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 #endif\r
42 \r
43 #ifdef CDS_ENABLE_HPSTAT\r
44 #   include <cds_test/stat_hp_out.h>\r
45 #   include <cds_test/stat_dhp_out.h>\r
46 #   include <iostream>\r
47 #endif\r
48 \r
49 int main( int argc, char **argv )\r
50 {\r
51     int result;\r
52     cds::Initialize();\r
53     {\r
54         // Read test config file\r
55         cds_test::init_config( argc, argv );\r
56 \r
57         std::cout << "Hardware concurrency: " << std::thread::hardware_concurrency() << "\n";\r
58 \r
59         // Init Google test\r
60         ::testing::InitGoogleTest( &argc, argv );\r
61 \r
62         cds_test::config const& general_cfg = cds_test::stress_fixture::get_config( "General" );\r
63 \r
64         // Init SMR\r
65         cds::gc::HP hzpGC( \r
66             general_cfg.get_size_t( "hazard_pointer_count", 16 ),\r
67             general_cfg.get_size_t( "hp_max_thread_count", 0 ),\r
68             general_cfg.get_size_t( "hp_retired_ptr_count", 0 ),\r
69             general_cfg.get( "hp_scan_strategy", "inplace" ) == "inplace" ? cds::gc::HP::scan_type::inplace : cds::gc::HP::scan_type::classic\r
70         );\r
71 \r
72         cds::gc::DHP dhpGC(\r
73             general_cfg.get_size_t( "dhp_init_guard_count", 16 )\r
74         );\r
75 \r
76 #ifdef CDSUNIT_USE_URCU\r
77         size_t rcu_buffer_size = general_cfg.get_size_t( "rcu_buffer_size", 256 );\r
78 \r
79         // RCU varieties\r
80         typedef cds::urcu::gc< cds::urcu::general_instant<> >    rcu_gpi;\r
81         rcu_gpi   gpiRCU;\r
82 \r
83         typedef cds::urcu::gc< cds::urcu::general_buffered<> >    rcu_gpb;\r
84         rcu_gpb   gpbRCU( rcu_buffer_size );\r
85 \r
86         typedef cds::urcu::gc< cds::urcu::general_threaded<> >    rcu_gpt;\r
87         rcu_gpt   gptRCU( rcu_buffer_size );\r
88 \r
89 #   ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED\r
90         typedef cds::urcu::gc< cds::urcu::signal_buffered<> >    rcu_shb;\r
91         rcu_shb   shbRCU( rcu_buffer_size, SIGUSR1 );\r
92 #   endif\r
93 #endif // CDSUNIT_USE_URCU\r
94 \r
95         cds::threading::Manager::attachThread();\r
96 \r
97         result =  RUN_ALL_TESTS();\r
98 \r
99         cds::threading::Manager::detachThread();\r
100     }\r
101 \r
102 #ifdef CDS_ENABLE_HPSTAT\r
103     {\r
104         cds::gc::HP::stat const& st = cds::gc::HP::postmortem_statistics();\r
105         EXPECT_EQ( st.guard_allocated, st.guard_freed );\r
106         EXPECT_EQ( st.retired_count, st.free_count );\r
107         std::cout << st;\r
108     }\r
109     {\r
110         cds::gc::DHP::stat const& st = cds::gc::DHP::postmortem_statistics();\r
111         EXPECT_EQ( st.guard_allocated, st.guard_freed );\r
112         EXPECT_EQ( st.retired_count, st.free_count );\r
113         std::cout << st;\r
114     }\r
115 #endif\r
116 \r
117     cds::Terminate();\r
118 \r
119     return result;\r
120 }\r