[wasm][test] Simplify EXPECT_CALL function invocations.

R=clemensh@chromium.org

Change-Id: I40e8068630deda0396680e062d471cda0c4ef875
Reviewed-on: https://chromium-review.googlesource.com/c/1439416
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59136}
This commit is contained in:
Michael Starzinger 2019-01-28 17:09:28 +01:00 committed by Commit Bot
parent 8e13ddc680
commit aff79f4eb1
4 changed files with 54 additions and 72 deletions

View File

@ -26,9 +26,8 @@ WASM_EXEC_TEST(TryCatchThrow) {
WASM_STMTS(WASM_DROP, WASM_I32V(kResult0))));
// Need to call through JS to allow for creation of stack traces.
Handle<JSFunction> jsfunc = r.builder().WrapCode(r.function()->func_index);
EXPECT_CALL(kResult0, jsfunc, 0);
EXPECT_CALL(kResult1, jsfunc, 1);
r.CheckCallViaJS(kResult0, 0);
r.CheckCallViaJS(kResult1, 1);
}
} // namespace test_run_wasm_exceptions

View File

@ -74,38 +74,34 @@ ManuallyImportedJSFunction CreateJSSelector(FunctionSig* sig, int which) {
WASM_EXEC_TEST(Run_Int32Sub_jswrapped) {
WasmRunner<int, int, int> r(execution_tier);
BUILD(r, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = r.builder().WrapCode(r.function()->func_index);
EXPECT_CALL(33, jsfunc, 44, 11);
EXPECT_CALL(-8723487, jsfunc, -8000000, 723487);
r.CheckCallViaJS(33, 44, 11);
r.CheckCallViaJS(-8723487, -8000000, 723487);
}
WASM_EXEC_TEST(Run_Float32Div_jswrapped) {
WasmRunner<float, float, float> r(execution_tier);
BUILD(r, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = r.builder().WrapCode(r.function()->func_index);
EXPECT_CALL(92, jsfunc, 46, 0.5);
EXPECT_CALL(64, jsfunc, -16, -0.25);
r.CheckCallViaJS(92, 46, 0.5);
r.CheckCallViaJS(64, -16, -0.25);
}
WASM_EXEC_TEST(Run_Float64Add_jswrapped) {
WasmRunner<double, double, double> r(execution_tier);
BUILD(r, WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = r.builder().WrapCode(r.function()->func_index);
EXPECT_CALL(3, jsfunc, 2, 1);
EXPECT_CALL(-5.5, jsfunc, -5.25, -0.25);
r.CheckCallViaJS(3, 2, 1);
r.CheckCallViaJS(-5.5, -5.25, -0.25);
}
WASM_EXEC_TEST(Run_I32Popcount_jswrapped) {
WasmRunner<int, int> r(execution_tier);
BUILD(r, WASM_I32_POPCNT(WASM_GET_LOCAL(0)));
Handle<JSFunction> jsfunc = r.builder().WrapCode(r.function()->func_index);
EXPECT_CALL(2, jsfunc, 9, 0);
EXPECT_CALL(3, jsfunc, 11, 0);
EXPECT_CALL(6, jsfunc, 0x3F, 0);
r.CheckCallViaJS(2, 9);
r.CheckCallViaJS(3, 11);
r.CheckCallViaJS(6, 0x3F);
}
WASM_EXEC_TEST(Run_CallJS_Add_jswrapped) {
@ -118,15 +114,11 @@ WASM_EXEC_TEST(Run_CallJS_Add_jswrapped) {
ManuallyImportedJSFunction import = {sigs.i_i(), js_function};
WasmRunner<int, int> r(execution_tier, &import);
uint32_t js_index = 0;
BUILD(r, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0)));
WasmFunctionCompiler& t = r.NewFunction(sigs.i_i());
BUILD(t, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0)));
Handle<JSFunction> jsfunc = r.builder().WrapCode(t.function_index());
EXPECT_CALL(101, jsfunc, 2, -8);
EXPECT_CALL(199, jsfunc, 100, -1);
EXPECT_CALL(-666666801, jsfunc, -666666900, -1);
r.CheckCallViaJS(101, 2);
r.CheckCallViaJS(199, 100);
r.CheckCallViaJS(-666666801, -666666900);
}
void RunJSSelectTest(ExecutionTier tier, int which) {
@ -159,9 +151,8 @@ void RunJSSelectTest(ExecutionTier tier, int which) {
t.Build(&code[0], &code[end]);
}
Handle<JSFunction> jsfunc = r.builder().WrapCode(t.function_index());
double expected = inputs.arg_d(which);
EXPECT_CALL(expected, jsfunc, 0.0, 0.0);
r.CheckCallViaJS(expected, t.function_index(), nullptr, 0);
}
}
@ -218,7 +209,6 @@ void RunWASMSelectTest(ExecutionTier tier, int which) {
WasmRunner<void> r(tier);
WasmFunctionCompiler& t = r.NewFunction(&sig);
BUILD(t, WASM_GET_LOCAL(which));
Handle<JSFunction> jsfunc = r.builder().WrapCode(t.function_index());
Handle<Object> args[] = {
isolate->factory()->NewNumber(inputs.arg_d(0)),
@ -232,7 +222,7 @@ void RunWASMSelectTest(ExecutionTier tier, int which) {
};
double expected = inputs.arg_d(which);
EXPECT_CALL(expected, jsfunc, args, kMaxParams);
r.CheckCallViaJS(expected, t.function_index(), args, kMaxParams);
}
}
@ -290,7 +280,6 @@ void RunWASMSelectAlignTest(ExecutionTier tier, int num_args, int num_params) {
WasmRunner<void> r(tier);
WasmFunctionCompiler& t = r.NewFunction(&sig);
BUILD(t, WASM_GET_LOCAL(which));
Handle<JSFunction> jsfunc = r.builder().WrapCode(t.function_index());
Handle<Object> args[] = {isolate->factory()->NewNumber(inputs.arg_d(0)),
isolate->factory()->NewNumber(inputs.arg_d(1)),
@ -305,7 +294,7 @@ void RunWASMSelectAlignTest(ExecutionTier tier, int num_args, int num_params) {
double nan = std::numeric_limits<double>::quiet_NaN();
double expected = which < num_args ? inputs.arg_d(which) : nan;
EXPECT_CALL(expected, jsfunc, args, num_args);
r.CheckCallViaJS(expected, t.function_index(), args, num_args);
}
}
@ -405,8 +394,6 @@ void RunJSSelectAlignTest(ExecutionTier tier, int num_args, int num_params) {
WasmFunctionCompiler& t = r.NewFunction(&sig);
t.Build(&code[0], &code[end]);
Handle<JSFunction> jsfunc = r.builder().WrapCode(t.function_index());
Handle<Object> args[] = {
factory->NewNumber(inputs.arg_d(0)),
factory->NewNumber(inputs.arg_d(1)),
@ -422,7 +409,7 @@ void RunJSSelectAlignTest(ExecutionTier tier, int num_args, int num_params) {
double nan = std::numeric_limits<double>::quiet_NaN();
double expected = which < num_args ? inputs.arg_d(which) : nan;
EXPECT_CALL(expected, jsfunc, args, num_args);
r.CheckCallViaJS(expected, t.function_index(), args, num_args);
}
}

View File

@ -485,37 +485,6 @@ FunctionSig* WasmRunnerBase::CreateSig(MachineType return_type,
// static
bool WasmRunnerBase::trap_happened;
void EXPECT_CALL(double expected, Handle<JSFunction> jsfunc,
Handle<Object>* buffer, int count) {
Isolate* isolate = jsfunc->GetIsolate();
Handle<Object> global(isolate->context()->global_object(), isolate);
MaybeHandle<Object> retval =
Execution::Call(isolate, jsfunc, global, count, buffer);
CHECK(!retval.is_null());
Handle<Object> result = retval.ToHandleChecked();
if (result->IsSmi()) {
CHECK_EQ(expected, Smi::ToInt(*result));
} else {
CHECK(result->IsHeapNumber());
CHECK_FLOAT_EQ(expected, HeapNumber::cast(*result)->value());
}
}
void EXPECT_CALL(double expected, Handle<JSFunction> jsfunc, double a,
double b) {
Isolate* isolate = jsfunc->GetIsolate();
Handle<Object> buffer[] = {isolate->factory()->NewNumber(a),
isolate->factory()->NewNumber(b)};
EXPECT_CALL(expected, jsfunc, buffer, 2);
}
void EXPECT_CALL(double expected, Handle<JSFunction> jsfunc, double a) {
Isolate* isolate = jsfunc->GetIsolate();
Handle<Object> buffer[] = {isolate->factory()->NewNumber(a)};
EXPECT_CALL(expected, jsfunc, buffer, 1);
}
} // namespace wasm
} // namespace internal
} // namespace v8

