[wasm][test][cleanup] Use more base::Vector
The {CallWasmFunctionForTesting} function currently receives arguments as a pair of {int} and {Handle<Object>*}. Encapsulating this as a {base::Vector} makes the relation more clear and improves readability at call sites. R=ahaas@chromium.org Change-Id: I884f8d0dc1c33389b60cc53750f2e3bfcaf644a5 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4218353 Reviewed-by: Andreas Haas <ahaas@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/main@{#85638}
This commit is contained in:
parent
2c9f7ac40d
commit
d3a3d73384
@ -114,8 +114,7 @@ TEST(Run_WasmModule_Buffer_Externalized_GrowMem) {
|
|||||||
handle(memory_object->array_buffer(), isolate));
|
handle(memory_object->array_buffer(), isolate));
|
||||||
|
|
||||||
// Grow using an internal Wasm bytecode.
|
// Grow using an internal Wasm bytecode.
|
||||||
result = testing::CallWasmFunctionForTesting(isolate, instance, "main", 0,
|
result = testing::CallWasmFunctionForTesting(isolate, instance, "main", {});
|
||||||
nullptr);
|
|
||||||
CHECK_EQ(26, result);
|
CHECK_EQ(26, result);
|
||||||
CHECK(external2.buffer_->was_detached()); // growing always detaches
|
CHECK(external2.buffer_->was_detached()); // growing always detaches
|
||||||
CHECK_EQ(0, external2.buffer_->byte_length());
|
CHECK_EQ(0, external2.buffer_->byte_length());
|
||||||
|
@ -138,7 +138,7 @@ TEST(Run_WasmModule_CompilationHintsLazy) {
|
|||||||
isolate, &thrower, module.ToHandleChecked(), {}, {});
|
isolate, &thrower, module.ToHandleChecked(), {}, {});
|
||||||
CHECK(!instance.is_null());
|
CHECK(!instance.is_null());
|
||||||
int32_t result = testing::CallWasmFunctionForTesting(
|
int32_t result = testing::CallWasmFunctionForTesting(
|
||||||
isolate, instance.ToHandleChecked(), "main", 0, nullptr);
|
isolate, instance.ToHandleChecked(), "main", {});
|
||||||
CHECK_EQ(kReturnValue, result);
|
CHECK_EQ(kReturnValue, result);
|
||||||
|
|
||||||
// Lazy function was invoked and therefore compiled.
|
// Lazy function was invoked and therefore compiled.
|
||||||
@ -578,7 +578,7 @@ TEST(TestInterruptLoop) {
|
|||||||
|
|
||||||
InterruptThread thread(isolate, memory_array);
|
InterruptThread thread(isolate, memory_array);
|
||||||
CHECK(thread.Start());
|
CHECK(thread.Start());
|
||||||
testing::CallWasmFunctionForTesting(isolate, instance, "main", 0, nullptr);
|
testing::CallWasmFunctionForTesting(isolate, instance, "main", {});
|
||||||
Address address = reinterpret_cast<Address>(
|
Address address = reinterpret_cast<Address>(
|
||||||
&memory_array[InterruptThread::interrupt_location_]);
|
&memory_array[InterruptThread::interrupt_location_]);
|
||||||
CHECK_EQ(InterruptThread::interrupt_value_,
|
CHECK_EQ(InterruptThread::interrupt_value_,
|
||||||
@ -658,16 +658,17 @@ TEST(Run_WasmModule_GrowMemOobFixedIndex) {
|
|||||||
// Initial memory size is 16 pages, should trap till index > MemSize on
|
// Initial memory size is 16 pages, should trap till index > MemSize on
|
||||||
// consecutive GrowMem calls
|
// consecutive GrowMem calls
|
||||||
for (uint32_t i = 1; i < 5; i++) {
|
for (uint32_t i = 1; i < 5; i++) {
|
||||||
Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(i), isolate)};
|
Handle<Object> params[1] = {handle(Smi::FromInt(i), isolate)};
|
||||||
v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
|
v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
|
||||||
testing::CallWasmFunctionForTesting(isolate, instance, "main", 1, params);
|
testing::CallWasmFunctionForTesting(isolate, instance, "main",
|
||||||
|
base::ArrayVector(params));
|
||||||
CHECK(try_catch.HasCaught());
|
CHECK(try_catch.HasCaught());
|
||||||
isolate->clear_pending_exception();
|
isolate->clear_pending_exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(1), isolate)};
|
Handle<Object> params[1] = {handle(Smi::FromInt(1), isolate)};
|
||||||
int32_t result = testing::CallWasmFunctionForTesting(isolate, instance,
|
int32_t result = testing::CallWasmFunctionForTesting(
|
||||||
"main", 1, params);
|
isolate, instance, "main", base::ArrayVector(params));
|
||||||
CHECK_EQ(0xACED, result);
|
CHECK_EQ(0xACED, result);
|
||||||
}
|
}
|
||||||
Cleanup();
|
Cleanup();
|
||||||
@ -708,23 +709,24 @@ TEST(Run_WasmModule_GrowMemOobVariableIndex) {
|
|||||||
Handle<Object> params[1] = {
|
Handle<Object> params[1] = {
|
||||||
Handle<Object>(Smi::FromInt((16 + i) * kPageSize - 3), isolate)};
|
Handle<Object>(Smi::FromInt((16 + i) * kPageSize - 3), isolate)};
|
||||||
v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
|
v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
|
||||||
testing::CallWasmFunctionForTesting(isolate, instance, "main", 1, params);
|
testing::CallWasmFunctionForTesting(isolate, instance, "main",
|
||||||
|
base::ArrayVector(params));
|
||||||
CHECK(try_catch.HasCaught());
|
CHECK(try_catch.HasCaught());
|
||||||
isolate->clear_pending_exception();
|
isolate->clear_pending_exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < 5; i++) {
|
for (int i = 1; i < 5; i++) {
|
||||||
Handle<Object> params[1] = {
|
Handle<Object> params[1] = {
|
||||||
Handle<Object>(Smi::FromInt((20 + i) * kPageSize - 4), isolate)};
|
handle(Smi::FromInt((20 + i) * kPageSize - 4), isolate)};
|
||||||
int32_t result = testing::CallWasmFunctionForTesting(isolate, instance,
|
int32_t result = testing::CallWasmFunctionForTesting(
|
||||||
"main", 1, params);
|
isolate, instance, "main", base::ArrayVector(params));
|
||||||
CHECK_EQ(0xACED, result);
|
CHECK_EQ(0xACED, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
|
v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
|
||||||
Handle<Object> params[1] = {
|
Handle<Object> params[1] = {handle(Smi::FromInt(25 * kPageSize), isolate)};
|
||||||
Handle<Object>(Smi::FromInt(25 * kPageSize), isolate)};
|
testing::CallWasmFunctionForTesting(isolate, instance, "main",
|
||||||
testing::CallWasmFunctionForTesting(isolate, instance, "main", 1, params);
|
base::ArrayVector(params));
|
||||||
CHECK(try_catch.HasCaught());
|
CHECK(try_catch.HasCaught());
|
||||||
isolate->clear_pending_exception();
|
isolate->clear_pending_exception();
|
||||||
}
|
}
|
||||||
|
@ -96,10 +96,10 @@ class WasmSerializationTest {
|
|||||||
Handle<JSReceiver>::null(),
|
Handle<JSReceiver>::null(),
|
||||||
MaybeHandle<JSArrayBuffer>())
|
MaybeHandle<JSArrayBuffer>())
|
||||||
.ToHandleChecked();
|
.ToHandleChecked();
|
||||||
Handle<Object> params[1] = {
|
Handle<Object> params[1] = {handle(Smi::FromInt(41), CcTest::i_isolate())};
|
||||||
Handle<Object>(Smi::FromInt(41), CcTest::i_isolate())};
|
|
||||||
int32_t result = testing::CallWasmFunctionForTesting(
|
int32_t result = testing::CallWasmFunctionForTesting(
|
||||||
CcTest::i_isolate(), instance, kFunctionName, 1, params);
|
CcTest::i_isolate(), instance, kFunctionName,
|
||||||
|
base::ArrayVector(params));
|
||||||
CHECK_EQ(42, result);
|
CHECK_EQ(42, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ class WasmSerializationTest {
|
|||||||
CHECK_EQ(0, data_.size);
|
CHECK_EQ(0, data_.size);
|
||||||
while (data_.size == 0) {
|
while (data_.size == 0) {
|
||||||
testing::CallWasmFunctionForTesting(serialization_isolate, instance,
|
testing::CallWasmFunctionForTesting(serialization_isolate, instance,
|
||||||
kFunctionName, 0, nullptr);
|
kFunctionName, {});
|
||||||
data_ = compiled_module.Serialize();
|
data_ = compiled_module.Serialize();
|
||||||
}
|
}
|
||||||
CHECK_LT(0, data_.size);
|
CHECK_LT(0, data_.size);
|
||||||
|
@ -73,8 +73,7 @@ class SharedEngineIsolate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t Run(Handle<WasmInstanceObject> instance) {
|
int32_t Run(Handle<WasmInstanceObject> instance) {
|
||||||
return testing::CallWasmFunctionForTesting(isolate(), instance, "main", 0,
|
return testing::CallWasmFunctionForTesting(isolate(), instance, "main", {});
|
||||||
nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -130,7 +130,7 @@ int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return CallWasmFunctionForTesting(isolate, instance.ToHandleChecked(), "main",
|
return CallWasmFunctionForTesting(isolate, instance.ToHandleChecked(), "main",
|
||||||
0, nullptr);
|
{});
|
||||||
}
|
}
|
||||||
|
|
||||||
WasmInterpretationResult InterpretWasmModule(
|
WasmInterpretationResult InterpretWasmModule(
|
||||||
@ -218,8 +218,8 @@ MaybeHandle<WasmExportedFunction> GetExportedFunction(
|
|||||||
|
|
||||||
int32_t CallWasmFunctionForTesting(Isolate* isolate,
|
int32_t CallWasmFunctionForTesting(Isolate* isolate,
|
||||||
Handle<WasmInstanceObject> instance,
|
Handle<WasmInstanceObject> instance,
|
||||||
const char* name, int argc,
|
const char* name,
|
||||||
Handle<Object> argv[],
|
base::Vector<Handle<Object>> args,
|
||||||
std::unique_ptr<const char[]>* exception) {
|
std::unique_ptr<const char[]>* exception) {
|
||||||
DCHECK_IMPLIES(exception != nullptr, *exception == nullptr);
|
DCHECK_IMPLIES(exception != nullptr, *exception == nullptr);
|
||||||
MaybeHandle<WasmExportedFunction> maybe_export =
|
MaybeHandle<WasmExportedFunction> maybe_export =
|
||||||
@ -231,8 +231,8 @@ int32_t CallWasmFunctionForTesting(Isolate* isolate,
|
|||||||
|
|
||||||
// Call the JS function.
|
// Call the JS function.
|
||||||
Handle<Object> undefined = isolate->factory()->undefined_value();
|
Handle<Object> undefined = isolate->factory()->undefined_value();
|
||||||
MaybeHandle<Object> retval =
|
MaybeHandle<Object> retval = Execution::Call(isolate, main_export, undefined,
|
||||||
Execution::Call(isolate, main_export, undefined, argc, argv);
|
args.length(), args.begin());
|
||||||
|
|
||||||
// The result should be a number.
|
// The result should be a number.
|
||||||
if (retval.is_null()) {
|
if (retval.is_null()) {
|
||||||
|
@ -34,7 +34,7 @@ MaybeHandle<WasmExportedFunction> GetExportedFunction(
|
|||||||
// set and an exception occurs).
|
// set and an exception occurs).
|
||||||
int32_t CallWasmFunctionForTesting(
|
int32_t CallWasmFunctionForTesting(
|
||||||
Isolate* isolate, Handle<WasmInstanceObject> instance, const char* name,
|
Isolate* isolate, Handle<WasmInstanceObject> instance, const char* name,
|
||||||
int argc, Handle<Object> argv[],
|
base::Vector<Handle<Object>> args,
|
||||||
std::unique_ptr<const char[]>* exception = nullptr);
|
std::unique_ptr<const char[]>* exception = nullptr);
|
||||||
|
|
||||||
// Decode, verify, and run the function labeled "main" in the
|
// Decode, verify, and run the function labeled "main" in the
|
||||||
|
@ -124,8 +124,7 @@ void ExecuteAgainstReference(Isolate* isolate,
|
|||||||
testing::MakeDefaultArguments(isolate, main_function->sig());
|
testing::MakeDefaultArguments(isolate, main_function->sig());
|
||||||
std::unique_ptr<const char[]> exception_ref;
|
std::unique_ptr<const char[]> exception_ref;
|
||||||
int32_t result_ref = testing::CallWasmFunctionForTesting(
|
int32_t result_ref = testing::CallWasmFunctionForTesting(
|
||||||
isolate, instance_ref, "main", static_cast<int>(compiled_args.size()),
|
isolate, instance_ref, "main", compiled_args.as_vector(), &exception_ref);
|
||||||
compiled_args.begin(), &exception_ref);
|
|
||||||
// Reached max steps, do not try to execute the test module as it might
|
// Reached max steps, do not try to execute the test module as it might
|
||||||
// never terminate.
|
// never terminate.
|
||||||
if (max_steps < 0) return;
|
if (max_steps < 0) return;
|
||||||
@ -157,8 +156,7 @@ void ExecuteAgainstReference(Isolate* isolate,
|
|||||||
|
|
||||||
std::unique_ptr<const char[]> exception;
|
std::unique_ptr<const char[]> exception;
|
||||||
int32_t result = testing::CallWasmFunctionForTesting(
|
int32_t result = testing::CallWasmFunctionForTesting(
|
||||||
isolate, instance, "main", static_cast<int>(compiled_args.size()),
|
isolate, instance, "main", compiled_args.as_vector(), &exception);
|
||||||
compiled_args.begin(), &exception);
|
|
||||||
|
|
||||||
if ((exception_ref != nullptr) != (exception != nullptr)) {
|
if ((exception_ref != nullptr) != (exception != nullptr)) {
|
||||||
FATAL("Exception mispatch! Expected: <%s>; got: <%s>",
|
FATAL("Exception mispatch! Expected: <%s>; got: <%s>",
|
||||||
|
Loading…
Reference in New Issue
Block a user