Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add common method for registering different test types #1168

Merged
merged 3 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
cmake_minimum_required( VERSION 3.16 )

project( antelope-spring )
include(CTest) # suppresses DartConfiguration.tcl error
enable_testing()
include(CTest)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")

include( GNUInstallDirs )
include( MASSigning )
include( AddTestHelpers )

set( CMAKE_CXX_STANDARD 20 )
set( CMAKE_CXX_EXTENSIONS ON )
Expand Down
37 changes: 37 additions & 0 deletions CMakeModules/AddTestHelpers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function(setup_test_common)
cmake_parse_arguments(PARSE_ARGV 0 arg "" "NAME;COST;TIMEOUT" "COMMAND")

add_test(NAME "${arg_NAME}" COMMAND ${arg_COMMAND} WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")

if(arg_COST)
set_tests_properties("${arg_NAME}" PROPERTIES COST ${arg_COST})
endif()
if(arg_TIMEOUT)
set_tests_properties("${arg_NAME}" PROPERTIES TIMEOUT ${arg_TIMEOUT})
endif()
endfunction()

function(add_p_test)
setup_test_common(${ARGV})
endfunction()

function(add_wasmspec_test)
cmake_parse_arguments(PARSE_ARGV 0 arg "" "NAME;COST;TIMEOUT" "COMMAND")

setup_test_common(${ARGV})
set_property(TEST "${arg_NAME}" PROPERTY LABELS wasm_spec_tests)
endfunction()

function(add_np_test)
cmake_parse_arguments(PARSE_ARGV 0 arg "" "NAME;COST;TIMEOUT" "COMMAND")

setup_test_common(${ARGV})
set_property(TEST "${arg_NAME}" PROPERTY LABELS nonparallelizable_tests)
endfunction()

function(add_lr_test)
cmake_parse_arguments(PARSE_ARGV 0 arg "" "NAME;COST;TIMEOUT" "COMMAND")

setup_test_common(${ARGV})
set_property(TEST "${arg_NAME}" PROPERTY LABELS long_running_tests)
endfunction()
2 changes: 1 addition & 1 deletion plugins/chain_plugin/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ add_executable( test_chain_plugin
main.cpp
)
target_link_libraries( test_chain_plugin chain_plugin eosio_testing eosio_chain_wrap )
add_test(NAME test_chain_plugin COMMAND plugins/chain_plugin/test/test_chain_plugin WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
add_p_test(NAME test_chain_plugin COMMAND plugins/chain_plugin/test/test_chain_plugin)
3 changes: 1 addition & 2 deletions plugins/http_plugin/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ target_link_libraries( http_plugin_unit_tests
target_include_directories( http_plugin_unit_tests PUBLIC
${CMAKE_SOURCE_DIR}/plugins/http_plugin/include )

add_test( NAME http_plugin_unit_tests COMMAND http_plugin_unit_tests )
set_property(TEST http_plugin_unit_tests PROPERTY LABELS nonparallelizable_tests)
add_np_test( NAME http_plugin_unit_tests COMMAND http_plugin_unit_tests )
2 changes: 1 addition & 1 deletion plugins/net_plugin/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ add_executable( test_net_plugin
main.cpp
)
target_link_libraries( test_net_plugin net_plugin eosio_testing eosio_chain_wrap )
add_test(NAME test_net_plugin COMMAND plugins/net_plugin/tests/test_net_plugin WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
add_p_test(NAME test_net_plugin COMMAND plugins/net_plugin/tests/test_net_plugin)
2 changes: 1 addition & 1 deletion plugins/producer_plugin/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ add_executable( test_producer_plugin
main.cpp
)
target_link_libraries( test_producer_plugin producer_plugin eosio_testing eosio_chain_wrap )
add_test(NAME test_producer_plugin COMMAND plugins/producer_plugin/test/test_producer_plugin WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
add_p_test(NAME test_producer_plugin COMMAND plugins/producer_plugin/test/test_producer_plugin)
2 changes: 1 addition & 1 deletion plugins/resource_monitor_plugin/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_executable( test_resmon_plugin test_resmon_plugin.cpp test_add_file_system.cpp test_threshold.cpp )
target_link_libraries( test_resmon_plugin resource_monitor_plugin Boost::included_unit_test_framework )
target_include_directories( test_resmon_plugin PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
add_test(NAME test_resmon_plugin COMMAND plugins/resource_monitor_plugin/test/test_resmon_plugin WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
add_p_test(NAME test_resmon_plugin COMMAND plugins/resource_monitor_plugin/test/test_resmon_plugin)
2 changes: 1 addition & 1 deletion plugins/trace_api_plugin/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ add_executable( test_trace_api_plugin
target_link_libraries( test_trace_api_plugin trace_api_plugin Boost::included_unit_test_framework )
target_include_directories( test_trace_api_plugin PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )

add_test(NAME test_trace_api_plugin COMMAND plugins/trace_api_plugin/test/test_trace_api_plugin WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
add_p_test(NAME test_trace_api_plugin COMMAND plugins/trace_api_plugin/test/test_trace_api_plugin)
503 changes: 182 additions & 321 deletions tests/CMakeLists.txt

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions tests/trx_generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ target_link_libraries(trx_generator PRIVATE eosio_chain fc Boost::program_option
add_executable(trx_generator_tests trx_generator_tests.cpp trx_provider.cpp trx_generator.cpp)
target_link_libraries(trx_generator_tests PRIVATE eosio_chain fc Boost::program_options Boost::included_unit_test_framework ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS})
target_include_directories(trx_generator_tests PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
add_test(trx_generator_tests trx_generator_tests)
set_property(TEST trx_generator_tests PROPERTY LABELS nonparallelizable_tests)
add_np_test(NAME trx_generator_tests COMMAND trx_generator_tests)
8 changes: 4 additions & 4 deletions unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ target_include_directories( unit_test PUBLIC
${CMAKE_CURRENT_BINARY_DIR}/include)

### MARK TEST SUITES FOR EXECUTION ###
add_test(NAME protocol_feature_digest_unit_test COMMAND unit_test --run_test=protocol_feature_digest_tests --report_level=detailed --color_output)
add_p_test(NAME protocol_feature_digest_unit_test COMMAND unit_test --run_test=protocol_feature_digest_tests --report_level=detailed --color_output)
set(ctest_tests "protocol_feature_digest_tests")
foreach(TEST_SUITE ${UNIT_TESTS}) # create an independent target for each test suite
execute_process(COMMAND sh -c "grep -E 'BOOST_AUTO_TEST_SUITE\\s*[(]' '${TEST_SUITE}' | grep -vE '//.*BOOST_AUTO_TEST_SUITE\\s*[(]' | cut -d ')' -f 1 | cut -d '(' -f 2" OUTPUT_VARIABLE SUITE_NAMES OUTPUT_STRIP_TRAILING_WHITESPACE) # get the test suite name from the *.cpp file
Expand All @@ -96,11 +96,11 @@ foreach(TEST_SUITE ${UNIT_TESTS}) # create an independent target for each test s
execute_process(COMMAND sh -c "echo ${SUITE_NAME} | sed -e 's/s$//' | sed -e 's/_test$//'" OUTPUT_VARIABLE TRIMMED_SUITE_NAME OUTPUT_STRIP_TRAILING_WHITESPACE) # trim "_test" or "_tests" from the end of ${SUITE_NAME}
# to run unit_test with all log from blockchain displayed, put "--verbose" after "--", i.e. "unit_test -- --verbose"
foreach(RUNTIME ${EOSIO_WASM_RUNTIMES})
add_test(NAME ${TRIMMED_SUITE_NAME}_unit_test_${RUNTIME} COMMAND unit_test --run_test=${SUITE_NAME} --report_level=detailed --color_output -- --${RUNTIME})
add_p_test(NAME ${TRIMMED_SUITE_NAME}_unit_test_${RUNTIME} COMMAND unit_test --run_test=${SUITE_NAME} --report_level=detailed --color_output -- --${RUNTIME})
# add a duplicate test to run without fsgsbase instructions for a limited number of OC wasm tests
if(RUNTIME STREQUAL "eos-vm-oc" AND TRIMMED_SUITE_NAME MATCHES "^wasm_part")
add_test(NAME ${TRIMMED_SUITE_NAME}_unit_test_${RUNTIME}-nofsgs COMMAND unit_test --run_test=${SUITE_NAME} --report_level=detailed --color_output -- --${RUNTIME})
set_tests_properties(${TRIMMED_SUITE_NAME}_unit_test_${RUNTIME}-nofsgs PROPERTIES ENVIRONMENT "SPRING_DISABLE_FSGSBASE=1" COST 5000)
add_p_test(NAME ${TRIMMED_SUITE_NAME}_unit_test_${RUNTIME}-nofsgs COMMAND unit_test --run_test=${SUITE_NAME} --report_level=detailed --color_output -- --${RUNTIME} COST 5000)
set_tests_properties(${TRIMMED_SUITE_NAME}_unit_test_${RUNTIME}-nofsgs PROPERTIES ENVIRONMENT "SPRING_DISABLE_FSGSBASE=1")
endif()
# build list of tests to run during coverage testing
if(ctest_tests)
Expand Down
3 changes: 1 addition & 2 deletions unittests/wasm-spec-tests/generated-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ foreach(TEST_SUITE ${WASM_TESTS}) # create an independent target for each test s
foreach(RUNTIME ${EOSIO_WASM_RUNTIMES})
get_test_property(${SN}_unit_test_${RUNTIME} LABELS TEST_LABEL)
if ("NOTFOUND" STREQUAL "${TEST_LABEL}") # prevent duplicates
add_test(NAME ${SN}_unit_test_${RUNTIME} COMMAND wasm_spec_test --run_test=${SN} --report_level=detailed --color_output -- --${RUNTIME})
set_property(TEST ${SN}_unit_test_${RUNTIME} PROPERTY LABELS wasm_spec_tests)
add_wasmspec_test(NAME ${SN}_unit_test_${RUNTIME} COMMAND wasm_spec_test --run_test=${SN} --report_level=detailed --color_output -- --${RUNTIME})
# build list of tests to run during coverage testing
if(ctest_tests)
string(APPEND ctest_tests "|")
Expand Down