From bf2ca98aaa98b45304b03ef89ef6e9ddefb8397b Mon Sep 17 00:00:00 2001 From: wangzhen Date: Sat, 24 Aug 2024 13:53:36 +0800 Subject: [PATCH] Add load and foreground report to rss Signed-off-by: wangzhen Change-Id: I2764028054b48fe23fc450238c4e683139621e46 --- .../include/ability_connect_manager.h | 3 +- .../include/ability_manager_service.h | 14 ++------ .../src/ability_connect_manager.cpp | 8 ++--- .../src/ability_manager_service.cpp | 16 ++++----- services/abilitymgr/src/ability_record.cpp | 35 ++++++------------- .../abilitymgr/src/mission_list_manager.cpp | 2 +- .../appmgr/include/app_mgr_service_inner.h | 3 ++ services/appmgr/src/app_mgr_service_inner.cpp | 26 +++++++++++++- services/common/include/res_sched_util.h | 13 +++++-- services/common/src/res_sched_util.cpp | 22 ++++++++++-- .../abilitymanagerservicefirst_fuzzer.cpp | 2 +- .../ability_manager_service_fourth_test.cpp | 26 +++++++------- .../ams_ability_running_record_test/BUILD.gn | 1 + .../BUILD.gn | 1 + .../ams_service_event_drive_test/BUILD.gn | 1 + .../ams_service_startup_test/BUILD.gn | 1 + test/unittest/lifecycle_test/BUILD.gn | 1 + .../lifecycle_test/lifecycle_test.cpp | 27 +++++++++----- .../res_sched_util_test.cpp | 23 +++++++++--- utils/global/constant/global_constant.h | 31 ++++++++++++++++ 20 files changed, 172 insertions(+), 84 deletions(-) diff --git a/services/abilitymgr/include/ability_connect_manager.h b/services/abilitymgr/include/ability_connect_manager.h index 83a7254780..6ab91bc3de 100644 --- a/services/abilitymgr/include/ability_connect_manager.h +++ b/services/abilitymgr/include/ability_connect_manager.h @@ -330,7 +330,6 @@ public: std::shared_ptr GetUIExtensionRootHostInfo(const sptr token); // MSG 0 - 20 represents timeout message - static constexpr uint32_t LOAD_TIMEOUT_MSG = 0; static constexpr uint32_t CONNECT_TIMEOUT_MSG = 1; private: @@ -629,7 +628,7 @@ private: std::string GetServiceKey(const std::shared_ptr &service); int32_t ReportXiaoYiToRSSIfNeeded(const AppExecFwk::AbilityInfo &abilityInfo); - int32_t ReportAbilitStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo); + int32_t ReportAbilityStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo); private: const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask"; diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 1225630cc5..a70c58110d 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1795,16 +1795,6 @@ public: static constexpr uint32_t LOAD_HALF_TIMEOUT_MSG = 8; static constexpr uint32_t FOREGROUND_HALF_TIMEOUT_MSG = 9; -#ifdef SUPPORT_ASAN - static constexpr uint32_t LOAD_TIMEOUT = 150000; // ms - static constexpr uint32_t ACTIVE_TIMEOUT = 75000; // ms - static constexpr uint32_t INACTIVE_TIMEOUT = 7500; // ms -#else - static constexpr uint32_t LOAD_TIMEOUT = 10000; // ms - static constexpr uint32_t ACTIVE_TIMEOUT = 5000; // ms - static constexpr uint32_t INACTIVE_TIMEOUT = 500; // ms -#endif - static constexpr uint32_t MIN_DUMP_ARGUMENT_NUM = 2; static constexpr uint32_t MAX_WAIT_SYSTEM_UI_NUM = 600; static constexpr uint32_t MAX_WAIT_SETTINGS_DATA_NUM = 300; @@ -2034,9 +2024,9 @@ private: void UnsubscribeBundleEventCallback(); - void ReportAbilitStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo); + void ReportAbilityStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo); - void ReportAbilitAssociatedStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo, int64_t type, + void ReportAbilityAssociatedStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo, int64_t type, const sptr &callerToken); void ReportEventToRSS(const AppExecFwk::AbilityInfo &abilityInfo, sptr callerToken); diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index d21f207655..9b56ef5bbd 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -3254,7 +3254,7 @@ int32_t AbilityConnectManager::ReportXiaoYiToRSSIfNeeded(const AppExecFwk::Abili TAG_LOGI(AAFwkTag::ABILITYMGR, "bundleName is extension, abilityName:%{public}s", abilityInfo.name.c_str()); - auto ret = ReportAbilitStartInfoToRSS(abilityInfo); + auto ret = ReportAbilityStartInfoToRSS(abilityInfo); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, ret:%{public}d", ret); return ret; @@ -3262,7 +3262,7 @@ int32_t AbilityConnectManager::ReportXiaoYiToRSSIfNeeded(const AppExecFwk::Abili return ERR_OK; } -int32_t AbilityConnectManager::ReportAbilitStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo) +int32_t AbilityConnectManager::ReportAbilityStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); std::vector runningProcessInfos; @@ -3280,8 +3280,8 @@ int32_t AbilityConnectManager::ReportAbilitStartInfoToRSS(const AppExecFwk::Abil break; } } - TAG_LOGI(AAFwkTag::ABILITYMGR, "ReportAbilitStartInfoToRSS, abilityName:%{public}s", abilityInfo.name.c_str()); - ResSchedUtil::GetInstance().ReportAbilitStartInfoToRSS(abilityInfo, pid, isColdStart); + TAG_LOGI(AAFwkTag::ABILITYMGR, "ReportAbilityStartInfoToRSS, abilityName:%{public}s", abilityInfo.name.c_str()); + ResSchedUtil::GetInstance().ReportAbilityStartInfoToRSS(abilityInfo, pid, isColdStart); return ERR_OK; } } // namespace AAFwk diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 7a5bb82935..bc7986d9ad 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -1284,7 +1284,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrStartAbility(abilityRequest); @@ -2230,8 +2230,8 @@ int32_t AbilityManagerService::StartUIAbilityBySCBDefaultCommon(AbilityRequest & } } - ReportAbilitStartInfoToRSS(abilityInfo); - ReportAbilitAssociatedStartInfoToRSS(abilityInfo, RES_TYPE_SCB_START_ABILITY, sessionInfo->callerToken); + ReportAbilityStartInfoToRSS(abilityInfo); + ReportAbilityAssociatedStartInfoToRSS(abilityInfo, RES_TYPE_SCB_START_ABILITY, sessionInfo->callerToken); auto uiAbilityManager = GetUIAbilityManagerByUid(IPCSkeleton::GetCallingUid()); CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE); // here we don't need want param "IS_CALL_BY_SCB" any more, remove it. @@ -2565,7 +2565,7 @@ void AbilityManagerService::UnsubscribeBundleEventCallback() TAG_LOGD(AAFwkTag::ABILITYMGR, "UnsubscribeBundleEventCallback success."); } -void AbilityManagerService::ReportAbilitStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo) +void AbilityManagerService::ReportAbilityStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); if (abilityInfo.type == AppExecFwk::AbilityType::PAGE && @@ -2583,11 +2583,11 @@ void AbilityManagerService::ReportAbilitStartInfoToRSS(const AppExecFwk::Ability break; } } - ResSchedUtil::GetInstance().ReportAbilitStartInfoToRSS(abilityInfo, pid, isColdStart); + ResSchedUtil::GetInstance().ReportAbilityStartInfoToRSS(abilityInfo, pid, isColdStart); } } -void AbilityManagerService::ReportAbilitAssociatedStartInfoToRSS( +void AbilityManagerService::ReportAbilityAssociatedStartInfoToRSS( const AppExecFwk::AbilityInfo &abilityInfo, int64_t type, const sptr &callerToken) { CHECK_POINTER_LOG(callerToken, "null callerToken"); @@ -2595,7 +2595,7 @@ void AbilityManagerService::ReportAbilitAssociatedStartInfoToRSS( CHECK_POINTER_LOG(callerAbility, "null callerAbility"); int32_t callerUid = callerAbility->GetUid(); int32_t callerPid = callerAbility->GetPid(); - ResSchedUtil::GetInstance().ReportAbilitAssociatedStartInfoToRSS(abilityInfo, type, callerUid, callerPid); + ResSchedUtil::GetInstance().ReportAbilityAssociatedStartInfoToRSS(abilityInfo, type, callerUid, callerPid); } void AbilityManagerService::ReportEventToRSS(const AppExecFwk::AbilityInfo &abilityInfo, @@ -2897,7 +2897,7 @@ int AbilityManagerService::StartExtensionAbilityInner(const Want &want, const sp if (eventInfo.errCode != ERR_OK) { EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); } - ReportAbilitAssociatedStartInfoToRSS(abilityRequest.abilityInfo, RES_TYPE_EXTENSION_START_ABILITY, callerToken); + ReportAbilityAssociatedStartInfoToRSS(abilityRequest.abilityInfo, RES_TYPE_EXTENSION_START_ABILITY, callerToken); return eventInfo.errCode; } diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index d8d8eec8d9..c60d9a9a05 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -55,6 +55,7 @@ using AbilityRuntime::FreezeUtil; namespace AAFwk { using namespace OHOS::Security; using namespace OHOS::AAFwk::PermissionConstants; +using namespace OHOS::AbilityRuntime::GlobalConstant; const std::string DEBUG_APP = "debugApp"; const std::string NATIVE_DEBUG = "nativeDebug"; const std::string PERF_CMD = "perfCmd"; @@ -94,29 +95,6 @@ const int TERMINATE_TIMEOUT_ASANENABLED = 150; const int HALF_TIMEOUT = 2; const int MAX_URI_COUNT = 500; const int RESTART_SCENEBOARD_DELAY = 500; -#ifdef SUPPORT_ASAN -const int COLDSTART_TIMEOUT_MULTIPLE = 15000; -const int LOAD_TIMEOUT_MULTIPLE = 15000; -const int FOREGROUND_TIMEOUT_MULTIPLE = 7500; -const int BACKGROUND_TIMEOUT_MULTIPLE = 4500; -const int ACTIVE_TIMEOUT_MULTIPLE = 7500; -const int TERMINATE_TIMEOUT_MULTIPLE = 15000; -const int INACTIVE_TIMEOUT_MULTIPLE = 800; -const int DUMP_TIMEOUT_MULTIPLE = 1500; -const int SHAREDATA_TIMEOUT_MULTIPLE = 7500; -#else -const int COLDSTART_TIMEOUT_MULTIPLE = 10; -const int LOAD_TIMEOUT_MULTIPLE = 10; -const int FOREGROUND_TIMEOUT_MULTIPLE = 5; -const int BACKGROUND_TIMEOUT_MULTIPLE = 3; -const int ACTIVE_TIMEOUT_MULTIPLE = 5; -const int TERMINATE_TIMEOUT_MULTIPLE = 10; -const int INACTIVE_TIMEOUT_MULTIPLE = 1; -const int DUMP_TIMEOUT_MULTIPLE = 1000; -const int SHAREDATA_TIMEOUT_MULTIPLE = 5; -const int32_t TYPE_RESERVE = 1; -const int32_t TYPE_OTHERS = 2; -#endif auto g_addLifecycleEventTask = [](sptr token, FreezeUtil::TimeoutState state, std::string &methodName) { CHECK_POINTER_LOG(token, "token is nullptr"); @@ -497,6 +475,8 @@ void AbilityRecord::PostForegroundTimeoutTask() SendEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, foregroundTimeout); std::string methodName = "ForegroundAbility"; g_addLifecycleEventTask(token_, FreezeUtil::TimeoutState::FOREGROUND, methodName); + ResSchedUtil::GetInstance().ReportLoadingEventToRss(LoadingStage::FOREGROUND_BEGIN, GetPid(), GetUid(), + foregroundTimeout); } void AbilityRecord::RemoveForegroundTimeoutTask() @@ -535,6 +515,8 @@ void AbilityRecord::PostUIExtensionAbilityTimeoutTask(uint32_t messageId) static_cast(FOREGROUND_TIMEOUT_MULTIPLE); SendEvent(AbilityManagerService::FOREGROUND_HALF_TIMEOUT_MSG, timeout / HALF_TIMEOUT, recordId_, true); SendEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, timeout, recordId_, true); + ResSchedUtil::GetInstance().ReportLoadingEventToRss(LoadingStage::FOREGROUND_BEGIN, GetPid(), GetUid(), + timeout); break; } default: { @@ -1442,6 +1424,9 @@ void AbilityRecord::SetAbilityState(AbilityState state) if (state == AbilityState::FOREGROUND || state == AbilityState::ACTIVE || state == AbilityState::BACKGROUND) { SetRestarting(false); } + if (state == AbilityState::FOREGROUND) { + ResSchedUtil::GetInstance().ReportLoadingEventToRss(LoadingStage::FOREGROUND_END, GetPid(), GetUid()); + } } #endif // SUPPORT_SCREEN void AbilityRecord::SetScheduler(const sptr &scheduler) @@ -1457,9 +1442,8 @@ void AbilityRecord::SetScheduler(const sptr &scheduler) } } if (schedulerDeathRecipient_ == nullptr) { - std::weak_ptr thisWeakPtr(shared_from_this()); schedulerDeathRecipient_ = - new AbilitySchedulerRecipient([thisWeakPtr](const wptr &remote) { + new AbilitySchedulerRecipient([thisWeakPtr = weak_from_this()](const wptr &remote) { auto abilityRecord = thisWeakPtr.lock(); if (abilityRecord) { abilityRecord->OnSchedulerDied(remote); @@ -1477,6 +1461,7 @@ void AbilityRecord::SetScheduler(const sptr &scheduler) TAG_LOGI(AAFwkTag::ABILITYMGR, "Sceneboard DeathRecipient Added"); } pid_ = static_cast(IPCSkeleton::GetCallingPid()); // set pid when ability attach to service. + ResSchedUtil::GetInstance().ReportLoadingEventToRss(LoadingStage::LOAD_END, GetPid(), GetUid()); // add collaborator mission bind pid NotifyMissionBindPid(); #ifdef WITH_DLP diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index 53a1625b4e..efc551c7d5 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -194,7 +194,7 @@ int MissionListManager::StartAbility(AbilityRequest &abilityRequest) } NotifyStartAbilityResult(abilityRequest, ret); if (callerAbility != nullptr) { - ResSchedUtil::GetInstance().ReportAbilitAssociatedStartInfoToRSS(abilityRequest.abilityInfo, + ResSchedUtil::GetInstance().ReportAbilityAssociatedStartInfoToRSS(abilityRequest.abilityInfo, RES_TYPE_MISSION_LIST_START_ABILITY, callerAbility->GetUid(), callerAbility->GetPid()); } return ret; diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index f8abb8f9a7..f40cbc552d 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -1389,6 +1389,9 @@ private: void PresetMaxChildProcess(const std::shared_ptr &abilityInfo, int32_t &maxChildProcess); + void AfterLoadAbility(std::shared_ptr appRecord, std::shared_ptr abilityInfo, + std::shared_ptr loadParam); + private: /** * ClearUpApplicationData, clear the application data. diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 92a6e07ae2..90647668ef 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -69,6 +69,7 @@ #include "permission_constants.h" #include "permission_verification.h" #include "render_state_observer_manager.h" +#include "res_sched_util.h" #include "startup_util.h" #include "string_ex.h" #ifdef ABILITY_RUNTIME_FEATURE_SANDBOXMANAGER @@ -559,13 +560,36 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, s abilityRunningRecord->SetUIExtensionAbilityId(uiExtensionAbilityId); } } + AfterLoadAbility(appRecord, abilityInfo, loadParam); +} - if (abilityInfo->type == AppExecFwk::AbilityType::PAGE && appRecord != nullptr) { +void AppMgrServiceInner::AfterLoadAbility(std::shared_ptr appRecord, + std::shared_ptr abilityInfo, std::shared_ptr loadParam) +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + if (!appRecord || !abilityInfo || !loadParam) { + return; + } + if (abilityInfo->type == AppExecFwk::AbilityType::PAGE) { appRecord->SetUIAbilityLaunched(true); } PerfProfile::GetInstance().SetAbilityLoadEndTime(GetTickCount()); PerfProfile::GetInstance().Dump(); PerfProfile::GetInstance().Reset(); + + auto reportLoadTask = [appRecord]() { + auto priorityObj = appRecord->GetPriorityObject(); + if (priorityObj) { + auto timeOut = AbilityRuntime::GlobalConstant::GetLoadTimeOutBase() * + AAFwk::AppUtils::GetInstance().GetTimeoutUnitTimeRatio(); + AAFwk::ResSchedUtil::GetInstance().ReportLoadingEventToRss(AAFwk::LoadingStage::LOAD_BEGIN, + priorityObj->GetPid(), appRecord->GetUid(), timeOut); + } + }; + if (taskHandler_) { + taskHandler_->SubmitTask(reportLoadTask); + } + appRecord->UpdateAbilityState(loadParam->token, AbilityState::ABILITY_STATE_CREATE); } diff --git a/services/common/include/res_sched_util.h b/services/common/include/res_sched_util.h index 8abb767061..ed46b7b66d 100644 --- a/services/common/include/res_sched_util.h +++ b/services/common/include/res_sched_util.h @@ -29,16 +29,25 @@ using AbilityInfo = AppExecFwk::AbilityInfo; constexpr int64_t RES_TYPE_SCB_START_ABILITY = 0; constexpr int64_t RES_TYPE_EXTENSION_START_ABILITY = 1; constexpr int64_t RES_TYPE_MISSION_LIST_START_ABILITY = 2; + +enum class LoadingStage : int32_t { + LOAD_BEGIN = 1, + LOAD_END, + FOREGROUND_BEGIN, + FOREGROUND_END +}; + class ResSchedUtil final { public: static ResSchedUtil &GetInstance(); - void ReportAbilitStartInfoToRSS(const AbilityInfo &abilityInfo, int32_t pid, bool isColdStart); - void ReportAbilitAssociatedStartInfoToRSS( + void ReportAbilityStartInfoToRSS(const AbilityInfo &abilityInfo, int32_t pid, bool isColdStart); + void ReportAbilityAssociatedStartInfoToRSS( const AbilityInfo &abilityInfo, int64_t resSchedType, int32_t callerUid, int32_t callerPid); void ReportEventToRSS(const int32_t uid, const std::string &bundleName, const std::string &reason, const int32_t callerPid = -1); void GetAllFrozenPidsFromRSS(std::unordered_set &frozenPids); bool CheckShouldForceKillProcess(int32_t pid); + void ReportLoadingEventToRss(LoadingStage stage, int32_t pid, int32_t uid, int64_t timeDuration = 0); private: ResSchedUtil() = default; ~ResSchedUtil() = default; diff --git a/services/common/src/res_sched_util.cpp b/services/common/src/res_sched_util.cpp index ed663a3b01..10e256ea48 100644 --- a/services/common/src/res_sched_util.cpp +++ b/services/common/src/res_sched_util.cpp @@ -48,7 +48,7 @@ int64_t ResSchedUtil::convertType(int64_t resSchedType) return -1; } -void ResSchedUtil::ReportAbilitStartInfoToRSS(const AbilityInfo &abilityInfo, int32_t pid, bool isColdStart) +void ResSchedUtil::ReportAbilityStartInfoToRSS(const AbilityInfo &abilityInfo, int32_t pid, bool isColdStart) { #ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE uint32_t resType = ResourceSchedule::ResType::RES_TYPE_APP_ABILITY_START; @@ -64,7 +64,7 @@ void ResSchedUtil::ReportAbilitStartInfoToRSS(const AbilityInfo &abilityInfo, in #endif } -void ResSchedUtil::ReportAbilitAssociatedStartInfoToRSS( +void ResSchedUtil::ReportAbilityAssociatedStartInfoToRSS( const AbilityInfo &abilityInfo, int64_t resSchedType, int32_t callerUid, int32_t callerPid) { #ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE @@ -152,5 +152,23 @@ bool ResSchedUtil::CheckShouldForceKillProcess(int32_t pid) return true; #endif } + +void ResSchedUtil::ReportLoadingEventToRss(LoadingStage stage, int32_t pid, int32_t uid, int64_t timeDuration) +{ +#ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE + uint32_t resType = ResourceSchedule::ResType::RES_TYPE_KEY_PERF_SCENE; + std::unordered_map eventParams { + { "extType", "10015"}, + { "pid", std::to_string(pid) }, + { "uid", std::to_string(uid) }, + }; + if (timeDuration > 0) { // millisecond + eventParams.emplace("timeoutDuration", std::to_string(timeDuration)); + } + int64_t type = static_cast(stage); + TAG_LOGD(AAFwkTag::DEFAULT, "call"); + ResourceSchedule::ResSchedClient::GetInstance().ReportData(resType, type, eventParams); +#endif +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/test/fuzztest/abilitymanagerservicefirst_fuzzer/abilitymanagerservicefirst_fuzzer.cpp b/test/fuzztest/abilitymanagerservicefirst_fuzzer/abilitymanagerservicefirst_fuzzer.cpp index ac802e6dd8..934fdcf3b6 100755 --- a/test/fuzztest/abilitymanagerservicefirst_fuzzer/abilitymanagerservicefirst_fuzzer.cpp +++ b/test/fuzztest/abilitymanagerservicefirst_fuzzer/abilitymanagerservicefirst_fuzzer.cpp @@ -95,7 +95,7 @@ void DoSomethingInterestingWithMyAPI1(AbilityManagerService &abilityms, Want& wa AppExecFwk::ExtensionAbilityType extensionType = ExtensionAbilityType::SERVICE; abilityms.CheckOptExtensionAbility(want, abilityRequest, int32Param, extensionType); AppExecFwk::AbilityInfo abilityInfo; - abilityms.ReportAbilitStartInfoToRSS(abilityInfo); + abilityms.ReportAbilityStartInfoToRSS(abilityInfo); abilityms.ReportEventToRSS(abilityInfo, token); abilityms.StartExtensionAbility(want, token, int32Param, extensionType); abilityms.StopExtensionAbility(want, token, int32Param, extensionType); diff --git a/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp b/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp index 3d928e8582..d2b26b994c 100644 --- a/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp +++ b/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp @@ -240,38 +240,38 @@ HWTEST_F(AbilityManagerServiceFourthTest, GetConfiguration_001, TestSize.Level1) /* * Feature: AbilityManagerService - * Function: ReportAbilitStartInfoToRSS - * FunctionPoints: AbilityManagerService ReportAbilitStartInfoToRSS + * Function: ReportAbilityStartInfoToRSS + * FunctionPoints: AbilityManagerService ReportAbilityStartInfoToRSS */ -HWTEST_F(AbilityManagerServiceFourthTest, ReportAbilitStartInfoToRSS_001, TestSize.Level1) +HWTEST_F(AbilityManagerServiceFourthTest, ReportAbilityStartInfoToRSS_001, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportAbilitStartInfoToRSS start"); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportAbilityStartInfoToRSS start"); auto abilityMs = std::make_shared(); AppExecFwk::AbilityInfo abilityInfo; abilityInfo.type = AppExecFwk::AbilityType::PAGE; - abilityMs->ReportAbilitStartInfoToRSS(abilityInfo); + abilityMs->ReportAbilityStartInfoToRSS(abilityInfo); EXPECT_EQ(abilityInfo.type, AppExecFwk::AbilityType::PAGE); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportAbilitStartInfoToRSS end"); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportAbilityStartInfoToRSS end"); } /* * Feature: AbilityManagerService - * Function: ReportAbilitAssociatedStartInfoToRSS - * FunctionPoints: AbilityManagerService ReportAbilitAssociatedStartInfoToRSS + * Function: ReportAbilityAssociatedStartInfoToRSS + * FunctionPoints: AbilityManagerService ReportAbilityAssociatedStartInfoToRSS */ -HWTEST_F(AbilityManagerServiceFourthTest, ReportAbilitAssociatedStartInfoToRSS_001, TestSize.Level1) +HWTEST_F(AbilityManagerServiceFourthTest, ReportAbilityAssociatedStartInfoToRSS_001, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportAbilitAssociatedStartInfoToRSS start"); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportAbilityAssociatedStartInfoToRSS start"); auto abilityMs = std::make_shared(); AppExecFwk::AbilityInfo abilityInfo; abilityInfo.type = AppExecFwk::AbilityType::PAGE; sptr callerToken = nullptr; int64_t type = 0; - abilityMs->ReportAbilitAssociatedStartInfoToRSS(abilityInfo, type, callerToken); + abilityMs->ReportAbilityAssociatedStartInfoToRSS(abilityInfo, type, callerToken); callerToken = MockToken(AbilityType::PAGE); - abilityMs->ReportAbilitAssociatedStartInfoToRSS(abilityInfo, type, callerToken); + abilityMs->ReportAbilityAssociatedStartInfoToRSS(abilityInfo, type, callerToken); EXPECT_EQ(abilityInfo.type, AppExecFwk::AbilityType::PAGE); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportAbilitAssociatedStartInfoToRSS end"); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportAbilityAssociatedStartInfoToRSS end"); } /* diff --git a/test/unittest/ams_ability_running_record_test/BUILD.gn b/test/unittest/ams_ability_running_record_test/BUILD.gn index 7dde291834..2824d5a84c 100644 --- a/test/unittest/ams_ability_running_record_test/BUILD.gn +++ b/test/unittest/ams_ability_running_record_test/BUILD.gn @@ -64,6 +64,7 @@ ohos_unittest("AmsAbilityRunningRecordTest") { "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] diff --git a/test/unittest/ams_service_app_spawn_client_test/BUILD.gn b/test/unittest/ams_service_app_spawn_client_test/BUILD.gn index fbb03dc061..f18800721c 100644 --- a/test/unittest/ams_service_app_spawn_client_test/BUILD.gn +++ b/test/unittest/ams_service_app_spawn_client_test/BUILD.gn @@ -68,6 +68,7 @@ ohos_unittest("AmsServiceAppSpawnClientTest") { "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", diff --git a/test/unittest/ams_service_event_drive_test/BUILD.gn b/test/unittest/ams_service_event_drive_test/BUILD.gn index 1e386bf5d8..fc76314946 100644 --- a/test/unittest/ams_service_event_drive_test/BUILD.gn +++ b/test/unittest/ams_service_event_drive_test/BUILD.gn @@ -68,6 +68,7 @@ ohos_unittest("AmsServiceEventDriveTest") { "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", diff --git a/test/unittest/ams_service_startup_test/BUILD.gn b/test/unittest/ams_service_startup_test/BUILD.gn index 8f71f93e9b..0f06566865 100644 --- a/test/unittest/ams_service_startup_test/BUILD.gn +++ b/test/unittest/ams_service_startup_test/BUILD.gn @@ -66,6 +66,7 @@ ohos_unittest("AmsServiceStartupTest") { "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", diff --git a/test/unittest/lifecycle_test/BUILD.gn b/test/unittest/lifecycle_test/BUILD.gn index 6f18cd33af..9896b0b856 100644 --- a/test/unittest/lifecycle_test/BUILD.gn +++ b/test/unittest/lifecycle_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("lifecycle_test") { include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/include", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit/include", + "${ability_runtime_utils_path}/global/constant", ] sources = [ "lifecycle_test.cpp" ] diff --git a/test/unittest/lifecycle_test/lifecycle_test.cpp b/test/unittest/lifecycle_test/lifecycle_test.cpp index 2c69eebc73..9399d7e50d 100644 --- a/test/unittest/lifecycle_test/lifecycle_test.cpp +++ b/test/unittest/lifecycle_test/lifecycle_test.cpp @@ -30,6 +30,15 @@ using namespace OHOS::AppExecFwk; namespace OHOS { namespace AAFwk { +#ifdef SUPPORT_ASAN +constexpr uint32_t LOAD_TIMEOUT = 150000; // ms +constexpr uint32_t ACTIVE_TIMEOUT = 75000; // ms +constexpr uint32_t INACTIVE_TIMEOUT = 7500; // ms +#else +constexpr uint32_t LOAD_TIMEOUT = 10000; // ms +constexpr uint32_t ACTIVE_TIMEOUT = 5000; // ms +constexpr uint32_t INACTIVE_TIMEOUT = 500; // ms +#endif class LifecycleTest : public testing::Test, public LifecycleTestBase { public: static void SetUpTestCase(); @@ -145,7 +154,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_003, TestS pthread_t tid = 0; pthread_create(&tid, nullptr, LifecycleTest::AbilityStartThread, command_.get()); int ret = - LifecycleTest::SemTimedWaitMillis(AbilityManagerService::LOAD_TIMEOUT + DELAY_TEST_TIME, command_->sem_); + LifecycleTest::SemTimedWaitMillis(LOAD_TIMEOUT + DELAY_TEST_TIME, command_->sem_); EXPECT_NE(ret, 0); // check timeout handler EXPECT_EQ(launcherAbilityRecord_->GetAbilityState(), OHOS::AAFwk::AbilityState::ACTIVE); @@ -175,7 +184,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_004, TestS pthread_t tid = 0; pthread_create(&tid, nullptr, LifecycleTest::AbilityStartThread, command_.get()); int ret = - LifecycleTest::SemTimedWaitMillis(AbilityManagerService::LOAD_TIMEOUT + DELAY_TEST_TIME, command_->sem_); + LifecycleTest::SemTimedWaitMillis(LOAD_TIMEOUT + DELAY_TEST_TIME, command_->sem_); if (ret != 0) { // check timeout handler GTEST_LOG_(INFO) << "timeout. It shouldn't happen."; @@ -209,7 +218,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_005, TestS pthread_create(&tid, nullptr, LifecycleTest::AbilityStartThread, command_.get()); int ret = - LifecycleTest::SemTimedWaitMillis(AbilityManagerService::LOAD_TIMEOUT + DELAY_TEST_TIME, command_->sem_); + LifecycleTest::SemTimedWaitMillis(LOAD_TIMEOUT + DELAY_TEST_TIME, command_->sem_); if (ret != 0) { // check timeout handler. It won't happen normally. GTEST_LOG_(INFO) << "timeout. It shouldn't happen."; @@ -243,7 +252,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_006, TestS command_->state_ = OHOS::AAFwk::AbilityState::INITIAL; pthread_t tid = 0; pthread_create(&tid, nullptr, LifecycleTest::AbilityStartThread, command_.get()); - int ret = LifecycleTest::SemTimedWaitMillis(AbilityManagerService::ACTIVE_TIMEOUT, command_->sem_); + int ret = LifecycleTest::SemTimedWaitMillis(ACTIVE_TIMEOUT, command_->sem_); EXPECT_NE(ret, 0); // check AttachAbilityThread timeout handler EXPECT_EQ(launcherAbilityRecord_->IsReady(), false); @@ -272,7 +281,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_001, TestSize.Leve launcherAbilityRecord_->SetAbilityState(OHOS::AAFwk::AbilityState::INACTIVATING); pthread_t tid = 0; pthread_create(&tid, nullptr, LifecycleTest::AbilityStartThread, command_.get()); - int ret = LifecycleTest::SemTimedWaitMillis(AbilityManagerService::INACTIVE_TIMEOUT, command_->sem_); + int ret = LifecycleTest::SemTimedWaitMillis(INACTIVE_TIMEOUT, command_->sem_); EXPECT_NE(ret, 0); // check AbilityTransitionDone timeout handler EXPECT_NE(nextAbilityRecord_->GetAbilityState(), OHOS::AAFwk::AbilityState::INACTIVATING); @@ -328,7 +337,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_003, TestSize.Leve pthread_t tid = 0; pthread_create(&tid, nullptr, LifecycleTest::AbilityStartThread, command_.get()); int ret = LifecycleTest::SemTimedWaitMillis( - AbilityManagerService::INACTIVE_TIMEOUT + DELAY_TEST_TIME, command_->sem_); + INACTIVE_TIMEOUT + DELAY_TEST_TIME, command_->sem_); EXPECT_NE(ret, 0); // check timeout handler EXPECT_EQ(nextAbilityRecord_->GetAbilityState(), OHOS::AAFwk::AbilityState::ACTIVATING); @@ -391,7 +400,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_005, TestSize.Leve pthread_t tid = 0; pthread_create(&tid, nullptr, LifecycleTest::AbilityStartThread, command_.get()); int ret = - LifecycleTest::SemTimedWaitMillis(AbilityManagerService::LOAD_TIMEOUT + DELAY_TEST_TIME, command_->sem_); + LifecycleTest::SemTimedWaitMillis(LOAD_TIMEOUT + DELAY_TEST_TIME, command_->sem_); if (ret != 0) { // check timeout handler pthread_join(tid, nullptr); @@ -424,7 +433,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_006, TestSize.Leve pthread_t tid = 0; pthread_create(&tid, nullptr, LifecycleTest::AbilityStartThread, command_.get()); int ret = - LifecycleTest::SemTimedWaitMillis(AbilityManagerService::ACTIVE_TIMEOUT + DELAY_TEST_TIME, command_->sem_); + LifecycleTest::SemTimedWaitMillis(ACTIVE_TIMEOUT + DELAY_TEST_TIME, command_->sem_); EXPECT_NE(ret, 0); pthread_join(tid, nullptr); return; @@ -459,7 +468,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_007, TestSize.Leve EXPECT_EQ(AttachAbility(nextScheduler_, nextToken_), 0); pthread_t tid = 0; pthread_create(&tid, nullptr, LifecycleTest::AbilityStartThread, command_.get()); - int ret = LifecycleTest::SemTimedWaitMillis(AbilityManagerService::ACTIVE_TIMEOUT * 2, command_->sem_); + int ret = LifecycleTest::SemTimedWaitMillis(ACTIVE_TIMEOUT * 2, command_->sem_); if (ret != 0) { // check timeout handler pthread_join(tid, nullptr); diff --git a/test/unittest/res_sched_util_test/res_sched_util_test.cpp b/test/unittest/res_sched_util_test/res_sched_util_test.cpp index 43818deff3..7db03e02b0 100644 --- a/test/unittest/res_sched_util_test/res_sched_util_test.cpp +++ b/test/unittest/res_sched_util_test/res_sched_util_test.cpp @@ -50,7 +50,7 @@ void ResSchedUtilTest::TearDown() /** * @tc.number: ResSchedUtilTest_0100 - * @tc.desc: Test ReportAbilitStartInfoToRSS works + * @tc.desc: Test ReportAbilityStartInfoToRSS works * @tc.type: FUNC */ HWTEST_F(ResSchedUtilTest, ResSchedUtilTest_0100, TestSize.Level0) @@ -58,15 +58,15 @@ HWTEST_F(ResSchedUtilTest, ResSchedUtilTest_0100, TestSize.Level0) TAG_LOGI(AAFwkTag::TEST, "ResSchedUtilTest_0100 called."); AbilityInfo abilityInfo; int64_t resSchedType = -1; - AAFwk::ResSchedUtil::GetInstance().ReportAbilitStartInfoToRSS(abilityInfo, -1, false); - AAFwk::ResSchedUtil::GetInstance().ReportAbilitAssociatedStartInfoToRSS(abilityInfo, resSchedType, 0, 0); + AAFwk::ResSchedUtil::GetInstance().ReportAbilityStartInfoToRSS(abilityInfo, -1, false); + AAFwk::ResSchedUtil::GetInstance().ReportAbilityAssociatedStartInfoToRSS(abilityInfo, resSchedType, 0, 0); int64_t ret = AAFwk::ResSchedUtil::GetInstance().convertType(resSchedType); EXPECT_EQ(resSchedType, ret); } /** * @tc.number: ResSchedUtilTest_0200 - * @tc.desc: Test ReportAbilitStartInfoToRSS works + * @tc.desc: Test ReportAbilityStartInfoToRSS works * @tc.type: FUNC */ HWTEST_F(ResSchedUtilTest, ResSchedUtilTest_0200, TestSize.Level0) @@ -80,5 +80,20 @@ HWTEST_F(ResSchedUtilTest, ResSchedUtilTest_0200, TestSize.Level0) int64_t ret = AAFwk::ResSchedUtil::GetInstance().convertType(resSchedType); EXPECT_EQ(resSchedType, ret); } + +/** + * @tc.number: ResSchedUtilTest_0300 + * @tc.desc: Test ReportLoadingEventToRss works + * @tc.type: FUNC + */ +HWTEST_F(ResSchedUtilTest, ResSchedUtilTest_0300, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "ResSchedUtilTest_0300 called."); + AAFwk::ResSchedUtil::GetInstance().ReportLoadingEventToRss(AAFwk::LoadingStage::LOAD_BEGIN, + 0, 0, 0); + int64_t resSchedType = AAFwk::RES_TYPE_SCB_START_ABILITY; + int64_t ret = AAFwk::ResSchedUtil::GetInstance().convertType(resSchedType); + EXPECT_EQ(resSchedType, ret); +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/utils/global/constant/global_constant.h b/utils/global/constant/global_constant.h index 7ef355315b..1beb97646a 100644 --- a/utils/global/constant/global_constant.h +++ b/utils/global/constant/global_constant.h @@ -19,6 +19,37 @@ namespace OHOS::AbilityRuntime { namespace GlobalConstant { constexpr int32_t MAX_APP_CLONE_INDEX = 1000; + +constexpr int32_t TIMEOUT_UNIT_TIME = 1000; + +#ifdef SUPPORT_ASAN +constexpr int32_t COLDSTART_TIMEOUT_MULTIPLE = 15000; +constexpr int32_t LOAD_TIMEOUT_MULTIPLE = 15000; +constexpr int32_t FOREGROUND_TIMEOUT_MULTIPLE = 7500; +constexpr int32_t BACKGROUND_TIMEOUT_MULTIPLE = 4500; +constexpr int32_t ACTIVE_TIMEOUT_MULTIPLE = 7500; +constexpr int32_t TERMINATE_TIMEOUT_MULTIPLE = 15000; +constexpr int32_t INACTIVE_TIMEOUT_MULTIPLE = 800; +constexpr int32_t DUMP_TIMEOUT_MULTIPLE = 1500; +constexpr int32_t SHAREDATA_TIMEOUT_MULTIPLE = 7500; +#else +constexpr int32_t COLDSTART_TIMEOUT_MULTIPLE = 10; +constexpr int32_t LOAD_TIMEOUT_MULTIPLE = 10; +constexpr int32_t FOREGROUND_TIMEOUT_MULTIPLE = 5; +constexpr int32_t BACKGROUND_TIMEOUT_MULTIPLE = 3; +constexpr int32_t ACTIVE_TIMEOUT_MULTIPLE = 5; +constexpr int32_t TERMINATE_TIMEOUT_MULTIPLE = 10; +constexpr int32_t INACTIVE_TIMEOUT_MULTIPLE = 1; +constexpr int32_t DUMP_TIMEOUT_MULTIPLE = 1000; +constexpr int32_t SHAREDATA_TIMEOUT_MULTIPLE = 5; +constexpr int32_t TYPE_RESERVE = 1; +constexpr int32_t TYPE_OTHERS = 2; +#endif + +constexpr int32_t GetLoadTimeOutBase() +{ + return TIMEOUT_UNIT_TIME * LOAD_TIMEOUT_MULTIPLE; +} } // namespace GlobalConstant } // namespace OHOS::AbilityRuntime #endif // OHOS_ABILITY_RUNTIME_GLOBAL_CONSTANT_H \ No newline at end of file