-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCMakeLists.txt
167 lines (150 loc) · 8.93 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
### Build contracts with cdt if available ###
include(ExternalProject)
if( EOSIO_COMPILE_TEST_CONTRACTS )
set(EOSIO_WASM_OLD_BEHAVIOR "Off")
if( USE_EOSIO_CDT_1_7_X OR USE_EOSIO_CDT_1_8_X )
find_package( eosio.cdt REQUIRED )
set(CMAKE_ARGS_VAL -DCMAKE_TOOLCHAIN_FILE=${EOSIO_CDT_ROOT}/lib/cmake/eosio.cdt/EosioWasmToolchain.cmake -DEOSIO_COMPILE_TEST_CONTRACTS=${EOSIO_COMPILE_TEST_CONTRACTS} )
else()
find_package( cdt REQUIRED )
set(CMAKE_ARGS_VAL -DCMAKE_TOOLCHAIN_FILE=${CDT_ROOT}/lib/cmake/cdt/CDTWasmToolchain.cmake -DEOSIO_COMPILE_TEST_CONTRACTS=${EOSIO_COMPILE_TEST_CONTRACTS} )
endif()
if( USE_EOSIO_CDT_1_7_X )
list(APPEND CMAKE_ARGS_VAL -DUSE_EOSIO_CDT_1_7_X=${USE_EOSIO_CDT_1_7_X})
elseif( USE_EOSIO_CDT_1_8_X )
list(APPEND CMAKE_ARGS_VAL -DUSE_EOSIO_CDT_1_8_X=${USE_EOSIO_CDT_1_8_X})
endif()
message( STATUS "Building contracts in directory `./unittests/contracts/`" )
ExternalProject_Add(
contracts_project
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/contracts
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/contracts
CMAKE_ARGS ${CMAKE_ARGS_VAL}
UPDATE_COMMAND ""
PATCH_COMMAND ""
TEST_COMMAND ""
INSTALL_COMMAND ""
BUILD_ALWAYS 1
)
message( STATUS "Building contracts in directory `./unittests/test-contracts/`" )
ExternalProject_Add(
test_contracts_project
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test-contracts
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/test-contracts
CMAKE_ARGS ${CMAKE_ARGS_VAL}
UPDATE_COMMAND ""
PATCH_COMMAND ""
TEST_COMMAND ""
INSTALL_COMMAND ""
BUILD_ALWAYS 1
)
else()
message( STATUS "Not building contracts in directory `./unittests/contracts/`" )
add_subdirectory(contracts)
message( STATUS "Not building contracts in directory `./unittests/test-contracts/`" )
add_subdirectory(test-contracts)
endif()
if (NOT DISABLE_WASM_SPEC_TESTS)
add_subdirectory( wasm-spec-tests/generated-tests )
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test_contracts.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/include/test_contracts.hpp ESCAPE_QUOTES)
add_subdirectory(snapshots)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/snapshots.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/include/snapshots.hpp ESCAPE_QUOTES)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/deep-mind/deep-mind.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/include/deep-mind.hpp ESCAPE_QUOTES)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test-data/test-data.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/include/test-data.hpp ESCAPE_QUOTES)
add_custom_command(
OUTPUT protocol_feature_digest_tests.cpp
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/gen_protocol_feature_digest_tests.py ${CMAKE_CURRENT_SOURCE_DIR}/../libraries/chain/protocol_feature_manager.cpp > protocol_feature_digest_tests.cpp
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../libraries/chain/protocol_feature_manager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gen_protocol_feature_digest_tests.py
)
### BUILD UNIT TEST EXECUTABLE ###
file(GLOB UNIT_TESTS "*.cpp") # find all unit test suites
add_executable( unit_test ${UNIT_TESTS} protocol_feature_digest_tests.cpp) # build unit tests as one executable
target_link_libraries( unit_test eosio_chain_wrap state_history chainbase eosio_testing fc custom_appbase abieos ${PLATFORM_SPECIFIC_LIBS} )
target_compile_options(unit_test PUBLIC -DDISABLE_EOSLIB_SERIALIZE)
target_include_directories( unit_test PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/libraries/testing/include
${CMAKE_SOURCE_DIR}/test-contracts
${CMAKE_BINARY_DIR}/contracts
${CMAKE_CURRENT_SOURCE_DIR}/contracts
${CMAKE_CURRENT_BINARY_DIR}/contracts
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_SOURCE_DIR}/plugins/http_plugin/include
${CMAKE_SOURCE_DIR}/plugins/chain_interface/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)
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
string(REPLACE "\n" ";" SUITE_NAMES "${SUITE_NAMES}")
foreach(SUITE_NAME IN LISTS SUITE_NAMES)
if (NOT "" STREQUAL "${SUITE_NAME}") # ignore empty lines
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})
# build list of tests to run during coverage testing
if(ctest_tests)
string(APPEND ctest_tests "|")
endif()
string(APPEND ctest_tests ${TRIMMED_SUITE_NAME}_unit_test_$RUNTIME)
endforeach()
endif()
endforeach()
endforeach()
set(ctest_tests "'${ctest_tests}' -j8") # surround test list string in apostrophies
# The following tests are known to take the longest, bump up their cost (priority) so that they'll run first
# even on fresh first time test runs before ctest auto-detects costs
foreach(RUNTIME ${EOSIO_WASM_RUNTIMES})
set_tests_properties(api_part1_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(api_part2_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(api_part3_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(api_part4_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(wasm_part1_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(wasm_part2_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(wasm_part3_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(wasm_config_part1_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(wasm_config_part2_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(wasm_config_part3_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(wasm_config_part4_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(wasm_config_part5_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(snapshot_part1_unit_test_${RUNTIME} PROPERTIES COST 4000)
set_tests_properties(snapshot_part2_unit_test_${RUNTIME} PROPERTIES COST 4000)
set_tests_properties(finality_unit_test_${RUNTIME} PROPERTIES COST 4000)
set_tests_properties(delay_unit_test_${RUNTIME} PROPERTIES COST 3000)
endforeach()
### COVERAGE TESTING ###
if(ENABLE_COVERAGE_TESTING)
set(Coverage_NAME ${PROJECT_NAME}_ut_coverage)
# check for dependencies
if(NOT LCOV_PATH)
message(FATAL_ERROR "lcov not found! Aborting...")
endif()
if(NOT LLVMCOV_PATH)
message(FATAL_ERROR "llvm-cov not found! Aborting...")
endif()
if(NOT GENHTML_PATH)
message(FATAL_ERROR "genhtml not found! Aborting...")
endif()
# tests to skip during coverage testing
set(ctest_exclude_tests '') # no spaces allowed within tests list
# setup target
add_custom_target(${Coverage_NAME}
# cleanup lcov
COMMAND ${LCOV_PATH} --directory . --zerocounters
# run tests
COMMAND ./tools/ctestwrapper.sh -R ${ctest_tests} -E ${ctest_exclude_tests}
COMMAND ${LCOV_PATH} --directory . --capture --gcov-tool ${CMAKE_SOURCE_DIR}/tools/llvm-gcov.sh --output-file ${Coverage_NAME}.info
COMMAND ${LCOV_PATH} -remove ${Coverage_NAME}.info '*/boost/*' '/usr/lib/*' '/usr/include/*' '*/externals/*' '*/libfc/*' '*/wasm-jit/*' --output-file ${Coverage_NAME}_filtered.info
COMMAND ${GENHTML_PATH} -o ${Coverage_NAME} ${PROJECT_BINARY_DIR}/${Coverage_NAME}_filtered.info
COMMAND if [ "$CI" != "true" ]\; then ${CMAKE_COMMAND} -E remove ${Coverage_NAME}.base ${Coverage_NAME}.info ${Coverage_NAME}_filtered.info ${Coverage_NAME}.total ${PROJECT_BINARY_DIR}/${Coverage_NAME}.info.cleaned ${PROJECT_BINARY_DIR}/${Coverage_NAME}_filtered.info.cleaned\; fi
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMENT "Resetting code coverage counters to zero. Processing code coverage counters and generating report. Report published in ./${Coverage_NAME}"
)
# show info where to find the report
add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
COMMAND ;
COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report."
)
endif()