• 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 "plugins/ets/runtime/ets_coroutine.h"
19 #include "plugins/ets/runtime/ets_panda_file_items.h"
20 #include "plugins/ets/runtime/ets_vm.h"
21 #include "plugins/ets/runtime/types/ets_base_enum.h"
22 #include "tests/runtime/types/ets_test_mirror_classes.h"
23 
24 namespace ark::ets::test {
25 
26 class EtsBaseEnumMembers : public testing::Test {
27 public:
EtsBaseEnumMembers()28     EtsBaseEnumMembers()
29     {
30         RuntimeOptions options;
31         options.SetShouldLoadBootPandaFiles(true);
32         options.SetShouldInitializeIntrinsics(false);
33         options.SetCompilerEnableJit(false);
34         options.SetGcType("epsilon");
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         EtsCoroutine *coroutine = EtsCoroutine::GetCurrent();
46         vm_ = coroutine->GetPandaVM();
47     }
48 
~EtsBaseEnumMembers()49     ~EtsBaseEnumMembers() override
50     {
51         Runtime::Destroy();
52     }
53 
54     NO_COPY_SEMANTIC(EtsBaseEnumMembers);
55     NO_MOVE_SEMANTIC(EtsBaseEnumMembers);
56 
GetMembers()57     static std::vector<MirrorFieldInfo> GetMembers()
58     {
59         return std::vector<MirrorFieldInfo> {MIRROR_FIELD_INFO(EtsBaseEnum, value_, "value")};
60     }
61 
GetClass(const char * name)62     EtsClass *GetClass(const char *name)
63     {
64         os::memory::WriteLockHolder lock(*vm_->GetMutatorLock());
65         return vm_->GetClassLinker()->GetClass(name);
66     }
67 
68 private:
69     PandaEtsVM *vm_ = nullptr;
70 };
71 
TEST_F(EtsBaseEnumMembers,MemoryLayout)72 TEST_F(EtsBaseEnumMembers, MemoryLayout)
73 {
74     auto *klass = GetClass(panda_file_items::class_descriptors::BASE_ENUM.data());
75     MirrorFieldInfo::CompareMemberOffsets(klass, GetMembers());
76 }
77 }  // namespace ark::ets::test
78