• 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_vm.h"
20 #include "types/ets_class.h"
21 #include "types/ets_job.h"
22 #include "tests/runtime/types/ets_test_mirror_classes.h"
23 
24 namespace ark::ets::test {
25 
26 class EtsJobTest : public testing::Test {
27 public:
EtsJobTest()28     EtsJobTest()
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 
~EtsJobTest()49     ~EtsJobTest() override
50     {
51         Runtime::Destroy();
52     }
53 
54     NO_COPY_SEMANTIC(EtsJobTest);
55     NO_MOVE_SEMANTIC(EtsJobTest);
56 
GetJobMembers()57     static std::vector<MirrorFieldInfo> GetJobMembers()
58     {
59         return std::vector<MirrorFieldInfo> {
60             MIRROR_FIELD_INFO(EtsJob, value_, "val"),
61             MIRROR_FIELD_INFO(EtsJob, mutex_, "mutex"),
62             MIRROR_FIELD_INFO(EtsJob, event_, "event"),
63             MIRROR_FIELD_INFO(EtsJob, state_, "status"),
64         };
65     }
66 
67 protected:
68     PandaEtsVM *vm_ = nullptr;  // NOLINT(misc-non-private-member-variables-in-classes)
69 };
70 
71 // Check both EtsJob and ark::Class<Job> has the same number of fields
72 // and at the same offsets
TEST_F(EtsJobTest,JobMemoryLayout)73 TEST_F(EtsJobTest, JobMemoryLayout)
74 {
75     EtsClass *jobClass = PlatformTypes(vm_)->coreJob;
76     MirrorFieldInfo::CompareMemberOffsets(jobClass, GetJobMembers());
77 }
78 
79 }  // namespace ark::ets::test
80