diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6e44e9ba3e4..72bc2a31569 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,18 +11,18 @@ add_executable( chain_test ${UNIT_TESTS} ${COMMON_SOURCES} ) target_link_libraries( chain_test eos_native_contract eos_chain chainbase eos_utilities eos_egenesis_none wallet_plugin fc ${PLATFORM_SPECIFIC_LIBS} ) if(WASM_TOOLCHAIN) - add_subdirectory(slow_tests/memory_test) file(GLOB SLOW_TESTS "slow_tests/*.cpp") add_executable( slow_test ${SLOW_TESTS} ${COMMON_SOURCES} ) target_link_libraries( slow_test eos_native_contract eos_chain chainbase eos_utilities eos_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) - target_include_directories( slow_test PUBLIC ${CMAKE_BINARY_DIR}/contracts ${CMAKE_CURRENT_BINARY_DIR}/slow_tests ) - add_dependencies(slow_test currency exchange memory_test) + target_include_directories( slow_test PUBLIC ${CMAKE_BINARY_DIR}/contracts ) + add_dependencies(slow_test currency exchange) + add_subdirectory(api_tests/memory_test) file(GLOB API_TESTS "api_tests/*.cpp") add_executable( api_test ${API_TESTS} ${COMMON_SOURCES} ) target_link_libraries( api_test eos_native_contract eos_chain chainbase eos_utilities eos_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) - target_include_directories( api_test PUBLIC ${CMAKE_BINARY_DIR}/contracts ${CMAKE_SOURCE_DIR}/contracts ) - add_dependencies(api_test test_api) + target_include_directories( api_test PUBLIC ${CMAKE_BINARY_DIR}/contracts ${CMAKE_SOURCE_DIR}/contracts ${CMAKE_CURRENT_BINARY_DIR}/slow_tests ) + add_dependencies(api_test test_api memory_test) endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/eosd_run_test.sh ${CMAKE_CURRENT_BINARY_DIR}/eosd_run_test.sh COPYONLY) diff --git a/tests/api_tests/api_tests.cpp b/tests/api_tests/api_tests.cpp index bbdbe088b1c..0b351789962 100644 --- a/tests/api_tests/api_tests.cpp +++ b/tests/api_tests/api_tests.cpp @@ -33,6 +33,9 @@ #include #include + +#include "memory_test/memory_test.wast.hpp" + FC_REFLECT( dummy_message, (a)(b)(c) ); FC_REFLECT( u128_msg, (values) ); @@ -408,5 +411,85 @@ BOOST_FIXTURE_TEST_CASE(test_all, testing_fixture) } FC_LOG_AND_RETHROW() } +#define MEMORY_TEST_RUN(account_name) \ + Make_Blockchain(chain); \ + chain.produce_blocks(1); \ + Make_Account(chain, account_name); \ + chain.produce_blocks(1); \ + \ + \ + types::setcode handler; \ + handler.account = #account_name; \ + \ + auto wasm = assemble_wast( memory_test_wast ); \ + handler.code.resize(wasm.size()); \ + memcpy( handler.code.data(), wasm.data(), wasm.size() ); \ + \ + { \ + eos::chain::SignedTransaction trx; \ + trx.scope = {#account_name}; \ + trx.messages.resize(1); \ + trx.messages[0].code = config::EosContractName; \ + trx.messages[0].authorization.emplace_back(types::AccountPermission{#account_name,"active"}); \ + transaction_set_message(trx, 0, "setcode", handler); \ + trx.expiration = chain.head_block_time() + 100; \ + transaction_set_reference_block(trx, chain.head_block_id()); \ + chain.push_transaction(trx); \ + chain.produce_blocks(1); \ + } \ + \ + \ + { \ + eos::chain::SignedTransaction trx; \ + trx.scope = sort_names({#account_name,"inita"}); \ + transaction_emplace_message(trx, #account_name, \ + vector{}, \ + "transfer", types::transfer{#account_name, "inita", 1,""}); \ + trx.expiration = chain.head_block_time() + 100; \ + transaction_set_reference_block(trx, chain.head_block_id()); \ + chain.push_transaction(trx); \ + chain.produce_blocks(1); \ + } + +#define MEMORY_TEST_CASE(test_case_name, account_name) \ +BOOST_FIXTURE_TEST_CASE(test_case_name, testing_fixture) \ +{ try{ \ + MEMORY_TEST_RUN(account_name); \ +} FC_LOG_AND_RETHROW() } + +//Test wasm memory allocation +MEMORY_TEST_CASE(test_memory, testmemory) + +//Test wasm memory allocation at boundaries +MEMORY_TEST_CASE(test_memory_bounds, testbounds) + +//Test intrinsic provided memset and memcpy +MEMORY_TEST_CASE(test_memset_memcpy, testmemset) + +//Test memcpy overlap at start of destination +BOOST_FIXTURE_TEST_CASE(test_memcpy_overlap_start, testing_fixture) +{ + try { + MEMORY_TEST_RUN(testolstart); + BOOST_FAIL("memcpy should have thrown assert acception"); + } + catch(fc::assert_exception& ex) + { + BOOST_REQUIRE(ex.to_detail_string().find("overlap of memory range is undefined") != std::string::npos); + } +} + +//Test memcpy overlap at end of destination +BOOST_FIXTURE_TEST_CASE(test_memcpy_overlap_end, testing_fixture) +{ + try { + MEMORY_TEST_RUN(testolend); + BOOST_FAIL("memcpy should have thrown assert acception"); + } + catch(fc::assert_exception& ex) + { + BOOST_REQUIRE(ex.to_detail_string().find("overlap of memory range is undefined") != std::string::npos); + } +} BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/slow_tests/memory_test/CMakeLists.txt b/tests/api_tests/memory_test/CMakeLists.txt similarity index 100% rename from tests/slow_tests/memory_test/CMakeLists.txt rename to tests/api_tests/memory_test/CMakeLists.txt diff --git a/tests/slow_tests/memory_test/memory_test.cpp b/tests/api_tests/memory_test/memory_test.cpp similarity index 100% rename from tests/slow_tests/memory_test/memory_test.cpp rename to tests/api_tests/memory_test/memory_test.cpp diff --git a/tests/slow_tests/memory_test/memory_test.hpp b/tests/api_tests/memory_test/memory_test.hpp similarity index 100% rename from tests/slow_tests/memory_test/memory_test.hpp rename to tests/api_tests/memory_test/memory_test.hpp diff --git a/tests/slow_tests/slow_tests.cpp b/tests/slow_tests/slow_tests.cpp index bdb73c3def8..16a305f8c9e 100644 --- a/tests/slow_tests/slow_tests.cpp +++ b/tests/slow_tests/slow_tests.cpp @@ -47,7 +47,6 @@ #include #include #include -#include "memory_test/memory_test.wast.hpp" using namespace eos; using namespace chain; @@ -1184,85 +1183,4 @@ BOOST_FIXTURE_TEST_CASE(create_script_w_loop, testing_fixture) } } FC_LOG_AND_RETHROW() } -#define MEMORY_TEST_RUN(account_name) \ - Make_Blockchain(chain); \ - chain.produce_blocks(1); \ - Make_Account(chain, account_name); \ - chain.produce_blocks(1); \ - \ - \ - types::setcode handler; \ - handler.account = #account_name; \ - \ - auto wasm = assemble_wast( memory_test_wast ); \ - handler.code.resize(wasm.size()); \ - memcpy( handler.code.data(), wasm.data(), wasm.size() ); \ - \ - { \ - eos::chain::SignedTransaction trx; \ - trx.scope = {#account_name}; \ - trx.messages.resize(1); \ - trx.messages[0].code = config::EosContractName; \ - trx.messages[0].authorization.emplace_back(types::AccountPermission{#account_name,"active"}); \ - transaction_set_message(trx, 0, "setcode", handler); \ - trx.expiration = chain.head_block_time() + 100; \ - transaction_set_reference_block(trx, chain.head_block_id()); \ - chain.push_transaction(trx); \ - chain.produce_blocks(1); \ - } \ - \ - \ - { \ - eos::chain::SignedTransaction trx; \ - trx.scope = sort_names({#account_name,"inita"}); \ - transaction_emplace_message(trx, #account_name, \ - vector{}, \ - "transfer", types::transfer{#account_name, "inita", 1,""}); \ - trx.expiration = chain.head_block_time() + 100; \ - transaction_set_reference_block(trx, chain.head_block_id()); \ - chain.push_transaction(trx); \ - chain.produce_blocks(1); \ - } - -#define MEMORY_TEST_CASE(test_case_name, account_name) \ -BOOST_FIXTURE_TEST_CASE(test_case_name, testing_fixture) \ -{ try{ \ - MEMORY_TEST_RUN(account_name); \ -} FC_LOG_AND_RETHROW() } - -//Test wasm memory allocation -MEMORY_TEST_CASE(test_memory, testmemory) - -//Test wasm memory allocation at boundaries -MEMORY_TEST_CASE(test_memory_bounds, testbounds) - -//Test intrinsic provided memset and memcpy -MEMORY_TEST_CASE(test_memset_memcpy, testmemset) - -//Test memcpy overlap at start of destination -BOOST_FIXTURE_TEST_CASE(test_memcpy_overlap_start, testing_fixture) -{ - try { - MEMORY_TEST_RUN(testolstart); - BOOST_FAIL("memcpy should have thrown assert acception"); - } - catch(fc::assert_exception& ex) - { - BOOST_REQUIRE(ex.to_detail_string().find("overlap of memory range is undefined") != std::string::npos); - } -} - -//Test memcpy overlap at end of destination -BOOST_FIXTURE_TEST_CASE(test_memcpy_overlap_end, testing_fixture) -{ - try { - MEMORY_TEST_RUN(testolend); - BOOST_FAIL("memcpy should have thrown assert acception"); - } - catch(fc::assert_exception& ex) - { - BOOST_REQUIRE(ex.to_detail_string().find("overlap of memory range is undefined") != std::string::npos); - } -} - BOOST_AUTO_TEST_SUITE_END()