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 a unit test reusing args as locals #346

Merged
merged 1 commit into from
May 27, 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
31 changes: 31 additions & 0 deletions test/unittests/execute_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <test/utils/hex.hpp>

using namespace fizzy;
using namespace testing;

TEST(execute, end)
{
Expand Down Expand Up @@ -977,3 +978,33 @@ TEST(execute, fp_instructions)
// Second function with floating point parameters.
EXPECT_THAT(execute(*instance, 1, {}), Traps());
}

TEST(execute, reuse_args)
{
/* wat2wasm
(func $f (param i64 i64) (result i64)
local.get 0
local.get 1
i64.div_u
local.set 1
local.get 0
local.get 1
i64.rem_u
)
(func (result i64)
i64.const 23
i64.const 5
call $f
)
*/
const auto wasm = from_hex(
"0061736d01000000010b0260027e7e017e6000017e03030200010a19020e002000200180210120002001820b08"
"004217420510000b");

const std::vector<uint64_t> args{20, 3};
const auto expected = args[0] % (args[0] / args[1]);
EXPECT_THAT(execute(parse(wasm), 0, args), Result(expected));
EXPECT_THAT(args, ElementsAre(20, 3));

EXPECT_THAT(execute(parse(wasm), 1, {}), Result(23 % (23 / 5)));
}