From 7a9dfedda20d1fc26a9b77f3e4748b54d55c7a5d Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Tue, 21 Oct 2025 09:49:49 +0200 Subject: [PATCH 1/3] cmake, refactor: De-duplicate test-related code Co-authored-by: furszy --- src/CMakeLists.txt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ecbbbbe8e9..10f96c300d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -144,15 +144,16 @@ if(SECP256K1_BUILD_TESTS) list(APPEND TEST_DEFINITIONS SUPPORTS_CONCURRENCY=1) endif() - add_executable(noverify_tests tests.c) - target_link_libraries(noverify_tests secp256k1_precomputed secp256k1_asm) - target_compile_definitions(noverify_tests PRIVATE ${TEST_DEFINITIONS}) - add_test(NAME secp256k1_noverify_tests COMMAND noverify_tests) + function(add_executable_and_tests exe_name verify_definition) + add_executable(${exe_name} tests.c) + target_link_libraries(${exe_name} secp256k1_precomputed secp256k1_asm) + target_compile_definitions(${exe_name} PRIVATE ${verify_definition} ${TEST_DEFINITIONS}) + add_test(NAME secp256k1_${exe_name} COMMAND ${exe_name}) + endfunction() + + add_executable_and_tests(noverify_tests "") if(NOT CMAKE_BUILD_TYPE STREQUAL "Coverage") - add_executable(tests tests.c) - target_compile_definitions(tests PRIVATE VERIFY ${TEST_DEFINITIONS}) - target_link_libraries(tests secp256k1_precomputed secp256k1_asm) - add_test(NAME secp256k1_tests COMMAND tests) + add_executable_and_tests(tests VERIFY) endif() unset(TEST_DEFINITIONS) endif() From 7600f5f5fb973bb1859cd63f96d357cf98b72267 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Tue, 21 Oct 2025 09:55:42 +0200 Subject: [PATCH 2/3] cmake: Split test cases to improve parallelism --- src/CMakeLists.txt | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 10f96c300d..b5fd01a4e5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -144,16 +144,42 @@ if(SECP256K1_BUILD_TESTS) list(APPEND TEST_DEFINITIONS SUPPORTS_CONCURRENCY=1) endif() - function(add_executable_and_tests exe_name verify_definition) + set(test_targets "") + set(test_names "") + # Start with the longest-running tests. + list(APPEND test_targets ellswift) + list(APPEND test_names ellswift) + list(APPEND test_targets ecmult_constants) + list(APPEND test_names ecmult_constants) + list(APPEND test_targets "ecmult_pre_g wnaf point_times_order ecmult_near_split_bound ecmult_chain ecmult_gen_blind ecmult_const_tests ecmult_multi_tests ec_combine") + list(APPEND test_names ecmult) + # Continue with the remaining tests. + list(APPEND test_targets integer scalar field group ec ecdh ecdsa recovery extrakeys schnorrsig musig) + list(APPEND test_names integer scalar field group ec ecdh ecdsa recovery extrakeys schnorrsig musig) + # Combine short, trivial tests for log brevity. + list(APPEND test_targets "general hash utils") + list(APPEND test_names "general,hash,utils") + + function(add_executable_and_tests exe_name verify_definition label) add_executable(${exe_name} tests.c) target_link_libraries(${exe_name} secp256k1_precomputed secp256k1_asm) target_compile_definitions(${exe_name} PRIVATE ${verify_definition} ${TEST_DEFINITIONS}) - add_test(NAME secp256k1_${exe_name} COMMAND ${exe_name}) + foreach(test_target test_name IN ZIP_LISTS test_targets test_names) + string(REPLACE " " ";" test_target "${test_target}") + list(TRANSFORM test_target PREPEND "--target=") + add_test(NAME ${label}::${test_name} + COMMAND ${exe_name} ${test_target} --log=1 + COMMAND_EXPAND_LISTS + ) + set_tests_properties(${label}::${test_name} PROPERTIES + SKIP_REGULAR_EXPRESSION "module disabled" + ) + endforeach() endfunction() - add_executable_and_tests(noverify_tests "") + add_executable_and_tests(noverify_tests "" secp256k1_noverify) if(NOT CMAKE_BUILD_TYPE STREQUAL "Coverage") - add_executable_and_tests(tests VERIFY) + add_executable_and_tests(tests VERIFY secp256k1_verify) endif() unset(TEST_DEFINITIONS) endif() From 2d8da558168c5d82460074068867e126a7103fe9 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Tue, 21 Oct 2025 09:56:42 +0200 Subject: [PATCH 3/3] cmake: Set `LABELS` property for tests --- examples/CMakeLists.txt | 6 ++++-- src/CMakeLists.txt | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c9da9de6be..b850cc5dcd 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -8,8 +8,10 @@ function(add_example name) secp256k1 $<$:bcrypt> ) - set(test_name ${name}_example) - add_test(NAME secp256k1_${test_name} COMMAND ${target_name}) + add_test(NAME secp256k1_example::${name} COMMAND ${target_name}) + set_tests_properties(secp256k1_example::${name} PROPERTIES + LABELS secp256k1_example + ) endfunction() add_example(ecdsa) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b5fd01a4e5..6dc8df7431 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -172,6 +172,7 @@ if(SECP256K1_BUILD_TESTS) COMMAND_EXPAND_LISTS ) set_tests_properties(${label}::${test_name} PROPERTIES + LABELS ${label} SKIP_REGULAR_EXPRESSION "module disabled" ) endforeach() @@ -189,7 +190,10 @@ if(SECP256K1_BUILD_EXHAUSTIVE_TESTS) add_executable(exhaustive_tests tests_exhaustive.c) target_link_libraries(exhaustive_tests secp256k1_asm) target_compile_definitions(exhaustive_tests PRIVATE $<$>:VERIFY>) - add_test(NAME secp256k1_exhaustive_tests COMMAND exhaustive_tests) + add_test(NAME secp256k1_exhaustive COMMAND exhaustive_tests) + set_tests_properties(secp256k1_exhaustive PROPERTIES + LABELS secp256k1_exhaustive + ) endif() if(SECP256K1_BUILD_CTIME_TESTS)