2020-03-27 10:02:58 +00:00
|
|
|
// Copyright 2020 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 "test/unittests/heap/cppgc/tests.h"
|
|
|
|
|
2020-04-07 21:35:29 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2020-06-10 07:10:20 +00:00
|
|
|
#include "src/heap/cppgc/object-allocator.h"
|
2020-05-26 14:40:57 +00:00
|
|
|
#include "test/unittests/heap/cppgc/test-platform.h"
|
|
|
|
|
2022-04-06 11:56:49 +00:00
|
|
|
#if !CPPGC_IS_STANDALONE
|
|
|
|
#include "include/v8-initialization.h"
|
|
|
|
#endif // !CPPGC_IS_STANDALONE
|
|
|
|
|
2020-03-27 10:02:58 +00:00
|
|
|
namespace cppgc {
|
2020-05-06 22:14:44 +00:00
|
|
|
namespace internal {
|
2020-03-27 10:02:58 +00:00
|
|
|
namespace testing {
|
|
|
|
|
|
|
|
// static
|
2020-05-28 19:04:43 +00:00
|
|
|
std::shared_ptr<TestPlatform> TestWithPlatform::platform_;
|
2020-03-27 10:02:58 +00:00
|
|
|
|
|
|
|
// static
|
|
|
|
void TestWithPlatform::SetUpTestSuite() {
|
2022-04-06 11:56:49 +00:00
|
|
|
platform_ = std::make_shared<TestPlatform>(
|
2020-11-19 12:27:35 +00:00
|
|
|
std::make_unique<DelegatingTracingController>());
|
2022-04-06 11:56:49 +00:00
|
|
|
|
|
|
|
#if !CPPGC_IS_STANDALONE
|
|
|
|
// For non-standalone builds, we need to initialize V8's platform so that it
|
|
|
|
// can be looked-up by trace-event.h.
|
|
|
|
v8::V8::InitializePlatform(platform_->GetV8Platform());
|
2022-05-13 11:10:04 +00:00
|
|
|
#ifdef V8_ENABLE_SANDBOX
|
2022-04-07 09:59:54 +00:00
|
|
|
CHECK(v8::V8::InitializeSandbox());
|
2022-05-13 11:10:04 +00:00
|
|
|
#endif // V8_ENABLE_SANDBOX
|
2022-04-06 11:56:49 +00:00
|
|
|
v8::V8::Initialize();
|
|
|
|
#endif // !CPPGC_IS_STANDALONE
|
2020-03-27 10:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void TestWithPlatform::TearDownTestSuite() {
|
2022-04-06 11:56:49 +00:00
|
|
|
#if !CPPGC_IS_STANDALONE
|
|
|
|
v8::V8::Dispose();
|
|
|
|
v8::V8::DisposePlatform();
|
|
|
|
#endif // !CPPGC_IS_STANDALONE
|
2020-05-26 14:40:57 +00:00
|
|
|
platform_.reset();
|
2020-03-27 10:02:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 22:28:41 +00:00
|
|
|
TestWithHeap::TestWithHeap()
|
|
|
|
: heap_(Heap::Create(platform_)),
|
|
|
|
allocation_handle_(heap_->GetAllocationHandle()) {}
|
2020-03-27 10:02:58 +00:00
|
|
|
|
2022-06-09 09:26:07 +00:00
|
|
|
TestWithHeap::~TestWithHeap() {
|
|
|
|
#if defined(CPPGC_CAGED_HEAP)
|
|
|
|
CagedHeap::Instance().ResetForTesting();
|
|
|
|
#endif // defined(CPPGC_CAGED_HEAP)
|
|
|
|
}
|
|
|
|
|
2020-06-10 07:10:20 +00:00
|
|
|
void TestWithHeap::ResetLinearAllocationBuffers() {
|
|
|
|
Heap::From(GetHeap())->object_allocator().ResetLinearAllocationBuffers();
|
|
|
|
}
|
|
|
|
|
2020-04-07 21:35:29 +00:00
|
|
|
TestSupportingAllocationOnly::TestSupportingAllocationOnly()
|
2021-01-26 23:09:23 +00:00
|
|
|
: no_gc_scope_(GetHeap()->GetHeapHandle()) {}
|
2020-03-27 10:02:58 +00:00
|
|
|
|
|
|
|
} // namespace testing
|
2020-05-06 22:14:44 +00:00
|
|
|
} // namespace internal
|
2020-03-27 10:02:58 +00:00
|
|
|
} // namespace cppgc
|