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

Side by Side Diff: test/cctest/wasm/test-wasm-trap-position.cc

Issue 2583543002: Revert of [wasm] Make WasmRunner the central test structure (Closed)
Patch Set: Created 4 years 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 unified diff | Download patch
« no previous file with comments | « test/cctest/wasm/test-wasm-stack.cc ('k') | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/wasm/wasm-macro-gen.h" 5 #include "src/wasm/wasm-macro-gen.h"
6 6
7 #include "test/cctest/cctest.h" 7 #include "test/cctest/cctest.h"
8 #include "test/cctest/compiler/value-helper.h" 8 #include "test/cctest/compiler/value-helper.h"
9 #include "test/cctest/wasm/wasm-run-utils.h" 9 #include "test/cctest/wasm/wasm-run-utils.h"
10 #include "test/common/wasm/test-signatures.h" 10 #include "test/common/wasm/test-signatures.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 CHECK_CSTREQ(excInfos[frameNr].func_name, *funName); 55 CHECK_CSTREQ(excInfos[frameNr].func_name, *funName);
56 CHECK_EQ(excInfos[frameNr].line_nr, frame->GetLineNumber()); 56 CHECK_EQ(excInfos[frameNr].line_nr, frame->GetLineNumber());
57 CHECK_EQ(excInfos[frameNr].column, frame->GetColumn()); 57 CHECK_EQ(excInfos[frameNr].column, frame->GetColumn());
58 } 58 }
59 } 59 }
60 60
61 } // namespace 61 } // namespace
62 62
63 // Trigger a trap for executing unreachable. 63 // Trigger a trap for executing unreachable.
64 TEST(Unreachable) { 64 TEST(Unreachable) {
65 WasmRunner<void> r(kExecuteCompiled);
66 TestSignatures sigs; 65 TestSignatures sigs;
66 TestingModule module;
67
68 WasmFunctionCompiler comp1(sigs.v_v(), &module,
69 ArrayVector("exec_unreachable"));
67 // Set the execution context, such that a runtime error can be thrown. 70 // Set the execution context, such that a runtime error can be thrown.
68 r.SetModuleContext(); 71 comp1.SetModuleContext();
72 BUILD(comp1, WASM_UNREACHABLE);
73 uint32_t wasm_index = comp1.CompileAndAdd();
69 74
70 BUILD(r, WASM_UNREACHABLE); 75 Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index);
71 uint32_t wasm_index = r.function()->func_index;
72
73 Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index);
74 76
75 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( 77 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
76 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 78 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
77 CompileRun("(function callFn(fn) { fn(); })")))); 79 CompileRun("(function callFn(fn) { fn(); })"))));
78 80
79 Isolate* isolate = js_wasm_wrapper->GetIsolate(); 81 Isolate* isolate = js_wasm_wrapper->GetIsolate();
80 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, 82 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10,
81 v8::StackTrace::kOverview); 83 v8::StackTrace::kOverview);
82 Handle<Object> global(isolate->context()->global_object(), isolate); 84 Handle<Object> global(isolate->context()->global_object(), isolate);
83 MaybeHandle<Object> maybe_exc; 85 MaybeHandle<Object> maybe_exc;
84 Handle<Object> args[] = {js_wasm_wrapper}; 86 Handle<Object> args[] = {js_wasm_wrapper};
85 MaybeHandle<Object> returnObjMaybe = 87 MaybeHandle<Object> returnObjMaybe =
86 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); 88 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc);
87 CHECK(returnObjMaybe.is_null()); 89 CHECK(returnObjMaybe.is_null());
88 90
89 // Line and column are 1-based, so add 1 for the expected wasm output. 91 // Line and column are 1-based, so add 1 for the expected wasm output.
90 ExceptionInfo expected_exceptions[] = { 92 ExceptionInfo expected_exceptions[] = {
91 {"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 2}, // -- 93 {"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 2}, // --
92 {"callFn", 1, 24} // -- 94 {"callFn", 1, 24} // --
93 }; 95 };
94 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); 96 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
95 } 97 }
96 98
97 // Trigger a trap for loading from out-of-bounds. 99 // Trigger a trap for loading from out-of-bounds.
98 TEST(IllegalLoad) { 100 TEST(IllegalLoad) {
99 WasmRunner<void> r(kExecuteCompiled);
100 TestSignatures sigs; 101 TestSignatures sigs;
102 TestingModule module;
103
104 WasmFunctionCompiler comp1(sigs.v_v(), &module, ArrayVector("mem_oob"));
101 // Set the execution context, such that a runtime error can be thrown. 105 // Set the execution context, such that a runtime error can be thrown.
102 r.SetModuleContext(); 106 comp1.SetModuleContext();
107 BUILD(comp1, WASM_IF(WASM_ONE, WASM_SEQ(WASM_LOAD_MEM(MachineType::Int32(),
108 WASM_I32V_1(-3)),
109 WASM_DROP)));
110 uint32_t wasm_index = comp1.CompileAndAdd();
103 111
104 BUILD(r, WASM_IF(WASM_ONE, WASM_SEQ(WASM_LOAD_MEM(MachineType::Int32(), 112 WasmFunctionCompiler comp2(sigs.v_v(), &module, ArrayVector("call_mem_oob"));
105 WASM_I32V_1(-3)), 113 // Insert a NOP such that the position of the call is not one.
106 WASM_DROP))); 114 BUILD(comp2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index));
107 uint32_t wasm_index_1 = r.function()->func_index; 115 uint32_t wasm_index_2 = comp2.CompileAndAdd();
108 116
109 WasmFunctionCompiler& f2 = r.NewFunction<void>(); 117 Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2);
110 // Insert a NOP such that the position of the call is not one.
111 BUILD(f2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index_1));
112 uint32_t wasm_index_2 = f2.function_index();
113
114 Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2);
115 118
116 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( 119 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
117 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 120 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
118 CompileRun("(function callFn(fn) { fn(); })")))); 121 CompileRun("(function callFn(fn) { fn(); })"))));
119 122
120 Isolate* isolate = js_wasm_wrapper->GetIsolate(); 123 Isolate* isolate = js_wasm_wrapper->GetIsolate();
121 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, 124 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10,
122 v8::StackTrace::kOverview); 125 v8::StackTrace::kOverview);
123 Handle<Object> global(isolate->context()->global_object(), isolate); 126 Handle<Object> global(isolate->context()->global_object(), isolate);
124 MaybeHandle<Object> maybe_exc; 127 MaybeHandle<Object> maybe_exc;
125 Handle<Object> args[] = {js_wasm_wrapper}; 128 Handle<Object> args[] = {js_wasm_wrapper};
126 MaybeHandle<Object> returnObjMaybe = 129 MaybeHandle<Object> returnObjMaybe =
127 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); 130 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc);
128 CHECK(returnObjMaybe.is_null()); 131 CHECK(returnObjMaybe.is_null());
129 132
130 // Line and column are 1-based, so add 1 for the expected wasm output. 133 // Line and column are 1-based, so add 1 for the expected wasm output.
131 ExceptionInfo expected_exceptions[] = { 134 ExceptionInfo expected_exceptions[] = {
132 {"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 8}, // -- 135 {"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 8}, // --
133 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 3}, // -- 136 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 3}, // --
134 {"callFn", 1, 24} // -- 137 {"callFn", 1, 24} // --
135 }; 138 };
136 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); 139 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
137 } 140 }
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-wasm-stack.cc ('k') | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698