View File

@ -491,15 +491,42 @@ class WasmRunner : public WasmRunnerBase {
}
}
Handle<Code> GetWrapperCode() { return wrapper_.GetWrapperCode(); }
};
void CheckCallViaJS(double expected, uint32_t function_index,
Handle<Object>* buffer, int count) {
Isolate* isolate = builder_.isolate();
if (jsfuncs_.size() <= function_index) {
jsfuncs_.resize(function_index + 1);
}
if (jsfuncs_[function_index].is_null()) {
jsfuncs_[function_index] = builder_.WrapCode(function_index);
}
Handle<JSFunction> jsfunc = jsfuncs_[function_index];
Handle<Object> global(isolate->context()->global_object(), isolate);
MaybeHandle<Object> retval =
Execution::Call(isolate, jsfunc, global, count, buffer);
// TODO(mstarzinger): Rename these since they are not macros but functions.
void EXPECT_CALL(double expected, Handle<JSFunction> jsfunc,
Handle<Object>* buffer, int count);
void EXPECT_CALL(double expected, Handle<JSFunction> jsfunc, double a,
double b);
void EXPECT_CALL(double expected, Handle<JSFunction> jsfunc, double a);
CHECK(!retval.is_null());
Handle<Object> result = retval.ToHandleChecked();
if (result->IsSmi()) {
CHECK_EQ(expected, Smi::ToInt(*result));
} else {
CHECK(result->IsHeapNumber());
CHECK_FLOAT_EQ(expected, HeapNumber::cast(*result)->value());
}
}
void CheckCallViaJS(double expected, ParamTypes... p) {
Isolate* isolate = builder_.isolate();
uint32_t function_index = function()->func_index;
Handle<Object> buffer[] = {isolate->factory()->NewNumber(p)...};
return CheckCallViaJS(expected, function_index, buffer, sizeof...(p));
}
Handle<Code> GetWrapperCode() { return wrapper_.GetWrapperCode(); }
private:
std::vector<Handle<JSFunction>> jsfuncs_;
};
// A macro to define tests that run in different engine configurations.
#define WASM_EXEC_TEST(name) \