Commit a9a51965 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Cover some more traps in test-run-wasm-exceptions.

R=clemensh@chromium.org
TEST=cctest/test-run-wasm-exceptions
BUG=v8:8729

Change-Id: I3751599bd72aaae1a9816e728437c64daf465f41
Reviewed-on: https://chromium-review.googlesource.com/c/1477733
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59691}
parent ef3505cb
...@@ -158,20 +158,23 @@ WASM_EXEC_TEST(TryCatchTrapTypeError) { ...@@ -158,20 +158,23 @@ WASM_EXEC_TEST(TryCatchTrapTypeError) {
r.CheckCallViaJS(kResult1, 1); r.CheckCallViaJS(kResult1, 1);
} }
namespace {
// TODO(8729): The semantics of this are not yet specified and might change, // TODO(8729): The semantics of this are not yet specified and might change,
// this test aims at keeping semantics of various execution tiers consistent. // this test aims at keeping semantics of various execution tiers consistent.
// TODO(mstarzinger): Add further tests for different kinds of traps. void TestTryCatchTrap(byte* code, size_t code_size,
WASM_EXEC_TEST(TryCatchTrapUnreachable) { ExecutionTier execution_tier) {
TestSignatures sigs; TestSignatures sigs;
EXPERIMENTAL_FLAG_SCOPE(eh); EXPERIMENTAL_FLAG_SCOPE(eh);
WasmRunner<uint32_t, uint32_t> r(execution_tier, nullptr, "main", WasmRunner<uint32_t, uint32_t> r(execution_tier, nullptr, "main",
kRuntimeExceptionSupport); kRuntimeExceptionSupport);
r.builder().AddMemory(kWasmPageSize);
constexpr uint32_t kResult0 = 23; constexpr uint32_t kResult0 = 23;
constexpr uint32_t kResult1 = 42; constexpr uint32_t kResult1 = 42;
// Build a trapping helper function. // Build a trapping helper function.
WasmFunctionCompiler& trap_func = r.NewFunction(sigs.i_ii()); WasmFunctionCompiler& trap_func = r.NewFunction(sigs.i_ii());
BUILD(trap_func, WASM_UNREACHABLE); trap_func.Build(code, code + code_size);
// Build the main test function. // Build the main test function.
BUILD(r, WASM_TRY_CATCH_T( BUILD(r, WASM_TRY_CATCH_T(
...@@ -189,6 +192,28 @@ WASM_EXEC_TEST(TryCatchTrapUnreachable) { ...@@ -189,6 +192,28 @@ WASM_EXEC_TEST(TryCatchTrapUnreachable) {
r.CheckCallViaJS(kResult1, 1); r.CheckCallViaJS(kResult1, 1);
} }
} // namespace
WASM_EXEC_TEST(TryCatchTrapUnreachable) {
byte code[] = {WASM_UNREACHABLE};
TestTryCatchTrap(code, arraysize(code), execution_tier);
}
WASM_EXEC_TEST(TryCatchTrapMemOutOfBounds) {
byte code[] = {WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(-1))};
TestTryCatchTrap(code, arraysize(code), execution_tier);
}
WASM_EXEC_TEST(TryCatchTrapDivByZero) {
byte code[] = {WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I32V_1(0))};
TestTryCatchTrap(code, arraysize(code), execution_tier);
}
WASM_EXEC_TEST(TryCatchTrapRemByZero) {
byte code[] = {WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I32V_1(0))};
TestTryCatchTrap(code, arraysize(code), execution_tier);
}
} // namespace test_run_wasm_exceptions } // namespace test_run_wasm_exceptions
} // namespace wasm } // namespace wasm
} // namespace internal } // namespace internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment