1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "common_components/heap/allocator/region_desc.h" 17 #include "common_components/heap/allocator/region_space.h" 18 #include "common_components/serialize/serialize_utils.h" 19 #include "common_components/serialize/serialize_utils.cpp" 20 #include "common_components/tests/test_helper.h" 21 22 using namespace common; 23 24 namespace common::test { 25 class SerializeUtilsTest : public common::test::BaseTestWithScope { 26 protected: SetUpTestCase()27 static void SetUpTestCase() 28 { 29 BaseRuntime::GetInstance()->Init(); 30 } 31 TearDownTestCase()32 static void TearDownTestCase() 33 { 34 BaseRuntime::GetInstance()->Fini(); 35 } SetUp()36 void SetUp() override 37 { 38 MutatorManager::Instance().CreateRuntimeMutator(ThreadType::GC_THREAD); 39 } 40 TearDown()41 void TearDown() override 42 { 43 MutatorManager::Instance().DestroyRuntimeMutator(ThreadType::GC_THREAD); 44 } 45 }; 46 HWTEST_F_L0(SerializeUtilsTest,GetSerializeObjectSpace)47HWTEST_F_L0(SerializeUtilsTest, GetSerializeObjectSpace) 48 { 49 RegionSpace& theAllocator = reinterpret_cast<RegionSpace&>(Heap::GetHeap().GetAllocator()); 50 uintptr_t addr = theAllocator.AllocOldRegion(); 51 ASSERT_NE(addr, 0); 52 RegionDesc* region = RegionDesc::GetRegionDescAt(addr); 53 region->SetRegionType(RegionDesc::RegionType::END_OF_REGION_TYPE); 54 SerializedBaseObjectSpace spaceType = SerializeUtils::GetSerializeObjectSpace(addr); 55 EXPECT_EQ(spaceType, SerializedBaseObjectSpace::OTHER); 56 } 57 } // namespace common::test