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 virtual void SetUp()
44 {
45 }
46
TearDown()47 virtual void TearDown()
48 {
49 }
50 };
51
52 /**
53 * @tc.name: FrameIntervalTest
54 * @tc.desc: Test whether the FrameInterval interface are normal.
55 * @tc.type: FUNC
56 */
HWTEST_F(FrameIntervalTest, FrameIntervalTest, TestSize.Level1)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 */
HWTEST_F(FrameIntervalTest, OnQoSIntervalsTest, TestSize.Level1)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 }
74
75 /**
76 * @tc.name: BeginTest
77 * @tc.desc: Test whether the Begin interface are normal.
78 * @tc.type: FUNC
79 */
HWTEST_F(FrameIntervalTest, BeginTest, TestSize.Level1)80 HWTEST_F(FrameIntervalTest, BeginTest, TestSize.Level1)
81 {
82 FrameInterval* fi = new FrameInterval(100000, QoS(5));
83 int ret = fi->Begin();
84 EXPECT_EQ(0, ret);
85
86 int ret1 = fi->Begin();
87 EXPECT_EQ(-1, ret1);
88 }
89
90 /**
91 * @tc.name: EndTest
92 * @tc.desc: Test whether the End interface are normal.
93 * @tc.type: FUNC
94 */
HWTEST_F(FrameIntervalTest, EndTest, TestSize.Level1)95 HWTEST_F(FrameIntervalTest, EndTest, TestSize.Level1)
96 {
97 FrameInterval* fi = new FrameInterval(100000, QoS(5));
98 fi->End();
99 EXPECT_FALSE(fi->isBegun);
100
101 fi->isBegun = true;
102 fi->End();
103 EXPECT_FALSE(fi->isBegun);
104 }
105 /**
106 * @tc.name: updateTest
107 * @tc.desc: Test whether the update interface are normal.
108 * @tc.type: FUNC
109 */
HWTEST_F(FrameIntervalTest, updateTest, TestSize.Level1)110 HWTEST_F(FrameIntervalTest, updateTest, TestSize.Level1)
111 {
112 FrameInterval* fi = new FrameInterval(100000, QoS(5));
113 uint64_t deadline = 900;
114 fi->Update(deadline);
115 deadline = 1500000;
116 fi->Update(deadline);
117
118 deadline = 100000;
119 fi->Update(deadline);
120 }
121
122 /**
123 * @tc.name: JoinTest
124 * @tc.desc: Test whether the Join interface are normal.
125 * @tc.type: FUNC
126 */
HWTEST_F(FrameIntervalTest, JoinTest, TestSize.Level1)127 HWTEST_F(FrameIntervalTest, JoinTest, TestSize.Level1)
128 {
129 FrameInterval* fi = new FrameInterval(100000, QoS(5));
130 fi->Join();
131 fi->Leave();
132 }