• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include <thread>
18 #include "dfx/log/ffrt_log_api.h"
19 #include "sched/workgroup_internal.h"
20 #include "eu/execute_unit.h"
21 
22 #define private public
23 #include "sched/frame_interval.h"
24 #undef private
25 #include "common.h"
26 
27 using namespace testing;
28 #ifdef HWTEST_TESTING_EXT_ENABLE
29 using namespace testing::ext;
30 #endif
31 using namespace ffrt;
32 
33 class FrameIntervalTest : public testing::Test {
34 protected:
SetUpTestCase()35     static void SetUpTestCase()
36     {
37     }
38 
TearDownTestCase()39     static void TearDownTestCase()
40     {
41     }
42 
SetUp()43     void SetUp() override
44     {
45     }
46 
TearDown()47     void TearDown() override
48     {
49     }
50 };
51 
52 /**
53  * @tc.name: FrameIntervalTest
54  * @tc.desc: Test whether the FrameInterval interface are normal.
55  * @tc.type: FUNC
56  */
57 HWTEST_F(FrameIntervalTest, FrameIntervalTest, TestSize.Level1)
58 {
59     FrameInterval* fi = new FrameInterval(100000, QoS(5));
60     EXPECT_NE(fi, nullptr);
61 }
62 
63 /**
64  * @tc.name: OnQoSIntervalsTest
65  * @tc.desc: Test whether the OnQoSIntervals interface are normal.
66  * @tc.type: FUNC
67  */
68 HWTEST_F(FrameIntervalTest, OnQoSIntervalsTest, TestSize.Level1)
69 {
70     FrameInterval* fi = new FrameInterval(100000, QoS(5));
71     fi->OnQoSIntervals(ffrt::IntervalState::DEADLINE_BEGIN);
72     fi->OnQoSIntervals(ffrt::IntervalState::DEADLINE_END);
73     EXPECT_NE(fi, nullptr);
74 }
75 
76 /**
77  * @tc.name: BeginTest
78  * @tc.desc: Test whether the Begin interface are normal.
79  * @tc.type: FUNC
80  */
81 HWTEST_F(FrameIntervalTest, BeginTest, TestSize.Level1)
82 {
83     FrameInterval* fi = new FrameInterval(100000, QoS(5));
84     int ret = fi->Begin();
85     EXPECT_EQ(0, ret);
86 
87     int ret1 = fi->Begin();
88     EXPECT_EQ(-1, ret1);
89 }
90 
91 /**
92  * @tc.name: EndTest
93  * @tc.desc: Test whether the End interface are normal.
94  * @tc.type: FUNC
95  */
96 HWTEST_F(FrameIntervalTest, EndTest, TestSize.Level1)
97 {
98     FrameInterval* fi = new FrameInterval(100000, QoS(5));
99     fi->End();
100     EXPECT_FALSE(fi->isBegun);
101 
102     fi->isBegun = true;
103     fi->End();
104     EXPECT_FALSE(fi->isBegun);
105 }
106 /**
107  * @tc.name: updateTest
108  * @tc.desc: Test whether the update interface are normal.
109  * @tc.type: FUNC
110  */
111 HWTEST_F(FrameIntervalTest, updateTest, TestSize.Level1)
112 {
113     FrameInterval* fi = new FrameInterval(100000, QoS(5));
114     EXPECT_NE(fi, nullptr);
115     uint64_t deadline = 900;
116     fi->Update(deadline);
117     deadline = 1500000;
118     fi->Update(deadline);
119 
120     deadline = 100000;
121     fi->Update(deadline);
122 }
123 
124 /**
125  * @tc.name: JoinTest
126  * @tc.desc: Test whether the Join interface are normal.
127  * @tc.type: FUNC
128  */
129 HWTEST_F(FrameIntervalTest, JoinTest, TestSize.Level1)
130 {
131     FrameInterval* fi = new FrameInterval(100000, QoS(5));
132     EXPECT_NE(fi, nullptr);
133     fi->Join();
134     fi->Leave();
135 }