!11 新增服务client端和server端、inner_api与测试用例代码

Merge pull request !11 from edwardcaoyue/master
This commit is contained in:
openharmony_ci
2023-06-14 07:20:41 +00:00
committed by Gitee
30 changed files with 3503 additions and 1 deletions
+18 -1
View File
@@ -37,7 +37,24 @@
},
"build": {
"sub_component": [
"//foundation/resourceschedule/qos_manager/etc/init:concurrent_task_service.cfg"
"//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"
],
"inner_kits": [
{
"header": {
"header_base": "//foundation/resourceschedule/qos_manager/interfaces/inner_api/",
"header_files": [
"concurrent_task_client.h"
]
},
"name": "//foundation/resourceschedule/qos_manager/frameworks/concurrent_task_client:concurrent_task_client"
}
],
"test": [
"//foundation/resourceschedule/qos_manager/test:concurrent_unittest"
]
}
}
@@ -0,0 +1,62 @@
# 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.
import("//build/ohos.gni")
import("//build/test.gni")
config("client_private_config") {
cflags_cc = [ "-fexceptions" ]
include_dirs = [
"./include",
"../../include",
"../../services/include",
"../../interfaces/inner_api/",
"//commonlibrary/c_utils/base/include",
"//utils/system/safwk/native/include",
"//third_party/jsoncpp/include",
]
}
config("client_public_config") {
visibility = [":*"]
cflags = [ "-fstack-protector-strong" ]
include_dirs = [ "include" ]
}
ohos_shared_library("concurrent_task_client") {
configs = [
":client_private_config",
]
public_configs = [ ":client_public_config" ]
sources = [
"src/concurrent_task_client.cpp",
"src/concurrent_task_service_proxy.cpp",
]
deps = [
"//third_party/jsoncpp:jsoncpp",
]
external_deps = [
"c_utils:utils",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_single",
"samgr:samgr_proxy",
]
subsystem_name = "resourceschedule"
part_name = "qos_manager"
}
@@ -0,0 +1,43 @@
/*
* 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_SERVICE_INTERFACES_INNERAPI_CONCURRENT_TASK_CLIENT_INCLUDE_CONCURRENT_TASK_ERRORS_H
#define CONCURRENT_TASK_SERVICE_INTERFACES_INNERAPI_CONCURRENT_TASK_CLIENT_INCLUDE_CONCURRENT_TASK_ERRORS_H
#include "errors.h"
namespace OHOS {
namespace ConcurrentTask {
enum {
CONCURRENT_TASK_MODULE_COMMON = 0x00,
CONCURRENT_TASK_MODULE_SERVICE = 0x01,
};
constexpr ErrCode CONCURRENT_TASK_COMMON_ERR_OFFSET = ErrCodeOffset(SUBSYS_IAWARE, CONCURRENT_TASK_MODULE_COMMON);
enum {
ERR_CONCURRENT_TASK_INVALID_PARAM = CONCURRENT_TASK_COMMON_ERR_OFFSET + 1,
GET_CONCURRENT_TASK_SERVICE_FAILED,
};
constexpr ErrCode CONCURRENT_TASK_SERVICE_ERR_OFFSET = ErrCodeOffset(SUBSYS_IAWARE, CONCURRENT_TASK_MODULE_SERVICE);
enum {
ERR_CONCURRENT_TASK_PARCEL_ERROR = CONCURRENT_TASK_SERVICE_ERR_OFFSET + 1,
ERR_CONCURRENT_TASK_PERMISSION_DENIED,
ERR_CONCURRENT_TASK_WRITE_FILE_FAILED,
};
} // namespace ConcurrentTask
} // namespace OHOS
#endif // CONCURRENT_TASK_SERVICE_INTERFACES_INNERAPI_CONCURRENT_TASK_CLIENT_INCLUDE_CONCURRENT_TASK_ERRORS_H
@@ -0,0 +1,40 @@
/*
* 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"
namespace OHOS {
namespace ConcurrentTask {
class ConcurrentTaskServiceProxy : public IRemoteProxy<IConcurrentTaskService> {
public:
explicit ConcurrentTaskServiceProxy(const sptr<IRemoteObject>& impl) : IRemoteProxy<IConcurrentTaskService>(impl) {}
virtual ~ConcurrentTaskServiceProxy() {}
void ReportData(uint32_t resType, int64_t value, const Json::Value& payload) override;
void QueryInterval(int queryItem, IntervalReply& queryRs) override;
private:
DISALLOW_COPY_AND_MOVE(ConcurrentTaskServiceProxy);
static inline BrokerDelegator<ConcurrentTaskServiceProxy> delegator_;
};
} // namespace ConcurrentTask
} // namespace OHOS
#endif // CONCUURENT_TASK_INTERFACES_INNERAPI_CONCURRENT_TASK_CLIENT_INCLUDE_CONCUURENT_TASK_SERVICE_PROXY_H
@@ -0,0 +1,58 @@
/*
* 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_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_TYPE_H
#define CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_TYPE_H
namespace OHOS {
namespace ConcurrentTask {
constexpr int MAX_KEY_THREADS = 5;
enum MsgType {
MSG_FOREGROUND = 0,
MSG_BACKGROUND,
MSG_APP_START,
MSG_APP_KILLED,
MSG_FOCUS,
MSG_SYSTEM_MAX,
MSG_APP_START_TYPE = 100,
MSG_REG_RENDER = MSG_APP_START_TYPE,
MSG_REG_UI,
MSG_REG_KEY_THERAD,
MSG_TYPE_MAX
};
enum PrioType {
PRIO_RT = 0,
RPIO_IN = 1,
PRIO_NORMAL = 2,
};
enum QueryIntervalItem {
QUERY_UI = 0,
QUERY_RENDER = 1,
QUERY_RENDER_SERVICE = 2,
QUERY_COMPOSER = 3,
QURRY_TYPE_MAX
};
struct IntervalReply {
int rtgId;
int paramA;
int paramB;
int paramC;
};
}
}
#endif // CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_TYPE_H
@@ -0,0 +1,40 @@
/*
* 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_INTERFACES_INNERAPI_CONCURRENT_TASK_CLIENT_INCLUDE_ICONCURRENT_TASK_SERVICE_H
#define CONCURRENT_TASK_SEVICES_INTERFACES_INNERAPI_CONCURRENT_TASK_CLIENT_INCLUDE_ICONCURRENT_TASK_SERVICE_H
#include "iremote_broker.h"
#include "json/json.h"
#include "concurrent_task_type.h"
namespace OHOS {
namespace ConcurrentTask {
class IConcurrentTaskService : public IRemoteBroker {
public:
enum : uint32_t {
REPORT_DATA = 1,
QUERY_INTERVAL = 2,
};
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ResourceSchedule.ConcurrentTaskService");
virtual void ReportData(uint32_t resType, int64_t value, const Json::Value& payload) = 0;
virtual void QueryInterval(int queryItem, IntervalReply& queryRs) = 0;
};
} // namespace ConcurrentTask
} // namespace OHOS
#endif // CONCURRENT_TASK_SEVICES_INTERFACES_INNERAPI_CONCURRENT_TASK_CLIENT_INCLUDE_ICONCURRENT_TASK_SERVICE_H
@@ -0,0 +1,110 @@
/*
* 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_client.h"
#include <cinttypes>
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "concurrent_task_log.h"
#include "concurrent_task_errors.h"
#include "system_ability_definition.h"
namespace OHOS {
namespace ConcurrentTask {
ConcurrentTaskClient& ConcurrentTaskClient::GetInstance()
{
static ConcurrentTaskClient instance;
return instance;
}
void ConcurrentTaskClient::ReportData(uint32_t resType, int64_t value,
const std::unordered_map<std::string, std::string>& mapPayload)
{
CONCUR_LOGD("ConcurrentTaskClient::ReportData receive resType = %{public}u, value = %{public}" PRId64 ".",
resType, 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);
}
void ConcurrentTaskClient::QueryInterval(int queryItem, IntervalReply& queryRs)
{
if (TryConnect() != ERR_OK) {
CONCUR_LOGE("QueryInterval connnect fail");
return;
}
clientService_->QueryInterval(queryItem, queryRs);
return;
}
ErrCode ConcurrentTaskClient::TryConnect()
{
std::lock_guard<std::mutex> lock(mutex_);
if (clientService_) {
return ERR_OK;
}
sptr<ISystemAbilityManager> systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (!systemManager) {
CONCUR_LOGE("ConcurrentTaskClient::Fail to get registry.");
return GET_CONCURRENT_TASK_SERVICE_FAILED;
}
remoteObject_ = systemManager->GetSystemAbility(CONCURRENT_TASK_SERVICE_ID);
if (!remoteObject_) {
CONCUR_LOGE("ConcurrentTaskClient::Fail to connect concurrent task schedule service.");
return GET_CONCURRENT_TASK_SERVICE_FAILED;
}
clientService_ = iface_cast<IConcurrentTaskService>(remoteObject_);
if (!clientService_) {
return GET_CONCURRENT_TASK_SERVICE_FAILED;
}
try {
recipient_ = new ConcurrentTaskDeathRecipient(*this);
} catch (const std::bad_alloc& e) {
CONCUR_LOGE("ConcurrentTaskClient::New ConcurrentTaskDeathRecipient fail.");
}
if (!recipient_) {
return GET_CONCURRENT_TASK_SERVICE_FAILED;
}
clientService_->AsObject()->AddDeathRecipient(recipient_);
CONCUR_LOGD("ConcurrentTaskClient::Connect concurrent task service success.");
return ERR_OK;
}
void ConcurrentTaskClient::StopRemoteObject()
{
if (clientService_ && clientService_->AsObject()) {
clientService_->AsObject()->RemoveDeathRecipient(recipient_);
}
clientService_ = nullptr;
}
ConcurrentTaskClient::ConcurrentTaskDeathRecipient::ConcurrentTaskDeathRecipient(
ConcurrentTaskClient& concurrentTaskClient) : concurrentTaskClient_(concurrentTaskClient) {}
ConcurrentTaskClient::ConcurrentTaskDeathRecipient::~ConcurrentTaskDeathRecipient() {}
void ConcurrentTaskClient::ConcurrentTaskDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& object)
{
concurrentTaskClient_.StopRemoteObject();
}
} // namespace ConcurrentTask
} // namespace OHOS
@@ -0,0 +1,84 @@
/*
* 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())) {
return;
}
if (!data.WriteUint32(resType)) {
return;
}
if (!data.WriteInt64(value)) {
return;
}
if (!data.WriteString(payload.toStyledString())) {
return;
}
error = Remote()->SendRequest(IConcurrentTaskService::REPORT_DATA, data, reply, option);
if (error != NO_ERROR) {
CONCUR_LOGE("Send request error: %{public}d", error);
return;
}
CONCUR_LOGD("ConcurrentTaskServiceProxy::ReportData success.");
}
void ConcurrentTaskServiceProxy::QueryInterval(int queryItem, IntervalReply& queryRs)
{
int32_t error;
MessageParcel data;
MessageParcel reply;
MessageOption option = { MessageOption::TF_SYNC };
queryRs.rtgId = -1;
queryRs.paramA = -1;
queryRs.paramB = -1;
queryRs.paramC = -1;
if (!data.WriteInterfaceToken(ConcurrentTaskServiceProxy::GetDescriptor())) {
return;
}
if (!data.WriteInt64(queryItem)) {
return;
}
error = Remote()->SendRequest(IConcurrentTaskService::QUERY_INTERVAL, data, reply, option);
if (error != NO_ERROR) {
CONCUR_LOGE("QueryInterval error: %{public}d", error);
return;
}
if (!reply.ReadInt32(queryRs.rtgId)) {
return;
}
if (!reply.ReadInt32(queryRs.paramA)) {
return;
}
if (!reply.ReadInt32(queryRs.paramB)) {
return;
}
if (!reply.ReadInt32(queryRs.paramC)) {
return;
}
return;
}
} // namespace ConcurrentTask
} // namespace OHOS
@@ -0,0 +1,89 @@
/*
* 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_SERVICE_INTERFACES_INNERAPI_CONCURRENT_TASK_CLIENT_INCLUDE_CONCURRENT_TASK_CLIENT_H
#define CONCURRENT_TASK_SERVICE_INTERFACES_INNERAPI_CONCURRENT_TASK_CLIENT_INCLUDE_CONCURRENT_TASK_CLIENT_H
#include <unordered_map>
#include "iremote_object.h"
#include "iconcurrent_task_service.h"
namespace OHOS {
namespace ConcurrentTask {
/*
* this class wrapped the functions of IConcurrentTaskService,effect is the same.
* but through ConcurrentTaskClient, you don't need to get IConcurrentTaskService from samgr,
* just use the functions is ok.
*/
class ConcurrentTaskClient {
public:
/**
* @brief Only need one client connect to ConcurrentTaskService, singleton pattern.
*
* @return Returns the only one implement of ConcurrentTaskClient.
*/
static ConcurrentTaskClient& GetInstance();
/**
* @brief Report scene data to the concurrent task service through inter-process communication.
*
* @param resType Indicates the resource type, default is 0.
* @param value Indicates the uid of module of report scene module.
* @param mapPayload Indicates the context info of the scene data.
*/
void ReportData(uint32_t resType, int64_t value, const std::unordered_map<std::string, std::string>& mapPayload);
/**
* @brief Query rtg id and other info provided by concurrent task service.
*
* @param queryItem Information of the corresponding query module.
* @param queryRs Indicates the context info of the query message.
*/
void QueryInterval(int queryItem, IntervalReply& queryRs);
/**
* @brief Stop remote object and reset ConcurrentTaskClient.
*/
void StopRemoteObject();
protected:
ConcurrentTaskClient() = default;
virtual ~ConcurrentTaskClient() = default;
private:
class ConcurrentTaskDeathRecipient : public IRemoteObject::DeathRecipient {
public:
explicit ConcurrentTaskDeathRecipient(ConcurrentTaskClient& concurrentTaskClient);
~ConcurrentTaskDeathRecipient() override;
void OnRemoteDied(const wptr<IRemoteObject>& object) override;
private:
ConcurrentTaskClient& concurrentTaskClient_;
};
ErrCode TryConnect();
std::mutex mutex_;
sptr<ConcurrentTaskDeathRecipient> recipient_;
sptr<IRemoteObject> remoteObject_;
sptr<IConcurrentTaskService> clientService_;
DISALLOW_COPY_AND_MOVE(ConcurrentTaskClient);
};
} // namespace ConcurrentTask
} // namespace OHOS
#endif // CONCURRENT_TASK_SERVICE_INTERFACES_INNERAPI_ConcurrentTask_CLIENT_INCLUDE_CONCURRENT_TASK_CLIENT_H
+64
View File
@@ -0,0 +1,64 @@
# 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.
import("//build/ohos.gni")
config("concurrent_task_config") {
visibility = [":*"]
cflags_cc = [ "-fexceptions" ]
include_dirs = [
"include",
"../include",
"../frameworks/concurrent_task_client/include/",
"../interfaces/inner_api/",
"//foundation/resourceschedule/frame_aware_sched/common/include/",
"//utils/system/safwk/native/include",
"//commonlibrary/c_utils/base/include",
"//third_party/libxml2/include",
"//third_party/jsoncpp/include",
]
}
ohos_shared_library("concurrentsvc") {
public_configs = [
":concurrent_task_config",
]
sources = [
"src/concurrent_task_service.cpp",
"src/concurrent_task_service_ability.cpp",
"src/concurrent_task_service_stub.cpp",
"src/concurrent_task_controller.cpp",
"src/qos_interface.cpp",
"src/qos_manager.cpp",
]
deps = [
"//foundation/resourceschedule/frame_aware_sched/interfaces/innerkits/frameintf:rtg_interface",
"//third_party/jsoncpp:jsoncpp",
"//third_party/libxml2:xml2",
]
external_deps = [
"c_utils:utils",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_single",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
subsystem_name = "resourceschedule"
part_name = "qos_manager"
}
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_CONTROLLER_H
#define CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_CONTROLLER_H
#include <unordered_set>
#include <list>
#include <mutex>
#include <unordered_map>
#include <vector>
#include "json/json.h"
#include "concurrent_task_type.h"
#include "qos_manager.h"
namespace OHOS {
namespace ConcurrentTask {
class ForegroundAppRecord;
class TaskController {
public:
static TaskController& GetInstance();
TaskController() = default;
virtual ~TaskController() = default;
void ReportData(uint32_t resType, int64_t value, const Json::Value& payload);
void QueryInterval(int queryItem, IntervalReply& queryRs);
void Init();
void Release();
private:
bool CheckUid(pid_t uid);
void TypeMapInit();
void QosApplyInit();
void SetHwcAuth(bool status);
void TryCreateRsGroup();
void QueryUi(pid_t uid, IntervalReply& queryRs);
void QueryRender(pid_t uid, IntervalReply& queryRs);
void QueryRenderService(pid_t uid, IntervalReply& queryRs);
void QueryHwc(pid_t uid, IntervalReply& queryRs);
int GetRequestType(std::string strRequstType);
void DealSystemRequest(int requestType, const Json::Value& payload);
void DealAppRequest(int requestType, const Json::Value& payload, pid_t uid);
void NewForeground(int uid);
void NewBackground(int uid);
void NewAppStart(int uid);
void AppKilled(int uid);
std::list<ForegroundAppRecord>::iterator GetRecordOfUid(int uid);
void PrintInfo();
std::mutex appInfoLock_;
std::list<ForegroundAppRecord> foregroundApp_ = {};
std::unordered_map<std::string, int> msgType_ = {};
QosManager qosManager_;
std::vector<int> authApps_;
int renderServiceGrpId_ = -1;
bool rtgEnabled_ = false;
};
class ForegroundAppRecord {
public:
explicit ForegroundAppRecord(int uid);
~ForegroundAppRecord();
void AddKeyThread(int tid, int prio = PRIO_NORMAL);
bool BeginScene();
bool EndScene();
int GetUid();
int GetGrpId();
bool IsValid();
void PrintKeyThreads();
private:
int uid_ = 0;
int grpId_ = 0;
std::unordered_set<int> keyThreads_;
};
} // namespace ConcurrentTask
} // namespace OHOS
#endif // CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_CONTROLLER_H
@@ -0,0 +1,37 @@
/*
* 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_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_SEVICE_H
#define CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_SEVICE_H
#include "concurrent_task_service_stub.h"
#include "concurrent_task_log.h"
namespace OHOS {
namespace ConcurrentTask {
class ConcurrentTaskService : public ConcurrentTaskServiceStub {
public:
ConcurrentTaskService() {}
~ConcurrentTaskService() override = default;
void ReportData(uint32_t resType, int64_t value, const Json::Value& payload) override;
void QueryInterval(int queryItem, IntervalReply& queryRs) override;
private:
DISALLOW_COPY_AND_MOVE(ConcurrentTaskService);
};
} // namespace ConcurrentTask
} // namespace OHOS
#endif // CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_SEVICE_H
@@ -0,0 +1,47 @@
/*
* 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_ABILITY_H
#define CONCURRENT_TASK_SEVICES_INCLUDE_CONCURRENT_TASK_SERVICE_ABILITY_H
#include "system_ability.h"
#include "concurrent_task_service.h"
namespace OHOS {
namespace ConcurrentTask {
class ConcurrentTaskServiceAbility : public SystemAbility {
DECLARE_SYSTEM_ABILITY(ConcurrentTaskServiceAbility);
public:
ConcurrentTaskServiceAbility(int32_t sysAbilityId, bool runOnCreate) : SystemAbility(sysAbilityId, runOnCreate) {}
~ConcurrentTaskServiceAbility() override = default;
private:
void OnStart() override;
void OnStop() override;
void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
sptr<ConcurrentTaskService> service_;
DISALLOW_COPY_AND_MOVE(ConcurrentTaskServiceAbility);
};
} // namespace ConcurrentTask
} // namespace OHOS
#endif // CONCURRENT_TASK_SEVICES_INCLUDE_CONCURRENT_TASK_SERVICE_ABILITY_H
@@ -0,0 +1,44 @@
/*
* 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 <map>
#include "iremote_stub.h"
#include "iconcurrent_task_service.h"
namespace OHOS {
namespace ConcurrentTask {
class ConcurrentTaskServiceStub : public IRemoteStub<IConcurrentTaskService> {
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 QueryIntervalInner(MessageParcel& data, MessageParcel& reply);
Json::Value StringToJson(const std::string& str);
void Init();
using RequestFuncType = std::function<int32_t (MessageParcel& data, MessageParcel& reply)>;
std::map<uint32_t, RequestFuncType> funcMap_;
};
} // namespace ConcurrentTask
} // namespace OHOS
#endif // CONCURRENT_TASK_SEVICES_INCLUDE_CONCURRENT_TASK_SERVICE_STUB_H
+155
View File
@@ -0,0 +1,155 @@
/*
* 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 QOS_INTERFACE_H
#define QOS_INTERFACE_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* generic
*/
#define SYSTEM_UID 1000
#define ROOT_UID 0
/*
* auth_ctrl
*/
struct AuthCtrlData {
unsigned int uid;
unsigned int type;
unsigned int rtgUaFlag;
unsigned int qosUaFlag;
unsigned int status;
};
enum class AuthManipulateType {
AUTH_ENABLE = 1,
AUTH_DELETE,
AUTH_GET,
AUTH_SWITCH,
AUTH_MAX_NR,
};
enum class AuthStatus {
AUTH_STATUS_DISABLED = 1,
AUTH_STATUS_SYSTEM_SERVER = 2,
AUTH_STATUS_FOREGROUND = 3,
AUTH_STATUS_BACKGROUND = 4,
AUTH_STATUS_DEAD,
};
enum class QosClassLevel {
qos_unspecified = 0,
qos_background = 1,
qos_utility = 2,
qos_default = 3,
qos_user_initiated = 4,
qos_deadline_request = 5,
qos_user_interactive = 6,
qos_max,
};
#define BASIC_AUTH_CTRL_OPERATION \
_IOWR(0xCD, 1, struct AuthCtrlData)
/*
* qos ctrl
*/
enum class QosManipulateType {
QOS_APPLY = 1,
QOS_LEAVE,
QOS_MAX_NR,
};
struct QosCtrlData {
int pid;
unsigned int type;
unsigned int level;
};
struct QosPolicyData {
int nice;
int latencyNice;
int uclampMin;
int uclampMax;
int rtSchedPriority;
};
enum class QosPolicyType {
QOS_POLICY_DEFAULT = 1,
QOS_POLICY_SYSTEM_SERVER = 2,
QOS_POLICY_FRONT = 3,
QOS_POLICY_BACK = 4,
QOS_POLICY_MAX_NR,
};
#define QOS_FLAG_NICE 0X01
#define QOS_FLAG_LATENCY_NICE 0X02
#define QOS_FLAG_UCLAMP 0x04
#define QOS_FLAG_RT 0x08
#define QOS_FLAG_ALL (QOS_FLAG_NICE | \
QOS_FLAG_LATENCY_NICE | \
QOS_FLAG_UCLAMP | \
QOS_FLAG_RT)
struct QosPolicyDatas {
int policyType;
unsigned int policyFlag;
struct QosPolicyData policys[static_cast<int>(QosClassLevel::qos_max)];
};
#define QOS_CTRL_BASIC_OPERATION \
_IOWR(0xCC, 1, struct QosCtrlData)
#define QOS_CTRL_POLICY_OPERATION \
_IOWR(0xCC, 2, struct QosPolicyDatas)
/*
* RTG
*/
#define AF_RTG_ALL 0x1fff
#define AF_RTG_DELEGATED 0x1fff
struct RtgEnableData {
int enable;
int len;
char *data;
};
#define CMD_ID_SET_ENABLE \
_IOWR(0xAB, 1, struct RtgEnableData)
/*
* interface
*/
int EnableRtg(bool flag);
int AuthEnable(unsigned int uid, unsigned int uaFlag, unsigned int status);
int AuthPause(unsigned int uid);
int AuthDelete(unsigned int uid);
int AuthGet(unsigned int uid, unsigned int *uaFlag, unsigned int *status);
int AuthSwitch(unsigned int uid, unsigned int rtgFlag, unsigned int qosFlag, unsigned int status);
int QosApply(unsigned int level);
int QosApplyForOther(unsigned int level, int tid);
int QosLeave(void);
int QosLeaveForOther(int tid);
int QosPolicy(struct QosPolicyDatas *policyDatas);
#ifdef __cplusplus
}
#endif
#endif /* OQS_INTERFACE_H */
+31
View File
@@ -0,0 +1,31 @@
/*
* 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 QOS_MANAGER_H
#define QOS_MANAGER_H
#include "qos_interface.h"
namespace OHOS {
namespace ConcurrentTask {
class QosManager {
public:
void Init();
int SetQosPolicy(struct QosPolicyDatas *policyDatas);
};
} // namespace ConcurrentTask
} // namespace OHOS
#endif
+520
View File
@@ -0,0 +1,520 @@
/*
* 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 <cinttypes>
#include <sys/resource.h>
#include <sched.h>
#include <linux/sched.h>
#include "rtg_interface.h"
#include "ipc_skeleton.h"
#include "concurrent_task_log.h"
#include "concurrent_task_controller.h"
constexpr int TARGET_UID = 3039;
using namespace OHOS::RME;
namespace OHOS {
namespace ConcurrentTask {
TaskController& TaskController::GetInstance()
{
static TaskController instance;
return instance;
}
void TaskController::ReportData(uint32_t resType, int64_t value, const Json::Value& payload)
{
pid_t uid = IPCSkeleton::GetInstance().GetCallingUid();
if (!CheckUid(uid)) {
CONCUR_LOGE("only system call can be allowed");
return;
}
Json::ValueType type = payload.type();
if (type != Json::objectValue) {
CONCUR_LOGE("error payload");
return;
}
if (payload.empty()) {
CONCUR_LOGE("payload is empty");
return;
}
std::string strRequstType = "";
try {
strRequstType = payload["type"].asString();
} catch (...) {
CONCUR_LOGE("Unexpected type format");
return;
}
if (strRequstType.length() == 0) {
CONCUR_LOGE("Get payload type err");
return;
}
int requstType = GetRequestType(strRequstType);
DealSystemRequest(requstType, payload);
PrintInfo();
}
void TaskController::QueryInterval(int queryItem, IntervalReply& queryRs)
{
pid_t uid = IPCSkeleton::GetInstance().GetCallingUid();
if (uid == 0) {
CONCUR_LOGE("Uid is 0, error query");
return;
}
switch (queryItem) {
case QUERY_UI:
QueryUi(uid, queryRs);
break;
case QUERY_RENDER:
QueryRender(uid, queryRs);
break;
case QUERY_RENDER_SERVICE:
QueryRenderService(uid, queryRs);
break;
case QUERY_COMPOSER:
QueryHwc(uid, queryRs);
break;
default:
break;
}
}
void TaskController::QueryUi(int uid, IntervalReply& queryRs)
{
if (uid == SYSTEM_UID) {
return;
}
pid_t pid = IPCSkeleton::GetInstance().GetCallingPid();
auto iter = GetRecordOfUid(uid);
if (iter == foregroundApp_.end()) {
CONCUR_LOGD("Query ui with uid %{public}d failed: pid %{public}d", uid, pid);
return;
}
int grpId = iter->GetGrpId();
if (grpId <= 0) {
CONCUR_LOGI("%{public}d Query ui with none grpid", uid);
queryRs.rtgId = -1;
} else {
queryRs.rtgId = grpId;
}
}
void TaskController::QueryRender(int uid, IntervalReply& queryRs)
{
if (uid == SYSTEM_UID) {
return;
}
pid_t pid = IPCSkeleton::GetInstance().GetCallingPid();
auto iter = GetRecordOfUid(uid);
if (iter == foregroundApp_.end()) {
CONCUR_LOGD("Query render with uid %{public}d failed, pid %{public}d", uid, pid);
return;
}
int grpId = iter->GetGrpId();
if (grpId <= 0) {
CONCUR_LOGI("%{public}d Query render with none grpid", uid);
queryRs.rtgId = -1;
} else {
queryRs.rtgId = grpId;
}
}
void TaskController::QueryRenderService(int uid, IntervalReply& queryRs)
{
if (renderServiceGrpId_ > 0) {
CONCUR_LOGD("uid %{public}d query rs group %{public}d.", uid, renderServiceGrpId_);
queryRs.rtgId = renderServiceGrpId_;
return;
}
TryCreateRsGroup();
queryRs.rtgId = renderServiceGrpId_;
CONCUR_LOGE("uid %{public}d query rs group failed and create %{public}d.", uid, renderServiceGrpId_);
}
void TaskController::QueryHwc(int uid, IntervalReply& queryRs)
{
if (uid == SYSTEM_UID) {
return;
}
pid_t pid = IPCSkeleton::GetInstance().GetCallingPid();
auto iter = GetRecordOfUid(uid);
if (iter == foregroundApp_.end()) {
CONCUR_LOGD("Query ipc thread with uid %{public}d failed, pid %{public}d", uid, pid);
return;
}
int grpId = iter->GetGrpId();
if (grpId <= 0) {
CONCUR_LOGI("%{public}d Query ipc thread with none grpid", uid);
queryRs.rtgId = -1;
} else {
queryRs.rtgId = grpId;
}
}
void TaskController::SetHwcAuth(bool status)
{
int ret;
if (status) {
ret = AuthEnable(TARGET_UID, AF_RTG_ALL, static_cast<unsigned int>(AuthStatus::AUTH_STATUS_FOREGROUND));
} else {
ret = AuthDelete(TARGET_UID);
}
if (ret == 0) {
CONCUR_LOGI("set auth status(%{public}d) for %{public}d success", status, TARGET_UID);
} else {
CONCUR_LOGE("set auth status(%{public}d) for %{public}d fail with ret %{public}d ", status, TARGET_UID, ret);
}
}
void TaskController::Init()
{
SetHwcAuth(true);
TypeMapInit();
qosManager_.Init();
TryCreateRsGroup();
}
void TaskController::Release()
{
SetHwcAuth(false);
msgType_.clear();
if (renderServiceGrpId_ <= 0) {
return;
}
DestroyRtgGrp(renderServiceGrpId_);
renderServiceGrpId_ = -1;
}
void TaskController::TypeMapInit()
{
msgType_.clear();
msgType_.insert(pair<std::string, int>("foreground", MSG_FOREGROUND));
msgType_.insert(pair<std::string, int>("background", MSG_BACKGROUND));
msgType_.insert(pair<std::string, int>("appStart", MSG_APP_START));
msgType_.insert(pair<std::string, int>("appKilled", MSG_APP_KILLED));
}
void TaskController::TryCreateRsGroup()
{
if (!rtgEnabled_) {
rtgEnabled_ = EnableRtg(true) < 0 ? false : true;
if (!rtgEnabled_) {
CONCUR_LOGE("Rtg enable failed");
return;
}
CONCUR_LOGI("Enable Rtg");
}
renderServiceGrpId_ = CreateNewRtgGrp(PRIO_RT, MAX_KEY_THREADS);
if (renderServiceGrpId_ <= 0) {
CONCUR_LOGI("CreateRsRtgGroup with RT failed, try change to normal type.");
renderServiceGrpId_ = CreateNewRtgGrp(PRIO_NORMAL, MAX_KEY_THREADS);
}
if (renderServiceGrpId_ <= 0) {
CONCUR_LOGI("CreateRsRtgGroup failed! rtGrp:%{public}d", renderServiceGrpId_);
}
}
int TaskController::GetRequestType(std::string strRequstType)
{
auto iter = msgType_.find(strRequstType);
if (iter == msgType_.end()) {
return MSG_TYPE_MAX;
}
return msgType_[strRequstType];
}
bool TaskController::CheckUid(pid_t uid)
{
if ((uid != SYSTEM_UID) && (uid != 0)) {
return false;
}
return true;
}
void TaskController::DealSystemRequest(int requestType, const Json::Value& payload)
{
int appUid = 0;
try {
appUid = stoi(payload["uid"].asString());
} catch (...) {
CONCUR_LOGE("Unexpected uid format");
}
if (appUid < 0) {
CONCUR_LOGE("appUid error:%d", appUid);
return;
}
switch (requestType) {
case MSG_FOREGROUND:
NewForeground(appUid);
break;
case MSG_BACKGROUND:
NewBackground(appUid);
break;
case MSG_APP_START:
NewAppStart(appUid);
break;
case MSG_APP_KILLED:
AppKilled(appUid);
break;
default:
CONCUR_LOGE("Unknown system request");
break;
}
}
void TaskController::DealAppRequest(int requestType, const Json::Value& payload, pid_t uid)
{
if (uid <= SYSTEM_UID) {
CONCUR_LOGE("Unexpected uid in app req");
return;
}
int tid = 0;
try {
tid = stoi(payload["tid"].asString());
} catch (...) {
CONCUR_LOGE("Unexpected tid format");
return;
}
if ((requestType >= MSG_REG_RENDER) && (requestType <= MSG_REG_KEY_THERAD)) {
int prioType = PRIO_NORMAL;
auto record = GetRecordOfUid(uid);
if (record == foregroundApp_.end()) {
return;
}
if (requestType != MSG_REG_KEY_THERAD) {
prioType = PRIO_RT;
}
record->AddKeyThread(tid, prioType);
}
}
std::list<ForegroundAppRecord>::iterator TaskController::GetRecordOfUid(int uid)
{
for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) {
if (iter->GetUid() == uid) {
return iter;
}
}
return foregroundApp_.end();
}
void TaskController::NewForeground(int uid)
{
auto it = find(authApps_.begin(), authApps_.end(), uid);
if (it == authApps_.end()) {
CONCUR_LOGI("un-authed uid %{public}d", uid);
return;
}
unsigned int uidParam = static_cast<unsigned int>(uid);
unsigned int uaFlag = AF_RTG_ALL;
unsigned int status = static_cast<unsigned int>(AuthStatus::AUTH_STATUS_FOREGROUND);
int ret = AuthEnable(uidParam, uaFlag, status);
if (ret == 0) {
CONCUR_LOGI("auth_enable %{public}d success", uid);
} else {
CONCUR_LOGE("auth_enable %{public}d fail with ret %{public}d", uid, ret);
}
bool found = false;
for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) {
if (iter->GetUid() == uid) {
found = true;
CONCUR_LOGI("uid %{public}d is already in foreground.", uid);
iter->BeginScene();
}
}
CONCUR_LOGI("uid %{public}d change to foreground.", uid);
if (!found) {
ForegroundAppRecord *tempRecord = new ForegroundAppRecord(uid);
if (tempRecord->IsValid()) {
foregroundApp_.push_back(*tempRecord);
tempRecord->BeginScene();
} else {
delete tempRecord;
}
}
}
void TaskController::NewBackground(int uid)
{
auto it = find(authApps_.begin(), authApps_.end(), uid);
if (it == authApps_.end()) {
CONCUR_LOGI("un-authed uid %{public}d", uid);
return;
}
CONCUR_LOGI("uid %{public}d change to background.", uid);
unsigned int uidParam = static_cast<unsigned int>(uid);
int ret = AuthPause(uidParam);
if (ret == 0) {
CONCUR_LOGI("auth_pause %{public}d success", uid);
} else {
CONCUR_LOGI("auth_pause %{public}d fail with %{public}d", uid, ret);
}
for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) {
if (iter->GetUid() == uid) {
iter->EndScene();
return;
}
}
}
void TaskController::NewAppStart(int uid)
{
CONCUR_LOGI("uid %{public}d start.", uid);
unsigned int uidParam = static_cast<unsigned int>(uid);
unsigned int uaFlag = AF_RTG_ALL;
unsigned int status = static_cast<unsigned int>(AuthStatus::AUTH_STATUS_BACKGROUND);
int ret = AuthEnable(uidParam, uaFlag, status);
if (ret == 0) {
CONCUR_LOGI("auth_enable %{public}d success", uid);
} else {
CONCUR_LOGE("auth_enable %{public}d fail with ret %{public}d", uid, ret);
}
authApps_.push_back(uid);
}
void TaskController::AppKilled(int uid)
{
CONCUR_LOGI("uid %{public}d killed.", uid);
unsigned int uidParam = static_cast<unsigned int>(uid);
int ret = AuthDelete(uidParam);
if (ret == 0) {
CONCUR_LOGI("auth_delete %{public}d success", uid);
} else {
CONCUR_LOGE("auth_delete %{public}d fail with %{public}d", uid, ret);
}
std::lock_guard<std::mutex> lock(appInfoLock_);
for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) {
if (iter->GetUid() == uid) {
foregroundApp_.erase(iter++);
break;
}
}
for (auto iter = authApps_.begin(); iter != authApps_.end(); iter++) {
if (*iter == uid) {
authApps_.erase(iter++);
break;
}
}
}
void TaskController::PrintInfo()
{
for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) {
iter->PrintKeyThreads();
}
}
ForegroundAppRecord::ForegroundAppRecord(int uid)
{
uid_ = uid;
grpId_ = CreateNewRtgGrp(PRIO_RT, MAX_KEY_THREADS);
if (grpId_ <= 0) {
CONCUR_LOGI("CreateNewRtgGroup with RT failed, try change to normal type.");
grpId_ = CreateNewRtgGrp(PRIO_NORMAL, MAX_KEY_THREADS);
}
if (grpId_ <= 0) {
CONCUR_LOGI("CreateNewRtgGroup failed! rtGrp:%{public}d, pid: %{public}d", grpId_, uid);
}
}
ForegroundAppRecord::~ForegroundAppRecord()
{
if (grpId_ > 0) {
DestroyRtgGrp(grpId_);
}
}
void ForegroundAppRecord::AddKeyThread(int tid, int prio)
{
int rtgPrio = (prio >= PRIO_NORMAL) ? PRIO_NORMAL : PRIO_RT;
if (keyThreads_.find(tid) != keyThreads_.end()) {
return;
}
if (grpId_ <= 0) {
CONCUR_LOGI("Add key thread fail: Grp id not been created success.");
return;
}
if (keyThreads_.size() >= MAX_KEY_THREADS) {
CONCUR_LOGI("Add key thread fail: Key threads num limit.");
return;
}
if (prio == RPIO_IN) {
setpriority(PRIO_PROCESS, tid, -13); // -13 represent spcial nice in qos
} else {
int ret = AddThreadToRtg(tid, grpId_, rtgPrio);
if (ret != 0) {
CONCUR_LOGI("Add key thread fail: Kernel err report.");
} else {
CONCUR_LOGI("Add key thread %{public}d", tid);
}
keyThreads_.insert(tid);
}
}
bool ForegroundAppRecord::BeginScene()
{
if (grpId_ <= 0) {
CONCUR_LOGI("Error begin scene in uid %{public}d", uid_);
return false;
}
OHOS::RME::BeginFrameFreq(grpId_, 0);
OHOS::RME::EndFrameFreq(grpId_);
return true;
}
bool ForegroundAppRecord::EndScene()
{
if (grpId_ <= 0) {
CONCUR_LOGI("Error end scene in uid %{public}d", uid_);
return false;
}
OHOS::RME::EndScene(grpId_);
return true;
}
int ForegroundAppRecord::GetUid()
{
return uid_;
}
int ForegroundAppRecord::GetGrpId()
{
return grpId_;
}
bool ForegroundAppRecord::IsValid()
{
if (uid_ > 0 && grpId_ > 0) {
return true;
}
return false;
}
void ForegroundAppRecord::PrintKeyThreads()
{
std::string strLog = "pid ";
strLog.append(std::to_string(uid_));
strLog.append(" has key threads: ");
for (auto iter = keyThreads_.begin(); iter != keyThreads_.end(); iter++) {
std::string temp = std::to_string(*iter);
strLog.append(temp);
strLog.append(", ");
}
CONCUR_LOGD("%{public}s", strLog.c_str());
}
} // namespace ConcurrentTask
} // namespace OHOS
+31
View File
@@ -0,0 +1,31 @@
/*
* 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.h"
#include "concurrent_task_controller.h"
namespace OHOS {
namespace ConcurrentTask {
void ConcurrentTaskService::ReportData(uint32_t resType, int64_t value, const Json::Value& payload)
{
TaskController::GetInstance().ReportData(resType, value, payload);
}
void ConcurrentTaskService::QueryInterval(int queryItem, IntervalReply& queryRs)
{
TaskController::GetInstance().QueryInterval(queryItem, queryRs);
}
} // namespace ConcurrentTask
} // namespace OHOS
@@ -0,0 +1,58 @@
/*
* 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_ability.h"
#include "concurrent_task_log.h"
#include "concurrent_task_controller.h"
#include "concurrent_task_service.h"
#include "system_ability_definition.h"
namespace OHOS {
namespace ConcurrentTask {
REGISTER_SYSTEM_ABILITY_BY_ID(ConcurrentTaskServiceAbility, CONCURRENT_TASK_SERVICE_ID, true);
void ConcurrentTaskServiceAbility::OnStart()
{
TaskController::GetInstance().Init();
if (!service_) {
try {
service_ = new ConcurrentTaskService();
} catch (const std::bad_alloc& e) {
CONCUR_LOGE("ConcurrentTaskServiceAbility:: new ConcurentTaskService failed.");
}
}
if (!Publish(service_)) {
CONCUR_LOGE("ConcurrentTaskServiceAbility:: Register service failed.");
}
CONCUR_LOGI("ConcurrentTaskServiceAbility ::OnStart.");
}
void ConcurrentTaskServiceAbility::OnStop()
{
TaskController::GetInstance().Release();
CONCUR_LOGI("ConcurrentTaskServiceAbility::OnStop!");
}
void ConcurrentTaskServiceAbility::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
{
CONCUR_LOGI("ConcurrentTaskServiceAbility::Add");
}
void ConcurrentTaskServiceAbility::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
{
CONCUR_LOGI("ConcurrentTaskServiceAbility::Remove");
}
} // namespace ConcurrentTask
} // namespace OHOS
@@ -0,0 +1,150 @@
/*
* 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;
if (!data.ReadUint32(type)) {
return ERR_CONCURRENT_TASK_PARCEL_ERROR;
}
int64_t value = 0;
if (!data.ReadInt64(value)) {
return ERR_CONCURRENT_TASK_PARCEL_ERROR;
}
std::string payload;
if (!data.ReadString(payload)) {
return ERR_CONCURRENT_TASK_PARCEL_ERROR;
}
if (payload.empty()) {
return ERR_OK;
}
ReportData(type, value, 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;
if (!data.ReadInt32(item)) {
return ERR_CONCURRENT_TASK_PARCEL_ERROR;
}
IntervalReply queryRs;
queryRs.rtgId = -1;
queryRs.paramA = -1;
queryRs.paramB = -1;
queryRs.paramC = -1;
QueryInterval(item, queryRs);
if (!reply.WriteInt32(queryRs.rtgId)) {
return ERR_CONCURRENT_TASK_PARCEL_ERROR;
}
if (!reply.WriteInt32(queryRs.paramA)) {
return ERR_CONCURRENT_TASK_PARCEL_ERROR;
}
if (!reply.WriteInt32(queryRs.paramB)) {
return ERR_CONCURRENT_TASK_PARCEL_ERROR;
}
if (!reply.WriteInt32(queryRs.paramC)) {
return ERR_CONCURRENT_TASK_PARCEL_ERROR;
}
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<Json::CharReader> 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_ = {
{ REPORT_DATA,
[this](auto& data, auto& reply) {return ReportDataInner(data, reply); } },
{ QUERY_INTERVAL,
[this](auto& data, auto& reply) {return QueryIntervalInner(data, reply); } },
};
}
} // namespace ResourceSchedule
} // namespace OHOS
+324
View File
@@ -0,0 +1,324 @@
/*
* 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 GNU_SOURCE
#define GNU_SOURCE
#endif
#include <cstdio>
#include <unistd.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include "../include/qos_interface.h"
constexpr unsigned int AF_QOS_ALL = 0x0003;
constexpr unsigned int AF_QOS_DELEGATED = 0x0001;
static int TrivalOpenRtgNode(void)
{
char fileName[] = "/proc/self/sched_rtg_ctrl";
int fd = open(fileName, O_RDWR);
#ifdef QOS_DEBUG
if (fd < 0) {
printf("task %d belong to user %d open rtg node failed\n", getpid(), getuid());
}
#endif
return fd;
}
static int TrivalOpenAuthCtrlNode(void)
{
char fileName[] = "/dev/auth_ctrl";
int fd = open(fileName, O_RDWR);
#ifdef QOS_DEBUG
if (fd < 0) {
printf("task %d belong to user %d open auth node failed\n", getpid(), getuid());
}
#endif
return fd;
}
static int TrivalOpenQosCtrlNode(void)
{
char fileName[] = "/proc/thread-self/sched_qos_ctrl";
int fd = open(fileName, O_RDWR);
#ifdef QOS_DEBUG
if (fd < 0) {
printf("task %d belong to user %d open qos node failed\n", getpid(), getuid());
}
#endif
return fd;
}
int EnableRtg(bool flag)
{
struct RtgEnableData enableData;
char configStr[] = "load_freq_switch:1;sched_cycle:1;frame_max_util:750";
int ret;
enableData.enable = flag;
enableData.len = sizeof(configStr);
enableData.data = configStr;
int fd = TrivalOpenRtgNode();
if (fd < 0) {
return fd;
}
ret = ioctl(fd, CMD_ID_SET_ENABLE, &enableData);
if (ret < 0) {
printf("set rtg config enable failed.\n");
}
close(fd);
return 0;
};
int AuthEnable(unsigned int uid, unsigned int uaFlag, unsigned int status)
{
struct AuthCtrlData data;
int fd;
int ret;
fd = TrivalOpenAuthCtrlNode();
if (fd < 0) {
return fd;
}
data.uid = uid;
data.rtgUaFlag = uaFlag;
data.qosUaFlag = AF_QOS_ALL;
data.status = status;
data.type = static_cast<unsigned int>(AuthManipulateType::AUTH_ENABLE);
ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data);
#ifdef QOS_DEBUG
if (ret < 0) {
printf("auth enable failed for uid %u with status %u\n", uid, status);
}
#endif
close(fd);
return ret;
}
int AuthSwitch(unsigned int uid, unsigned int rtgFlag, unsigned int qosFlag, unsigned int status)
{
struct AuthCtrlData data;
int fd;
int ret;
fd = TrivalOpenAuthCtrlNode();
if (fd < 0) {
return fd;
}
data.uid = uid;
data.rtgUaFlag = rtgFlag;
data.qosUaFlag = qosFlag;
data.status = status;
data.type = static_cast<unsigned int>(AuthManipulateType::AUTH_SWITCH);
ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data);
#ifdef QOS_DEBUG
if (ret < 0) {
printf("auth switch failed for uid %u with status %u\n", uid, status);
}
#endif
close(fd);
return ret;
}
int AuthDelete(unsigned int uid)
{
struct AuthCtrlData data;
int fd;
int ret;
fd = TrivalOpenAuthCtrlNode();
if (fd < 0) {
return fd;
}
data.uid = uid;
data.type = static_cast<unsigned int>(AuthManipulateType::AUTH_DELETE);
ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data);
#ifdef QOS_DEBUG
if (ret < 0) {
printf("auth delete failed for uid %u\n", uid);
}
#endif
close(fd);
return ret;
}
int AuthPause(unsigned int uid)
{
struct AuthCtrlData data;
int fd;
int ret;
fd = TrivalOpenAuthCtrlNode();
if (fd < 0) {
return fd;
}
data.uid = uid;
data.type = static_cast<unsigned int>(AuthManipulateType::AUTH_SWITCH);
data.rtgUaFlag = 0;
data.qosUaFlag = AF_QOS_DELEGATED;
data.status = static_cast<unsigned int>(AuthStatus::AUTH_STATUS_BACKGROUND);
ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data);
#ifdef QOS_DEBUG
if (ret < 0) {
printf("auth pause failed for uid %u\n", uid);
}
#endif
close(fd);
return ret;
}
int AuthGet(unsigned int uid, unsigned int *uaFlag, unsigned int *status)
{
struct AuthCtrlData data;
int fd;
int ret;
fd = TrivalOpenAuthCtrlNode();
if (fd < 0) {
return fd;
}
data.uid = uid;
data.type = static_cast<unsigned int>(AuthManipulateType::AUTH_GET);
ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data);
#ifdef QOS_DEBUG
if (ret < 0) {
printf("auth get failed for uid %u\n", uid);
}
#endif
close(fd);
*uaFlag = data.rtgUaFlag;
*status = data.status;
return ret;
}
int QosApply(unsigned int level)
{
int tid = gettid();
int ret;
ret = QosApplyForOther(level, tid);
return ret;
}
int QosApplyForOther(unsigned int level, int tid)
{
struct QosCtrlData data;
int fd;
int ret;
fd = TrivalOpenQosCtrlNode();
if (fd < 0) {
return fd;
}
data.level = level;
data.type = static_cast<unsigned int>(QosManipulateType::QOS_APPLY);
data.pid = tid;
ret = ioctl(fd, QOS_CTRL_BASIC_OPERATION, &data);
#ifdef QOS_DEBUG
if (ret < 0) {
printf("qos apply failed for task %d\n", tid);
}
#endif
close(fd);
return ret;
}
int QosLeave(void)
{
struct QosCtrlData data;
int fd;
int ret;
fd = TrivalOpenQosCtrlNode();
if (fd < 0) {
return fd;
}
data.type = static_cast<unsigned int>(QosManipulateType::QOS_LEAVE);
data.pid = gettid();
ret = ioctl(fd, QOS_CTRL_BASIC_OPERATION, &data);
#ifdef QOS_DEBUG
if (ret < 0) {
printf("qos leave failed for task %d\n", getpid());
}
#endif
close(fd);
return ret;
}
int QosLeaveForOther(int tid)
{
struct QosCtrlData data;
int fd;
int ret;
fd = TrivalOpenQosCtrlNode();
if (fd < 0) {
return fd;
}
data.type = static_cast<unsigned int>(QosManipulateType::QOS_LEAVE);
data.pid = tid;
ret = ioctl(fd, QOS_CTRL_BASIC_OPERATION, &data);
#ifdef QOS_DEBUG
if (ret < 0) {
printf("qos leave failed for task %d\n", tid);
}
#endif
close(fd);
return ret;
}
int QosPolicy(struct QosPolicyDatas *policyDatas)
{
int fd;
int ret;
fd = TrivalOpenQosCtrlNode();
if (fd < 0) {
return fd;
}
ret = ioctl(fd, QOS_CTRL_POLICY_OPERATION, policyDatas);
#ifdef QOS_DEBUG
if (ret < 0) {
printf("set qos policy failed for task %d\n", getpid());
}
#endif
close(fd);
return ret;
}
+109
View File
@@ -0,0 +1,109 @@
/*
* 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 "qos_manager.h"
#include <unistd.h>
#include "concurrent_task_log.h"
static struct QosPolicyDatas g_defaultQosPolicy = {
.policyType = static_cast<unsigned int>(QosPolicyType::QOS_POLICY_DEFAULT),
.policyFlag = QOS_FLAG_ALL,
.policys = {
{0, 0, 0, 1024, 0},
{0, 0, 0, 1024, 0},
{0, 0, 0, 1024, 0},
{0, 0, 0, 1024, 0},
{0, 0, 0, 1024, 0},
{0, 0, 0, 1024, 0},
{0, 0, 0, 1024, 0},
}
};
static struct QosPolicyDatas g_foregroundQosPolicy = {
.policyType = static_cast<unsigned int>(QosPolicyType::QOS_POLICY_FRONT),
.policyFlag = QOS_FLAG_ALL,
.policys = {
{0, 0, 0, 1024, 0},
{10, 10, 0, 200, 0},
{5, 5, 0, 250, 0},
{0, 0, 0, 1024, 0},
{-5, -5, 300, 1024, 0},
{-10, -10, 500, 1024, 0},
{-10, -10, 500, 1024, 2},
}
};
static struct QosPolicyDatas g_backgroundQosPolicy = {
.policyType = static_cast<unsigned int>(QosPolicyType::QOS_POLICY_BACK),
.policyFlag = QOS_FLAG_ALL & ~QOS_FLAG_RT,
.policys = {
{0, 0, 0, 1024, 0},
{15, 15, 0, 150, 0},
{10, 10, 0, 200, 0},
{5, 5, 0, 250, 0},
{0, 0, 0, 300, 0},
{-5, -5, 0, 350, 0},
{-5, -5, 0, 350, 3},
}
};
static struct QosPolicyDatas g_systemServerQosPolicy = {
.policyType = static_cast<unsigned int>(QosPolicyType::QOS_POLICY_SYSTEM_SERVER),
.policyFlag = QOS_FLAG_ALL,
.policys = {
{0, 0, 0, 1024, 0},
{10, 10, 0, 200, 0},
{5, 5, 0, 250, 0},
{0, 0, 0, 1024, 0},
{-5, -5, 300, 1024, 0},
{-10, -10, 500, 1024, 0},
{-10, -10, 500, 1024, 2},
}
};
namespace OHOS {
namespace ConcurrentTask {
int QosManager::SetQosPolicy(struct QosPolicyDatas *policyDatas)
{
return QosPolicy(policyDatas);
}
void QosManager::Init()
{
int ret;
ret = SetQosPolicy(&g_defaultQosPolicy);
if (ret) {
CONCUR_LOGE("%{public}d set g_defaultQosPolicy failed", getuid());
}
ret = SetQosPolicy(&g_foregroundQosPolicy);
if (ret) {
CONCUR_LOGE("%{public}d set g_foregroundQosPolicy failed", getuid());
}
ret = SetQosPolicy(&g_backgroundQosPolicy);
if (ret) {
CONCUR_LOGE("%{public}d set g_backgroundQosPolicy failed", getuid());
}
ret = SetQosPolicy(&g_systemServerQosPolicy);
if (ret) {
CONCUR_LOGE("%{public}d set g_systemServerQosPolicy failed", getuid());
}
CONCUR_LOGI("set qos policy finish");
}
}
}
+292
View File
@@ -0,0 +1,292 @@
# 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.
import("//build/ohos.gni")
import("//build/ohos_var.gni")
import("//build/test.gni")
module_output_path = "qosmanagertest/"
gtest_public_deps = [ "//third_party/googletest:gtest_main" ]
config("test_config") {
include_dirs = [
"../include/",
"../frameworks/concurrent_task_client/include",
"../interfaces/inner_api/",
"../services/include/",
"//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" ]
}
}
ohos_unittest("concurrent_svc_intf_test") {
module_out_path = module_output_path
configs = [
":test_config",
]
sources = [
"unittest/phone/concurrent_svc_intf_test.cpp",
]
deps = [
"../frameworks/concurrent_task_client:concurrent_task_client",
]
external_deps = [
"c_utils:utils",
"eventhandler:libeventhandler",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
"ipc:ipc_single",
"hiviewdfx_hilog_native:libhilog",
]
if (is_standard_system) {
public_deps = gtest_public_deps
}
subsystem_name = "resourceschedule"
part_name = "resourceschedule_qos_manager"
}
ohos_unittest("concurrent_task_client_test") {
module_out_path = module_output_path
configs = [
":ffrt_test_config",
":test_config",
]
sources = [
"unittest/phone/concurrent_task_client_test.cpp",
]
deps = [
"../frameworks/concurrent_task_client:concurrent_task_client",
]
if (is_standard_system) {
public_deps = gtest_public_deps
}
external_deps = [
"ipc:ipc_single",
"hiviewdfx_hilog_native:libhilog",
]
subsystem_name = "resourceschedule"
part_name = "resourceschedule_qos_manager"
}
ohos_unittest("concurrent_task_controller_test") {
module_out_path = module_output_path
configs = [
":ffrt_test_config",
":test_config",
]
sources = [
"unittest/phone/concurrent_task_controller_test.cpp",
]
deps = [
"../services:concurrentsvc",
"../frameworks/concurrent_task_client:concurrent_task_client",
"//third_party/jsoncpp:jsoncpp",
]
external_deps = [
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
if (is_standard_system) {
public_deps = gtest_public_deps
}
subsystem_name = "resourceschedule"
part_name = "resourceschedule_qos_manager"
}
ohos_unittest("concurrent_task_service_ability_test") {
module_out_path = module_output_path
configs = [
":ffrt_test_config",
":test_config",
]
sources = [
"unittest/phone/concurrent_task_service_ability_test.cpp",
]
deps = [
"../services:concurrentsvc",
"../frameworks/concurrent_task_client:concurrent_task_client",
]
external_deps = [
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
if (is_standard_system) {
public_deps = gtest_public_deps
}
subsystem_name = "resourceschedule"
part_name = "resourceschedule_qos_manager"
}
ohos_unittest("qos_interface_test") {
module_out_path = module_output_path
configs = [
":ffrt_test_config",
":test_config",
]
sources = [
"unittest/phone/qos_interface_test.cpp",
]
deps = [
"../services:concurrentsvc",
"../frameworks/concurrent_task_client:concurrent_task_client",
]
external_deps = [
"c_utils:utils",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
"hiviewdfx_hilog_native:libhilog",
]
if (is_standard_system) {
public_deps = gtest_public_deps
}
subsystem_name = "resourceschedule"
part_name = "resourceschedule_qos_manager"
}
ohos_unittest("qos_manager_test") {
module_out_path = module_output_path
configs = [
":ffrt_test_config",
":test_config",
]
sources = [
"unittest/phone/qos_manager_test.cpp",
]
deps = [
"../services:concurrentsvc",
"../frameworks/concurrent_task_client:concurrent_task_client",
]
external_deps = [
"c_utils:utils",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
"hiviewdfx_hilog_native:libhilog",
]
if (is_standard_system) {
public_deps = gtest_public_deps
}
subsystem_name = "resourceschedule"
part_name = "resourceschedule_qos_manager"
}
ohos_unittest("concurrent_task_service_test") {
module_out_path = module_output_path
configs = [
":ffrt_test_config",
":test_config",
]
sources = [
"unittest/phone/concurrent_task_service_test.cpp",
]
deps = [
"../services:concurrentsvc",
"../frameworks/concurrent_task_client:concurrent_task_client",
]
external_deps = [
"c_utils:utils",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
"hiviewdfx_hilog_native:libhilog",
]
if (is_standard_system) {
public_deps = gtest_public_deps
}
subsystem_name = "resourceschedule"
part_name = "resourceschedule_qos_manager"
}
group("concurrent_unittest") {
testonly = true
deps = []
if (!is_asan) {
deps += [
":qos_interface_test",
":qos_manager_test",
":concurrent_svc_intf_test",
":concurrent_task_client_test",
":concurrent_task_controller_test",
":concurrent_task_service_ability_test",
":concurrent_task_service_test",
]
}
}
@@ -0,0 +1,126 @@
/*
* 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 <map>
#include <string>
#include <unistd.h>
#include <iostream>
#include "gtest/gtest.h"
#include "concurrent_task_log.h"
#include "concurrent_task_client.h"
namespace OHOS {
namespace ConcurrentTask {
using namespace testing;
using namespace testing::ext;
using namespace OHOS::ConcurrentTask;
using namespace std;
constexpr int HUGE_ITEM = 1000000;
class ConcurrentSvcIntfTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
static int QueryInterval(int item)
{
IntervalReply rs;
rs.rtgId = -1;
cout << "start to query renderService" <<endl;
OHOS::ConcurrentTask::ConcurrentTaskClient::GetInstance().QueryInterval(
item, rs);
return rs.rtgId;
}
void ConcurrentSvcIntfTest::SetUpTestCase()
{
}
void ConcurrentSvcIntfTest::TearDownTestCase()
{
}
void ConcurrentSvcIntfTest::SetUp()
{
}
void ConcurrentSvcIntfTest::TearDown()
{
}
/**
* @tc.name: QueryBeforeGetPriv
* @tc.desc: Before get privlege, render query result should be wrong
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentSvcIntfTest, QueryBeforeGetPriv, TestSize.Level1)
{
int grpId = QueryInterval(QUERY_RENDER);
EXPECT_EQ(grpId, -1);
}
/**
* @tc.name: QueryHugeItem
* @tc.desc: If query a huge item, should return invalid.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentSvcIntfTest, QueryHugeItem, TestSize.Level1)
{
int grpId = QueryInterval(HUGE_ITEM);
EXPECT_LT(grpId, 0);
}
/**
* @tc.name: QueryNagativeItem
* @tc.desc: If query a huge item, should return invalid.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentSvcIntfTest, QueryNagativeItem, TestSize.Level1)
{
int grpId = QueryInterval(-1);
EXPECT_LT(grpId, 0);
}
/**
* @tc.name: QuerySystemUid
* @tc.desc: Confirm the test binary can execute seteuid function.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentSvcIntfTest, QueryRenderServiceTest, TestSize.Level1)
{
int grpId = QueryInterval(QUERY_RENDER_SERVICE);
#if TDD_MUSL
EXPECT_GT(grpId, 0);
#else
(void)grpId;
#endif
}
/**
* @tc.name: QuerySystemUid
* @tc.desc: Qu.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentSvcIntfTest, QueryInvalidValueTest, TestSize.Level1)
{
int grpId = QueryInterval(QURRY_TYPE_MAX);
EXPECT_LT(grpId, 0);
}
}
}
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "concurrent_task_client.h"
namespace OHOS {
namespace FFRT_TEST {
using namespace testing;
using namespace testing::ext;
using namespace OHOS::ConcurrentTask;
class ConcurrentTaskClientTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void ConcurrentTaskClientTest::SetUpTestCase()
{
}
void ConcurrentTaskClientTest::TearDownTestCase()
{
}
void ConcurrentTaskClientTest::SetUp()
{
}
void ConcurrentTaskClientTest::TearDown()
{
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskClientTest, ReportDataTest, TestSize.Level1)
{
uint32_t resType = 0;
int64_t value = 3587;
std::unordered_map<std::string, std::string> payload;
payload["uid"] = "3587";
payload["type"] = "appStart";
ConcurrentTaskClient::GetInstance().ReportData(resType, value, payload);
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskClientTest, QueryIntervalTest, TestSize.Level1)
{
int queryItem = 3;
IntervalReply queryRs = {87, 657, 357, 214};
ConcurrentTaskClient::GetInstance().QueryInterval(queryItem, queryRs);
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskClientTest, StopRemoteObjectTest, TestSize.Level1)
{
ConcurrentTaskClient::GetInstance().StopRemoteObject();
}
}
}
@@ -0,0 +1,339 @@
/*
* 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 <cinttypes>
#include <sys/resource.h>
#include <sched.h>
#include <linux/sched.h>
#include "gtest/gtest.h"
#define private public
#include "concurrent_task_controller.h"
#include "rtg_interface.h"
#include "ipc_skeleton.h"
#include "concurrent_task_log.h"
#undef private
namespace OHOS {
namespace FFRT_TEST {
using namespace testing;
using namespace testing::ext;
using namespace OHOS::ConcurrentTask;
using namespace std;
class ConcurrentTaskControllerTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void ConcurrentTaskControllerTest::SetUpTestCase()
{
}
void ConcurrentTaskControllerTest::TearDownTestCase()
{
}
void ConcurrentTaskControllerTest::SetUp()
{
}
void ConcurrentTaskControllerTest::TearDown()
{
}
/**
* @tc.name: ReportDataTest
* @tc.desc: Test whether the ReportDataTest interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskControllerTest, ReportDataTest, TestSize.Level1)
{
uint32_t resType = 0;
int64_t value = 0;
const Json::Value payload;
TaskController repData;
repData.ReportData(resType, value, payload);
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskControllerTest, QueryIntervalTest, TestSize.Level1)
{
TaskController queInt;
int queryItem = QUERY_UI;
IntervalReply queryRs = {87, 657, 357, 214};
queInt.QueryInterval(queryItem, queryRs);
queryItem = QUERY_RENDER;
queInt.QueryInterval(queryItem, queryRs);
queryItem = QUERY_RENDER_SERVICE;
queInt.QueryInterval(queryItem, queryRs);
queryItem = QUERY_COMPOSER;
queInt.QueryInterval(queryItem, queryRs);
queryItem = QURRY_TYPE_MAX;
queInt.QueryInterval(queryItem, queryRs);
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskControllerTest, InitTest, TestSize.Level1)
{
TaskController::GetInstance().Init();
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskControllerTest, AuthHwcTest, TestSize.Level1)
{
TaskController::GetInstance().SetHwcAuth(true);
TaskController::GetInstance().SetHwcAuth(false);
TaskController::GetInstance().SetHwcAuth(true);
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskControllerTest, CheckUidTest, TestSize.Level1)
{
int uid = SYSTEM_UID;
bool ret = TaskController::GetInstance().CheckUid(uid);
EXPECT_EQ(ret, true);
uid = 0;
ret = TaskController::GetInstance().CheckUid(uid);
EXPECT_EQ(ret, true);
uid = 100;
ret = TaskController::GetInstance().CheckUid(uid);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskControllerTest, TypeMapInitTest, TestSize.Level1)
{
TaskController::GetInstance().TypeMapInit();
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskControllerTest, TryCreateRsGroupTest, TestSize.Level1)
{
TaskController::GetInstance().rtgEnabled_ = false;
TaskController::GetInstance().TryCreateRsGroup();
TaskController::GetInstance().rtgEnabled_ = true;
TaskController::GetInstance().TryCreateRsGroup();
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskControllerTest, QueryRenderServiceTest, TestSize.Level1)
{
int uid = SYSTEM_UID;
IntervalReply queryRs = {87, 657, 357, 214};
TaskController::GetInstance().QueryRenderService(uid, queryRs);
int flag = TaskController::GetInstance().renderServiceGrpId_;
TaskController::GetInstance().renderServiceGrpId_ = 1;
TaskController::GetInstance().QueryRenderService(uid, queryRs);
TaskController::GetInstance().renderServiceGrpId_ = -1;
TaskController::GetInstance().QueryRenderService(uid, queryRs);
TaskController::GetInstance().renderServiceGrpId_ = flag;
TaskController::GetInstance().QueryRenderService(uid, queryRs);
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskControllerTest, GetRequestTypeTest, TestSize.Level1)
{
std::string strRequstType = "test";
int ret = TaskController::GetInstance().GetRequestType(strRequstType);
EXPECT_EQ(ret, MSG_TYPE_MAX);
TaskController::GetInstance().msgType_["test"] = 8;
ret = TaskController::GetInstance().GetRequestType(strRequstType);
EXPECT_EQ(ret, 8);
TaskController::GetInstance().msgType_.erase("test");
ret = TaskController::GetInstance().GetRequestType(strRequstType);
EXPECT_EQ(ret, MSG_TYPE_MAX);
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskControllerTest, NewForegroundTest, TestSize.Level1)
{
TaskController fore;
int uid = 0;
fore.NewForeground(uid);
fore.NewBackground(uid);
fore.NewAppStart(uid);
fore.NewForeground(uid);
fore.NewBackground(uid);
fore.AppKilled(uid);
uid = 574;
fore.foregroundApp_.push_back(ForegroundAppRecord(574));
fore.foregroundApp_.push_back(ForegroundAppRecord(1));
fore.foregroundApp_.push_back(ForegroundAppRecord(3));
auto iter = fore.foregroundApp_.begin();
EXPECT_EQ(iter->GetUid(), uid);
fore.NewForeground(uid);
fore.NewBackground(uid);
fore.NewAppStart(uid);
fore.NewForeground(uid);
fore.NewBackground(uid);
fore.AppKilled(uid);
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskControllerTest, PrintInfoTest, TestSize.Level1)
{
TaskController print;
print.foregroundApp_.push_back(ForegroundAppRecord(1));
print.foregroundApp_.push_back(ForegroundAppRecord(3));
print.foregroundApp_.push_back(ForegroundAppRecord(5));
auto iter = print.foregroundApp_.begin();
EXPECT_NE(iter, print.foregroundApp_.end());
print.PrintInfo();
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskControllerTest, AddKeyThreadTest, TestSize.Level1)
{
int uid = 758;
int tid = 45;
int tid2 = 46;
int tid3 = 47;
int tid4 = 48;
int tid5 = 49;
int prio = PRIO_NORMAL;
ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(uid);
foregroundapprecord.AddKeyThread(tid, prio);
foregroundapprecord.keyThreads_.insert(tid);
foregroundapprecord.AddKeyThread(tid, prio);
foregroundapprecord.grpId_ = -1;
foregroundapprecord.AddKeyThread(tid, prio);
foregroundapprecord.grpId_ = 1;
foregroundapprecord.AddKeyThread(tid, prio);
foregroundapprecord.keyThreads_.insert(tid2);
foregroundapprecord.keyThreads_.insert(tid3);
foregroundapprecord.keyThreads_.insert(tid4);
foregroundapprecord.keyThreads_.insert(tid5);
foregroundapprecord.keyThreads_.insert(tid5);
foregroundapprecord.AddKeyThread(tid, prio);
prio = RPIO_IN;
foregroundapprecord.keyThreads_.insert(tid);
prio = PRIO_RT;
foregroundapprecord.keyThreads_.insert(tid);
foregroundapprecord.AddKeyThread(tid, prio);
foregroundapprecord.keyThreads_.clear();
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskControllerTest, BeginSceneTest, TestSize.Level1)
{
int uid = 758;
ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(uid);
foregroundapprecord.BeginScene();
foregroundapprecord.EndScene();
foregroundapprecord.grpId_ = -1;
foregroundapprecord.BeginScene();
foregroundapprecord.EndScene();
foregroundapprecord.grpId_ = 1;
foregroundapprecord.BeginScene();
foregroundapprecord.EndScene();
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskControllerTest, IsValidTest, TestSize.Level1)
{
int uid = 758;
ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(uid);
EXPECT_EQ(foregroundapprecord.GetUid(), foregroundapprecord.uid_);
EXPECT_EQ(foregroundapprecord.GetGrpId(), foregroundapprecord.grpId_);
foregroundapprecord.uid_ = -1;
foregroundapprecord.grpId_ = 1;
EXPECT_EQ(foregroundapprecord.IsValid(), false);
foregroundapprecord.uid_ = -1;
foregroundapprecord.grpId_ = -1;
EXPECT_EQ(foregroundapprecord.IsValid(), false);
foregroundapprecord.uid_ = 1;
foregroundapprecord.grpId_ = -1;
EXPECT_EQ(foregroundapprecord.IsValid(), false);
foregroundapprecord.uid_ = 1;
foregroundapprecord.grpId_ = 1;
EXPECT_EQ(foregroundapprecord.IsValid(), true);
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskControllerTest, PrintKeyThreadsTest, TestSize.Level1)
{
int uid = 758;
ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(uid);
foregroundapprecord.keyThreads_.insert(1);
foregroundapprecord.keyThreads_.insert(3);
foregroundapprecord.keyThreads_.insert(5);
foregroundapprecord.keyThreads_.insert(7);
foregroundapprecord.keyThreads_.insert(9);
auto iter = foregroundapprecord.keyThreads_.begin();
EXPECT_NE(iter, foregroundapprecord.keyThreads_.end());
foregroundapprecord.PrintKeyThreads();
}
}
}
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#define private public
#include "concurrent_task_service_ability.h"
#undef private
namespace OHOS {
namespace FFRT_TEST {
using namespace testing;
using namespace testing::ext;
using namespace OHOS::ConcurrentTask;
class ConcurrentTaskServiceAbilityTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void ConcurrentTaskServiceAbilityTest::SetUpTestCase()
{
}
void ConcurrentTaskServiceAbilityTest::TearDownTestCase()
{
}
void ConcurrentTaskServiceAbilityTest::SetUp()
{
}
void ConcurrentTaskServiceAbilityTest::TearDown()
{
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskServiceAbilityTest, OnStartTest, TestSize.Level1)
{
int32_t sysAbilityId = 8745;
bool runOnCreate = true;
ConcurrentTaskServiceAbility concurrenttaskserviceability = ConcurrentTaskServiceAbility(sysAbilityId, runOnCreate);
concurrenttaskserviceability.OnStart();
concurrenttaskserviceability.OnStart();
concurrenttaskserviceability.OnStop();
}
/**
* @tc.name: PushTaskTest
* @tc.desc: Test whether the PushTask interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskServiceAbilityTest, OnAddSystemAbilityTest, TestSize.Level1)
{
int32_t sysAbilityId = 8745;
bool runOnCreate = true;
int32_t systemAbilityId = 6587;
std::string deviceId = "test";
ConcurrentTaskServiceAbility concurrenttaskserviceability = ConcurrentTaskServiceAbility(sysAbilityId, runOnCreate);
concurrenttaskserviceability.OnStart();
concurrenttaskserviceability.OnAddSystemAbility(systemAbilityId, deviceId);
concurrenttaskserviceability.OnRemoveSystemAbility(systemAbilityId, deviceId);
concurrenttaskserviceability.OnStop();
}
}
}
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "concurrent_task_service.h"
#include "concurrent_task_controller.h"
namespace OHOS {
namespace FFRT_TEST {
using namespace testing;
using namespace testing::ext;
using namespace OHOS::ConcurrentTask;
class ConcurrentTaskServiceTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void ConcurrentTaskServiceTest::SetUpTestCase()
{
}
void ConcurrentTaskServiceTest::TearDownTestCase()
{
}
void ConcurrentTaskServiceTest::SetUp()
{
}
void ConcurrentTaskServiceTest::TearDown()
{
}
/**
* @tc.name: QueryIntervalTest
* @tc.desc: Test whether the QueryInterval interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(ConcurrentTaskServiceTest, QueryIntervalTest, TestSize.Level1)
{
int queryItem = 0;
IntervalReply queryRs = {87, 657, 357, 214};
ConcurrentTaskService queInt;
queInt.QueryInterval(queryItem, queryRs);
}
}
}
+241
View File
@@ -0,0 +1,241 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "../include/qos_interface.h"
namespace OHOS {
namespace FFRT_TEST {
using namespace testing;
using namespace testing::ext;
using namespace OHOS::FFRT_TEST;
using namespace std;
class QosInterfaceTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void QosInterfaceTest::SetUpTestCase()
{
}
void QosInterfaceTest::TearDownTestCase()
{
}
void QosInterfaceTest::SetUp()
{
}
void QosInterfaceTest::TearDown()
{
}
extern "C" {
/**
* @tc.name: EnableRtgTest
* @tc.desc: Test whether the OnRemoteRequest interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(QosInterfaceTest, EnableRtgTest, TestSize.Level1)
{
bool flag = true;
int ret = EnableRtg(flag);
EXPECT_EQ(ret, 0);
}
/**
* @tc.name: AuthEnableTest
* @tc.desc: Test whether the OnRemoteRequest interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(QosInterfaceTest, AuthEnableTest, TestSize.Level1)
{
unsigned int uid = 1;
unsigned int uaFlag = 1;
unsigned int status = 1;
int ret = AuthEnable(uid, uaFlag, status);
EXPECT_EQ(ret, 0);
}
/**
* @tc.name: AuthSwitchTest
* @tc.desc: Test whether the AuthSwitch interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(QosInterfaceTest, AuthSwitchTest, TestSize.Level1)
{
unsigned int uid = 1;
unsigned int rtgFlag = 1;
unsigned int qosFlag = 1;
unsigned int status = 1;
int ret = AuthSwitch(uid, rtgFlag, qosFlag, status);
EXPECT_EQ(ret, 0);
}
/**
* @tc.name: AuthDeleteTest
* @tc.desc: Test whether the AuthDelete interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(QosInterfaceTest, AuthDeleteTest, TestSize.Level1)
{
unsigned int uid = 1;
int ret = AuthDelete(uid);
EXPECT_EQ(ret, 0);
}
/**
* @tc.name: AuthPauseTest
* @tc.desc: Test whether the AuthPause interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(QosInterfaceTest, AuthPauseTest, TestSize.Level1)
{
unsigned int uid = 1;
int ret = -1;
ret = AuthPause(uid);
EXPECT_EQ(ret, -1);
}
/**
* @tc.name: QosApplyTest
* @tc.desc: Test whether the QosApply interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(QosInterfaceTest, QosApplyTest, TestSize.Level1)
{
unsigned int level = 1;
int ret = -1;
ret = QosApply(level);
#if ARM64_TEST
EXPECT_EQ(ret, 0);
#else
(void)ret;
#endif
}
/**
* @tc.name: AuthGetTest
* @tc.desc: Test whether the AuthGet interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(QosInterfaceTest, AuthGetTest, TestSize.Level1)
{
unsigned int uid = 1000;
unsigned int uaFlag1 = 0;
unsigned int *uaFlag = &uaFlag1;
unsigned int status1 = 0;
unsigned int *status = &status1;
int ret = AuthGet(uid, uaFlag, status);
EXPECT_GE(ret, 0);
uid = -1;
ret = AuthGet(uid, uaFlag, status);
EXPECT_EQ(ret, -1);
}
/**
* @tc.name: QosApplyForOtherTest
* @tc.desc: Test whether the QosApplyForOther interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(QosInterfaceTest, QosApplyForOtherTest, TestSize.Level1)
{
unsigned int level = 1;
int tid = gettid();
int ret = -1;
ret = QosApplyForOther(level, tid);
#if ARM64_TEST
EXPECT_EQ(ret, 0);
#else
(void)ret;
#endif
}
/**
* @tc.name: QosLeaveTest
* @tc.desc: Test whether the QosLeave interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(QosInterfaceTest, QosLeaveTest, TestSize.Level1)
{
int ret = -1;
ret = QosLeave();
#if ARM64_TEST
EXPECT_EQ(ret, 0);
#else
(void)ret;
#endif
}
/**
* @tc.name: QosLeaveForOtherTest
* @tc.desc: Test whether the QosLeaveForOther interface are normal.
* @tc.type: FUNC
*/
HWTEST_F(QosInterfaceTest, QosLeaveForOtherTest, TestSize.Level1)
{
int ret = -1;
int tid = gettid();
int level = 1;
ret = QosApplyForOther(level, tid);
ret = QosLeaveForOther(tid);
#if ARM64_TEST
EXPECT_EQ(ret, 0);
#else
(void)ret;
#endif
}
/**
* @tc.name: QosPolicyTest
* @tc.desc: Test whether the QosPolicy interface are normal.
* @tc.type: FUNC
*/
static struct QosPolicyDatas g_defaultQosPolicy = {
.policyType = static_cast<unsigned int>(QosPolicyType::QOS_POLICY_DEFAULT),
.policyFlag = QOS_FLAG_ALL,
.policys = {
{0, 0, 0, 1024, 0},
{0, 0, 0, 1024, 0},
{0, 0, 0, 1024, 0},
{0, 0, 0, 1024, 0},
{0, 0, 0, 1024, 0},
{0, 0, 0, 1024, 0},
{0, 0, 0, 1024, 0},
}
};
HWTEST_F(QosInterfaceTest, QosPolicyTest, TestSize.Level1)
{
int ret = -1;
struct QosPolicyDatas *policyDatas = nullptr;
ret = QosPolicy(policyDatas);
EXPECT_EQ(ret, -1);
#if ARM64_TEST
ret = QosPolicy(&g_defaultQosPolicy);
EXPECT_EQ(ret, 0);
#endif
}
}
}
}
+63
View File
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "qos_manager.h"
namespace OHOS {
namespace FFRT_TEST {
using namespace testing;
using namespace testing::ext;
using namespace OHOS::FFRT_TEST;
using namespace ConcurrentTask;
using namespace std;
class QosManagerTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void QosManagerTest::SetUpTestCase()
{
}
void QosManagerTest::TearDownTestCase()
{
}
void QosManagerTest::SetUp()
{
}
void QosManagerTest::TearDown()
{
}
/**
* @tc.name: DecDepRefTest
* @tc.desc: Confirm the test binary can execute in root priv.
* @tc.type: FUNC
*/
HWTEST_F(QosManagerTest, TaskHandleTest, TestSize.Level1)
{
QosManager qosManager;
qosManager.Init();
}
}
}