Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Unit Tests Now Run In Parallel #6716

Merged
merged 22 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
16387f4
Whitespace correction in wasm_tests.cpp
kj4ezj Feb 7, 2019
633c740
ctest now runs tests on all available cores
kj4ezj Feb 7, 2019
c679cb2
Removed references to zombie variable in CMake
kj4ezj Feb 7, 2019
e65e82b
Unit tests are now added to test execution by test suite, rather than…
kj4ezj Feb 7, 2019
f4b2c42
Added error checking for empty lines, cleaned up comments
kj4ezj Feb 7, 2019
644b8ab
Set Buildkite to automagically determine number of cores for parallel…
kj4ezj Feb 7, 2019
207b8be
Fixed incorrect ctest command-line option
kj4ezj Feb 7, 2019
f94690e
Changed how CPU cores are detected in Buildkite
kj4ezj Feb 8, 2019
b4d13d5
Fixed depricated method of BASH command substitution, testing multipl…
kj4ezj Feb 8, 2019
c0f64f3
Reverted Buildkite configuration
kj4ezj Feb 8, 2019
d1eea60
Reverted /tools/ctestwrapper.sh
kj4ezj Feb 8, 2019
d020e58
Fixed delimiter when specifying tests to include in coverage report
kj4ezj Feb 8, 2019
4a2bb7b
Fixed CMake string concatenation issue
kj4ezj Feb 8, 2019
5d2e6e3
Fixed empty string checking in CMake
kj4ezj Feb 8, 2019
c84f185
Finally fixed coverage testing
kj4ezj Feb 8, 2019
6df6b23
Added regex to grep command to ignore whitespace as spoonincode sugge…
kj4ezj Feb 11, 2019
78db535
Removed wasm_tests/weighted_cpu_limit_tests test exclusion edge case …
kj4ezj Feb 11, 2019
1a3610d
Deleted wasm_tests/weighted_cpu_limit_tests as flaky tests are useles…
kj4ezj Feb 11, 2019
f35211f
Fixed escape character conflicting between CMake and regex
kj4ezj Feb 11, 2019
c1564d2
Now grep ignores single-line comments containing test suite declarations
kj4ezj Feb 11, 2019
1dcb2bd
Grep queries now ignore lines where a test suite declaration has been…
kj4ezj Feb 11, 2019
57f747e
Fixed escape character conflicting between CMake and regex
kj4ezj Feb 11, 2019
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
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include_directories("${CMAKE_SOURCE_DIR}/plugins/wallet_plugin/include")

file(GLOB UNIT_TESTS "*.cpp")

add_executable( plugin_test ${UNIT_TESTS} ${WASM_UNIT_TESTS} )
add_executable( plugin_test ${UNIT_TESTS} )
target_link_libraries( plugin_test eosio_testing eosio_chain chainbase chain_plugin wallet_plugin fc ${PLATFORM_SPECIFIC_LIBS} )

target_include_directories( plugin_test PUBLIC
Expand Down
76 changes: 35 additions & 41 deletions unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
find_package( Gperftools QUIET )

### Build contracts with cdt if available
### Build contracts with cdt if available ###
include(ExternalProject)
# if no cdt root is given use default path
if(EOSIO_CDT_ROOT STREQUAL "" OR NOT EOSIO_CDT_ROOT)
Expand Down Expand Up @@ -40,13 +40,11 @@ add_subdirectory(contracts)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/config.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/include/config.hpp ESCAPE_QUOTES)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/contracts.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/include/contracts.hpp ESCAPE_QUOTES)

file(GLOB UNIT_TESTS "*.cpp")

add_executable( unit_test ${UNIT_TESTS} ${WASM_UNIT_TESTS} )
### BUILD UNIT TEST EXECUTABLE ###
file(GLOB UNIT_TESTS "*.cpp") # find all unit test suites
add_executable( unit_test ${UNIT_TESTS}) # build unit tests as one executable
target_link_libraries( unit_test eosio_chain chainbase eosio_testing fc ${PLATFORM_SPECIFIC_LIBS} )

target_compile_options(unit_test PUBLIC -DDISABLE_EOSLIB_SERIALIZE)

