diff --git a/bundle.json b/bundle.json index c38bfa374ef2a4d836ed0c0d86d82cea58bc9b11..de2762f32d886dad7a3922e2453eefa1b6111b23 100644 --- a/bundle.json +++ b/bundle.json @@ -15,7 +15,6 @@ "syscap": [], "features": [], "adapted_system_type": [ - "mini", "small", "standard" ], @@ -41,7 +40,8 @@ "//foundation/resourceschedule/frame_aware_sched/interfaces/innerkits/frameintf:frame_msg_intf", "//foundation/resourceschedule/frame_aware_sched/interfaces/innerkits/frameintf:frame_trace_intf", "//foundation/resourceschedule/frame_aware_sched/interfaces/innerkits/frameintf:rtg_interface", - "//foundation/resourceschedule/frame_aware_sched/profiles:frame_aware_sched_config" + "//foundation/resourceschedule/frame_aware_sched/profiles:frame_aware_sched_config", + "//foundation/resourceschedule/frame_aware_sched/qos_manager:qos_manager" ], "inner_kits": [ { @@ -71,6 +71,15 @@ }, "name": "//foundation/resourceschedule/frame_aware_sched/interfaces/innerkits/frameintf:frame_trace_intf" }, + { + "header": { + "header_base": "//foundation/resourceschedule/frame_aware_sched/interfaces/inner_api/", + "header_files": [ + "qos.h" + ] + }, + "name": "//foundation/resourceschedule/frame_aware_sched/qos_manager:qos_manager" + }, { "header": { "header_base": "//foundation/resourceschedule/frame_aware_sched/common/include", diff --git a/frameworks/core/frame_aware_policy/include/intellisense_server.h b/frameworks/core/frame_aware_policy/include/intellisense_server.h index f4cccf61171296a15e802935e9836060d0b8b211..48e6a3e523460cc0b33f49bc511623166bd850f9 100644 --- a/frameworks/core/frame_aware_policy/include/intellisense_server.h +++ b/frameworks/core/frame_aware_policy/include/intellisense_server.h @@ -48,6 +48,9 @@ private: void NewBackground(int pid); void NewDiedProcess(int pid); void NewAppRecord(int pid); + void AuthAppKilled(int uid); + void AuthForeground(int uid); + void AuthBackground(int uid); int TryCreateRtgForApp(AppInfo *app); inline CgroupPolicy CheckCgroupState(const CgroupPolicy cgroup); std::list::iterator GetRecordOfPid(int pid); diff --git a/frameworks/core/frame_aware_policy/src/intellisense_server.cpp b/frameworks/core/frame_aware_policy/src/intellisense_server.cpp index 11a79ffa172579946ba3ad00029e469b0cf03974..9c8d67ec8372e5edc9a2b8732116638a354d0507 100644 --- a/frameworks/core/frame_aware_policy/src/intellisense_server.cpp +++ b/frameworks/core/frame_aware_policy/src/intellisense_server.cpp @@ -21,6 +21,7 @@ #include #include #include +#include "qos_common.h" #include "para_config.h" #include "rtg_interface.h" #include "rme_log_domain.h" @@ -240,8 +241,10 @@ void IntelliSenseServer::ReportCgroupChange(const int pid, const int uid, const } if (newState == CgroupPolicy::SP_BACKGROUND) { NewBackground(pid); + AuthBackground(uid); } else if (newState == CgroupPolicy::SP_FOREGROUND) { NewForeground(pid); + AuthForeground(uid); } } @@ -250,6 +253,9 @@ void IntelliSenseServer::ReportAppInfo(const int pid, const int uid, const std:: if (!m_switch) { return; } + if (state == ThreadState::CREATE) { + AuthForeground(uid); + } RME_LOGI("Get app info:%{public}d %{public}d %{public}s %{public}d", pid, uid, bundleName.c_str(), static_cast(state)); } @@ -266,6 +272,7 @@ void IntelliSenseServer::ReportProcessInfo(const int pid, } switch (state) { case ThreadState::DIED: + AuthAppKilled(uid); NewDiedProcess(pid); break; case ThreadState::CREATE: @@ -288,5 +295,38 @@ void IntelliSenseServer::SetPara(const int32_t currentFps, const int32_t current map tempMap = m_subEventPara[key]; RME_LOGI("[SetPara]:subEventPara map size: %{public}zu", tempMap.size()); } + +void IntelliSenseServer::AuthAppKilled(int uid) +{ + int ret = AuthDelete(uid); + if (ret == 0) { + RME_LOGI("auth_delete %{public}d success", uid); + } else { + RME_LOGE("auth_delete %{public}d failed", uid); + } +} + +void IntelliSenseServer::AuthForeground(int uid) +{ + unsigned int flag = AF_RTG_ALL; + int status = AUTH_STATUS_FOREGROUND; + int ret = AuthEnable(uid, flag, status); + if (ret == 0) { + RME_LOGI("auth_enable %{public}d success", uid); + } else { + RME_LOGE("auth_enable %{public}d failed", uid); + } +} + +void IntelliSenseServer::AuthBackground(int uid) +{ + int ret = AuthPause(uid); + if (ret == 0) { + RME_LOGI("auth_pause %{public}d success", uid); + } else { + RME_LOGE("auth_pause %{public}d failed", uid); + } +} + } // namespace RME } // namesapce OHOS diff --git a/interfaces/inner_api/qos.h b/interfaces/inner_api/qos.h new file mode 100644 index 0000000000000000000000000000000000000000..98a82b86d9695b9009c6eac6db7097be5733fdfb --- /dev/null +++ b/interfaces/inner_api/qos.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef QOS_MANAGER_H +#define QOS_MANAGER_H + +namespace OHOS { +namespace QOS { +enum class QosLevel { + qos_background = 1, + qos_utility, + qos_default, + qos_user_initiated = 4, +}; + +class QosController { +public: + static QosController& GetInstance(); + + int SetThreadQosForOtherThread(enum QosLevel level, int tid); + int ResetThreadQosForOtherThread(int tid); + +private: + QosController() = default; + ~QosController() = default; + + QosController(const QosController&) = delete; + QosController& operator=(const QosController&) = delete; + QosController(QosController&&) = delete; + QosController& operator=(const QosController&&) = delete; + + int SetPolicy(); + bool policyStatus_ = false; +}; + +int SetThreadQos(enum QosLevel level); +int SetQosForOtherThread(enum QosLevel level, int tid); +int ResetThreadQos(); +int ResetQosForOtherThread(int tid); + +} // namespace QOS +} // namespace OHOS + +#endif // QOS_MANAGER_H \ No newline at end of file diff --git a/interfaces/innerkits/frameintf/BUILD.gn b/interfaces/innerkits/frameintf/BUILD.gn index bace3b594fce51b61e1a0789e222fce948919de5..31f9037be1383df364ae86ef0b5188f3a20dcdab 100644 --- a/interfaces/innerkits/frameintf/BUILD.gn +++ b/interfaces/innerkits/frameintf/BUILD.gn @@ -83,6 +83,7 @@ config("frame_msg_intf_config") { "./", "../../../frameworks/core/frame_aware_policy/include", "../../../common/include", + "../../../qos_manager/include", "//third_party/libxml2/include", ] } @@ -92,6 +93,7 @@ ohos_shared_library("frame_msg_intf") { "../../../frameworks/core/frame_aware_policy/src/app_info.cpp", "../../../frameworks/core/frame_aware_policy/src/intellisense_server.cpp", "../../../frameworks/core/frame_aware_policy/src/para_config.cpp", + "../../../qos_manager/src/qos_common.cpp", "frame_msg_intf.cpp", "rtg_interface.cpp", ] diff --git a/qos_manager/BUILD.gn b/qos_manager/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9bb8383079b9268a1d66e5b1a5b779a7bf61b2d4 --- /dev/null +++ b/qos_manager/BUILD.gn @@ -0,0 +1,36 @@ +# Copyright (C) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") + +config("qos_manager_config") { + visibility = [ ":*" ] + include_dirs = [ + "include/", + "../common/include/", + "../interfaces/inner_api/", + ] +} + +ohos_shared_library("qos_manager") { + public_configs = [ ":qos_manager_config" ] + sources = [ + "src/qos_common.cpp", + "src/qos_manager.cpp", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + subsystem_name = "resourceschedule" + part_name = "frame_aware_sched" +} diff --git a/qos_manager/include/qos_common.h b/qos_manager/include/qos_common.h new file mode 100644 index 0000000000000000000000000000000000000000..7f6e50232912415ad39b7331e95bd07abd2eeca7 --- /dev/null +++ b/qos_manager/include/qos_common.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef QOS_COMMON_H +#define QOS_COMMON_H + +constexpr int NR_QOS = 6; +constexpr int QOS_NICE_FLAG = 0x01; +constexpr int QOS_LATENCY_NICE_FLAG = 0x02; +constexpr int QOS_UCLAMP_FLAG = 0x04; +constexpr int QOS_RT_FLAG = 0x08; +constexpr int QOS_ALL_FLAG = (QOS_NICE_FLAG | QOS_LATENCY_NICE_FLAG | \ + QOS_UCLAMP_FLAG | QOS_RT_FLAG); + +constexpr int AF_RTG_ALL = 0x1fff; +constexpr int AF_RTG_DELEGATED = 0x1fff; + +struct AuthCtrlData { + int uid; + unsigned int type; + unsigned int rtgFlag; + unsigned int qosFlag; + unsigned int status; +}; + +struct QosCtrlData { + int pid; + unsigned int type; + int level; +}; + +struct QosPolicyData { + int nice; + int latencyNice; + int uclampMin; + int uclampMax; + int rtSchedPriority; +}; + +struct QosPolicyDatas { + int policyType; + unsigned int policyFlag; + struct QosPolicyData policys[NR_QOS + 1]; +}; + +enum AuthOperationType { + AUTH_ENABLE = 1, + AUTH_DELETE, + AUTH_GET, + AUTH_SWITCH, + AUTH_MAX_NR, +}; + +enum QosOperationType { + QOS_APPLY = 1, + QOS_LEAVE, + QOS_MAX_NR, +}; + +enum QosPolicyType { + QOS_POLICY_DEFAULT = 1, + QOS_POLICY_SYSTEM_SERVER = 2, + QOS_POLICY_FRONT = 3, + QOS_POLICY_BACK = 4, + QOS_POLICY_MAX_NR, +}; + +enum AuthStatus { + AUTH_STATUS_DISABLED = 1, + AUTH_STATUS_SYSTEM_SERVER = 2, + AUTH_STATUS_FOREGROUND, + AUTH_STATUS_BACKGROUND, + AUTH_STATUS_DEAD, +}; + +#define QOS_CTRL_BASIC_OPERATION \ + _IOWR(0xCC, 1, struct QosCtrlData) +#define QOS_CTRL_POLICY_OPERATION \ + _IOWR(0xCC, 2, struct QosPolicyDatas) +#define BASIC_AUTH_CTRL_OPERATION \ + _IOWR(0xCD, 1, struct AuthCtrlData) + +int AuthEnable(int uid, unsigned int flag, unsigned int status); +int AuthPause(int uid); +int AuthDelete(int uid); +int QosApplyForThread(int level, int tid); +int QosLeaveForThread(int tid); +int QosPolicy(struct QosPolicyDatas *policyDatas); + +#endif // QOS_COMMON_H \ No newline at end of file diff --git a/qos_manager/src/qos_common.cpp b/qos_manager/src/qos_common.cpp new file mode 100644 index 0000000000000000000000000000000000000000..86bcc513429b893bcb0574e05707aafcf0d65718 --- /dev/null +++ b/qos_manager/src/qos_common.cpp @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "qos_common.h" +#include +#include +#include +#include +#include +#include "rme_log_domain.h" + +constexpr unsigned int AF_QOS_DELEGATED = 0x0001; + +DEFINE_RMELOG_INTELLISENSE("qos_manager"); + +static int TrivalOpenQosCtrlNode(void) +{ + char fileName[] = "/proc/thread-self/sched_qos_ctrl"; + int fd = open(fileName, O_RDWR); + return fd; +} + +static int TrivalOpenAuthCtrlNode(void) +{ + char fileName[] = "/dev/auth_ctrl"; + int fd = open(fileName, O_RDWR); + return fd; +} + +int AuthEnable(int uid, unsigned int flag, unsigned int status) +{ + struct AuthCtrlData data; + int fd; + int ret; + + fd = TrivalOpenAuthCtrlNode(); + if (fd < 0) { + RME_LOGE("thread %{public}d belong to user %{public}d open auth node failed\n", gettid(), getuid()); + return fd; + } + + data.uid = uid; + data.rtgFlag = flag; + data.qosFlag = AF_QOS_DELEGATED; + data.status = status; + data.type = AUTH_ENABLE; + + ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data); + if (ret < 0) { + RME_LOGE("auth enable failed for uid %{public}d with status %{public}u\n", uid, status); + } + close(fd); + return ret; +} + +int AuthPause(int uid) +{ + struct AuthCtrlData data; + int fd; + int ret; + + fd = TrivalOpenAuthCtrlNode(); + if (fd < 0) { + RME_LOGE("thread %{public}d belong to user %{public}d open auth node failed\n", gettid(), getuid()); + return fd; + } + + data.uid = uid; + data.rtgFlag = 0; + data.qosFlag = AF_QOS_DELEGATED; + data.status = AUTH_STATUS_BACKGROUND; + data.type = AUTH_SWITCH; + + ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data); + if (ret < 0) { + RME_LOGE("auth pause failed for uid %{public}d\n", uid); + } + close(fd); + return ret; +} + +int AuthDelete(int uid) +{ + struct AuthCtrlData data; + int fd; + int ret; + + fd = TrivalOpenAuthCtrlNode(); + if (fd < 0) { + RME_LOGE("thread %{public}d belong to user %{public}d open auth node failed\n", gettid(), getuid()); + return fd; + } + + data.uid = uid; + data.type = AUTH_DELETE; + + ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data); + if (ret < 0) { + RME_LOGE("auth delete failed for uid %{public}d\n", uid); + } + close(fd); + return ret; +} + +int QosApplyForThread(int level, int tid) +{ + struct QosCtrlData data; + int fd; + + int ret; + + fd = TrivalOpenQosCtrlNode(); + if (fd < 0) { + RME_LOGE("thread %{public}d belong to user %{public}d open qos node failed\n", gettid(), getuid()); + return fd; + } + + data.level = level; + data.type = QOS_APPLY; + data.pid = tid; + + ret = ioctl(fd, QOS_CTRL_BASIC_OPERATION, &data); + if (ret < 0) { + RME_LOGE("qos apply failed for thread %{public}d\n", tid); + } + close(fd); + return ret; +} + +int QosLeaveForThread(int tid) +{ + struct QosCtrlData data; + int fd; + int ret; + + fd = TrivalOpenQosCtrlNode(); + if (fd < 0) { + RME_LOGE("thread %{public}d belong to user %{public}d open qos node failed\n", gettid(), getuid()); + return fd; + } + + data.type = QOS_LEAVE; + data.pid = tid; + + ret = ioctl(fd, QOS_CTRL_BASIC_OPERATION, &data); + if (ret < 0) { + RME_LOGE("qos leave failed for thread %{public}d\n", tid); + } + close(fd); + return ret; +} + +int QosPolicy(struct QosPolicyDatas *policyDatas) +{ + int fd; + int ret; + + fd = TrivalOpenQosCtrlNode(); + if (fd < 0) { + RME_LOGE("thread %{public}d belong to user %{public}d open qos node failed\n", gettid(), getuid()); + return fd; + } + + ret = ioctl(fd, QOS_CTRL_POLICY_OPERATION, policyDatas); + if (ret < 0) { + RME_LOGE("set qos policy failed for thread %{public}d\n", gettid()); + } + close(fd); + return ret; +} \ No newline at end of file diff --git a/qos_manager/src/qos_manager.cpp b/qos_manager/src/qos_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ec1dad69a5d1bc79dbe144e05f1ed5bc588803b3 --- /dev/null +++ b/qos_manager/src/qos_manager.cpp @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "qos.h" +#include +#include +#include "qos_common.h" +#include "rme_log_domain.h" + +constexpr int ERROR_NUM = -1; + +namespace OHOS { +namespace QOS { + +DEFINE_RMELOG_INTELLISENSE("qos_manager"); + +static struct QosPolicyDatas g_defaultPolicy = { + .policyType = QOS_POLICY_DEFAULT, + .policyFlag = QOS_ALL_FLAG, + .policys = { + {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + } +}; + +static struct QosPolicyDatas g_systemServerPolicy = { + .policyType = QOS_POLICY_SYSTEM_SERVER, + .policyFlag = QOS_ALL_FLAG, + .policys = { + {0, 0, 0, 1024, 0}, + {10, 0, 0, 1024, 0}, + {5, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + } +}; + +static struct QosPolicyDatas g_foregroundPolicy = { + .policyType = QOS_POLICY_FRONT, + .policyFlag = QOS_ALL_FLAG, + .policys = { + {0, 0, 0, 1024, 0}, + {10, 0, 0, 1024, 0}, + {5, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + } +}; + +static struct QosPolicyDatas g_backgroundPolicy = { + .policyType = QOS_POLICY_BACK, + .policyFlag = QOS_ALL_FLAG & ~QOS_RT_FLAG, + .policys = { + {0, 0, 0, 1024, 0}, + {15, 0, 0, 1024, 0}, + {10, 0, 0, 1024, 0}, + {5, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + } +}; + +QosController& QosController::GetInstance() +{ + static QosController instance; + if (!instance.policyStatus_) { + int ret = instance.SetPolicy(); + if (ret == 0) { + instance.policyStatus_ = true; + RME_LOGI("set qos policy success"); + } + } + return instance; +} + +int QosController::SetPolicy() +{ + int ret; + + ret = QosPolicy(&g_defaultPolicy); + if (ret) { + RME_LOGE("set g_defaultPolicy failed"); + return ret; + } + + ret = QosPolicy(&g_foregroundPolicy); + if (ret) { + RME_LOGE("set g_foregroundPolicy failed"); + return ret; + } + + ret = QosPolicy(&g_backgroundPolicy); + if (ret) { + RME_LOGE("set g_backgroundPolicy failed"); + return ret; + } + + ret = QosPolicy(&g_systemServerPolicy); + if (ret) { + RME_LOGE("set g_systemServerPolicy failed"); + } + return ret; +} + +int QosController::SetThreadQosForOtherThread(enum QosLevel level, int tid) +{ + int qos = static_cast(level); + if (level < QosLevel::qos_background || level > QosLevel::qos_user_initiated) { + RME_LOGE("invalid qos level %{public}d", qos); + return ERROR_NUM; + } + int ret = QosApplyForThread(qos, tid); + if (ret == 0) { + RME_LOGI("qoslevel %{public}d apply for tid %{public}d success", qos, tid); + } else { + RME_LOGE("qoslevel %{public}d apply for tid %{public}d failure", qos, tid); + } + + return ret; +} + +int QosController::ResetThreadQosForOtherThread(int tid) +{ + int ret = QosLeaveForThread(tid); + if (ret == 0) { + RME_LOGI("qoslevel reset for tid %{public}d success", tid); + } else { + RME_LOGE("qoslevel reset for tid %{public}d failure", tid); + } + + return ret; +} + +int SetThreadQos(enum QosLevel level) +{ + int tid = gettid(); + return QosController::GetInstance().SetThreadQosForOtherThread(level, tid); +} + +int SetQosForOtherThread(enum QosLevel level, int tid) +{ + return QosController::GetInstance().SetThreadQosForOtherThread(level, tid); +} + +int ResetThreadQos() +{ + int tid = gettid(); + return QosController::GetInstance().ResetThreadQosForOtherThread(tid); +} + +int ResetQosForOtherThread(int tid) +{ + return QosController::GetInstance().ResetThreadQosForOtherThread(tid); +} + +} // namespace QOS +} // namespace OHOS \ No newline at end of file diff --git a/test/BUILD.gn b/test/BUILD.gn index eded3f2f15e9b6bcb4474501f4df1368c122644f..2de4d12d4a1d69e9996ddcdaa1b7dcdda5df118c 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -75,12 +75,33 @@ ohos_unittest("rtg_interface_test") { subsystem_name = "resourceschedule" } +ohos_unittest("qos_manager_test") { + module_out_path = module_output_path + + sources = [ "unittest/phone/qos_manager_test.cpp" ] + + include_dirs = [ + "../interfaces/inner_api", + "../qos_manager/include", + ] + + deps = [ "../qos_manager:qos_manager" ] + + if (is_standard_system) { + public_deps = frame_aware_sched_public_deps + } + + part_name = "frame_aware_sched" + subsystem_name = "resourceschedule" +} + group("frame_unittest") { testonly = true deps = [] if (!is_asan) { deps += [ ":frame_msg_intf_test", + ":qos_manager_test", ":rtg_interface_test", ] } diff --git a/test/unittest/phone/qos_manager_test.cpp b/test/unittest/phone/qos_manager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ce4d8e6178b30e479f1f9b128a810d5f3d96e583 --- /dev/null +++ b/test/unittest/phone/qos_manager_test.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include "qos.h" +#include +#include + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::QOS; + +class QosManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void QosManagerTest::SetUpTestCase() +{ +} + +void QosManagerTest::TearDownTestCase() +{ +} + +void QosManagerTest::SetUp() +{ +} + +void QosManagerTest::TearDown() +{ +} + +/** + * @tc.name: QosManagerTest + * @tc.desc: Verify the CreateAndDestroy function. + * @tc.type: FUNC + */ +HWTEST_F(QosManagerTest, SetThreadQosTest1, TestSize.Level1) +{ + int ret = SetThreadQos(QosLevel::qos_user_initiated); + EXPECT_EQ(ret, 0); + ret = SetThreadQos(QosLevel::qos_default); + EXPECT_EQ(ret, 0); + ret = SetThreadQos(QosLevel::qos_utility); + EXPECT_EQ(ret, 0); + ret = SetThreadQos(QosLevel::qos_background); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(QosManagerTest, SetThreadQosTest3, TestSize.Level1) +{ + int ret = SetQosForOtherThread(QosLevel::qos_user_initiated, gettid()); + EXPECT_EQ(ret, 0); + ret = SetQosForOtherThread(QosLevel::qos_default, gettid()); + EXPECT_EQ(ret, 0); + ret = SetQosForOtherThread(QosLevel::qos_utility, gettid()); + EXPECT_EQ(ret, 0); + ret = SetQosForOtherThread(QosLevel::qos_background, gettid()); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(QosManagerTest, ResetThreadQosTest1, TestSize.Level1) +{ + int ret = SetThreadQos(QosLevel::qos_user_initiated); + EXPECT_EQ(ret, 0); + ret = ResetThreadQos(); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(QosManagerTest, ResetThreadQosTest2, TestSize.Level1) +{ + int ret = SetQosForOtherThread(QosLevel::qos_user_initiated, gettid()); + EXPECT_EQ(ret, 0); + ret = ResetQosForOtherThread(gettid()); + EXPECT_EQ(ret, 0); +} \ No newline at end of file