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

Commit

Permalink
Moving memory_test to api_tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjohnson5972 committed Sep 11, 2017
1 parent a3dce48 commit e58d924
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 87 deletions.
10 changes: 5 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
83 changes: 83 additions & 0 deletions tests/api_tests/api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

#include <test_api/test_api.wast.hpp>
#include <test_api/test_api.hpp>

#include "memory_test/memory_test.wast.hpp"

FC_REFLECT( dummy_message, (a)(b)(c) );
FC_REFLECT( u128_msg, (values) );

Expand Down Expand Up @@ -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<types::AccountPermission>{}, \
"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()
82 changes: 0 additions & 82 deletions tests/slow_tests/slow_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include <currency/currency.wast.hpp>
#include <exchange/exchange.wast.hpp>
#include <infinite/infinite.wast.hpp>
#include "memory_test/memory_test.wast.hpp"

using namespace eos;
using namespace chain;
Expand Down Expand Up @@ -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<types::AccountPermission>{}, \
"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()

0 comments on commit e58d924

Please sign in to comment.