• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 
18 #include "ets_coroutine.h"
19 #include "ets_vm.h"
20 
21 #include "types/ets_abc_file.h"
22 #include "types/ets_abc_runtime_linker.h"
23 #include "tests/runtime/types/ets_test_mirror_classes.h"
24 
25 namespace ark::ets::test {
26 
27 class EtsAbcRuntimeLinkerTest : public testing::Test {
28 public:
EtsAbcRuntimeLinkerTest()29     EtsAbcRuntimeLinkerTest()
30     {
31         options_.SetShouldLoadBootPandaFiles(true);
32         options_.SetShouldInitializeIntrinsics(false);
33         options_.SetCompilerEnableJit(false);
34         options_.SetGcType("g1-gc");
35         options_.SetLoadRuntimes({"ets"});
36 
37         auto stdlib = std::getenv("PANDA_STD_LIB");
38         if (stdlib == nullptr) {
39             std::cerr << "PANDA_STD_LIB env variable should be set and point to mock_stdlib.abc" << std::endl;
40             std::abort();
41         }
42         options_.SetBootPandaFiles({stdlib});
43 
44         Runtime::Create(options_);
45     }
46 
~EtsAbcRuntimeLinkerTest()47     ~EtsAbcRuntimeLinkerTest() override
48     {
49         Runtime::Destroy();
50     }
51 
52     NO_COPY_SEMANTIC(EtsAbcRuntimeLinkerTest);
53     NO_MOVE_SEMANTIC(EtsAbcRuntimeLinkerTest);
54 
SetUp()55     void SetUp() override
56     {
57         coroutine_ = EtsCoroutine::GetCurrent();
58         vm_ = coroutine_->GetPandaVM();
59         coroutine_->ManagedCodeBegin();
60     }
61 
TearDown()62     void TearDown() override
63     {
64         coroutine_->ManagedCodeEnd();
65     }
66 
GetEtsAbcClassMembers()67     static std::vector<MirrorFieldInfo> GetEtsAbcClassMembers()
68     {
69         return std::vector<MirrorFieldInfo> {MIRROR_FIELD_INFO(EtsAbcFile, fileHandlePtr_, "fileHandlePtr")};
70     }
71 
GetEtsAbcRuntimeLinkerClassMembers()72     static std::vector<MirrorFieldInfo> GetEtsAbcRuntimeLinkerClassMembers()
73     {
74         return std::vector<MirrorFieldInfo> {MIRROR_FIELD_INFO(EtsAbcRuntimeLinker, parentLinker_, "parentLinker"),
75                                              MIRROR_FIELD_INFO(EtsAbcRuntimeLinker, abcFiles_, "abcFiles")};
76     }
77 
78 protected:
79     PandaEtsVM *vm_ = nullptr;  // NOLINT(misc-non-private-member-variables-in-classes)
80 
81 private:
82     RuntimeOptions options_;
83     EtsCoroutine *coroutine_ = nullptr;
84 };
85 
TEST_F(EtsAbcRuntimeLinkerTest,AbcFileMemoryLayout)86 TEST_F(EtsAbcRuntimeLinkerTest, AbcFileMemoryLayout)
87 {
88     EtsClass *abcFileClass = PlatformTypes(vm_)->coreAbcFile;
89     MirrorFieldInfo::CompareMemberOffsets(abcFileClass, GetEtsAbcClassMembers());
90 }
91 
TEST_F(EtsAbcRuntimeLinkerTest,AbcRuntimeLinkerMemoryLayout)92 TEST_F(EtsAbcRuntimeLinkerTest, AbcRuntimeLinkerMemoryLayout)
93 {
94     EtsClass *abcRuntimeLinkerClass = PlatformTypes(vm_)->coreAbcRuntimeLinker;
95     MirrorFieldInfo::CompareMemberOffsets(abcRuntimeLinkerClass, GetEtsAbcRuntimeLinkerClassMembers());
96 }
97 
98 }  // namespace ark::ets::test
99