From 0dfb826fa42811883318dce621c97d06d288e4e5 Mon Sep 17 00:00:00 2001 From: zhoudail Date: Thu, 3 Apr 2025 15:49:21 +0800 Subject: [PATCH] qos manager idl Change-Id: Ie5b6ab192ca1a7fa08ed1e5f9f58144ff2cae506 Signed-off-by: zhoudail --- .vscode/settings.json | 57 ++++ frameworks/concurrent_task_client/BUILD.gn | 57 +++- .../ConcurrentTaskIdlTypes.idl} | 26 +- .../IConcurrentTaskService.idl} | 35 +- .../include/concurrent_task_service_proxy.h | 44 --- .../libconcurrent_task_client.versionscript | 21 ++ .../src/concurrent_task_client.cpp | 69 ++-- .../src/concurrent_task_service_proxy.cpp | 152 --------- frameworks/native/BUILD.gn | 1 - interfaces/inner_api/concurrent_task_client.h | 6 +- interfaces/inner_api/concurrent_task_type.h | 3 +- qos/BUILD.gn | 1 - services/BUILD.gn | 8 +- .../concurrent_task_controller_interface.h | 3 +- services/include/concurrent_task_service.h | 24 +- .../include/concurrent_task_service_stub.h | 48 --- services/src/concurrent_task_service.cpp | 75 ++++- services/src/concurrent_task_service_stub.cpp | 201 ----------- test/BUILD.gn | 5 +- test/fuzztest/BUILD.gn | 2 +- test/fuzztest/concurrent_fuzzer/BUILD.gn | 1 + .../concurrent_fuzzer/concurrent_fuzzer.cpp | 315 ++---------------- .../phone/concurrent_task_service_test.cpp | 114 ++++++- 23 files changed, 425 insertions(+), 843 deletions(-) create mode 100644 .vscode/settings.json rename frameworks/concurrent_task_client/{include/concurrent_task_service_ipc_interface_code.h => idl/ConcurrentTaskIdlTypes.idl} (54%) rename frameworks/concurrent_task_client/{include/iconcurrent_task_service.h => idl/IConcurrentTaskService.idl} (32%) delete mode 100644 frameworks/concurrent_task_client/include/concurrent_task_service_proxy.h create mode 100644 frameworks/concurrent_task_client/libconcurrent_task_client.versionscript delete mode 100644 frameworks/concurrent_task_client/src/concurrent_task_service_proxy.cpp delete mode 100644 services/include/concurrent_task_service_stub.h delete mode 100644 services/src/concurrent_task_service_stub.cpp diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d29bca9 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,57 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "cinttypes": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "map": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/frameworks/concurrent_task_client/BUILD.gn b/frameworks/concurrent_task_client/BUILD.gn index 25358c3..2af424e 100644 --- a/frameworks/concurrent_task_client/BUILD.gn +++ b/frameworks/concurrent_task_client/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2025 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 @@ -11,9 +11,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/idl_tool/idl.gni") import("//build/ohos.gni") import("//build/test.gni") +idl_gen_interface("qos_manager_interface") { + src_idl = rebase_path("./idl/IConcurrentTaskService.idl") + sources_common = [ "ConcurrentTaskIdlTypes.idl" ] +} + config("client_private_config") { cflags_cc = [ "-fexceptions" ] include_dirs = [ @@ -28,9 +34,41 @@ config("client_public_config") { include_dirs = [ "include", "../../interfaces/inner_api/", + "${target_gen_dir}", ] } +ohos_source_set("concurrent_task_idl") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + output_values = get_target_outputs(":qos_manager_interface") + sources = filter_include(output_values, [ "*_stub.cpp" ]) + sources += filter_include(output_values, [ "*_types.cpp" ]) + public_configs = [ ":client_public_config" ] + deps = [ ":qos_manager_interface" ] + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] + cflags_cc = [ + "-fomit-frame-pointer", + "-fdata-sections", + "-ffunction-sections", + "-fno-unroll-loops", + "-fno-exceptions", + "-fno-unwind-tables", + "-fno-asynchronous-unwind-tables", + "-g0", + "-Os", + ] + subsystem_name = "resourceschedule" + part_name = "qos_manager" +} + ohos_shared_library("concurrent_task_client") { branch_protector_ret = "pac_ret" configs = [ ":client_private_config" ] @@ -45,25 +83,30 @@ ohos_shared_library("concurrent_task_client") { "-fno-exceptions", "-fno-unwind-tables", "-fno-asynchronous-unwind-tables", - "-g0", "-Os", ] ldflags = [ "-Wl,--exclude-libs=ALL" ] - sources = [ - "src/concurrent_task_client.cpp", - "src/concurrent_task_service_proxy.cpp", - ] - public_external_deps = [ "jsoncpp:jsoncpp" ] + output_values = get_target_outputs(":qos_manager_interface") + + sources = [ "src/concurrent_task_client.cpp" ] + + sources += filter_include(output_values, [ "*_proxy.cpp" ]) + sources += filter_include(output_values, [ "*_types.cpp" ]) + + deps = [ ":qos_manager_interface" ] external_deps = [ "c_utils:utils", "hilog:libhilog", + "ipc:ipc_core", "ipc:ipc_single", + "jsoncpp:jsoncpp", "samgr:samgr_proxy", ] + version_script = "libconcurrent_task_client.versionscript" subsystem_name = "resourceschedule" part_name = "qos_manager" } diff --git a/frameworks/concurrent_task_client/include/concurrent_task_service_ipc_interface_code.h b/frameworks/concurrent_task_client/idl/ConcurrentTaskIdlTypes.idl similarity index 54% rename from frameworks/concurrent_task_client/include/concurrent_task_service_ipc_interface_code.h rename to frameworks/concurrent_task_client/idl/ConcurrentTaskIdlTypes.idl index 157a3ab..4e78823 100644 --- a/frameworks/concurrent_task_client/include/concurrent_task_service_ipc_interface_code.h +++ b/frameworks/concurrent_task_client/idl/ConcurrentTaskIdlTypes.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -13,20 +13,16 @@ * limitations under the License. */ -#ifndef CONCURRENT_TASK_SERVICES_IPC_INTERFACE_CODE_H -#define CONCURRENT_TASK_SERVICES_IPC_INTERFACE_CODE_H +package OHOS.ConcurrentTask; -/* SAID:1912 */ -namespace OHOS { -namespace ConcurrentTask { -enum class ConcurrentTaskInterfaceCode { - REPORT_DATA = 1, - QUERY_INTERVAL = 2, - QUERY_DEADLINE = 3, - REQUEST_AUTH = 4, - REPORT_SCENE_INFO = 5, +struct IpcIntervalReply { + int rtgId; + int tid; + int paramA; + int paramB; + String bundleName; }; -} // namespace ConcurrentTask -} // namespace OHOS -#endif // CONCURRENT_TASK_SERVICES_IPC_INTERFACE_CODE_H +struct IpcDeadlineReply { + boolean setStatus; +}; diff --git a/frameworks/concurrent_task_client/include/iconcurrent_task_service.h b/frameworks/concurrent_task_client/idl/IConcurrentTaskService.idl similarity index 32% rename from frameworks/concurrent_task_client/include/iconcurrent_task_service.h rename to frameworks/concurrent_task_client/idl/IConcurrentTaskService.idl index b133e2d..edc271b 100644 --- a/frameworks/concurrent_task_client/include/iconcurrent_task_service.h +++ b/frameworks/concurrent_task_client/idl/IConcurrentTaskService.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -13,27 +13,12 @@ * limitations under the License. */ -#ifndef CONCURRENT_TASK_SERVICES_INTERFACES_INNERKITS_CONCURRENT_TASK_CLIENT_INCLUDE_ICONCURRENT_TASK_SERVICE_H -#define CONCURRENT_TASK_SERVICES_INTERFACES_INNERKITS_CONCURRENT_TASK_CLIENT_INCLUDE_ICONCURRENT_TASK_SERVICE_H - -#include "iremote_broker.h" -#include "json/json.h" -#include "concurrent_task_type.h" - -/* SAID:1912 */ -namespace OHOS { -namespace ConcurrentTask { -class IConcurrentTaskService : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ResourceSchedule.ConcurrentTaskService"); - - virtual void ReportData(uint32_t resType, int64_t value, const Json::Value& payload) = 0; - virtual void ReportSceneInfo(uint32_t type, const Json::Value& payload) = 0; - virtual void QueryInterval(int queryItem, IntervalReply& queryRs) = 0; - virtual void QueryDeadline(int queryItem, DeadlineReply& ddlReply, const Json::Value& payload) = 0; - virtual void RequestAuth(const Json::Value& payload) = 0; -}; -} // namespace ConcurrentTask -} // namespace OHOS - -#endif // CONCURRENT_TASK_SERVICES_INTERFACES_INNERKITS_CONCURRENT_TASK_CLIENT_INCLUDE_ICONCURRENT_TASK_SERVICE_H + import ConcurrentTaskIdlTypes; + + interface OHOS.ConcurrentTask.IConcurrentTaskService { + [oneway] void ReportData([in] unsigned int resType, [in] long value, [in] Map payload); + [oneway] void ReportSceneInfo([in] unsigned int type, [in] Map payload); + void QueryInterval([in] int queryItem, [inout] IpcIntervalReply queryRs); + [oneway] void QueryDeadline([in] int queryItem, [in] IpcDeadlineReply ipcDdlReply, [in] Map payload); + void RequestAuth([in] Map payload); + } \ No newline at end of file diff --git a/frameworks/concurrent_task_client/include/concurrent_task_service_proxy.h b/frameworks/concurrent_task_client/include/concurrent_task_service_proxy.h deleted file mode 100644 index 57d1bf2..0000000 --- a/frameworks/concurrent_task_client/include/concurrent_task_service_proxy.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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. - */ - -#ifndef CONCUURENT_TASK_INTERFACES_INNERAPI_CONCURRENT_TASK_CLIENT_INCLUDE_CONCUURENT_TASK_SERVICE_PROXY_H -#define CONCUURENT_TASK_INTERFACES_INNERAPI_CONCURRENT_TASK_CLIENT_INCLUDE_CONCUURENT_TASK_SERVICE_PROXY_H - -#include "iremote_proxy.h" -#include "iremote_object.h" -#include "iconcurrent_task_service.h" -#include "concurrent_task_service_ipc_interface_code.h" - -namespace OHOS { -namespace ConcurrentTask { -class ConcurrentTaskServiceProxy : public IRemoteProxy { -public: - explicit ConcurrentTaskServiceProxy(const sptr& impl) : IRemoteProxy(impl) {} - virtual ~ConcurrentTaskServiceProxy() {} - - void ReportData(uint32_t resType, int64_t value, const Json::Value& payload) override; - void ReportSceneInfo(uint32_t type, const Json::Value& payload) override; - void QueryInterval(int queryItem, IntervalReply& queryRs) override; - void QueryDeadline(int queryItem, DeadlineReply& ddlReply, const Json::Value& payload) override; - void RequestAuth(const Json::Value& payload) override; - -private: - DISALLOW_COPY_AND_MOVE(ConcurrentTaskServiceProxy); - static inline BrokerDelegator delegator_; -}; -} // namespace ConcurrentTask -} // namespace OHOS - -#endif // CONCUURENT_TASK_INTERFACES_INNERAPI_CONCURRENT_TASK_CLIENT_INCLUDE_CONCUURENT_TASK_SERVICE_PROXY_H \ No newline at end of file diff --git a/frameworks/concurrent_task_client/libconcurrent_task_client.versionscript b/frameworks/concurrent_task_client/libconcurrent_task_client.versionscript new file mode 100644 index 0000000..591eb0e --- /dev/null +++ b/frameworks/concurrent_task_client/libconcurrent_task_client.versionscript @@ -0,0 +1,21 @@ +# Copyright (c) 2025 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. + +1.0 { + global: + extern "C++" { + OHOS::ConcurrentTask::ConcurrentTaskClient::*; + }; + local: + *; +}; \ No newline at end of file diff --git a/frameworks/concurrent_task_client/src/concurrent_task_client.cpp b/frameworks/concurrent_task_client/src/concurrent_task_client.cpp index e512ead..55ce58f 100644 --- a/frameworks/concurrent_task_client/src/concurrent_task_client.cpp +++ b/frameworks/concurrent_task_client/src/concurrent_task_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "concurrent_task_client.h" #include #include "if_system_ability_manager.h" @@ -19,9 +20,41 @@ #include "concurrent_task_log.h" #include "concurrent_task_errors.h" #include "system_ability_definition.h" +#include "iconcurrent_task_service.h" +#include "concurrent_task_idl_types.h" namespace OHOS { namespace ConcurrentTask { + +static IntervalReply IpcToQueryRs(const IpcIntervalReply& IpcQueryRs) +{ + IntervalReply queryRs; + queryRs.rtgId = IpcQueryRs.rtgId; + queryRs.tid = IpcQueryRs.tid; + queryRs.paramA = IpcQueryRs.paramA; + queryRs.paramB = IpcQueryRs.paramB; + queryRs.bundleName = IpcQueryRs.bundleName; + return queryRs; +} + +static IpcIntervalReply QueryRsToIpc(const IntervalReply& queryRs) +{ + IpcIntervalReply IpcQueryRs; + IpcQueryRs.rtgId = queryRs.rtgId; + IpcQueryRs.tid = queryRs.tid; + IpcQueryRs.paramA = queryRs.paramA; + IpcQueryRs.paramB = queryRs.paramB; + IpcQueryRs.bundleName = queryRs.bundleName; + return IpcQueryRs; +} + +static IpcDeadlineReply DdlReplyToIpc(const DeadlineReply& ddlreply) +{ + IpcDeadlineReply IpcDdlReply; + IpcDdlReply.setStatus = ddlreply.setStatus; + return IpcDdlReply; +} + ConcurrentTaskClient& ConcurrentTaskClient::GetInstance() { static ConcurrentTaskClient instance; @@ -36,11 +69,7 @@ void ConcurrentTaskClient::ReportData(uint32_t resType, int64_t value, if (TryConnect() != ERR_OK) { return; } - Json::Value payload; - for (auto it = mapPayload.begin(); it != mapPayload.end(); ++it) { - payload[it->first] = it->second; - } - clientService_->ReportData(resType, value, payload); + clientService_->ReportData(resType, value, mapPayload); } void ConcurrentTaskClient::ReportSceneInfo(uint32_t type, @@ -49,11 +78,7 @@ void ConcurrentTaskClient::ReportSceneInfo(uint32_t type, if (TryConnect() != ERR_OK) { return; } - Json::Value payload; - for (auto it = mapPayload.begin(); it != mapPayload.end(); ++it) { - payload[it->first] = it->second; - } - clientService_->ReportSceneInfo(type, payload); + clientService_->ReportSceneInfo(type, mapPayload); } void ConcurrentTaskClient::QueryInterval(int queryItem, IntervalReply& queryRs) @@ -62,7 +87,9 @@ void ConcurrentTaskClient::QueryInterval(int queryItem, IntervalReply& queryRs) CONCUR_LOGE("QueryInterval connnect fail"); return; } - clientService_->QueryInterval(queryItem, queryRs); + IpcIntervalReply IpcQueryRs = QueryRsToIpc(queryRs); + clientService_->QueryInterval(queryItem, IpcQueryRs); + queryRs = IpcToQueryRs(IpcQueryRs); return; } @@ -72,11 +99,12 @@ void ConcurrentTaskClient::QueryDeadline(int queryItem, DeadlineReply& ddlReply, if (TryConnect() != ERR_OK) { return; } - Json::Value payload; + std::unordered_map payload; for (auto it = mapPayload.begin(); it != mapPayload.end(); ++it) { payload[std::to_string(it->first)] = std::to_string(it->second); } - clientService_->QueryDeadline(queryItem, ddlReply, payload); + const IpcDeadlineReply& IpcDdlReply = DdlReplyToIpc(ddlReply); + clientService_->QueryDeadline(queryItem, IpcDdlReply, payload); return; } @@ -85,11 +113,7 @@ void ConcurrentTaskClient::RequestAuth(const std::unordered_mapfirst] = it->second; - } - clientService_->RequestAuth(payload); + clientService_->RequestAuth(mapPayload); return; } @@ -99,11 +123,8 @@ void ConcurrentTaskClient::QueryDeadline(int queryItem, DeadlineReply& ddlReply, if (TryConnect() != ERR_OK) { return; } - Json::Value payload; - for (auto it = mapPayload.begin(); it != mapPayload.end(); ++it) { - payload[it->first] = it->second; - } - clientService_->QueryDeadline(queryItem, ddlReply, payload); + const IpcDeadlineReply& IpcDdlReply = DdlReplyToIpc(ddlReply); + clientService_->QueryDeadline(queryItem, IpcDdlReply, mapPayload); return; } diff --git a/frameworks/concurrent_task_client/src/concurrent_task_service_proxy.cpp b/frameworks/concurrent_task_client/src/concurrent_task_service_proxy.cpp deleted file mode 100644 index a601473..0000000 --- a/frameworks/concurrent_task_client/src/concurrent_task_service_proxy.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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 "concurrent_task_service_proxy.h" -#include "concurrent_task_log.h" -#include "concurrent_task_errors.h" - -namespace OHOS { -namespace ConcurrentTask { -void ConcurrentTaskServiceProxy::ReportData(uint32_t resType, int64_t value, const Json::Value& payload) -{ - int32_t error; - MessageParcel data; - MessageParcel reply; - MessageOption option = { MessageOption::TF_ASYNC }; - if (!data.WriteInterfaceToken(ConcurrentTaskServiceProxy::GetDescriptor())) { - CONCUR_LOGE("Write interface token failed in ReportData Proxy"); - return; - } - if (!data.WriteUint32(resType) || !data.WriteInt64(value) || !data.WriteString(payload.toStyledString())) { - CONCUR_LOGE("Write info failed in ReportData Proxy"); - return; - } - uint32_t code = static_cast(ConcurrentTaskInterfaceCode::REPORT_DATA); - error = Remote()->SendRequest(code, data, reply, option); - if (error != NO_ERROR) { - CONCUR_LOGE("Send request error: %{public}d", error); - return; - } - CONCUR_LOGD("ConcurrentTaskServiceProxy::ReportData success."); -} - -void ConcurrentTaskServiceProxy::ReportSceneInfo(uint32_t type, const Json::Value& payload) -{ - int32_t error; - MessageParcel data; - MessageParcel reply; - MessageOption option = { MessageOption::TF_ASYNC }; - if (!data.WriteInterfaceToken(ConcurrentTaskServiceProxy::GetDescriptor())) { - CONCUR_LOGE("Write interface token failed in ReportSceneInfo Proxy"); - return; - } - if (!data.WriteUint32(type) || !data.WriteString(payload.toStyledString())) { - CONCUR_LOGE("Write info failed in ReportSceneInfo Proxy"); - return; - } - uint32_t code = static_cast(ConcurrentTaskInterfaceCode::REPORT_SCENE_INFO); - error = Remote()->SendRequest(code, data, reply, option); - if (error != NO_ERROR) { - CONCUR_LOGE("Send request error: %{public}d", error); - return; - } - CONCUR_LOGD("ConcurrentTaskServiceProxy::ReportSceneInfo success."); -} - -void ConcurrentTaskServiceProxy::QueryInterval(int queryItem, IntervalReply& queryRs) -{ - int32_t error; - MessageParcel data; - MessageParcel reply; - MessageOption option = { MessageOption::TF_SYNC }; - - if (!data.WriteInterfaceToken(ConcurrentTaskServiceProxy::GetDescriptor())) { - CONCUR_LOGE("Write interface token failed in QueryInterval Proxy"); - return; - } - if (!data.WriteInt32(queryItem) || !data.WriteInt32(queryRs.tid) || !data.WriteInt32(queryRs.paramA)) { - CONCUR_LOGE("Write info failed in QueryInterval Proxy"); - return; - } - - uint32_t code = static_cast(ConcurrentTaskInterfaceCode::QUERY_INTERVAL); - error = Remote()->SendRequest(code, data, reply, option); - if (error != NO_ERROR) { - CONCUR_LOGE("QueryInterval error: %{public}d", error); - return; - } - queryRs.rtgId = -1; - queryRs.tid = -1; - queryRs.paramA = -1; - queryRs.paramB = -1; - queryRs.bundleName = ""; - - if (!reply.ReadInt32(queryRs.rtgId) || !reply.ReadInt32(queryRs.tid) - || !reply.ReadInt32(queryRs.paramA) || !reply.ReadInt32(queryRs.paramB) - || !reply.ReadString(queryRs.bundleName)) { - CONCUR_LOGE("Read info failed in QueryInterval Proxy"); - return; - } - return; -} - -void ConcurrentTaskServiceProxy::QueryDeadline(int queryItem, DeadlineReply& ddlReply, const Json::Value& payload) -{ - int32_t error; - MessageParcel data; - MessageParcel reply; - MessageOption option = { MessageOption::TF_ASYNC }; - - if (!data.WriteInterfaceToken(ConcurrentTaskServiceProxy::GetDescriptor())) { - CONCUR_LOGE("Write interface token failed in QueryDeadline Proxy"); - return; - } - if (!data.WriteInt32(queryItem) || !data.WriteString(payload.toStyledString())) { - CONCUR_LOGE("Write info failed in QueryDeadline Proxy"); - return; - } - uint32_t code = static_cast(ConcurrentTaskInterfaceCode::QUERY_DEADLINE); - error = Remote()->SendRequest(code, data, reply, option); - if (error != NO_ERROR) { - CONCUR_LOGE("QueryDeadline error: %{public}d", error); - return; - } - CONCUR_LOGD("ConcurrentTaskServiceProxy::QueryDeadline success."); -} - -void ConcurrentTaskServiceProxy::RequestAuth(const Json::Value& payload) -{ - int32_t error; - MessageParcel data; - MessageParcel reply; - MessageOption option = { MessageOption::TF_SYNC }; - if (!data.WriteInterfaceToken(ConcurrentTaskServiceProxy::GetDescriptor())) { - CONCUR_LOGE("Write interface token failed in RequestAuth Proxy"); - return; - } - if (!data.WriteString(payload.toStyledString())) { - CONCUR_LOGE("Write info failed in RequestAuth Proxy"); - return; - } - uint32_t code = static_cast(ConcurrentTaskInterfaceCode::REQUEST_AUTH); - error = Remote()->SendRequest(code, data, reply, option); - if (error != NO_ERROR) { - CONCUR_LOGE("Send request error: %{public}d", error); - return; - } - CONCUR_LOGD("ConcurrentTaskServiceProxy::RequestAuth success."); -} -} // namespace ConcurrentTask -} // namespace OHOS diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn index 2c62418..a14c09e 100644 --- a/frameworks/native/BUILD.gn +++ b/frameworks/native/BUILD.gn @@ -25,7 +25,6 @@ ohos_shared_library("qos_ndk") { "-fno-exceptions", "-fno-unwind-tables", "-fno-asynchronous-unwind-tables", - "-g0", "-Os", ] include_dirs = [ diff --git a/interfaces/inner_api/concurrent_task_client.h b/interfaces/inner_api/concurrent_task_client.h index 76977fa..f56b85b 100644 --- a/interfaces/inner_api/concurrent_task_client.h +++ b/interfaces/inner_api/concurrent_task_client.h @@ -18,8 +18,7 @@ #include #include "iremote_object.h" -#include "iconcurrent_task_service.h" -#include "concurrent_task_service_ipc_interface_code.h" +#include namespace OHOS { namespace ConcurrentTask { @@ -28,7 +27,7 @@ namespace ConcurrentTask { * but through ConcurrentTaskClient, you don't need to get IConcurrentTaskService from samgr, * just use the functions is ok. */ - +class IConcurrentTaskService; class ConcurrentTaskClient { public: /** @@ -89,6 +88,7 @@ public: * @param mapPayload Indicates the context info of the auth request data. */ void RequestAuth(const std::unordered_map& mapPayload); + /** * @brief Stop remote object and reset ConcurrentTaskClient. */ diff --git a/interfaces/inner_api/concurrent_task_type.h b/interfaces/inner_api/concurrent_task_type.h index 0ea1a37..d543941 100644 --- a/interfaces/inner_api/concurrent_task_type.h +++ b/interfaces/inner_api/concurrent_task_type.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -43,6 +43,7 @@ enum MsgType { MSG_TYPE_MAX }; + enum PrioType { PRIO_RT = 0, RPIO_IN = 1, diff --git a/qos/BUILD.gn b/qos/BUILD.gn index 2e29882..63351cf 100644 --- a/qos/BUILD.gn +++ b/qos/BUILD.gn @@ -34,7 +34,6 @@ ohos_shared_library("qos") { "-fno-exceptions", "-fno-unwind-tables", "-fno-asynchronous-unwind-tables", - "-g0", "-Os", ] public_configs = [ ":qos_config" ] diff --git a/services/BUILD.gn b/services/BUILD.gn index 5cb3d24..e673091 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2025 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 @@ -57,13 +57,15 @@ ohos_shared_library("concurrentsvc") { "src/concurrent_task_controller_interface.cpp", "src/concurrent_task_service.cpp", "src/concurrent_task_service_ability.cpp", - "src/concurrent_task_service_stub.cpp", "src/func_loader.cpp", "src/qos_interface.cpp", "src/qos_policy.cpp", ] - deps = [ "../etc/param:ffrt_etc" ] + deps = [ + "../etc/param:ffrt_etc", + "../frameworks/concurrent_task_client/:concurrent_task_idl", + ] if (defined( global_parts_info.hmosresourceschedule_frame_aware_sched_override)) { diff --git a/services/include/concurrent_task_controller_interface.h b/services/include/concurrent_task_controller_interface.h index 4462b32..97ee36e 100644 --- a/services/include/concurrent_task_controller_interface.h +++ b/services/include/concurrent_task_controller_interface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -22,6 +22,7 @@ #include "json/value.h" #include "concurrent_task_type.h" +#include "concurrent_task_idl_types.h" #include "func_loader.h" #include "qos_policy.h" diff --git a/services/include/concurrent_task_service.h b/services/include/concurrent_task_service.h index 957340c..8208978 100644 --- a/services/include/concurrent_task_service.h +++ b/services/include/concurrent_task_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -16,8 +16,11 @@ #ifndef CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_SEVICE_H #define CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_SEVICE_H +#include +#include "json/json.h" +#include "concurrent_task_type.h" +#include "concurrent_task_idl_types.h" #include "concurrent_task_service_stub.h" -#include "concurrent_task_log.h" namespace OHOS { namespace ConcurrentTask { @@ -26,11 +29,18 @@ public: ConcurrentTaskService() {} ~ConcurrentTaskService() override = default; - void ReportData(uint32_t resType, int64_t value, const Json::Value& payload) override; - void ReportSceneInfo(uint32_t type, const Json::Value& payload) override; - void QueryInterval(int queryItem, IntervalReply& queryRs) override; - void QueryDeadline(int queryItem, DeadlineReply& ddlReply, const Json::Value& payload) override; - void RequestAuth(const Json::Value& payload) override; + ErrCode ReportData(uint32_t resType, int64_t value, + const std::unordered_map& payload) override; + ErrCode ReportSceneInfo(uint32_t type, const std::unordered_map& payload) override; + ErrCode QueryInterval(int queryItem, IpcIntervalReply& IpcQueryRs) override; + ErrCode QueryDeadline(int queryItem, const IpcDeadlineReply& IpcDdlReply, + const std::unordered_map& payload) override; + ErrCode RequestAuth(const std::unordered_map& payload) override; + + Json::Value MapToJson(const std::unordered_map& dataMap); + IntervalReply IpcToQueryRs(const IpcIntervalReply& IpcToQueryRs); + IpcIntervalReply QueryRsToIpc(const IntervalReply& queryRs); + DeadlineReply IpcToDdlReply(const IpcDeadlineReply& IpcDdlReply); private: DISALLOW_COPY_AND_MOVE(ConcurrentTaskService); }; diff --git a/services/include/concurrent_task_service_stub.h b/services/include/concurrent_task_service_stub.h deleted file mode 100644 index 0a7ea6b..0000000 --- a/services/include/concurrent_task_service_stub.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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. - */ - -#ifndef CONCURRENT_TASK_SEVICES_INCLUDE_CONCURRENT_TASK_SERVICE_STUB_H -#define CONCURRENT_TASK_SEVICES_INCLUDE_CONCURRENT_TASK_SERVICE_STUB_H - -#include -#include "iremote_stub.h" -#include "iconcurrent_task_service.h" -#include "concurrent_task_service_ipc_interface_code.h" - -namespace OHOS { -namespace ConcurrentTask { -class ConcurrentTaskServiceStub : public IRemoteStub { -public: - ConcurrentTaskServiceStub(); - ~ConcurrentTaskServiceStub(); - int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - int32_t ReportDataInner(MessageParcel& data, MessageParcel& reply); - int32_t ReportSceneInfoInner(MessageParcel& data, MessageParcel& reply); - int32_t QueryIntervalInner(MessageParcel& data, MessageParcel& reply); - int32_t QueryDeadlineInner(MessageParcel& data, MessageParcel& reply); - int32_t RequestAuthInner(MessageParcel& data, MessageParcel& reply); - Json::Value StringToJson(const std::string& str); - - void Init(); - - using RequestFuncType = std::function; - std::map funcMap_; -}; -} // namespace ConcurrentTask -} // namespace OHOS - -#endif // CONCURRENT_TASK_SEVICES_INCLUDE_CONCURRENT_TASK_SERVICE_STUB_H diff --git a/services/src/concurrent_task_service.cpp b/services/src/concurrent_task_service.cpp index a90c7c1..ef9aa4e 100644 --- a/services/src/concurrent_task_service.cpp +++ b/services/src/concurrent_task_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -14,35 +14,88 @@ */ #include "concurrent_task_service.h" - +#include "concurrent_task_log.h" #include "concurrent_task_controller_interface.h" namespace OHOS { namespace ConcurrentTask { -void ConcurrentTaskService::ReportData(uint32_t resType, int64_t value, const Json::Value& payload) + +ErrCode ConcurrentTaskService::ReportData( + uint32_t resType, int64_t value, const std::unordered_map& payload) { - TaskControllerInterface::GetInstance().ReportData(resType, value, payload); + Json::Value payloadData = MapToJson(payload); + TaskControllerInterface::GetInstance().ReportData(resType, value, payloadData); + return ERR_OK; } -void ConcurrentTaskService::ReportSceneInfo(uint32_t type, const Json::Value& payload) +ErrCode ConcurrentTaskService::ReportSceneInfo( + uint32_t type, const std::unordered_map& payload) { - TaskControllerInterface::GetInstance().ReportSceneInfo(type, payload); + Json::Value payloadData = MapToJson(payload); + TaskControllerInterface::GetInstance().ReportSceneInfo(type, payloadData); + return ERR_OK; } -void ConcurrentTaskService::QueryInterval(int queryItem, IntervalReply& queryRs) +ErrCode ConcurrentTaskService::QueryInterval(int queryItem, IpcIntervalReply& IpcQueryRs) { + IntervalReply queryRs = IpcToQueryRs(IpcQueryRs); TaskControllerInterface::GetInstance().QueryInterval(queryItem, queryRs); + IpcQueryRs = QueryRsToIpc(queryRs); + return ERR_OK; } -void ConcurrentTaskService::QueryDeadline(int queryItem, DeadlineReply& queryRs, const Json::Value& payload) +ErrCode ConcurrentTaskService::QueryDeadline( + int queryItem, const IpcDeadlineReply& IpcDdlReply, const std::unordered_map& payload) { - TaskControllerInterface::GetInstance().QueryDeadline(queryItem, queryRs, payload); + Json::Value payloadData = MapToJson(payload); + DeadlineReply queryRs = IpcToDdlReply(IpcDdlReply); + TaskControllerInterface::GetInstance().QueryDeadline(queryItem, queryRs, payloadData); + return ERR_OK; } -void ConcurrentTaskService::RequestAuth(const Json::Value& payload) +ErrCode ConcurrentTaskService::RequestAuth(const std::unordered_map& payload) { - TaskControllerInterface::GetInstance().RequestAuth(payload); + Json::Value payloadData = MapToJson(payload); + TaskControllerInterface::GetInstance().RequestAuth(payloadData); + return ERR_OK; } +Json::Value ConcurrentTaskService::MapToJson(const std::unordered_map& dataMap) +{ + Json::Value root; + for (const auto& pair : dataMap) { + root[pair.first] = pair.second; + } + return root; +} + +IntervalReply ConcurrentTaskService::IpcToQueryRs(const IpcIntervalReply& IpcQueryRs) +{ + IntervalReply queryRs; + queryRs.rtgId = IpcQueryRs.rtgId; + queryRs.tid = IpcQueryRs.tid; + queryRs.paramA = IpcQueryRs.paramA; + queryRs.paramB = IpcQueryRs.paramB; + queryRs.bundleName = IpcQueryRs.bundleName; + return queryRs; +} + +IpcIntervalReply ConcurrentTaskService::QueryRsToIpc(const IntervalReply& queryRs) +{ + IpcIntervalReply IpcQueryRs; + IpcQueryRs.rtgId = queryRs.rtgId; + IpcQueryRs.tid = queryRs.tid; + IpcQueryRs.paramA = queryRs.paramA; + IpcQueryRs.paramB = queryRs.paramB; + IpcQueryRs.bundleName = queryRs.bundleName; + return IpcQueryRs; +} + +DeadlineReply ConcurrentTaskService::IpcToDdlReply(const IpcDeadlineReply& IpcDdlReply) +{ + DeadlineReply ddlReply; + ddlReply.setStatus = IpcDdlReply.setStatus; + return ddlReply; +} } // namespace ConcurrentTask } // namespace OHOS diff --git a/services/src/concurrent_task_service_stub.cpp b/services/src/concurrent_task_service_stub.cpp deleted file mode 100644 index dbdd533..0000000 --- a/services/src/concurrent_task_service_stub.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* - * 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 "concurrent_task_service_stub.h" -#include "concurrent_task_log.h" -#include "concurrent_task_errors.h" -#include "string_ex.h" -#include "ipc_skeleton.h" - -namespace OHOS { -namespace ConcurrentTask { -namespace { - bool IsValidToken(MessageParcel& data) - { - std::u16string descriptor = ConcurrentTaskServiceStub::GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - return descriptor == remoteDescriptor; - } -} - -ConcurrentTaskServiceStub::ConcurrentTaskServiceStub() -{ - Init(); -} - -ConcurrentTaskServiceStub::~ConcurrentTaskServiceStub() -{ - funcMap_.clear(); -} - -int32_t ConcurrentTaskServiceStub::ReportDataInner(MessageParcel& data, [[maybe_unused]] MessageParcel& reply) -{ - if (!IsValidToken(data)) { - return ERR_CONCURRENT_TASK_PARCEL_ERROR; - } - - uint32_t type = 0; - int64_t value = 0; - std::string payload; - if (!data.ReadUint32(type) || !data.ReadInt64(value) || !data.ReadString(payload)) { - CONCUR_LOGE("Read info failed in ReportData Stub"); - return IPC_STUB_ERR; - } - if (payload.empty()) { - return ERR_OK; - } - ReportData(type, value, StringToJson(payload)); - return ERR_OK; -} - -int32_t ConcurrentTaskServiceStub::ReportSceneInfoInner(MessageParcel& data, [[maybe_unused]] MessageParcel& reply) -{ - if (!IsValidToken(data)) { - return ERR_CONCURRENT_TASK_PARCEL_ERROR; - } - - uint32_t type = 0; - std::string payload; - if (!data.ReadUint32(type) || !data.ReadString(payload)) { - CONCUR_LOGE("Read info failed in ReportSceneInfoInner Stub"); - return IPC_STUB_ERR; - } - if (payload.empty()) { - return ERR_OK; - } - ReportSceneInfo(type, StringToJson(payload)); - return ERR_OK; -} - -int32_t ConcurrentTaskServiceStub::QueryIntervalInner(MessageParcel& data, [[maybe_unused]] MessageParcel& reply) -{ - if (!IsValidToken(data)) { - return ERR_CONCURRENT_TASK_PARCEL_ERROR; - } - int item; - IntervalReply queryRs; - queryRs.rtgId = -1; - queryRs.tid = -1; - queryRs.paramA = -1; - queryRs.paramB = -1; - if (!data.ReadInt32(item) || !data.ReadInt32(queryRs.tid) || !data.ReadInt32(queryRs.paramA)) { - CONCUR_LOGE("Read info failed in QueryInterval Stub"); - return IPC_STUB_ERR; - } - QueryInterval(item, queryRs); - if (!reply.WriteInt32(queryRs.rtgId) || !reply.WriteInt32(queryRs.tid) - || !reply.WriteInt32(queryRs.paramA) || !reply.WriteInt32(queryRs.paramB) - || !reply.WriteString(queryRs.bundleName)) { - CONCUR_LOGE("Write info failed in QueryInterval Stub"); - return IPC_STUB_ERR; - } - return ERR_OK; -} - -int32_t ConcurrentTaskServiceStub::QueryDeadlineInner(MessageParcel& data, [[maybe_unused]] MessageParcel& reply) -{ - if (!IsValidToken(data)) { - return ERR_CONCURRENT_TASK_PARCEL_ERROR; - } - int queryItem; - DeadlineReply ddlReply; - std::string payload; - if (!data.ReadInt32(queryItem) || !data.ReadString(payload)) { - CONCUR_LOGE("Read info failed in QueryDeadline Stub"); - return IPC_STUB_ERR; - } - if (payload.empty()) { - return ERR_OK; - } - QueryDeadline(queryItem, ddlReply, StringToJson(payload)); - return ERR_OK; -} - -int32_t ConcurrentTaskServiceStub::RequestAuthInner(MessageParcel& data, [[maybe_unused]] MessageParcel& reply) -{ - if (!IsValidToken(data)) { - return ERR_CONCURRENT_TASK_PARCEL_ERROR; - } - - std::string payload; - if (!data.ReadString(payload)) { - CONCUR_LOGE("Read info failed in RequestAuth Stub"); - return IPC_STUB_ERR; - } - if (payload.empty()) { - return ERR_OK; - } - RequestAuth(StringToJson(payload)); - return ERR_OK; -} - -int32_t ConcurrentTaskServiceStub::OnRemoteRequest(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - auto uid = IPCSkeleton::GetCallingUid(); - auto pid = IPCSkeleton::GetCallingPid(); - CONCUR_LOGD("ConcurrentTaskServiceStub::OnRemoteRequest, code = %{public}u, flags = %{public}d," - " uid = %{public}d pid = %{public}d", code, option.GetFlags(), uid, pid); - - auto itFunc = funcMap_.find(code); - if (itFunc != funcMap_.end()) { - auto requestFunc = itFunc->second; - if (requestFunc) { - return requestFunc(data, reply); - } - } - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); -} - -Json::Value ConcurrentTaskServiceStub::StringToJson(const std::string& payload) -{ - bool res; - Json::CharReaderBuilder readerBuilder; - JSONCPP_STRING errs; - std::unique_ptr const jsonReader(readerBuilder.newCharReader()); - Json::Value root; - if (!IsAsciiString(payload)) { - CONCUR_LOGE("Payload is not ascii string"); - return root; - } - try { - res = jsonReader->parse(payload.c_str(), payload.c_str() + payload.length(), &root, &errs); - } catch (...) { - CONCUR_LOGE("Unexpected json parse"); - return root; - } - if (!res || !errs.empty()) { - CONCUR_LOGE("ConcurentTaskServiceStub::payload = %{public}s Incorrect JSON format ", payload.c_str()); - } - return root; -} - -void ConcurrentTaskServiceStub::Init() -{ - funcMap_ = { - { static_cast(ConcurrentTaskInterfaceCode::REPORT_DATA), - [this](auto& data, auto& reply) {return ReportDataInner(data, reply); } }, - { static_cast(ConcurrentTaskInterfaceCode::REPORT_SCENE_INFO), - [this](auto& data, auto& reply) {return ReportSceneInfoInner(data, reply); } }, - { static_cast(ConcurrentTaskInterfaceCode::QUERY_INTERVAL), - [this](auto& data, auto& reply) {return QueryIntervalInner(data, reply); } }, - { static_cast(ConcurrentTaskInterfaceCode::QUERY_DEADLINE), - [this](auto& data, auto& reply) {return QueryDeadlineInner(data, reply); } }, - { static_cast(ConcurrentTaskInterfaceCode::REQUEST_AUTH), - [this](auto& data, auto& reply) {return RequestAuthInner(data, reply); } }, - }; -} -} // namespace ResourceSchedule -} // namespace OHOS diff --git a/test/BUILD.gn b/test/BUILD.gn index d55e7ec..70496db 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022 Huawei Device Co., Ltd. +# Copyright (C) 2022-2025 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 @@ -157,6 +157,7 @@ ohos_unittest("concurrent_task_service_ability_test") { "c_utils:utils", "frame_aware_sched:rtg_interface", "hilog:libhilog", + "jsoncpp:jsoncpp", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] @@ -229,12 +230,14 @@ ohos_unittest("concurrent_task_service_test") { sources = [ "unittest/phone/concurrent_task_service_test.cpp" ] deps = [ "../frameworks/concurrent_task_client:concurrent_task_client", + "../frameworks/concurrent_task_client/:concurrent_task_idl", "../services:concurrentsvc", ] external_deps = [ "c_utils:utils", "frame_aware_sched:rtg_interface", "hilog:libhilog", + "jsoncpp:jsoncpp", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 7c54752..c325574 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2025 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 diff --git a/test/fuzztest/concurrent_fuzzer/BUILD.gn b/test/fuzztest/concurrent_fuzzer/BUILD.gn index adcf0ff..12d46cc 100644 --- a/test/fuzztest/concurrent_fuzzer/BUILD.gn +++ b/test/fuzztest/concurrent_fuzzer/BUILD.gn @@ -46,5 +46,6 @@ ohos_fuzztest("ConcurrentFuzzTest") { "ipc:ipc_single", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "jsoncpp:jsoncpp", ] } diff --git a/test/fuzztest/concurrent_fuzzer/concurrent_fuzzer.cpp b/test/fuzztest/concurrent_fuzzer/concurrent_fuzzer.cpp index d8178de..8b79a00 100644 --- a/test/fuzztest/concurrent_fuzzer/concurrent_fuzzer.cpp +++ b/test/fuzztest/concurrent_fuzzer/concurrent_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 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 @@ -19,17 +19,12 @@ #include "concurrent_task_service_ability.h" #include "concurrent_task_controller_interface.h" #undef private -#include "concurrent_task_service_proxy.h" #include "concurrent_task_service.h" -#include "concurrent_task_service_stub.h" -#include "iservice_registry.h" #include "securec.h" #include "qos.h" #include "qos_interface.h" #include "qos_policy.h" -#include "concurrent_task_client.h" #include "system_ability_definition.h" -#include "concurrent_fuzzer.h" using namespace OHOS::ConcurrentTask; using namespace OHOS::QOS; @@ -41,22 +36,6 @@ size_t g_baseFuzzPos; #define QUADRUPLE 4 #define LEN 4 -class ConcurrentTaskServiceStubFuzer : public ConcurrentTaskServiceStub { -public: - ConcurrentTaskServiceStubFuzer() = default; - virtual ~ConcurrentTaskServiceStubFuzer() = default; - void ReportData(uint32_t resType, int64_t value, const Json::Value& payload) override - {} - void ReportSceneInfo(uint32_t type, const Json::Value& payload) override - {} - void QueryInterval(int queryItem, IntervalReply& queryRs) override - {} - void QueryDeadline(int queryItem, DeadlineReply& ddlReply, const Json::Value& payload) override - {} - void RequestAuth(const Json::Value& payload) override - {} -}; - namespace { constexpr int TEST_DATA_FIRST = 1; constexpr int TEST_DATA_SECOND = 2; @@ -68,6 +47,7 @@ namespace { constexpr int TEST_DATA_EIGHTH = 8; constexpr int TEST_DATA_TENTH = 10; } + template T GetData() { T object{}; @@ -83,17 +63,6 @@ template T GetData() return object; } -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) { g_baseFuzzData = data; @@ -111,7 +80,7 @@ bool FuzzConcurrentTaskServiceReportData(const uint8_t* data, size_t size) data1.ReadRawData(size1); MessageParcel reply; MessageOption option; - uint32_t code = static_cast(ConcurrentTaskInterfaceCode::REPORT_DATA); + uint32_t code = static_cast(IConcurrentTaskServiceIpcCode::COMMAND_REPORT_DATA); ConcurrentTaskService s = ConcurrentTaskService(); s.OnRemoteRequest(code, data1, reply, option); } @@ -135,7 +104,7 @@ bool FuzzConcurrentTaskServiceReportSceneInfo(const uint8_t* data, size_t size) data1.ReadRawData(size1); MessageParcel reply; MessageOption option; - uint32_t code = static_cast(ConcurrentTaskInterfaceCode::REPORT_SCENE_INFO); + uint32_t code = static_cast(IConcurrentTaskServiceIpcCode::COMMAND_REPORT_SCENE_INFO); ConcurrentTaskService s = ConcurrentTaskService(); s.OnRemoteRequest(code, data1, reply, option); } @@ -159,7 +128,7 @@ bool FuzzConcurrentTaskServiceQueryInterval(const uint8_t* data, size_t size) data1.ReadRawData(size1); MessageParcel reply; MessageOption option; - uint32_t code = static_cast(ConcurrentTaskInterfaceCode::QUERY_INTERVAL); + uint32_t code = static_cast(IConcurrentTaskServiceIpcCode::COMMAND_QUERY_INTERVAL); ConcurrentTaskService s = ConcurrentTaskService(); s.OnRemoteRequest(code, data1, reply, option); } @@ -183,7 +152,7 @@ bool FuzzConcurrentTaskServiceQueryDeadline(const uint8_t* data, size_t size) data1.ReadRawData(size1); MessageParcel reply; MessageOption option; - uint32_t code = static_cast(ConcurrentTaskInterfaceCode::QUERY_DEADLINE); + uint32_t code = static_cast(IConcurrentTaskServiceIpcCode::COMMAND_QUERY_DEADLINE); ConcurrentTaskService s = ConcurrentTaskService(); s.OnRemoteRequest(code, data1, reply, option); } @@ -207,7 +176,7 @@ bool FuzzConcurrentTaskServiceRequestAuth(const uint8_t* data, size_t size) data1.ReadRawData(size1); MessageParcel reply; MessageOption option; - uint32_t code = static_cast(ConcurrentTaskInterfaceCode::REQUEST_AUTH); + uint32_t code = static_cast(IConcurrentTaskServiceIpcCode::COMMAND_REQUEST_AUTH); ConcurrentTaskService s = ConcurrentTaskService(); s.OnRemoteRequest(code, data1, reply, option); } @@ -392,145 +361,32 @@ bool FuzzConcurrentTaskServiceAbilityOnRemoveSystemAbility(const uint8_t* data, return true; } -bool FuzzConcurrentTaskServiceStubReportData(const uint8_t* data, size_t size) +bool FuzzConcurrentTaskClientReportData(const uint8_t* data, size_t size) { g_baseFuzzData = data; g_baseFuzzSize = size; g_baseFuzzPos = 0; - if (size > sizeof(uint32_t) + sizeof(int64_t) + sizeof(uint32_t) + sizeof(uint32_t)) { - ConcurrentTaskService s = ConcurrentTaskService(); + if (size > sizeof(int) + sizeof(pid_t) + sizeof(uint32_t)) { uint32_t resType = GetData(); int64_t value = GetData(); - Json::Value jsValue; - jsValue["1111"] = std::to_string(GetData()); - jsValue["2222"] = std::to_string(GetData()); - s.ReportData(resType, value, jsValue); + std::unordered_map mapPayload; + mapPayload["218211"] = std::to_string(GetData()); + ConcurrentTaskClient::GetInstance().ReportData(resType, value, mapPayload); } return true; } -bool FuzzConcurrentTaskServiceStubReportSceneInfo(const uint8_t* data, size_t size) +bool FuzzConcurrentTaskClientReportSceneInfo(const uint8_t* data, size_t size) { g_baseFuzzData = data; g_baseFuzzSize = size; g_baseFuzzPos = 0; - if (size > sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t)) { - ConcurrentTaskService s = ConcurrentTaskService(); + if (size > sizeof(int) + sizeof(pid_t) + sizeof(uint32_t)) { uint32_t type = GetData(); - Json::Value jsValue; - jsValue["1111"] = std::to_string(GetData()); - jsValue["2222"] = std::to_string(GetData()); - s.ReportSceneInfo(type, jsValue); - } - return true; -} - -bool FuzzConcurrentTaskServiceStubQueryInterval(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > sizeof(int) + sizeof(int)) { - ConcurrentTaskService s = ConcurrentTaskService(); - int queryItem = GetData(); - queryItem = queryItem % (QURRY_TYPE_MAX + 1); - IntervalReply queryRs; - s.QueryInterval(queryItem, queryRs); - } - return true; -} - -bool FuzzConcurrentTaskServiceStubQueryDeadline(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > sizeof(int) + sizeof(int) + sizeof(int)) { - int deadlineType = GetData(); - deadlineType = deadlineType % (MSG_GAME + 1); - DeadlineReply queryRs; - Json::Value jsValue; - jsValue["2123"] = std::to_string(GetData()); - jsValue["2333"] = std::to_string(GetData()); - ConcurrentTaskService s = ConcurrentTaskService(); - s.QueryDeadline(deadlineType, queryRs, jsValue); - } - return true; -} - -bool FuzzConcurrentTaskServiceStubRequestAuth(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > sizeof(int) + sizeof(int)) { - Json::Value payload; - payload["2187"] = std::to_string(GetData()); - payload["2376"] = std::to_string(GetData()); - ConcurrentTaskService s = ConcurrentTaskService(); - s.RequestAuth(payload); - } - return true; -} - -bool FuzzConcurrentTaskServiceStubQueryDeadlineInner(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - MessageParcel data4; - int32_t intData; - data4.WriteInterfaceToken(ConcurrentTaskServiceStub::GetDescriptor()); - if (size >= sizeof(int32_t)) { - const char *str2; - intData = GetData(); - str2 = reinterpret_cast(data + g_baseFuzzPos); - size_t size1 = (size - g_baseFuzzPos) > LEN ? LEN : (size - g_baseFuzzPos); - std::string str(str2, size1); - data4.WriteInt32(intData); - data4.WriteString(str); - } else if (size > 0) { - intData = GetData(); - data4.WriteInt32(intData); - } - - MessageParcel reply; - ConcurrentTaskServiceStubFuzer s = ConcurrentTaskServiceStubFuzer(); - s.QueryDeadlineInner(data4, reply); - return true; -} - -bool FuzzConcurrentTaskServiceStubRequestAuthInner(const uint8_t* data, size_t size) -{ - if (data == nullptr) { - return false; - } - - MessageParcel data3; - data3.WriteInterfaceToken(ConcurrentTaskServiceStub::GetDescriptor()); - if (size >= sizeof(int)) { - const char *data1 = reinterpret_cast(data); - size_t size1 = size > LEN ? LEN : size; - std::string str1(data1, size1); - data3.WriteString(str1); - } else if (size == 0) { - std::string str1 = ""; - data3.WriteString(str1); + std::unordered_map mapPayload; + mapPayload["218222"] = std::to_string(GetData()); + ConcurrentTaskClient::GetInstance().ReportSceneInfo(type, mapPayload); } - - MessageParcel reply; - ConcurrentTaskServiceStubFuzer s = ConcurrentTaskServiceStubFuzer(); - s.RequestAuthInner(data3, reply); - return true; -} - -bool FuzzConcurrentTaskServiceStringToJson(const uint8_t* data, size_t size) -{ - const char *data1 = reinterpret_cast(data); - size_t size1 = size > LEN ? LEN : size; - std::string str(data1, size1); - ConcurrentTaskServiceStubFuzer s = ConcurrentTaskServiceStubFuzer(); - s.StringToJson(str); return true; } @@ -580,15 +436,6 @@ bool FuzzConcurrentTaskClinetRequestAuth(const uint8_t* data, size_t size) return true; } -bool FuzzConcurrentTaskClientTryConnect(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - ConcurrentTaskClient::GetInstance().TryConnect(); - return true; -} - bool FuzzConcurrentTaskClientStopRemoteObject(const uint8_t* data, size_t size) { g_baseFuzzData = data; @@ -598,107 +445,6 @@ bool FuzzConcurrentTaskClientStopRemoteObject(const uint8_t* data, size_t size) return true; } -bool FuzzConcurrentTaskServiceProxyReportData(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size >= sizeof(uint32_t) + sizeof(int64_t) + sizeof(int32_t)) { - uint32_t intdata1 = GetData(); - int64_t intdata2 = GetData(); - Json::Value payload; - payload["2123"] = std::to_string(GetData()); - sptr systemAbilityManager = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = systemAbilityManager->GetSystemAbility(CONCURRENT_TASK_SERVICE_ID); - ConcurrentTaskServiceProxy s = ConcurrentTaskServiceProxy(remoteObject); - s.ReportData(intdata1, intdata2, payload); - } - return true; -} - -bool FuzzConcurrentTaskServiceProxyReportSceneInfo(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size >= sizeof(uint32_t) + sizeof(int32_t)) { - uint32_t intdata1 = GetData(); - Json::Value payload; - payload["2123"] = std::to_string(GetData()); - sptr systemAbilityManager = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = systemAbilityManager->GetSystemAbility(CONCURRENT_TASK_SERVICE_ID); - ConcurrentTaskServiceProxy s = ConcurrentTaskServiceProxy(remoteObject); - s.ReportSceneInfo(intdata1, payload); - } - return true; -} - -bool FuzzConcurrentTaskServiceProxyQueryInterval(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - IntervalReply queryRs; - queryRs.rtgId = -1; - queryRs.paramA = -1; - queryRs.paramB = -1; - sptr systemAbilityManager = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = systemAbilityManager->GetSystemAbility(CONCURRENT_TASK_SERVICE_ID); - if (size >= sizeof(int) + sizeof(int)) { - int intdata1 = GetData(); - queryRs.tid = GetData(); - ConcurrentTaskServiceProxy s = ConcurrentTaskServiceProxy(remoteObject); - s.QueryInterval(intdata1, queryRs); - } else if (size >= sizeof(int)) { - int queryItem = 12345; - queryRs.tid = GetData(); - ConcurrentTaskServiceProxy s = ConcurrentTaskServiceProxy(remoteObject); - s.QueryInterval(queryItem, queryRs); - } - return true; -} - -bool FuzzConcurrentTaskServiceProxyQueryDeadline(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size >= sizeof(int) + sizeof(int)) { - int queryItem = GetData(); - queryItem = queryItem % (QURRY_TYPE_MAX + 1); - DeadlineReply ddlReply; - Json::Value payload; - payload["2147"] = std::to_string(GetData()); - sptr systemAbilityManager = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = systemAbilityManager->GetSystemAbility(CONCURRENT_TASK_SERVICE_ID); - ConcurrentTaskServiceProxy s = ConcurrentTaskServiceProxy(remoteObject); - s.QueryDeadline(queryItem, ddlReply, payload); - } - return true; -} - -bool FuzzConcurrentTaskServiceProxyRequestAuth(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size >= sizeof(int)) { - Json::Value payload; - payload["2147"] = std::to_string(GetData()); - sptr systemAbilityManager = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = systemAbilityManager->GetSystemAbility(CONCURRENT_TASK_SERVICE_ID); - ConcurrentTaskServiceProxy s = ConcurrentTaskServiceProxy(remoteObject); - s.RequestAuth(payload); - } - return true; -} - - bool FuzzConcurrentTaskControllerInterfaceReportData(const uint8_t* data, size_t size) { g_baseFuzzData = data; @@ -813,42 +559,33 @@ static void TaskControllerFuzzTestSuit(const uint8_t *data, size_t size) 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::FuzzConcurrentTaskServiceReportSceneInfo(data, size); - OHOS::FuzzConcurrentTaskServiceRequestAuth(data, size); OHOS::FuzzConcurrentTaskServiceQueryInterval(data, size); + OHOS::FuzzConcurrentTaskServiceRequestAuth(data, size); + OHOS::FuzzConcurrentTaskServiceQueryDeadline(data, size); + OHOS::FuzzConcurrentTaskServiceStopRemoteObject(data, size); OHOS::FuzzConcurrentTaskServiceSetThreadQos(data, size); OHOS::FuzzConcurrentTaskServiceSetQosForOtherThread(data, size); OHOS::FuzzConcurrentTaskServiceResetThreadQos(data, size); OHOS::FuzzConcurrentTaskServiceResetQosForOtherThread(data, size); - OHOS::FuzzConcurrentTaskServiceQueryDeadline(data, size); + OHOS::FuzzQosPolicyInit(data, size); OHOS::FuzzQosInterfaceEnableRtg(data, size); OHOS::FuzzQosInterfaceQosLeave(data, size); - OHOS::FuzzConcurrentTaskServiceStubReportData(data, size); - OHOS::FuzzConcurrentTaskServiceStubReportSceneInfo(data, size); - OHOS::FuzzConcurrentTaskServiceStubQueryInterval(data, size); - OHOS::FuzzConcurrentTaskServiceStubQueryDeadline(data, size); - OHOS::FuzzConcurrentTaskServiceStubRequestAuth(data, size); + OHOS::FuzzConcurrentTaskServiceAbilityOnStart(data, size); OHOS::FuzzConcurrentTaskServiceAbilityOnStop(data, size); OHOS::FuzzConcurrentTaskServiceAbilityOnAddSystemAbility(data, size); OHOS::FuzzConcurrentTaskServiceAbilityOnRemoveSystemAbility(data, size); - OHOS::FuzzConcurrentTaskServiceStubQueryDeadlineInner(data, size); - OHOS::FuzzConcurrentTaskServiceStubRequestAuthInner(data, size); - OHOS::FuzzConcurrentTaskServiceStringToJson(data, size); + + OHOS::FuzzConcurrentTaskClientReportData(data, size); + OHOS::FuzzConcurrentTaskClientReportSceneInfo(data, size); OHOS::FuzzConcurrentTaskClientQueryInterval(data, size); - OHOS::FuzzConcurrentTaskServiceStubQueryDeadline(data, size); OHOS::FuzzConcurrentTaskClinetRequestAuth(data, size); - OHOS::FuzzConcurrentTaskClientTryConnect(data, size); OHOS::FuzzConcurrentTaskClientStopRemoteObject(data, size); - OHOS::FuzzConcurrentTaskServiceProxyReportData(data, size); - OHOS::FuzzConcurrentTaskServiceProxyReportSceneInfo(data, size); - OHOS::FuzzConcurrentTaskServiceProxyQueryInterval(data, size); - OHOS::FuzzConcurrentTaskServiceProxyQueryDeadline(data, size); - OHOS::FuzzConcurrentTaskServiceProxyRequestAuth(data, size); + TaskControllerFuzzTestSuit(data, size); return 0; } diff --git a/test/unittest/phone/concurrent_task_service_test.cpp b/test/unittest/phone/concurrent_task_service_test.cpp index 7ab7053..e9f5cb2 100644 --- a/test/unittest/phone/concurrent_task_service_test.cpp +++ b/test/unittest/phone/concurrent_task_service_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -15,6 +15,7 @@ #include "gtest/gtest.h" #include "concurrent_task_service.h" +#include "json/json.h" namespace OHOS { namespace FFRT_TEST { @@ -55,10 +56,10 @@ void ConcurrentTaskServiceTest::TearDown() HWTEST_F(ConcurrentTaskServiceTest, QueryIntervalTest, TestSize.Level1) { int queryItem = 0; - IntervalReply queryRs = {87, 657, 357, 214}; + IpcIntervalReply IpcQueryRs = {87, 657, 357, 214}; ConcurrentTaskService queInt; - queInt.QueryInterval(queryItem, queryRs); - EXPECT_NE(queryRs.tid, -1); + queInt.QueryInterval(queryItem, IpcQueryRs); + EXPECT_NE(IpcQueryRs.tid, -1); } /** @@ -69,13 +70,110 @@ HWTEST_F(ConcurrentTaskServiceTest, QueryIntervalTest, TestSize.Level1) HWTEST_F(ConcurrentTaskServiceTest, QueryDeadlineTest, TestSize.Level1) { int queryItem = 0; - DeadlineReply ddlReply = { false }; - Json::Value payload; + IpcDeadlineReply IpcDdlReply = { false }; + std::unordered_map payload; payload["1111"] = "60"; payload["2222"] = "90"; ConcurrentTaskService queInt; - queInt.QueryDeadline(queryItem, ddlReply, payload); + queInt.QueryDeadline(queryItem, IpcDdlReply, payload); EXPECT_FALSE(payload.empty()); } + +/** + * @tc.name: MapToJsonTest + * @tc.desc: Test MapToJson function with a non-empty and empty map + * @tc.type: FUNC + */ +HWTEST_F(ConcurrentTaskServiceTest, MapToJsonTest, TestSize.Level1) +{ + ConcurrentTaskService service; + + std::unordered_map dataMap = {{"key1", "value1"}, {"key2", "value2"}, {"key3", "value3"}}; + Json::Value expectedJson; + expectedJson["key1"] = "value1"; + expectedJson["key2"] = "value2"; + expectedJson["key3"] = "value3"; + Json::Value resultJson = service.MapToJson(dataMap); + EXPECT_EQ(expectedJson, resultJson); + + std::unordered_map dataMap2; + Json::Value expectedJson2; + Json::Value resultJson2 = service.MapToJson(dataMap2); + EXPECT_EQ(expectedJson2, resultJson2); +} + +/** + * @tc.name: IpcToQueryRsTest + * @tc.desc: Test whether the IpcToQueryRsTest interface are normal. + * @tc.type: FUNC + */ +HWTEST_F(ConcurrentTaskServiceTest, IpcToQueryRsTest, TestSize.Level1) +{ + IpcIntervalReply ipcQueryRs; + ipcQueryRs.rtgId = 1; + ipcQueryRs.tid = 2; + ipcQueryRs.paramA = 3; + ipcQueryRs.paramB = 3; + ipcQueryRs.bundleName = "testBundle"; + + IntervalReply expectedQueryRs; + expectedQueryRs.rtgId = 1; + expectedQueryRs.tid = 2; + expectedQueryRs.paramA = 3; + expectedQueryRs.paramB = 3; + expectedQueryRs.bundleName = "testBundle"; + + ConcurrentTaskService service; + IntervalReply actualQueryRs = service.IpcToQueryRs(ipcQueryRs); + + EXPECT_EQ(expectedQueryRs.rtgId, actualQueryRs.rtgId); + EXPECT_EQ(expectedQueryRs.tid, actualQueryRs.tid); + EXPECT_EQ(expectedQueryRs.paramA, actualQueryRs.paramA); + EXPECT_EQ(expectedQueryRs.paramB, actualQueryRs.paramB); + EXPECT_EQ(expectedQueryRs.bundleName, actualQueryRs.bundleName); +} + +/** + * @tc.name: QueryRsToIpcTest + * @tc.desc: Test whether the QueryRsToIpcTest interface are normal. + * @tc.type: FUNC + */ +HWTEST_F(ConcurrentTaskServiceTest, QueryRsToIpcTest, TestSize.Level1) +{ + IntervalReply queryRs; + queryRs.rtgId = 1; + queryRs.tid = 2; + queryRs.paramA = 3; + queryRs.paramB = 3; + queryRs.bundleName = "mockedBundleName"; + + ConcurrentTaskService service; + IpcIntervalReply actualIpcQueryRs = service.QueryRsToIpc(queryRs); + + EXPECT_EQ(actualIpcQueryRs.rtgId, queryRs.rtgId); + EXPECT_EQ(actualIpcQueryRs.tid, queryRs.tid); + EXPECT_EQ(actualIpcQueryRs.paramA, queryRs.paramA); + EXPECT_EQ(actualIpcQueryRs.paramB, queryRs.paramB); + EXPECT_EQ(actualIpcQueryRs.bundleName, queryRs.bundleName); +} + +/** + * @tc.name: IpcToDdlReplyTest + * @tc.desc: Test whether the IpcToDdlReplyTest interface are normal. + * @tc.type: FUNC + */ +HWTEST_F(ConcurrentTaskServiceTest, IpcToDdlReplyTest, TestSize.Level1) +{ + IpcDeadlineReply IpcDdlReply; + IpcDdlReply.setStatus = 123; + + DeadlineReply expectedDdlReply; + expectedDdlReply.setStatus = IpcDdlReply.setStatus; + + ConcurrentTaskService service; + DeadlineReply resultDdlReply = service.IpcToDdlReply(IpcDdlReply); + + EXPECT_EQ(expectedDdlReply.setStatus, resultDdlReply.setStatus); } -} \ No newline at end of file +} // namespace FFRT_TEST +} // namespace OHOS \ No newline at end of file -- Gitee