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 <gtest/gtest.h>
17 
18 #include "frame_sched.h"
19 #include "sync_fence.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 class FrameSchedTest : public testing::Test {
26 public:
27     static void SetUpTestCase();
28     static void TearDownTestCase();
29 };
30 
SetUpTestCase()31 void FrameSchedTest::SetUpTestCase()
32 {
33 }
34 
TearDownTestCase()35 void FrameSchedTest::TearDownTestCase()
36 {
37 }
38 
39 /*
40 * Function: SetFrameParam
41 * Type: Function
42 * Rank: Important(2)
43 * EnvConditions: N/A
44 * CaseDescription: 1. call SetFrameParam
45 *                  2. check ret
46 */
47 HWTEST_F(FrameSchedTest, SetFrameParam001, Function | MediumTest | Level2)
48 {
49     Rosen::FrameSched frameSched_;
50     frameSched_.SetFrameParam(0, 0, 0, 0);
51 }
52 
53 /*
54 * Function: MonitorGpuStart
55 * Type: Function
56 * Rank: Important(2)
57 * EnvConditions: N/A
58 * CaseDescription: 1. call MonitorGpuStart
59 *                  2. check ret
60 */
61 HWTEST_F(FrameSchedTest, MonitorGpuStart001, Function | MediumTest | Level2)
62 {
63     Rosen::FrameSched frameSched_;
64     frameSched_.MonitorGpuStart();
65 }
66 
67 /*
68 * Function: MonitorGpuEnd
69 * Type: Function
70 * Rank: Important(2)
71 * EnvConditions: N/A
72 * CaseDescription: 1. call MonitorGpuEnd
73 *                  2. check ret
74 */
75 HWTEST_F(FrameSchedTest, MonitorGpuEnd001, Function | MediumTest | Level2)
76 {
77     Rosen::FrameSched frameSched_;
78     frameSched_.MonitorGpuEnd();
79 }
80 
81 /*
82 * Function: SyncMerge
83 * Type: Function
84 * Rank: Important(2)
85 * EnvConditions: N/A
86 * CaseDescription: 1. call SyncMerge
87 *                  2. check ret
88 */
89 HWTEST_F(FrameSchedTest, SyncMergeTest001, Function | MediumTest | Level2)
90 {
91     int32_t newFenceFd = -1;
92     ASSERT_EQ(SyncFence::SyncMerge("SyncMergeTest001", 1, -1, newFenceFd), -1);
93     ASSERT_EQ(newFenceFd, -1);
94 
95     sptr<SyncFence> fence = new SyncFence(0);
96     ASSERT_EQ(fence->GetStatus(), FenceStatus::ERROR);
97 
98     sptr<SyncFence> fence1 = new SyncFence(-1);
99     EXPECT_EQ(fence1->GetStatus(), ERROR);
100 }
101 
102 /*
103 * Function: LoadLibrary
104 * Type: Function
105 * Rank: Important(2)
106 * EnvConditions: N/A
107 * CaseDescription: 1. call LoadLibrary
108 *                  2. check ret
109 */
110 HWTEST_F(FrameSchedTest, LoadLibrary001, Function | MediumTest | Level2)
111 {
112     auto frameSched = new Rosen::FrameSched();
113     frameSched->schedSoLoaded_ = false;
114     frameSched->LoadLibrary();
115     frameSched->schedSoLoaded_ = true;
116     frameSched->LoadLibrary();
117     delete frameSched;
118 }
119 
120 /*
121 * Function: CloseLibrary
122 * Type: Function
123 * Rank: Important(2)
124 * EnvConditions: N/A
125 * CaseDescription: 1. call CloseLibrary
126 *                  2. check ret
127 */
128 HWTEST_F(FrameSchedTest, CloseLibrary001, Function | MediumTest | Level2)
129 {
130     auto frameSched = new Rosen::FrameSched();
131     frameSched->schedHandle_ = nullptr;
132     frameSched->CloseLibrary();
133     delete frameSched;
134 }
135 
136 /*
137 * Function: LoadSymbol
138 * Type: Function
139 * Rank: Important(2)
140 * EnvConditions: N/A
141 * CaseDescription: 1. call LoadSymbol
142 *                  2. check ret
143 */
144 HWTEST_F(FrameSchedTest, LoadSymbol001, Function | MediumTest | Level2)
145 {
146     auto frameSched = new Rosen::FrameSched();
147     frameSched->schedSoLoaded_ = false;
148     frameSched->LoadSymbol("LoadSymbol001");
149     delete frameSched;
150 }
151 
152 /*
153 * Function: Init
154 * Type: Function
155 * Rank: Important(2)
156 * EnvConditions: N/A
157 * CaseDescription: 1. call Init
158 *                  2. check ret
159 */
160 HWTEST_F(FrameSchedTest, Init001, Function | MediumTest | Level2)
161 {
162     auto frameSched = new Rosen::FrameSched();
163     frameSched->initFunc_ = nullptr;
164     frameSched->Init();
165     delete frameSched;
166 }
167 }