diff --git a/contrib/teamcity/builds/build-tsan.sh b/contrib/teamcity/builds/build-tsan.sh --- a/contrib/teamcity/builds/build-tsan.sh +++ b/contrib/teamcity/builds/build-tsan.sh @@ -13,7 +13,9 @@ ) build_with_cmake --Werror --clang -run_test_bitcoin "with thread sanitizer" +# TSAN runs out of memory with the default radix_tests/insert_stress_test values +run_test_bitcoin "with thread sanitizer" \ + -radix_insert_stress_test_threads=16 -radix_insert_stress_test_elements=128 # Libs and utils tests ninja check diff --git a/src/test/main.cpp b/src/test/main.cpp --- a/src/test/main.cpp +++ b/src/test/main.cpp @@ -6,8 +6,19 @@ #include +#include + #include +static std::set customArguments{ + "-testsuitename", + "-axionactivationtime", +}; + +void AddCustomArguments(const std::set &arguments) { + customArguments.insert(arguments.begin(), arguments.end()); +} + namespace utf = boost::unit_test::framework; /* @@ -18,14 +29,7 @@ std::string error; CustomArgumentsFixture() { - const std::string testsuitename = "-testsuitename"; - - const std::set testArgs = { - testsuitename, - "-axionactivationtime", - }; - - for (const auto &arg : testArgs) { + for (const auto &arg : customArguments) { gArgs.AddArg(arg, "", ArgsManager::ALLOW_ANY, OptionsCategory::HIDDEN); } @@ -37,7 +41,7 @@ } master_test_suite.p_name.value = - gArgs.GetArg(testsuitename, master_test_suite.p_name.value); + gArgs.GetArg("-testsuitename", master_test_suite.p_name.value); } ~CustomArgumentsFixture(){}; diff --git a/src/test/radix_tests.cpp b/src/test/radix_tests.cpp --- a/src/test/radix_tests.cpp +++ b/src/test/radix_tests.cpp @@ -307,20 +307,25 @@ CheckConstTree(mytree, false); } -#define THREADS 128 -#define ELEMENTS 65536 +static CustomArguments insertStressTestArguments({ + "-radix_insert_stress_test_threads", + "-radix_insert_stress_test_elements", +}); BOOST_AUTO_TEST_CASE(insert_stress_test) { typedef TestElement E; + int nThreads = gArgs.GetArg("-radix_insert_stress_test_threads", 128); + int nElements = gArgs.GetArg("-radix_insert_stress_test_elements", 65536); + RadixTree mytree; std::atomic success{0}; std::vector threads; - for (int i = 0; i < THREADS; i++) { + for (int i = 0; i < nThreads; i++) { threads.push_back(std::thread([&] { MMIXLinearCongruentialGenerator lcg; - for (int j = 0; j < ELEMENTS; j++) { + for (int j = 0; j < nElements; j++) { uint32_t v = lcg.next(); if (mytree.remove(v)) { @@ -352,11 +357,11 @@ t.join(); } - BOOST_CHECK_EQUAL(success.load(), ELEMENTS); + BOOST_CHECK_EQUAL(success.load(), nElements); // All the elements have been inserted into the tree. MMIXLinearCongruentialGenerator lcg; - for (int i = 0; i < ELEMENTS; i++) { + for (int i = 0; i < nElements; i++) { uint32_t v = lcg.next(); BOOST_CHECK_EQUAL(mytree.get(v)->getId(), v); auto ptr = RCUPtr::make(v); diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -73,6 +73,24 @@ static constexpr Amount CENT(COIN / 100); +void AddCustomArguments(const std::set &arguments); + +/** + * Instantiate a static CustomArguments instance to add custom arguments in the + * tests: + * // In the test .cpp file + * static CustomArguments argumentsForMyTest({"-foo", "-bar"}); + * + * Then get the arguments from the test: + * // In the test case + * gArgs.getArg("-foo", 42); + */ +struct CustomArguments { + explicit CustomArguments(const std::set &arguments) { + AddCustomArguments(arguments); + } +}; + /** * Basic testing setup. * This just configures logging, data dir and chain parameters.