diff --git a/common/src/config_reader.cpp b/common/src/config_reader.cpp deleted file mode 100644 index a576be0112edf32b31b6f4f96f8f3d06b35ba21b..0000000000000000000000000000000000000000 --- a/common/src/config_reader.cpp +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include - -#include "config_reader.h" -#include "config_policy_utils.h" -#include "concurrent_task_log.h" -#include "parameters.h" - -using namespace std; - -namespace OHOS { -namespace ConcurrentTask { -namespace { - const std::string XML_TAG_QOS_CONFIG = "qosconfig"; - const std::string XML_TAG_QOS_AUTH = "auth"; - const std::string XML_TAG_UIDLIST = "uidlist"; - const std::string XML_TAG_UID = "uid"; - const std::string XML_TAG_BUNDLENAMELIST = "bundlenamelist"; - const std::string XML_TAG_BUNDLENAME = "bundlename"; - const std::string XML_TAG_POWER_MODE = "powermode"; - const std::string XML_TAG_SWITCH = "switch"; - const std::string XML_TAG_FPS = "fps"; - const std::string XML_TAG_DEGRADATION_FPS = "degradationfps"; - const std::string XML_TAG_FPS_HIGH = "120"; - const std::string XML_TAG_FPS_MEDIUM = "90"; - const std::string XML_TAG_FPS_STANDARD = "60"; - constexpr int FPS_OFFSET = 10000; -} - -bool ConfigReader::IsValidNode(const xmlNode* currNode) -{ - if (!currNode) { - return false; - } - if (!currNode->name || currNode->type == XML_COMMENT_NODE) { - return false; - } - return true; -} - -bool ConfigReader::FillinUidInfo(const xmlNode* currNode) -{ - if (!IsValidNode(currNode)) { - CONCUR_LOGE("FillinUidInfo:: currNode is nullptr!"); - return false; - } - xmlNodePtr currNodePtr = currNode->xmlChildrenNode; - for (; currNodePtr; currNodePtr = currNodePtr->next) { - if (xmlStrcmp(currNodePtr->name, reinterpret_cast(XML_TAG_UID.c_str())) == 0) { - xmlChar *attrValue = xmlGetProp(currNodePtr, reinterpret_cast(XML_TAG_UID.c_str())); - if (!attrValue) { - CONCUR_LOGE("FillinUidInfo:: uid null!"); - return false; - } - int64_t uid = atoi(reinterpret_cast(attrValue)); - authProcUidConfigs_.insert(uid); - xmlFree(attrValue); - } - } - return true; -} - -bool ConfigReader::FillinBundleNameInfo(const xmlNode* currNode) -{ - if (!IsValidNode(currNode)) { - CONCUR_LOGE("FillinBundleNameInfo:: currNode is nullptr!"); - return false; - } - xmlNodePtr currNodePtr = currNode->xmlChildrenNode; - for (; currNodePtr; currNodePtr = currNodePtr->next) { - if (xmlStrcmp(currNodePtr->name, reinterpret_cast(XML_TAG_BUNDLENAME.c_str())) == 0) { - xmlChar *attrValue = xmlGetProp(currNodePtr, reinterpret_cast(XML_TAG_BUNDLENAME.c_str())); - if (!attrValue) { - CONCUR_LOGE("FillinBundleNameInfo:: bundleName null!"); - return false; - } - std::string bundleName = reinterpret_cast(attrValue); - authProcBundleNameConfigs_.insert(bundleName); - xmlFree(attrValue); - } - } - return true; -} - -void ConfigReader::ParseAuth(const xmlNode* currNode) -{ - xmlNodePtr currNodePtr = currNode->xmlChildrenNode; - for (; currNodePtr; currNodePtr = currNodePtr->next) { - if (xmlStrcmp(currNodePtr->name, reinterpret_cast(XML_TAG_UIDLIST.c_str())) == 0) { - if (!FillinUidInfo(currNodePtr)) { - CONCUR_LOGE("ParseAuth:: uid fill in authProcUidConfigs_ error!"); - continue; - } - } - - if (xmlStrcmp(currNodePtr->name, reinterpret_cast(XML_TAG_BUNDLENAMELIST.c_str())) == 0) { - if (!FillinBundleNameInfo(currNodePtr)) { - CONCUR_LOGE("ParseAuth:: bundleName fill in authProcBundleNameConfigs_ error!"); - continue; - } - } - } -} - -void ConfigReader::ParsePowerMode(const xmlNode* currNode) -{ - if (!IsValidNode(currNode)) { - CONCUR_LOGE("ParsePowerMode:: currNode is nullptr!"); - return; - } - xmlNodePtr currNodePtr = currNode->xmlChildrenNode; - for (; currNodePtr; currNodePtr = currNodePtr->next) { - if (xmlStrcmp(currNodePtr->name, reinterpret_cast(XML_TAG_SWITCH.c_str())) == 0) { - char* switchValue = reinterpret_cast(xmlNodeGetContent(currNodePtr)); - if (!switchValue) { - CONCUR_LOGE("ParsePowerMode:: switch is null!"); - continue; - } - if (strncmp(switchValue, "1", 1) == 0) { - powerModeSchedSwitch_ = true; - } else if (strncmp(switchValue, "0", 1) == 0) { - powerModeSchedSwitch_ = false; - } else { - CONCUR_LOGE("ParsePowerMode:: invalid switch value!"); - } - xmlFree(switchValue); - } - - if (xmlStrcmp(currNodePtr->name, reinterpret_cast(XML_TAG_DEGRADATION_FPS.c_str())) == 0) { - char* fpsValue = reinterpret_cast(xmlGetProp(currNodePtr, - reinterpret_cast(XML_TAG_FPS.c_str()))); - char* deFpsValue = reinterpret_cast(xmlNodeGetContent(currNodePtr)); - if (fpsValue && deFpsValue && IsValidFps(fpsValue) && IsPositiveInt(deFpsValue)) { - degradationFpsMap_.insert(std::make_pair(atoi(fpsValue), atoi(deFpsValue))); - } else { - CONCUR_LOGE("ParsePowerMode:: fps is null or invalid!"); - } - if (fpsValue) { - xmlFree(fpsValue); - } - if (deFpsValue) { - xmlFree(deFpsValue); - } - } - } -} - -bool ConfigReader::LoadFromConfigFile(const std::string& configFile) -{ - // skip the empty string, else you will get empty node - xmlDocPtr xmlDocPtr = xmlReadFile(configFile.c_str(), nullptr, - XML_PARSE_NOBLANKS | XML_PARSE_NOERROR | XML_PARSE_NOWARNING); - if (!xmlDocPtr) { - CONCUR_LOGE("LoadFromConfigFile:: xmlReadFile error!"); - return false; - } - xmlNodePtr rootNodePtr = xmlDocGetRootElement(xmlDocPtr); - if (!rootNodePtr || !rootNodePtr->name || - xmlStrcmp(rootNodePtr->name, reinterpret_cast(XML_TAG_QOS_CONFIG.c_str())) != 0) { - CONCUR_LOGE("LoadFromConfigFile:: root element tag error!"); - xmlFreeDoc(xmlDocPtr); - return false; - } - xmlNodePtr currNodePtr = rootNodePtr->xmlChildrenNode; - for (; currNodePtr; currNodePtr = currNodePtr->next) { - if (!IsValidNode(currNodePtr)) { - CONCUR_LOGE("LoadFromConfigFile:: IsInvalidNode!"); - continue; - } - if (xmlStrcmp(currNodePtr->name, reinterpret_cast(XML_TAG_QOS_AUTH.c_str())) == 0) { - ParseAuth(currNodePtr); - } - if (xmlStrcmp(currNodePtr->name, reinterpret_cast(XML_TAG_POWER_MODE.c_str())) == 0) { - ParsePowerMode(currNodePtr); - } - } - ConfigHilog(); - xmlFreeDoc(xmlDocPtr); - return true; -} - -void ConfigReader::GetRealConfigPath(const char* configName, std::string& configPath) -{ - if (!configName) { - CONCUR_LOGE("GetRealConfigPath:: configName is nullptr!"); - return; - } - char buf[PATH_MAX] = {0}; - char* configFilePath = GetOneCfgFile(configName, buf, PATH_MAX); - char tmpPath[PATH_MAX] = {0}; - if (!configFilePath || strlen(configFilePath) == 0 || strlen(configFilePath) > PATH_MAX || - !realpath(configFilePath, tmpPath)) { - CONCUR_LOGE("GetRealConfigPath:: get config file path error!"); - configPath = ""; - return; - } - configPath = tmpPath; -} - -bool ConfigReader::IsUidAuth(pid_t uid) -{ - if (authProcUidConfigs_.find(uid) != authProcUidConfigs_.end()) { - return true; - } - return false; -} - -bool ConfigReader::IsBundleNameAuth(std::string& bundleName) -{ - if (authProcBundleNameConfigs_.find(bundleName) != authProcBundleNameConfigs_.end()) { - return true; - } - return false; -} - -bool ConfigReader::GetPowerModeSchedSwitch() -{ - return powerModeSchedSwitch_; -} - -int ConfigReader::GetDegratationFps(int fps) -{ - if (degradationFpsMap_.find(fps) == degradationFpsMap_.end()) { - return fps + FPS_OFFSET; - } - return degradationFpsMap_[fps] + FPS_OFFSET; -} - -bool ConfigReader::IsValidFps(const std::string& fps) -{ - if (fps == XML_TAG_FPS_HIGH || fps == XML_TAG_FPS_MEDIUM || fps == XML_TAG_FPS_STANDARD) { - return true; - } - return false; -} - -bool ConfigReader::IsPositiveInt(const std::string& intStr) -{ - int num = 0; - try { - num = stoi(intStr); - } catch (...) { - CONCUR_LOGE("Unexpected number format!"); - return false; - } - return num > 0; -} - -void ConfigReader::ConfigHilog() -{ - bool getConfigRead = OHOS::system::GetBoolParameter("persist.qos.configreadlog", false); - if (getConfigRead) { - for (auto iter : authProcUidConfigs_) { - CONCUR_LOGI("authProcUidConfigs_ contain uid = %{public}d", (int32_t)iter); - } - for (auto iter : authProcBundleNameConfigs_) { - CONCUR_LOGI("authProcBundleNameConfigs_ contain bundleName = %{public}s", iter.c_str()); - } - CONCUR_LOGI("powerModeSchedSwitch_ = %{public}d", powerModeSchedSwitch_); - for (auto iter : degradationFpsMap_) { - CONCUR_LOGI("fps = %{public}d degradationFps = %{public}d", iter.first, iter.second); - } - } -} -} -} \ No newline at end of file diff --git a/etc/param/ffrt.para b/etc/param/ffrt.para index f00573b4e67a70fefa18802c5e110a039e9b6201..1b7974a934f9beb9fe23c1e12459f7e1435f2004 100644 --- a/etc/param/ffrt.para +++ b/etc/param/ffrt.para @@ -12,7 +12,7 @@ # limitations under the License. ffrt.interval.ui=false -persist.ffrt.interval.renderthread=true +ffrt.interval.renderthread=true ffrt.interval.renderservice=false ffrt.interval.slide=false ffrt.interval.limit=false diff --git a/etc/param/ffrt.para.dac b/etc/param/ffrt.para.dac index dee7fbe20e7c0c509d5a9c320442ddc794d339ee..1eabbde8263f06ff71ffc4272bfaf5d48de669b3 100644 --- a/etc/param/ffrt.para.dac +++ b/etc/param/ffrt.para.dac @@ -12,7 +12,7 @@ # limitations under the License. ffrt.interval.ui = system:system:0664 -persist.ffrt.interval.renderthread = system:system:0664 +ffrt.interval.renderthread = system:system:0664 ffrt.interval.renderservice = system:system:0664 ffrt.interval.slide = system:system:0664 ffrt.interval.limit = system:system:0664 diff --git a/frameworks/concurrent_task_client/src/concurrent_task_service_proxy.cpp b/frameworks/concurrent_task_client/src/concurrent_task_service_proxy.cpp index 8e0e4a89b2c54a2771edb616a21be6df1437c139..6ba5a9bdaacba3cb9a8b4bf0942ff1c84de84556 100644 --- a/frameworks/concurrent_task_client/src/concurrent_task_service_proxy.cpp +++ b/frameworks/concurrent_task_client/src/concurrent_task_service_proxy.cpp @@ -53,7 +53,7 @@ void ConcurrentTaskServiceProxy::QueryInterval(int queryItem, IntervalReply& que CONCUR_LOGE("Write interface token failed in QueryInterval Proxy"); return; } - if (!data.WriteInt32(queryItem) || !data.WriteInt32(queryRs.tid)) { + if (!data.WriteInt32(queryItem) || !data.WriteInt32(queryRs.tid) || !data.WriteInt32(queryRs.paramA)) { CONCUR_LOGE("Write info failed in QueryInterval Proxy"); return; } diff --git a/frameworks/concurrent_task_client/include/concurrent_task_type.h b/interfaces/inner_api/concurrent_task_type.h similarity index 99% rename from frameworks/concurrent_task_client/include/concurrent_task_type.h rename to interfaces/inner_api/concurrent_task_type.h index a83277f2c2934d1a5cb7398bc607ac06530673be..ba6bc1a0a87d4328e394a094407335490bbd173b 100644 --- a/frameworks/concurrent_task_client/include/concurrent_task_type.h +++ b/interfaces/inner_api/concurrent_task_type.h @@ -15,6 +15,9 @@ #ifndef CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_TYPE_H #define CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_TYPE_H + +#include + namespace OHOS { namespace ConcurrentTask { constexpr int MAX_KEY_THREADS = 5; diff --git a/services/BUILD.gn b/services/BUILD.gn index 21036d9e62cc4617cf43c7bc4e38e736f100284a..8c231099d710bb7329e33f515536968eed3ef9b8 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -48,17 +48,16 @@ ohos_shared_library("concurrentsvc") { "-fno-exceptions", "-fno-unwind-tables", "-fno-asynchronous-unwind-tables", - "-g0", "-Os", ] ldflags = [ "-Wl,--exclude-libs=ALL" ] sources = [ - "../common/src/config_reader.cpp", - "src/concurrent_task_controller.cpp", + "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", ] diff --git a/services/include/concurrent_task_controller.h b/services/include/concurrent_task_controller.h deleted file mode 100644 index d15651dd92a64104d84036d2b19f89fd8df5b212..0000000000000000000000000000000000000000 --- a/services/include/concurrent_task_controller.h +++ /dev/null @@ -1,153 +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_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_CONTROLLER_H -#define CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_CONTROLLER_H - -#include -#include -#include -#include -#include -#include -#include "json/json.h" -#include "concurrent_task_type.h" -#include "config_reader.h" -#include "qos_policy.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 QueryDeadline(int queryItem, DeadlineReply& ddlReply, const Json::Value& payload); - void RequestAuth(const Json::Value& payload); - void Init(); - void Release(); - int CreateNewRtgGrp(int prioType, int rtNum); - -private: - void TypeMapInit(); - void QosApplyInit(); - int TryCreateSystemGroup(); - void TryCreateHardwareGroup(); - void TryCreateRsGroup(); - void TryCreateRSMainGrp(); - void TryCreateRSRenderGrp(); - void QueryUi(pid_t uid, IntervalReply& queryRs); - void QueryRender(pid_t uid, IntervalReply& queryRs); - void QueryRenderService(pid_t uid, IntervalReply& queryRs); - void QueryRenderServiceMain(pid_t uid, pid_t pid, IntervalReply& queryRs); - void QueryRenderServiceRender(pid_t uid, pid_t pid, IntervalReply& queryRs); - void QueryHardware(pid_t uid, pid_t pid, IntervalReply& queryRs); - void QueryExecutorStart(pid_t uid, pid_t pid, IntervalReply& queryRs); - void QueryHwc(pid_t uid, IntervalReply& queryRs); - int GetRequestType(std::string strRequstType); - void DealSystemRequest(int requestType, const Json::Value& payload); - void NewForeground(int uid, int pid); - void NewBackground(int uid, int pid); - void NewAppStart(int uid, int pid, const std::string& bundleName); - void AppKilled(int uid, int pid); - void ContinuousTaskProcess(int uid, int pid, int status); - void FocusStatusProcess(int uid, int pid, int status); - void InteractionSceneProcess(int status); - void DeadlinePerfMode(); - void DeadlinePowerMode(); - int AuthSystemProcess(int pid); - bool ConfigReaderInit(); - bool ModifySystemRate(const Json::Value& payload); - void SetAppRate(const Json::Value& payload); - int FindRateFromInfo(int uiTid, const Json::Value& payload); - void SetRenderServiceRate(const Json::Value& payload); - void SetAppAndRenderServiceRate(int appRate, int rsRate); - bool CheckJsonValid(const Json::Value& payload); - void SetFrameRate(int rtgId, int rate); - ForegroundAppRecord* GetRecordOfPid(int pid); - void PrintInfo(); - bool ParsePayload(const Json::Value& payload, int& uid, int& pid, std::string& bundleName); - std::string GetProcessNameByToken(); - void ModifyGameState(const Json::Value& payload); - int GetGamePid(const std::string &gameMsg) const; - GameStatus GetGameScene(const std::string &gameMsg) const; - void NewForegroundAppRecord(int pid, int uiTid, bool ddlEnabled); - - std::mutex appInfoLock_; - std::mutex rateInfoLock_; - std::mutex executorStartLock_; - std::mutex ddlPowerModeLock_; - std::mutex configReaderMutex_; - std::list foregroundApp_ = {}; - std::list rsThreads_ = {}; - std::unordered_map msgType_ = {}; - QosPolicy qosPolicy_; - std::vector authApps_; - int renderServiceMainGrpId_ = -1; - int renderServiceRenderGrpId_ = -1; - int renderServiceMainTid_ = -1; - int renderServiceRenderTid_ = -1; - int hardwareGrpId_ = -1; - int hardwareTid_ = -1; - int systemRate_ = 0; - int uniAppRate_ = 0; - bool rtgEnabled_ = false; - bool configEnable_ = false; - int authedRSPid_ = 0; - bool ddlSceneSchedSwitch_ = false; - bool ddlPowerModeEnable_ = false; - std::atomic curGamePid_ = -1; - int executorNum_ = 0; - std::map appBundleName; - std::unique_ptr configReader_ = nullptr; - - const std::string RENDER_SERVICE_PROCESS_NAME = "render_service"; - const std::string RESOURCE_SCHEDULE_PROCESS_NAME = "resource_schedule_service"; - const std::string GAME_ACCELERATE_SCHED_PROCESS_NAME = "game_accelerate_schedule"; -}; - -class ForegroundAppRecord { -public: - explicit ForegroundAppRecord(int pid, int uiTid, bool createGrp = true); - ~ForegroundAppRecord(); - - void AddKeyThread(int tid, int prio = PRIO_NORMAL); - bool BeginScene(); - bool EndScene(); - int GetPid() const; - int GetGrpId() const; - int GetRate() const; - void SetRate(int appRate); - int GetUiTid() const; - void SetUiTid(int uiTid); - void SetGrpId(int grpId); - bool IsValid(); - void PrintKeyThreads(); - -private: - int pid_ = 0; - int grpId_ = 0; - int rate_ = 0; - int uiTid_ = 0; - std::unordered_set keyThreads_; -}; -} // namespace ConcurrentTask -} // namespace OHOS - -#endif // CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_CONTROLLER_H diff --git a/services/include/concurrent_task_controller_interface.h b/services/include/concurrent_task_controller_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..0cf6d6dd29ad908d21c701a9d1a1dcec4330e06f --- /dev/null +++ b/services/include/concurrent_task_controller_interface.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 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_INTERFACE_H +#define CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_CONTROLLER_INTERFACE_H + +#include + +#include "json/json.h" +#include "json/value.h" + +#include "concurrent_task_type.h" +#include "func_loader.h" + +namespace OHOS { +namespace ConcurrentTask { +using ReportDataFunc = void (*)(uint32_t resType, int64_t value, const Json::Value& payload); +using QueryIntervalFunc = void (*)(int queryItem, IntervalReply& queryRs); +using QueryDeadlineFunc = void (*)(int queryItem, DeadlineReply& ddlReply, const Json::Value& payload); +using RequestAuthFunc = void (*)(const Json::Value& payload); +using InitFunc = void (*)(); +using ReleaseFunc = void (*)(); +using CreateNewRtgGrpFunc = int (*)(int prioType, int rtNum); + +class TaskControllerInterface { +public: + static TaskControllerInterface& GetInstance(); + TaskControllerInterface(); + virtual ~TaskControllerInterface() = default; + void RequestAuth(const Json::Value& payload); + void ReportData(uint32_t resType, int64_t value, const Json::Value& payload); + void QueryInterval(int queryItem, IntervalReply& queryRs); + void QueryDeadline(int queryItem, DeadlineReply& ddlReply, const Json::Value& payload); + void Init(); + void Release(); + +private: + bool LoadFunc(); + FuncLoader funcLoader_; + std::mutex funcLoaderLock_; + bool inited_ = false; + + ReportDataFunc reportDataFunc_ = nullptr; + QueryIntervalFunc queryIntervalFunc_ = nullptr; + QueryDeadlineFunc queryDeadlineFunc_ = nullptr; + RequestAuthFunc requestAuthFunc_ = nullptr; + InitFunc initFunc_ = nullptr; + ReleaseFunc releaseFunc_ = nullptr; +}; +} // namespace ConcurrentTask +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/test/unittest/phone/config_reader_test.cpp b/services/include/func_loader.h similarity index 46% rename from test/unittest/phone/config_reader_test.cpp rename to services/include/func_loader.h index 7eb9119f15b1798c2d14e8de5f8d202afa35cf44..ba1d2816b87a7f602997a819761125edd0731a7f 100644 --- a/test/unittest/phone/config_reader_test.cpp +++ b/services/include/func_loader.h @@ -1,59 +1,39 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include "config_reader.h" -#include "gtest/gtest.h" - -namespace OHOS { -namespace FFRT_TEST { -using namespace testing; -using namespace testing::ext; -using namespace OHOS::ConcurrentTask; - -class ConfigReaderTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -void ConfigReaderTest::SetUpTestCase() -{ -} - -void ConfigReaderTest::TearDownTestCase() -{ -} - -void ConfigReaderTest::SetUp() -{ -} - -void ConfigReaderTest::TearDown() -{ -} - -/** - * @tc.name: ConfigReaderTest - * @tc.desc: Test whether the ConfigReader interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConfigReaderTest, ConfigReaderTest, TestSize.Level1) -{ -} -} -} \ No newline at end of file +/* + * Copyright (c) 2024 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_FUNC_LOADER_H +#define CONCURRENT_TASK_SEVICES_INCLUDE_FUNC_LOADER_H + +#include + +namespace OHOS { +namespace ConcurrentTask { +class FuncLoader { +public: + FuncLoader(const std::string& funcImplPath); + ~FuncLoader(); + void* LoadSymbol(const char* sysName); + bool GetLoadSuccess(); + +private: + void LoadFile(const char* fileName); + std::string funcImplPath_; + void* fileHandle_ = nullptr; + bool enable_ = false; +}; +} // namespace ConcurrentTask +} // namespace OHOS + +#endif // CONCURRENT_TASK_SEVICES_INCLUDE_FUNC_LOADER_H diff --git a/services/include/qos_interface.h b/services/include/qos_interface.h index 855b5d26e277038c4683ed2de60e2487c8f8b723..e871494808fc15f7ec3f552dcb94fd7be9af00a8 100644 --- a/services/include/qos_interface.h +++ b/services/include/qos_interface.h @@ -28,59 +28,11 @@ constexpr int ROOT_UID = 0; constexpr int NR_QOS = 7; constexpr unsigned int SET_RTG_ENABLE = 1; constexpr unsigned int QOS_CTRL_IPC_MAGIC = 0xCC; -constexpr unsigned int AUTH_CTRL_IPC_MAGIC = 0xCD; constexpr unsigned int RTG_SCHED_IPC_MAGIC = 0xAB; constexpr unsigned int AF_QOS_ALL = 0x0003; constexpr unsigned int AF_QOS_DELEGATED = 0x0001; -/* - * auth_ctrl - */ -struct AuthCtrlData { - unsigned int pid; - unsigned int type; - unsigned int rtgUaFlag; - unsigned int qosUaFlag; - unsigned int status; -#ifdef QOS_EXT_ENABLE - bool enhanceStatus; -#endif -}; - -enum class AuthManipulateType { - AUTH_ENABLE = 1, - AUTH_DELETE, - AUTH_GET, - AUTH_SWITCH, - AUTH_MAX_NR, -}; - -enum class AuthStatus { - AUTH_STATUS_DEFAULT = 1, - AUTH_STATUS_SYSTEM_SERVER = 2, - AUTH_STATUS_FOREGROUND = 3, - AUTH_STATUS_BACKGROUND = 4, - AUTH_STATUS_FOCUS = 5, - AUTH_STATUS_DEAD, -}; - -enum AuthCtrlCmdid { - BASIC_AUTH_CTRL = 1, -#ifdef QOS_EXT_ENABLE - ENHANCE_AUTH_CTRL = 2, -#endif - AUTH_CTRL_MAX_NR -}; - -#define BASIC_AUTH_CTRL_OPERATION \ - _IOWR(AUTH_CTRL_IPC_MAGIC, BASIC_AUTH_CTRL, struct AuthCtrlData) - -#ifdef QOS_EXT_ENABLE -#define ENHANCE_AUTH_CTRL_OPERATION \ - _IOWR(AUTH_CTRL_IPC_MAGIC, ENHANCE_AUTH_CTRL, struct AuthCtrlData) -#endif - /* * qos ctrl */ @@ -97,10 +49,9 @@ struct QosCtrlData { unsigned int level; int qos; #ifdef QOS_EXT_ENABLE - int qos; int staticQos; int dynamicQos; - bool tagSchedEnable = true; + bool tagSchedEnable = false; #endif }; @@ -158,13 +109,6 @@ enum QosCtrlCmdid { #define QOS_CTRL_POLICY_OPERATION \ _IOWR(QOS_CTRL_IPC_MAGIC, QOS_POLICY, struct QosPolicyDatas) -/* - * RTG - */ -#define AF_RTG_ALL 0x1fff -#define AF_RTG_DELEGATED 0x1fff -#define AF_RTG_APP 0x10b8 - struct RtgEnableData { int enable; int len; @@ -178,12 +122,6 @@ struct RtgEnableData { * interface */ int EnableRtg(bool flag); -int AuthEnable(unsigned int pid, unsigned int uaFlag, unsigned int status); -int AuthPause(unsigned int pid); -int AuthDelete(unsigned int pid); -int AuthGet(unsigned int pid); -int AuthSwitch(unsigned int pid, unsigned int rtgFlag, unsigned int qosFlag, unsigned int status); -int AuthEnhance(unsigned int pid, bool enhanceStatus); int QosApply(unsigned int level); int QosApplyForOther(unsigned int level, int tid); int QosLeave(void); diff --git a/services/src/concurrent_task_controller.cpp b/services/src/concurrent_task_controller.cpp deleted file mode 100644 index a0b1e2f0940ddc2181e97a82f59bee2355e816df..0000000000000000000000000000000000000000 --- a/services/src/concurrent_task_controller.cpp +++ /dev/null @@ -1,1095 +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 -#include -#include -#include -#include -#include -#include -#include "accesstoken_kit.h" -#include "concurrent_task_log.h" -#include "rtg_interface.h" -#include "ipc_skeleton.h" -#include "parameters.h" -#include "concurrent_task_controller.h" - -using namespace OHOS::RME; -using namespace OHOS::Security::AccessToken; - -namespace OHOS { -namespace ConcurrentTask { -namespace { - const std::string INTERVAL_DDL = "persist.ffrt.interval.renderthread"; - const std::string INTERVAL_APP_RATE = "persist.ffrt.interval.appRate"; - const std::string INTERVAL_RS_RATE = "persist.ffrt.interval.rsRate"; - const std::string CONFIG_FILE_NAME = "etc/qos_manager/qos_manager_config.xml"; - constexpr int CURRENT_RATE = 120; - constexpr int PARAM_TYPE = 1; - constexpr int UNI_APP_RATE_ID = -1; - const char RTG_SCHED_IPC_MAGIC = 0xAB; - constexpr int RTG_TYPE_MAX = 3; - constexpr int RS_UID = 1003; - constexpr int EXECUTOR_LIMIT_NUM = 3; -} - -#define CMD_ID_SET_RTG \ - _IOWR(RTG_SCHED_IPC_MAGIC, SET_RTG, struct rtg_str_data) - -TaskController& TaskController::GetInstance() -{ - static TaskController instance; - return instance; -} - -void TaskController::RequestAuth(const Json::Value& payload) -{ - { - std::lock_guard autolock(configReaderMutex_); - if (!configEnable_ && !ConfigReaderInit()) { - return; - } - } - pid_t uid = IPCSkeleton::GetInstance().GetCallingUid(); - auto bundleName = GetProcessNameByToken(); - if (configReader_->IsBundleNameAuth(bundleName) || configReader_->IsUidAuth(uid)) { - pid_t pid = IPCSkeleton::GetInstance().GetCallingPid(); - AuthSystemProcess(pid); - return; - } - CONCUR_LOGE("Invalid uid %{public}d, can't call RequestAuth", uid); -} - -void TaskController::ReportData(uint32_t resType, int64_t value, const Json::Value& payload) -{ - pid_t uid = IPCSkeleton::GetInstance().GetCallingUid(); - if (GetProcessNameByToken() != RESOURCE_SCHEDULE_PROCESS_NAME) { - CONCUR_LOGE("Invalid uid %{public}d, only RSS can call ReportData", uid); - return; - } - if (!CheckJsonValid(payload)) { - 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(); - pid_t pid = IPCSkeleton::GetInstance().GetCallingPid(); - 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_RENDER_SERVICE_MAIN: - QueryRenderServiceMain(uid, pid, queryRs); - break; - case QUERY_RENDER_SERVICE_RENDER: - QueryRenderServiceRender(uid, pid, queryRs); - break; - case QUERY_COMPOSER: - QueryHwc(uid, queryRs); - break; - case QUERY_HARDWARE: - QueryHardware(uid, pid, queryRs); - break; - case QUERY_EXECUTOR_START: - QueryExecutorStart(uid, pid, queryRs); - break; - default: - break; - } -} - -std::string TaskController::GetProcessNameByToken() -{ - AccessTokenID tokenID = IPCSkeleton::GetInstance().GetCallingTokenID(); - NativeTokenInfo tokenInfo; - if (AccessTokenKit::GetNativeTokenInfo(tokenID, tokenInfo) != AccessTokenKitRet::RET_SUCCESS) { - return ""; - } - return tokenInfo.processName; -} - -void TaskController::QueryUi(int uid, IntervalReply& queryRs) -{ - pid_t pid = IPCSkeleton::GetInstance().GetCallingPid(); - ForegroundAppRecord* record = GetRecordOfPid(pid); - if (!record) { - CONCUR_LOGD("Query ui with pid %{public}d failed", pid); - return; - } - int grpId = record->GetGrpId(); - if (grpId <= 0) { - CONCUR_LOGI("%{public}d Query ui with none grpid", pid); - queryRs.rtgId = -1; - } else { - queryRs.rtgId = grpId; - } - queryRs.bundleName = appBundleName[pid]; -} - -void TaskController::QueryRender(int uid, IntervalReply& queryRs) -{ - pid_t pid = IPCSkeleton::GetInstance().GetCallingPid(); - ForegroundAppRecord* record = GetRecordOfPid(pid); - if (!record) { - CONCUR_LOGD("Query render with pid %{public}d failed", pid); - return; - } - int grpId = record->GetGrpId(); - if (grpId <= 0) { - CONCUR_LOGI("%{public}d Query render with none grpid", pid); - queryRs.rtgId = -1; - } else { - queryRs.rtgId = grpId; - } -} - -void TaskController::QueryRenderService(int uid, IntervalReply& queryRs) -{ - if (uid != RS_UID) { - return; - } - int queryTid = queryRs.tid; - if (renderServiceMainGrpId_ <= 0) { - TryCreateRSMainGrp(); - CONCUR_LOGI("uid %{public}d query rs group failed and create %{public}d.", uid, renderServiceMainGrpId_); - if (renderServiceMainGrpId_ <= 0) { - CONCUR_LOGE("uid %{public}d create rs group failed", uid); - return; - } - } - - queryRs.rtgId = renderServiceMainGrpId_; - if (queryTid <= 0) { - return; - } - list::iterator iter = find(rsThreads_.begin(), rsThreads_.end(), queryTid); - if (iter != rsThreads_.end()) { - return; - } - queryRs.rtgId = renderServiceMainGrpId_; - int ret = AddThreadToRtg(queryTid, renderServiceMainGrpId_, PRIO_RT); - if (ret < 0) { - CONCUR_LOGE("uid %{public}d tid %{public}d join rs group failed", uid, queryTid); - return; - } - CONCUR_LOGI("uid %{public}d tid %{public}d join rs group success in Query", uid, queryTid); - SetFrameRateAndPrioType(renderServiceMainGrpId_, CURRENT_RATE, PARAM_TYPE); -} - -void TaskController::QueryRenderServiceMain(int uid, int pid, IntervalReply& queryRs) -{ - if (uid != RS_UID) { - return; - } - if (authedRSPid_ != pid) { - if (AuthSystemProcess(pid) != 0) { - return; - } - authedRSPid_ = pid; - } - if (renderServiceMainGrpId_ <= 0) { - TryCreateRSMainGrp(); - CONCUR_LOGI("uid %{public}d query rs group failed and create %{public}d.", uid, renderServiceMainGrpId_); - if (renderServiceMainGrpId_ <= 0) { - CONCUR_LOGE("uid %{public}d create rs group failed", uid); - return; - } - } - queryRs.rtgId = renderServiceMainGrpId_; - if (renderServiceMainTid_ <= 0) { - renderServiceMainTid_ = queryRs.tid; - int ret = AddThreadToRtg(renderServiceMainTid_, renderServiceMainGrpId_, PRIO_RT); - if (ret < 0) { - CONCUR_LOGE("uid %{public}d tid %{public}d join rs group failed.", uid, renderServiceMainTid_); - } - } - SetFrameRateAndPrioType(renderServiceMainGrpId_, CURRENT_RATE, PARAM_TYPE); -} - -void TaskController::QueryRenderServiceRender(int uid, int pid, IntervalReply& queryRs) -{ - if (uid != RS_UID) { - return; - } - if (renderServiceRenderGrpId_ <= 0) { - TryCreateRSRenderGrp(); - if (renderServiceRenderGrpId_ <= 0) { - CONCUR_LOGE("uid %{public}d create rs group failed", uid); - return; - } - } - queryRs.rtgId = renderServiceRenderGrpId_; - if (renderServiceRenderTid_ <= 0 || renderServiceRenderTid_ != queryRs.tid) { - renderServiceRenderTid_ = queryRs.tid; - int ret = AddThreadToRtg(renderServiceRenderTid_, renderServiceRenderGrpId_, PRIO_RT); - if (ret < 0) { - CONCUR_LOGE("uid %{public}d tid %{public}d join rs group failed.", uid, renderServiceMainGrpId_); - } - } - SetFrameRateAndPrioType(renderServiceRenderGrpId_, CURRENT_RATE, PARAM_TYPE); -} - -void TaskController::QueryHardware(int uid, int pid, IntervalReply& queryRs) -{ - if (uid != RS_UID) { - return; - } - if (hardwareGrpId_ < 0) { - return; - } - hardwareTid_ = queryRs.tid; - TryCreateRSMainGrp(); - int ret = AddThreadToRtg(hardwareTid_, renderServiceMainGrpId_, PRIO_RT); - if (ret < 0) { - CONCUR_LOGE("uid %{public}d tid %{public}d join hardware group failed.", uid, hardwareTid_); - return; - } - queryRs.rtgId = hardwareGrpId_; -} - -void TaskController::QueryExecutorStart(int uid, int pid, IntervalReply& queryRs) -{ - if (uid != RS_UID) { - return; - } - if (renderServiceMainGrpId_ < 0) { - return; - } - std::lock_guard lock(executorStartLock_); - if (executorNum_ >= EXECUTOR_LIMIT_NUM) { - return; - } - if (queryRs.tid <= 0) { - return; - } - int ret = AddThreadToRtg(queryRs.tid, renderServiceMainGrpId_, PRIO_RT); - if (ret < 0) { - CONCUR_LOGE("uid %{public}d tid %{public}d join executor group failed.", uid, renderServiceMainTid_); - return; - } - executorNum_++; - queryRs.rtgId = renderServiceMainGrpId_; -} - -void TaskController::QueryHwc(int uid, IntervalReply& queryRs) -{ - pid_t pid = IPCSkeleton::GetInstance().GetCallingPid(); - ForegroundAppRecord* record = GetRecordOfPid(pid); - if (!record) { - CONCUR_LOGD("Query ipc thread with pid %{public}d failed", pid); - return; - } - int grpId = record->GetGrpId(); - if (grpId <= 0) { - CONCUR_LOGI("%{public}d Query ipc thread with none grpid", pid); - queryRs.rtgId = -1; - } else { - queryRs.rtgId = grpId; - } -} - -void TaskController::Init() -{ - TypeMapInit(); - qosPolicy_.Init(); - TryCreateRsGroup(); - - std::lock_guard autolock(configReaderMutex_); - if (!configEnable_) { - ConfigReaderInit(); - } -} - -bool TaskController::ConfigReaderInit() -{ - configReader_ = make_unique(); - if (!configReader_) { - CONCUR_LOGE("configReader_ initialize error!"); - return configEnable_; - } - - std::string realPath; - configReader_->GetRealConfigPath(CONFIG_FILE_NAME.c_str(), realPath); - if (realPath.empty() || !configReader_->LoadFromConfigFile(realPath)) { - CONCUR_LOGE("config load failed!"); - return configEnable_; - } - configEnable_ = true; - ddlSceneSchedSwitch_ = configReader_->GetPowerModeSchedSwitch(); - CONCUR_LOGI("deadline scene sched switch = %{public}d", ddlSceneSchedSwitch_); - return configEnable_; -} - -void TaskController::Release() -{ - msgType_.clear(); - if (renderServiceMainGrpId_ > 0) { - DestroyRtgGrp(renderServiceMainGrpId_); - renderServiceMainGrpId_ = -1; - } - if (renderServiceRenderGrpId_ > 0) { - DestroyRtgGrp(renderServiceRenderGrpId_); - renderServiceRenderGrpId_ = -1; - } - ddlSceneSchedSwitch_ = false; - - std::lock_guard autolock(configReaderMutex_); - configReader_ = nullptr; -} - -void TaskController::TypeMapInit() -{ - msgType_.clear(); - msgType_.insert(pair("foreground", MSG_FOREGROUND)); - msgType_.insert(pair("background", MSG_BACKGROUND)); - msgType_.insert(pair("appStart", MSG_APP_START)); - msgType_.insert(pair("appKilled", MSG_APP_KILLED)); - msgType_.insert(pair("continuousStart", MSG_CONTINUOUS_TASK_START)); - msgType_.insert(pair("continuousEnd", MSG_CONTINUOUS_TASK_END)); - msgType_.insert(pair("getFocus", MSG_GET_FOCUS)); - msgType_.insert(pair("loseFocus", MSG_LOSE_FOCUS)); - msgType_.insert(pair("enterInteractionScene", MSG_ENTER_INTERACTION_SCENE)); - msgType_.insert(pair("exitInteractionScene", MSG_EXIT_INTERACTION_SCENE)); -} - -void TaskController::TryCreateRSMainGrp() -{ - if (renderServiceMainGrpId_ == -1) { - renderServiceMainGrpId_ = TryCreateSystemGroup(); - hardwareGrpId_ = renderServiceMainGrpId_; - } -} - -void TaskController::TryCreateRSRenderGrp() -{ - if (renderServiceRenderGrpId_ == -1) { - renderServiceRenderGrpId_ = TryCreateSystemGroup(); - } -} - -void TaskController::TryCreateRsGroup() -{ - TryCreateRSMainGrp(); - TryCreateRSRenderGrp(); -} - -int TaskController::TryCreateSystemGroup() -{ - if (!rtgEnabled_) { - rtgEnabled_ = EnableRtg(true) < 0 ? false : true; - if (!rtgEnabled_) { - CONCUR_LOGE("Rtg enable failed"); - return -1; - } - CONCUR_LOGI("Enable Rtg"); - } - int grpId = CreateNewRtgGrp(PRIO_RT, MAX_KEY_THREADS); - if (grpId <= 0) { - CONCUR_LOGI("CreateRsRtgGroup with RT failed, try change to normal type."); - grpId = CreateNewRtgGrp(PRIO_NORMAL, MAX_KEY_THREADS); - } - if (grpId <= 0) { - CONCUR_LOGI("CreateRsRtgGroup failed! rtGrp:%{public}d", grpId); - return -1; - } - return grpId; -} - -int TaskController::GetRequestType(std::string strRequstType) -{ - auto iter = msgType_.find(strRequstType); - if (iter == msgType_.end()) { - return MSG_TYPE_MAX; - } - return msgType_[strRequstType]; -} - -bool TaskController::ParsePayload(const Json::Value& payload, int& uid, int& pid, std::string& bundleName) -{ - try { - uid = stoi(payload["uid"].asString()); - pid = stoi(payload["pid"].asString()); - bundleName = payload["bundleName"].asString(); - } catch(...) { - CONCUR_LOGE("Unexpected uid or pid format"); - return false; - } - if (uid > 0 && pid > 0) { - return true; - } - return false; -} - -void TaskController::DealSystemRequest(int requestType, const Json::Value& payload) -{ - int uid = -1; - int pid = -1; - std::string bundleName = ""; - if (!ParsePayload(payload, uid, pid, bundleName)) { - return; - } - switch (requestType) { - case MSG_FOREGROUND: - NewForeground(uid, pid); - break; - case MSG_BACKGROUND: - NewBackground(uid, pid); - break; - case MSG_APP_START: - NewAppStart(uid, pid, bundleName); - break; - case MSG_APP_KILLED: - AppKilled(uid, pid); - break; - case MSG_CONTINUOUS_TASK_START: - case MSG_CONTINUOUS_TASK_END: - ContinuousTaskProcess(uid, pid, requestType); - break; - case MSG_GET_FOCUS: - case MSG_LOSE_FOCUS: - FocusStatusProcess(uid, pid, requestType); - break; - case MSG_ENTER_INTERACTION_SCENE: - case MSG_EXIT_INTERACTION_SCENE: - InteractionSceneProcess(requestType); - break; - default: - CONCUR_LOGE("Unknown system request"); - break; - } -} - -ForegroundAppRecord* TaskController::GetRecordOfPid(int pid) -{ - std::lock_guard lock(appInfoLock_); - for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) { - if (iter->GetPid() == pid) { - return &*iter; - } - } - return nullptr; -} - -void TaskController::NewForeground(int uid, int pid) -{ - int uiTid = pid; - auto it = find(authApps_.begin(), authApps_.end(), pid); - if (it == authApps_.end()) { - CONCUR_LOGI("un-authed pid %{public}d", pid); - return; - } - int ret = AuthGet(pid); - if (ret != static_cast(AuthStatus::AUTH_STATUS_FOCUS)) { - CONCUR_LOGI("pid %{public}d change to foreground.", pid); - unsigned int pidParam = static_cast(pid); - unsigned int uaFlag = AF_RTG_APP; - unsigned int status = static_cast(AuthStatus::AUTH_STATUS_FOREGROUND); - int ret = AuthEnable(pidParam, uaFlag, status); - if (ret == 0) { - CONCUR_LOGI("auth_enable %{public}d success", pid); - } else { - CONCUR_LOGE("auth_enable %{public}d fail with ret %{public}d", pid, ret); - } - } else { - CONCUR_LOGI("pid %{public}d is already focus", pid); - } - bool found = false; - bool ddlEnabled = OHOS::system::GetBoolParameter(INTERVAL_DDL, false); - std::lock_guard lock(appInfoLock_); - for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) { - if (iter->GetPid() == pid) { - found = true; - if (ddlEnabled && pid != curGamePid_) { - iter->AddKeyThread(uiTid, PRIO_RT); - } - iter->BeginScene(); - break; - } - } - if (!found) { - NewForegroundAppRecord(pid, uiTid, ddlEnabled); - } -} - -void TaskController::NewForegroundAppRecord(int pid, int uiTid, bool ddlEnabled) -{ - ForegroundAppRecord& appRecord = foregroundApp_.emplace_back(pid, uiTid, pid != curGamePid_); - if (foregroundApp_.size() <= 0 || appRecord.GetPid() != pid) { - CONCUR_LOGE("pid %{public}d create app record failed", pid); - return; - } - if (appRecord.IsValid()) { - if (ddlEnabled && pid != curGamePid_) { - appRecord.AddKeyThread(uiTid, PRIO_RT); - } - appRecord.BeginScene(); - } -} - -void TaskController::NewBackground(int uid, int pid) -{ - auto it = find(authApps_.begin(), authApps_.end(), pid); - if (it == authApps_.end()) { - CONCUR_LOGI("un-authed pid %{public}d", pid); - return; - } - CONCUR_LOGI("pid %{public}d change to background.", pid); - unsigned int pidParam = static_cast(pid); - - int ret = AuthPause(pidParam); - if (ret == 0) { - CONCUR_LOGI("auth_pause %{public}d success", pid); - } else { - CONCUR_LOGI("auth_pause %{public}d fail with %{public}d", pid, ret); - } - std::lock_guard lock(appInfoLock_); - for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) { - if (iter->GetPid() == pid) { - iter->EndScene(); - return; - } - } -} - -void TaskController::NewAppStart(int uid, int pid, const std::string& bundleName) -{ - CONCUR_LOGI("pid %{public}d start.", pid); - unsigned int pidParam = static_cast(pid); - unsigned int uaFlag = AF_RTG_APP; - unsigned int status = static_cast(AuthStatus::AUTH_STATUS_DEFAULT); - - int ret = AuthEnable(pidParam, uaFlag, status); - if (ret == 0) { - CONCUR_LOGI("auth_enable %{public}d success", pid); - } else { - CONCUR_LOGE("auth_enable %{public}d fail with ret %{public}d", pid, ret); - return; - } - std::lock_guard lock(appInfoLock_); - authApps_.push_back(pid); - appBundleName[pid] = bundleName; -} - -void TaskController::AppKilled(int uid, int pid) -{ - CONCUR_LOGI("pid %{public}d killed.", pid); - unsigned int pidParam = static_cast(pid); - int ret = AuthDelete(pidParam); - if (ret == 0) { - CONCUR_LOGI("auth_delete %{public}d success", pid); - } else { - CONCUR_LOGE("auth_delete %{public}d fail with %{public}d", pid, ret); - } - std::lock_guard lock(appInfoLock_); - for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) { - if (iter->GetPid() == pid) { - foregroundApp_.erase(iter); - break; - } - } - for (auto iter = authApps_.begin(); iter != authApps_.end(); iter++) { - if (*iter == pid) { - authApps_.erase(iter); - break; - } - } - appBundleName.erase(pid); -} - -int TaskController::AuthSystemProcess(int pid) -{ - unsigned int uaFlag = AF_RTG_ALL; - unsigned int status = static_cast(AuthStatus::AUTH_STATUS_SYSTEM_SERVER); - int ret = AuthEnable(pid, uaFlag, status); - if (ret == 0) { - CONCUR_LOGI("auth process %{public}d success", pid); - } else { - CONCUR_LOGI("auth process %{public}d failed, ret %{public}d", pid, ret); - } - return ret; -} - -void TaskController::ContinuousTaskProcess(int uid, int pid, int status) -{ - int ret = -1; - if (status == static_cast(MSG_CONTINUOUS_TASK_START)) { - ret = AuthEnhance(pid, true); - CONCUR_LOGI("auth_enhance pid %{public}d start, ret %{public}d", pid, ret); - } else if (status == static_cast(MSG_CONTINUOUS_TASK_END)) { - ret = AuthEnhance(pid, false); - CONCUR_LOGI("auth_enhance pid %{public}d end, ret %{public}d", pid, ret); - } else { - CONCUR_LOGE("Invalid auth_enhance status %{public}d", status); - } -} - -void TaskController::FocusStatusProcess(int uid, int pid, int status) -{ - int ret = -1; - unsigned int rtgFlag = AF_RTG_APP; - unsigned int qosFlag = AF_QOS_DELEGATED; - if (status == static_cast(MSG_GET_FOCUS)) { - ret = AuthSwitch(pid, rtgFlag, qosFlag, static_cast(AuthStatus::AUTH_STATUS_FOCUS)); - CONCUR_LOGI("pid %{public}d get focus. ret %{public}d", pid, ret); - } else if (status == static_cast(MSG_LOSE_FOCUS)) { - ret = AuthSwitch(pid, rtgFlag, qosFlag, static_cast(AuthStatus::AUTH_STATUS_FOREGROUND)); - CONCUR_LOGI("pid %{public}d lose focus. ret %{public}d", pid, ret); - } else { - CONCUR_LOGE("Invalid focus status %{public}d", status); - } -} - -void TaskController::InteractionSceneProcess(int status) -{ - std::lock_guard lock(ddlPowerModeLock_); - if (ddlSceneSchedSwitch_) { - if (status == MSG_ENTER_INTERACTION_SCENE) { - DeadlinePerfMode(); - } else if (status == MSG_EXIT_INTERACTION_SCENE) { - DeadlinePowerMode(); - } - } -} - -void TaskController::DeadlinePerfMode() -{ - if (ddlPowerModeEnable_) { - StartTrace(HITRACE_TAG_ACE, "Deadline perf mode"); - SetAppAndRenderServiceRate(uniAppRate_, systemRate_); - ddlPowerModeEnable_ = false; - CONCUR_LOGI("Deadline switch to perf mode"); - FinishTrace(HITRACE_TAG_ACE); - } -} - -void TaskController::DeadlinePowerMode() -{ - if (!ddlPowerModeEnable_) { - StartTrace(HITRACE_TAG_ACE, "Deadline power mode"); - int appRate = uniAppRate_; - int rsRate = systemRate_; - if (configEnable_ && configReader_) { - appRate = configReader_->GetDegratationFps(appRate); - rsRate = configReader_->GetDegratationFps(rsRate); - } - SetAppAndRenderServiceRate(appRate, rsRate); - ddlPowerModeEnable_ = true; - CONCUR_LOGI("Deadline switch to power mode"); - FinishTrace(HITRACE_TAG_ACE); - } -} -void TaskController::QueryDeadline(int queryItem, DeadlineReply& ddlReply, const Json::Value& payload) -{ - pid_t uid = IPCSkeleton::GetInstance().GetCallingUid(); - std::string processName = GetProcessNameByToken(); - if (processName != RENDER_SERVICE_PROCESS_NAME && processName != GAME_ACCELERATE_SCHED_PROCESS_NAME) { - CONCUR_LOGE("Invalid uid %{public}d, only RS or RSS can call QueryDeadline", uid); - return; - } - switch (queryItem) { - case DDL_RATE: { - ModifySystemRate(payload); - break; - } - case MSG_GAME: { - ModifyGameState(payload); - break; - } - default: { - break; - } - } -} - -void TaskController::ModifyGameState(const Json::Value& payload) -{ - if (!CheckJsonValid(payload)) { - CONCUR_LOGE("[MSG_GAME]receive json invalid"); - return; - } - if (payload["gameMsg"].isNull()) { - CONCUR_LOGE("[MSG_GAME]message is null"); - return; - } - std::string gameMsg = payload["gameMsg"].asString(); - int oldGamePid = curGamePid_; - int newGamePid = GetGamePid(gameMsg); - curGamePid_ = newGamePid; - CONCUR_LOGI("[MSG_GAME]current game pid is %{public}d, old game pid is %{public}d", - newGamePid, oldGamePid); - if (curGamePid_ == -1) { - return; - } - std::lock_guard lock(appInfoLock_); - for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) { - if (iter->GetPid() == curGamePid_ && iter->GetGrpId() >= 0) { - CONCUR_LOGI("[MSG_GAME]destroy rtg grp, pid is %{public}d grpId is %{public}d", - iter->GetPid(), iter->GetGrpId()); - DestroyRtgGrp(iter->GetGrpId()); - iter->SetGrpId(-1); - break; - } - } - return; -} - -int TaskController::GetGamePid(const std::string &gameMsg) const -{ - GameStatus status = GetGameScene(gameMsg); - CONCUR_LOGI("[MSG_GAME]gamescene status %{public}d", status); - int gamePid = -1; - if (status == GAME_ENTRY_MSG) { - size_t pos = gameMsg.find(","); - if (pos == string::npos) { - return -1; - } - int ret = sscanf_s(gameMsg.substr(0, pos).c_str(), "{\"gamePid\":\"%d\"", &gamePid); - if (ret <= 0) { - CONCUR_LOGE("[MSG_GAME]message parsing failed, ret is %{public}d", ret); - } else { - CONCUR_LOGI("[MSG_GAME]message parsing success"); - } - } - return gamePid; -} - -GameStatus TaskController::GetGameScene(const std::string &gameMsg) const -{ - if (gameMsg.find("gameScene\":\"1") != std::string::npos) { - return GAME_ENTRY_MSG; - } - if (gameMsg.find("gameScene\":\"0") != std::string::npos) { - return GAME_EXIT_MSG; - } - if (gameMsg.find("cameraScene\":\"1") != std::string::npos) { - return CAMERA_ENTRY_MSG; - } - if (gameMsg.find("cameraScene\":\"0") != std::string::npos) { - return CAMERA_EXIT_MSG; - } - if (gameMsg.find("GTXGamePid\":") != std::string::npos) { - return GAME_GTX_MSG; - } - return STATUS_MSG_MAX; -} - -bool TaskController::ModifySystemRate(const Json::Value& payload) -{ - if (!CheckJsonValid(payload)) { - CONCUR_LOGI("service receive json invalid"); - return false; - } - SetAppRate(payload); - SetRenderServiceRate(payload); - return true; -} - -void TaskController::SetAppRate(const Json::Value& payload) -{ - int rtgId = 0; - int uiTid = 0; - int appRate = FindRateFromInfo(UNI_APP_RATE_ID, payload); - if (appRate > 0 && appRate != uniAppRate_) { - CONCUR_LOGD("set unified app rate %{public}d", appRate); - uniAppRate_ = appRate; - if (ddlSceneSchedSwitch_ && ddlPowerModeEnable_ && configEnable_ && configReader_) { - appRate = configReader_->GetDegratationFps(appRate); - } - bool ret = OHOS::system::SetParameter(INTERVAL_APP_RATE, std::to_string(appRate)); - if (ret == false) { - CONCUR_LOGI("set app rate param failed"); - } - StartTrace(HITRACE_TAG_ACE, - "SetAppRate:" + std::to_string(appRate) + " ret:" + std::to_string(ret)); - FinishTrace(HITRACE_TAG_ACE); - return; - } - std::lock_guard lock(appInfoLock_); - for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) { - uiTid = iter->GetUiTid(); - rtgId = iter->GetGrpId(); - if (uiTid <= 0 || rtgId <= 0) { - continue; - } - appRate = FindRateFromInfo(uiTid, payload); - if (appRate > 0 && appRate != iter->GetRate()) { - CONCUR_LOGI("set app rate %{public}d rtgId is %{public}d, old rate is %{public}d", - appRate, rtgId, iter->GetRate()); - SetFrameRate(rtgId, appRate); - iter->SetRate(appRate); - } - } - return; -} - -int TaskController::FindRateFromInfo(int uiTid, const Json::Value& payload) -{ - int appRate = 0; - if (payload[std::to_string(uiTid)].isNull()) { - CONCUR_LOGD("FindRateFromInfo tid %{public}d is null", uiTid); - return appRate; - } - try { - appRate = stoi(payload[std::to_string(uiTid)].asString()); - } catch (...) { - CONCUR_LOGI("application %{public}d is not in rtg_group", uiTid); - } - return appRate; -} - -void TaskController::SetRenderServiceRate(const Json::Value& payload) -{ - int rsRate = FindRateFromInfo(renderServiceMainTid_, payload); - std::lock_guard lock(rateInfoLock_); - if (renderServiceMainGrpId_ > 0 && rsRate > 0 && rsRate != systemRate_) { - CONCUR_LOGD("set rs rate %{public}d rtgId is %{public}d, old rate is %{public}d", - rsRate, renderServiceMainGrpId_, systemRate_); - SetFrameRate(renderServiceMainGrpId_, rsRate); - systemRate_ = rsRate; - if (ddlSceneSchedSwitch_ && ddlPowerModeEnable_ && configEnable_ && configReader_) { - rsRate = configReader_->GetDegratationFps(rsRate); - } - bool ret = OHOS::system::SetParameter(INTERVAL_RS_RATE, std::to_string(rsRate)); - if (ret == false) { - CONCUR_LOGI("set rs rate param failed"); - } - StartTrace(HITRACE_TAG_ACE, - "SetRSRate:" + std::to_string(rsRate) + " ret:" + std::to_string(ret)); - FinishTrace(HITRACE_TAG_ACE); - } -} - -void TaskController::SetAppAndRenderServiceRate(int appRate, int rsRate) -{ - bool ret = OHOS::system::SetParameter(INTERVAL_APP_RATE, std::to_string(appRate)); - if (ret == false) { - CONCUR_LOGI("set app rate param failed"); - } - StartTrace(HITRACE_TAG_ACE, - "SetAppRate:" + std::to_string(appRate) + " ret:" + std::to_string(ret)); - FinishTrace(HITRACE_TAG_ACE); - - ret = OHOS::system::SetParameter(INTERVAL_RS_RATE, std::to_string(rsRate)); - if (ret == false) { - CONCUR_LOGI("set rs rate param failed"); - } - StartTrace(HITRACE_TAG_ACE, - "SetRSRate:" + std::to_string(rsRate) + " ret:" + std::to_string(ret)); - FinishTrace(HITRACE_TAG_ACE); -} - -bool TaskController::CheckJsonValid(const Json::Value& payload) -{ - Json::ValueType type = payload.type(); - if (type != Json::objectValue) { - CONCUR_LOGE("error payload"); - return false; - } - if (payload.empty()) { - CONCUR_LOGI("payload empty"); - return false; - } - return true; -} - -void TaskController::SetFrameRate(int rtgId, int rate) -{ - if (rtgId > 0) { - SetFrameRateAndPrioType(rtgId, rate, PARAM_TYPE); - } -} - -void TaskController::PrintInfo() -{ - std::lock_guard lock(appInfoLock_); - for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) { - iter->PrintKeyThreads(); - } -} - -int TaskController::CreateNewRtgGrp(int prioType, int rtNum) -{ - struct rtg_grp_data grp_data; - int ret; - char fileName[] = "/proc/self/sched_rtg_ctrl"; - int fd = open(fileName, O_RDWR); - if (fd < 0) { - CONCUR_LOGE("Open file /proc/self/sched_rth_ctrl, errno = %{public}d", errno); - return fd; - } - (void)memset_s(&grp_data, sizeof(struct rtg_grp_data), 0, sizeof(struct rtg_grp_data)); - if ((prioType > 0) && (prioType < RTG_TYPE_MAX)) { - grp_data.prio_type = prioType; - } - if (rtNum > 0) { - grp_data.rt_cnt = rtNum; - } - grp_data.rtg_cmd = CMD_CREATE_RTG_GRP; - ret = ioctl(fd, CMD_ID_SET_RTG, &grp_data); - if (ret <= 0) { - CONCUR_LOGE("create rtg grp failed, errno = %{public}d (%{public}s)", errno, strerror(errno)); - } else { - CONCUR_LOGI("create rtg grp success, get rtg id %{public}d.", ret); - } - close(fd); - return ret; -} - -ForegroundAppRecord::ForegroundAppRecord(int pid, int uiTid, bool createGrp) -{ - pid_ = pid; - uiTid_ = uiTid; - if (OHOS::system::GetBoolParameter(INTERVAL_DDL, false) && createGrp) { - grpId_ = TaskController::GetInstance().CreateNewRtgGrp(PRIO_RT, MAX_KEY_THREADS); - } else { - grpId_ = -1; - } -} - -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, tid is %{public}d", tid); - 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. ret is %{public}d", ret); - } else { - CONCUR_LOGI("Add key thread %{public}d", tid); - } - keyThreads_.insert(tid); - } -} - -bool ForegroundAppRecord::BeginScene() -{ - if (grpId_ <= 0) { - CONCUR_LOGI("Error begin scene in pid %{public}d", pid_); - return false; - } - OHOS::RME::BeginFrameFreq(0); - OHOS::RME::EndFrameFreq(0); - return true; -} - -bool ForegroundAppRecord::EndScene() -{ - if (grpId_ <= 0) { - CONCUR_LOGI("Error end scene loss grpId_ in pid %{public}d", pid_); - return false; - } - OHOS::RME::EndScene(grpId_); - return true; -} - -int ForegroundAppRecord::GetPid() const -{ - return pid_; -} - -int ForegroundAppRecord::GetGrpId() const -{ - return grpId_; -} - -void ForegroundAppRecord::SetGrpId(int grpId) -{ - grpId_ = grpId; -} - -void ForegroundAppRecord::SetRate(int appRate) -{ - rate_ = appRate; -} - -int ForegroundAppRecord::GetRate() const -{ - return rate_; -} - -void ForegroundAppRecord::SetUiTid(int uiTid) -{ - uiTid_ = uiTid; -} - -int ForegroundAppRecord::GetUiTid() const -{ - return uiTid_; -} - -bool ForegroundAppRecord::IsValid() -{ - if (pid_ > 0) { - return true; - } - return false; -} - -void ForegroundAppRecord::PrintKeyThreads() -{ - std::string strLog = "pid "; - strLog.append(std::to_string(pid_)); - 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 diff --git a/services/src/concurrent_task_controller_interface.cpp b/services/src/concurrent_task_controller_interface.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b2f080cfad0ba3e36a19e1537d2a5c2b4c16440d --- /dev/null +++ b/services/src/concurrent_task_controller_interface.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2024 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_controller_interface.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "accesstoken_kit.h" +#include "concurrent_task_log.h" +#include "concurrent_task_type.h" +#include "ipc_skeleton.h" +#include "parameter.h" +#include "rtg_interface.h" + +namespace OHOS { +namespace ConcurrentTask { +TaskControllerInterface::TaskControllerInterface() : funcLoader_("libtask_controller.z.so") {} + +TaskControllerInterface& TaskControllerInterface::GetInstance() +{ + static TaskControllerInterface instance; + return instance; +} + +void TaskControllerInterface::RequestAuth(const Json::Value& payload) +{ + if (!inited_) { + CONCUR_LOGE("[TaskControllerInterface] RequestAuth failed, funcLoader_ load func failed"); + return; + } + requestAuthFunc_(payload); +} + +void TaskControllerInterface::ReportData(uint32_t resType, int64_t value, const Json::Value& payload) +{ + if (!inited_) { + CONCUR_LOGE("[TaskControllerInterface] ReportData failed, funcLoader_ load func failed"); + return; + } + reportDataFunc_(resType, value, payload); +} + +void TaskControllerInterface::QueryInterval(int queryItem, IntervalReply& queryRs) +{ + if (!inited_) { + CONCUR_LOGE("[TaskControllerInterface] QueryInterval failed, funcLoader_ load func failed"); + return; + } + queryIntervalFunc_(queryItem, queryRs); +} + +void TaskControllerInterface::QueryDeadline(int queryItem, DeadlineReply& ddlReply, const Json::Value& payload) +{ + if (!inited_) { + CONCUR_LOGE("[TaskControllerInterface] QueryDeadline failed, funcLoader_ load func failed"); + return; + } + queryDeadlineFunc_(queryItem, ddlReply, payload); +} + +void TaskControllerInterface::Init() +{ + std::lock_guard autoLock(funcLoaderLock_); + if (inited_) { + return; + } + if (!LoadFunc()) { + CONCUR_LOGE("TaskControllerInterface load function failed."); + return; + } + CONCUR_LOGI("TaskControllerInterface load function success."); + inited_ = true; + initFunc_(); +} + +void TaskControllerInterface::Release() +{ + if (!inited_) { + CONCUR_LOGE("[TaskControllerInterface] Release failed, funcLoader_ load func failed"); + return; + } + releaseFunc_(); +} + +bool TaskControllerInterface::LoadFunc() +{ + reportDataFunc_ = ReportDataFunc(funcLoader_.LoadSymbol("ReportData")); + queryIntervalFunc_ = QueryIntervalFunc(funcLoader_.LoadSymbol("QueryInterval")); + queryDeadlineFunc_ = QueryDeadlineFunc(funcLoader_.LoadSymbol("QueryDeadline")); + requestAuthFunc_ = RequestAuthFunc(funcLoader_.LoadSymbol("RequestAuth")); + initFunc_ = InitFunc(funcLoader_.LoadSymbol("Init")); + releaseFunc_ = ReleaseFunc(funcLoader_.LoadSymbol("Release")); + + return funcLoader_.GetLoadSuccess(); +} +} // namespace ConcurrentTask +} // namespace OHOS \ No newline at end of file diff --git a/services/src/concurrent_task_service.cpp b/services/src/concurrent_task_service.cpp index 4302e894c7672d31caf19777e0cafae8761e79c7..6627ef2d7a9531932705c7f911dc6f69398ea251 100644 --- a/services/src/concurrent_task_service.cpp +++ b/services/src/concurrent_task_service.cpp @@ -14,28 +14,29 @@ */ #include "concurrent_task_service.h" -#include "concurrent_task_controller.h" + +#include "concurrent_task_controller_interface.h" namespace OHOS { namespace ConcurrentTask { void ConcurrentTaskService::ReportData(uint32_t resType, int64_t value, const Json::Value& payload) { - TaskController::GetInstance().ReportData(resType, value, payload); + TaskControllerInterface::GetInstance().ReportData(resType, value, payload); } void ConcurrentTaskService::QueryInterval(int queryItem, IntervalReply& queryRs) { - TaskController::GetInstance().QueryInterval(queryItem, queryRs); + TaskControllerInterface::GetInstance().QueryInterval(queryItem, queryRs); } void ConcurrentTaskService::QueryDeadline(int queryItem, DeadlineReply& queryRs, const Json::Value& payload) { - TaskController::GetInstance().QueryDeadline(queryItem, queryRs, payload); + TaskControllerInterface::GetInstance().QueryDeadline(queryItem, queryRs, payload); } void ConcurrentTaskService::RequestAuth(const Json::Value& payload) { - TaskController::GetInstance().RequestAuth(payload); + TaskControllerInterface::GetInstance().RequestAuth(payload); } } // namespace ConcurrentTask diff --git a/services/src/concurrent_task_service_ability.cpp b/services/src/concurrent_task_service_ability.cpp index e3edd1f4ee00a5cfe72ebaa358cca948ffb0701d..a2a06910067fe3f062f03c15f3f187b7a56e9162 100644 --- a/services/src/concurrent_task_service_ability.cpp +++ b/services/src/concurrent_task_service_ability.cpp @@ -15,7 +15,7 @@ #include "concurrent_task_service_ability.h" #include "concurrent_task_log.h" -#include "concurrent_task_controller.h" +#include "concurrent_task_controller_interface.h" #include "concurrent_task_service.h" #include "system_ability_definition.h" @@ -25,7 +25,7 @@ REGISTER_SYSTEM_ABILITY_BY_ID(ConcurrentTaskServiceAbility, CONCURRENT_TASK_SERV void ConcurrentTaskServiceAbility::OnStart() { - TaskController::GetInstance().Init(); + TaskControllerInterface::GetInstance().Init(); if (!service_) { try { service_ = new ConcurrentTaskService(); @@ -41,7 +41,7 @@ void ConcurrentTaskServiceAbility::OnStart() void ConcurrentTaskServiceAbility::OnStop() { - TaskController::GetInstance().Release(); + TaskControllerInterface::GetInstance().Release(); CONCUR_LOGI("ConcurrentTaskServiceAbility::OnStop!"); } diff --git a/services/src/concurrent_task_service_stub.cpp b/services/src/concurrent_task_service_stub.cpp index c33ec9bf227f0c2ef452fe1407c629d65ffb6e8d..6bcf9bd75ce37241beceb9e2be60503f89d43164 100644 --- a/services/src/concurrent_task_service_stub.cpp +++ b/services/src/concurrent_task_service_stub.cpp @@ -71,7 +71,7 @@ int32_t ConcurrentTaskServiceStub::QueryIntervalInner(MessageParcel& data, [[may queryRs.tid = -1; queryRs.paramA = -1; queryRs.paramB = -1; - if (!data.ReadInt32(item) || !data.ReadInt32(queryRs.tid)) { + if (!data.ReadInt32(item) || !data.ReadInt32(queryRs.tid) || !data.ReadInt32(queryRs.paramA)) { CONCUR_LOGE("Read info failed in QueryInterval Stub"); return IPC_STUB_ERR; } diff --git a/common/include/config_reader.h b/services/src/func_loader.cpp similarity index 30% rename from common/include/config_reader.h rename to services/src/func_loader.cpp index fb78112562198955b11e6b6acc4b57ebce7ab433..6430a76a9b4e69e62898bc49419f501a1ed7c32e 100644 --- a/common/include/config_reader.h +++ b/services/src/func_loader.cpp @@ -12,39 +12,73 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef CONCURRENT_TASK_SERVICES_COMMON_INCLUDE_CONFIG_READER_H -#define CONCURRENT_TASK_SERVICES_COMMON_INCLUDE_CONFIG_READER_H -#include -#include -#include -#include "libxml/parser.h" -#include "libxml/xpath.h" +#include "func_loader.h" + +#include +#include +#include +#include +#include +#include + +#include "concurrent_task_log.h" namespace OHOS { namespace ConcurrentTask { -class ConfigReader { -public: - bool LoadFromConfigFile(const std::string& configFile); - void GetRealConfigPath(const char* configName, std::string& configPath); - bool IsUidAuth(pid_t uid); - bool IsBundleNameAuth(std::string& bundleName); - bool GetPowerModeSchedSwitch(); - int GetDegratationFps(int fps); -private: - bool IsValidNode(const xmlNode* currNode); - bool IsValidFps(const std::string& fps); - bool IsPositiveInt(const std::string& intStr); - bool FillinUidInfo(const xmlNode* currNode); - bool FillinBundleNameInfo(const xmlNode* currNode); - void ParseAuth(const xmlNode* currNode); - void ParsePowerMode(const xmlNode* currNode); - void ConfigHilog(); - bool powerModeSchedSwitch_ = false; - std::unordered_set authProcUidConfigs_; - std::unordered_set authProcBundleNameConfigs_; - std::map degradationFpsMap_; -}; +FuncLoader::FuncLoader(const std::string& funcImplPath) : funcImplPath_(funcImplPath) +{ + LoadFile(funcImplPath_.c_str()); +} + +FuncLoader::~FuncLoader() +{ + if (fileHandle_ != nullptr) { + dlclose(fileHandle_); + } + fileHandle_ = nullptr; +} + +void FuncLoader::LoadFile(const char* fileName) +{ + if (!fileName || strlen(fileName) == 0 || strlen(fileName) > PATH_MAX) { + CONCUR_LOGE("%{public}s, load %{pulibc}s file fail", __func__, fileName); + return; + } + const char* preFix = "lib"; + if (strncmp(fileName, preFix, strlen(preFix)) != 0) { + CONCUR_LOGE("invailed fileName!"); + return; + } + fileHandle_ = dlopen(fileName, RTLD_LAZY); + if (fileHandle_ == nullptr) { + enable_ = false; + CONCUR_LOGE("dlopen %{public}s ffail", fileName); + return; + } + CONCUR_LOGD("%{public}s, load %{pulibc}s file success", __func__, fileName); + enable_ = true; +} + +void* FuncLoader::LoadSymbol(const char* sysName) +{ + if (!enable_) { + return nullptr; + } + void* funcSym = dlsym(fileHandle_, sysName); + if (funcSym == nullptr) { + CONCUR_LOGE("dlsym func %{public}s fail", sysName); + enable_ = false; + return nullptr; + } + CONCUR_LOGD("dlsym func %{public}s success", sysName); + return funcSym; +} + +bool FuncLoader::GetLoadSuccess() +{ + return enable_; +} + } // namespace ConcurrentTask -} // namespace OHOS -#endif // CONCURRENT_TASK_SERVICES_COMMON_INCLUDE_CONFIG_READER_H +} // namespace OHOS \ No newline at end of file diff --git a/services/src/qos_interface.cpp b/services/src/qos_interface.cpp index b970b4b144878fe3a0ae8e812e64589e3441bfce..ebabca7480befd3205e18464dc32a26693aba356 100644 --- a/services/src/qos_interface.cpp +++ b/services/src/qos_interface.cpp @@ -16,14 +16,17 @@ #ifndef GNU_SOURCE #define GNU_SOURCE #endif + +#include "qos_interface.h" + #include #include +#include #include + #include -#include -#include -#include "qos_interface.h" +#include "concurrent_task_log.h" static int TrivalOpenRtgNode(void) { @@ -31,18 +34,7 @@ static int TrivalOpenRtgNode(void) int fd = open(fileName, O_RDWR); if (fd < 0) { CONCUR_LOGE("[Interface] task %{public}d belong to user %{public}d open rtg node failed, errno = %{public}d", - getpid(), getuid(), errno); - } - return fd; -} - -static int TrivalOpenAuthCtrlNode(void) -{ - char fileName[] = "/dev/auth_ctrl"; - int fd = open(fileName, O_RDWR); - if (fd < 0) { - CONCUR_LOGE("[Interface] task %{public}d belong to user %{public}d open auth node failed, errno = %{public}d", - getpid(), getuid(), errno); + getpid(), getuid(), errno); } return fd; } @@ -53,17 +45,15 @@ static int TrivalOpenQosCtrlNode(void) int fd = open(fileName, O_RDWR); if (fd < 0) { CONCUR_LOGE("[Interface] task %{public}d belong to user %{public}d open qos node failed, errno = %{public}d", - getpid(), getuid(), errno); + getpid(), getuid(), errno); } return fd; } int EnableRtg(bool flag) { - struct RtgEnableData enableData; char configStr[] = "load_freq_switch:1;sched_cycle:1;frame_max_util:1024"; - int ret; - + struct RtgEnableData enableData; enableData.enable = flag; enableData.len = sizeof(configStr); enableData.data = configStr; @@ -72,9 +62,9 @@ int EnableRtg(bool flag) return fd; } - ret = ioctl(fd, CMD_ID_SET_ENABLE, &enableData); + int ret = ioctl(fd, CMD_ID_SET_ENABLE, &enableData); if (ret < 0) { - printf("set rtg config enable failed.\n"); + CONCUR_LOGE("set rtg config enable failed."); } close(fd); @@ -82,179 +72,26 @@ int EnableRtg(bool flag) return 0; }; -int AuthEnable(unsigned int pid, unsigned int uaFlag, unsigned int status) -{ - struct AuthCtrlData data; - int fd; - int ret; - - fd = TrivalOpenAuthCtrlNode(); - if (fd < 0) { - return fd; - } - - data.pid = pid; - data.rtgUaFlag = uaFlag; - data.qosUaFlag = AF_QOS_DELEGATED; - data.status = status; - data.type = static_cast(AuthManipulateType::AUTH_ENABLE); - - ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data); -#ifdef QOS_DEBUG - if (ret < 0) { - printf("auth enable failed for pid %u with status %u\n", pid, status); - } -#endif - close(fd); - return ret; -} - -int AuthSwitch(unsigned int pid, unsigned int rtgFlag, unsigned int qosFlag, unsigned int status) -{ - struct AuthCtrlData data; - int fd; - int ret; - - fd = TrivalOpenAuthCtrlNode(); - if (fd < 0) { - return fd; - } - - data.pid = pid; - data.rtgUaFlag = rtgFlag; - data.qosUaFlag = qosFlag; - data.status = status; - data.type = static_cast(AuthManipulateType::AUTH_SWITCH); - - ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data); -#ifdef QOS_DEBUG - if (ret < 0) { - printf("auth switch failed for pid %u with status %u\n", pid, status); - } -#endif - close(fd); - return ret; -} - -int AuthDelete(unsigned int pid) -{ - struct AuthCtrlData data; - int fd; - int ret; - - fd = TrivalOpenAuthCtrlNode(); - if (fd < 0) { - return fd; - } - - data.pid = pid; - data.type = static_cast(AuthManipulateType::AUTH_DELETE); - - ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data); -#ifdef QOS_DEBUG - if (ret < 0) { - printf("auth delete failed for pid %u\n", pid); - } -#endif - close(fd); - return ret; -} - -int AuthPause(unsigned int pid) -{ - struct AuthCtrlData data; - int fd; - int ret; - - fd = TrivalOpenAuthCtrlNode(); - if (fd < 0) { - return fd; - } - - data.pid = pid; - data.type = static_cast(AuthManipulateType::AUTH_SWITCH); - data.rtgUaFlag = 0; - data.qosUaFlag = AF_QOS_DELEGATED; - data.status = static_cast(AuthStatus::AUTH_STATUS_BACKGROUND); - - ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data); -#ifdef QOS_DEBUG - if (ret < 0) { - printf("auth pause failed for pid %u\n", pid); - } -#endif - close(fd); - return ret; -} - -int AuthGet(unsigned int pid) -{ - struct AuthCtrlData data; - int fd; - int ret; - - fd = TrivalOpenAuthCtrlNode(); - if (fd < 0) { - return fd; - } - - data.pid = pid; - data.type = static_cast(AuthManipulateType::AUTH_GET); - - ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data); - if (ret < 0) { - close(fd); - return ret; - } - close(fd); - - return static_cast(data.status); -} - -int AuthEnhance(unsigned int pid, bool enhanceStatus) -{ - int ret = 0; -#ifdef QOS_EXT_ENABLE - struct AuthCtrlData data; - int fd = TrivalOpenAuthCtrlNode(); - if (fd < 0) { - return fd; - } - - data.pid = pid; - data.enhanceStatus = enhanceStatus; - ret = ioctl(fd, ENHANCE_AUTH_CTRL_OPERATION, &data); - close(fd); -#endif - return ret; -} - int QosApply(unsigned int level) { int tid = gettid(); - int ret; - - ret = QosApplyForOther(level, tid); + int ret = QosApplyForOther(level, tid); return ret; } int QosApplyForOther(unsigned int level, int tid) { - struct QosCtrlData data; - int fd; - - int ret; - - fd = TrivalOpenQosCtrlNode(); + int fd = TrivalOpenQosCtrlNode(); if (fd < 0) { return fd; } + struct QosCtrlData data; data.level = level; data.type = static_cast(QosManipulateType::QOS_APPLY); data.pid = tid; - ret = ioctl(fd, QOS_CTRL_BASIC_OPERATION, &data); + int ret = ioctl(fd, QOS_CTRL_BASIC_OPERATION, &data); if (ret < 0) { CONCUR_LOGE("[Interface] task %{public}d apply qos failed, errno = %{public}d", tid, errno); } @@ -264,19 +101,16 @@ int QosApplyForOther(unsigned int level, int tid) int QosLeave(void) { - struct QosCtrlData data; - int fd; - int ret; - - fd = TrivalOpenQosCtrlNode(); + int fd = TrivalOpenQosCtrlNode(); if (fd < 0) { return fd; } + struct QosCtrlData data; data.type = static_cast(QosManipulateType::QOS_LEAVE); data.pid = gettid(); - ret = ioctl(fd, QOS_CTRL_BASIC_OPERATION, &data); + int ret = ioctl(fd, QOS_CTRL_BASIC_OPERATION, &data); if (ret < 0) { CONCUR_LOGE("[Interface] task %{public}d leave qos failed, errno = %{public}d", gettid(), errno); } @@ -286,19 +120,16 @@ int QosLeave(void) int QosLeaveForOther(int tid) { - struct QosCtrlData data; - int fd; - int ret; - - fd = TrivalOpenQosCtrlNode(); + int fd = TrivalOpenQosCtrlNode(); if (fd < 0) { return fd; } + struct QosCtrlData data; data.type = static_cast(QosManipulateType::QOS_LEAVE); data.pid = tid; - ret = ioctl(fd, QOS_CTRL_BASIC_OPERATION, &data); + int ret = ioctl(fd, QOS_CTRL_BASIC_OPERATION, &data); if (ret < 0) { CONCUR_LOGE("[Interface] task %{public}d leave qos failed, errno = %{public}d", tid, errno); } @@ -306,17 +137,14 @@ int QosLeaveForOther(int tid) return ret; } -int QosPolicySet(const struct QosPolicyDatas *policyDatas) +int QosPolicySet(const struct QosPolicyDatas* policyDatas) { - int fd; - int ret; - - fd = TrivalOpenQosCtrlNode(); + int fd = TrivalOpenQosCtrlNode(); if (fd < 0) { return fd; } - ret = ioctl(fd, QOS_CTRL_POLICY_OPERATION, policyDatas); + int ret = ioctl(fd, QOS_CTRL_POLICY_OPERATION, policyDatas); if (ret < 0) { CONCUR_LOGE("[Interface] set qos policy failed, errno = %{public}d", errno); } @@ -324,18 +152,15 @@ int QosPolicySet(const struct QosPolicyDatas *policyDatas) return ret; } -int QosGet(int &level) +int QosGet(int& level) { int tid = gettid(); return QosGetForOther(tid, level); } -int QosGetForOther(int tid, int &level) +int QosGetForOther(int tid, int& level) { - int fd; - int ret = 0; - - fd = TrivalOpenQosCtrlNode(); + int fd = TrivalOpenQosCtrlNode(); if (fd < 0) { return fd; } @@ -345,7 +170,7 @@ int QosGetForOther(int tid, int &level) data.pid = tid; data.qos = -1; - ret = ioctl(fd, QOS_CTRL_BASIC_OPERATION, &data); + int ret = ioctl(fd, QOS_CTRL_BASIC_OPERATION, &data); if (ret < 0) { CONCUR_LOGE("[Interface] task %{public}d get qos failed, errno = %{public}d", tid, errno); } diff --git a/test/BUILD.gn b/test/BUILD.gn index ed891bcb982b076c4cf43df05e7b42cd9f08becf..b20590a52a5ce1fc7143504fc191551339ff0cc8 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -83,12 +83,42 @@ ohos_unittest("concurrent_task_client_test") { part_name = "qos_manager" } -ohos_unittest("concurrent_task_controller_test") { +ohos_unittest("func_loader_test") { module_out_path = module_output_path configs = [ ":test_config" ] - sources = [ "unittest/phone/concurrent_task_controller_test.cpp" ] + sources = [ "unittest/phone/func_loader_test.cpp" ] + deps = [ + "../etc/param:ffrt_etc", + "../frameworks/concurrent_task_client:concurrent_task_client", + "../services:concurrentsvc", + ] + + external_deps = [ + "c_utils:utils", + "frame_aware_sched:rtg_interface", + "hilog:libhilog", + "init:libbegetutil", + "jsoncpp:jsoncpp", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if (is_standard_system) { + external_deps += [ "googletest:gtest_main" ] + } + + subsystem_name = "resourceschedule" + part_name = "qos_manager" +} + +ohos_unittest("concurrent_task_controller_interface_test") { + module_out_path = module_output_path + + configs = [ ":test_config" ] + + sources = [ "unittest/phone/concurrent_task_controller_interface_test.cpp" ] deps = [ "../etc/param:ffrt_etc", "../frameworks/concurrent_task_client:concurrent_task_client", @@ -264,26 +294,6 @@ ohos_unittest("qos_ndk_test") { part_name = "qos_manager" } -ohos_unittest("config_reader_test") { - module_out_path = module_output_path - configs = [ ":test_config" ] - - sources = [ "unittest/phone/config_reader_test.cpp" ] - deps = [ "../services:concurrentsvc" ] - - external_deps = [ - "c_utils:utils", - "config_policy:configpolicy_util", - "frame_aware_sched:rtg_interface", - "hilog:libhilog", - "init:libbegetutil", - "libxml2:libxml2", - ] - - subsystem_name = "resourceschedule" - part_name = "qos_manager" -} - group("concurrent_unittest") { testonly = true deps = [] @@ -291,10 +301,10 @@ group("concurrent_unittest") { deps += [ ":concurrent_svc_intf_test", ":concurrent_task_client_test", - ":concurrent_task_controller_test", + ":concurrent_task_controller_interface_test", ":concurrent_task_service_ability_test", ":concurrent_task_service_test", - ":config_reader_test", + ":func_loader_test", ":qos_interface_test", ":qos_ndk_test", ":qos_policy_test", diff --git a/test/fuzztest/concurrent_fuzzer/concurrent_fuzzer.cpp b/test/fuzztest/concurrent_fuzzer/concurrent_fuzzer.cpp index 61fcf135c3a14e2355e7ee16ea53095a66417c67..11504ace505b28a2f0b910c122d00c70fda6d956 100644 --- a/test/fuzztest/concurrent_fuzzer/concurrent_fuzzer.cpp +++ b/test/fuzztest/concurrent_fuzzer/concurrent_fuzzer.cpp @@ -17,7 +17,7 @@ #define private public #include "concurrent_task_client.h" #include "concurrent_task_service_ability.h" -#include "concurrent_task_controller.h" +#include "concurrent_task_controller_interface.h" #undef private #include "concurrent_task_service_proxy.h" #include "concurrent_task_service.h" @@ -283,72 +283,6 @@ bool FuzzQosInterfaceEnableRtg(const uint8_t* data, size_t size) return true; } -bool FuzzQosInterfaceAuthEnable(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > sizeof(unsigned int) + sizeof(unsigned int) + sizeof(unsigned int)) { - unsigned int pid = GetData(); - unsigned int uaFlag = GetData(); - unsigned int status = GetData(); - AuthEnable(pid, uaFlag, status); - } - return true; -} - -bool FuzzQosInterfaceAuthSwitch(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > QUADRUPLE * sizeof(unsigned int)) { - unsigned int pid = GetData(); - unsigned int rtgFlag = GetData(); - unsigned int qosFlag = GetData(); - unsigned int status = GetData(); - AuthSwitch(pid, rtgFlag, qosFlag, status); - } - return true; -} - -bool FuzzQosInterfaceAuthPause(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > sizeof(unsigned int) + sizeof(unsigned int)) { - unsigned int pid = GetData(); - AuthPause(pid); - } - return true; -} - -bool FuzzQosInterfaceAuthGet(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > sizeof(unsigned int) + sizeof(unsigned int)) { - unsigned int pid = GetData(); - AuthGet(pid); - } - return true; -} - -bool FuzzQosInterfaceAuthEnhance(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > sizeof(unsigned int) + sizeof(unsigned int)) { - unsigned int pid = GetData(); - bool enhanceStatus = GetData(); - AuthEnhance(pid, enhanceStatus); - } - return true; -} - bool FuzzQosInterfaceQosLeave(const uint8_t* data, size_t size) { g_baseFuzzData = data; @@ -704,256 +638,80 @@ bool FuzzConcurrentTaskServiceProxyRequestAuth(const uint8_t* data, size_t size) return true; } -bool FuzzTaskControllerQueryRenderService(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int)) { - int uid = GetData(); - IntervalReply queryRs; - queryRs.tid = GetData(); - queryRs.rtgId = GetData(); - queryRs.paramA = 1; - queryRs.paramB = 1; - TaskController::GetInstance().renderServiceMainGrpId_ = GetData(); - TaskController::GetInstance().QueryRenderService(uid, queryRs); - } - return true; -} -bool FuzzTaskControllerQueryExecutorStart(const uint8_t* data, size_t size) +bool FuzzConcurrentTaskControllerInterfaceReportData(const uint8_t* data, size_t size) { g_baseFuzzData = data; g_baseFuzzSize = size; g_baseFuzzPos = 0; - if (size > sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int)) { - int uid = GetData(); - IntervalReply queryRs; - queryRs.tid = GetData(); - queryRs.rtgId = GetData(); - queryRs.paramA = 1; - queryRs.paramB = 1; - TaskController::GetInstance().renderServiceMainGrpId_ = GetData(); - TaskController::GetInstance().QueryRenderService(uid, queryRs); - } - return true; -} - -bool FuzzTaskControllerGetRequestType(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > sizeof(int)) { - std::string msgType = std::to_string(GetData()); - TaskController::GetInstance().GetRequestType(msgType); - } - return true; -} - -bool FuzzTaskControllerDealSystemRequest(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > sizeof(int) + sizeof(int) + sizeof(int)) { - Json::Value payload; - payload["pid"] = GetData(); - payload["uid"] = GetData(); - int requestType = GetData(); - TaskController::GetInstance().DealSystemRequest(requestType, payload); - } - return true; -} - -bool FuzzTaskControllerNewForeground(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > sizeof(int) + sizeof(int)) { - int uid = GetData(); - int pid = GetData(); - TaskController::GetInstance().NewForeground(uid, pid); - } - return true; -} - -bool FuzzTaskControllerNewForegroundAppRecord(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 pid = GetData(); - int uiPid = GetData(); - bool ddlEnable = GetData(); - TaskController::GetInstance().NewForegroundAppRecord(pid, uiPid, ddlEnable); - } - return true; -} - -bool FuzzTaskControllerNewBackground(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > sizeof(int) + sizeof(int)) { - int pid = GetData(); - int uid = GetData(); - TaskController::GetInstance().NewBackground(uid, pid); - } - return true; -} - -bool FuzzTaskControllerNewAppStart(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 pid = GetData(); - int uid = GetData(); - std::string bundleName = std::to_string(GetData()); - TaskController::GetInstance().NewAppStart(uid, pid, bundleName); + if (size > sizeof(uint32_t) + sizeof(int64_t) + sizeof(uint32_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()); + TaskControllerInterface::GetInstance().ReportData(resType, value, jsValue); } return true; } -bool FuzzTaskControllerAppKilled(const uint8_t* data, size_t size) +bool FuzzConcurrentTaskControllerInterfaceQueryInterval(const uint8_t* data, size_t size) { g_baseFuzzData = data; g_baseFuzzSize = size; g_baseFuzzPos = 0; if (size > sizeof(int) + sizeof(int)) { - int pid = GetData(); - int uid = GetData(); - TaskController::GetInstance().AppKilled(uid, pid); - } - return true; -} - -bool FuzzTaskControllerAuthSystemProcess(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > sizeof(int)) { - int pid = GetData(); - TaskController::GetInstance().AuthSystemProcess(pid); - } - return true; -} - -bool FuzzTaskControllerContinuousTaskProcess(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 pid = GetData(); - int uid = GetData(); - int status = GetData(); - TaskController::GetInstance().ContinuousTaskProcess(uid, pid, status); + ConcurrentTaskService s = ConcurrentTaskService(); + int queryItem = GetData(); + queryItem = queryItem % (QURRY_TYPE_MAX + 1); + IntervalReply queryRs; + TaskControllerInterface::GetInstance().QueryInterval(queryItem, queryRs); } return true; } -bool FuzzTaskControllerFocusStatusProcess(const uint8_t* data, size_t size) +bool FuzzConcurrentTaskControllerInterfaceQueryDeadline(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 pid = GetData(); - int uid = GetData(); - int status = GetData(); - TaskController::GetInstance().FocusStatusProcess(uid, pid, status); - } - return true; -} - -bool FuzzTaskControllerModifyGameState(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > sizeof(int) + sizeof(int)) { - const char* str1 = reinterpret_cast(data + g_baseFuzzPos); - size_t size1 = (size - g_baseFuzzPos) > LEN ? LEN : (size - g_baseFuzzPos); - std::string gameMsg(str1, size1); - Json::Value payload; - payload["gameMsg"] = gameMsg.c_str(); - TaskController::GetInstance().ModifyGameState(payload); - } else { - Json::Value payload; - payload["gameMsg"] = "gameScene\":\"1"; - TaskController::GetInstance().ModifyGameState(payload); + 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(); + TaskControllerInterface::GetInstance().QueryDeadline(deadlineType, queryRs, jsValue); } return true; } -bool FuzzTaskControllerModifySystemRate(const uint8_t* data, size_t size) +bool FuzzConcurrentTaskControllerInterfaceRequestAuth(const uint8_t* data, size_t size) { g_baseFuzzData = data; g_baseFuzzSize = size; g_baseFuzzPos = 0; if (size > sizeof(int) + sizeof(int)) { - const char* str1 = reinterpret_cast(data + g_baseFuzzPos); - size_t size1 = (size - g_baseFuzzPos) > LEN ? LEN : (size - g_baseFuzzPos); - std::string gameMsg(str1, size1); Json::Value payload; - payload["gameMsg"] = gameMsg.c_str(); - TaskController::GetInstance().ModifyGameState(payload); - } else { - Json::Value payload; - payload["gameMsg"] = "gameScene\":\"1"; - TaskController::GetInstance().ModifyGameState(payload); - } - return true; -} - -bool FuzzTaskControllerSetAppRate(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > sizeof(int) + sizeof(int) + sizeof(int)) { - Json::Value payload; - payload[std::to_string(GetData()).c_str()] = std::to_string(GetData()).c_str(); - TaskController::GetInstance().SetAppRate(payload); - } else { - Json::Value payload; - payload["-1"] = std::to_string(GetData()).c_str(); - TaskController::GetInstance().SetAppRate(payload); + payload["2187"] = std::to_string(GetData()); + payload["2376"] = std::to_string(GetData()); + ConcurrentTaskService s = ConcurrentTaskService(); + TaskControllerInterface::GetInstance().RequestAuth(payload); } return true; } -bool FuzzTaskControllerSetRenderServiceRate(const uint8_t* data, size_t size) +bool FuzzConcurrentTaskControllerInterfaceInit(const uint8_t* data, size_t size) { - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - if (size > sizeof(int) + sizeof(int) + sizeof(int)) { - Json::Value payload; - payload[std::to_string(GetData()).c_str()] = std::to_string(GetData()).c_str(); - TaskController::GetInstance().SetRenderServiceRate(payload); - } + TaskControllerInterface::GetInstance().Init(); return true; } -bool FuzzTaskControllerCheckJsonValid(const uint8_t* data, size_t size) +bool FuzzConcurrentTaskControllerInterfaceRelease(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[std::to_string(GetData()).c_str()] = std::to_string(GetData()).c_str(); - TaskController::GetInstance().CheckJsonValid(payload); - } + TaskControllerInterface::GetInstance().Release(); return true; } @@ -973,23 +731,6 @@ bool FuzzQosControllerGetThreadQosForOtherThread(const uint8_t* data, size_t siz static void TaskControllerFuzzTestSuit(const uint8_t *data, size_t size) { - OHOS::FuzzTaskControllerQueryRenderService(data, size); - OHOS::FuzzTaskControllerQueryExecutorStart(data, size); - OHOS::FuzzTaskControllerGetRequestType(data, size); - OHOS::FuzzTaskControllerDealSystemRequest(data, size); - OHOS::FuzzTaskControllerNewForeground(data, size); - OHOS::FuzzTaskControllerNewForegroundAppRecord(data, size); - OHOS::FuzzTaskControllerNewBackground(data, size); - OHOS::FuzzTaskControllerNewAppStart(data, size); - OHOS::FuzzTaskControllerAppKilled(data, size); - OHOS::FuzzTaskControllerAuthSystemProcess(data, size); - OHOS::FuzzTaskControllerContinuousTaskProcess(data, size); - OHOS::FuzzTaskControllerFocusStatusProcess(data, size); - OHOS::FuzzTaskControllerModifyGameState(data, size); - OHOS::FuzzTaskControllerSetAppRate(data, size); - OHOS::FuzzTaskControllerModifySystemRate(data, size); - OHOS::FuzzTaskControllerSetRenderServiceRate(data, size); - OHOS::FuzzTaskControllerCheckJsonValid(data, size); OHOS::FuzzQosControllerGetThreadQosForOtherThread(data, size); } @@ -1009,11 +750,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) OHOS::FuzzConcurrentTaskServiceQueryDeadline(data, size); OHOS::FuzzQosPolicyInit(data, size); OHOS::FuzzQosInterfaceEnableRtg(data, size); - OHOS::FuzzQosInterfaceAuthEnable(data, size); - OHOS::FuzzQosInterfaceAuthSwitch(data, size); - OHOS::FuzzQosInterfaceAuthGet(data, size); - OHOS::FuzzQosInterfaceAuthEnhance(data, size); - OHOS::FuzzQosInterfaceAuthPause(data, size); OHOS::FuzzQosInterfaceQosLeave(data, size); OHOS::FuzzConcurrentTaskServiceStubReportData(data, size); OHOS::FuzzConcurrentTaskServiceStubQueryInterval(data, size); diff --git a/test/unittest/phone/concurrent_task_controller_interface_test.cpp b/test/unittest/phone/concurrent_task_controller_interface_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3f2933eec48c19977cde7df0450b830bb4df5dde --- /dev/null +++ b/test/unittest/phone/concurrent_task_controller_interface_test.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "gtest/gtest.h" +#include "parameters.h" +#define private public +#include "concurrent_task_controller_interface.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 ConcurrentTaskControllerInterfaceTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void ConcurrentTaskControllerInterfaceTest::SetUpTestCase() {} + +void ConcurrentTaskControllerInterfaceTest::TearDownTestCase() {} + +void ConcurrentTaskControllerInterfaceTest::SetUp() {} + +void ConcurrentTaskControllerInterfaceTest::TearDown() {} + +/** + * @tc.name: RequestAuthTest + * @tc.desc: Test whether the ReportDataTest interface are normal. + * @tc.type: FUNC + */ +HWTEST_F(ConcurrentTaskControllerInterfaceTest, RequestAuthTest, TestSize.Level1) +{ + const Json::Value payload; + TaskControllerInterface repData; + repData.RequestAuth(payload); +} + +/** + * @tc.name: ReportDataTest + * @tc.desc: Test whether the ReportDataTest interface are normal. + * @tc.type: FUNC + */ +HWTEST_F(ConcurrentTaskControllerInterfaceTest, ReportDataTest, TestSize.Level1) +{ + uint32_t resType = 0; + int64_t value = 0; + const Json::Value payload; + TaskControllerInterface repData; + repData.ReportData(resType, value, payload); +} + +/** + * @tc.name: QueryDeadlineTest + * @tc.desc: Test whether the QueryDeadlineTest interface are normal. + * @tc.type: FUNC + */ +HWTEST_F(ConcurrentTaskControllerInterfaceTest, QueryDeadlineTest, TestSize.Level1) +{ + int queryItem = DDL_RATE; + DeadlineReply ddlReply = {false}; + const Json::Value payload; + TaskControllerInterface::GetInstance().QueryDeadline(queryItem, ddlReply, payload); +} + +/** + * @tc.name: PushTaskTest + * @tc.desc: Test whether the PushTask interface are normal. + * @tc.type: FUNC + */ +HWTEST_F(ConcurrentTaskControllerInterfaceTest, QueryIntervalTest, TestSize.Level1) +{ + TaskControllerInterface 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(ConcurrentTaskControllerInterfaceTest, InitTest, TestSize.Level1) +{ + TaskControllerInterface::GetInstance().Init(); +} + +/** + * @tc.name: PushTaskTest + * @tc.desc: Test whether the PushTask interface are normal. + * @tc.type: FUNC + */ +HWTEST_F(ConcurrentTaskControllerInterfaceTest, ReleaseTest, TestSize.Level1) +{ + TaskControllerInterface::GetInstance().Release(); +} +} // namespace FFRT_TEST +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/phone/concurrent_task_controller_test.cpp b/test/unittest/phone/concurrent_task_controller_test.cpp deleted file mode 100644 index be2df456c41819d49f7e5a7ee7d2948282a0a9f2..0000000000000000000000000000000000000000 --- a/test/unittest/phone/concurrent_task_controller_test.cpp +++ /dev/null @@ -1,603 +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 -#include -#include -#include -#include "gtest/gtest.h" -#include "parameters.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, 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, TryCreateRSMainGrpTest, TestSize.Level1) -{ - TaskController::GetInstance().rtgEnabled_ = false; - TaskController::GetInstance().TryCreateRSMainGrp(); - TaskController::GetInstance().rtgEnabled_ = true; - TaskController::GetInstance().TryCreateRSMainGrp(); -} - -/** - * @tc.name: PushTaskTest - * @tc.desc: Test whether the PushTask interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, TryCreateRSRenderGrpTest, TestSize.Level1) -{ - TaskController::GetInstance().rtgEnabled_ = false; - TaskController::GetInstance().TryCreateRSRenderGrp(); - TaskController::GetInstance().rtgEnabled_ = true; - TaskController::GetInstance().TryCreateRSRenderGrp(); -} - -/** - * @tc.name:QueryRenderServiceTest - * @tc.desc: Test whether the QueryRenderService interface is 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 grpId = TaskController::GetInstance().renderServiceMainGrpId_; - EXPECT_TRUE(grpId > 0); -} - -/** - * @tc.name: PushTaskTest - * @tc.desc: Test whether the PushTask interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, QueryRenderServiceMainTest, TestSize.Level1) -{ - int uid = SYSTEM_UID; - int pid = getpid(); - IntervalReply queryRs = {87, 657, 357, 214}; - TaskController::GetInstance().QueryRenderServiceMain(uid, pid, queryRs); - int flag = TaskController::GetInstance().renderServiceMainGrpId_; - TaskController::GetInstance().renderServiceMainGrpId_ = 1; - TaskController::GetInstance().QueryRenderServiceMain(uid, pid, queryRs); - TaskController::GetInstance().renderServiceMainGrpId_ = -1; - TaskController::GetInstance().QueryRenderServiceMain(uid, pid, queryRs); - TaskController::GetInstance().renderServiceMainGrpId_ = flag; - TaskController::GetInstance().QueryRenderServiceMain(uid, pid, queryRs); -} - -/** - * @tc.name: PushTaskTest - * @tc.desc: Test whether the PushTask interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, QueryRenderServiceRenderTest, TestSize.Level1) -{ - int uid = SYSTEM_UID; - int pid = getpid(); - IntervalReply queryRs = {87, 657, 357, 214}; - TaskController::GetInstance().QueryRenderServiceRender(uid, pid, queryRs); - int flag = TaskController::GetInstance().renderServiceRenderGrpId_; - TaskController::GetInstance().renderServiceRenderGrpId_ = 1; - TaskController::GetInstance().QueryRenderServiceRender(uid, pid, queryRs); - TaskController::GetInstance().renderServiceRenderGrpId_ = -1; - TaskController::GetInstance().QueryRenderServiceRender(uid, pid, queryRs); - TaskController::GetInstance().renderServiceRenderGrpId_ = flag; - TaskController::GetInstance().QueryRenderServiceRender(uid, pid, 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 = getuid(); - int tid = gettid(); - fore.NewForeground(uid, tid); - fore.NewBackground(uid, tid); - fore.NewAppStart(uid, tid, ""); - fore.NewForeground(uid, tid); - fore.NewBackground(uid, tid); - fore.ContinuousTaskProcess(uid, tid, static_cast(MSG_CONTINUOUS_TASK_START)); - fore.FocusStatusProcess(uid, tid, static_cast(MSG_GET_FOCUS)); - fore.FocusStatusProcess(uid, tid, static_cast(MSG_LOSE_FOCUS)); - fore.AppKilled(uid, tid); - tid = 574; - fore.foregroundApp_.push_back(ForegroundAppRecord(tid, 0)); - fore.foregroundApp_.push_back(ForegroundAppRecord(1, 0)); - fore.foregroundApp_.push_back(ForegroundAppRecord(3, 0)); - auto iter = fore.foregroundApp_.begin(); - EXPECT_EQ(iter->GetPid(), tid); - fore.NewForeground(uid, tid); - fore.NewBackground(uid, tid); - fore.NewAppStart(uid, tid, ""); - fore.NewForeground(uid, tid); - fore.NewBackground(uid, tid); - fore.ContinuousTaskProcess(uid, tid, static_cast(MSG_CONTINUOUS_TASK_END)); - fore.AppKilled(uid, tid); -} - -/** - * @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, 0)); - print.foregroundApp_.push_back(ForegroundAppRecord(3, 0)); - print.foregroundApp_.push_back(ForegroundAppRecord(5, 0)); - 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(tid, 0); - 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 pid = 758; - ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(pid, 0); - 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 pid = 758; - ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(pid, 0); - EXPECT_EQ(foregroundapprecord.GetPid(), foregroundapprecord.pid_); - EXPECT_EQ(foregroundapprecord.GetGrpId(), foregroundapprecord.grpId_); - foregroundapprecord.pid_ = -1; - foregroundapprecord.grpId_ = 1; - EXPECT_EQ(foregroundapprecord.IsValid(), false); - foregroundapprecord.pid_ = -1; - foregroundapprecord.grpId_ = -1; - EXPECT_EQ(foregroundapprecord.IsValid(), false); - foregroundapprecord.pid_ = 1; - foregroundapprecord.grpId_ = -1; - EXPECT_EQ(foregroundapprecord.IsValid(), true); - foregroundapprecord.pid_ = 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 pid = 758; - ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(pid, 0); - 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(); -} - - -/** - * @tc.name: QueryDeadlineTest - * @tc.desc: Test whether the QueryDeadlineTest interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, QueryDeadlineTest, TestSize.Level1) -{ - int queryItem = DDL_RATE; - DeadlineReply ddlReply = { false }; - const Json::Value payload; - TaskController::GetInstance().QueryDeadline(queryItem, ddlReply, payload); -} - -/** - * @tc.name: ModifySystemRateTest - * @tc.desc: Test whether the ModifySystemRate interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, ModifySystemRateTest, TestSize.Level1) -{ - Json::Value payload; - TaskController::GetInstance().ModifySystemRate(payload); - payload["1111"] = "60"; - TaskController::GetInstance().ModifySystemRate(payload); -} - -/** - * @tc.name: SetAppRate - * @tc.desc: Test whether the SetAppRate interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, SetAppRateTest, TestSize.Level1) -{ - Json::Value payload; - ForegroundAppRecord foreApp1 = ForegroundAppRecord(758, 758); - foreApp1.SetRate(60); - TaskController::GetInstance().foregroundApp_.push_back(foreApp1); - TaskController::GetInstance().foregroundApp_.begin()->grpId_ = 1; - payload["758"] = "120"; - TaskController::GetInstance().SetAppRate(payload); - int curAppRate = TaskController::GetInstance().foregroundApp_.begin()->GetRate(); - EXPECT_EQ(curAppRate, 120); - payload["-1"] = "120"; - TaskController::GetInstance().SetAppRate(payload); - EXPECT_EQ(OHOS::system::GetIntParameter("persist.ffrt.interval.appRate", 0), 120); -} - -/** - * @tc.name: FindRateFromInfo - * @tc.desc: Test whether the FindRateFromInfo interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, FindRateFromInfoTest, TestSize.Level1) -{ - Json::Value payload; - payload["758"] = "120"; - payload["759"] = "120XXY"; - int ret = TaskController::GetInstance().FindRateFromInfo(754, payload); - EXPECT_EQ(ret, 0); - ret = TaskController::GetInstance().FindRateFromInfo(758, payload); - EXPECT_EQ(ret, 120); - TaskController::GetInstance().FindRateFromInfo(759, payload); -} - -/** - * @tc.name: SetRenderServiceRate - * @tc.desc: Test whether the SetRenderServiceRate interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, SetRenderServiceRateTest, TestSize.Level1) -{ - Json::Value payload; - payload["758"] = "120"; - TaskController::GetInstance().renderServiceMainTid_ = 758; - TaskController::GetInstance().systemRate_ = 0; - TaskController::GetInstance().renderServiceMainGrpId_ = 1; - TaskController::GetInstance().SetRenderServiceRate(payload); - EXPECT_EQ(TaskController::GetInstance().systemRate_, 120); - EXPECT_EQ(OHOS::system::GetIntParameter("persist.ffrt.interval.rsRate", 0), 120); -} - -/** - * @tc.name: SetFrameRate - * @tc.desc: Test whether the SetFrameRate interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, SetFrameRateTest, TestSize.Level1) -{ - TaskController::GetInstance().SetFrameRate(758, 120); - TaskController::GetInstance().SetFrameRate(0, 120); -} - -/** - * @tc.name: GetPid - * @tc.desc: Test whether the GetPid interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, GetPidTest, TestSize.Level1) -{ - ForegroundAppRecord foreApp = ForegroundAppRecord(758, 0); - EXPECT_EQ(foreApp.GetPid(), 758); -} - -/** - * @tc.name: GetUiTid - * @tc.desc: Test whether the GetUiTid interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, GetUiTidTest, TestSize.Level1) -{ - ForegroundAppRecord foreApp = ForegroundAppRecord(758, 758); - EXPECT_EQ(foreApp.GetUiTid(), 758); -} - -/** - * @tc.name: SetRate - * @tc.desc: Test whether the SetRate interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, SetRateTest, TestSize.Level1) -{ - ForegroundAppRecord foreApp = ForegroundAppRecord(758, 758); - foreApp.SetRate(120); - EXPECT_EQ(foreApp.GetRate(), 120); -} - -/** - * @tc.name: SetUiTid - * @tc.desc: Test whether the SetUiTid interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, SetUiTidTest, TestSize.Level1) -{ - ForegroundAppRecord foreApp = ForegroundAppRecord(758, 758); - EXPECT_EQ(foreApp.GetUiTid(), 758); - foreApp.SetUiTid(755); - EXPECT_EQ(foreApp.GetUiTid(), 755); -} - -/** - * @tc.name: SetGrpId - * @tc.desc: Test whether the SetGrpId interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, SetGrpId, TestSize.Level1) -{ - ForegroundAppRecord foreApp = ForegroundAppRecord(758, 758); - foreApp.SetGrpId(-1); - EXPECT_EQ(foreApp.GetGrpId(), -1); -} - -/** - * @tc.name: GetGameScene - * @tc.desc: Test whether the GetGameScene interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, GetGameScene, TestSize.Level1) -{ - std::string testMsg = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\"," - "\"gameScene\":\"1\",\"renderThread\":\"5579\"}"; - GameStatus status = TaskController::GetInstance().GetGameScene(testMsg); - EXPECT_EQ(status, GAME_ENTRY_MSG); - testMsg = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\",\"gameScene\":\"0\"}"; - status = TaskController::GetInstance().GetGameScene(testMsg); - EXPECT_EQ(status, GAME_EXIT_MSG); - testMsg = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\",\"gameScene\":\"2\"}"; - status = TaskController::GetInstance().GetGameScene(testMsg); - EXPECT_EQ(status, STATUS_MSG_MAX); - testMsg = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\",\"cameraScene\":\"1\"}"; - status = TaskController::GetInstance().GetGameScene(testMsg); - EXPECT_EQ(status, CAMERA_ENTRY_MSG); - testMsg = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\",\"cameraScene\":\"0\"}"; - status = TaskController::GetInstance().GetGameScene(testMsg); - EXPECT_EQ(status, CAMERA_EXIT_MSG); -} - -/** - * @tc.name: GetGamePid - * @tc.desc: Test whether the GetGamePid interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, GetGamePid, TestSize.Level1) -{ - std::string testMsg = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\"," - "\"gameScene\":\"1\",\"renderThread\":\"5579\"}"; - int gamePid = TaskController::GetInstance().GetGamePid(testMsg); - EXPECT_EQ(gamePid, 5578); - testMsg = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\",\"gameScene\":\"0\"}"; - gamePid = TaskController::GetInstance().GetGamePid(testMsg); - EXPECT_EQ(gamePid, -1); - testMsg = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\",\"gameScene\":\"2\"}"; - gamePid = TaskController::GetInstance().GetGamePid(testMsg); - EXPECT_EQ(gamePid, -1); -} - -/** - * @tc.name: NewForegroundAppRecord - * @tc.desc: Test whether the NewForegroundAppRecord interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, NewForegroundAppRecord, TestSize.Level1) -{ - TaskController::GetInstance().curGamePid_ = 756; - TaskController::GetInstance().NewForegroundAppRecord(756, 756, true); - TaskController::GetInstance().NewForegroundAppRecord(757, 757, true); - TaskController::GetInstance().NewForegroundAppRecord(757, 757, false); -} - -/** - * @tc.name: ModifyGameState - * @tc.desc: Test whether the ModifyGameState interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, ModifyGameState, TestSize.Level1) -{ - Json::Value payload; - payload["gameMsg"] = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\"," - "\"gameScene\":\"1\",\"renderThread\":\"5579\"}"; - TaskController::GetInstance().ModifyGameState(payload); - EXPECT_EQ(TaskController::GetInstance().curGamePid_, 5578); - payload["gameMsg"] = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\"," - "\"gameScene\":\"0\"}"; - TaskController::GetInstance().ModifyGameState(payload); - EXPECT_EQ(TaskController::GetInstance().curGamePid_, -1); -} -} -} diff --git a/test/unittest/phone/concurrent_task_service_test.cpp b/test/unittest/phone/concurrent_task_service_test.cpp index 9f16cf4d413ea319b64b5dfdd7aa01c54b34560e..32ee825b058a6385eb3d7abc06b6920a86de9721 100644 --- a/test/unittest/phone/concurrent_task_service_test.cpp +++ b/test/unittest/phone/concurrent_task_service_test.cpp @@ -15,7 +15,6 @@ #include "gtest/gtest.h" #include "concurrent_task_service.h" -#include "concurrent_task_controller.h" namespace OHOS { namespace FFRT_TEST { diff --git a/test/unittest/phone/func_loader_test.cpp b/test/unittest/phone/func_loader_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..75a2cd4737e782313b7f91d01b765d889cd3fe3f --- /dev/null +++ b/test/unittest/phone/func_loader_test.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "gtest/gtest.h" +#define private public +#include "func_loader.h" +#include "concurrent_task_controller_interface.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 FuncLoaderTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void FuncLoaderTest::SetUpTestCase() {} + +void FuncLoaderTest::TearDownTestCase() {} + +void FuncLoaderTest::SetUp() {} + +void FuncLoaderTest::TearDown() {} + +/** + * @tc.name: LoadFileTest + * @tc.desc: Test whether the ReportDataTest interface are normal. + * @tc.type: FUNC + */ +HWTEST_F(FuncLoaderTest, LoadFileTest, TestSize.Level1) +{ + FuncLoader funcLoader("111"); + funcLoader.LoadFile("222"); +} + +/** + * @tc.name: LoadSymbolTest + * @tc.desc: Test whether the ReportDataTest interface are normal. + * @tc.type: FUNC + */ +HWTEST_F(FuncLoaderTest, LoadSymbolTest, TestSize.Level1) +{ + FuncLoader funcLoader("/lib/libconcurrent_task_client.z.so"); + + funcLoader.LoadSymbol("Init"); + funcLoader.LoadSymbol("Release"); + funcLoader.LoadSymbol("ReportData"); + funcLoader.LoadSymbol("QueryInterval"); + funcLoader.LoadSymbol("QueryDeadline"); + funcLoader.LoadSymbol("RequestAuth"); +} + +/** + * @tc.name: GetLoadSuccessTest + * @tc.desc: Test whether the ReportDataTest interface are normal. + * @tc.type: FUNC + */ +HWTEST_F(FuncLoaderTest, GetLoadSuccessTest, TestSize.Level1) +{ + FuncLoader funcLoader("/lib/libconcurrent_task_client.z.so"); + bool ret = funcLoader.GetLoadSuccess(); + if (ret) { + EXPECT_EQ(ret, true); + } else { + EXPECT_EQ(ret, false); + } +} + +} // namespace FFRT_TEST +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/phone/qos_interface_test.cpp b/test/unittest/phone/qos_interface_test.cpp index 8bca921e5f52517a9d8c6d7dff9505f79debc754..1fa0ca682d48651435d868625cb10c4e50165fb6 100644 --- a/test/unittest/phone/qos_interface_test.cpp +++ b/test/unittest/phone/qos_interface_test.cpp @@ -73,69 +73,6 @@ HWTEST_F(QosInterfaceTest, EnableRtgTest, TestSize.Level1) 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 pid = getpid(); - unsigned int uaFlag = AF_RTG_ALL; - unsigned int status = static_cast(AuthStatus::AUTH_STATUS_BACKGROUND); - int ret = AuthEnable(pid, 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 pid = getpid(); - unsigned int rtgFlag = AF_RTG_ALL; - unsigned int qosFlag = AF_QOS_ALL; - unsigned int status = static_cast(AuthStatus::AUTH_STATUS_BACKGROUND); - AuthEnable(pid, rtgFlag, status); - status = static_cast(AuthStatus::AUTH_STATUS_FOREGROUND); - int ret = AuthSwitch(pid, 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 pid = getpid(); - unsigned int uaFlag = AF_RTG_ALL; - unsigned int status = static_cast(AuthStatus::AUTH_STATUS_BACKGROUND); - AuthEnable(pid, uaFlag, status); - int ret = AuthDelete(pid); - EXPECT_EQ(ret, 0); - AuthEnable(pid, uaFlag, status); -} - -/** - * @tc.name: AuthPauseTest - * @tc.desc: Test whether the AuthPause interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(QosInterfaceTest, AuthPauseTest, TestSize.Level1) -{ - unsigned int pid = getpid(); - unsigned int uaFlag = AF_RTG_ALL; - unsigned int status = static_cast(AuthStatus::AUTH_STATUS_BACKGROUND); - AuthEnable(pid, uaFlag, status); - int ret = AuthPause(pid); - EXPECT_EQ(ret, 0); - AuthEnable(pid, uaFlag, status); -} - /** * @tc.name: QosApplyTest * @tc.desc: Test whether the QosApply interface are normal. @@ -153,44 +90,6 @@ HWTEST_F(QosInterfaceTest, QosApplyTest, TestSize.Level1) #endif } -/** - * @tc.name: AuthGetTest - * @tc.desc: Test whether the AuthGet interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(QosInterfaceTest, AuthGetTest, TestSize.Level1) -{ - unsigned int pid = getpid(); - unsigned int uaFlag1 = 0; - unsigned int *uaFlag = &uaFlag1; - unsigned int status1 = 0; - unsigned int *status = &status1; - int ret = AuthGet(pid); - if (!IsLinuxOs()) { - return; - } - EXPECT_GE(ret, 0); - pid = -1; - ret = AuthGet(pid); - EXPECT_EQ(ret, -1); -} - -/** - * @tc.name: AuthEnhanceTest - * @tc.desc: Test whether the AuthEnhance interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(QosInterfaceTest, AuthEnhanceTest, TestSize.Level1) -{ - unsigned int pid = getpid(); - bool enhanceStatus = false; - int ret = AuthEnhance(pid, enhanceStatus); - EXPECT_EQ(ret, 0); - enhanceStatus = false; - ret = AuthEnhance(pid, enhanceStatus); - EXPECT_EQ(ret, 0); -} - /** * @tc.name: QosApplyForOtherTest * @tc.desc: Test whether the QosApplyForOther interface are normal. @@ -271,11 +170,6 @@ HWTEST_F(QosInterfaceTest, QosPolicyTest, TestSize.Level1) ret = QosPolicySet(policyDatas); EXPECT_EQ(ret, -1); #if defined(ARM64_TEST) && ARM64_TEST - unsigned int pid = getpid(); - unsigned int rtgFlag = AF_RTG_ALL; - unsigned int qosFlag = AF_QOS_ALL; - unsigned int status = static_cast(AuthStatus::AUTH_STATUS_FOREGROUND); - ret = AuthSwitch(pid, rtgFlag, qosFlag, status); EXPECT_EQ(ret, 0); ret = QosPolicySet(&g_defaultQosPolicy); EXPECT_EQ(ret, 0);