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
25 using namespace panda;
26 using namespace panda::ecmascript;
27
28 namespace panda::test {
29
30 class JitFortTest : public BaseTestWithScope<false> {
31 public:
SetUp()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
HWTEST_F_L0(JitFortTest,AddRegionTest001)46 HWTEST_F_L0(JitFortTest, AddRegionTest001)
47 {
48 JitFort *jitFort = new JitFort();
49 bool res = jitFort->AddRegion();
50 ASSERT_EQ(res, true);
51 }
52
HWTEST_F_L0(JitFortTest,AddRegionTest002)53 HWTEST_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
HWTEST_F_L0(JitFortTest,AllocateTest001)62 HWTEST_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
HWTEST_F_L0(JitFortTest,GetDescTest001)71 HWTEST_F_L0(JitFortTest, GetDescTest001)
72 {
73 MemDescPool *pool = new MemDescPool(1, 1);
74 ASSERT_NE(pool, nullptr);
75 pool->GetDescFromPool();
76 }
77
HWTEST_F_L0(JitFortTest,MemDescPoolFreeTest001)78 HWTEST_F_L0(JitFortTest, MemDescPoolFreeTest001)
79 {
80 MemDescPool *pool = new MemDescPool(1, 1);
81 ASSERT_NE(pool, nullptr);
82 pool->~MemDescPool();
83 }
84
HWTEST_F_L0(JitFortTest,InitRegionTest001)85 HWTEST_F_L0(JitFortTest, InitRegionTest001)
86 {
87 JitFort *jitFort = new JitFort();
88 ASSERT_NE(jitFort, nullptr);
89 jitFort->InitRegions();
90 }
91
HWTEST_F_L0(JitFortTest,InRangeTest001)92 HWTEST_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