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.Level0) 58 { 59 FrameInterval* fi = new FrameInterval(100000, QoS(5)); 60 EXPECT_NE(fi, nullptr); 61 delete fi; 62 } 63 64 /** 65 * @tc.name: OnQoSIntervalsTest 66 * @tc.desc: Test whether the OnQoSIntervals interface are normal. 67 * @tc.type: FUNC 68 */ 69 HWTEST_F(FrameIntervalTest, OnQoSIntervalsTest, TestSize.Level0) 70 { 71 FrameInterval* fi = new FrameInterval(100000, QoS(5)); 72 fi->OnQoSIntervals(ffrt::IntervalState::DEADLINE_BEGIN); 73 fi->OnQoSIntervals(ffrt::IntervalState::DEADLINE_END); 74 EXPECT_NE(fi, nullptr); 75 delete fi; 76 } 77 78 /** 79 * @tc.name: BeginTest 80 * @tc.desc: Test whether the Begin interface are normal. 81 * @tc.type: FUNC 82 */ 83 HWTEST_F(FrameIntervalTest, BeginTest, TestSize.Level0) 84 { 85 FrameInterval* fi = new FrameInterval(100000, QoS(5)); 86 int ret = fi->Begin(); 87 EXPECT_EQ(0, ret); 88 89 int ret1 = fi->Begin(); 90 EXPECT_EQ(-1, ret1); 91 delete fi; 92 } 93 94 /** 95 * @tc.name: EndTest 96 * @tc.desc: Test whether the End interface are normal. 97 * @tc.type: FUNC 98 */ 99 HWTEST_F(FrameIntervalTest, EndTest, TestSize.Level0) 100 { 101 FrameInterval* fi = new FrameInterval(100000, QoS(5)); 102 fi->End(); 103 EXPECT_FALSE(fi->isBegin); 104 105 fi->isBegin = true; 106 fi->End(); 107 EXPECT_FALSE(fi->isBegin); 108 delete fi; 109 } 110 /** 111 * @tc.name: updateTest 112 * @tc.desc: Test whether the update interface are normal. 113 * @tc.type: FUNC 114 */ 115 HWTEST_F(FrameIntervalTest, updateTest, TestSize.Level0) 116 { 117 FrameInterval* fi = new FrameInterval(100000, QoS(5)); 118 EXPECT_NE(fi, nullptr); 119 uint64_t deadline = 900; 120 fi->Update(deadline); 121 deadline = 1500000; 122 fi->Update(deadline); 123 124 deadline = 100000; 125 fi->Update(deadline); 126 delete fi; 127 } 128 129 /** 130 * @tc.name: JoinTest 131 * @tc.desc: Test whether the Join interface are normal. 132 * @tc.type: FUNC 133 */ 134 HWTEST_F(FrameIntervalTest, JoinTest, TestSize.Level0) 135 { 136 FrameInterval* fi = new FrameInterval(100000, QoS(5)); 137 EXPECT_NE(fi, nullptr); 138 fi->Join(); 139 fi->Leave(); 140 delete fi; 141 } 142 143 HWTEST_F(FrameIntervalTest, JoinSubTest, TestSize.Level0) 144 { 145 FrameInterval* fi = new FrameInterval(100000, QoS(5)); 146 EXPECT_NE(fi, nullptr); 147 fi->wg = nullptr; 148 fi->OnQoSIntervals(ffrt::IntervalState::DEADLINE_BEGIN); 149 fi->Join(); 150 } 151