target_include_directories( unit_test PUBLIC
${CMAKE_SOURCE_DIR}/libraries/testing/include
${CMAKE_SOURCE_DIR}/test-contracts
Expand All @@ -55,59 +53,55 @@ target_include_directories( unit_test PUBLIC
${CMAKE_CURRENT_BINARY_DIR}/contracts
${CMAKE_CURRENT_BINARY_DIR}/include )

#Manually run unit_test for all supported runtimes
#To run unit_test with all log from blockchain displayed, put --verbose after --, i.e. unit_test -- --verbose
add_test(NAME unit_test_wavm COMMAND unit_test
-t \!wasm_tests/weighted_cpu_limit_tests
--report_level=detailed --color_output --catch_system_errors=no -- --wavm)
add_test(NAME unit_test_wabt COMMAND unit_test
-t \!wasm_tests/weighted_cpu_limit_tests
--report_level=detailed --color_output -- --wabt)

### MARK TEST SUITES FOR EXECUTION ###
foreach(TEST_SUITE ${UNIT_TESTS}) # create an independent target for each test suite
execute_process(COMMAND bash -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_NAME OUTPUT_STRIP_TRAILING_WHITESPACE) # get the test suite name from the *.cpp file
if (NOT "" STREQUAL "${SUITE_NAME}") # ignore empty lines
execute_process(COMMAND bash -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"
add_test(NAME ${TRIMMED_SUITE_NAME}_unit_test_wavm COMMAND unit_test --run_test=${SUITE_NAME} --report_level=detailed --color_output --catch_system_errors=no -- --wavm)
add_test(NAME ${TRIMMED_SUITE_NAME}_unit_test_wabt COMMAND unit_test --run_test=${SUITE_NAME} --report_level=detailed --color_output -- --wabt)
# build list of tests to run during coverage testing
if(NOT "" STREQUAL "${ctest_tests}")
set(ctest_tests "${ctest_tests}|${TRIMMED_SUITE_NAME}_unit_test_wavm|${TRIMMED_SUITE_NAME}_unit_test_wabt")
else()
set(ctest_tests "${TRIMMED_SUITE_NAME}_unit_test_wavm|${TRIMMED_SUITE_NAME}_unit_test_wabt")
endif()
endif()
endforeach(TEST_SUITE)
set(ctest_tests "'${ctest_tests}' -j8") # surround test list string in apostrophies

### 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() # NOT LCOV_PATH

endif()
if(NOT LLVMCOV_PATH)
message(FATAL_ERROR "llvm-cov not found! Aborting...")
endif() # NOT LCOV_PATH

endif()
if(NOT GENHTML_PATH)
message(FATAL_ERROR "genhtml not found! Aborting...")
endif() # NOT GENHTML_PATH

# no spaces allowed within tests list
set(ctest_tests 'unit_test_wabt|unit_test_wavm')
set(ctest_exclude_tests '')

# Setup target
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
# cleanup lcov
COMMAND ${LCOV_PATH} --directory . --zerocounters

# Run tests
# 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/*' '*/fc/*' '*/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
)
# 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()
63 changes: 0 additions & 63 deletions unittests/wasm_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,69 +510,6 @@ BOOST_FIXTURE_TEST_CASE(misaligned_tests, tester ) try {
check_aligned(misaligned_const_ref_wast);
} FC_LOG_AND_RETHROW()

// test weighted cpu limit
BOOST_FIXTURE_TEST_CASE(weighted_cpu_limit_tests, tester ) try {
// TODO Increase the robustness of this test.
resource_limits_manager mgr = control->get_mutable_resource_limits_manager();
create_accounts( {N(f_tests)} );
create_accounts( {N(acc2)} );
bool pass = false;

std::string code = R"=====(
(module
(import "env" "require_auth" (func $require_auth (param i64)))
(import "env" "eosio_assert" (func $eosio_assert (param i32 i32)))
(table 0 anyfunc)
(memory $0 1)
(export "apply" (func $apply))
(func $i64_trunc_u_f64 (param $0 f64) (result i64) (i64.trunc_u/f64 (get_local $0)))
(func $test (param $0 i64))
(func $apply (param $0 i64)(param $1 i64)(param $2 i64)
)=====";
for (int i = 0; i < 1024; ++i) {
code += "(call $test (call $i64_trunc_u_f64 (f64.const 1)))\n";
}
code += "))";

produce_blocks(1);
set_code(N(f_tests), code.c_str());
produce_blocks(10);

mgr.set_account_limits(N(f_tests), -1, -1, 1);
int count = 0;
while (count < 4) {
signed_transaction trx;

for (int i = 0; i < 2; ++i) {
action act;
act.account = N(f_tests);
act.name = N() + (i * 16);
act.authorization = vector<permission_level>{{N(f_tests),config::active_name}};
trx.actions.push_back(act);
}

set_transaction_headers(trx);
trx.sign(get_private_key( N(f_tests), "active" ), control->get_chain_id());

try {
push_transaction(trx, fc::time_point::maximum(), 0);
produce_block();
BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id()));
pass = true;
count++;
} catch( eosio::chain::leeway_deadline_exception& ) {
BOOST_REQUIRE_EQUAL(count, 3);
break;
}
BOOST_REQUIRE_EQUAL(true, validate());

if (count == 2) { // add a big weight on acc2, making f_tests out of resource
mgr.set_account_limits(N(acc2), -1, -1, 100000000);
}
}
BOOST_REQUIRE_EQUAL(count, 3);
} FC_LOG_AND_RETHROW()

/**
* Make sure WASM "start" method is used correctly
*/
Expand Down