Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add more call tests #571

Merged
merged 1 commit into from
Oct 5, 2020
Merged
Changes from all commits
Commits
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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the point of this test that the same local is used twice?

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be a dup of imported_functions_call_indirect ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are simplified variants of it. They can detect an implementation defect in #572, so I keep them as they are.

{
/* 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