From a9a519659452a83d8a355fd61e348ca42f2f4bae Mon Sep 17 00:00:00 2001 From: Michael Starzinger Date: Tue, 19 Feb 2019 15:54:45 +0100 Subject: [PATCH] [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 Reviewed-by: Clemens Hammacher Cr-Commit-Position: refs/heads/master@{#59691} --- test/cctest/wasm/test-run-wasm-exceptions.cc | 31 ++++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/test/cctest/wasm/test-run-wasm-exceptions.cc b/test/cctest/wasm/test-run-wasm-exceptions.cc index c53654326b..eefaa678d1 100644 --- a/test/cctest/wasm/test-run-wasm-exceptions.cc +++ b/test/cctest/wasm/test-run-wasm-exceptions.cc @@ -158,20 +158,23 @@ WASM_EXEC_TEST(TryCatchTrapTypeError) { r.CheckCallViaJS(kResult1, 1); } +namespace { + // TODO(8729): The semantics of this are not yet specified and might change, // this test aims at keeping semantics of various execution tiers consistent. -// TODO(mstarzinger): Add further tests for different kinds of traps. -WASM_EXEC_TEST(TryCatchTrapUnreachable) { +void TestTryCatchTrap(byte* code, size_t code_size, + ExecutionTier execution_tier) { TestSignatures sigs; EXPERIMENTAL_FLAG_SCOPE(eh); WasmRunner r(execution_tier, nullptr, "main", kRuntimeExceptionSupport); + r.builder().AddMemory(kWasmPageSize); constexpr uint32_t kResult0 = 23; constexpr uint32_t kResult1 = 42; // Build a trapping helper function. 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(r, WASM_TRY_CATCH_T( @@ -189,6 +192,28 @@ WASM_EXEC_TEST(TryCatchTrapUnreachable) { 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 wasm } // namespace internal