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 26 using namespace testing; 27 using namespace testing::ext; 28 using namespace ffrt; 29 30 class FrameIntervalTest : public testing::Test { 31 protected: SetUpTestCase()32 static void SetUpTestCase() 33 { 34 } 35 TearDownTestCase()36 static void TearDownTestCase() 37 { 38 } 39 SetUp()40 virtual void SetUp() 41 { 42 } 43 TearDown()44 virtual void TearDown() 45 { 46 } 47 }; 48 49 /** 50 * @tc.name: FrameIntervalTest 51 * @tc.desc: Test whether the FrameInterval interface are normal. 52 * @tc.type: FUNC 53 */ 54 HWTEST_F(FrameIntervalTest, FrameIntervalTest, TestSize.Level1) 55 { 56 FrameInterval* fi = new FrameInterval(100000, 5); 57 EXPECT_NE(fi, nullptr); 58 } 59 60 /** 61 * @tc.name: OnQoSIntervalsTest 62 * @tc.desc: Test whether the OnQoSIntervals interface are normal. 63 * @tc.type: FUNC 64 */ 65 HWTEST_F(FrameIntervalTest, OnQoSIntervalsTest, TestSize.Level1) 66 { 67 FrameInterval* fi = new FrameInterval(100000, 5); 68 fi->OnQoSIntervals(ffrt::IntervalState::DEADLINE_BEGIN); 69 fi->OnQoSIntervals(ffrt::IntervalState::DEADLINE_END); 70 } 71 72 /** 73 * @tc.name: BeginTest 74 * @tc.desc: Test whether the Begin interface are normal. 75 * @tc.type: FUNC 76 */ 77 HWTEST_F(FrameIntervalTest, BeginTest, TestSize.Level1) 78 { 79 FrameInterval* fi = new FrameInterval(100000, 5); 80 int ret = fi->Begin(); 81 EXPECT_EQ(0, ret); 82 83 int ret1 = fi->Begin(); 84 EXPECT_EQ(-1, ret1); 85 } 86 87 /** 88 * @tc.name: EndTest 89 * @tc.desc: Test whether the End interface are normal. 90 * @tc.type: FUNC 91 */ 92 HWTEST_F(FrameIntervalTest, EndTest, TestSize.Level1) 93 { 94 FrameInterval* fi = new FrameInterval(100000, 5); 95 fi->End(); 96 EXPECT_FALSE(fi->isBegun); 97 98 fi->isBegun = true; 99 fi->End(); 100 EXPECT_FALSE(fi->isBegun); 101 } 102 /** 103 * @tc.name: updateTest 104 * @tc.desc: Test whether the update interface are normal. 105 * @tc.type: FUNC 106 */ 107 HWTEST_F(FrameIntervalTest, updateTest, TestSize.Level1) 108 { 109 FrameInterval* fi = new FrameInterval(100000, 5); 110 uint64_t deadline = 900; 111 fi->Update(deadline); 112 deadline = 1500000; 113 fi->Update(deadline); 114 115 deadline = 100000; 116 fi->Update(deadline); 117 } 118 119 /** 120 * @tc.name: JoinTest 121 * @tc.desc: Test whether the Join interface are normal. 122 * @tc.type: FUNC 123 */ 124 HWTEST_F(FrameIntervalTest, JoinTest, TestSize.Level1) 125 { 126 FrameInterval* fi = new FrameInterval(100000, 5); 127 fi->Join(); 128 fi->Leave(); 129 }