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

Unified Diff: test/cctest/wasm/wasm-run-utils.h

Issue 2685583003: [wasm] Do not use setjmp/longjmp in cctests. (Closed)
Patch Set: Change comments Created 3 years, 10 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-run-wasm-64.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/wasm/wasm-run-utils.h
diff --git a/test/cctest/wasm/wasm-run-utils.h b/test/cctest/wasm/wasm-run-utils.h
index 7eef59c515ed1965adf63edc0d002bbe781be612..31f98f4ce63bd7b7bce221257c5e73d385f32564 100644
--- a/test/cctest/wasm/wasm-run-utils.h
+++ b/test/cctest/wasm/wasm-run-utils.h
@@ -741,9 +741,9 @@ class WasmRunnerBase : public HandleAndZoneScope {
bool interpret() { return module_.execution_mode() == kExecuteInterpreted; }
public:
- // This field has to be static. Otherwise, gcc complains about the using in
+ // This field has to be static. Otherwise, gcc complains about the use in
// the lambda context below.
- static jmp_buf jump_buffer;
+ static bool trap_happened;
};
template <typename ReturnType, typename... ParamTypes>
@@ -762,15 +762,24 @@ class WasmRunner : public WasmRunnerBase {
DCHECK(compiled_);
if (interpret()) return CallInterpreter(p...);
- // Use setjmp/longjmp to deal with traps in WebAssembly code.
ReturnType return_value = static_cast<ReturnType>(0xdeadbeefdeadbeef);
- static int setjmp_ret;
- setjmp_ret = setjmp(WasmRunnerBase::jump_buffer);
- // setjmp returns 0 on the first return, 1 (passed to longjmp) after trap.
- if (setjmp_ret == 0) {
- DoCall(static_cast<void*>(&p)..., static_cast<void*>(&return_value));
- }
- return return_value;
+ WasmRunnerBase::trap_happened = false;
+ auto trap_callback = []() -> void {
+ WasmRunnerBase::trap_happened = true;
+ set_trap_callback_for_testing(nullptr);
+ };
+ set_trap_callback_for_testing(trap_callback);
+
+ wrapper_.SetInnerCode(
+ module_.GetFunctionCode(functions_[0]->function_index()));
+ CodeRunner<int32_t> runner(CcTest::InitIsolateOnce(),
+ wrapper_.GetWrapperCode(), wrapper_.signature());
+ int32_t result = runner.Call(static_cast<void*>(&p)...,
+ static_cast<void*>(&return_value));
+ CHECK_EQ(WASM_WRAPPER_RETURN_VALUE, result);
+ return WasmRunnerBase::trap_happened
+ ? static_cast<ReturnType>(0xdeadbeefdeadbeef)
+ : return_value;
}
ReturnType CallInterpreter(ParamTypes... p) {
@@ -791,30 +800,10 @@ class WasmRunner : public WasmRunnerBase {
return ReturnType{0};
}
}
-
- private:
- // Don't inline this function. The setjmp above should be followed immediately
- // by a call.
- template <typename... Ptrs>
- V8_NOINLINE void DoCall(Ptrs... ptrs) {
- auto trap_callback = []() -> void {
- set_trap_callback_for_testing(nullptr);
- longjmp(WasmRunnerBase::jump_buffer, 1);
- };
- set_trap_callback_for_testing(trap_callback);
-
- wrapper_.SetInnerCode(
- module_.GetFunctionCode(functions_[0]->function_index()));
- CodeRunner<int32_t> runner(CcTest::InitIsolateOnce(),
- wrapper_.GetWrapperCode(), wrapper_.signature());
- int32_t result = runner.Call(ptrs...);
- // If we arrive here, no trap happened.
- CHECK_EQ(WASM_WRAPPER_RETURN_VALUE, result);
- }
};
// Declare static variable.
-jmp_buf WasmRunnerBase::jump_buffer;
+bool WasmRunnerBase::trap_happened;
// A macro to define tests that run in different engine configurations.
#define WASM_EXEC_TEST(name) \
« no previous file with comments | « test/cctest/wasm/test-run-wasm-64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698