diff --git a/BUILD.bazel b/BUILD.bazel index c873b20952..17c1adecf9 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -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", diff --git a/BUILD.gn b/BUILD.gn index 84284af993..c5f46f1b0c 100644 --- a/BUILD.gn +++ b/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", diff --git a/include/cppgc/default-platform.h b/include/cppgc/default-platform.h index f9af756c39..a27871cc37 100644 --- a/include/cppgc/default-platform.h +++ b/include/cppgc/default-platform.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, diff --git a/samples/cppgc/hello-world.cc b/samples/cppgc/hello-world.cc index fe0d002ab4..65b7aa9db2 100644 --- a/samples/cppgc/hello-world.cc +++ b/samples/cppgc/hello-world.cc @@ -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 heap = cppgc::Heap::Create(cppgc_platform); diff --git a/src/heap/cppgc/default-platform.cc b/src/heap/cppgc/default-platform.cc deleted file mode 100644 index 1899557134..0000000000 --- a/src/heap/cppgc/default-platform.cc +++ /dev/null @@ -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 diff --git a/test/unittests/api/deserialize-unittest.cc b/test/unittests/api/deserialize-unittest.cc index 5e6edcff6b..6e3731ecad 100644 --- a/test/unittests/api/deserialize-unittest.cc +++ b/test/unittests/api/deserialize-unittest.cc @@ -15,7 +15,7 @@ namespace v8 { -class DeserializeTest : public testing::Test { +class DeserializeTest : public TestWithPlatform { public: class IsolateAndContextScope { public: diff --git a/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc b/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc index 02bf80876a..5d57cf5614 100644 --- a/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc +++ b/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc @@ -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(); } diff --git a/test/unittests/compiler/bytecode-analysis-unittest.cc b/test/unittests/compiler/bytecode-analysis-unittest.cc index 021c88374b..4cd7b4427f 100644 --- a/test/unittests/compiler/bytecode-analysis-unittest.cc +++ b/test/unittests/compiler/bytecode-analysis-unittest.cc @@ -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; } diff --git a/test/unittests/compiler/graph-reducer-unittest.cc b/test/unittests/compiler/graph-reducer-unittest.cc index 98de4c7f7c..ba777a8cac 100644 --- a/test/unittests/compiler/graph-reducer-unittest.cc +++ b/test/unittests/compiler/graph-reducer-unittest.cc @@ -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::Set(Reducer::NoChange()); } - static void TearDownTestCase() { + static void TearDownTestSuite() { DefaultValue::Clear(); - TestWithZone::TearDownTestCase(); + TestWithZone::TearDownTestSuite(); } protected: diff --git a/test/unittests/compiler/persistent-unittest.cc b/test/unittests/compiler/persistent-unittest.cc index 4c5a1974c7..89c65c2579 100644 --- a/test/unittests/compiler/persistent-unittest.cc +++ b/test/unittests/compiler/persistent-unittest.cc @@ -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); diff --git a/test/unittests/compiler/zone-stats-unittest.cc b/test/unittests/compiler/zone-stats-unittest.cc index c75ba1eff7..7187d35000 100644 --- a/test/unittests/compiler/zone-stats-unittest.cc +++ b/test/unittests/compiler/zone-stats-unittest.cc @@ -10,7 +10,7 @@ namespace v8 { namespace internal { namespace compiler { -class ZoneStatsTest : public ::testing::Test { +class ZoneStatsTest : public TestWithPlatform { public: ZoneStatsTest() : zone_stats_(&allocator_) {} diff --git a/test/unittests/execution/microtask-queue-unittest.cc b/test/unittests/execution/microtask-queue-unittest.cc index 736de80762..55e36c9f44 100644 --- a/test/unittests/execution/microtask-queue-unittest.cc +++ b/test/unittests/execution/microtask-queue-unittest.cc @@ -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 { diff --git a/test/unittests/heap/cppgc/run-all-unittests.cc b/test/unittests/heap/cppgc/run-all-unittests.cc index dc30e750cd..a920c14f2f 100644 --- a/test/unittests/heap/cppgc/run-all-unittests.cc +++ b/test/unittests/heap/cppgc/run-all-unittests.cc @@ -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(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 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(); } diff --git a/test/unittests/heap/cppgc/tests.cc b/test/unittests/heap/cppgc/tests.cc index b2bed85f1d..65c4012a8d 100644 --- a/test/unittests/heap/cppgc/tests.cc +++ b/test/unittests/heap/cppgc/tests.cc @@ -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 TestWithPlatform::platform_; // static void TestWithPlatform::SetUpTestSuite() { - platform_ = std::make_unique( + platform_ = std::make_shared( std::make_unique()); + +#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(); } diff --git a/test/unittests/heap/heap-utils.h b/test/unittests/heap/heap-utils.h index 2cd123c827..fdff16c2dc 100644 --- a/test/unittests/heap/heap-utils.h +++ b/test/unittests/heap/heap-utils.h @@ -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 diff --git a/test/unittests/heap/unmapper-unittest.cc b/test/unittests/heap/unmapper-unittest.cc index fadc6ed7e2..9f6dc506de 100644 --- a/test/unittests/heap/unmapper-unittest.cc +++ b/test/unittests/heap/unmapper-unittest.cc @@ -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 +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 +SequentialUnmapperTestMixin::SequentialUnmapperTestMixin() { + SequentialUnmapperTest::DoMixinSetUp(); +} +template +SequentialUnmapperTestMixin::~SequentialUnmapperTestMixin() { + SequentialUnmapperTest::DoMixinTearDown(); +} + // See v8:5945. TEST_F(SequentialUnmapperTest, UnmapOnTeardownAfterAlreadyFreeingPooled) { if (FLAG_enable_third_party_heap) return; diff --git a/test/unittests/logging/runtime-call-stats-unittest.cc b/test/unittests/logging/runtime-call-stats-unittest.cc index 755bbf47e1..f69127bf9e 100644 --- a/test/unittests/logging/runtime-call-stats-unittest.cc +++ b/test/unittests/logging/runtime-call-stats-unittest.cc @@ -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; } diff --git a/test/unittests/objects/value-serializer-unittest.cc b/test/unittests/objects/value-serializer-unittest.cc index d3bec38c40..97c7c5448f 100644 --- a/test/unittests/objects/value-serializer-unittest.cc +++ b/test/unittests/objects/value-serializer-unittest.cc @@ -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; } diff --git a/test/unittests/run-all-unittests.cc b/test/unittests/run-all-unittests.cc index 8437ac0acb..fba903688d 100644 --- a/test/unittests/run-all-unittests.cc +++ b/test/unittests/run-all-unittests.cc @@ -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 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]); diff --git a/test/unittests/tasks/background-compile-task-unittest.cc b/test/unittests/tasks/background-compile-task-unittest.cc index 0bdf866ae0..5ad5279a72 100644 --- a/test/unittests/tasks/background-compile-task-unittest.cc +++ b/test/unittests/tasks/background-compile-task-unittest.cc @@ -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; diff --git a/test/unittests/test-utils.h b/test/unittests/test-utils.h index cac8980b68..18305a04a7 100644 --- a/test/unittests/test-utils.h +++ b/test/unittests/test-utils.h @@ -8,6 +8,7 @@ #include #include +#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 +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 platform_; +}; + using CounterMap = std::map; 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>; -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(); diff --git a/test/unittests/utils/allocation-unittest.cc b/test/unittests/utils/allocation-unittest.cc index b6f8d8699f..af0eb5a612 100644 --- a/test/unittests/utils/allocation-unittest.cc +++ b/test/unittests/utils/allocation-unittest.cc @@ -4,6 +4,8 @@ #include "src/utils/allocation.h" +#include "test/unittests/test-utils.h" + #if V8_OS_POSIX #include #include @@ -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; diff --git a/test/unittests/wasm/function-body-decoder-unittest.cc b/test/unittests/wasm/function-body-decoder-unittest.cc index a3f1292eb7..02f741f6e7 100644 --- a/test/unittests/wasm/function-body-decoder-unittest.cc +++ b/test/unittests/wasm/function-body-decoder-unittest.cc @@ -344,7 +344,7 @@ class FunctionBodyDecoderTestBase : public WithZoneMixin { } }; -using FunctionBodyDecoderTest = FunctionBodyDecoderTestBase<::testing::Test>; +using FunctionBodyDecoderTest = FunctionBodyDecoderTestBase; TEST_F(FunctionBodyDecoderTest, Int32Const1) { byte code[] = {kExprI32Const, 0}; @@ -5142,7 +5142,8 @@ TEST_F(BytecodeIteratorTest, WithLocalDecls) { ******************************************************************************/ class FunctionBodyDecoderTestOnBothMemoryTypes - : public FunctionBodyDecoderTestBase<::testing::TestWithParam> { + : public FunctionBodyDecoderTestBase< + WithDefaultPlatformMixin<::testing::TestWithParam>> { public: bool is_memory64() const { return GetParam() == kMemory64; } }; diff --git a/test/unittests/wasm/subtyping-unittest.cc b/test/unittests/wasm/subtyping-unittest.cc index 10713a6db4..9ad4731415 100644 --- a/test/unittests/wasm/subtyping-unittest.cc +++ b/test/unittests/wasm/subtyping-unittest.cc @@ -13,7 +13,7 @@ namespace internal { namespace wasm { namespace subtyping_unittest { -class WasmSubtypingTest : public ::testing::Test {}; +class WasmSubtypingTest : public TestWithPlatform {}; using FieldInit = std::pair; constexpr ValueType ref(uint32_t index) { diff --git a/test/unittests/wasm/trap-handler-win-unittest.cc b/test/unittests/wasm/trap-handler-win-unittest.cc index b90fafeee9..53522f3a90 100644 --- a/test/unittests/wasm/trap-handler-win-unittest.cc +++ b/test/unittests/wasm/trap-handler-win-unittest.cc @@ -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. diff --git a/test/unittests/zone/zone-allocator-unittest.cc b/test/unittests/zone/zone-allocator-unittest.cc index c0c18843ac..6f43d34983 100644 --- a/test/unittests/zone/zone-allocator-unittest.cc +++ b/test/unittests/zone/zone-allocator-unittest.cc @@ -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 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 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 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 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 zone_allocator(&zone); diff --git a/test/unittests/zone/zone-chunk-list-unittest.cc b/test/unittests/zone/zone-chunk-list-unittest.cc index d982c1e0ec..697d29c28f 100644 --- a/test/unittests/zone/zone-chunk-list-unittest.cc +++ b/test/unittests/zone/zone-chunk-list-unittest.cc @@ -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); diff --git a/test/unittests/zone/zone-unittest.cc b/test/unittests/zone/zone-unittest.cc index b063848990..b10c240c14 100644 --- a/test/unittests/zone/zone-unittest.cc +++ b/test/unittests/zone/zone-unittest.cc @@ -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(size_t) call. -struct ZoneTest {}; +class ZoneTest : public TestWithPlatform {}; -TEST(Zone, 8ByteAlignment) { +// This struct is just a type tag for Zone::Allocate(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(zone.Allocate(i)) % 8, 0); + ASSERT_EQ(reinterpret_cast(zone.Allocate(i)) % 8, 0); } }