diff --git a/bundle.json b/bundle.json index 6f6da4793c4813539d0d3b499ab21c3b03c2a9be..4962b7f05b7e6b804a1b05f0a57c1420b3b92405 100644 --- a/bundle.json +++ b/bundle.json @@ -43,7 +43,8 @@ "//foundation/resourceschedule/qos_manager/etc/init:concurrent_task_service.cfg", "//foundation/resourceschedule/qos_manager/sa_profile:concurrent_task_sa_profile", "//foundation/resourceschedule/qos_manager/services:concurrentsvc", - "//foundation/resourceschedule/qos_manager/frameworks/concurrent_task_client:concurrent_task_client" + "//foundation/resourceschedule/qos_manager/frameworks/concurrent_task_client:concurrent_task_client", + "//foundation/resourceschedule/qos_manager/qos:qos" ], "inner_kits": [ { @@ -54,10 +55,20 @@ ] }, "name": "//foundation/resourceschedule/qos_manager/frameworks/concurrent_task_client:concurrent_task_client" + }, + { + "header": { + "header_base": "//foundation/resourceschedule/qos_manager/interfaces/inner_api/", + "header_files": [ + "qos.h" + ] + }, + "name": "//foundation/resourceschedule/qos_manager/qos:qos" } ], "test": [ - "//foundation/resourceschedule/qos_manager/test:concurrent_unittest" + "//foundation/resourceschedule/qos_manager/test:concurrent_unittest", + "//foundation/resourceschedule/qos_manager/test/fuzztest:concurrent_fuzztest" ] } } diff --git a/interfaces/inner_api/qos.h b/interfaces/inner_api/qos.h new file mode 100644 index 0000000000000000000000000000000000000000..84f2d5e4e369ea381e20113c594b7b031fe74854 --- /dev/null +++ b/interfaces/inner_api/qos.h @@ -0,0 +1,52 @@ +/* + * 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_INTERFACES_INNER_API_QOS_H +#define QOS_MANAGER_INTERFACES_INNER_API_QOS_H + +namespace OHOS { +namespace QOS { +enum class QosLevel { + QOS_BACKGROUND = 1, + QOS_UTILITY, + QOS_DEFAULT, + QOS_USER_INITIATED, +}; + +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 SetThreadQos(enum QosLevel level); +int SetQosForOtherThread(enum QosLevel level, int tid); +int ResetThreadQos(); +int ResetQosForOtherThread(int tid); +} // namespace QOS +} // namespace OHOS + +#endif // QOS_MANAGER_INTERFACES_INNER_API_QOS_H \ No newline at end of file diff --git a/qos/BUILD.gn b/qos/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f1ba6657dcf1443e352437e6b0a3af4a726f6e55 --- /dev/null +++ b/qos/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_config") { + visibility = [ ":*" ] + include_dirs = [ + "../include/", + "../interfaces/inner_api/", + "../services/include/", + ] +} + +ohos_shared_library("qos") { + public_configs = [ ":qos_config" ] + sources = [ + "../services/src/qos_interface.cpp", + "qos.cpp", + ] + + external_deps = [ "hilog:libhilog" ] + + subsystem_name = "resourceschedule" + part_name = "qos_manager" +} diff --git a/qos/qos.cpp b/qos/qos.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ae2ceff4b5fc809d1a7c026e09e997277cbc2ddc --- /dev/null +++ b/qos/qos.cpp @@ -0,0 +1,84 @@ +/* + * 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 +#include +#include "concurrent_task_log.h" +#include "qos_interface.h" +#include "qos.h" +using namespace OHOS::ConcurrentTask; + +constexpr int ERROR_NUM = -1; + +namespace OHOS { +namespace QOS { +QosController& QosController::GetInstance() +{ + static QosController instance; + return instance; +} + +int QosController::SetThreadQosForOtherThread(enum QosLevel level, int tid) +{ + int qos = static_cast(level); + if (level < QosLevel::QOS_BACKGROUND || level > QosLevel::QOS_USER_INITIATED) { + CONCUR_LOGE("[Qos] invalid qos level %{public}d", qos); + return ERROR_NUM; + } + int ret = QosApplyForOther(qos, tid); + if (ret == 0) { + CONCUR_LOGD("[Qos] qoslevel %{public}d apply for tid %{public}d success", qos, tid); + } else { + CONCUR_LOGE("[Qos] qoslevel %{public}d apply for tid %{public}d failure", qos, tid); + } + + return ret; +} + +int QosController::ResetThreadQosForOtherThread(int tid) +{ + int ret = QosLeaveForOther(tid); + if (ret == 0) { + CONCUR_LOGD("[Qos] qoslevel reset for tid %{public}d success", tid); + } else { + CONCUR_LOGE("[Qos] 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 diff --git a/services/BUILD.gn b/services/BUILD.gn index 6244b988347dc834e1a148c956c2e45c562ebbb6..15b7a730e4a1f33ae4881ce6e6d337c583e4995c 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -38,7 +38,7 @@ ohos_shared_library("concurrentsvc") { "src/concurrent_task_service_ability.cpp", "src/concurrent_task_service_stub.cpp", "src/qos_interface.cpp", - "src/qos_manager.cpp", + "src/qos_policy.cpp", ] deps = [ @@ -46,7 +46,8 @@ ohos_shared_library("concurrentsvc") { "//third_party/jsoncpp:jsoncpp", ] - if (defined(global_parts_info.resourceschedule_frame_aware_sched_override)) { + if (defined( + global_parts_info.hmosresourceschedule_frame_aware_sched_override)) { defines = [ "QOS_EXT_ENABLE" ] } diff --git a/services/include/concurrent_task_controller.h b/services/include/concurrent_task_controller.h index 739cee9dde7e3c8a58e76254cc301cf8d8ce6cc3..5cb2d59f117625194f721b8e0c1e9bda34d654c5 100644 --- a/services/include/concurrent_task_controller.h +++ b/services/include/concurrent_task_controller.h @@ -23,7 +23,7 @@ #include #include "json/json.h" #include "concurrent_task_type.h" -#include "qos_manager.h" +#include "qos_policy.h" namespace OHOS { namespace ConcurrentTask { @@ -62,7 +62,7 @@ private: std::mutex appInfoLock_; std::list foregroundApp_ = {}; std::unordered_map msgType_ = {}; - QosManager qosManager_; + QosPolicy qosPolicy_; std::vector authApps_; int renderServiceGrpId_ = -1; int rsTid_ = -1; diff --git a/services/include/qos_interface.h b/services/include/qos_interface.h index 199e283d3db41fb58fb6de83b65ce664c291673e..ab7120f2ae4cc7dc54b0d6e54a8952a4e0189386 100644 --- a/services/include/qos_interface.h +++ b/services/include/qos_interface.h @@ -167,7 +167,7 @@ int QosApply(unsigned int level); int QosApplyForOther(unsigned int level, int tid); int QosLeave(void); int QosLeaveForOther(int tid); -int QosPolicy(const struct QosPolicyDatas *policyDatas); +int QosPolicySet(const struct QosPolicyDatas *policyDatas); #ifdef __cplusplus } diff --git a/services/include/qos_manager.h b/services/include/qos_policy.h similarity index 97% rename from services/include/qos_manager.h rename to services/include/qos_policy.h index a22fa42e7ac3bea77eb0b97f30d61084ea18599b..42824cbd8b63c951d572208a0c6e97ac20e0dc68 100644 --- a/services/include/qos_manager.h +++ b/services/include/qos_policy.h @@ -20,7 +20,7 @@ namespace OHOS { namespace ConcurrentTask { -class QosManager { +class QosPolicy { public: void Init(); int SetQosPolicy(struct QosPolicyDatas *policyDatas); diff --git a/services/src/concurrent_task_controller.cpp b/services/src/concurrent_task_controller.cpp index 5269e2e0933e297ac8a2063d54dafd517b3e3366..75939ed08d19f719785d9c53bee3732952a90563 100644 --- a/services/src/concurrent_task_controller.cpp +++ b/services/src/concurrent_task_controller.cpp @@ -197,7 +197,7 @@ void TaskController::Init() { SetSystemAuth(RS_UID, true); TypeMapInit(); - qosManager_.Init(); + qosPolicy_.Init(); TryCreateRsGroup(); } @@ -330,7 +330,6 @@ std::list::iterator TaskController::GetRecordOfUid(int uid) void TaskController::NewForeground(int uid, const Json::Value& payload) { int uiTid = 0; -#ifdef QOS_EXT_ENABLE try { uiTid = std::stoi(payload["pid"].asString()); } catch (...) { @@ -341,7 +340,6 @@ void TaskController::NewForeground(int uid, const Json::Value& payload) CONCUR_LOGE("uiTid error: %{public}d", uiTid); return; } -#endif auto it = find(authApps_.begin(), authApps_.end(), uid); if (it == authApps_.end()) { CONCUR_LOGI("un-authed uid %{public}d", uid); diff --git a/services/src/qos_interface.cpp b/services/src/qos_interface.cpp index b16bbd918ff6157b65a2a1ecbbbb06fd0f909a94..0e46ca6c6084b064154a0280c91999dea13c4cab 100644 --- a/services/src/qos_interface.cpp +++ b/services/src/qos_interface.cpp @@ -303,7 +303,7 @@ int QosLeaveForOther(int tid) return ret; } -int QosPolicy(const struct QosPolicyDatas *policyDatas) +int QosPolicySet(const struct QosPolicyDatas *policyDatas) { int fd; int ret; diff --git a/services/src/qos_manager.cpp b/services/src/qos_policy.cpp similarity index 95% rename from services/src/qos_manager.cpp rename to services/src/qos_policy.cpp index 31db399af762dd2cae4fbbb458db442aaa701fdf..f068fb785c815baa7c1fec47784785328d25c1fa 100644 --- a/services/src/qos_manager.cpp +++ b/services/src/qos_policy.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "qos_manager.h" +#include "qos_policy.h" #include #include "concurrent_task_log.h" @@ -92,12 +92,12 @@ static struct QosPolicyDatas g_systemServerQosPolicy = { namespace OHOS { namespace ConcurrentTask { -int QosManager::SetQosPolicy(struct QosPolicyDatas *policyDatas) +int QosPolicy::SetQosPolicy(struct QosPolicyDatas *policyDatas) { - return QosPolicy(policyDatas); + return QosPolicySet(policyDatas); } -void QosManager::Init() +void QosPolicy::Init() { int ret; diff --git a/test/BUILD.gn b/test/BUILD.gn index ab39237ff7cd0fb6bac7c9323e5ad1b50013f8c3..79785a9938c7444629a569a116eb897e9f2808fa 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -28,40 +28,14 @@ config("test_config") { "//third_party/jsoncpp/include/", "//foundation/resourceschedule/frame_aware_sched/common/include/", ] -} - -config("ffrt_test_config") { - include_dirs = [ - "//foundation/resourceschedule/resourceschedule_qos_manager/interfaces/inner_api/", - "//foundation/resourceschedule/resourceschedule_qos_manager/include", - ] cflags = [ "-Wno-unused-variable", "-Wno-unused-function", ] - defines = [ - "QOS_INTERVAL", - "QOS_DISPATCH", - "QOS_RTG", - "QOS_MULTI_RTG", - "QOS_RTG_RT", - "QOS_CHECKPOINT", - "QOS_SUBMIT", - "QOS_DEMO", - "ATRACE_MODE=0", # 0 is off, 5 is bytrace, 6 is pmu - "ATRACE_LEVEL=0", - "ATRACE_LOGI_ENABLE=0", - "ATRACE_LOGD_ENABLE=0", - "ATRACE_SCOPE_LOG_ENABLE=0", - "ATRACE_DURATION_LOG_ENABLE=0", - "FFRT_RELEASE", - "DISABLE_MONITOR", - ] - if (target_cpu == "arm64") { - defines += [ "ARM64_TEST" ] + defines = [ "ARM64_TEST" ] } } @@ -86,16 +60,13 @@ ohos_unittest("concurrent_svc_intf_test") { } subsystem_name = "resourceschedule" - part_name = "resourceschedule_qos_manager" + part_name = "qos_manager" } ohos_unittest("concurrent_task_client_test") { module_out_path = module_output_path - configs = [ - ":ffrt_test_config", - ":test_config", - ] + configs = [ ":test_config" ] sources = [ "unittest/phone/concurrent_task_client_test.cpp" ] deps = [ "../frameworks/concurrent_task_client:concurrent_task_client" ] @@ -110,16 +81,13 @@ ohos_unittest("concurrent_task_client_test") { ] subsystem_name = "resourceschedule" - part_name = "resourceschedule_qos_manager" + part_name = "qos_manager" } ohos_unittest("concurrent_task_controller_test") { module_out_path = module_output_path - configs = [ - ":ffrt_test_config", - ":test_config", - ] + configs = [ ":test_config" ] sources = [ "unittest/phone/concurrent_task_controller_test.cpp" ] deps = [ @@ -140,16 +108,13 @@ ohos_unittest("concurrent_task_controller_test") { } subsystem_name = "resourceschedule" - part_name = "resourceschedule_qos_manager" + part_name = "qos_manager" } ohos_unittest("concurrent_task_service_ability_test") { module_out_path = module_output_path - configs = [ - ":ffrt_test_config", - ":test_config", - ] + configs = [ ":test_config" ] sources = [ "unittest/phone/concurrent_task_service_ability_test.cpp" ] deps = [ @@ -168,16 +133,13 @@ ohos_unittest("concurrent_task_service_ability_test") { } subsystem_name = "resourceschedule" - part_name = "resourceschedule_qos_manager" + part_name = "qos_manager" } ohos_unittest("qos_interface_test") { module_out_path = module_output_path - configs = [ - ":ffrt_test_config", - ":test_config", - ] + configs = [ ":test_config" ] sources = [ "unittest/phone/qos_interface_test.cpp" ] deps = [ @@ -196,18 +158,15 @@ ohos_unittest("qos_interface_test") { } subsystem_name = "resourceschedule" - part_name = "resourceschedule_qos_manager" + part_name = "qos_manager" } -ohos_unittest("qos_manager_test") { +ohos_unittest("qos_policy_test") { module_out_path = module_output_path - configs = [ - ":ffrt_test_config", - ":test_config", - ] + configs = [ ":test_config" ] - sources = [ "unittest/phone/qos_manager_test.cpp" ] + sources = [ "unittest/phone/qos_policy_test.cpp" ] deps = [ "../frameworks/concurrent_task_client:concurrent_task_client", "../services:concurrentsvc", @@ -224,16 +183,13 @@ ohos_unittest("qos_manager_test") { } subsystem_name = "resourceschedule" - part_name = "resourceschedule_qos_manager" + part_name = "qos_manager" } ohos_unittest("concurrent_task_service_test") { module_out_path = module_output_path - configs = [ - ":ffrt_test_config", - ":test_config", - ] + configs = [ ":test_config" ] sources = [ "unittest/phone/concurrent_task_service_test.cpp" ] deps = [ @@ -252,7 +208,27 @@ ohos_unittest("concurrent_task_service_test") { } subsystem_name = "resourceschedule" - part_name = "resourceschedule_qos_manager" + part_name = "qos_manager" +} + +ohos_unittest("qos_test") { + module_out_path = module_output_path + + configs = [ ":test_config" ] + + sources = [ "unittest/phone/qos_test.cpp" ] + deps = [ "../qos:qos" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + + if (is_standard_system) { + public_deps = gtest_public_deps + } + + subsystem_name = "resourceschedule" + part_name = "qos_manager" } group("concurrent_unittest") { @@ -266,7 +242,8 @@ group("concurrent_unittest") { ":concurrent_task_service_ability_test", ":concurrent_task_service_test", ":qos_interface_test", - ":qos_manager_test", + ":qos_policy_test", + ":qos_test", ] } } diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7c547522659fb5e43b7ad40d0c770a84d6194af2 --- /dev/null +++ b/test/fuzztest/BUILD.gn @@ -0,0 +1,20 @@ +# 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. + +group("concurrent_fuzztest") { + testonly = true + deps = [ + # deps file + "concurrent_fuzzer:ConcurrentFuzzTest", + ] +} diff --git a/test/fuzztest/concurrent_fuzzer/BUILD.gn b/test/fuzztest/concurrent_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7f025a65d5070acd138943caa01bb2a92a55ad41 --- /dev/null +++ b/test/fuzztest/concurrent_fuzzer/BUILD.gn @@ -0,0 +1,42 @@ +# 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/config/features.gni") +import("//build/test.gni") + +ohos_fuzztest("ConcurrentFuzzTest") { + module_out_path = "qos_manager/concurrent_fuzz_test/" + fuzz_config_file = "../../../test/fuzztest/concurrent_fuzzer" + include_dirs = [ + "../../../include/", + "../../../interfaces/inner_api/", + "../../../frameworks/concurrent_task_client/include/", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "concurrent_fuzzer.cpp" ] + defines = [] + deps = [ + "../../../frameworks/concurrent_task_client:concurrent_task_client", + "../../../services:concurrentsvc", + ] + external_deps = [ + "c_utils:utils", + "ipc:ipc_single", + "samgr:samgr_proxy", + ] +} diff --git a/test/fuzztest/concurrent_fuzzer/concurrent_fuzzer.cpp b/test/fuzztest/concurrent_fuzzer/concurrent_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..efa1e79439a1b530002c3c71bc17c2dcdd13480b --- /dev/null +++ b/test/fuzztest/concurrent_fuzzer/concurrent_fuzzer.cpp @@ -0,0 +1,82 @@ +/* + * 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 +#include +#define private public +#include "concurrent_task_client.h" +#undef private +#include "concurrent_task_service_proxy.h" +#include "securec.h" +#include "concurrent_fuzzer.h" + +using namespace OHOS::ConcurrentTask; + +namespace OHOS { +bool FuzzConcurrentTaskTryConnect(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return false; + } + if (size < sizeof(int32_t)) { + return false; + } + return ConcurrentTaskClient::GetInstance().TryConnect() == ERR_OK; +} + +bool FuzzConcurrentTaskServiceReportData(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return false; + } + if (size < sizeof(int32_t)) { + return false; + } + + std::string name((const char*) data, size); + uint32_t resType = static_cast(*data); + int64_t value = static_cast(*data); + std::unordered_map payload; + payload["name"] = name; + OHOS::ConcurrentTask::ConcurrentTaskClient::GetInstance().ReportData(resType, value, payload); + return true; +} + +bool FuzzConcurrentTaskServiceQueryInterval(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return false; + } + if (size < sizeof(int32_t)) { + return false; + } + + std::string name((const char*) data, size); + int queryItem = static_cast(*data); + IntervalReply rs; + rs.rtgId = -1; + OHOS::ConcurrentTask::ConcurrentTaskClient::GetInstance().QueryInterval(queryItem, rs); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzConcurrentTaskTryConnect(data, size); + OHOS::FuzzConcurrentTaskServiceReportData(data, size); + OHOS::FuzzConcurrentTaskServiceQueryInterval(data, size); + return 0; +} diff --git a/test/fuzztest/concurrent_fuzzer/concurrent_fuzzer.h b/test/fuzztest/concurrent_fuzzer/concurrent_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..2108ad46bd9b3529bb47ba426f313daef20edc98 --- /dev/null +++ b/test/fuzztest/concurrent_fuzzer/concurrent_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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 CONCURRENT_FUZZER_H +#define CONCURRENT_FUZZER_H + +#define FUZZ_PROJECT_NAME "concurrent_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/concurrent_fuzzer/corpus/init b/test/fuzztest/concurrent_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/test/fuzztest/concurrent_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/concurrent_fuzzer/project.xml b/test/fuzztest/concurrent_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..d0eec29c4400ad75b28df69a9d2d783a170499bf --- /dev/null +++ b/test/fuzztest/concurrent_fuzzer/project.xml @@ -0,0 +1,24 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/unittest/phone/qos_interface_test.cpp b/test/unittest/phone/qos_interface_test.cpp index e5beabdd33dd70b31ce42b12aa7fa9f8eaa7ad0d..42a3b22b554e24010da51b420875dd689aba27c5 100644 --- a/test/unittest/phone/qos_interface_test.cpp +++ b/test/unittest/phone/qos_interface_test.cpp @@ -229,10 +229,10 @@ HWTEST_F(QosInterfaceTest, QosPolicyTest, TestSize.Level1) { int ret = -1; struct QosPolicyDatas *policyDatas = nullptr; - ret = QosPolicy(policyDatas); + ret = QosPolicySet(policyDatas); EXPECT_EQ(ret, -1); #if defined(ARM64_TEST) && ARM64_TEST - ret = QosPolicy(&g_defaultQosPolicy); + ret = QosPolicySet(&g_defaultQosPolicy); EXPECT_EQ(ret, 0); #endif } diff --git a/test/unittest/phone/qos_manager_test.cpp b/test/unittest/phone/qos_policy_test.cpp similarity index 77% rename from test/unittest/phone/qos_manager_test.cpp rename to test/unittest/phone/qos_policy_test.cpp index 7514ca7d31cf583dbdf4b89ade07fda4abc910e5..50a3c64b81ea7a81e749cd4fe33dd2f3879a676c 100644 --- a/test/unittest/phone/qos_manager_test.cpp +++ b/test/unittest/phone/qos_policy_test.cpp @@ -14,7 +14,7 @@ */ #include "gtest/gtest.h" -#include "qos_manager.h" +#include "qos_policy.h" namespace OHOS { namespace FFRT_TEST { @@ -25,7 +25,7 @@ using namespace ConcurrentTask; using namespace std; -class QosManagerTest : public testing::Test { +class QosPolicyTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); @@ -33,19 +33,19 @@ public: void TearDown(); }; -void QosManagerTest::SetUpTestCase() +void QosPolicyTest::SetUpTestCase() { } -void QosManagerTest::TearDownTestCase() +void QosPolicyTest::TearDownTestCase() { } -void QosManagerTest::SetUp() +void QosPolicyTest::SetUp() { } -void QosManagerTest::TearDown() +void QosPolicyTest::TearDown() { } @@ -54,10 +54,10 @@ void QosManagerTest::TearDown() * @tc.desc: Confirm the test binary can execute in root priv. * @tc.type: FUNC */ -HWTEST_F(QosManagerTest, TaskHandleTest, TestSize.Level1) +HWTEST_F(QosPolicyTest, TaskHandleTest, TestSize.Level1) { - QosManager qosManager; - qosManager.Init(); + QosPolicy qosPolicy; + qosPolicy.Init(); } } } \ No newline at end of file diff --git a/test/unittest/phone/qos_test.cpp b/test/unittest/phone/qos_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..451128c5590b75ffeb81198761b850dc01983fd3 --- /dev/null +++ b/test/unittest/phone/qos_test.cpp @@ -0,0 +1,96 @@ +/* + * 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 +#include +#include "gtest/gtest.h" +#include "qos.h" + +namespace OHOS { +namespace QOS { +using namespace testing; +using namespace testing::ext; +using namespace OHOS::QOS; + +class QosTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void QosTest::SetUpTestCase() +{ +} + +void QosTest::TearDownTestCase() +{ +} + +void QosTest::SetUp() +{ +} + +void QosTest::TearDown() +{ +} + +/** + * @tc.name: QosTest + * @tc.desc: Verify the Set and Reset QosLevel function. + * @tc.type: FUNC + */ +HWTEST_F(QosTest, 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(QosTest, SetThreadQosTest2, 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(QosTest, ResetThreadQosTest1, TestSize.Level1) +{ + int ret = SetThreadQos(QosLevel::QOS_USER_INITIATED); + EXPECT_EQ(ret, 0); + ret = ResetThreadQos(); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(QosTest, ResetThreadQosTest2, TestSize.Level1) +{ + int ret = SetQosForOtherThread(QosLevel::QOS_USER_INITIATED, gettid()); + EXPECT_EQ(ret, 0); + ret = ResetQosForOtherThread(gettid()); + EXPECT_EQ(ret, 0); +} +} // QOS +} // OHOS \ No newline at end of file