v8/test/unittests/heap/cppgc/tests.cc
Michael Lippautz b73835ef64 cppgc: Make tests use idiomatic allocation
Neither Member, nor GarbageCollected objects (and friends) should be
allocated on the stack. Create a special test fixture that allows for
writing idiomatic unit tests that depend on allocation but do not pull
in garbage collection.

Bug: chromium:1056170
Change-Id: I4118201a51658f7247412434a867d35c91299439
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2139583
Reviewed-by: Omer Katz <omerkatz@chromium.org>
Reviewed-by: Anton Bikineev <bikineev@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67046}
2020-04-08 06:56:20 +00:00

35 lines
918 B
C++

// 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"
#include <memory>
namespace cppgc {
namespace testing {
// static
std::unique_ptr<cppgc::PageAllocator> TestWithPlatform::page_allocator_;
// static
void TestWithPlatform::SetUpTestSuite() {
page_allocator_ = std::make_unique<v8::base::PageAllocator>();
cppgc::InitializePlatform(page_allocator_.get());
}
// static
void TestWithPlatform::TearDownTestSuite() {
cppgc::ShutdownPlatform();
page_allocator_.reset();
}
TestWithHeap::TestWithHeap() : heap_(Heap::Create()) {}
TestSupportingAllocationOnly::TestSupportingAllocationOnly()
: no_gc_scope_(std::make_unique<internal::Heap::NoGCScope>(
internal::Heap::From(GetHeap()))) {}
} // namespace testing
} // namespace cppgc