[test] Add a unittest platform setup mixin
Change the unittest runner to no longer uncondtionally set up a default platform in the "environment", but to instead make platform set-up part of the "mixin" framework for test fixtures. Requires modifying some tests that expect the platform to be available, and all flag implications resolved, before the mixin constructors run. We still keep the environment for setting up the process for cppgc. This process setup can only be done once per process, so it can no longer use the platform -- that's ok though, the page allocator used by cppgc's process initialisation doesn't have to be the same as the platform's so we can just pass in a separate new one. Change-Id: Ic8ccf39722e8212962c5bba87350c4b304388a7c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3571886 Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Auto-Submit: Leszek Swirski <leszeks@chromium.org> Commit-Queue: Leszek Swirski <leszeks@chromium.org> Cr-Commit-Position: refs/heads/main@{#79820}
This commit is contained in:
parent
38facbaae8
commit
0ff8205261
@ -2921,7 +2921,6 @@ filegroup(
|
||||
"src/heap/cppgc/compactor.h",
|
||||
"src/heap/cppgc/concurrent-marker.cc",
|
||||
"src/heap/cppgc/concurrent-marker.h",
|
||||
"src/heap/cppgc/default-platform.cc",
|
||||
"src/heap/cppgc/explicit-management.cc",
|
||||
"src/heap/cppgc/free-list.cc",
|
||||
"src/heap/cppgc/free-list.h",
|
||||
|
1
BUILD.gn
1
BUILD.gn
@ -5610,7 +5610,6 @@ v8_source_set("cppgc_base") {
|
||||
"src/heap/cppgc/compactor.h",
|
||||
"src/heap/cppgc/concurrent-marker.cc",
|
||||
"src/heap/cppgc/concurrent-marker.h",
|
||||
"src/heap/cppgc/default-platform.cc",
|
||||
"src/heap/cppgc/explicit-management.cc",
|
||||
"src/heap/cppgc/free-list.cc",
|
||||
"src/heap/cppgc/free-list.h",
|
||||
|
@ -19,15 +19,6 @@ namespace cppgc {
|
||||
*/
|
||||
class V8_EXPORT DefaultPlatform : public Platform {
|
||||
public:
|
||||
/**
|
||||
* Use this method instead of 'cppgc::InitializeProcess' when using
|
||||
* 'cppgc::DefaultPlatform'. 'cppgc::DefaultPlatform::InitializeProcess'
|
||||
* will initialize cppgc and v8 if needed (for non-standalone builds).
|
||||
*
|
||||
* \param platform DefaultPlatform instance used to initialize cppgc/v8.
|
||||
*/
|
||||
static void InitializeProcess(DefaultPlatform* platform);
|
||||
|
||||
using IdleTaskSupport = v8::platform::IdleTaskSupport;
|
||||
explicit DefaultPlatform(
|
||||
int thread_pool_size = 0,
|
||||
|
@ -57,7 +57,7 @@ int main(int argc, char* argv[]) {
|
||||
#endif // !CPPGC_IS_STANDALONE
|
||||
// Initialize the process. This must happen before any cppgc::Heap::Create()
|
||||
// calls.
|
||||
cppgc::DefaultPlatform::InitializeProcess(cppgc_platform.get());
|
||||
cppgc::InitializeProcess(cppgc_platform->GetPageAllocator());
|
||||
{
|
||||
// Create a managed heap.
|
||||
std::unique_ptr<cppgc::Heap> heap = cppgc::Heap::Create(cppgc_platform);
|
||||
|
@ -1,14 +0,0 @@
|
||||
// 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 "include/cppgc/default-platform.h"
|
||||
|
||||
namespace cppgc {
|
||||
|
||||
// static
|
||||
void DefaultPlatform::InitializeProcess(DefaultPlatform* platform) {
|
||||
cppgc::InitializeProcess(platform->GetPageAllocator());
|
||||
}
|
||||
|
||||
} // namespace cppgc
|
@ -15,7 +15,7 @@
|
||||
|
||||
namespace v8 {
|
||||
|
||||
class DeserializeTest : public testing::Test {
|
||||
class DeserializeTest : public TestWithPlatform {
|
||||
public:
|
||||
class IsolateAndContextScope {
|
||||
public:
|
||||
|
@ -43,9 +43,8 @@ class LazyCompileDispatcherTestFlags {
|
||||
static void SetFlagsForTest() {
|
||||
CHECK_NULL(save_flags_);
|
||||
save_flags_ = new SaveFlags();
|
||||
FLAG_single_threaded = true;
|
||||
FlagList::EnforceFlagImplications();
|
||||
FLAG_lazy_compile_dispatcher = true;
|
||||
FlagList::EnforceFlagImplications();
|
||||
}
|
||||
|
||||
static void RestoreFlags() {
|
||||
@ -68,13 +67,13 @@ class LazyCompileDispatcherTest : public TestWithNativeContext {
|
||||
LazyCompileDispatcherTest& operator=(const LazyCompileDispatcherTest&) =
|
||||
delete;
|
||||
|
||||
static void SetUpTestCase() {
|
||||
static void SetUpTestSuite() {
|
||||
LazyCompileDispatcherTestFlags::SetFlagsForTest();
|
||||
TestWithNativeContext::SetUpTestCase();
|
||||
TestWithNativeContext::SetUpTestSuite();
|
||||
}
|
||||
|
||||
static void TearDownTestCase() {
|
||||
TestWithNativeContext::TearDownTestCase();
|
||||
static void TearDownTestSuite() {
|
||||
TestWithNativeContext::TearDownTestSuite();
|
||||
LazyCompileDispatcherTestFlags::RestoreFlags();
|
||||
}
|
||||
|
||||
|
@ -28,17 +28,17 @@ class BytecodeAnalysisTest : public TestWithIsolateAndZone {
|
||||
BytecodeAnalysisTest(const BytecodeAnalysisTest&) = delete;
|
||||
BytecodeAnalysisTest& operator=(const BytecodeAnalysisTest&) = delete;
|
||||
|
||||
static void SetUpTestCase() {
|
||||
static void SetUpTestSuite() {
|
||||
CHECK_NULL(save_flags_);
|
||||
save_flags_ = new SaveFlags();
|
||||
i::FLAG_ignition_elide_noneffectful_bytecodes = false;
|
||||
i::FLAG_ignition_reo = false;
|
||||
|
||||
TestWithIsolateAndZone::SetUpTestCase();
|
||||
TestWithIsolateAndZone::SetUpTestSuite();
|
||||
}
|
||||
|
||||
static void TearDownTestCase() {
|
||||
TestWithIsolateAndZone::TearDownTestCase();
|
||||
static void TearDownTestSuite() {
|
||||
TestWithIsolateAndZone::TearDownTestSuite();
|
||||
delete save_flags_;
|
||||
save_flags_ = nullptr;
|
||||
}
|
||||
|
@ -413,14 +413,14 @@ class GraphReducerTest : public TestWithZone {
|
||||
public:
|
||||
GraphReducerTest() : TestWithZone(kCompressGraphZone), graph_(zone()) {}
|
||||
|
||||
static void SetUpTestCase() {
|
||||
TestWithZone::SetUpTestCase();
|
||||
static void SetUpTestSuite() {
|
||||
TestWithZone::SetUpTestSuite();
|
||||
DefaultValue<Reduction>::Set(Reducer::NoChange());
|
||||
}
|
||||
|
||||
static void TearDownTestCase() {
|
||||
static void TearDownTestSuite() {
|
||||
DefaultValue<Reduction>::Clear();
|
||||
TestWithZone::TearDownTestCase();
|
||||
TestWithZone::TearDownTestSuite();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -17,7 +17,9 @@ static int small_big_distr(base::RandomNumberGenerator* rand) {
|
||||
return rand->NextInt() / std::max(1, rand->NextInt() / 100);
|
||||
}
|
||||
|
||||
TEST(PersistentMap, RefTest) {
|
||||
class PersistentMapTest : public TestWithPlatform {};
|
||||
|
||||
TEST_F(PersistentMapTest, RefTest) {
|
||||
base::RandomNumberGenerator rand(92834738);
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
@ -76,7 +78,7 @@ TEST(PersistentMap, RefTest) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PersistentMap, Zip) {
|
||||
TEST_F(PersistentMapTest, Zip) {
|
||||
base::RandomNumberGenerator rand(92834738);
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
|
@ -10,7 +10,7 @@ namespace v8 {
|
||||
namespace internal {
|
||||
namespace compiler {
|
||||
|
||||
class ZoneStatsTest : public ::testing::Test {
|
||||
class ZoneStatsTest : public TestWithPlatform {
|
||||
public:
|
||||
ZoneStatsTest() : zone_stats_(&allocator_) {}
|
||||
|
||||
|
@ -39,16 +39,16 @@ class WithFinalizationRegistryMixin : public TMixin {
|
||||
WithFinalizationRegistryMixin& operator=(
|
||||
const WithFinalizationRegistryMixin&) = delete;
|
||||
|
||||
static void SetUpTestCase() {
|
||||
static void SetUpTestSuite() {
|
||||
CHECK_NULL(save_flags_);
|
||||
save_flags_ = new SaveFlags();
|
||||
FLAG_expose_gc = true;
|
||||
FLAG_allow_natives_syntax = true;
|
||||
TMixin::SetUpTestCase();
|
||||
TMixin::SetUpTestSuite();
|
||||
}
|
||||
|
||||
static void TearDownTestCase() {
|
||||
TMixin::TearDownTestCase();
|
||||
static void TearDownTestSuite() {
|
||||
TMixin::TearDownTestSuite();
|
||||
CHECK_NOT_NULL(save_flags_);
|
||||
delete save_flags_;
|
||||
save_flags_ = nullptr;
|
||||
@ -67,7 +67,8 @@ using TestWithNativeContextAndFinalizationRegistry = //
|
||||
WithFinalizationRegistryMixin< //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
::testing::Test>>>>>;
|
||||
WithDefaultPlatformMixin< //
|
||||
::testing::Test>>>>>>;
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -3,25 +3,22 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "include/cppgc/platform.h"
|
||||
#include "src/base/page-allocator.h"
|
||||
#include "test/unittests/heap/cppgc/test-platform.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
|
||||
namespace {
|
||||
|
||||
class DefaultPlatformEnvironment final : public ::testing::Environment {
|
||||
class CppGCEnvironment final : public ::testing::Environment {
|
||||
public:
|
||||
DefaultPlatformEnvironment() = default;
|
||||
|
||||
void SetUp() override {
|
||||
platform_ =
|
||||
std::make_unique<cppgc::internal::testing::TestPlatform>(nullptr);
|
||||
cppgc::InitializeProcess(platform_->GetPageAllocator());
|
||||
// Initialize the process for cppgc with an arbitrary page allocator. This
|
||||
// has to survive as long as the process, so it's ok to leak the allocator
|
||||
// here.
|
||||
cppgc::InitializeProcess(new v8::base::PageAllocator());
|
||||
}
|
||||
|
||||
void TearDown() override { cppgc::ShutdownProcess(); }
|
||||
|
||||
private:
|
||||
std::shared_ptr<cppgc::internal::testing::TestPlatform> platform_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@ -35,6 +32,6 @@ int main(int argc, char** argv) {
|
||||
testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
|
||||
testing::InitGoogleMock(&argc, argv);
|
||||
testing::AddGlobalTestEnvironment(new DefaultPlatformEnvironment);
|
||||
testing::AddGlobalTestEnvironment(new CppGCEnvironment);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
@ -9,6 +9,10 @@
|
||||
#include "src/heap/cppgc/object-allocator.h"
|
||||
#include "test/unittests/heap/cppgc/test-platform.h"
|
||||
|
||||
#if !CPPGC_IS_STANDALONE
|
||||
#include "include/v8-initialization.h"
|
||||
#endif // !CPPGC_IS_STANDALONE
|
||||
|
||||
namespace cppgc {
|
||||
namespace internal {
|
||||
namespace testing {
|
||||
@ -18,12 +22,23 @@ std::shared_ptr<TestPlatform> TestWithPlatform::platform_;
|
||||
|
||||
// static
|
||||
void TestWithPlatform::SetUpTestSuite() {
|
||||
platform_ = std::make_unique<TestPlatform>(
|
||||
platform_ = std::make_shared<TestPlatform>(
|
||||
std::make_unique<DelegatingTracingController>());
|
||||
|
||||
#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());
|
||||
v8::V8::Initialize();
|
||||
#endif // !CPPGC_IS_STANDALONE
|
||||
}
|
||||
|
||||
// static
|
||||
void TestWithPlatform::TearDownTestSuite() {
|
||||
#if !CPPGC_IS_STANDALONE
|
||||
v8::V8::Dispose();
|
||||
v8::V8::DisposePlatform();
|
||||
#endif // !CPPGC_IS_STANDALONE
|
||||
platform_.reset();
|
||||
}
|
||||
|
||||
|
@ -37,12 +37,13 @@ class WithHeapInternals : public TMixin, HeapInternalsBase {
|
||||
}
|
||||
};
|
||||
|
||||
using TestWithHeapInternals = //
|
||||
WithHeapInternals< //
|
||||
WithInternalIsolateMixin< //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
::testing::Test>>>>;
|
||||
using TestWithHeapInternals = //
|
||||
WithHeapInternals< //
|
||||
WithInternalIsolateMixin< //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
WithDefaultPlatformMixin< //
|
||||
::testing::Test>>>>>;
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
@ -236,14 +236,32 @@ class TrackingPageAllocator : public ::v8::PageAllocator {
|
||||
// This test is currently incompatible with the sandbox. Enable it
|
||||
// once the VirtualAddressSpace interface is stable.
|
||||
#if !V8_OS_FUCHSIA && !V8_SANDBOX
|
||||
class SequentialUnmapperTest : public TestWithIsolate {
|
||||
|
||||
template <typename TMixin>
|
||||
class SequentialUnmapperTestMixin : public TMixin {
|
||||
public:
|
||||
SequentialUnmapperTestMixin();
|
||||
~SequentialUnmapperTestMixin() override;
|
||||
};
|
||||
|
||||
class SequentialUnmapperTest : public //
|
||||
WithInternalIsolateMixin< //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
SequentialUnmapperTestMixin< //
|
||||
WithDefaultPlatformMixin< //
|
||||
::testing::Test>>>>> {
|
||||
public:
|
||||
SequentialUnmapperTest() = default;
|
||||
~SequentialUnmapperTest() override = default;
|
||||
SequentialUnmapperTest(const SequentialUnmapperTest&) = delete;
|
||||
SequentialUnmapperTest& operator=(const SequentialUnmapperTest&) = delete;
|
||||
|
||||
static void SetUpTestCase() {
|
||||
static void FreeProcessWidePtrComprCageForTesting() {
|
||||
IsolateAllocator::FreeProcessWidePtrComprCageForTesting();
|
||||
}
|
||||
|
||||
static void DoMixinSetUp() {
|
||||
CHECK_NULL(tracking_page_allocator_);
|
||||
old_page_allocator_ = GetPlatformPageAllocator();
|
||||
tracking_page_allocator_ = new TrackingPageAllocator(old_page_allocator_);
|
||||
@ -266,11 +284,9 @@ class SequentialUnmapperTest : public TestWithIsolate {
|
||||
#endif
|
||||
IsolateAllocator::InitializeOncePerProcess();
|
||||
#endif
|
||||
TestWithIsolate::SetUpTestCase();
|
||||
}
|
||||
|
||||
static void TearDownTestCase() {
|
||||
TestWithIsolate::TearDownTestCase();
|
||||
static void DoMixinTearDown() {
|
||||
#ifdef V8_COMPRESS_POINTERS_IN_SHARED_CAGE
|
||||
// Free the process-wide cage reservation, otherwise the pages won't be
|
||||
// freed until process teardown.
|
||||
@ -308,6 +324,15 @@ TrackingPageAllocator* SequentialUnmapperTest::tracking_page_allocator_ =
|
||||
v8::PageAllocator* SequentialUnmapperTest::old_page_allocator_ = nullptr;
|
||||
bool SequentialUnmapperTest::old_flag_;
|
||||
|
||||
template <typename TMixin>
|
||||
SequentialUnmapperTestMixin<TMixin>::SequentialUnmapperTestMixin() {
|
||||
SequentialUnmapperTest::DoMixinSetUp();
|
||||
}
|
||||
template <typename TMixin>
|
||||
SequentialUnmapperTestMixin<TMixin>::~SequentialUnmapperTestMixin() {
|
||||
SequentialUnmapperTest::DoMixinTearDown();
|
||||
}
|
||||
|
||||
// See v8:5945.
|
||||
TEST_F(SequentialUnmapperTest, UnmapOnTeardownAfterAlreadyFreeingPooled) {
|
||||
if (FLAG_enable_third_party_heap) return;
|
||||
|
@ -50,14 +50,14 @@ class RuntimeCallStatsTest : public TestWithNativeContext {
|
||||
TracingFlags::runtime_stats.store(0, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
static void SetUpTestCase() {
|
||||
TestWithIsolate::SetUpTestCase();
|
||||
static void SetUpTestSuite() {
|
||||
TestWithIsolate::SetUpTestSuite();
|
||||
// Use a custom time source to precisly emulate system time.
|
||||
RuntimeCallTimer::Now = &RuntimeCallStatsTestNow;
|
||||
}
|
||||
|
||||
static void TearDownTestCase() {
|
||||
TestWithIsolate::TearDownTestCase();
|
||||
static void TearDownTestSuite() {
|
||||
TestWithIsolate::TearDownTestSuite();
|
||||
// Restore the original time source.
|
||||
RuntimeCallTimer::Now = &base::TimeTicks::Now;
|
||||
}
|
||||
|
@ -2466,14 +2466,14 @@ class ValueSerializerTestWithSharedArrayBufferClone
|
||||
return sab;
|
||||
}
|
||||
|
||||
static void SetUpTestCase() {
|
||||
static void SetUpTestSuite() {
|
||||
flag_was_enabled_ = i::FLAG_harmony_sharedarraybuffer;
|
||||
i::FLAG_harmony_sharedarraybuffer = true;
|
||||
ValueSerializerTest::SetUpTestCase();
|
||||
ValueSerializerTest::SetUpTestSuite();
|
||||
}
|
||||
|
||||
static void TearDownTestCase() {
|
||||
ValueSerializerTest::TearDownTestCase();
|
||||
static void TearDownTestSuite() {
|
||||
ValueSerializerTest::TearDownTestSuite();
|
||||
i::FLAG_harmony_sharedarraybuffer = flag_was_enabled_;
|
||||
flag_was_enabled_ = false;
|
||||
}
|
||||
@ -2923,14 +2923,14 @@ class ValueSerializerTestWithWasm : public ValueSerializerTest {
|
||||
}
|
||||
|
||||
protected:
|
||||
static void SetUpTestCase() {
|
||||
static void SetUpTestSuite() {
|
||||
g_saved_flag = i::FLAG_expose_wasm;
|
||||
i::FLAG_expose_wasm = true;
|
||||
ValueSerializerTest::SetUpTestCase();
|
||||
ValueSerializerTest::SetUpTestSuite();
|
||||
}
|
||||
|
||||
static void TearDownTestCase() {
|
||||
ValueSerializerTest::TearDownTestCase();
|
||||
static void TearDownTestSuite() {
|
||||
ValueSerializerTest::TearDownTestSuite();
|
||||
i::FLAG_expose_wasm = g_saved_flag;
|
||||
g_saved_flag = false;
|
||||
}
|
||||
|
@ -8,34 +8,21 @@
|
||||
#include "include/libplatform/libplatform.h"
|
||||
#include "include/v8-initialization.h"
|
||||
#include "src/base/compiler-specific.h"
|
||||
#include "src/base/page-allocator.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
|
||||
namespace {
|
||||
|
||||
class DefaultPlatformEnvironment final : public ::testing::Environment {
|
||||
class CppGCEnvironment final : public ::testing::Environment {
|
||||
public:
|
||||
DefaultPlatformEnvironment() = default;
|
||||
|
||||
void SetUp() override {
|
||||
platform_ = v8::platform::NewDefaultPlatform(
|
||||
0, v8::platform::IdleTaskSupport::kEnabled);
|
||||
ASSERT_TRUE(platform_.get() != nullptr);
|
||||
v8::V8::InitializePlatform(platform_.get());
|
||||
#ifdef V8_SANDBOX
|
||||
ASSERT_TRUE(v8::V8::InitializeSandbox());
|
||||
#endif
|
||||
cppgc::InitializeProcess(platform_->GetPageAllocator());
|
||||
v8::V8::Initialize();
|
||||
// Initialize the process for cppgc with an arbitrary page allocator. This
|
||||
// has to survive as long as the process, so it's ok to leak the allocator
|
||||
// here.
|
||||
cppgc::InitializeProcess(new v8::base::PageAllocator());
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
ASSERT_TRUE(platform_.get() != nullptr);
|
||||
v8::V8::Dispose();
|
||||
v8::V8::DisposePlatform();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<v8::Platform> platform_;
|
||||
void TearDown() override { cppgc::ShutdownProcess(); }
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@ -50,7 +37,7 @@ int main(int argc, char** argv) {
|
||||
testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
|
||||
testing::InitGoogleMock(&argc, argv);
|
||||
testing::AddGlobalTestEnvironment(new DefaultPlatformEnvironment);
|
||||
testing::AddGlobalTestEnvironment(new CppGCEnvironment);
|
||||
v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
|
||||
v8::V8::InitializeExternalStartupData(argv[0]);
|
||||
v8::V8::InitializeICUDefaultLocation(argv[0]);
|
||||
|
@ -35,14 +35,14 @@ class BackgroundCompileTaskTest : public TestWithNativeContext {
|
||||
|
||||
AccountingAllocator* allocator() { return allocator_; }
|
||||
|
||||
static void SetUpTestCase() {
|
||||
static void SetUpTestSuite() {
|
||||
CHECK_NULL(save_flags_);
|
||||
save_flags_ = new SaveFlags();
|
||||
TestWithNativeContext::SetUpTestCase();
|
||||
TestWithNativeContext::SetUpTestSuite();
|
||||
}
|
||||
|
||||
static void TearDownTestCase() {
|
||||
TestWithNativeContext::TearDownTestCase();
|
||||
static void TearDownTestSuite() {
|
||||
TestWithNativeContext::TearDownTestSuite();
|
||||
CHECK_NOT_NULL(save_flags_);
|
||||
delete save_flags_;
|
||||
save_flags_ = nullptr;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "include/libplatform/libplatform.h"
|
||||
#include "include/v8-array-buffer.h"
|
||||
#include "include/v8-context.h"
|
||||
#include "include/v8-local-handle.h"
|
||||
@ -26,6 +27,32 @@ namespace v8 {
|
||||
|
||||
class ArrayBufferAllocator;
|
||||
|
||||
template <typename TMixin>
|
||||
class WithDefaultPlatformMixin : public TMixin {
|
||||
public:
|
||||
WithDefaultPlatformMixin() {
|
||||
platform_ = v8::platform::NewDefaultPlatform(
|
||||
0, v8::platform::IdleTaskSupport::kEnabled);
|
||||
CHECK_NOT_NULL(platform_.get());
|
||||
v8::V8::InitializePlatform(platform_.get());
|
||||
#ifdef V8_SANDBOX
|
||||
CHECK(v8::V8::InitializeSandbox());
|
||||
#endif // V8_SANDBOX
|
||||
v8::V8::Initialize();
|
||||
}
|
||||
|
||||
~WithDefaultPlatformMixin() {
|
||||
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_;
|
||||
};
|
||||
|
||||
using CounterMap = std::map<std::string, int>;
|
||||
|
||||
enum CountersMode { kNoCounters, kEnableCounters };
|
||||
@ -123,20 +150,26 @@ class WithContextMixin : public TMixin {
|
||||
v8::Context::Scope context_scope_;
|
||||
};
|
||||
|
||||
using TestWithPlatform = //
|
||||
WithDefaultPlatformMixin< //
|
||||
::testing::Test>;
|
||||
|
||||
// Use v8::internal::TestWithIsolate if you are testing internals,
|
||||
// aka. directly work with Handles.
|
||||
using TestWithIsolate = //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
::testing::Test>>;
|
||||
using TestWithIsolate = //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
WithDefaultPlatformMixin< //
|
||||
::testing::Test>>>;
|
||||
|
||||
// Use v8::internal::TestWithNativeContext if you are testing internals,
|
||||
// aka. directly work with Handles.
|
||||
using TestWithContext = //
|
||||
WithContextMixin< //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
::testing::Test>>>;
|
||||
using TestWithContext = //
|
||||
WithContextMixin< //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
WithDefaultPlatformMixin< //
|
||||
::testing::Test>>>>;
|
||||
|
||||
namespace internal {
|
||||
|
||||
@ -196,43 +229,50 @@ class WithZoneMixin : public TMixin {
|
||||
Zone zone_;
|
||||
};
|
||||
|
||||
using TestWithIsolate = //
|
||||
WithInternalIsolateMixin< //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
::testing::Test>>>;
|
||||
|
||||
using TestWithZone = WithZoneMixin<::testing::Test>;
|
||||
|
||||
using TestWithIsolateAndZone = //
|
||||
WithZoneMixin< //
|
||||
WithInternalIsolateMixin< //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
using TestWithIsolate = //
|
||||
WithInternalIsolateMixin< //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
WithDefaultPlatformMixin< //
|
||||
::testing::Test>>>>;
|
||||
|
||||
using TestWithNativeContext = //
|
||||
WithInternalIsolateMixin< //
|
||||
WithContextMixin< //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
::testing::Test>>>>;
|
||||
using TestWithZone = WithZoneMixin<WithDefaultPlatformMixin< //
|
||||
::testing::Test>>;
|
||||
|
||||
using TestWithNativeContextAndCounters = //
|
||||
WithInternalIsolateMixin< //
|
||||
WithContextMixin< //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
::testing::Test, kEnableCounters>>>>;
|
||||
|
||||
using TestWithNativeContextAndZone = //
|
||||
WithZoneMixin< //
|
||||
WithInternalIsolateMixin< //
|
||||
WithContextMixin< //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
using TestWithIsolateAndZone = //
|
||||
WithZoneMixin< //
|
||||
WithInternalIsolateMixin< //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
WithDefaultPlatformMixin< //
|
||||
::testing::Test>>>>>;
|
||||
|
||||
using TestWithNativeContext = //
|
||||
WithInternalIsolateMixin< //
|
||||
WithContextMixin< //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
WithDefaultPlatformMixin< //
|
||||
::testing::Test>>>>>;
|
||||
|
||||
using TestWithNativeContextAndCounters = //
|
||||
WithInternalIsolateMixin< //
|
||||
WithContextMixin< //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
WithDefaultPlatformMixin< //
|
||||
::testing::Test>,
|
||||
kEnableCounters>>>>;
|
||||
|
||||
using TestWithNativeContextAndZone = //
|
||||
WithZoneMixin< //
|
||||
WithInternalIsolateMixin< //
|
||||
WithContextMixin< //
|
||||
WithIsolateScopeMixin< //
|
||||
WithIsolateMixin< //
|
||||
WithDefaultPlatformMixin< //
|
||||
::testing::Test>>>>>>;
|
||||
|
||||
class V8_NODISCARD SaveFlags {
|
||||
public:
|
||||
SaveFlags();
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include "src/utils/allocation.h"
|
||||
|
||||
#include "test/unittests/test-utils.h"
|
||||
|
||||
#if V8_OS_POSIX
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
@ -29,7 +31,7 @@ namespace {
|
||||
// We don't test the execution permission because to do so we'd have to
|
||||
// dynamically generate code and test if we can execute it.
|
||||
|
||||
class MemoryAllocationPermissionsTest : public ::testing::Test {
|
||||
class MemoryAllocationPermissionsTest : public TestWithPlatform {
|
||||
static void SignalHandler(int signal, siginfo_t* info, void*) {
|
||||
siglongjmp(continuation_, 1);
|
||||
}
|
||||
@ -127,9 +129,9 @@ TEST_F(MemoryAllocationPermissionsTest, DoTest) {
|
||||
|
||||
// Basic tests of allocation.
|
||||
|
||||
class AllocationTest : public ::testing::Test {};
|
||||
class AllocationTest : public TestWithPlatform {};
|
||||
|
||||
TEST(AllocationTest, AllocateAndFree) {
|
||||
TEST_F(AllocationTest, AllocateAndFree) {
|
||||
size_t page_size = v8::internal::AllocatePageSize();
|
||||
CHECK_NE(0, page_size);
|
||||
|
||||
@ -154,7 +156,7 @@ TEST(AllocationTest, AllocateAndFree) {
|
||||
v8::internal::FreePages(page_allocator, aligned_mem_addr, kAllocationSize);
|
||||
}
|
||||
|
||||
TEST(AllocationTest, ReserveMemory) {
|
||||
TEST_F(AllocationTest, ReserveMemory) {
|
||||
v8::PageAllocator* page_allocator = v8::internal::GetPlatformPageAllocator();
|
||||
size_t page_size = v8::internal::AllocatePageSize();
|
||||
const size_t kAllocationSize = 1 * v8::internal::MB;
|
||||
|
@ -344,7 +344,7 @@ class FunctionBodyDecoderTestBase : public WithZoneMixin<BaseTest> {
|
||||
}
|
||||
};
|
||||
|
||||
using FunctionBodyDecoderTest = FunctionBodyDecoderTestBase<::testing::Test>;
|
||||
using FunctionBodyDecoderTest = FunctionBodyDecoderTestBase<TestWithPlatform>;
|
||||
|
||||
TEST_F(FunctionBodyDecoderTest, Int32Const1) {
|
||||
byte code[] = {kExprI32Const, 0};
|
||||
@ -5142,7 +5142,8 @@ TEST_F(BytecodeIteratorTest, WithLocalDecls) {
|
||||
******************************************************************************/
|
||||
|
||||
class FunctionBodyDecoderTestOnBothMemoryTypes
|
||||
: public FunctionBodyDecoderTestBase<::testing::TestWithParam<MemoryType>> {
|
||||
: public FunctionBodyDecoderTestBase<
|
||||
WithDefaultPlatformMixin<::testing::TestWithParam<MemoryType>>> {
|
||||
public:
|
||||
bool is_memory64() const { return GetParam() == kMemory64; }
|
||||
};
|
||||
|
@ -13,7 +13,7 @@ namespace internal {
|
||||
namespace wasm {
|
||||
namespace subtyping_unittest {
|
||||
|
||||
class WasmSubtypingTest : public ::testing::Test {};
|
||||
class WasmSubtypingTest : public TestWithPlatform {};
|
||||
using FieldInit = std::pair<ValueType, bool>;
|
||||
|
||||
constexpr ValueType ref(uint32_t index) {
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "src/base/page-allocator.h"
|
||||
#include "src/trap-handler/trap-handler.h"
|
||||
#include "src/utils/allocation.h"
|
||||
#include "test/unittests/test-utils.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
@ -23,7 +24,7 @@ i::Address g_start_address;
|
||||
// on if V8 doesn't handle the exception. This allows tools like ASan to
|
||||
// register a handler early on during the process startup and still generate
|
||||
// stack traces on failures.
|
||||
class ExceptionHandlerFallbackTest : public ::testing::Test {
|
||||
class ExceptionHandlerFallbackTest : public v8::TestWithPlatform {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
// Register this handler as the last handler.
|
||||
|
@ -3,12 +3,16 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "src/zone/zone-allocator.h"
|
||||
|
||||
#include "test/unittests/test-utils.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
TEST(RecyclingZoneAllocator, ReuseSameSize) {
|
||||
class RecyclingZoneAllocatorTest : public TestWithPlatform {};
|
||||
|
||||
TEST_F(RecyclingZoneAllocatorTest, ReuseSameSize) {
|
||||
AccountingAllocator accounting_allocator;
|
||||
Zone zone(&accounting_allocator, ZONE_NAME);
|
||||
RecyclingZoneAllocator<int> zone_allocator(&zone);
|
||||
@ -18,7 +22,7 @@ TEST(RecyclingZoneAllocator, ReuseSameSize) {
|
||||
CHECK_EQ(zone_allocator.allocate(10), allocated);
|
||||
}
|
||||
|
||||
TEST(RecyclingZoneAllocator, ReuseSmallerSize) {
|
||||
TEST_F(RecyclingZoneAllocatorTest, ReuseSmallerSize) {
|
||||
AccountingAllocator accounting_allocator;
|
||||
Zone zone(&accounting_allocator, ZONE_NAME);
|
||||
RecyclingZoneAllocator<int> zone_allocator(&zone);
|
||||
@ -28,7 +32,7 @@ TEST(RecyclingZoneAllocator, ReuseSmallerSize) {
|
||||
CHECK_EQ(zone_allocator.allocate(10), allocated);
|
||||
}
|
||||
|
||||
TEST(RecyclingZoneAllocator, DontReuseTooSmallSize) {
|
||||
TEST_F(RecyclingZoneAllocatorTest, DontReuseTooSmallSize) {
|
||||
AccountingAllocator accounting_allocator;
|
||||
Zone zone(&accounting_allocator, ZONE_NAME);
|
||||
RecyclingZoneAllocator<int> zone_allocator(&zone);
|
||||
@ -40,7 +44,7 @@ TEST(RecyclingZoneAllocator, DontReuseTooSmallSize) {
|
||||
CHECK_NE(zone_allocator.allocate(1), allocated);
|
||||
}
|
||||
|
||||
TEST(RecyclingZoneAllocator, ReuseMultipleSize) {
|
||||
TEST_F(RecyclingZoneAllocatorTest, ReuseMultipleSize) {
|
||||
AccountingAllocator accounting_allocator;
|
||||
Zone zone(&accounting_allocator, ZONE_NAME);
|
||||
RecyclingZoneAllocator<int> zone_allocator(&zone);
|
||||
@ -56,7 +60,7 @@ TEST(RecyclingZoneAllocator, ReuseMultipleSize) {
|
||||
CHECK_EQ(zone_allocator.allocate(10), allocated1);
|
||||
}
|
||||
|
||||
TEST(RecyclingZoneAllocator, DontChainSmallerSizes) {
|
||||
TEST_F(RecyclingZoneAllocatorTest, DontChainSmallerSizes) {
|
||||
AccountingAllocator accounting_allocator;
|
||||
Zone zone(&accounting_allocator, ZONE_NAME);
|
||||
RecyclingZoneAllocator<int> zone_allocator(&zone);
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "src/zone/accounting-allocator.h"
|
||||
#include "src/zone/zone.h"
|
||||
#include "test/unittests/test-utils.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace v8 {
|
||||
@ -13,7 +14,9 @@ namespace internal {
|
||||
|
||||
const size_t kItemCount = size_t(1) << 10;
|
||||
|
||||
TEST(ZoneChunkList, ForwardIterationTest) {
|
||||
class ZoneChunkListTest : public TestWithPlatform {};
|
||||
|
||||
TEST_F(ZoneChunkListTest, ForwardIterationTest) {
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
|
||||
@ -33,7 +36,7 @@ TEST(ZoneChunkList, ForwardIterationTest) {
|
||||
EXPECT_EQ(count, kItemCount);
|
||||
}
|
||||
|
||||
TEST(ZoneChunkList, ReverseIterationTest) {
|
||||
TEST_F(ZoneChunkListTest, ReverseIterationTest) {
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
|
||||
@ -53,7 +56,7 @@ TEST(ZoneChunkList, ReverseIterationTest) {
|
||||
EXPECT_EQ(count, kItemCount);
|
||||
}
|
||||
|
||||
TEST(ZoneChunkList, PushFrontTest) {
|
||||
TEST_F(ZoneChunkListTest, PushFrontTest) {
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
|
||||
@ -73,7 +76,7 @@ TEST(ZoneChunkList, PushFrontTest) {
|
||||
EXPECT_EQ(count, kItemCount);
|
||||
}
|
||||
|
||||
TEST(ZoneChunkList, RewindTest) {
|
||||
TEST_F(ZoneChunkListTest, RewindTest) {
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
|
||||
@ -120,7 +123,7 @@ TEST(ZoneChunkList, RewindTest) {
|
||||
EXPECT_EQ(count, zone_chunk_list.size());
|
||||
}
|
||||
|
||||
TEST(ZoneChunkList, FindTest) {
|
||||
TEST_F(ZoneChunkListTest, FindTest) {
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
|
||||
@ -139,7 +142,7 @@ TEST(ZoneChunkList, FindTest) {
|
||||
EXPECT_EQ(*zone_chunk_list.Find(index), 42u);
|
||||
}
|
||||
|
||||
TEST(ZoneChunkList, CopyToTest) {
|
||||
TEST_F(ZoneChunkListTest, CopyToTest) {
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
|
||||
@ -158,7 +161,7 @@ TEST(ZoneChunkList, CopyToTest) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ZoneChunkList, SmallCopyToTest) {
|
||||
TEST_F(ZoneChunkListTest, SmallCopyToTest) {
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
|
||||
@ -182,7 +185,7 @@ struct Fubar {
|
||||
size_t b_;
|
||||
};
|
||||
|
||||
TEST(ZoneChunkList, BigCopyToTest) {
|
||||
TEST_F(ZoneChunkListTest, BigCopyToTest) {
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
|
||||
@ -214,7 +217,7 @@ void TestForwardIterationOfConstList(
|
||||
EXPECT_EQ(count, kItemCount);
|
||||
}
|
||||
|
||||
TEST(ZoneChunkList, ConstForwardIterationTest) {
|
||||
TEST_F(ZoneChunkListTest, ConstForwardIterationTest) {
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
|
||||
@ -227,7 +230,7 @@ TEST(ZoneChunkList, ConstForwardIterationTest) {
|
||||
TestForwardIterationOfConstList(zone_chunk_list);
|
||||
}
|
||||
|
||||
TEST(ZoneChunkList, RewindAndIterate) {
|
||||
TEST_F(ZoneChunkListTest, RewindAndIterate) {
|
||||
// Regression test for https://bugs.chromium.org/p/v8/issues/detail?id=7478
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
@ -267,7 +270,7 @@ TEST(ZoneChunkList, RewindAndIterate) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ZoneChunkList, PushBackPopBackSize) {
|
||||
TEST_F(ZoneChunkListTest, PushBackPopBackSize) {
|
||||
// Regression test for https://bugs.chromium.org/p/v8/issues/detail?id=7489
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
@ -280,7 +283,7 @@ TEST(ZoneChunkList, PushBackPopBackSize) {
|
||||
CHECK_EQ(size_t(0), zone_chunk_list.size());
|
||||
}
|
||||
|
||||
TEST(ZoneChunkList, AdvanceZeroTest) {
|
||||
TEST_F(ZoneChunkListTest, AdvanceZeroTest) {
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
|
||||
@ -297,7 +300,7 @@ TEST(ZoneChunkList, AdvanceZeroTest) {
|
||||
CHECK_EQ(iterator_advance, zone_chunk_list.begin());
|
||||
}
|
||||
|
||||
TEST(ZoneChunkList, AdvancePartwayTest) {
|
||||
TEST_F(ZoneChunkListTest, AdvancePartwayTest) {
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
|
||||
@ -318,7 +321,7 @@ TEST(ZoneChunkList, AdvancePartwayTest) {
|
||||
CHECK_EQ(iterator_advance, iterator_one_by_one);
|
||||
}
|
||||
|
||||
TEST(ZoneChunkList, AdvanceEndTest) {
|
||||
TEST_F(ZoneChunkListTest, AdvanceEndTest) {
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
|
||||
@ -335,7 +338,7 @@ TEST(ZoneChunkList, AdvanceEndTest) {
|
||||
CHECK_EQ(iterator_advance, zone_chunk_list.end());
|
||||
}
|
||||
|
||||
TEST(ZoneChunkList, FindOverChunkBoundary) {
|
||||
TEST_F(ZoneChunkListTest, FindOverChunkBoundary) {
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
|
||||
|
@ -5,20 +5,23 @@
|
||||
#include "src/zone/zone.h"
|
||||
|
||||
#include "src/zone/accounting-allocator.h"
|
||||
#include "test/unittests/test-utils.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
// This struct is just a type tag for Zone::Allocate<T>(size_t) call.
|
||||
struct ZoneTest {};
|
||||
class ZoneTest : public TestWithPlatform {};
|
||||
|
||||
TEST(Zone, 8ByteAlignment) {
|
||||
// This struct is just a type tag for Zone::Allocate<T>(size_t) call.
|
||||
struct ZoneTestTag {};
|
||||
|
||||
TEST_F(ZoneTest, 8ByteAlignment) {
|
||||
AccountingAllocator allocator;
|
||||
Zone zone(&allocator, ZONE_NAME);
|
||||
|
||||
for (size_t i = 0; i < 16; ++i) {
|
||||
ASSERT_EQ(reinterpret_cast<intptr_t>(zone.Allocate<ZoneTest>(i)) % 8, 0);
|
||||
ASSERT_EQ(reinterpret_cast<intptr_t>(zone.Allocate<ZoneTestTag>(i)) % 8, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user