Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: test/cctest/wasm/test-wasm-trap-position.cc

Issue 1924253002: [wasm] Patch trapping position into stack trace (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@pass-wasm-position-to-runtime
Patch Set: add TODO with tracking bug Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/wasm/test-wasm-stack.cc ('k') | test/mjsunit/wasm/stack.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/wasm/test-wasm-trap-position.cc
diff --git a/test/cctest/wasm/test-wasm-stack.cc b/test/cctest/wasm/test-wasm-trap-position.cc
similarity index 66%
copy from test/cctest/wasm/test-wasm-stack.cc
copy to test/cctest/wasm/test-wasm-trap-position.cc
index d32a2efb39c0001b50f9faa9025d1d319e66e9a5..13f2929ede8196b0ffde06ed4f5c8a4690568791 100644
--- a/test/cctest/wasm/test-wasm-stack.cc
+++ b/test/cctest/wasm/test-wasm-trap-position.cc
@@ -31,19 +31,6 @@ namespace {
} \
} while (0)
-void PrintStackTrace(v8::Local<v8::StackTrace> stack) {
- printf("Stack Trace (length %d):\n", stack->GetFrameCount());
- for (int i = 0, e = stack->GetFrameCount(); i != e; ++i) {
- v8::Local<v8::StackFrame> frame = stack->GetFrame(i);
- v8::Local<v8::String> script = frame->GetScriptName();
- v8::Local<v8::String> func = frame->GetFunctionName();
- printf("[%d] (%s) %s:%d:%d\n", i,
- script.IsEmpty() ? "<null>" : *v8::String::Utf8Value(script),
- func.IsEmpty() ? "<null>" : *v8::String::Utf8Value(func),
- frame->GetLineNumber(), frame->GetColumn());
- }
-}
-
struct ExceptionInfo {
const char* func_name;
int line_nr;
@@ -59,7 +46,6 @@ void CheckExceptionInfos(Isolate* isolate, Handle<Object> exc,
// Extract stack frame from the exception.
Local<v8::Value> localExc = Utils::ToLocal(exc);
v8::Local<v8::StackTrace> stack = v8::Exception::GetStackTrace(localExc);
- PrintStackTrace(stack);
CHECK(!stack.IsEmpty());
CHECK_EQ(N, stack->GetFrameCount());
@@ -74,27 +60,19 @@ void CheckExceptionInfos(Isolate* isolate, Handle<Object> exc,
} // namespace
-// Call from JS to WASM to JS and throw an Error from JS.
-TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) {
+// Trigger a trap for executing unreachable.
+TEST(Unreachable) {
TestSignatures sigs;
TestingModule module;
- // Initialize WasmFunctionCompiler first, since it sets up the HandleScope.
- WasmFunctionCompiler comp1(sigs.v_v(), &module);
-
- uint32_t js_throwing_index = module.AddJsFunction(
- sigs.v_v(),
- "(function js() {\n function a() {\n throw new Error(); };\n a(); })");
-
- // Add a nop such that we don't always get position 1.
- BUILD(comp1, WASM_NOP, WASM_CALL_FUNCTION0(js_throwing_index));
+ WasmFunctionCompiler comp1(sigs.v_v(), &module,
+ ArrayVector("exec_unreachable"));
+ // Set the execution context, such that a runtime error can be thrown.
+ comp1.SetModuleContext();
+ BUILD(comp1, WASM_UNREACHABLE);
uint32_t wasm_index = comp1.CompileAndAdd();
- WasmFunctionCompiler comp2(sigs.v_v(), &module);
- BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index));
- uint32_t wasm_index_2 = comp2.CompileAndAdd();
-
- Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2);
+ Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index);
Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
@@ -110,33 +88,29 @@ TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) {
Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc);
CHECK(returnObjMaybe.is_null());
- // Line number is 1-based, with 0 == kNoLineNumberInfo.
ExceptionInfo expected_exceptions[] = {
- {"a", 3, 8}, // -
- {"js", 4, 2}, // -
- {"<WASM>", static_cast<int>(wasm_index), 2}, // -
- {"<WASM>", static_cast<int>(wasm_index_2), 1}, // -
- {"callFn", 1, 24} // -
+ {"<WASM>", static_cast<int>(wasm_index), 1}, // --
+ {"callFn", 1, 24} // --
};
CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
expected_exceptions);
}
-// Trigger a trap in WASM, stack should be JS -> WASM -> WASM.
-TEST(CollectDetailedWasmStack_WasmError) {
+// Trigger a trap for loading from out-of-bounds.
+TEST(IllegalLoad) {
TestSignatures sigs;
TestingModule module;
- WasmFunctionCompiler comp1(sigs.i_v(), &module,
- ArrayVector("exec_unreachable"));
+ WasmFunctionCompiler comp1(sigs.v_v(), &module, ArrayVector("mem_oob"));
// Set the execution context, such that a runtime error can be thrown.
comp1.SetModuleContext();
- BUILD(comp1, WASM_UNREACHABLE);
+ BUILD(comp1, WASM_IF(WASM_ONE,
+ WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(-3))));
uint32_t wasm_index = comp1.CompileAndAdd();
- WasmFunctionCompiler comp2(sigs.i_v(), &module,
- ArrayVector("call_exec_unreachable"));
- BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index));
+ WasmFunctionCompiler comp2(sigs.v_v(), &module, ArrayVector("call_mem_oob"));
+ // Insert a NOP such that the position of the call is not one.
+ BUILD(comp2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index));
uint32_t wasm_index_2 = comp2.CompileAndAdd();
Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2);
@@ -151,16 +125,15 @@ TEST(CollectDetailedWasmStack_WasmError) {
Handle<Object> global(isolate->context()->global_object(), isolate);
MaybeHandle<Object> maybe_exc;
Handle<Object> args[] = {js_wasm_wrapper};
- MaybeHandle<Object> maybe_return_obj =
+ MaybeHandle<Object> returnObjMaybe =
Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc);
- CHECK(maybe_return_obj.is_null());
+ CHECK(returnObjMaybe.is_null());
// Line number is 1-based, with 0 == kNoLineNumberInfo.
ExceptionInfo expected_exceptions[] = {
- // TODO(clemens): position should be 1
- {"<WASM>", static_cast<int>(wasm_index), -1}, // -
- {"<WASM>", static_cast<int>(wasm_index_2), 1}, // -
- {"callFn", 1, 24} //-
+ {"<WASM>", static_cast<int>(wasm_index), 6}, // --
+ {"<WASM>", static_cast<int>(wasm_index_2), 2}, // --
+ {"callFn", 1, 24} // --
};
CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
expected_exceptions);
« no previous file with comments | « test/cctest/wasm/test-wasm-stack.cc ('k') | test/mjsunit/wasm/stack.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698