main.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright (c) 2006-2018 Maxim Khizhinsky
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #include <cds_test/stress_test.h>
  6. #include <cds/init.h>
  7. #include <cds/gc/hp.h>
  8. #include <cds/gc/dhp.h>
  9. #ifdef CDSUNIT_USE_URCU
  10. # include <cds/urcu/general_instant.h>
  11. # include <cds/urcu/general_buffered.h>
  12. # include <cds/urcu/general_threaded.h>
  13. # include <cds/urcu/signal_buffered.h>
  14. #endif
  15. #ifdef CDS_ENABLE_HPSTAT
  16. # include <cds_test/stat_hp_out.h>
  17. # include <cds_test/stat_dhp_out.h>
  18. # include <iostream>
  19. #endif
  20. #include <random>
  21. /*static*/ std::random_device cds_test::fixture::random_dev_;
  22. /*static*/ std::mt19937 cds_test::fixture::random_gen_( random_dev_());
  23. int main( int argc, char **argv )
  24. {
  25. int result;
  26. cds::Initialize();
  27. {
  28. // Read test config file
  29. cds_test::init_config( argc, argv );
  30. std::cout << "Hardware concurrency: " << std::thread::hardware_concurrency() << "\n";
  31. // Init Google test
  32. ::testing::InitGoogleTest( &argc, argv );
  33. cds_test::config const& general_cfg = cds_test::stress_fixture::get_config( "General" );
  34. // Init SMR
  35. cds::gc::HP hzpGC(
  36. general_cfg.get_size_t( "hazard_pointer_count", 16 ),
  37. general_cfg.get_size_t( "hp_max_thread_count", 0 ),
  38. general_cfg.get_size_t( "hp_retired_ptr_count", 0 ),
  39. general_cfg.get( "hp_scan_strategy", "inplace" ) == "inplace" ? cds::gc::HP::scan_type::inplace : cds::gc::HP::scan_type::classic
  40. );
  41. cds::gc::DHP dhpGC(
  42. general_cfg.get_size_t( "dhp_init_guard_count", 16 )
  43. );
  44. #ifdef CDSUNIT_USE_URCU
  45. size_t rcu_buffer_size = general_cfg.get_size_t( "rcu_buffer_size", 256 );
  46. // RCU varieties
  47. typedef cds::urcu::gc< cds::urcu::general_instant<> > rcu_gpi;
  48. rcu_gpi gpiRCU;
  49. typedef cds::urcu::gc< cds::urcu::general_buffered<> > rcu_gpb;
  50. rcu_gpb gpbRCU( rcu_buffer_size );
  51. typedef cds::urcu::gc< cds::urcu::general_threaded<> > rcu_gpt;
  52. rcu_gpt gptRCU( rcu_buffer_size );
  53. # ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
  54. typedef cds::urcu::gc< cds::urcu::signal_buffered<> > rcu_shb;
  55. rcu_shb shbRCU( rcu_buffer_size, SIGUSR1 );
  56. # endif
  57. #endif // CDSUNIT_USE_URCU
  58. cds::threading::Manager::attachThread();
  59. result = RUN_ALL_TESTS();
  60. cds::threading::Manager::detachThread();
  61. }
  62. #ifdef CDS_ENABLE_HPSTAT
  63. {
  64. cds::gc::HP::stat const& st = cds::gc::HP::postmortem_statistics();
  65. EXPECT_EQ( st.guard_allocated, st.guard_freed );
  66. EXPECT_EQ( st.retired_count, st.free_count );
  67. std::cout << st;
  68. }
  69. {
  70. cds::gc::DHP::stat const& st = cds::gc::DHP::postmortem_statistics();
  71. EXPECT_EQ( st.guard_allocated, st.guard_freed );
  72. EXPECT_EQ( st.retired_count, st.free_count );
  73. std::cout << st;
  74. }
  75. #endif
  76. cds::Terminate();
  77. return result;
  78. }