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 #include <gtest/gtest.h> 16 #include <thread> 17 #include "core/task_ctx.h" 18 #include "core/dependence_manager.h" 19 #include "sched/qos.h" 20 #include "ffrt.h" 21 #include "internal_inc/types.h" 22 23 using namespace testing; 24 using namespace testing::ext; 25 using namespace ffrt; 26 using namespace std; 27 28 class TaskCtxTest : public testing::Test { 29 protected: SetUpTestCase()30 static void SetUpTestCase() 31 { 32 } 33 TearDownTestCase()34 static void TearDownTestCase() 35 { 36 } 37 SetUp()38 virtual void SetUp() 39 { 40 } 41 TearDown()42 virtual void TearDown() 43 { 44 } 45 }; 46 47 /** 48 * @tc.name: ChargeQoSSubmit 49 * @tc.desc: Test whether the ChargeQoSSubmit interface are normal. 50 * @tc.type: FUNC 51 */ 52 53 HWTEST_F(TaskCtxTest, ChargeQoSSubmit, TestSize.Level1) 54 { __anonbeb3e76b0102() 55 auto func = ([]() {std::cout << std::endl << " push a task " << std::endl;}); 56 TaskCtx *task = new TaskCtx(nullptr, nullptr, 0, nullptr, QoS()); 57 QoS qos = QoS(static_cast<int>(qos_inherit)); 58 task->SetQos(qos); 59 EXPECT_EQ(task->qos, qos_default); 60 delete task; 61 __anonbeb3e76b0202() 62 auto func1 = ([]() {std::cout << std::endl << " push a task " << std::endl;}); 63 TaskCtx *task1 = new TaskCtx(nullptr, nullptr, 0, nullptr, QoS(static_cast<int>(qos_user_interactive))); __anonbeb3e76b0302() 64 auto func2 = ([]() {std::cout << std::endl << " push a task " << std::endl;}); 65 TaskCtx *task2 = new TaskCtx(nullptr, task1, 0, nullptr, QoS()); 66 QoS qos2 = QoS(static_cast<int>(qos_inherit)); 67 task2->SetQos(qos2); 68 EXPECT_EQ(task2->qos, static_cast<int>(qos_user_interactive)); 69 delete task1; 70 delete task2; 71 __anonbeb3e76b0402() 72 auto func3 = ([]() {std::cout << std::endl << " push a task " << std::endl;}); 73 TaskCtx *task3 = new TaskCtx(nullptr, nullptr, 0, nullptr, QoS()); 74 QoS qos3 = QoS(static_cast<int>(qos_user_interactive)); 75 task3->SetQos(qos3); 76 EXPECT_EQ(task3->qos, static_cast<int>(qos_user_interactive)); 77 delete task3; 78 } 79