Run unit tests in parallel if possible

ReadResponse unit tests usually takes at least 30 seconds to run on my
computer, so having the unit tests run on more than one thread makes a
big difference.
pull/226/head
Guðni Már Gilbert 2022-10-21 21:30:15 +00:00
parent c2601d9a34
commit 745be900ef
1 changed files with 10 additions and 1 deletions

View File

@ -15,12 +15,21 @@ if(GCOV_ENABLE)
COMMAND ${CMAKE_COMMAND} -E remove ${PROJECT_BINARY_DIR}/.ctest-finished
)
include(ProcessorCount)
ProcessorCount(N)
if(N EQUAL 0)
message(WARNING "CTest: There was an issue reading the core count, tests won't be run in parallel")
else()
message(STATUS "CTest: Detected ${N} CPU threads")
set(ctest_test_args ${ctest_test_args} -j${N})
endif()
# This step needs to always return OK but log whether it was successful or not. The thought here
# is that if the tests all pass, .ctest-finished is created and we can check for its existance
# after generating the report to determine if the overall build result is a pass or fail.
add_custom_target(
test_run_all
COMMAND ${CMAKE_COMMAND} -E env CTEST_OUTPUT_ON_FAILURE=1 ${CMAKE_CTEST_COMMAND} --timeout 30
COMMAND ${CMAKE_COMMAND} -E env CTEST_OUTPUT_ON_FAILURE=1 ${CMAKE_CTEST_COMMAND} ${ctest_test_args} --timeout 30
COMMAND ${CMAKE_COMMAND} -E touch .ctest-finished || exit 0
BYPRODUCTS ${PROJECT_BINARY_DIR}/.ctest-finished
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"