diff --git a/BUILD.gn b/BUILD.gn
index 090dae612c2c5b7df700e9ec85c25c56d4ec6a67..c9361fed1bde4296b66fa6e791624f0c066b02a3 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -164,6 +164,7 @@ group("common_components_js_unittest") {
"common_components/mutator/tests:unittest",
"common_components/heap/collector/tests:unittest",
"common_components/objects/tests:unittest",
+ "common_components/thread/tests:unittest",
"common_components/heap/barrier/tests:unittest",
]
}
@@ -182,6 +183,7 @@ group("common_components_unittest") {
"common_components/mutator/tests:host_unittest",
"common_components/heap/collector/tests:host_unittest",
"common_components/objects/tests:host_unittest",
+ "common_components/thread/tests:host_unittest",
"common_components/heap/barrier/tests:host_unittest",
]
}
@@ -239,6 +241,7 @@ group("ark_unittest") {
"common_components/heap/allocator/tests:host_unittest",
"common_components/mutator/tests:host_unittest",
"common_components/heap/barrier/tests:unittest",
+ "common_components/thread/tests:host_unittest",
"common_components/heap/collector/tests:host_unittest",
]
}
diff --git a/common_components/heap/collector/tests/collector_resources_test.cpp b/common_components/heap/collector/tests/collector_resources_test.cpp
index c05a505ae9ecf5fac640edba6548a8b9c29ba3fc..19de3d5072074c00773bb6fe249f9a3a88030d3b 100755
--- a/common_components/heap/collector/tests/collector_resources_test.cpp
+++ b/common_components/heap/collector/tests/collector_resources_test.cpp
@@ -49,4 +49,15 @@ HWTEST_F_L0(CollectorResourcesTest, RequestHeapDumpTest) {
GCTask::GCTaskType::GC_TASK_INVALID);
EXPECT_TRUE(Heap::GetHeap().IsGCEnabled());
}
+
+HWTEST_F_L0(CollectorResourcesTest, StartRuntimeThreadsTest) {
+ Heap::GetHeap().GetCollectorResources().Fini();
+ Heap::GetHeap().GetCollectorResources().StartRuntimeThreads();
+ EXPECT_TRUE(Heap::GetHeap().GetCollectorResources().GetFinalizerProcessor().IsRunning());
+}
+
+HWTEST_F_L0(CollectorResourcesTest, StopRuntimeThreadsTest) {
+ Heap::GetHeap().GetCollectorResources().StopRuntimeThreads();
+ EXPECT_FALSE(Heap::GetHeap().GetCollectorResources().GetFinalizerProcessor().IsRunning());
+}
} // namespace common::test
\ No newline at end of file
diff --git a/common_components/tests/ohos_test.xml b/common_components/tests/ohos_test.xml
index 864e893b2a23f2daf2129c99fce1d82913b6e73b..f729b42b33268aa13c39d0e1539a0d468a5322dc 100644
--- a/common_components/tests/ohos_test.xml
+++ b/common_components/tests/ohos_test.xml
@@ -48,6 +48,11 @@
+
+
+
+
+
diff --git a/common_components/thread/tests/BUILD.gn b/common_components/thread/tests/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..1a57336aaaefb23c3e975ea0b7aafb894714655c
--- /dev/null
+++ b/common_components/thread/tests/BUILD.gn
@@ -0,0 +1,57 @@
+# Copyright (c) 2025 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//arkcompiler/ets_runtime/common_components/tests/test_helper.gni")
+
+module_output_path = "ets_runtime"
+
+host_unittest_action("Thread_Holder_Test") {
+ module_out_path = module_output_path
+
+ sources = [
+ # test file
+ "thread_holder_test.cpp",
+ ]
+
+ configs = [
+ "//arkcompiler/ets_runtime/common_components:common_components_test_config",
+ "//arkcompiler/ets_runtime:icu_path_test_config",
+ ]
+
+ deps = [ "//arkcompiler/ets_runtime/common_components:libark_common_components_test" ]
+
+ # hiviewdfx libraries
+ external_deps = [
+ "icu:shared_icui18n",
+ "icu:shared_icuuc",
+ "zlib:libz",
+ ]
+}
+
+group("unittest") {
+ testonly = true
+
+ # deps file
+ deps = [
+ ":Thread_Holder_Test",
+ ]
+}
+
+group("host_unittest") {
+ testonly = true
+
+ # deps file
+ deps = [
+ ":Thread_Holder_TestAction",
+ ]
+}
\ No newline at end of file
diff --git a/common_components/thread/tests/thread_holder_test.cpp b/common_components/thread/tests/thread_holder_test.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b25e88e3714c424c76a4e37aa8fde37d404d83f3
--- /dev/null
+++ b/common_components/thread/tests/thread_holder_test.cpp
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "common_components/tests/test_helper.h"
+#include "common_components/mutator/mutator.h"
+#include "common_components/mutator/mutator_manager.h"
+#include "common_interfaces/base_runtime.h"
+#include "common_interfaces/thread/thread_holder-inl.h"
+#include "common_interfaces/thread/thread_holder.h"
+#include "common_interfaces/thread/thread_holder_manager.h"
+
+using namespace common;
+
+namespace ark {
+class Coroutine;
+}
+
+namespace common::test {
+using Coroutine = ark::Coroutine;
+namespace {
+ void SetCurrentThreadHolder(ThreadHolder* holder)
+ {
+ ThreadHolder::SetCurrent(holder);
+ }
+}
+
+class ThreadHolderTest : public BaseTestWithScope {
+protected:
+ static void SetUpTestCase()
+ {
+ BaseRuntime::GetInstance()->Init();
+ }
+
+ static void TearDownTestCase()
+ {
+ BaseRuntime::GetInstance()->Fini();
+ }
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+};
+
+size_t callCount;
+void CallBackVisitor(void *root)
+{
+ callCount++;
+}
+
+HWTEST_F_L0(ThreadHolderTest, VisitAllThreadsTest) {
+ ThreadHolder *curHolder = ThreadHolder::CreateAndRegisterNewThreadHolder(nullptr);
+ ASSERT_TRUE(curHolder != nullptr);
+ SetCurrentThreadHolder(curHolder);
+
+ curHolder->WaitSuspension();
+
+ CommonRootVisitor visitor = nullptr;
+ curHolder->VisitAllThreads(visitor);
+
+ ThreadHolder* result = ThreadHolder::GetCurrent();
+ EXPECT_EQ(result, curHolder);
+}
+
+HWTEST_F_L0(ThreadHolderTest, UnregisterThreadHolderTest) {
+ ThreadHolder *curHolder = ThreadHolder::CreateAndRegisterNewThreadHolder(nullptr);
+ Mutator *mutator = static_cast(curHolder->GetMutator());
+
+ auto& mutator_manager = MutatorManager::Instance();
+ auto& list = mutator_manager.allMutatorList_;
+ list.clear();
+
+ ThreadHolderManager thManager;
+ thManager.UnregisterThreadHolder(curHolder);
+ EXPECT_EQ(mutator->PopRawObject(), nullptr);
+}
+
+HWTEST_F_L0(ThreadHolderTest, TryBindMutatorTest) {
+ ThreadHolder *curHolder = ThreadHolder::CreateAndRegisterNewThreadHolder(nullptr);
+ ASSERT_TRUE(curHolder != nullptr);
+ SetCurrentThreadHolder(curHolder);
+
+ ThreadLocal::SetProcessorFlag(true);
+ ThreadHolder::TryBindMutatorScope scope(curHolder);
+ EXPECT_EQ(ThreadLocal::GetAllocBuffer(), nullptr);
+}
+} // namespace panda::test
\ No newline at end of file