Commit b24896c6 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[test] Move single-threaded platform cctest to unittests

Also add a mixin for using the single-threaded default platform instead
of swapping it in with SetPlatformForTesting.

Bug: v8:12781
Change-Id: I304303e58ed713e5558d108cd7eb826c17abb40f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3574553
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79829}
parent 74f7a26d
......@@ -29492,38 +29492,6 @@ TEST(CodeLikeFunction) {
ExpectInt32("new Function(new CodeLike())()", 7);
}
UNINITIALIZED_TEST(SingleThreadedDefaultPlatform) {
v8::V8::SetFlagsFromString("--single-threaded");
auto old_platform = i::V8::GetCurrentPlatform();
std::unique_ptr<v8::Platform> new_platform(
v8::platform::NewSingleThreadedDefaultPlatform());
i::V8::SetPlatformForTesting(new_platform.get());
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
isolate->Enter();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
{
i::HandleScope scope(i_isolate);
v8::Local<Context> env = Context::New(isolate);
env->Enter();
CompileRunChecked(isolate,
"function f() {"
" for (let i = 0; i < 10; i++)"
" (new Array(10)).fill(0);"
" return 0;"
"}"
"f();");
env->Exit();
}
CcTest::CollectGarbage(i::NEW_SPACE, i_isolate);
CcTest::CollectAllAvailableGarbage(i_isolate);
isolate->Exit();
isolate->Dispose();
i::V8::SetPlatformForTesting(old_platform);
}
THREADED_TEST(MicrotaskQueueOfContext) {
auto microtask_queue = v8::MicrotaskQueue::New(CcTest::isolate());
v8::HandleScope scope(CcTest::isolate());
......@@ -360,6 +360,7 @@ v8_source_set("unittests_sources") {
"libplatform/default-job-unittest.cc",
"libplatform/default-platform-unittest.cc",
"libplatform/default-worker-threads-task-runner-unittest.cc",
"libplatform/single-threaded-default-platform-unittest.cc",
"libplatform/task-queue-unittest.cc",
"libplatform/worker-thread-unittest.cc",
"logging/counters-unittest.cc",
......
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "include/v8-platform.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
template <typename TMixin>
class WithSingleThreadedDefaultPlatformMixin : public TMixin {
public:
WithSingleThreadedDefaultPlatformMixin() {
platform_ = v8::platform::NewSingleThreadedDefaultPlatform();
CHECK_NOT_NULL(platform_.get());
v8::V8::InitializePlatform(platform_.get());
#ifdef V8_SANDBOX
CHECK(v8::V8::InitializeSandbox());
#endif // V8_SANDBOX
v8::V8::Initialize();
}
~WithSingleThreadedDefaultPlatformMixin() override {
CHECK_NOT_NULL(platform_.get());
v8::V8::Dispose();
v8::V8::DisposePlatform();
}
v8::Platform* platform() const { return platform_.get(); }
private:
std::unique_ptr<v8::Platform> platform_;
};
class SingleThreadedDefaultPlatformTest
: public WithContextMixin< //
WithIsolateScopeMixin< //
WithIsolateMixin< //
WithSingleThreadedDefaultPlatformMixin< //
::testing::Test>>>> {
public:
static void SetUpTestSuite() {
CHECK_NULL(save_flags_);
save_flags_ = new i::SaveFlags();
v8::V8::SetFlagsFromString("--single-threaded");
WithContextMixin::SetUpTestSuite();
}
static void TearDownTestSuite() {
WithContextMixin::TearDownTestSuite();
CHECK_NOT_NULL(save_flags_);
delete save_flags_;
save_flags_ = nullptr;
}
private:
static i::SaveFlags* save_flags_;
};
// static
i::SaveFlags* SingleThreadedDefaultPlatformTest::save_flags_;
TEST_F(SingleThreadedDefaultPlatformTest, SingleThreadedDefaultPlatform) {
RunJS(
"function f() {"
" for (let i = 0; i < 10; i++)"
" (new Array(10)).fill(0);"
" return 0;"
"}"
"f();");
}
} // namespace v8
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