Skip to content

Commit 09f004b

Browse files
committed
Merge bitcoin/bitcoin#32945: tests: speed up coins_tests by parallelizing
06ab3a3 tests: speed up coins_tests by parallelizing (Anthony Towns) Pull request description: Updates the cmake logic to generate a separate test for each BOOST_FIXTURE_TEST_SUITE declaration in a file, and splits coins_tests.cpp into three separate suites so that they can be run in parallel. Also updates the convention enforced by test/lint/lint-tests.py. ACKs for top commit: l0rinc: reACK 06ab3a3 maflcko: lgtm ACK 06ab3a3 achow101: ACK 06ab3a3 Tree-SHA512: 940d9aa31dab60d1000b5f57d8dc4b2c5b4045c7e5c979ac407aba39f2285d53bc00c5e4d7bf2247551fd7e1c8681144e11fc8c005a874282c4c59bd362fb467
2 parents 5d98fc7 + 06ab3a3 commit 09f004b

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/test/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,21 +183,20 @@ function(add_boost_test source_file)
183183

184184
file(READ "${source_file}" source_file_content)
185185
string(REGEX
186-
MATCH "(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\\(([A-Za-z0-9_]+)"
186+
MATCHALL "(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\\(([A-Za-z0-9_]+)"
187187
test_suite_macro "${source_file_content}"
188188
)
189-
string(REGEX
189+
list(TRANSFORM test_suite_macro
190190
REPLACE "(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\\(" ""
191-
test_suite_name "${test_suite_macro}"
192191
)
193-
if(test_suite_name)
192+
foreach(test_suite_name IN LISTS test_suite_macro)
194193
add_test(NAME ${test_suite_name}
195194
COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no --log_level=test_suite -- DEBUG_LOG_OUT
196195
)
197196
set_property(TEST ${test_suite_name} PROPERTY
198197
SKIP_REGULAR_EXPRESSION "no test cases matching filter"
199198
)
200-
endif()
199+
endforeach()
201200
endfunction()
202201

203202
function(add_all_test_targets)

src/test/coins_tests.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ class CCoinsViewCacheTest : public CCoinsViewCache
104104

105105
} // namespace
106106

107-
BOOST_FIXTURE_TEST_SUITE(coins_tests, BasicTestingSetup)
108-
109107
static const unsigned int NUM_SIMULATION_ITERATIONS = 40000;
110108

111109
struct CacheTest : BasicTestingSetup {
@@ -283,16 +281,29 @@ void SimulationTest(CCoinsView* base, bool fake_best_block)
283281
}
284282
}; // struct CacheTest
285283

284+
BOOST_FIXTURE_TEST_SUITE(coins_tests_base, BasicTestingSetup)
285+
286286
// Run the above simulation for multiple base types.
287-
BOOST_FIXTURE_TEST_CASE(coins_cache_simulation_test, CacheTest)
287+
BOOST_FIXTURE_TEST_CASE(coins_cache_base_simulation_test, CacheTest)
288288
{
289289
CCoinsViewTest base{m_rng};
290290
SimulationTest(&base, false);
291+
}
292+
293+
BOOST_AUTO_TEST_SUITE_END()
291294

295+
BOOST_FIXTURE_TEST_SUITE(coins_tests_dbbase, BasicTestingSetup)
296+
297+
BOOST_FIXTURE_TEST_CASE(coins_cache_dbbase_simulation_test, CacheTest)
298+
{
292299
CCoinsViewDB db_base{{.path = "test", .cache_bytes = 1 << 23, .memory_only = true}, {}};
293300
SimulationTest(&db_base, true);
294301
}
295302

303+
BOOST_AUTO_TEST_SUITE_END()
304+
305+
BOOST_FIXTURE_TEST_SUITE(coins_tests, BasicTestingSetup)
306+
296307
struct UpdateTest : BasicTestingSetup {
297308
// Store of all necessary tx and undo data for next test
298309
typedef std::map<COutPoint, std::tuple<CTransaction,CTxUndo,Coin>> UtxoData;

test/lint/lint-tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ def check_matching_test_names(test_suite_list):
3030
not_matching = [
3131
x
3232
for x in test_suite_list
33-
if re.search(r"/(.*?)\.cpp:BOOST_FIXTURE_TEST_SUITE\(\1, .*\)", x) is None
33+
if re.search(r"/(.*?)\.cpp:BOOST_FIXTURE_TEST_SUITE\(\1(_[a-z0-9]+)?, .*\)", x) is None
3434
]
3535
if len(not_matching) > 0:
3636
not_matching = "\n".join(not_matching)
3737
error_msg = (
3838
"The test suite in file src/test/foo_tests.cpp should be named\n"
39-
'"foo_tests". Please make sure the following test suites follow\n'
40-
"that convention:\n\n"
39+
'`foo_tests`, or if there are multiple test suites, `foo_tests_bar`.\n'
40+
'Please make sure the following test suites follow that convention:\n\n'
4141
f"{not_matching}\n"
4242
)
4343
print(error_msg)

0 commit comments

Comments
 (0)