Skip to content

Commit

Permalink
wasm: wasm: buffered logs
Browse files Browse the repository at this point in the history
  • Loading branch information
malytomas committed May 25, 2024
1 parent 49ecf4f commit 278e5cb
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion externals/wamr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ set(WAMR_BUILD_FAST_INTERP 1)
set(WAMR_BUILD_FAST_JIT 0)
set(WAMR_BUILD_GLOBAL_HEAP_POOL 0)
set(WAMR_BUILD_INTERP 1)
#set(WAMR_BUILD_INVOKE_NATIVE_GENERAL 1) # avoid using asm - it clashes with jpeg
set(WAMR_BUILD_JIT 0)
set(WAMR_BUILD_LIBC_BUILTIN 1)
set(WAMR_BUILD_LIBC_UVWASI 0)
Expand All @@ -39,6 +38,7 @@ set(WAMR_DISABLE_APP_ENTRY 1)
set(WAMR_DISABLE_HW_BOUND_CHECK 1) # interferes with c++ exceptions
set(WAMR_DISABLE_STACK_HW_BOUND_CHECK 1) # interferes with c++ exceptions
set(WAMR_DISABLE_WAKEUP_BLOCKING_OP 0)
add_compile_definitions(BUILTIN_LIBC_BUFFERED_PRINTF=1 BUILTIN_LIBC_BUFFERED_PRINT_SIZE=512)

if(MSVC)
enable_language(ASM_MASM)
Expand Down
2 changes: 1 addition & 1 deletion externals/wamr/wamr
Submodule wamr updated 126 files
1 change: 0 additions & 1 deletion sources/libcore/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ namespace cage
CAGE_THROW_ERROR(Exception, "failed to initialize wasm runtime");
return 0;
}();
(void)dummy;
}

WasmTypeEnum convert(wasm_valkind_t k)
Expand Down
18 changes: 18 additions & 0 deletions sources/test-core/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,27 @@ void testWasm()
f(43);
f(44);
}
{
WasmFunction f = inst->function<sint32(sint32, sint32)>("div_int32");
CAGE_TEST(f(19, 5) == 19 / 5);
CAGE_TEST(f(20, 5) == 20 / 5);
CAGE_TEST(f(21, 5) == 21 / 5);
CAGE_TEST(f(-20, 5) == -20 / 5);
CAGE_TEST(f(20, -5) == 20 / -5);
CAGE_TEST(f(-20, -5) == -20 / -5);
}
{
CAGE_TESTCASE("invalid functions");
CAGE_TEST_THROWN(inst->function<float(float, float)>("sum_invalid"));
CAGE_TEST_THROWN([&]() { WasmFunction f = inst->function<float(double, double)>("sum_double"); }());
CAGE_TEST_THROWN([&]() { WasmFunction f = inst->function<double(float, double)>("sum_double"); }());
CAGE_TEST_THROWN([&]() { WasmFunction f = inst->function<double(double, float)>("sum_double"); }());
}
{
CAGE_TESTCASE("division by zero inside wasm");
WasmFunction f = inst->function<sint32(sint32, sint32)>("div_int32");
CAGE_TEST_THROWN(f(10, 0));
}
}

{
Expand Down Expand Up @@ -129,6 +143,10 @@ void testWasm()
CAGE_TEST_THROWN(inst->wasm2native(1'000'000'000));
CAGE_TEST_THROWN(inst->strLen(1'000'000'000));
}
{
CAGE_TESTCASE("invalid memory access inside wasm");
CAGE_TEST_THROWN(set_string(1'000'000'000, 32));
}
}

{
Expand Down
5 changes: 5 additions & 0 deletions sources/test-core/wasm/sums.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ void give_number(int32_t num)
{
// nothing
}

int32_t div_int32(int32_t a, int32_t b)
{
return a / b;
}
Binary file modified sources/test-core/wasm/sums.wasm
Binary file not shown.

0 comments on commit 278e5cb

Please sign in to comment.