Skip to content

Commit

Permalink
clean up wasm_tests with 33MB memory
Browse files Browse the repository at this point in the history
  • Loading branch information
spoonincode committed Feb 26, 2018
1 parent 9a071d0 commit 00f8100
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
24 changes: 12 additions & 12 deletions tests/wasm_tests/test_wasts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@ static const char grow_memory_wast[] = R"=====(

static const char biggest_memory_wast[] = R"=====(
(module
(import "env" "sbrk" (func $sbrk (param i32) (result i32)))
(import "env" "eosio_assert" (func $eosio_assert (param i32 i32)))
(import "env" "sbrk" (func $$sbrk (param i32) (result i32)))
(import "env" "eosio_assert" (func $$eosio_assert (param i32 i32)))
(table 0 anyfunc)
(memory $0 ${MAX_WASM_PAGES})
(export "memory" (memory $0))
(export "apply" (func $apply))
(memory $$0 ${MAX_WASM_PAGES})
(export "memory" (memory $$0))
(export "apply" (func $$apply))
(func $apply (param $0 i64) (param $1 i64)
(call $eosio_assert
(func $$apply (param $$0 i64) (param $$1 i64)
(call $$eosio_assert
(i32.eq
(call $sbrk
(call $$sbrk
(i32.const 1)
)
(i32.const -1)
Expand All @@ -124,10 +124,10 @@ static const char biggest_memory_wast[] = R"=====(
static const char too_big_memory_wast[] = R"=====(
(module
(table 0 anyfunc)
(memory $0 ${MAX_WASM_PAGES_PLUS_ONE})
(export "memory" (memory $0))
(export "apply" (func $apply))
(func $apply (param $0 i64) (param $1 i64))
(memory $$0 ${MAX_WASM_PAGES_PLUS_ONE})
(export "memory" (memory $$0))
(export "apply" (func $$apply))
(func $$apply (param $$0 i64) (param $$1 i64))
)
)=====";

Expand Down
28 changes: 14 additions & 14 deletions tests/wasm_tests/wasm_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ BOOST_FIXTURE_TEST_CASE( big_memory, tester ) try {
produce_block();

string biggest_memory_wast_f = fc::format_string(biggest_memory_wast, fc::mutable_variant_object(
"MAX_WASM_PAGES", eosio::chain::wasm_constraints::maximum_linear_memory/64*1024));
"MAX_WASM_PAGES", eosio::chain::wasm_constraints::maximum_linear_memory/(64*1024)));

set_code(N(bigmem), biggest_memory_wast_f); //should pass, 16 pages is fine
set_code(N(bigmem), biggest_memory_wast_f.c_str());
produce_blocks(1);

signed_transaction trx;
Expand All @@ -360,14 +360,14 @@ BOOST_FIXTURE_TEST_CASE( big_memory, tester ) try {

set_tapos(trx);
trx.sign(get_private_key( N(bigmem), "active" ), chain_id_type());
//but should not be able to grow beyond 16th page, asserts if sbrk(1) returns other then -1
//but should not be able to grow beyond largest page
push_transaction(trx);

produce_blocks(1);

string too_big_memory_wast_f = fc::format_string(biggest_memory_wast, fc::mutable_variant_object(
"MAX_WASM_PAGES_PLUS_ONE", eosio::chain::wasm_constraints::maximum_linear_memory/64*1024+1));
BOOST_CHECK_THROW(set_code(N(bigmem), too_big_memory_wast_f), eosio::chain::wasm_execution_error);
string too_big_memory_wast_f = fc::format_string(too_big_memory_wast, fc::mutable_variant_object(
"MAX_WASM_PAGES_PLUS_ONE", eosio::chain::wasm_constraints::maximum_linear_memory/(64*1024)+1));
BOOST_CHECK_THROW(set_code(N(bigmem), too_big_memory_wast_f.c_str()), eosio::chain::wasm_execution_error);

} FC_LOG_AND_RETHROW()

Expand Down Expand Up @@ -471,17 +471,17 @@ BOOST_FIXTURE_TEST_CASE( offset_check, tester ) try {

for(const string& s : loadops) {
std::stringstream ss;
ss << "(module (memory $0 16) (func $apply (param $0 i64) (param $1 i64) ";
ss << "(drop (" << s << " offset=1048574 (i32.const 0)))";
ss << "(module (memory $0 " << eosio::chain::wasm_constraints::maximum_linear_memory/(64*1024) << ") (func $apply (param $0 i64) (param $1 i64) ";
ss << "(drop (" << s << " offset=" << eosio::chain::wasm_constraints::maximum_linear_memory-2 << " (i32.const 0)))";
ss << "))";

set_code(N(offsets), ss.str().c_str());
produce_block();
}
for(const vector<string>& o : storeops) {
std::stringstream ss;
ss << "(module (memory $0 16) (func $apply (param $0 i64) (param $1 i64) ";
ss << "(" << o[0] << " offset=1048574 (i32.const 0) (" << o[1] << ".const 0))";
ss << "(module (memory $0 " << eosio::chain::wasm_constraints::maximum_linear_memory/(64*1024) << ") (func $apply (param $0 i64) (param $1 i64) ";
ss << "(" << o[0] << " offset=" << eosio::chain::wasm_constraints::maximum_linear_memory-2 << " (i32.const 0) (" << o[1] << ".const 0))";
ss << "))";

set_code(N(offsets), ss.str().c_str());
Expand All @@ -490,17 +490,17 @@ BOOST_FIXTURE_TEST_CASE( offset_check, tester ) try {

for(const string& s : loadops) {
std::stringstream ss;
ss << "(module (memory $0 16) (func $apply (param $0 i64) (param $1 i64) ";
ss << "(drop (" << s << " offset=1048580 (i32.const 0)))";
ss << "(module (memory $0 " << eosio::chain::wasm_constraints::maximum_linear_memory/(64*1024) << ") (func $apply (param $0 i64) (param $1 i64) ";
ss << "(drop (" << s << " offset=" << eosio::chain::wasm_constraints::maximum_linear_memory+4 << " (i32.const 0)))";
ss << "))";

BOOST_CHECK_THROW(set_code(N(offsets), ss.str().c_str()), eosio::chain::wasm_execution_error);
produce_block();
}
for(const vector<string>& o : storeops) {
std::stringstream ss;
ss << "(module (memory $0 16) (func $apply (param $0 i64) (param $1 i64) ";
ss << "(" << o[0] << " offset=1048580 (i32.const 0) (" << o[1] << ".const 0))";
ss << "(module (memory $0 " << eosio::chain::wasm_constraints::maximum_linear_memory/(64*1024) << ") (func $apply (param $0 i64) (param $1 i64) ";
ss << "(" << o[0] << " offset=" << eosio::chain::wasm_constraints::maximum_linear_memory+4 << " (i32.const 0) (" << o[1] << ".const 0))";
ss << "))";

BOOST_CHECK_THROW(set_code(N(offsets), ss.str().c_str()), eosio::chain::wasm_execution_error);
Expand Down

0 comments on commit 00f8100

Please sign in to comment.