Skip to content

Commit f7c2251

Browse files
authored
Merge pull request #742 from wasmx/engine-test
test: add combined wasm_engine test with imports and start function
2 parents 47401da + fa7f59e commit f7c2251

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

test/unittests/wasm_engine_test.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,48 @@ TEST(wasm_engine, host_function)
363363
ASSERT_EQ(*result.value, 8388679);
364364
}
365365
}
366+
367+
TEST(wasm_engine, start_with_host_function)
368+
{
369+
/* wat2wasm
370+
(func $adler32 (import "env" "adler32") (param i32 i32) (result i32))
371+
(global $g1 (mut i32) (i32.const 0))
372+
(memory (export "memory") 1)
373+
(func $start
374+
i32.const 0
375+
i32.const 0x55aa55aa
376+
i32.store
377+
i32.const 0
378+
i32.const 32
379+
call $adler32
380+
global.set $g1
381+
)
382+
(start $start)
383+
(func $test (export "test") (result i32)
384+
global.get $g1
385+
)
386+
*/
387+
const auto wasm = from_hex(
388+
"0061736d01000000010e0360027f7f017f6000006000017f020f0103656e760761646c65723332000003030201"
389+
"0205030100010606017f0141000b071102066d656d6f72790200047465737400020801010a1c021500410041aa"
390+
"aba9ad0536020041004120100024000b040023000b");
391+
392+
// wasm3 fails on this
393+
for (auto engine_create_fn : {create_fizzy_engine, create_fizzy_c_engine, create_wabt_engine})
394+
{
395+
auto engine = engine_create_fn();
396+
ASSERT_TRUE(engine->parse(wasm));
397+
ASSERT_TRUE(engine->instantiate(wasm));
398+
const auto func = engine->find_function("test", ":i");
399+
ASSERT_TRUE(func.has_value());
400+
401+
const auto mem_check = engine->get_memory();
402+
const auto mem_expected = bytes{0xaa, 0x55, 0xaa, 0x55};
403+
EXPECT_EQ(mem_check.substr(0, 4), mem_expected);
404+
405+
const auto result = engine->execute(*func, {});
406+
ASSERT_FALSE(result.trapped);
407+
ASSERT_TRUE(result.value.has_value());
408+
ASSERT_EQ(*result.value, 0x3d3801ff);
409+
}
410+
}

0 commit comments

Comments
 (0)