Skip to content

Commit

Permalink
test: fizzy_execution with metering
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Jun 24, 2021
1 parent 78a0795 commit 83195ad
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/unittests/capi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,50 @@ TEST(capi_execute, execute_with_execution_conext)
fizzy_free_instance(instance);
}

TEST(capi_execute, execute_with_metered_execution_conext)
{
/* wat2wasm
(func (result i32) i32.const 42)
(func (result i32) call 0)
*/
const auto wasm =
from_hex("0061736d010000000105016000017f03030200000a0b020400412a0b040010000b");

auto module = fizzy_parse(wasm.data(), wasm.size(), nullptr);
ASSERT_NE(module, nullptr);

auto instance = fizzy_instantiate(
module, nullptr, 0, nullptr, nullptr, nullptr, 0, FizzyMemoryPagesLimitDefault, nullptr);
ASSERT_NE(instance, nullptr);

auto* ctx = fizzy_create_metered_execution_context(0, 100);
EXPECT_THAT(fizzy_execute(instance, 0, nullptr, ctx), CResult(42_u32));
EXPECT_THAT(fizzy_execute(instance, 1, nullptr, ctx), CResult(42_u32));
fizzy_free_execution_context(ctx);

// ctx = fizzy_create_metered_execution_context(0, 4);
// EXPECT_THAT(fizzy_execute(instance, 0, nullptr, ctx), CResult(42_u32));
// EXPECT_THAT(fizzy_execute(instance, 1, nullptr, ctx), CResult(42_u32));
// fizzy_free_execution_context(ctx);

ctx = fizzy_create_metered_execution_context(0, 2);
EXPECT_THAT(fizzy_execute(instance, 0, nullptr, ctx), CResult(42_u32));
EXPECT_THAT(fizzy_execute(instance, 1, nullptr, ctx), CTraps());
fizzy_free_execution_context(ctx);

ctx = fizzy_create_metered_execution_context(0, 1);
EXPECT_THAT(fizzy_execute(instance, 0, nullptr, ctx), CTraps());
EXPECT_THAT(fizzy_execute(instance, 1, nullptr, ctx), CTraps());
fizzy_free_execution_context(ctx);

ctx = fizzy_create_metered_execution_context(0, 0);
EXPECT_THAT(fizzy_execute(instance, 0, nullptr, ctx), CTraps());
EXPECT_THAT(fizzy_execute(instance, 1, nullptr, ctx), CTraps());
fizzy_free_execution_context(ctx);

fizzy_free_instance(instance);
}

TEST(capi, get_type_count)
{
/* wat2wasm
Expand Down

0 comments on commit 83195ad

Please sign in to comment.