Commit e8f9ff85 authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[test] Move cctest/test-api-wasm to unittests/

... api/api-wasm-unittest.

Bug: v8:12781
Change-Id: I6d6eafcbc67e114fc1fa9b1f1f8dea21ab831ee6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3748165Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Cr-Commit-Position: refs/heads/main@{#81937}
parent 7eda3f55
......@@ -333,7 +333,6 @@ v8_source_set("cctest_sources") {
# test-run-native-calls uses wasm's LinkageAllocator.
"compiler/test-run-native-calls.cc",
"test-api-wasm.cc",
"test-js-to-wasm.cc",
"wasm/test-backing-store.cc",
"wasm/test-c-wasm-entry.cc",
......
......@@ -553,8 +553,6 @@
'test-api/WasmI32AtomicWaitCallback': [SKIP],
'test-api/WasmI64AtomicWaitCallback': [SKIP],
'test-api/WasmSetJitCodeEventHandler': [SKIP],
'test-api-wasm/WasmStreaming*': [SKIP],
'test-api-wasm/WasmCompileToWasmModuleObject': [SKIP],
'test-backing-store/Run_WasmModule_Buffer_Externalized_Regression_UseAfterFree': [SKIP],
'test-c-wasm-entry/*': [SKIP],
'test-compilation-cache/*': [SKIP],
......@@ -841,7 +839,6 @@
# Performs GC or expects OOM
'test-alloc/StressHandles': [SKIP],
'test-alloc/StressJS': [SKIP],
'test-api-wasm/WasmStreamingCallback': [SKIP],
'test-api/DontLeakGlobalObjects': [SKIP],
'test-api/ExternalInternalizedStringCollectedAtGC': [SKIP],
'test-api/ExternalStringWithDisposeHandling': [SKIP],
......
......@@ -504,6 +504,7 @@ v8_source_set("unittests_sources") {
if (v8_enable_webassembly) {
sources += [
"../../test/common/wasm/wasm-macro-gen.h",
"api/api-wasm-unittest.cc",
"asmjs/asm-scanner-unittest.cc",
"asmjs/asm-types-unittest.cc",
"compiler/int64-lowering-unittest.cc",
......
......@@ -13,9 +13,10 @@
#include "include/v8-wasm.h"
#include "src/api/api-inl.h"
#include "src/handles/global-handles.h"
#include "test/cctest/cctest.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
namespace v8 {
bool wasm_streaming_callback_got_called = false;
bool wasm_streaming_data_got_collected = false;
......@@ -24,125 +25,124 @@ bool wasm_streaming_data_got_collected = false;
const uint8_t kMinimalWasmModuleBytes[]{0x00, 0x61, 0x73, 0x6d,
0x01, 0x00, 0x00, 0x00};
void WasmStreamingTestFinalizer(const v8::WeakCallbackInfo<void>& data) {
class ApiWasmTest : public TestWithIsolate {
public:
void TestWasmStreaming(WasmStreamingCallback callback,
Promise::PromiseState expected_state) {
isolate()->SetWasmStreamingCallback(callback);
HandleScope scope(isolate());
Local<Context> context = Context::New(isolate());
Context::Scope context_scope(context);
// Call {WebAssembly.compileStreaming} with {null} as parameter. The
// parameter is only really processed by the embedder, so for this test the
// value is irrelevant.
Local<Promise> promise =
Local<Promise>::Cast(RunJS("WebAssembly.compileStreaming(null)"));
while (platform::PumpMessageLoop(platform(), isolate())) {
}
CHECK_EQ(expected_state, promise->State());
}
};
void WasmStreamingTestFinalizer(const WeakCallbackInfo<void>& data) {
CHECK(!wasm_streaming_data_got_collected);
wasm_streaming_data_got_collected = true;
i::GlobalHandles::Destroy(reinterpret_cast<i::Address*>(data.GetParameter()));
}
void WasmStreamingCallbackTestCallbackIsCalled(
const v8::FunctionCallbackInfo<v8::Value>& args) {
const FunctionCallbackInfo<Value>& args) {
CHECK(!wasm_streaming_callback_got_called);
wasm_streaming_callback_got_called = true;
i::Handle<i::Object> global_handle =
reinterpret_cast<i::Isolate*>(args.GetIsolate())
->global_handles()
->Create(*v8::Utils::OpenHandle(*args.Data()));
->Create(*Utils::OpenHandle(*args.Data()));
i::GlobalHandles::MakeWeak(global_handle.location(), global_handle.location(),
WasmStreamingTestFinalizer,
v8::WeakCallbackType::kParameter);
}
void WasmStreamingCallbackTestOnBytesReceived(
const v8::FunctionCallbackInfo<v8::Value>& args) {
std::shared_ptr<v8::WasmStreaming> streaming =
v8::WasmStreaming::Unpack(args.GetIsolate(), args.Data());
// The first bytes of the WebAssembly magic word.
const uint8_t bytes[]{0x00, 0x61, 0x73};
streaming->OnBytesReceived(bytes, arraysize(bytes));
WeakCallbackType::kParameter);
}
void WasmStreamingCallbackTestFinishWithSuccess(
const v8::FunctionCallbackInfo<v8::Value>& args) {
std::shared_ptr<v8::WasmStreaming> streaming =
v8::WasmStreaming::Unpack(args.GetIsolate(), args.Data());
const FunctionCallbackInfo<Value>& args) {
std::shared_ptr<WasmStreaming> streaming =
WasmStreaming::Unpack(args.GetIsolate(), args.Data());
streaming->OnBytesReceived(kMinimalWasmModuleBytes,
arraysize(kMinimalWasmModuleBytes));
streaming->Finish();
}
void WasmStreamingCallbackTestFinishWithFailure(
const v8::FunctionCallbackInfo<v8::Value>& args) {
std::shared_ptr<v8::WasmStreaming> streaming =
v8::WasmStreaming::Unpack(args.GetIsolate(), args.Data());
const FunctionCallbackInfo<Value>& args) {
std::shared_ptr<WasmStreaming> streaming =
WasmStreaming::Unpack(args.GetIsolate(), args.Data());
streaming->Finish();
}
void WasmStreamingCallbackTestAbortWithReject(
const v8::FunctionCallbackInfo<v8::Value>& args) {
std::shared_ptr<v8::WasmStreaming> streaming =
v8::WasmStreaming::Unpack(args.GetIsolate(), args.Data());
streaming->Abort(v8::Object::New(args.GetIsolate()));
const FunctionCallbackInfo<Value>& args) {
std::shared_ptr<WasmStreaming> streaming =
WasmStreaming::Unpack(args.GetIsolate(), args.Data());
streaming->Abort(Object::New(args.GetIsolate()));
}
void WasmStreamingCallbackTestAbortNoReject(
const v8::FunctionCallbackInfo<v8::Value>& args) {
std::shared_ptr<v8::WasmStreaming> streaming =
v8::WasmStreaming::Unpack(args.GetIsolate(), args.Data());
const FunctionCallbackInfo<Value>& args) {
std::shared_ptr<WasmStreaming> streaming =
WasmStreaming::Unpack(args.GetIsolate(), args.Data());
streaming->Abort({});
}
void TestWasmStreaming(v8::WasmStreamingCallback callback,
v8::Promise::PromiseState expected_state) {
CcTest::isolate()->SetWasmStreamingCallback(callback);
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
// Call {WebAssembly.compileStreaming} with {null} as parameter. The parameter
// is only really processed by the embedder, so for this test the value is
// irrelevant.
v8::Local<v8::Promise> promise = v8::Local<v8::Promise>::Cast(
CompileRun("WebAssembly.compileStreaming(null)"));
void WasmStreamingCallbackTestOnBytesReceived(
const FunctionCallbackInfo<Value>& args) {
std::shared_ptr<WasmStreaming> streaming =
WasmStreaming::Unpack(args.GetIsolate(), args.Data());
EmptyMessageQueues(isolate);
CHECK_EQ(expected_state, promise->State());
// The first bytes of the WebAssembly magic word.
const uint8_t bytes[]{0x00, 0x61, 0x73};
streaming->OnBytesReceived(bytes, arraysize(bytes));
}
} // namespace
TEST(WasmStreamingCallback) {
TEST_F(ApiWasmTest, WasmStreamingCallback) {
TestWasmStreaming(WasmStreamingCallbackTestCallbackIsCalled,
v8::Promise::kPending);
Promise::kPending);
CHECK(wasm_streaming_callback_got_called);
CcTest::CollectAllAvailableGarbage();
CollectAllAvailableGarbage();
CHECK(wasm_streaming_data_got_collected);
}
TEST(WasmStreamingOnBytesReceived) {
TEST_F(ApiWasmTest, WasmStreamingOnBytesReceived) {
TestWasmStreaming(WasmStreamingCallbackTestOnBytesReceived,
v8::Promise::kPending);
Promise::kPending);
}
TEST(WasmStreamingFinishWithSuccess) {
TEST_F(ApiWasmTest, WasmStreamingFinishWithSuccess) {
TestWasmStreaming(WasmStreamingCallbackTestFinishWithSuccess,
v8::Promise::kFulfilled);
Promise::kFulfilled);
}
TEST(WasmStreamingFinishWithFailure) {
TEST_F(ApiWasmTest, WasmStreamingFinishWithFailure) {
TestWasmStreaming(WasmStreamingCallbackTestFinishWithFailure,
v8::Promise::kRejected);
Promise::kRejected);
}
TEST(WasmStreamingAbortWithReject) {
TEST_F(ApiWasmTest, WasmStreamingAbortWithReject) {
TestWasmStreaming(WasmStreamingCallbackTestAbortWithReject,
v8::Promise::kRejected);
Promise::kRejected);
}
TEST(WasmStreamingAbortWithoutReject) {
TestWasmStreaming(WasmStreamingCallbackTestAbortNoReject,
v8::Promise::kPending);
TEST_F(ApiWasmTest, WasmStreamingAbortWithoutReject) {
TestWasmStreaming(WasmStreamingCallbackTestAbortNoReject, Promise::kPending);
}
TEST(WasmCompileToWasmModuleObject) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
auto maybe_module = v8::WasmModuleObject::Compile(
CcTest::isolate(),
{kMinimalWasmModuleBytes, arraysize(kMinimalWasmModuleBytes)});
TEST_F(ApiWasmTest, WasmCompileToWasmModuleObject) {
Local<Context> context = Context::New(isolate());
Context::Scope context_scope(context);
auto maybe_module = WasmModuleObject::Compile(
isolate(), {kMinimalWasmModuleBytes, arraysize(kMinimalWasmModuleBytes)});
CHECK(!maybe_module.IsEmpty());
}
......@@ -151,23 +151,19 @@ namespace {
bool wasm_simd_enabled_value = false;
bool wasm_exceptions_enabled_value = false;
bool MockWasmSimdEnabledCallback(v8::Local<v8::Context>) {
bool MockWasmSimdEnabledCallback(Local<Context>) {
return wasm_simd_enabled_value;
}
bool MockWasmExceptionsEnabledCallback(v8::Local<v8::Context>) {
bool MockWasmExceptionsEnabledCallback(Local<Context>) {
return wasm_exceptions_enabled_value;
}
} // namespace
TEST(TestSetWasmSimdEnabledCallback) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
i::Handle<i::Context> i_context = v8::Utils::OpenHandle(*context);
TEST_F(ApiWasmTest, TestSetWasmSimdEnabledCallback) {
Local<Context> context = Context::New(isolate());
i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
// {Isolate::IsWasmSimdEnabled} calls the callback set by the embedder if
// such a callback exists. Otherwise it returns
......@@ -176,27 +172,23 @@ TEST(TestSetWasmSimdEnabledCallback) {
// the callback is set.
i::FLAG_experimental_wasm_simd = false;
CHECK(!i_isolate->IsWasmSimdEnabled(i_context));
CHECK(!i_isolate()->IsWasmSimdEnabled(i_context));
i::FLAG_experimental_wasm_simd = true;
CHECK(i_isolate->IsWasmSimdEnabled(i_context));
CHECK(i_isolate()->IsWasmSimdEnabled(i_context));
isolate->SetWasmSimdEnabledCallback(MockWasmSimdEnabledCallback);
isolate()->SetWasmSimdEnabledCallback(MockWasmSimdEnabledCallback);
wasm_simd_enabled_value = false;
CHECK(!i_isolate->IsWasmSimdEnabled(i_context));
CHECK(!i_isolate()->IsWasmSimdEnabled(i_context));
wasm_simd_enabled_value = true;
i::FLAG_experimental_wasm_simd = false;
CHECK(i_isolate->IsWasmSimdEnabled(i_context));
CHECK(i_isolate()->IsWasmSimdEnabled(i_context));
}
TEST(TestSetWasmExceptionsEnabledCallback) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
i::Handle<i::Context> i_context = v8::Utils::OpenHandle(*context);
TEST_F(ApiWasmTest, TestSetWasmExceptionsEnabledCallback) {
Local<Context> context = Context::New(isolate());
i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
// {Isolate::AreWasmExceptionsEnabled} calls the callback set by the embedder
// if such a callback exists. Otherwise it returns
......@@ -205,16 +197,19 @@ TEST(TestSetWasmExceptionsEnabledCallback) {
// the callback is set.
i::FLAG_experimental_wasm_eh = false;
CHECK(!i_isolate->AreWasmExceptionsEnabled(i_context));
CHECK(!i_isolate()->AreWasmExceptionsEnabled(i_context));
i::FLAG_experimental_wasm_eh = true;
CHECK(i_isolate->AreWasmExceptionsEnabled(i_context));
CHECK(i_isolate()->AreWasmExceptionsEnabled(i_context));
isolate->SetWasmExceptionsEnabledCallback(MockWasmExceptionsEnabledCallback);
isolate()->SetWasmExceptionsEnabledCallback(
MockWasmExceptionsEnabledCallback);
wasm_exceptions_enabled_value = false;
CHECK(!i_isolate->AreWasmExceptionsEnabled(i_context));
CHECK(!i_isolate()->AreWasmExceptionsEnabled(i_context));
wasm_exceptions_enabled_value = true;
i::FLAG_experimental_wasm_eh = false;
CHECK(i_isolate->AreWasmExceptionsEnabled(i_context));
CHECK(i_isolate()->AreWasmExceptionsEnabled(i_context));
}
} // namespace v8
......@@ -67,6 +67,9 @@
['not has_webassembly or variant == jitless', {
'ValueSerializerTestWithSharedArrayBufferClone.RoundTripWebAssemblyMemory': [SKIP],
'ValueSerializerTestWithWasm.*': [SKIP],
'ApiWasmTest.WasmStreaming*': [SKIP],
'ApiWasmTest.WasmCompileToWasmModuleObject': [SKIP],
'ApiWasmTest.WasmStreamingCallback': [SKIP],
}], # not has_webassembly or variant == jitless
##############################################################################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment