From 284ece914314e67d8be8d51a3851ce03846990e9 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 20 Jan 2023 13:05:56 +0000 Subject: [PATCH] cmake: Implement `make check` --- CMakeLists.txt | 3 +++ src/CMakeLists.txt | 20 ++++++++++++++++++++ src/test/CMakeLists.txt | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d07d0c6c98095..8b98611599ac9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,6 +155,9 @@ else() endif() endif() +find_package(Python3 3.8 REQUIRED COMPONENTS Interpreter) +set(PYTHON_COMMAND ${Python3_EXECUTABLE}) + add_subdirectory(src) add_subdirectory(test) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bdaeb02d38edb..1cb45b2b687c4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -288,4 +288,24 @@ endif() if(BUILD_TESTS) add_subdirectory(test) + + # https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/EmulateMakeCheck + if(TARGET bench_bitcoin) + set(run_bench_bitcoin COMMAND $ --sanity-check) + endif() + + set(run_util_test_runner "") + if(TARGET bitcoin-util AND TARGET bitcoin-tx) + set(run_util_test_runner COMMAND echo "Running test/util/test_runner.py..." COMMAND ${CMAKE_COMMAND} -E env BITCOINUTIL=$ BITCOINTX=$ ${PYTHON_COMMAND} ${CMAKE_BINARY_DIR}/test/util/test_runner.py) + endif() + + add_custom_target(check + ${run_bench_bitcoin} + ${run_util_test_runner} + COMMAND echo "Running test/util/rpcauth-test.py..." + COMMAND ${PYTHON_COMMAND} ${CMAKE_BINARY_DIR}/test/util/rpcauth-test.py + COMMAND ${CMAKE_COMMAND} -E chdir test ${CMAKE_CTEST_COMMAND} -C "$" + VERBATIM + ) + add_dependencies(check test_bitcoin) endif() diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index dfddd2abb5374..82ac2bee07348 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -174,3 +174,36 @@ if(ENABLE_WALLET) target_link_libraries(test_bitcoin BerkeleyDB::BerkeleyDB) endif() endif() + +function(add_boost_test source_file_name) + set(source_file_path "${CMAKE_CURRENT_SOURCE_DIR}/${source_file_name}") + if(NOT EXISTS ${source_file_path}) + return() + endif() + + file(READ "${source_file_path}" source_file_content) + string(REGEX + MATCH "(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\\(([A-Za-z0-9_]+)" + test_suite_macro "${source_file_content}" + ) + string(REGEX + REPLACE "(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\\(" "" + test_suite_name "${test_suite_macro}" + ) + if(test_suite_name) + add_test(NAME "${test_suite_name}:${source_file_name}" + COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no + ) + endif() +endfunction() + +function(add_all_test_targets) + get_target_property(test_sources test_bitcoin SOURCES) + foreach(test_source ${test_sources}) + add_boost_test(${test_source}) + endforeach() +endfunction() + +include(CTest) +enable_testing() +add_all_test_targets()