From f7057edce166809de8aa0dcfa3d24dd8d3d178ff Mon Sep 17 00:00:00 2001 From: "Aleksei.Glushko" Date: Fri, 10 Nov 2023 18:01:49 +0100 Subject: [PATCH] [K/N] Extract common part of gc runtime tests (2/2) Restore ParallelMarkConcurrentSweepTest.cpp with new content. --- .../cpp/ParallelMarkConcurrentSweepTest.cpp | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 kotlin-native/runtime/src/gc/pmcs/cpp/ParallelMarkConcurrentSweepTest.cpp diff --git a/kotlin-native/runtime/src/gc/pmcs/cpp/ParallelMarkConcurrentSweepTest.cpp b/kotlin-native/runtime/src/gc/pmcs/cpp/ParallelMarkConcurrentSweepTest.cpp new file mode 100644 index 00000000000..7d98016cc24 --- /dev/null +++ b/kotlin-native/runtime/src/gc/pmcs/cpp/ParallelMarkConcurrentSweepTest.cpp @@ -0,0 +1,84 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +#include "ParallelMarkConcurrentSweep.hpp" + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include "GCImpl.hpp" +#include "GlobalData.hpp" +#include "SafePoint.hpp" +#include "StableRef.hpp" +#include "TestSupport.hpp" +#include "TracingGCTest.hpp" + +using namespace kotlin; + +namespace { + +template +class ParallelMarkConcurrentSweepTest { +public: + ParallelMarkConcurrentSweepTest() { + if (supportedConfiguration()) { + mm::GlobalData::Instance().gc().impl().gc().reconfigure(kMaxParallelism, kCooperativeMutators, kAuxGCThreads); + } + } + + ~ParallelMarkConcurrentSweepTest() { + mm::GlobalsRegistry::Instance().ClearForTests(); + mm::SpecialRefRegistry::instance().clearForTests(); + mm::GlobalData::Instance().gc().ClearForTests(); + mm::GlobalData::Instance().allocator().clearForTests(); + } + + void SetUp() { + if (!supportedConfiguration()) { + GTEST_SKIP() << "Unsupported parallelism configuration"; + } + } + + static std::string getName() { + using namespace std::string_literals; + auto base = ""s; + auto parallelism = std::to_string(kMaxParallelism) + "Parallel"; + auto withMutators = kCooperativeMutators ? "WithMutators" : ""; + auto withAux = kAuxGCThreads > 0 ? "WithGCThreads" : ""; + return base + parallelism + withMutators + withAux; + } + +private: + bool supportedConfiguration() const { + return !compiler::gcMarkSingleThreaded() || (!kCooperativeMutators && kAuxGCThreads == 0); + } +}; + +} // namespace + +using ParallelismConfigs = ::testing::Types< + ParallelMarkConcurrentSweepTest, + ParallelMarkConcurrentSweepTest +#if !__has_feature(thread_sanitizer) // TODO: Fix auxilary threads with tsan. + , ParallelMarkConcurrentSweepTest, + ParallelMarkConcurrentSweepTest, + ParallelMarkConcurrentSweepTest, + ParallelMarkConcurrentSweepTest +#endif +>; +struct NameGenerator { + template + static std::string GetName(int) { + return T::getName(); + } +}; + +REGISTER_TYPED_TEST_SUITE_WITH_LISTS(TracingGCTest, TRACING_GC_TEST_LIST); +INSTANTIATE_TYPED_TEST_SUITE_P(PMCS, TracingGCTest, ParallelismConfigs, NameGenerator); + +REGISTER_TYPED_TEST_SUITE_WITH_LISTS(STWMarkGCTest, STW_MARK_GC_TEST_LIST); +INSTANTIATE_TYPED_TEST_SUITE_P(PMCS, STWMarkGCTest, ParallelismConfigs, NameGenerator);