1/* 2 * Copyright (c) 2024 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 "ecmascript/ecma_vm.h" 17#include "ecmascript/js_tagged_value.h" 18#include "ecmascript/tests/test_helper.h" 19 20#include "ecmascript/mem/concurrent_marker.h" 21#include "ecmascript/mem/partial_gc.h" 22#include "ecmascript/mem/jit_fort_memdesc.h" 23#include "ecmascript/mem/jit_fort.h" 24 25using namespace panda; 26using namespace panda::ecmascript; 27 28namespace panda::test { 29 30class JitFortTest : public BaseTestWithScope<false> { 31public: 32 void SetUp() override 33 { 34 JSRuntimeOptions options; 35 instance = JSNApi::CreateEcmaVM(options); 36 ASSERT_TRUE(instance != nullptr) << "Cannot create EcmaVM"; 37 thread = instance->GetJSThread(); 38 thread->ManagedCodeBegin(); 39 scope = new EcmaHandleScope(thread); 40 auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 41 heap->GetConcurrentMarker()->EnableConcurrentMarking(EnableConcurrentMarkType::ENABLE); 42 heap->GetSweeper()->EnableConcurrentSweep(EnableConcurrentSweepType::ENABLE); 43 } 44}; 45 46HWTEST_F_L0(JitFortTest, AddRegionTest001) 47{ 48 JitFort *jitFort = new JitFort(); 49 bool res = jitFort->AddRegion(); 50 ASSERT_EQ(res, true); 51} 52 53HWTEST_F_L0(JitFortTest, AddRegionTest002) 54{ 55 JitFort *jitFort = new JitFort(); 56 for (size_t i = 0; i < 16; i++) { 57 jitFort->AddRegion(); 58 } 59 ASSERT_EQ(jitFort->AddRegion(), false); 60} 61 62HWTEST_F_L0(JitFortTest, AllocateTest001) 63{ 64 MachineCodeDesc desc; 65 desc.instructionsSize = 18; 66 JitFort *jitFort = new JitFort(); 67 ASSERT_NE(jitFort, nullptr); 68 jitFort->Allocate(&desc); 69} 70 71HWTEST_F_L0(JitFortTest, GetDescTest001) 72{ 73 MemDescPool *pool = new MemDescPool(1, 1); 74 ASSERT_NE(pool, nullptr); 75 pool->GetDescFromPool(); 76} 77 78HWTEST_F_L0(JitFortTest, MemDescPoolFreeTest001) 79{ 80 MemDescPool *pool = new MemDescPool(1, 1); 81 ASSERT_NE(pool, nullptr); 82 pool->~MemDescPool(); 83} 84 85HWTEST_F_L0(JitFortTest, InitRegionTest001) 86{ 87 JitFort *jitFort = new JitFort(); 88 ASSERT_NE(jitFort, nullptr); 89 jitFort->InitRegions(); 90} 91 92HWTEST_F_L0(JitFortTest, InRangeTest001) 93{ 94 JitFort *jitFort = new JitFort(); 95 bool result = jitFort->InRange(1); 96 ASSERT_EQ(result, false); 97} 98 99} 100