Skip to content

Commit

Permalink
Merge pull request #571 from wasmx/call_tests
Browse files Browse the repository at this point in the history
test: Add more call tests
  • Loading branch information
chfast authored Oct 5, 2020
2 parents a74e152 + 5558024 commit f61a8f1
Showing 1 changed file with 60 additions and 6 deletions.
66 changes: 60 additions & 6 deletions test/unittests/execute_call_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@ TEST(execute_call, call_with_arguments)
EXPECT_THAT(execute(parse(wasm), 1, {}), Result(4));
}

TEST(execute_call, call_shared_stack_space)
{
/* wat2wasm
(module
(func $double (param i32) (result i32)
local.get 0
local.get 0
i32.add
)
(func $main (param i32) (param i32) (result i32)
local.get 1
local.get 0
i32.add
call $double
)
)
*/
const auto wasm = from_hex(
"0061736d01000000010c0260017f017f60027f7f017f03030200010a13020700200020006a0b0900200120006a"
"10000b");

auto instance = instantiate(parse(wasm));
EXPECT_THAT(execute(*instance, 1, {2, 3}), Result(10)); // double(2+3)
}

TEST(execute_call, call_indirect)
{
/* wat2wasm
Expand Down Expand Up @@ -205,6 +231,34 @@ TEST(execute_call, call_indirect_uninited_table)
EXPECT_THAT(execute(module, 3, {4}), Traps());
}

TEST(execute_call, call_indirect_shared_stack_space)
{
/* wat2wasm
(module
(type $ft (func (param i32) (result i32)))
(func $double (param i32) (result i32)
local.get 0
local.get 0
i32.add
)
(func $main (param i32) (param i32) (result i32)
local.get 1
local.get 0
call_indirect (type $ft)
)
(table anyfunc (elem $double))
)
*/
const auto wasm = from_hex(
"0061736d01000000010c0260017f017f60027f7f017f0303020001040501700101010907010041000b01000a13"
"020700200020006a0b0900200120001100000b");

auto instance = instantiate(parse(wasm));
EXPECT_THAT(execute(*instance, 1, {0, 10}), Result(20)); // double(10)
}

TEST(execute_call, imported_function_call)
{
/* wat2wasm
Expand Down Expand Up @@ -261,16 +315,16 @@ TEST(execute_call, imported_functions_call_indirect)
(func $sqr (import "env" "sqr") (param i32) (result i64))
(func $isqrt (import "env" "isqrt") (param i32) (result i64))
(func $double (param i32) (result i64)
get_local 0
i64.extend_u/i32
get_local 0
i64.extend_u/i32
local.get 0
i64.extend_i32_u
local.get 0
i64.extend_i32_u
i64.add
)
(func $main (param i32) (param i32) (result i64)
get_local 1
get_local 0
local.get 1
local.get 0
call_indirect (type $ft)
)
Expand Down

0 comments on commit f61a8f1

Please sign in to comment.