v8/test/unittests/libplatform/single-threaded-default-platform-unittest.cc
Clemens Backes e831949f5e [test] Fix setting flags in SingleThreadedDefaultPlatformTest
We will not be able to modify flags after initializing V8 (soon).
The {SingleThreadedDefaultPlatformTest} was resetting flags during
teardown for no reason, as we do not support running multiple tests in a
row anyway. Thus remove that use of {SaveFlags} and just set the
--single-threaded flag before initializing V8.

R=ahaas@chromium.org

Bug: v8:12887
Change-Id: Ia89d442cf4b2fe2e12e258da5c0c9f1f871ded12
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3695378
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81024}
2022-06-09 08:48:21 +00:00

73 lines
1.9 KiB
C++

// 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_ENABLE_SANDBOX
CHECK(v8::V8::InitializeSandbox());
#endif // V8_ENABLE_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 WithIsolateScopeMixin< //
WithIsolateMixin< //
WithSingleThreadedDefaultPlatformMixin< //
::testing::Test>>> {
public:
static void SetUpTestSuite() {
i::FLAG_single_threaded = true;
i::FlagList::EnforceFlagImplications();
WithIsolateScopeMixin::SetUpTestSuite();
}
static void TearDownTestSuite() {
WithIsolateScopeMixin::TearDownTestSuite();
}
};
TEST_F(SingleThreadedDefaultPlatformTest, SingleThreadedDefaultPlatform) {
{
i::HandleScope scope(i_isolate());
v8::Local<Context> env = Context::New(isolate());
v8::Context::Scope context_scope(env);
RunJS(
"function f() {"
" for (let i = 0; i < 10; i++)"
" (new Array(10)).fill(0);"
" return 0;"
"}"
"f();");
}
CollectGarbage(i::NEW_SPACE);
CollectAllAvailableGarbage();
}
} // namespace v8