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

Minimum viable type validation #403

Merged
merged 15 commits into from
Jul 17, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: type validation tests for non-polymorphic instructions
gumb0 committed Jul 17, 2020
commit 85be095e8651a99005d22bd7dbe8d094049b7e0e
86 changes: 86 additions & 0 deletions test/unittests/validation_stack_type_test.cpp
Original file line number Diff line number Diff line change
@@ -10,6 +10,92 @@
using namespace fizzy;
using namespace fizzy::test;

TEST(validation_stack_type, instruction_type_mismatch)
{
/* wat2wasm --no-check
(func (result i32)
i32.const 0
i64.const 0
i32.add
)
*/
const auto wasm = from_hex("0061736d010000000105016000017f030201000a09010700410042006a0b");
EXPECT_THROW_MESSAGE(parse(wasm), validation_error, "type mismatch");
}

TEST(validation_stack_type, instruction_multiple_args)
{
/* wat2wasm
(memory 1)
(func
i32.const 0
i64.const 0
i64.store
)
*/
const auto wasm =
from_hex("0061736d010000000104016000000302010005030100010a0b010900410042003703000b");
EXPECT_NO_THROW(parse(wasm));

/* wat2wasm --no-check
(memory 1)
(func
i64.const 0
i32.const 0
i64.store
)
*/
const auto wasm_invalid =
from_hex("0061736d010000000104016000000302010005030100010a0b010900420041003703000b");
EXPECT_THROW_MESSAGE(parse(wasm_invalid), validation_error, "type mismatch");
}

TEST(validation_stack_type, unreachable_instruction)
{
/* wat2wasm
(func (result i32)
unreachable
i32.add
)
*/
const auto wasm = from_hex("0061736d010000000105016000017f030201000a06010400006a0b");
EXPECT_NO_THROW(parse(wasm));

/* wat2wasm
(func (result i32)
unreachable
i32.const 0
i32.add
)
*/
const auto wasm_arg = from_hex("0061736d010000000105016000017f030201000a080106000041006a0b");
EXPECT_NO_THROW(parse(wasm_arg));

/* wat2wasm
(func (result i32)
unreachable
i32.const 0
i32.const 0
i32.add
)
*/
const auto wasm_multi_arg =
from_hex("0061736d010000000105016000017f030201000a0a01080000410041006a0b");
EXPECT_NO_THROW(parse(wasm_multi_arg));

/* wat2wasm --no-check
(func (result i32)
unreachable
i64.const 0
i32.const 0
i32.add
)
*/
const auto wasm_invalid =
from_hex("0061736d010000000105016000017f030201000a0a01080000420041006a0b");
EXPECT_THROW_MESSAGE(parse(wasm_invalid), validation_error, "type mismatch");
}

TEST(validation_stack_type, call_multiple_args)
{
/* wat2wasm