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 "c/deadline.h" 19 #include "internal_inc/osal.h" 20 #include "sched/interval.h" 21 #include "dm/dependence_manager.h" 22 #include "sched/frame_interval.h" 23 #include "dfx/log/ffrt_log_api.h" 24 #include "common.h" 25 26 using namespace testing; 27 #ifdef HWTEST_TESTING_EXT_ENABLE 28 using namespace testing::ext; 29 #endif 30 using namespace ffrt; 31 32 class DeadlineTest : public testing::Test { 33 protected: SetUpTestCase()34 static void SetUpTestCase() 35 { 36 } 37 TearDownTestCase()38 static void TearDownTestCase() 39 { 40 } 41 SetUp()42 void SetUp() override 43 { 44 } 45 TearDown()46 void TearDown() override 47 { 48 } 49 }; 50 51 /** 52 * @tc.name: qos_interval_create_test 53 * @tc.desc: Test whether the qos_interval_create interface are normal. 54 * @tc.type: FUNC 55 */ 56 HWTEST_F(DeadlineTest, qos_interval_create_test, TestSize.Level1) 57 { 58 uint64_t deadline_us = 50000; 59 qos qos = qos_deadline_request; 60 61 interval qi = qos_interval_create(deadline_us, qos); 62 EXPECT_NE(qi, nullptr); 63 64 qos = qos_max + 1; 65 interval qi1 = qos_interval_create(deadline_us, qos); 66 EXPECT_EQ(qi1, nullptr); 67 } 68 69 /** 70 * @tc.name: qos_interval_destroy_test 71 * @tc.desc: Test whether the qos_interval_destroy interface are normal. 72 * @tc.type: FUNC 73 */ 74 HWTEST_F(DeadlineTest, qos_interval_destroy_test, TestSize.Level1) 75 { 76 interval* qi = new interval(); 77 EXPECT_NE(qi, nullptr); 78 qos_interval_destroy(*qi); 79 80 uint64_t deadline_us = 50000; 81 qos qos = qos_max + 1; 82 83 interval qi1 = qos_interval_create(deadline_us, qos); 84 EXPECT_EQ(qi1, nullptr); 85 qos_interval_destroy(qi1); 86 } 87 88 /** 89 * @tc.name: qos_interval_begin_test 90 * @tc.desc: Test whether the qos_interval_begin interface are normal. 91 * @tc.type: FUNC 92 */ 93 HWTEST_F(DeadlineTest, qos_interval_begin_test, TestSize.Level1) 94 { 95 interval* qi = new interval(); 96 qos_interval_begin(*qi); 97 98 uint64_t deadline_us = 50000; 99 qos qos = qos_max + 1; 100 101 interval qi1 = qos_interval_create(deadline_us, qos); 102 EXPECT_EQ(qi1, nullptr); 103 qos_interval_begin(qi1); 104 } 105 106 /** 107 * @tc.name: qos_interval_update_test 108 * @tc.desc: Test whether the qos_interval_update interface are normal. 109 * @tc.type: FUNC 110 */ 111 HWTEST_F(DeadlineTest, qos_interval_update_test, TestSize.Level1) 112 { 113 uint64_t deadline_us = 50000; 114 qos qos = qos_max + 1; 115 uint64_t new_deadline_us = 40000; 116 interval* qi = new interval(); 117 qos_interval_update(*qi, new_deadline_us); 118 119 interval qi1 = qos_interval_create(deadline_us, qos); 120 EXPECT_EQ(qi1, nullptr); 121 qos_interval_update(qi1, new_deadline_us); 122 } 123 124 /** 125 * @tc.name: qos_interval_end_test 126 * @tc.desc: Test whether the qos_interval_end interface are normal. 127 * @tc.type: FUNC 128 */ 129 HWTEST_F(DeadlineTest, qos_interval_end_test, TestSize.Level1) 130 { 131 uint64_t deadline_us = 50000; 132 qos qos = qos_max + 1; 133 interval* qi = new interval(); 134 qos_interval_end(*qi); 135 136 interval qi1 = qos_interval_create(deadline_us, qos); 137 EXPECT_EQ(qi1, nullptr); 138 qos_interval_end(qi1); 139 } 140 141 /** 142 * @tc.name: qos_interval_join_test 143 * @tc.desc: Test whether the qos_interval_join interface are normal. 144 * @tc.type: FUNC 145 */ 146 HWTEST_F(DeadlineTest, qos_interval_join_test, TestSize.Level1) 147 { 148 uint64_t deadline_us = 50000; 149 qos qos = qos_deadline_request; 150 interval ret = qos_interval_create(deadline_us, qos); 151 EXPECT_NE(ret, nullptr); 152 qos_interval_join(ret); 153 154 qos = qos_max + 1; 155 interval ret1 = qos_interval_create(deadline_us, qos); 156 EXPECT_EQ(ret1, nullptr); 157 qos_interval_join(ret1); 158 } 159 160 /** 161 * @tc.name: qos_interval_leave_test 162 * @tc.desc: Test whether the qos_interval_leave interface are normal. 163 * @tc.type: FUNC 164 */ 165 HWTEST_F(DeadlineTest, qos_interval_leave_test, TestSize.Level1) 166 { 167 uint64_t deadline_us = 50000; 168 qos qos = qos_deadline_request; 169 interval ret = qos_interval_create(deadline_us, qos); 170 EXPECT_NE(ret, nullptr); 171 qos_interval_leave(ret); 172 173 qos = qos_max + 1; 174 interval ret1 = qos_interval_create(deadline_us, qos); 175 EXPECT_EQ(ret1, nullptr); 176 qos_interval_leave(ret1); 177 } 178