v8/test/unittests/libplatform/single-threaded-default-platform-unittest.cc
Samuel Groß 6f5f5662cc [sandbox] Turn V8_SANDBOX into V8_ENABLE_SANDBOX
This is more consistent with similar features, for example
V8_ENABLE_WEBASSEMBLY or V8_ENABLE_MAGLEV.

Drive-by: remove V8_SANDBOX_IS_AVAILABLE as it's no longer needed.

Bug: v8:10391
Change-Id: I8658c5b0c331a4c73892737083b2c2f9b8f84056
Cq-Include-Trybots: luci.v8.try:v8_linux64_heap_sandbox_dbg_ng,v8_linux_arm64_sim_heap_sandbox_dbg_ng
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3647355
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Auto-Submit: Samuel Groß <saelo@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80530}
2022-05-13 16:23:23 +00:00

83 lines
2.2 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() {
CHECK_NULL(save_flags_);
save_flags_ = new i::SaveFlags();
v8::V8::SetFlagsFromString("--single-threaded");
WithIsolateScopeMixin::SetUpTestSuite();
}
static void TearDownTestSuite() {
WithIsolateScopeMixin::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) {
{
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