From 30716ec48117ffa4628974714e3d9c46b417660b Mon Sep 17 00:00:00 2001 From: h60047265 Date: Fri, 18 Apr 2025 19:50:01 +0800 Subject: [PATCH] =?UTF-8?q?510=E4=BB=A3=E7=A0=81=E5=B7=AE=E5=BC=82?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: h60047265 --- .../source/system_ability_manager_proxy.cpp | 5 - interfaces/innerkits/rust/src/definition.rs | 2 + .../include/if_local_ability_manager.h | 10 - .../include/if_system_ability_manager.h | 12 - .../include/local_ability_manager_proxy.h | 1 - .../include/safwk_ipc_interface_code.h | 1 - .../include/system_ability_definition.h | 1 + .../include/system_ability_manager_proxy.h | 9 - services/dfx/source/hisysevent_adapter.cpp | 4 +- .../src/local_ability_manager_proxy.cpp | 42 -- .../native/include/system_ability_manager.h | 4 - .../include/system_ability_manager_dumper.h | 27 +- .../source/system_ability_manager_dumper.cpp | 278 +----------- services/samgr/native/test/unittest/BUILD.gn | 51 +-- .../mock_system_ability_manager_test.h | 30 -- .../include/system_ability_manager_mock.h | 101 ----- .../src/device_timed_collect_test.cpp | 4 +- .../src/local_ability_manager_proxy_test.cpp | 52 --- .../src/mock_system_ability_manager_test.cpp | 106 ----- .../system_ability_manager_dumper_test.cpp | 312 ++----------- .../src/system_ability_manager_mock.cpp | 197 -------- .../src/system_ability_mgr_load_test.cpp | 31 +- .../src/system_ability_mgr_new_test.cpp | 95 +++- .../src/system_ability_mgr_proxy_test.cpp | 1 - .../unittest/src/system_ability_mgr_test.cpp | 425 ++++++++---------- .../samgrdumper_fuzzer/samgrdumper_fuzzer.cpp | 28 +- 26 files changed, 378 insertions(+), 1451 deletions(-) delete mode 100644 services/samgr/native/test/unittest/include/mock_system_ability_manager_test.h delete mode 100644 services/samgr/native/test/unittest/include/system_ability_manager_mock.h delete mode 100644 services/samgr/native/test/unittest/src/mock_system_ability_manager_test.cpp delete mode 100644 services/samgr/native/test/unittest/src/system_ability_manager_mock.cpp diff --git a/frameworks/native/source/system_ability_manager_proxy.cpp b/frameworks/native/source/system_ability_manager_proxy.cpp index 3a7186e5..93784dee 100644 --- a/frameworks/native/source/system_ability_manager_proxy.cpp +++ b/frameworks/native/source/system_ability_manager_proxy.cpp @@ -1562,9 +1562,4 @@ int32_t SystemAbilityManagerProxy::GetCommonEventExtraDataIdlist(int32_t saId, s } return ERR_OK; } - -sptr SystemAbilityManagerProxy::GetLocalAbilityManagerProxy(int32_t systemAbilityId) -{ - return nullptr; -} } // namespace OHOS diff --git a/interfaces/innerkits/rust/src/definition.rs b/interfaces/innerkits/rust/src/definition.rs index fd1bd0e2..f7390324 100644 --- a/interfaces/innerkits/rust/src/definition.rs +++ b/interfaces/innerkits/rust/src/definition.rs @@ -306,6 +306,8 @@ pub const ECOLOGICAL_RULE_MANAGER_SA_ID: i32 = 6105; pub const SUBSYS_ACE_SYS_ABILITY_ID_BEGIN: i32 = 7001; pub const ARKUI_UI_APPEARANCE_SERVICE_ID: i32 = 7002; pub const CA_DAEMON_ID: i32 = 8001; +pub const TRUSTED_SERVICE_ID: i32 = 8002; +pub const ANTI_FRAUD_SERVICE_ID: i32 = 8003; pub const COMM_WEARABLE_DISTRIBUTED_NET_ABILITY_ID: i32 = 8400; // reserved for vendor diff --git a/interfaces/innerkits/samgr_proxy/include/if_local_ability_manager.h b/interfaces/innerkits/samgr_proxy/include/if_local_ability_manager.h index 1a4f5332..2fcedb6b 100755 --- a/interfaces/innerkits/samgr_proxy/include/if_local_ability_manager.h +++ b/interfaces/innerkits/samgr_proxy/include/if_local_ability_manager.h @@ -32,14 +32,6 @@ enum { IPC_STAT_CMD_GET = 2, IPC_STAT_CMD_MAX = 3 }; - -enum { - FFRT_STAT_CMD_START = 0, - FFRT_STAT_CMD_STOP = 1, - FFRT_STAT_CMD_GET = 2, - FFRT_STAT_CMD_MAX = 3 -}; - class SystemAbilityExtensionPara { public: SystemAbilityExtensionPara() @@ -62,7 +54,6 @@ public: return true; }; }; - class ILocalAbilityManager : public IRemoteBroker { public: virtual bool StartAbility(int32_t systemAbilityId, const std::string& eventStr) = 0; @@ -73,7 +64,6 @@ public: const nlohmann::json& idleReason, int32_t& delayTime) = 0; virtual bool SendStrategyToSA(int32_t type, int32_t systemAbilityId, int32_t level, std::string& action) = 0; virtual bool IpcStatCmdProc(int32_t fd, int32_t cmd) = 0; - virtual bool FfrtStatCmdProc(int32_t fd, int32_t cmd) = 0; virtual bool FfrtDumperProc(std::string& result) = 0; virtual int32_t SystemAbilityExtProc(const std::string& extension, int32_t said, SystemAbilityExtensionPara* callback, bool isAsync = false) = 0; diff --git a/interfaces/innerkits/samgr_proxy/include/if_system_ability_manager.h b/interfaces/innerkits/samgr_proxy/include/if_system_ability_manager.h index f1523911..c2395d8d 100644 --- a/interfaces/innerkits/samgr_proxy/include/if_system_ability_manager.h +++ b/interfaces/innerkits/samgr_proxy/include/if_system_ability_manager.h @@ -291,18 +291,6 @@ public: virtual int32_t GetExtensionRunningSaList(const std::string& extension, std::vector>& saList) = 0; - /** - * GetLocalAbilityManagerProxy, Return local ability manager proxy. - * - * @param systemAbilityId, need to obtain the said of sa. - * @return nullptr indicates acquistion failure. - */ - virtual sptr GetLocalAbilityManagerProxy(int32_t systemAbilityId) - { - (void)systemAbilityId; - return nullptr; - } - /** * GetRunningSaExtensionInfoList, Return list of started said and process hanlde that match extension. * diff --git a/interfaces/innerkits/samgr_proxy/include/local_ability_manager_proxy.h b/interfaces/innerkits/samgr_proxy/include/local_ability_manager_proxy.h index f4f9d6b9..7fb3a630 100755 --- a/interfaces/innerkits/samgr_proxy/include/local_ability_manager_proxy.h +++ b/interfaces/innerkits/samgr_proxy/include/local_ability_manager_proxy.h @@ -38,7 +38,6 @@ public: const nlohmann::json& idleReason, int32_t& delayTime); bool SendStrategyToSA(int32_t type, int32_t systemAbilityId, int32_t level, std::string& action); bool IpcStatCmdProc(int32_t fd, int32_t cmd); - bool FfrtStatCmdProc(int32_t fd, int32_t cmd); bool FfrtDumperProc(std::string& ffrtDumperInfo); int32_t SystemAbilityExtProc(const std::string& extension, int32_t said, SystemAbilityExtensionPara* callback, bool isAsync = false); diff --git a/interfaces/innerkits/samgr_proxy/include/safwk_ipc_interface_code.h b/interfaces/innerkits/samgr_proxy/include/safwk_ipc_interface_code.h index 8d3dff42..708df087 100755 --- a/interfaces/innerkits/samgr_proxy/include/safwk_ipc_interface_code.h +++ b/interfaces/innerkits/samgr_proxy/include/safwk_ipc_interface_code.h @@ -27,7 +27,6 @@ enum SafwkInterfaceCode : uint32_t { IPC_STAT_CMD_TRANSACTION = 6, FFRT_DUMPER_TRANSACTION = 7, SYSTEM_ABILITY_EXT_TRANSACTION = 8, - FFRT_STAT_CMD_TRANSACTION = 9, }; } #endif // !defined(SAFWK_IPC_INTERFACE_CODE_H) \ No newline at end of file diff --git a/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h b/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h index 354fb74a..b7b64cb6 100644 --- a/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h +++ b/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h @@ -320,6 +320,7 @@ enum { ARKUI_UI_APPEARANCE_SERVICE_ID = 7002, CA_DAEMON_ID = 8001, TRUSTED_SERVICE_ID = 8002, + ANTI_FRAUD_SERVICE_ID = 8003, ASSET_SERVICE_ID = 8100, EL5_FILEKEY_MANAGER_SERVICE_ID = 8250, COMM_FIREWALL_MANAGER_SYS_ABILITY_ID = 8300, diff --git a/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h b/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h index 506c267e..4e30f72d 100644 --- a/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h +++ b/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h @@ -255,15 +255,6 @@ public: * @return ERR_OK indicates that the list of hanlde that match extension success. */ int32_t GetExtensionRunningSaList(const std::string& extension, std::vector>& saList) override; - - /** - * GetLocalAbilityManagerProxy, Return local ability manager proxy. - * - * @param systemAbilityId, need to obtain the said of sa. - * @return nullptr indicates acquistion failure. - */ - sptr GetLocalAbilityManagerProxy(int32_t systemAbilityId) override; - int32_t GetRunningSaExtensionInfoList(const std::string& extension, std::vector& infoList) override; int32_t GetCommonEventExtraDataIdlist(int32_t saId, std::vector& extraDataIdList, diff --git a/services/dfx/source/hisysevent_adapter.cpp b/services/dfx/source/hisysevent_adapter.cpp index 6bb315b4..dc6e6eb4 100644 --- a/services/dfx/source/hisysevent_adapter.cpp +++ b/services/dfx/source/hisysevent_adapter.cpp @@ -60,8 +60,8 @@ constexpr int32_t CONTAINER_SA_MAX = 0x0001055f; //66911 static bool IsInCrashWhiteList(int32_t saId) { - std::vector whiteList = { 10, 1201, 1202, 1203, 1204, 1205, 1213, 1215, 5002, 5100, 5110, 9999, 65537, 65830, - 65850, 66064, 66186, 69930, 131071, 345135 }; + std::vector whiteList = { 1205, 1213, 1215, 9999, 65537, 65830, + 65850, 65888, 69930, 131071, 345135 }; for (auto sa : whiteList) { if (saId == sa) { return true; diff --git a/services/lsamgr/src/local_ability_manager_proxy.cpp b/services/lsamgr/src/local_ability_manager_proxy.cpp index efc62102..8ae8dee6 100644 --- a/services/lsamgr/src/local_ability_manager_proxy.cpp +++ b/services/lsamgr/src/local_ability_manager_proxy.cpp @@ -305,48 +305,6 @@ bool LocalAbilityManagerProxy::IpcStatCmdProc(int32_t fd, int32_t cmd) return result; } -bool LocalAbilityManagerProxy::FfrtStatCmdProc(int32_t fd, int32_t cmd) -{ - sptr iro = Remote(); - if (iro == nullptr) { - HILOG_ERROR(LOG_CORE, "FfrtStatCmdProc Remote null"); - return false; - } - - MessageParcel data; - if (!data.WriteInterfaceToken(LOCAL_ABILITY_MANAGER_INTERFACE_TOKEN)) { - HILOG_WARN(LOG_CORE, "FfrtStatCmdProc interface token check failed"); - return false; - } - - if (!data.WriteFileDescriptor(fd)) { - HILOG_WARN(LOG_CORE, "FfrtStatCmdProc write fd failed"); - return false; - } - - if (!data.WriteInt32(cmd)) { - HILOG_WARN(LOG_CORE, "FfrtStatCmdProc write cmd faild"); - return false; - } - - MessageParcel reply; - MessageOption option; - int32_t status = iro->SendRequest( - static_cast(SafwkInterfaceCode::FFRT_STAT_CMD_TRANSACTION), data, reply, option); - if (status != NO_ERROR) { - HILOG_ERROR(LOG_CORE, "FfrtStatCmdProc SendRequest failed, return value : %{public}d", status); - return false; - } - - bool result = false; - if (!reply.ReadBool(result)) { - HILOG_WARN(LOG_CORE, "FfrtStatCmdProc read bool faild"); - return false; - } - - return result; -} - bool LocalAbilityManagerProxy::FfrtDumperProc(std::string& ffrtDumperInfo) { sptr iro = Remote(); diff --git a/services/samgr/native/include/system_ability_manager.h b/services/samgr/native/include/system_ability_manager.h index e1818ee5..fffcb526 100644 --- a/services/samgr/native/include/system_ability_manager.h +++ b/services/samgr/native/include/system_ability_manager.h @@ -229,10 +229,6 @@ public: int32_t GetCommonEventExtraDataIdlist(int32_t saId, std::vector& extraDataIdList, const std::string& eventName = "") override; sptr GetSystemProcess(const std::u16string& procName); - sptr GetLocalAbilityManagerProxy(int32_t systemAbilityId) override - { - return nullptr; - } bool IsModuleUpdate(int32_t systemAbilityId) { CommonSaProfile saProfile; diff --git a/services/samgr/native/include/system_ability_manager_dumper.h b/services/samgr/native/include/system_ability_manager_dumper.h index f0091025..33295c48 100644 --- a/services/samgr/native/include/system_ability_manager_dumper.h +++ b/services/samgr/native/include/system_ability_manager_dumper.h @@ -21,7 +21,6 @@ #include "schedule/system_ability_state_scheduler.h" #include "system_ability_manager.h" -#include "if_local_ability_manager.h" namespace OHOS { enum { @@ -30,11 +29,6 @@ enum { IPC_STAT_CMD_INDEX = 2 }; -enum { - FFRT_STAT_PREFIX_INDEX = 0, - FFRT_STAT_PROCESS_INDEX = 1, - FFRT_STAT_CMD_INDEX = 2 -}; constexpr int32_t IPC_STAT_CMD_LEN = 3; class SystemAbilityManagerDumper { @@ -50,13 +44,6 @@ public: static bool FfrtDumpParser(std::vector& processIds, const std::string& processIdsStr); static int32_t FfrtDumpProc(std::shared_ptr abilityStateScheduler, int32_t fd, const std::vector& args); - static void GetFfrtLoadMetrics(std::shared_ptr abilityStateScheduler, - int32_t fd, const std::vector& args, std::string& result); - static bool FfrtStatCmdParser(int32_t& cmd, const std::vector& args); - static void CollectFfrtMetricInfoInProcs(int32_t fd, const std::vector& processIds, - std::shared_ptr abilityStateScheduler, int32_t cmd, std::string& result); - static sptr GetProcByProcessId( - std::shared_ptr abilityStateScheduler, int32_t processId); static bool GetFfrtDumpInfoProc(std::shared_ptr abilityStateScheduler, const std::vector& args, std::string& result); static int32_t ListenerDumpProc(std::map>& listeners, @@ -65,13 +52,6 @@ public: private: SystemAbilityManagerDumper() = default; ~SystemAbilityManagerDumper() = default; - static bool CollectFfrtStatistics(int32_t cmd, std::string& result); - static bool StartFfrtStatistics(std::string& result); - static bool StopFfrtStatistics(std::string& result); - static bool GetFfrtStatistics(std::string& result); - static void FfrtStatisticsParser(std::string& result); - static void ClearFfrtStatisticsBufferLocked(); - static void ClearFfrtStatistics(); static bool CanDump(); static void ShowHelp(std::string& result); static void ShowAllSystemAbilityInfo(std::shared_ptr abilityStateScheduler, @@ -83,8 +63,7 @@ private: static void ShowAllSystemAbilityInfoInState(const std::string& state, std::shared_ptr abilityStateScheduler, std::string& result); static void IllegalInput(std::string& result); - static void DumpFfrtInfoInProc( - std::shared_ptr abilityStateScheduler, int32_t pid, std::string& result); + static void DumpFfrtInfoByProcName(int32_t processId, const std::u16string processName, std::string& result); static int32_t SaveDumpResultToFd(int32_t fd, const std::string& result); static void GetSAMgrFfrtInfo(std::string& result); static void GetListenerDumpProc(std::map>& listeners, @@ -97,10 +76,6 @@ private: static void ShowSAByCallingPid(std::map>& listeners, int32_t pid, std::string& result); static void ShowListenerHelp(std::string& result); - static std::shared_ptr handler_; - static char* ffrtMetricBuffer; - static bool collectEnable; - static std::mutex ffrtMetricLock; }; } // namespace OHOS #endif // SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_MANAGER_DUMPER_H \ No newline at end of file diff --git a/services/samgr/native/source/system_ability_manager_dumper.cpp b/services/samgr/native/source/system_ability_manager_dumper.cpp index 7ee5db86..1dfcd431 100644 --- a/services/samgr/native/source/system_ability_manager_dumper.cpp +++ b/services/samgr/native/source/system_ability_manager_dumper.cpp @@ -40,15 +40,7 @@ constexpr int32_t FFRT_DUMP_PROC_LEN = 2; constexpr int32_t FFRT_DUMP_PIDS_INDEX = 1; constexpr int FFRT_BUFFER_SIZE = 512 * 1024; constexpr int LISTENER_BASE_INDEX = 1; -constexpr int32_t FFRT_METRIC_CMD_INDEX = 2; -constexpr int32_t FFRT_DUMP_METRIC_LEN = 3; -constexpr int32_t COLLECT_FFRT_METRIC_MAX_SIZE = 5000; -constexpr int32_t FFRT_STAT_SIZE = sizeof(ffrt_stat); -constexpr int32_t BUFFER_SIZE = FFRT_STAT_SIZE * COLLECT_FFRT_METRIC_MAX_SIZE; -constexpr int32_t DELAY_TIME = 60 * 1000; -constexpr const char* FFRT_STAT_STR_START = "--start-stat"; -constexpr const char* FFRT_STAT_STR_STOP = "--stop-stat"; -constexpr const char* FFRT_STAT_STR_GET = "--stat"; + constexpr const char* IPC_STAT_STR_START = "--start-stat"; constexpr const char* IPC_STAT_STR_STOP = "--stop-stat"; constexpr const char* IPC_STAT_STR_GET = "--stat"; @@ -59,11 +51,6 @@ constexpr const char* IPC_DUMP_FAIL = " fail\n"; } -std::shared_ptr SystemAbilityManagerDumper::handler_ = nullptr; -char* SystemAbilityManagerDumper::ffrtMetricBuffer = nullptr; -bool SystemAbilityManagerDumper::collectEnable = false; -std::mutex SystemAbilityManagerDumper::ffrtMetricLock; - void SystemAbilityManagerDumper::ShowListenerHelp(string& result) { result.append("SystemAbilityManager Listener Dump options:\n") @@ -269,245 +256,21 @@ int32_t SystemAbilityManagerDumper::FfrtDumpProc(std::shared_ptr abilityStateScheduler, - int32_t fd, const std::vector& args, std::string& result) +bool SystemAbilityManagerDumper::GetFfrtDumpInfoProc(std::shared_ptr abilityStateScheduler, + const std::vector& args, std::string& result) { - std::string pidStr = args[FFRT_DUMP_PIDS_INDEX]; - std::vector processIds; - FfrtDumpParser(processIds, pidStr); - if (processIds.empty()) { - HILOGE("FfrtDumpParser parse failed, illegal input processIdsStr %{public}s ", pidStr.c_str()); - IllegalInput(result); - return; - } - int32_t cmd = -1; - if (!FfrtStatCmdParser(cmd, args)) { + if (args.size() < FFRT_DUMP_PROC_LEN || args[FFRT_DUMP_PIDS_INDEX].empty()) { + HILOGE("FfrtDump param pid not exist"); IllegalInput(result); - return; - } - CollectFfrtMetricInfoInProcs(fd, processIds, abilityStateScheduler, cmd, result); -} - -bool SystemAbilityManagerDumper::FfrtStatCmdParser(int32_t& cmd, const std::vector& args) -{ - if (args[FFRT_METRIC_CMD_INDEX] == FFRT_STAT_STR_START) { - cmd = FFRT_STAT_CMD_START; - } else if (args[FFRT_METRIC_CMD_INDEX] == FFRT_STAT_STR_STOP) { - cmd = FFRT_STAT_CMD_STOP; - } else if (args[FFRT_METRIC_CMD_INDEX] == FFRT_STAT_STR_GET) { - cmd = FFRT_STAT_CMD_GET; - } else { return false; } - return true; -} - -void SystemAbilityManagerDumper::CollectFfrtMetricInfoInProcs(int32_t fd, const std::vector& processIds, - std::shared_ptr abilityStateScheduler, int32_t cmd, std::string& result) -{ - for (const int32_t pid : processIds) { - if (pid == getpid()) { - CollectFfrtStatistics(cmd, result); - continue; - } - sptr obj = GetProcByProcessId(abilityStateScheduler, pid); - if (obj == nullptr) { - HILOGE("CollectFfrtMetricInfoInProcs GetSystemProcess failed"); - result.append("process " + std::to_string(pid) + " not found!\n"); - continue; - } - obj->FfrtStatCmdProc(fd, cmd); - } -} - -bool SystemAbilityManagerDumper::StartFfrtStatistics(std::string& result) -{ - if (collectEnable) { - result.append("collect has been started\n"); - return false; - } - ClearFfrtStatisticsBufferLocked(); - ffrtMetricBuffer = new char[BUFFER_SIZE](); - auto ret = ffrt_dump(ffrt_dump_cmd_t::DUMP_START_STAT, ffrtMetricBuffer, BUFFER_SIZE); - if (ret != ERR_OK) { - ClearFfrtStatisticsBufferLocked(); - result.append("collect start failed\n"); - return false; - } - collectEnable = true; - result.append("collect start success\n"); - if (handler_ == nullptr) { - handler_ = std::make_shared("ffrtDumpHandler"); - } - HILOGI("StartFfrtStatistics PostTask delayTime:%{public}dms", DELAY_TIME); - handler_->PostTask(ClearFfrtStatistics, "ClearFfrtStatistics", DELAY_TIME); - return true; -} - -bool SystemAbilityManagerDumper::StopFfrtStatistics(std::string& result) -{ - if (!collectEnable) { - result.append("collect has not been started\n"); - return false; - } - collectEnable = false; - auto ret = ffrt_dump(ffrt_dump_cmd_t::DUMP_STOP_STAT, ffrtMetricBuffer, BUFFER_SIZE); - if (ret != ERR_OK) { - ClearFfrtStatisticsBufferLocked(); - result.append("collect stop failed\n"); - return false; - } - result.append("collect stop success\n"); - return true; -} - -bool SystemAbilityManagerDumper::GetFfrtStatistics(std::string& result) -{ - if (collectEnable) { - result.append("collect has not been stopped\n"); - return false; - } - if (ffrtMetricBuffer == nullptr) { - result.append("info not collected\n"); - return false; - } - FfrtStatisticsParser(result); - ClearFfrtStatisticsBufferLocked(); - handler_ = nullptr; - return true; -} - -void SystemAbilityManagerDumper::FfrtStatisticsParser(std::string& result) -{ - ffrt_stat* currentStat = (ffrt_stat*)ffrtMetricBuffer; - char* lastStat = ffrtMetricBuffer + BUFFER_SIZE; - std::string taskInfo; - uint64_t maxTime = 0; - uint64_t minTime = std::numeric_limits::max(); - uint64_t sumTime = 0; - uint64_t avgTime = 0; - int count = 0; - while ((char*)currentStat < lastStat && std::strcmp(currentStat->taskName, "") != 0) { - if (currentStat->startTime > currentStat->endTime) { - currentStat = (ffrt_stat*)((char*)currentStat + FFRT_STAT_SIZE); - continue; - } - auto duration = currentStat->endTime - currentStat->startTime; - sumTime += duration; - maxTime = std::max(maxTime, duration); - minTime = std::min(minTime, duration); - ++count; - taskInfo.append(currentStat->taskName); - taskInfo.append(" " + ToString(currentStat->startTime)); - taskInfo.append(" " + ToString(currentStat->endTime) + "\n"); - currentStat = (ffrt_stat*)((char*)currentStat + FFRT_STAT_SIZE); - } - if (count == 0) { - minTime = 0; - } else { - avgTime = sumTime / count; - } - result.append("sumTime:" + ToString(sumTime) + " maxTime:" + ToString(maxTime)); - result.append(" minTime:" + ToString(minTime) + " avgTime:" + ToString(avgTime)); - result.append(" cntTime:" + ToString(count) + "\n"); - result.append("-------------------------------------------------------------------------------------------\n"); - result.append("taskName startTime(us) endTime(us)\n"); - result.append("-------------------------------------------------------------------------------------------\n"); - result.append(taskInfo); - result.append("-------------------------------------------------------------------------------------------\n"); -} - -void SystemAbilityManagerDumper::ClearFfrtStatisticsBufferLocked() -{ - if (ffrtMetricBuffer != nullptr) { - delete[] ffrtMetricBuffer; - ffrtMetricBuffer = nullptr; - HILOGI("ClearFfrtStatisticsBuffer success"); - } - if (handler_ != nullptr) { - handler_->RemoveTask("ClearFfrtStatistics"); - } -} - -void SystemAbilityManagerDumper::ClearFfrtStatistics() -{ - HILOGW("ClearFfrtStatistics start"); - std::lock_guard autoLock(ffrtMetricLock); - if (collectEnable) { - auto ret = ffrt_dump(ffrt_dump_cmd_t::DUMP_STOP_STAT, ffrtMetricBuffer, BUFFER_SIZE); - if (ret != ERR_OK) { - HILOGE("ClearFfrtStatistics stop ffrt_dump err:%{public}d", ret); - } - collectEnable = false; - } - ClearFfrtStatisticsBufferLocked(); -} - -bool SystemAbilityManagerDumper::CollectFfrtStatistics(int32_t cmd, std::string& result) -{ - std::lock_guard autoLock(ffrtMetricLock); - result.append("pid:" + ToString(getpid()) + " "); - auto ret = false; - switch (cmd) { - case FFRT_STAT_CMD_START: { - ret = StartFfrtStatistics(result); - break; - } - case FFRT_STAT_CMD_STOP: { - ret = StopFfrtStatistics(result); - break; - } - case FFRT_STAT_CMD_GET: { - ret = GetFfrtStatistics(result); - break; - } - default: - break; - } - return ret; -} - -sptr SystemAbilityManagerDumper::GetProcByProcessId( - std::shared_ptr abilityStateScheduler, int32_t processId) -{ - std::u16string processName; - int32_t queryResult = abilityStateScheduler->GetProcessNameByProcessId(processId, processName); - if (queryResult != ERR_OK) { - HILOGE("GetProcessNameByProcessId failed, pid %{public}d not exist", processId); - return nullptr; - } - sptr obj = - iface_cast(SystemAbilityManager::GetInstance()->GetSystemProcess(processName)); - if (obj == nullptr) { - HILOGE("GetSystemProcess failed, pid:%{public}d processName:%{public}s not exist", - processId, Str16ToStr8(processName).c_str()); - } - return obj; -} - -bool SystemAbilityManagerDumper::GetFfrtDumpInfoProc(std::shared_ptr abilityStateScheduler, - const std::vector& args, std::string& result) -{ std::string pidStr = args[FFRT_DUMP_PIDS_INDEX]; std::vector processIds; - FfrtDumpParser(processIds, pidStr); + SystemAbilityManagerDumper::FfrtDumpParser(processIds, pidStr); if (processIds.empty()) { HILOGE("FfrtDumpParser parse failed, illegal input processIdsStr %{public}s ", pidStr.c_str()); IllegalInput(result); @@ -519,7 +282,14 @@ bool SystemAbilityManagerDumper::GetFfrtDumpInfoProc(std::shared_ptrGetProcessNameByProcessId(pid, processName); + if (queryResult != ERR_OK) { + HILOGE("GetProcessNameByProcessId failed, pid %{public}d not exist", pid); + result.append("process " + std::to_string(pid) + " not found!\n"); + continue; + } + DumpFfrtInfoByProcName(pid, processName, result); } return true; } @@ -559,12 +329,14 @@ void SystemAbilityManagerDumper::GetSAMgrFfrtInfo(std::string& result) delete[] buffer; } -void SystemAbilityManagerDumper::DumpFfrtInfoInProc( - std::shared_ptr abilityStateScheduler, int32_t pid, std::string& result) +void SystemAbilityManagerDumper::DumpFfrtInfoByProcName(int32_t pid, const std::u16string processName, + std::string& result) { - sptr obj = GetProcByProcessId(abilityStateScheduler, pid); + sptr obj = + iface_cast(SystemAbilityManager::GetInstance()->GetSystemProcess(processName)); if (obj == nullptr) { - HILOGE("DumpFfrtInfoInProc GetSystemProcess failed"); + HILOGE("GetSystemProcess failed, pid:%{public}d processName:%{public}s not exist", + pid, Str16ToStr8(processName).c_str()); result.append("process " + std::to_string(pid) + " not found!\n"); return; } @@ -745,13 +517,7 @@ void SystemAbilityManagerDumper::ShowHelp(std::string& result) .append(" -sa said: query sa state infos.\n") .append(" -p processname: query process state infos.\n") .append(" -sm state: query all sa based on state infos.\n") - .append(" -l: query all sa state infos.\n") - .append(" --listener -h: help text for listener.\n") - .append(" --ffrt [pid1|pid2] --start-stat/--stop-stat/--stat: start/stop/get") - .append(" the FFRT load statistics of a process.\n") - .append(" --ffrt [pid1|pid2]: query the FFRT dump infos of a process.\n") - .append(" --ipc procname/all --start-stat/--stop-stat/--stat: start/stop/get") - .append(" the IPC load statistics of a process.\n"); + .append(" -l: query all sa state infos.\n"); } void SystemAbilityManagerDumper::ShowAllSystemAbilityInfo( diff --git a/services/samgr/native/test/unittest/BUILD.gn b/services/samgr/native/test/unittest/BUILD.gn index 1093230a..c9841d2e 100644 --- a/services/samgr/native/test/unittest/BUILD.gn +++ b/services/samgr/native/test/unittest/BUILD.gn @@ -478,7 +478,6 @@ ohos_unittest("SystemAbilityMgrProxyTest") { "${samgr_services_dir}/test/unittest/src/mock_iro_sendrequest.cpp", "${samgr_services_dir}/test/unittest/src/mock_permission.cpp", "${samgr_services_dir}/test/unittest/src/sa_status_change_mock.cpp", - "${samgr_services_dir}/test/unittest/src/system_ability_manager_mock.cpp", "${samgr_services_dir}/test/unittest/src/system_ability_mgr_proxy_test.cpp", "//foundation/systemabilitymgr/samgr/frameworks/native/source/system_ability_manager_proxy.cpp", "//foundation/systemabilitymgr/samgr/frameworks/native/source/system_process_status_change_stub.cpp", @@ -564,6 +563,7 @@ ohos_unittest("SystemAbilityStateSchedulerTest") { "${samgr_services_dir}/source/collect/icollect_plugin.cpp", "${samgr_services_dir}/source/ffrt_handler.cpp", "${samgr_services_dir}/source/memory_guard.cpp", + "${samgr_services_dir}/source/rpc_callback_imp.cpp", "${samgr_services_dir}/source/samgr_time_handler.cpp", "${samgr_services_dir}/source/schedule/system_ability_event_handler.cpp", "${samgr_services_dir}/source/schedule/system_ability_state_machine.cpp", @@ -572,7 +572,9 @@ ohos_unittest("SystemAbilityStateSchedulerTest") { "${samgr_services_dir}/source/system_ability_manager_dumper.cpp", "${samgr_services_dir}/source/system_ability_manager_stub.cpp", "${samgr_services_dir}/source/system_ability_manager_util.cpp", + "${samgr_services_dir}/test/unittest/src/itest_transaction_service.cpp", "${samgr_services_dir}/test/unittest/src/mock_accesstoken_kit.cpp", + "${samgr_services_dir}/test/unittest/src/mock_permission.cpp", "${samgr_services_dir}/test/unittest/src/sa_status_change_mock.cpp", "${samgr_services_dir}/test/unittest/src/system_ability_event_handler_test.cpp", "${samgr_services_dir}/test/unittest/src/system_ability_state_machine_test.cpp", @@ -698,52 +700,6 @@ ohos_unittest("SystemAbilityMgrDumperTest") { } } -ohos_unittest("MockSystemAbilityManagerTest") { - module_out_path = module_output_path - - sources = [ - "${samgr_services_dir}/source/ffrt_handler.cpp", - "${samgr_services_dir}/source/system_ability_manager_dumper.cpp", - "${samgr_services_dir}/test/unittest/src/mock_system_ability_manager_test.cpp", - ] - - configs = [ - ":sam_test_config", - "${samgr_dir}/services/samgr/native:sam_config", - "${samgr_dir}/test/resource:coverage_flags", - ] - - if (target_cpu == "arm") { - cflags = [ "-DBINDER_IPC_32BIT" ] - } - - deps = [ ":samgr_proxy_tdd" ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "c_utils:utils", - "ffrt:libffrt", - "googletest:gtest_main", - "hilog:libhilog", - "hisysevent:libhisysevent", - "hitrace:hitrace_meter", - "init:libbeget_proxy", - "init:libbegetutil", - "ipc:ipc_single", - "ipc:libdbinder", - "json:nlohmann_json_static", - "safwk:system_ability_fwk", - ] - defines = [] - if (samgr_support_access_token) { - external_deps += [ - "access_token:libnativetoken_shared", - "access_token:libtokensetproc_shared", - ] - defines += [ "SUPPORT_ACCESS_TOKEN" ] - } -} - ohos_executable("manual_ondemand") { testonly = true sources = [ @@ -979,7 +935,6 @@ group("unittest") { testonly = true deps = [ ":LocalAbilityManagerProxyTest", - ":MockSystemAbilityManagerTest", ":SystemAbilityMgrCollectTest", ":SystemAbilityMgrDeviceNetworkingTest", ":SystemAbilityMgrDumperTest", diff --git a/services/samgr/native/test/unittest/include/mock_system_ability_manager_test.h b/services/samgr/native/test/unittest/include/mock_system_ability_manager_test.h deleted file mode 100644 index cf048648..00000000 --- a/services/samgr/native/test/unittest/include/mock_system_ability_manager_test.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MOCK_SYSTEM_ABILITY_MAGAGER_TEST_H -#define MOCK_SYSTEM_ABILITY_MAGAGER_TEST_H - -#include "gtest/gtest.h" - -namespace OHOS { -class MockSystemAbilityManagerTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; -} -#endif /* MOCK_SYSTEM_ABILITY_MAGAGER_TEST_H */ \ No newline at end of file diff --git a/services/samgr/native/test/unittest/include/system_ability_manager_mock.h b/services/samgr/native/test/unittest/include/system_ability_manager_mock.h deleted file mode 100644 index 1e356b02..00000000 --- a/services/samgr/native/test/unittest/include/system_ability_manager_mock.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef SAMGR_TEST_UNITTEST_INCLUDE_SYSTEM_ABILITY_MANAGER_MOCK_H -#define SAMGR_TEST_UNITTEST_INCLUDE_SYSTEM_ABILITY_MANAGER_MOCK_H - -#include "if_system_ability_manager.h" - -namespace OHOS { -class ISystemAbilityManagerMock : public ISystemAbilityManager { -public: - - std::vector ListSystemAbilities(unsigned int dumpFlags = DUMP_FLAG_PRIORITY_ALL) override; - - sptr GetSystemAbility(int32_t systemAbilityId) override; - - sptr CheckSystemAbility(int32_t systemAbilityId) override; - - int32_t RemoveSystemAbility(int32_t systemAbilityId) override; - - int32_t SubscribeSystemAbility(int32_t systemAbilityId, - const sptr& listener) override; - - int32_t UnSubscribeSystemAbility(int32_t systemAbilityId, - const sptr& listener) override; - - sptr GetSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; - - sptr CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; - - int32_t AddOnDemandSystemAbilityInfo(int32_t systemAbilityId, - const std::u16string& localAbilityManagerName) override; - - sptr CheckSystemAbility(int32_t systemAbilityId, bool& isExist) override; - - int32_t AddSystemAbility(int32_t systemAbilityId, const sptr& ability, - const SAExtraProp& extraProp = SAExtraProp(false, DUMP_FLAG_PRIORITY_DEFAULT, u"", u"")) override; - - int32_t AddSystemProcess(const std::u16string& procName, const sptr& procObject) override; - - sptr LoadSystemAbility(int32_t systemAbilityId, int32_t timeout) override; - - int32_t LoadSystemAbility(int32_t systemAbilityId, const sptr& callback) override; - - int32_t LoadSystemAbility(int32_t systemAbilityId, const std::string& deviceId, - const sptr& callback) override; - - int32_t UnloadSystemAbility(int32_t systemAbilityId) override; - - int32_t CancelUnloadSystemAbility(int32_t systemAbilityId) override; - - int32_t UnloadAllIdleSystemAbility() override; - - int32_t GetSystemProcessInfo(int32_t systemAbilityId, SystemProcessInfo& systemProcessInfo) override; - - int32_t GetRunningSystemProcess(std::list& systemProcessInfos) override; - - int32_t SubscribeSystemProcess(const sptr& listener) override; - - int32_t SendStrategy(int32_t type, std::vector& systemAbilityIds, - int32_t level, std::string& action) override; - - int32_t UnSubscribeSystemProcess(const sptr& listener) override; - - int32_t GetExtensionSaIds(const std::string& extension, std::vector &saIds) override; - - int32_t GetExtensionRunningSaList(const std::string& extension, - std::vector>& saList) override; - - int32_t GetRunningSaExtensionInfoList(const std::string& extension, - std::vector& infoList) override; - - int32_t GetCommonEventExtraDataIdlist(int32_t saId, std::vector& extraDataIdList, - const std::string& eventName = "") override; - - int32_t GetOnDemandReasonExtraData(int64_t extraDataId, MessageParcel& extraDataParcel) override; - - int32_t GetOnDemandPolicy(int32_t systemAbilityId, OnDemandPolicyType type, - std::vector& abilityOnDemandEvents) override; - - int32_t UpdateOnDemandPolicy(int32_t systemAbilityId, OnDemandPolicyType type, - const std::vector& abilityOnDemandEvents) override; - - int32_t GetOnDemandSystemAbilityIds(std::vector& systemAbilityIds) override; - - sptr AsObject() override; -}; -} -#endif /* SAMGR_TEST_UNITTEST_INCLUDE_SYSTEM_ABILITY_MANAGER_MOCK_H */ diff --git a/services/samgr/native/test/unittest/src/device_timed_collect_test.cpp b/services/samgr/native/test/unittest/src/device_timed_collect_test.cpp index 43d7649d..ff627b1a 100644 --- a/services/samgr/native/test/unittest/src/device_timed_collect_test.cpp +++ b/services/samgr/native/test/unittest/src/device_timed_collect_test.cpp @@ -825,6 +825,7 @@ HWTEST_F(DeviceTimedCollectTest, ProcessPersistenceTimedTask002, TestSize.Level3 } #endif +#ifdef PREFERENCES_ENABLE HWTEST_F(DeviceTimedCollectTest, ProcessPersistenceLoopTask001, TestSize.Level3) { DTEST_LOG << " ProcessPersistenceLoopTask001 begin" << std::endl; @@ -842,6 +843,7 @@ HWTEST_F(DeviceTimedCollectTest, ProcessPersistenceLoopTask001, TestSize.Level3) EXPECT_NE(0, disTime); DTEST_LOG << " ProcessPersistenceLoopTask001 end" << std::endl; } +#endif HWTEST_F(DeviceTimedCollectTest, PostNonPersistenceLoopTaskLocked001, TestSize.Level3) { @@ -908,4 +910,4 @@ HWTEST_F(DeviceTimedCollectTest, RemovePersistenceLoopTask001, TestSize.Level3) EXPECT_TRUE(deviceTimedCollect->persitenceLoopEventSet_.empty()); DTEST_LOG << " RemovePersistenceLoopTask001 end" << std::endl; } -} \ No newline at end of file +} diff --git a/services/samgr/native/test/unittest/src/local_ability_manager_proxy_test.cpp b/services/samgr/native/test/unittest/src/local_ability_manager_proxy_test.cpp index af8b0b48..c191b23c 100644 --- a/services/samgr/native/test/unittest/src/local_ability_manager_proxy_test.cpp +++ b/services/samgr/native/test/unittest/src/local_ability_manager_proxy_test.cpp @@ -294,58 +294,6 @@ HWTEST_F(LocalAbilityManagerProxyTest, SendStrategyToSA001, TestSize.Level3) EXPECT_TRUE(ret); } -/** - * @tc.name: FfrtStatCmdProc001 - * @tc.desc: test FfrtStatCmdProc001 - * @tc.type: FUNC - * @tc.require: I9DR69 - */ -HWTEST_F(LocalAbilityManagerProxyTest, FfrtStatCmdProc001, TestSize.Level3) -{ - sptr testAbility(new MockIroSendrequesteStub()); - sptr localAbility(new LocalAbilityManagerProxy(testAbility)); - int32_t fd = 0; - int32_t cmd = 0; - std::string action; - bool ret = localAbility->FfrtStatCmdProc(fd, cmd); - EXPECT_FALSE(ret); -} - -/** - * @tc.name: FfrtStatCmdProc002 - * @tc.desc: test FfrtStatCmdProc002 with fd invalid - * @tc.type: FUNC - * @tc.require: I9DR69 - */ -HWTEST_F(LocalAbilityManagerProxyTest, FfrtStatCmdProc002, TestSize.Level3) -{ - sptr testAbility(new MockIroSendrequesteStub()); - sptr localAbility(new LocalAbilityManagerProxy(testAbility)); - int32_t fd = -1; - int32_t cmd = 0; - std::string action; - bool ret = localAbility->FfrtStatCmdProc(fd, cmd); - EXPECT_FALSE(ret); -} - - -/** - * @tc.name: FfrtStatCmdProc003 - * @tc.desc: test FfrtStatCmdProc003 with cmd valid - * @tc.type: FUNC - * @tc.require: I9DR69 - */ -HWTEST_F(LocalAbilityManagerProxyTest, FfrtStatCmdProc003, TestSize.Level3) -{ - sptr testAbility(new MockIroSendrequesteStub()); - sptr localAbility(new LocalAbilityManagerProxy(testAbility)); - int32_t fd = 0; - int32_t cmd = -1; - std::string action; - bool ret = localAbility->FfrtStatCmdProc(fd, cmd); - EXPECT_FALSE(ret); -} - /** * @tc.name: IpcStatCmdProc001 * @tc.desc: test IpcStatCmdProc001 with fd valid and cmd valid diff --git a/services/samgr/native/test/unittest/src/mock_system_ability_manager_test.cpp b/services/samgr/native/test/unittest/src/mock_system_ability_manager_test.cpp deleted file mode 100644 index fc7eb388..00000000 --- a/services/samgr/native/test/unittest/src/mock_system_ability_manager_test.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "test_log.h" -#include "mock_system_ability_manager_test.h" -#include "ffrt_inner.h" - -#define private public -#include "system_ability_manager_dumper.h" - -using namespace std; -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -namespace ffrt { -#ifdef __cplusplus -extern "C" { -#endif //__cplusplus -int ffrt_dump(ffrt_dump_cmd_t cmd, char *buf, uint32_t len) -{ - return -1; -} -#ifdef __cplusplus -} -#endif -} -void MockSystemAbilityManagerTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; -} - -void MockSystemAbilityManagerTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void MockSystemAbilityManagerTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; -} - -void MockSystemAbilityManagerTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - -/** - * @tc.name: StartFfrtStatistics001 - * @tc.desc: StartFfrtStatistics - * @tc.type: FUNC - * @tc.require: IBSPUT - */ -HWTEST_F(MockSystemAbilityManagerTest, StartFfrtStatistics001, TestSize.Level3) -{ - DTEST_LOG << "StartFfrtStatistics001 begin" << std::endl; - std::string result; - EXPECT_FALSE(SystemAbilityManagerDumper::collectEnable); - auto ret = SystemAbilityManagerDumper::StartFfrtStatistics(result); - EXPECT_FALSE(ret); - DTEST_LOG << "StartFfrtStatistics001 end" << std::endl; -} - -/** - * @tc.name: StopFfrtStatistics001 - * @tc.desc: StopFfrtStatistics - * @tc.type: FUNC - * @tc.require: IBSPUT - */ -HWTEST_F(MockSystemAbilityManagerTest, StopFfrtStatistics001, TestSize.Level3) -{ - DTEST_LOG << "StopFfrtStatistics001 begin" << std::endl; - std::string result; - SystemAbilityManagerDumper::collectEnable = true; - auto ret = SystemAbilityManagerDumper::StopFfrtStatistics(result); - EXPECT_FALSE(ret); - DTEST_LOG << "StopFfrtStatistics001 end" << std::endl; -} - -/** - * @tc.name: ClearFfrtStatistics001 - * @tc.desc: ClearFfrtStatistics - * @tc.type: FUNC - * @tc.require: IBSPUT - */ -HWTEST_F(MockSystemAbilityManagerTest, ClearFfrtStatistics001, TestSize.Level3) -{ - DTEST_LOG << "ClearFfrtStatistics001 begin" << std::endl; - SystemAbilityManagerDumper::collectEnable = true; - SystemAbilityManagerDumper::ClearFfrtStatistics(); - EXPECT_FALSE(SystemAbilityManagerDumper::collectEnable); - DTEST_LOG << "ClearFfrtStatistics001 end" << std::endl; -} -} \ No newline at end of file diff --git a/services/samgr/native/test/unittest/src/system_ability_manager_dumper_test.cpp b/services/samgr/native/test/unittest/src/system_ability_manager_dumper_test.cpp index 856df813..812aa5aa 100644 --- a/services/samgr/native/test/unittest/src/system_ability_manager_dumper_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_manager_dumper_test.cpp @@ -17,7 +17,6 @@ #include "ability_death_recipient.h" #include "system_ability_status_change_proxy.h" #include "ipc_skeleton.h" -#include "ffrt_inner.h" #include "test_log.h" #include @@ -107,284 +106,6 @@ HWTEST_F(SystemAbilityManagerDumperTest, FfrtDumpProc001, TestSize.Level3) } #endif -/** - * @tc.name: FfrtDumpProc002 - * @tc.desc: FfrtDumpProc IllegalInput - * @tc.type: FUNC - * @tc.require: IBMM2R - */ -#ifdef SUPPORT_ACCESS_TOKEN -HWTEST_F(SystemAbilityManagerDumperTest, FfrtDumpProc002, TestSize.Level3) -{ - DTEST_LOG << "FfrtDumpProc002 begin" << std::endl; - SamMockPermission::MockProcess("hidumper_service"); - std::shared_ptr abilityStateScheduler = - std::make_shared(); - int32_t fd = -1; - std::vector args; - auto ret = SystemAbilityManagerDumper::FfrtDumpProc(abilityStateScheduler, fd, args); - EXPECT_EQ(ret, SAVE_FD_FAIL); - args.emplace_back("--ffrt"); - args.emplace_back("pid1"); - args.emplace_back("pid2"); - args.emplace_back("pid3"); - ret = SystemAbilityManagerDumper::FfrtDumpProc(abilityStateScheduler, fd, args); - EXPECT_EQ(ret, SAVE_FD_FAIL); - DTEST_LOG << "FfrtDumpProc002 end" << std::endl; -} -#endif - -/** - * @tc.name: FfrtDumpProc003 - * @tc.desc: FfrtDumpProc GetFfrtDumpInfoProc - * @tc.type: FUNC - * @tc.require: IBMM2R - */ -#ifdef SUPPORT_ACCESS_TOKEN -HWTEST_F(SystemAbilityManagerDumperTest, FfrtDumpProc003, TestSize.Level3) -{ - DTEST_LOG << "FfrtDumpProc003 begin" << std::endl; - SamMockPermission::MockProcess("hidumper_service"); - std::shared_ptr abilityStateScheduler = - std::make_shared(); - int32_t fd = -1; - std::vector args; - args.emplace_back("--ffrt"); - args.emplace_back("9999"); - auto ret = SystemAbilityManagerDumper::FfrtDumpProc(abilityStateScheduler, fd, args); - EXPECT_EQ(ret, SAVE_FD_FAIL); - DTEST_LOG << "FfrtDumpProc003 end" << std::endl; -} -#endif - -/** - * @tc.name: FfrtDumpProc004 - * @tc.desc: FfrtDumpProc GetFfrtLoadMetrics - * @tc.type: FUNC - * @tc.require: IBMM2R - */ -#ifdef SUPPORT_ACCESS_TOKEN -HWTEST_F(SystemAbilityManagerDumperTest, FfrtDumpProc004, TestSize.Level3) -{ - DTEST_LOG << "FfrtDumpProc004 begin" << std::endl; - SamMockPermission::MockProcess("hidumper_service"); - std::shared_ptr abilityStateScheduler = - std::make_shared(); - int32_t fd = -1; - std::vector args; - args.emplace_back("--ffrt"); - args.emplace_back("9999"); - args.emplace_back("--stat"); - auto ret = SystemAbilityManagerDumper::FfrtDumpProc(abilityStateScheduler, fd, args); - EXPECT_EQ(ret, SAVE_FD_FAIL); - DTEST_LOG << "FfrtDumpProc004 end" << std::endl; -} -#endif - -/** - * @tc.name: GetFfrtLoadMetrics001 - * @tc.desc: GetFfrtLoadMetrics processIds empty - * @tc.type: FUNC - * @tc.require: IBMM2R - */ -HWTEST_F(SystemAbilityManagerDumperTest, GetFfrtLoadMetrics001, TestSize.Level3) -{ - DTEST_LOG << "GetFfrtLoadMetrics001 begin" << std::endl; - std::shared_ptr abilityStateScheduler = - std::make_shared(); - int32_t fd = -1; - std::vector args; - args.emplace_back("--ffrt"); - args.emplace_back("test"); - std::string result; - SystemAbilityManagerDumper::GetFfrtLoadMetrics(abilityStateScheduler, fd, args, result); - EXPECT_NE(result.size(), 0); - DTEST_LOG << "GetFfrtLoadMetrics001 end" << std::endl; -} - -/** - * @tc.name: GetFfrtLoadMetrics002 - * @tc.desc: GetFfrtLoadMetrics cmd invalid - * @tc.type: FUNC - * @tc.require: IBMM2R - */ -HWTEST_F(SystemAbilityManagerDumperTest, GetFfrtLoadMetrics002, TestSize.Level3) -{ - DTEST_LOG << "GetFfrtLoadMetrics002 begin" << std::endl; - std::shared_ptr abilityStateScheduler = - std::make_shared(); - int32_t fd = -1; - std::vector args; - args.emplace_back("--ffrt"); - args.emplace_back("9999"); - args.emplace_back("xxx"); - std::string result; - SystemAbilityManagerDumper::GetFfrtLoadMetrics(abilityStateScheduler, fd, args, result); - EXPECT_NE(result.size(), 0); - DTEST_LOG << "GetFfrtLoadMetrics002 end" << std::endl; -} - -/** - * @tc.name: GetFfrtLoadMetrics003 - * @tc.desc: GetFfrtLoadMetrics cmd invalid - * @tc.type: FUNC - * @tc.require: IBMM2R - */ -HWTEST_F(SystemAbilityManagerDumperTest, GetFfrtLoadMetrics003, TestSize.Level3) -{ - DTEST_LOG << "GetFfrtLoadMetrics003 begin" << std::endl; - std::shared_ptr abilityStateScheduler = - std::make_shared(); - int32_t fd = -1; - std::vector args; - args.emplace_back("--ffrt"); - args.emplace_back("9999"); - args.emplace_back("--stat"); - std::string result; - SystemAbilityManagerDumper::GetFfrtLoadMetrics(abilityStateScheduler, fd, args, result); - EXPECT_NE(result.size(), 0); - DTEST_LOG << "GetFfrtLoadMetrics003 end" << std::endl; -} - -/** - * @tc.name: FfrtStatCmdParser001 - * @tc.desc: FfrtStatCmdParser - * @tc.type: FUNC - * @tc.require: IBMM2R - */ -HWTEST_F(SystemAbilityManagerDumperTest, FfrtStatCmdParser001, TestSize.Level3) -{ - DTEST_LOG << "FfrtStatCmdParser001 begin" << std::endl; - int32_t cmd = -1; - std::vector args; - args.emplace_back("--ffrt"); - args.emplace_back("9999"); - args.emplace_back("--start-stat"); - SystemAbilityManagerDumper::FfrtStatCmdParser(cmd, args); - EXPECT_NE(cmd, -1); - DTEST_LOG << "FfrtStatCmdParser001 end" << std::endl; -} - -/** - * @tc.name: FfrtStatCmdParser002 - * @tc.desc: FfrtStatCmdParser - * @tc.type: FUNC - * @tc.require: IBMM2R - */ -HWTEST_F(SystemAbilityManagerDumperTest, FfrtStatCmdParser002, TestSize.Level3) -{ - DTEST_LOG << "FfrtStatCmdParser002 begin" << std::endl; - int32_t cmd = -1; - std::vector args; - args.emplace_back("--ffrt"); - args.emplace_back("9999"); - args.emplace_back("--stop-stat"); - SystemAbilityManagerDumper::FfrtStatCmdParser(cmd, args); - EXPECT_NE(cmd, -1); - DTEST_LOG << "FfrtStatCmdParser002 end" << std::endl; -} - -/** - * @tc.name: FfrtStatCmdParser003 - * @tc.desc: FfrtStatCmdParser - * @tc.type: FUNC - * @tc.require: IBMM2R - */ -HWTEST_F(SystemAbilityManagerDumperTest, FfrtStatCmdParser003, TestSize.Level3) -{ - DTEST_LOG << "FfrtStatCmdParser003 begin" << std::endl; - int32_t cmd = -1; - std::vector args; - args.emplace_back("--ffrt"); - args.emplace_back("9999"); - args.emplace_back("--stat"); - SystemAbilityManagerDumper::FfrtStatCmdParser(cmd, args); - EXPECT_NE(cmd, -1); - DTEST_LOG << "FfrtStatCmdParser003 end" << std::endl; -} - -/** - * @tc.name: FfrtStatCmdParser004 - * @tc.desc: FfrtStatCmdParser cmd invalid - * @tc.type: FUNC - * @tc.require: IBMM2R - */ -HWTEST_F(SystemAbilityManagerDumperTest, FfrtStatCmdParser004, TestSize.Level3) -{ - DTEST_LOG << "FfrtStatCmdParser004 begin" << std::endl; - int32_t cmd = -1; - std::vector args; - args.emplace_back("--ffrt"); - args.emplace_back("9999"); - args.emplace_back("xxxx"); - SystemAbilityManagerDumper::FfrtStatCmdParser(cmd, args); - EXPECT_EQ(cmd, -1); - DTEST_LOG << "FfrtStatCmdParser004 end" << std::endl; -} - -/** - * @tc.name: CollectFfrtMetricInfoInProcs001 - * @tc.desc: CollectFfrtMetricInfoInProcs - * @tc.type: FUNC - * @tc.require: IBMM2R - */ -HWTEST_F(SystemAbilityManagerDumperTest, CollectFfrtMetricInfoInProcs001, TestSize.Level3) -{ - DTEST_LOG << "CollectFfrtMetricInfoInProcs001 begin" << std::endl; - std::shared_ptr abilityStateScheduler = - std::make_shared(); - int32_t fd = -1; - std::vector processIds; - processIds.emplace_back(getpid()); - int32_t cmd = -1; - std::string result; - SystemAbilityManagerDumper::CollectFfrtMetricInfoInProcs(fd, processIds, abilityStateScheduler, cmd, result); - EXPECT_NE(result.size(), 0); - DTEST_LOG << "CollectFfrtMetricInfoInProcs001 end" << std::endl; -} - -/** - * @tc.name: CollectFfrtStatistics001 - * @tc.desc: CollectFfrtStatistics - * @tc.type: FUNC - * @tc.require: IBMM2R - */ -HWTEST_F(SystemAbilityManagerDumperTest, CollectFfrtStatistics001, TestSize.Level3) -{ - DTEST_LOG << "CollectFfrtStatistics001 begin" << std::endl; - std::string result; - auto ret = SystemAbilityManagerDumper::CollectFfrtStatistics(FFRT_STAT_CMD_START, result); - SystemAbilityManagerDumper::ClearFfrtStatistics(); - EXPECT_TRUE(ret); - ret = SystemAbilityManagerDumper::CollectFfrtStatistics(FFRT_STAT_CMD_GET, result); - EXPECT_FALSE(ret); - ret = SystemAbilityManagerDumper::CollectFfrtStatistics(FFRT_STAT_CMD_STOP, result); - EXPECT_FALSE(ret); - ret = SystemAbilityManagerDumper::CollectFfrtStatistics(FFRT_STAT_CMD_START, result); - EXPECT_TRUE(ret); - ret = SystemAbilityManagerDumper::CollectFfrtStatistics(FFRT_STAT_CMD_START, result); - EXPECT_FALSE(ret); - ret = SystemAbilityManagerDumper::CollectFfrtStatistics(FFRT_STAT_CMD_GET, result); - EXPECT_FALSE(ret); - auto testTask1 = [] () { - DTEST_LOG << "testTask1 end" << std::endl; - }; - auto testTask2 = [] () { - DTEST_LOG << "testTask2 end" << std::endl; - }; - SystemAbilityManagerDumper::handler_->PostTask(testTask1, "testTask1", 0); - SystemAbilityManagerDumper::handler_->PostTask(testTask2, "testTask2", 0); - usleep(10 * 1000); - ret = SystemAbilityManagerDumper::CollectFfrtStatistics(FFRT_STAT_CMD_STOP, result); - EXPECT_TRUE(ret); - ffrt_stat* currentStat = (ffrt_stat*)SystemAbilityManagerDumper::ffrtMetricBuffer; - ASSERT_FALSE(currentStat == nullptr); - currentStat->endTime = 0; - ret = SystemAbilityManagerDumper::CollectFfrtStatistics(FFRT_STAT_CMD_GET, result); - EXPECT_TRUE(ret); - DTEST_LOG << "CollectFfrtStatistics001 end" << std::endl; -} - /** * @tc.name: GetSAMgrFfrtInfo001 * @tc.desc: GetSAMgrFfrtInfo @@ -1314,7 +1035,6 @@ HWTEST_F(SystemAbilityManagerDumperTest, GetFfrtDumpInfoProc001, TestSize.Level2 std::make_shared(); std::vector args; args.emplace_back("--ffrt"); - args.emplace_back(""); std::string result; bool ret = SystemAbilityManagerDumper::GetFfrtDumpInfoProc(systemAbilityStateScheduler, args, result); EXPECT_EQ(ret, false); @@ -1334,7 +1054,7 @@ HWTEST_F(SystemAbilityManagerDumperTest, GetFfrtDumpInfoProc002, TestSize.Level2 std::make_shared(); std::vector args; args.emplace_back("--ffrt"); - args.emplace_back("12k"); + args.emplace_back(""); std::string result; bool ret = SystemAbilityManagerDumper::GetFfrtDumpInfoProc(systemAbilityStateScheduler, args, result); EXPECT_EQ(ret, false); @@ -1350,6 +1070,26 @@ HWTEST_F(SystemAbilityManagerDumperTest, GetFfrtDumpInfoProc002, TestSize.Level2 HWTEST_F(SystemAbilityManagerDumperTest, GetFfrtDumpInfoProc003, TestSize.Level2) { DTEST_LOG << "GetFfrtDumpInfoProc003 begin" << std::endl; + std::shared_ptr systemAbilityStateScheduler = + std::make_shared(); + std::vector args; + args.emplace_back("--ffrt"); + args.emplace_back("12k"); + std::string result; + bool ret = SystemAbilityManagerDumper::GetFfrtDumpInfoProc(systemAbilityStateScheduler, args, result); + EXPECT_EQ(ret, false); + DTEST_LOG << "GetFfrtDumpInfoProc003 end" << std::endl; +} + +/** + * @tc.name: GetFfrtDumpInfoProc004 + * @tc.desc: test GetFfrtDumpInfoProc + * @tc.type: FUNC + * @tc.require: I6W28 + */ +HWTEST_F(SystemAbilityManagerDumperTest, GetFfrtDumpInfoProc004, TestSize.Level2) +{ + DTEST_LOG << "GetFfrtDumpInfoProc004 begin" << std::endl; std::shared_ptr systemAbilityStateScheduler = std::make_shared(); sptr saMgr = new SystemAbilityManager; @@ -1362,17 +1102,17 @@ HWTEST_F(SystemAbilityManagerDumperTest, GetFfrtDumpInfoProc003, TestSize.Level2 std::string result; bool ret = SystemAbilityManagerDumper::GetFfrtDumpInfoProc(systemAbilityStateScheduler, args, result); EXPECT_EQ(ret, true); - DTEST_LOG << "GetFfrtDumpInfoProc003 end" << std::endl; + DTEST_LOG << "GetFfrtDumpInfoProc004 end" << std::endl; } /** - * @tc.name: GetFfrtDumpInfoProc004 + * @tc.name: GetFfrtDumpInfoProc005 * @tc.desc: test GetFfrtDumpInfoProc * @tc.type: FUNC */ -HWTEST_F(SystemAbilityManagerDumperTest, GetFfrtDumpInfoProc004, TestSize.Level1) +HWTEST_F(SystemAbilityManagerDumperTest, GetFfrtDumpInfoProc005, TestSize.Level1) { - DTEST_LOG << "GetFfrtDumpInfoProc004 begin" << std::endl; + DTEST_LOG << "GetFfrtDumpInfoProc005 begin" << std::endl; std::shared_ptr systemAbilityStateScheduler = std::make_shared(); sptr saMgr = new SystemAbilityManager; @@ -1391,7 +1131,7 @@ HWTEST_F(SystemAbilityManagerDumperTest, GetFfrtDumpInfoProc004, TestSize.Level1 std::string result; bool ret = SystemAbilityManagerDumper::GetFfrtDumpInfoProc(systemAbilityStateScheduler, args, result); EXPECT_EQ(ret, true); - DTEST_LOG << "GetFfrtDumpInfoProc004 end" << std::endl; + DTEST_LOG << "GetFfrtDumpInfoProc005 end" << std::endl; } /** diff --git a/services/samgr/native/test/unittest/src/system_ability_manager_mock.cpp b/services/samgr/native/test/unittest/src/system_ability_manager_mock.cpp deleted file mode 100644 index f1f740f1..00000000 --- a/services/samgr/native/test/unittest/src/system_ability_manager_mock.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "system_ability_manager_mock.h" - -namespace OHOS { -std::vector ISystemAbilityManagerMock::ListSystemAbilities(unsigned int dumpFlags) -{ - std::vector vecSystemAbility; - return vecSystemAbility; -} - -sptr ISystemAbilityManagerMock::GetSystemAbility(int32_t systemAbilityId) -{ - return nullptr; -} - -sptr ISystemAbilityManagerMock::CheckSystemAbility(int32_t systemAbilityId) -{ - return nullptr; -} - -int32_t ISystemAbilityManagerMock::RemoveSystemAbility(int32_t systemAbilityId) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::SubscribeSystemAbility(int32_t systemAbilityId, - const sptr& listener) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::UnSubscribeSystemAbility(int32_t systemAbilityId, - const sptr& listener) -{ - return 0; -} - -sptr ISystemAbilityManagerMock::GetSystemAbility(int32_t systemAbilityId, - const std::string& deviceId) -{ - return nullptr; -} - -sptr ISystemAbilityManagerMock::CheckSystemAbility(int32_t systemAbilityId, - const std::string& deviceId) -{ - return nullptr; -} - -int32_t ISystemAbilityManagerMock::AddOnDemandSystemAbilityInfo(int32_t systemAbilityId, - const std::u16string& localAbilityManagerName) -{ - return 0; -} - -sptr ISystemAbilityManagerMock::CheckSystemAbility(int32_t systemAbilityId, bool& isExist) -{ - return nullptr; -} - -int32_t ISystemAbilityManagerMock::AddSystemAbility(int32_t systemAbilityId, const sptr& ability, - const SAExtraProp& extraProp) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::AddSystemProcess(const std::u16string& procName, - const sptr& procObject) -{ - return 0; -} - - -sptr ISystemAbilityManagerMock::LoadSystemAbility(int32_t systemAbilityId, int32_t timeout) -{ - return nullptr; -} - - -int32_t ISystemAbilityManagerMock::LoadSystemAbility(int32_t systemAbilityId, - const sptr& callback) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::LoadSystemAbility(int32_t systemAbilityId, const std::string& deviceId, - const sptr& callback) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::UnloadSystemAbility(int32_t systemAbilityId) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::CancelUnloadSystemAbility(int32_t systemAbilityId) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::UnloadAllIdleSystemAbility() -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::GetSystemProcessInfo(int32_t systemAbilityId, SystemProcessInfo& systemProcessInfo) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::GetRunningSystemProcess(std::list& systemProcessInfos) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::SubscribeSystemProcess(const sptr& listener) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::SendStrategy(int32_t type, std::vector& systemAbilityIds, - int32_t level, std::string& action) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::UnSubscribeSystemProcess(const sptr& listener) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::GetExtensionSaIds(const std::string& extension, std::vector &saIds) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::GetExtensionRunningSaList(const std::string& extension, - std::vector>& saList) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::GetRunningSaExtensionInfoList(const std::string& extension, - std::vector& infoList) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::GetCommonEventExtraDataIdlist(int32_t saId, std::vector& extraDataIdList, - const std::string& eventName) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::GetOnDemandReasonExtraData(int64_t extraDataId, MessageParcel& extraDataParcel) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::GetOnDemandPolicy(int32_t systemAbilityId, OnDemandPolicyType type, - std::vector& abilityOnDemandEvents) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::UpdateOnDemandPolicy(int32_t systemAbilityId, OnDemandPolicyType type, - const std::vector& abilityOnDemandEvents) -{ - return 0; -} - -int32_t ISystemAbilityManagerMock::GetOnDemandSystemAbilityIds(std::vector& systemAbilityIds) -{ - return 0; -} - -sptr ISystemAbilityManagerMock::AsObject() -{ - return nullptr; -} - -} diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_load_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_load_test.cpp index 1cd777e8..722e14e6 100644 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_load_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_load_test.cpp @@ -102,6 +102,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility001, TestSize.Level0) DTEST_LOG << "LoadSystemAbility001 begin" << std::endl; int32_t systemAbilityId = TEST_EXCEPTION_LOW_SA_ID; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t result = saMgr->LoadSystemAbility(systemAbilityId, nullptr); EXPECT_TRUE(result != ERR_OK); @@ -118,6 +119,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility002, TestSize.Level0) DTEST_LOG << "LoadSystemAbility002 begin" << std::endl; int32_t systemAbilityId = TEST_EXCEPTION_HIGH_SA_ID; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t result = saMgr->LoadSystemAbility(systemAbilityId, nullptr); EXPECT_TRUE(result != ERR_OK); @@ -134,6 +136,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility003, TestSize.Level0) DTEST_LOG << "LoadSystemAbility003 begin" << std::endl; int32_t systemAbilityId = DISTRIBUTED_SCHED_TEST_SO_ID; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t result = saMgr->LoadSystemAbility(systemAbilityId, nullptr); EXPECT_TRUE(result != ERR_OK); @@ -150,6 +153,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility004, TestSize.Level0) DTEST_LOG << "LoadSystemAbility004 begin" << std::endl; int32_t systemAbilityId = DISTRIBUTED_SCHED_TEST_SO_ID; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); sptr callback = new SystemAbilityLoadCallbackMock(); int32_t result = saMgr->LoadSystemAbility(systemAbilityId, callback); @@ -166,6 +170,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility005, TestSize.Level1) { DTEST_LOG << "LoadSystemAbility005 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); MessageParcel data; MessageParcel reply; MessageOption option; @@ -184,6 +189,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility006, TestSize.Level1) { DTEST_LOG << "LoadSystemAbility006 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); MessageParcel data; data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN); MessageParcel reply; @@ -203,6 +209,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility007, TestSize.Level1) { DTEST_LOG << "LoadSystemAbility007 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); MessageParcel data; data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN); data.WriteInt32(TEST_EXCEPTION_HIGH_SA_ID); @@ -223,6 +230,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility008, TestSize.Level1) { DTEST_LOG << "LoadSystemAbility008 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); MessageParcel data; data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN); data.WriteInt32(DISTRIBUTED_SCHED_TEST_SO_ID); @@ -243,6 +251,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility009, TestSize.Level1) { DTEST_LOG << "LoadSystemAbility009 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); MessageParcel data; data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN); data.WriteInt32(DISTRIBUTED_SCHED_TEST_SO_ID); @@ -267,6 +276,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility010, TestSize.Level3) DTEST_LOG << "LoadSystemAbility010 begin" << std::endl; sptr saMgr = new SystemAbilityManager; InitSaMgr(saMgr); + saMgr->saProfileMap_.clear(); sptr callback = new SystemAbilityLoadCallbackMock(); int32_t ret = saMgr->LoadSystemAbility(SAID, callback); EXPECT_EQ(ret, PROFILE_NOT_EXIST); @@ -299,6 +309,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, OnLoadSystemAbilitySuccess001, TestSize.Level { DTEST_LOG << "OnLoadSystemAbilitySuccess001 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); sptr callback = new SystemAbilityLoadCallbackMock(); saMgr->NotifySystemAbilityLoaded(DISTRIBUTED_SCHED_TEST_SO_ID, nullptr, nullptr); @@ -315,7 +326,8 @@ HWTEST_F(SystemAbilityMgrLoadTest, OnLoadSystemAbilitySuccess002, TestSize.Level { DTEST_LOG << "OnLoadSystemAbilitySuccess002 begin" << std::endl; sptr saMgr = new SystemAbilityManager; - saMgr->Init(); + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); sptr callback = new SystemAbilityLoadCallbackMock(); saMgr->NotifySystemAbilityLoaded(DISTRIBUTED_SCHED_TEST_SO_ID, nullptr, callback); EXPECT_TRUE(callback->GetSystemAbilityId() == DISTRIBUTED_SCHED_TEST_SO_ID); @@ -332,6 +344,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, OnLoadSystemAbilitySuccess003, TestSize.Level { DTEST_LOG << "OnLoadSystemAbilitySuccess003 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); sptr callback = new SystemAbilityLoadCallbackMock(); sptr remoteObject = new TestTransactionService(); @@ -350,6 +363,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, OnLoadSystemAbilitySuccess004, TestSize.Level { DTEST_LOG << " OnLoadSystemAbilitySuccess004 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); sptr callback = new SystemAbilityLoadCallbackMock(); saMgr->NotifySystemAbilityLoaded(DISTRIBUTED_SCHED_TEST_SO_ID, nullptr, nullptr); @@ -366,6 +380,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, ReportLoadSAOverflow001, TestSize.Level1) { DTEST_LOG << "ReportLoadSAOverflow001 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + ASSERT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); for (int i = 0; i < OVERFLOW_TIME; ++i) { sptr callback = new SystemAbilityLoadCallbackMock(); @@ -385,6 +400,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadRemoteSystemAbility001, TestSize.Level2) DTEST_LOG << "LoadRemoteSystemAbility001 begin" << std::endl; sptr saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); EXPECT_TRUE(saMgr != nullptr); + EXPECT_TRUE(saMgr != nullptr); int32_t systemAbilityId = TEST_EXCEPTION_LOW_SA_ID; std::string deviceId = ""; int32_t result = saMgr->LoadSystemAbility(systemAbilityId, deviceId, nullptr); @@ -704,6 +720,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, UnloadSystemAbility002, TestSize.Level3) { DTEST_LOG << "UnloadSystemAbility002 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t systemAbilityId = 1; CommonSaProfile saProfile; @@ -726,6 +743,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, UnloadSystemAbility003, TestSize.Level3) DTEST_LOG << " UnloadSystemAbility003 begin" << std::endl; SamMockPermission::MockProcess("memmgrservice"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); CommonSaProfile saProfile; saProfile.process = u"memmgrservice"; @@ -747,6 +765,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, CancelUnloadSystemAbility001, TestSize.Level3 { DTEST_LOG << " CancelUnloadSystemAbility001 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t systemAbilityId = -1; int32_t ret = saMgr->CancelUnloadSystemAbility(systemAbilityId); @@ -764,6 +783,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, CancelUnloadSystemAbility002, TestSize.Level3 { DTEST_LOG << " CancelUnloadSystemAbility002 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t systemAbilityId = 1; int32_t ret = saMgr->CancelUnloadSystemAbility(systemAbilityId); @@ -781,6 +801,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, CancelUnloadSystemAbility003, TestSize.Level3 { DTEST_LOG << " CancelUnloadSystemAbility003 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); CommonSaProfile saProfile; saMgr->saProfileMap_[1] = saProfile; @@ -801,6 +822,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, CancelUnloadSystemAbility004, TestSize.Level3 DTEST_LOG << " CancelUnloadSystemAbility004 begin" << std::endl; SamMockPermission::MockProcess("mockProcess"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); CommonSaProfile saProfile; saProfile.process = u"mockProcess"; @@ -822,6 +844,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, CancelUnloadSystemAbility005, TestSize.Level3 DTEST_LOG << " CancelUnloadSystemAbility005 begin" << std::endl; SamMockPermission::MockProcess("mockProcess"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); CommonSaProfile saProfile; saProfile.process = u"mockProcess"; @@ -844,6 +867,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, CancelUnloadSystemAbility006, TestSize.Level3 { DTEST_LOG << " CancelUnloadSystemAbility006 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); uint32_t accessToken = IPCSkeleton::GetCallingTokenID(); Security::AccessToken::NativeTokenInfo nativeTokenInfo; @@ -870,6 +894,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, DoUnloadSystemAbility001, TestSize.Level3) { DTEST_LOG << "DoUnloadSystemAbility001 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); std::u16string procName = u"foundation"; int32_t said = 401; @@ -899,6 +924,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, DoUnloadSystemAbility002, TestSize.Level3) { DTEST_LOG << "DoUnloadSystemAbility002 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); ISystemAbilityManager::SAExtraProp saExtraProp(false, 0, u"", u""); int32_t systemAbilityId = DISTRIBUTED_SCHED_TEST_TT_ID; @@ -925,6 +951,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, UnloadAllIdleSystemAbility001, TestSize.Level DTEST_LOG << "UnloadAllIdleSystemAbility001 begin" << std::endl; SamMockPermission::MockProcess("memmgrservice"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t ret = saMgr->UnloadAllIdleSystemAbility(); EXPECT_EQ(ret, ERR_OK); @@ -942,6 +969,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, UnloadAllIdleSystemAbility002, TestSize.Level DTEST_LOG << "UnloadAllIdleSystemAbility002 begin" << std::endl; SamMockPermission::MockProcess("memmgrservice"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); saMgr->abilityStateScheduler_ = nullptr; int32_t ret = saMgr->UnloadAllIdleSystemAbility(); @@ -960,6 +988,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, UnloadAllIdleSystemAbility003, TestSize.Level { DTEST_LOG << "UnloadAllIdleSystemAbility003 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t ret = saMgr->UnloadAllIdleSystemAbility(); EXPECT_EQ(ret, ERR_PERMISSION_DENIED); diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_new_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_new_test.cpp index 9fcf2cba..87454cc0 100644 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_new_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_new_test.cpp @@ -187,6 +187,9 @@ void SystemAbilityMgrNewTest::TearDown() HWTEST_F(SystemAbilityMgrNewTest, GetLocalNodeId001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); + string ret = saMgr->GetLocalNodeId(); EXPECT_EQ(ret, ""); } @@ -200,6 +203,9 @@ HWTEST_F(SystemAbilityMgrNewTest, GetLocalNodeId001, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, ReportGetSAPeriodically001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); + uint64_t pid_said = 123; int32_t count = 1; saMgr->saFrequencyMap_[pid_said] = count; @@ -216,7 +222,9 @@ HWTEST_F(SystemAbilityMgrNewTest, StartDynamicSystemProcess001, TestSize.Level3) { cout << "begin StartDynamicSystemProcess001 "<< endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); + std::u16string invalidProcess = u"1234567890123456789012345678901234567890123456789" "01234567890123456789012345678901234567890123456"; OnDemandEvent event; @@ -233,7 +241,9 @@ HWTEST_F(SystemAbilityMgrNewTest, StartDynamicSystemProcess001, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityWithDevice001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); + std::string deviceId = ""; auto ability = saMgr->GetSystemAbility(TEST_EXCEPTION_LOW_SA_ID, deviceId); EXPECT_EQ(ability, nullptr); @@ -256,7 +266,8 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityWithDevice001, TestSize.Level3 HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + EXPECT_TRUE(saMgr != nullptr); + saMgr->Init(); auto ability = saMgr->GetSystemAbilityFromRemote(TEST_EXCEPTION_LOW_SA_ID); EXPECT_EQ(ability, nullptr); } @@ -269,7 +280,9 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote001, TestSize.Level3 HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote002, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); + auto ability = saMgr->GetSystemAbilityFromRemote(TEST_SYSTEM_ABILITY1); EXPECT_EQ(ability, nullptr); } @@ -282,6 +295,8 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote002, TestSize.Level3 HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote003, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); SAInfo saInfo; saMgr->abilityMap_[1] = saInfo; @@ -298,6 +313,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote003, TestSize.Level3 HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote004, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); SAInfo saInfo; saInfo.isDistributed = true; @@ -317,6 +333,8 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote004, TestSize.Level3 HWTEST_F(SystemAbilityMgrNewTest, GetDBinder001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); sptr result = saMgr->GetDBinder(); EXPECT_TRUE(result == nullptr); } @@ -331,6 +349,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetDBinder001, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, NotifyRpcLoadCompleted001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); #ifdef SAMGR_ENABLE_DELAY_DBINDER saMgr->InitDbinderService(); @@ -338,6 +357,7 @@ HWTEST_F(SystemAbilityMgrNewTest, NotifyRpcLoadCompleted001, TestSize.Level3) sptr testAbility = new TestTransactionService(); saMgr->workHandler_ = nullptr; saMgr->NotifyRpcLoadCompleted("", 1, testAbility); + EXPECT_TRUE(saMgr != nullptr); } /** @@ -350,6 +370,7 @@ HWTEST_F(SystemAbilityMgrNewTest, NotifyRpcLoadCompleted001, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, NotifyRpcLoadCompleted002, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); sptr testAbility = new TestTransactionService(); saMgr->NotifyRpcLoadCompleted("", 1, testAbility); @@ -364,12 +385,14 @@ HWTEST_F(SystemAbilityMgrNewTest, NotifyRpcLoadCompleted002, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, NotifyRpcLoadCompleted003, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); #ifdef SAMGR_ENABLE_DELAY_DBINDER saMgr->InitDbinderService(); #endif sptr testAbility = new TestTransactionService(); saMgr->NotifyRpcLoadCompleted("", 1, testAbility); + EXPECT_TRUE(saMgr != nullptr); } /** @@ -383,7 +406,8 @@ HWTEST_F(SystemAbilityMgrNewTest, Dump001, TestSize.Level3) { SamMockPermission::MockProcess("hidumper_service"); sptr saMgr = new SystemAbilityManager; - saMgr->abilityStateScheduler_ = std::make_shared(); + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); vector args; args.push_back(u"test_name"); int32_t result = saMgr->Dump(1, args); @@ -401,7 +425,8 @@ HWTEST_F(SystemAbilityMgrNewTest, Dump002, TestSize.Level3) { SamMockPermission::MockProcess("hidumper_service"); sptr saMgr = new SystemAbilityManager; - saMgr->abilityStateScheduler_ = std::make_shared(); + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); vector args; vector argsWithStr8; args.push_back(u"test_name"); @@ -421,7 +446,8 @@ HWTEST_F(SystemAbilityMgrNewTest, Dump003, TestSize.Level3) { SamMockPermission::MockProcess("hidumper_service"); sptr saMgr = new SystemAbilityManager; - saMgr->abilityStateScheduler_ = std::make_shared(); + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); vector args; args.push_back(u"--ipc"); args.push_back(u"all"); @@ -440,7 +466,8 @@ HWTEST_F(SystemAbilityMgrNewTest, Dump004, TestSize.Level3) { SamMockPermission::MockProcess("hidumper_service"); sptr saMgr = new SystemAbilityManager; - saMgr->abilityStateScheduler_ = std::make_shared(); + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); vector args; args.push_back(u"--ffrt"); args.push_back(u"99999"); @@ -458,6 +485,8 @@ HWTEST_F(SystemAbilityMgrNewTest, Dump004, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, AddSamgrToAbilityMap001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); saMgr->AddSamgrToAbilityMap(); vector args; args.push_back(u"test_name"); @@ -474,6 +503,7 @@ HWTEST_F(SystemAbilityMgrNewTest, AddSamgrToAbilityMap001, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, GetCommonEventExtraIdList001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); sptr commonEventCollect = new CommonEventCollect(saMgr->collectManager_); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -521,13 +551,14 @@ HWTEST_F(SystemAbilityMgrNewTest, GetCommonEventExtraIdList001, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, RemoveWhiteCommonEvent001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); saMgr->workHandler_ = make_shared("workHandler"); saMgr->CleanFfrt(); saMgr->collectManager_ = sptr(new DeviceStatusCollectManager()); saMgr->CleanFfrt(); saMgr->abilityStateScheduler_ = std::make_shared(); saMgr->CleanFfrt(); - InitSaMgr(saMgr); const std::u16string name; saMgr->NotifyRemoteSaDied(name); saMgr->RemoveWhiteCommonEvent(); @@ -543,6 +574,7 @@ HWTEST_F(SystemAbilityMgrNewTest, RemoveWhiteCommonEvent001, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, SetFfrt001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); saMgr->SetFfrt(); EXPECT_NE(saMgr->collectManager_, nullptr); @@ -558,6 +590,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetRunningSaExtensionInfoList001, TestSize.Lev { DTEST_LOG << __func__ << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); const int32_t maxLoop = 4; map saProfileMapTmp; @@ -587,6 +620,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetRunningSaExtensionInfoList002, TestSize.Lev { DTEST_LOG << __func__ << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); const int32_t maxLoop = 4; map saProfileMapTmp; @@ -627,6 +661,8 @@ HWTEST_F(SystemAbilityMgrNewTest, GetRunningSaExtensionInfoList002, TestSize.Lev HWTEST_F(SystemAbilityMgrNewTest, CheckSystemAbility006, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t systemAbilityId = -1; bool isExist; sptr ret = saMgr->CheckSystemAbility(systemAbilityId, isExist); @@ -642,6 +678,7 @@ HWTEST_F(SystemAbilityMgrNewTest, CheckSystemAbility006, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, RemoveSystemAbility005, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); const sptr ability = nullptr; int32_t ret = saMgr->RemoveSystemAbility(ability); @@ -656,6 +693,7 @@ HWTEST_F(SystemAbilityMgrNewTest, RemoveSystemAbility005, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, AddSystemAbility006, TestSize.Level1) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t systemAbilityId = -1; const sptr ability; @@ -672,6 +710,7 @@ HWTEST_F(SystemAbilityMgrNewTest, AddSystemAbility006, TestSize.Level1) HWTEST_F(SystemAbilityMgrNewTest, AddSystemAbility007, TestSize.Level1) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t systemAbilityId = -1; const sptr ability; @@ -689,6 +728,8 @@ HWTEST_F(SystemAbilityMgrNewTest, AddSystemAbility007, TestSize.Level1) HWTEST_F(SystemAbilityMgrNewTest, GetSystemProcess001, TestSize.Level1) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); std::u16string procName; sptr ret = saMgr->GetSystemProcess(procName); EXPECT_EQ(ret, nullptr); @@ -702,6 +743,8 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemProcess001, TestSize.Level1) HWTEST_F(SystemAbilityMgrNewTest, GetSystemProcessInfo003, TestSize.Level1) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + saMgr->abilityStateScheduler_ = nullptr; int32_t systemAbilityId = 0; SystemProcessInfo systemProcessInfo; int32_t ret = saMgr->GetSystemProcessInfo(systemAbilityId, systemProcessInfo); @@ -716,6 +759,9 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemProcessInfo003, TestSize.Level1) HWTEST_F(SystemAbilityMgrNewTest, IsModuleUpdate001, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); + saMgr->saProfileMap_.clear(); bool ret = saMgr->IsModuleUpdate(SAID); EXPECT_FALSE(ret); } @@ -728,6 +774,9 @@ HWTEST_F(SystemAbilityMgrNewTest, IsModuleUpdate001, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IsModuleUpdate002, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); + saMgr->saProfileMap_.clear(); CommonSaProfile saprofile; saMgr->saProfileMap_[saprofile.saId] = saprofile; bool ret = saMgr->IsModuleUpdate(saprofile.saId); @@ -742,6 +791,9 @@ HWTEST_F(SystemAbilityMgrNewTest, IsModuleUpdate002, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IsModuleUpdate003, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); + saMgr->saProfileMap_.clear(); CommonSaProfile saprofile; saprofile.moduleUpdate = true; saMgr->saProfileMap_[saprofile.saId] = saprofile; @@ -758,6 +810,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetExtensionSaIdsInner001, TestSize.Level3) { DTEST_LOG << __func__ << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); MessageParcel data; MessageParcel reply; @@ -774,6 +827,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetExtensionSaIdsInner002, TestSize.Level3) { DTEST_LOG << __func__ << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); MessageParcel data; MessageParcel reply; @@ -798,6 +852,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetExtensionSaIdsInner003, TestSize.Level3) { DTEST_LOG << __func__ << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); const int32_t maxLoop = 4; map saProfileMapTmp; @@ -830,6 +885,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetExtensionRunningSaListInner001, TestSize.Le { DTEST_LOG << __func__ << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); MessageParcel data; MessageParcel reply; @@ -846,6 +902,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetExtensionRunningSaListInner002, TestSize.Le { DTEST_LOG << __func__ << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); MessageParcel data; MessageParcel reply; @@ -870,6 +927,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetExtensionRunningSaListInner003, TestSize.Le { DTEST_LOG << __func__ << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); const int32_t maxLoop = 4; map saProfileMapTmp; @@ -905,6 +963,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcDumpProc001, TestSize.Level2) { SamMockPermission::MockProcess("hidumper_service"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = -1; int32_t fd = 1; std::vector args; @@ -923,6 +983,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcDumpProc002, TestSize.Level2) { SamMockPermission::MockProcess("hidumper_service"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = -1; int32_t fd = 1; std::vector args; @@ -942,6 +1004,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcDumpProc003, TestSize.Level2) { SamMockPermission::MockProcess("hidumper_service"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = -1; int32_t fd = 1; std::vector args; @@ -961,6 +1025,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcDumpProc004, TestSize.Level2) { SamMockPermission::MockProcess("hidumper_service"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = -1; int32_t fd = 1; std::vector args; @@ -979,6 +1045,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcDumpProc004, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IpcStatSamgrProc001, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = IPC_STAT_CMD_START - 1; int32_t fd = 1; bool ret = saMgr->IpcStatSamgrProc(fd, cmd); @@ -996,6 +1064,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcStatSamgrProc001, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IpcStatSamgrProc002, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = IPC_STAT_CMD_START; int32_t dmd = IPC_STAT_CMD_STOP; int32_t emd = IPC_STAT_CMD_GET; @@ -1018,6 +1088,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcStatSamgrProc002, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IpcDumpAllProcess001, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = IPC_STAT_CMD_START; int32_t fd = 1; bool ret = true; @@ -1033,6 +1105,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcDumpAllProcess001, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IpcDumpSamgrProcess001, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = 4; int32_t fd = 1; bool ret = true; @@ -1049,6 +1123,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcDumpSamgrProcess001, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IpcDumpSingleProcess001, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = IPC_STAT_CMD_START; int32_t fd = 1; bool ret = true; @@ -1070,7 +1146,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcDumpSingleProcess001, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, DoLoadForPerf001, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; - saMgr->abilityStateScheduler_ = std::make_shared(); + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); CommonSaProfile saProfile; saProfile.process = u"memmgrservice"; saMgr->saProfileMap_[-1] = saProfile; @@ -1087,6 +1164,8 @@ HWTEST_F(SystemAbilityMgrNewTest, DoLoadForPerf001, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IsDistributedSystemAbility001, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); bool res = saMgr->IsDistributedSystemAbility(-1); EXPECT_FALSE(res); CommonSaProfile saProfile; @@ -1109,7 +1188,7 @@ HWTEST_F(SystemAbilityMgrNewTest, RegisterDistribute001, TestSize.Level2) DTEST_LOG<<"RegisterDistribute001 BEGIN"< saMgr = new SystemAbilityManager(); EXPECT_FALSE(saMgr == nullptr); - saMgr->Init(); + InitSaMgr(saMgr); saMgr->isDbinderServiceInit_ = false; saMgr->distributedSaList_.push_back(softBusServerSaID); saMgr->InitDbinderService(); diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_proxy_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_proxy_test.cpp index edd34499..46b7e501 100644 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_proxy_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_proxy_test.cpp @@ -20,7 +20,6 @@ #include "mock_iro_sendrequest.h" #include "sam_mock_permission.h" #include "sa_status_change_mock.h" -#include "system_ability_manager_mock.h" #include "system_ability_load_callback_proxy.h" #include "system_ability_status_change_proxy.h" #include "system_ability_load_callback_stub.h" diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp index 69743254..1b8fc244 100644 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp @@ -38,7 +38,6 @@ #include "system_ability_manager.h" #ifdef SUPPORT_COMMON_EVENT #include "common_event_collect.h" -#include "ability_death_recipient.h" #endif using namespace std; @@ -48,14 +47,6 @@ using namespace OHOS; namespace OHOS { namespace { -enum { - SHEEFT_CRITICAL = 0, - SHEEFT_HIGH, - SHEEFT_NORMAL, - SHEEFT_DEFAULT, - SHEEFT_PROTO, -}; - constexpr int32_t SAID = 1234; constexpr int32_t TEST_VALUE = 2021; constexpr int32_t TEST_REVERSE_VALUE = 1202; @@ -66,28 +57,9 @@ constexpr int32_t TEST_SYSTEM_ABILITY1 = 1491; constexpr int32_t TEST_SYSTEM_ABILITY2 = 1492; constexpr int32_t SHFIT_BIT = 32; constexpr int32_t MAX_COUNT = INT32_MAX - 1000000; -const unsigned int DUMP_FLAG_PRIORITY_CRITICAL = 1 << SHEEFT_CRITICAL; -const unsigned int DUMP_FLAG_PRIORITY_HIGH = 1 << SHEEFT_HIGH; -const unsigned int DUMP_FLAG_PRIORITY_NORMAL = 1 << SHEEFT_NORMAL; -const unsigned int DUMP_FLAG_PRIORITY_DEFAULT = 1 << SHEEFT_DEFAULT; -const unsigned int DUMP_FLAG_PRIORITY_ALL = DUMP_FLAG_PRIORITY_CRITICAL | - DUMP_FLAG_PRIORITY_HIGH | DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PRIORITY_DEFAULT; -const unsigned int DUMP_FLAG_PROTO = 1 << SHEEFT_PROTO; const std::u16string PROCESS_NAME = u"test_process_name"; const std::u16string DEVICE_NAME = u"test_name"; - -void InitSaMgr(sptr& saMgr) -{ - saMgr->abilityDeath_ = sptr(new AbilityDeathRecipient()); - saMgr->systemProcessDeath_ = sptr(new SystemProcessDeathRecipient()); - saMgr->abilityStatusDeath_ = sptr(new AbilityStatusDeathRecipient()); - saMgr->abilityCallbackDeath_ = sptr(new AbilityCallbackDeathRecipient()); - saMgr->remoteCallbackDeath_ = sptr(new RemoteCallbackDeathRecipient()); - saMgr->workHandler_ = make_shared("workHandler"); - saMgr->collectManager_ = sptr(new DeviceStatusCollectManager()); - saMgr->abilityStateScheduler_ = std::make_shared(); -} } void SystemProcessStatusChange::OnSystemProcessStarted(SystemProcessInfo& systemProcessInfo) @@ -130,10 +102,9 @@ void SystemAbilityMgrTest::TearDown() */ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility001, TestSize.Level1) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); - ISystemAbilityManager::SAExtraProp extraProp(false, DUMP_FLAG_PRIORITY_DEFAULT, u"", u""); - int32_t result = saMgr->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, nullptr, extraProp); + sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_TRUE(sm != nullptr); + int32_t result = sm->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, nullptr); DTEST_LOG << "add TestTransactionService result = " << result << std::endl; EXPECT_TRUE(result != ERR_OK); } @@ -145,13 +116,13 @@ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility001, TestSize.Level1) */ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility002, TestSize.Level1) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_TRUE(sm != nullptr); sptr testAbility = new TestTransactionService(); - ISystemAbilityManager::SAExtraProp extraProp(false, DUMP_FLAG_PRIORITY_DEFAULT, u"", u""); - int32_t result = saMgr->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, testAbility, extraProp); + int32_t result = sm->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, testAbility); DTEST_LOG << "add TestTransactionService result = " << result << std::endl; EXPECT_EQ(result, ERR_OK); + sm->RemoveSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID); } /** @@ -161,14 +132,15 @@ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility002, TestSize.Level1) */ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility003, TestSize.Level1) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_TRUE(sm != nullptr); sptr testAbility = new TestTransactionService(); - ISystemAbilityManager::SAExtraProp extraProp(false, DUMP_FLAG_PRIORITY_DEFAULT, u"", u""); - int32_t result = saMgr->AddSystemAbility(TEST_EXCEPTION_HIGH_SA_ID, testAbility, extraProp); + int32_t result = sm->AddSystemAbility(TEST_EXCEPTION_HIGH_SA_ID, testAbility); EXPECT_TRUE(result != ERR_OK); - result = saMgr->AddSystemAbility(TEST_EXCEPTION_LOW_SA_ID, testAbility, extraProp); + result = sm->AddSystemAbility(TEST_EXCEPTION_LOW_SA_ID, testAbility); EXPECT_TRUE(result != ERR_OK); + sm->RemoveSystemAbility(TEST_EXCEPTION_HIGH_SA_ID); + sm->RemoveSystemAbility(TEST_EXCEPTION_LOW_SA_ID); } /** @@ -178,13 +150,14 @@ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility003, TestSize.Level1) */ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility004, TestSize.Level1) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); int32_t systemAbilityId = DISTRIBUTED_SCHED_TEST_TT_ID; + sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_TRUE(sm != nullptr); ISystemAbilityManager::SAExtraProp saExtraProp(false, ISystemAbilityManager::DUMP_FLAG_PRIORITY_DEFAULT, u"", u""); - int32_t ret = saMgr->AddSystemAbility(systemAbilityId, new TestTransactionService(), saExtraProp); + int32_t ret = sm->AddSystemAbility(systemAbilityId, new TestTransactionService(), saExtraProp); EXPECT_EQ(ret, ERR_OK); + sm->RemoveSystemAbility(systemAbilityId); } /** @@ -194,15 +167,16 @@ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility004, TestSize.Level1) */ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility005, TestSize.Level1) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); int32_t systemAbilityId = DISTRIBUTED_SCHED_TEST_SO_ID; + sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_TRUE(sm != nullptr); std::u16string capability = u"{\"Capabilities\":{\"aaa\":\"[10.4, 20.5]\",\"bbb\":\"[11, 55]\",\ \"ccc\":\"this is string\", \"ddd\":\"[aa, bb, cc, dd]\", \"eee\":5.60, \"fff\":4545, \"ggg\":true}}"; ISystemAbilityManager::SAExtraProp saExtraProp(true, ISystemAbilityManager::DUMP_FLAG_PRIORITY_DEFAULT, capability, u""); - int32_t ret = saMgr->AddSystemAbility(systemAbilityId, new TestTransactionService(), saExtraProp); + int32_t ret = sm->AddSystemAbility(systemAbilityId, new TestTransactionService(), saExtraProp); EXPECT_EQ(ret, ERR_OK); + sm->RemoveSystemAbility(systemAbilityId); } /** @@ -212,9 +186,9 @@ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility005, TestSize.Level1) */ HWTEST_F(SystemAbilityMgrTest, RemoveSystemAbility001, TestSize.Level1) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); - int32_t result = saMgr->RemoveSystemAbility(-1); + sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_TRUE(sm != nullptr); + int32_t result = sm->RemoveSystemAbility(-1); EXPECT_TRUE(result != ERR_OK); } @@ -225,12 +199,11 @@ HWTEST_F(SystemAbilityMgrTest, RemoveSystemAbility001, TestSize.Level1) */ HWTEST_F(SystemAbilityMgrTest, RemoveSystemAbility002, TestSize.Level1) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_TRUE(sm != nullptr); sptr testAbility = new TestTransactionService(); - ISystemAbilityManager::SAExtraProp extraProp(false, DUMP_FLAG_PRIORITY_DEFAULT, u"", u""); - saMgr->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, testAbility, extraProp); - int32_t result = saMgr->RemoveSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID); + sm->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, testAbility); + int32_t result = sm->RemoveSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID); EXPECT_EQ(result, ERR_OK); } @@ -242,12 +215,11 @@ HWTEST_F(SystemAbilityMgrTest, RemoveSystemAbility002, TestSize.Level1) */ HWTEST_F(SystemAbilityMgrTest, RemoveSystemAbility003, TestSize.Level1) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); - saMgr->abilityStateScheduler_ = nullptr; + sptr saMgr = SystemAbilityManager::GetInstance(); sptr testAbility = new TestTransactionService(); ISystemAbilityManager::SAExtraProp extraProp; saMgr->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, testAbility, extraProp); + saMgr->abilityStateScheduler_ = nullptr; int32_t result = saMgr->RemoveSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID); EXPECT_EQ(result, ERR_INVALID_VALUE); } @@ -259,51 +231,12 @@ HWTEST_F(SystemAbilityMgrTest, RemoveSystemAbility003, TestSize.Level1) */ HWTEST_F(SystemAbilityMgrTest, RemoveSystemAbility004, TestSize.Level3) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + EXPECT_TRUE(saMgr != nullptr); int32_t result = saMgr->RemoveSystemAbility(-1); EXPECT_TRUE(result != ERR_OK); } -/** - * @tc.name: RemoveSystemAbility006 - * @tc.desc: test RemoveSystemAbility, ERR_INVALID_VALUE. - * @tc.type: FUNC - * @tc.require: I6NKWX - */ -HWTEST_F(SystemAbilityMgrTest, RemoveSystemAbility006, TestSize.Level0) -{ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); - sptr testAbility = new TestTransactionService(); - ISystemAbilityManager::SAExtraProp saExtraProp; - saMgr->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, testAbility, saExtraProp); - std::shared_ptr saScheduler = saMgr->abilityStateScheduler_; - saMgr->abilityStateScheduler_ = nullptr; - int32_t ret = saMgr->RemoveSystemAbility(testAbility); - EXPECT_EQ(ret, ERR_INVALID_VALUE); -} - -/** - * @tc.name: RemoveSystemAbility007 - * @tc.desc: test RemoveSystemAbility, ERR_OK. - * @tc.type: FUNC - * @tc.require: I6NKWX - */ -HWTEST_F(SystemAbilityMgrTest, RemoveSystemAbility007, TestSize.Level0) -{ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); - sptr testAbility = new TestTransactionService(); - ISystemAbilityManager::SAExtraProp saExtraProp; - saMgr->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, testAbility, saExtraProp); - CommonSaProfile saProfile = {u"test", DISTRIBUTED_SCHED_TEST_TT_ID}; - saProfile.cacheCommonEvent = true; - saMgr->saProfileMap_[DISTRIBUTED_SCHED_TEST_TT_ID] = saProfile; - int32_t ret = saMgr->RemoveSystemAbility(testAbility); - EXPECT_EQ(ret, ERR_OK); -} - /** * @tc.name: GetSystemAbility001 * @tc.desc: get not exist system ability. @@ -311,9 +244,9 @@ HWTEST_F(SystemAbilityMgrTest, RemoveSystemAbility007, TestSize.Level0) */ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility001, TestSize.Level1) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); - auto ability = saMgr->GetSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID); + sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_TRUE(sm != nullptr); + auto ability = sm->GetSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID); EXPECT_EQ(ability, nullptr); } @@ -324,13 +257,13 @@ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility001, TestSize.Level1) */ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility002, TestSize.Level1) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_TRUE(sm != nullptr); sptr testAbility = new TestTransactionService(); - ISystemAbilityManager::SAExtraProp extraProp(false, DUMP_FLAG_PRIORITY_DEFAULT, u"", u""); - saMgr->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, testAbility, extraProp); - auto ability = saMgr->GetSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID); + sm->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, testAbility); + auto ability = sm->GetSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID); EXPECT_TRUE(ability != nullptr); + sm->RemoveSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID); } /** @@ -340,12 +273,11 @@ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility002, TestSize.Level1) */ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility003, TestSize.Level1) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_TRUE(sm != nullptr); sptr testAbility = new TestTransactionService(); - ISystemAbilityManager::SAExtraProp extraProp(false, DUMP_FLAG_PRIORITY_DEFAULT, u"", u""); - saMgr->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, testAbility, extraProp); - auto ability = saMgr->GetSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID); + sm->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, testAbility); + auto ability = sm->GetSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID); EXPECT_TRUE(ability != nullptr); sptr targetAblility = iface_cast(ability); EXPECT_TRUE(targetAblility != nullptr); @@ -353,6 +285,7 @@ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility003, TestSize.Level1) int32_t result = targetAblility->ReverseInt(TEST_VALUE, rep); DTEST_LOG << "testAbility ReverseInt result = " << result << ", get reply = " << rep << std::endl; EXPECT_EQ(rep, TEST_REVERSE_VALUE); + sm->RemoveSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID); } /** @@ -362,18 +295,17 @@ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility003, TestSize.Level1) */ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility004, TestSize.Level2) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); - ISystemAbilityManager::SAExtraProp extraProp(false, DUMP_FLAG_PRIORITY_DEFAULT, u"", u""); + sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_TRUE(sm != nullptr); for (int32_t i = 0; i < REPEAT; ++i) { - auto result = saMgr->AddSystemAbility((DISTRIBUTED_SCHED_TEST_SO_ID + i), - new TestTransactionService(), extraProp); + auto result = sm->AddSystemAbility((DISTRIBUTED_SCHED_TEST_SO_ID + i), new TestTransactionService()); EXPECT_EQ(result, ERR_OK); } for (int32_t i = 0; i < REPEAT; ++i) { int32_t saId = DISTRIBUTED_SCHED_TEST_SO_ID + i; - auto saObject = saMgr->GetSystemAbility(saId); + auto saObject = sm->GetSystemAbility(saId); EXPECT_TRUE(saObject != nullptr); + sm->RemoveSystemAbility(saId); } } @@ -384,10 +316,10 @@ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility004, TestSize.Level2) */ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility005, TestSize.Level2) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_TRUE(sm != nullptr); string fakeDeviceId = "fake_dev"; - auto abilityObj = saMgr->GetSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, fakeDeviceId); + auto abilityObj = sm->GetSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, fakeDeviceId); EXPECT_EQ(abilityObj, nullptr); } @@ -398,14 +330,14 @@ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility005, TestSize.Level2) */ HWTEST_F(SystemAbilityMgrTest, CheckSystemAbility001, TestSize.Level1) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); int32_t systemAbilityId = DISTRIBUTED_SCHED_TEST_TT_ID; + sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_TRUE(sm != nullptr); sptr testAbility = new TestTransactionService(); - ISystemAbilityManager::SAExtraProp extraProp(false, DUMP_FLAG_PRIORITY_DEFAULT, u"", u""); - saMgr->AddSystemAbility(systemAbilityId, testAbility, extraProp); - sptr abilityObj = saMgr->CheckSystemAbility(systemAbilityId); + sm->AddSystemAbility(systemAbilityId, testAbility); + sptr abilityObj = sm->CheckSystemAbility(systemAbilityId); EXPECT_TRUE(abilityObj != nullptr); + sm->RemoveSystemAbility(systemAbilityId); } /** @@ -416,10 +348,8 @@ HWTEST_F(SystemAbilityMgrTest, CheckSystemAbility001, TestSize.Level1) */ HWTEST_F(SystemAbilityMgrTest, CheckSystemAbility002, TestSize.Level1) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); - saMgr->abilityStateScheduler_ = nullptr; int32_t systemAbilityId = DISTRIBUTED_SCHED_TEST_TT_ID; + sptr saMgr = SystemAbilityManager::GetInstance(); bool isExist = true; sptr abilityObj = saMgr->CheckSystemAbility(systemAbilityId, isExist); EXPECT_EQ(abilityObj, nullptr); @@ -433,8 +363,7 @@ HWTEST_F(SystemAbilityMgrTest, CheckSystemAbility002, TestSize.Level1) */ HWTEST_F(SystemAbilityMgrTest, CheckSystemAbility003, TestSize.Level3) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); saMgr->abilityStateScheduler_ = nullptr; bool isExist = true; sptr ret = saMgr->CheckSystemAbility(SAID, isExist); @@ -449,12 +378,15 @@ HWTEST_F(SystemAbilityMgrTest, CheckSystemAbility003, TestSize.Level3) */ HWTEST_F(SystemAbilityMgrTest, CheckSystemAbility004, TestSize.Level3) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + std::shared_ptr systemAbilityStateScheduler = + std::make_shared(); + saMgr->abilityStateScheduler_ = systemAbilityStateScheduler; std::shared_ptr systemAbilityContext = std::make_shared(); std::shared_ptr systemProcessContext = std::make_shared(); + systemAbilityStateScheduler->abilityContextMap_.clear(); systemAbilityContext->ownProcessContext = systemProcessContext; - saMgr->abilityStateScheduler_->abilityContextMap_[SAID] = systemAbilityContext; + systemAbilityStateScheduler->abilityContextMap_[SAID] = systemAbilityContext; systemAbilityContext->state = SystemAbilityState::UNLOADING; bool isExist = true; sptr ret = saMgr->CheckSystemAbility(SAID, isExist); @@ -470,12 +402,12 @@ HWTEST_F(SystemAbilityMgrTest, CheckSystemAbility004, TestSize.Level3) HWTEST_F(SystemAbilityMgrTest, CheckSystemAbility005, TestSize.Level3) { DTEST_LOG << " CheckSystemAbility005 " << std::endl; - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); int32_t systemAbilityId = DISTRIBUTED_SCHED_TEST_TT_ID; + sptr saMgr = SystemAbilityManager::GetInstance(); bool isExist = true; saMgr->abilityStateScheduler_ = nullptr; sptr abilityObj = saMgr->CheckSystemAbility(systemAbilityId, isExist); + saMgr->abilityStateScheduler_ = make_shared(); EXPECT_EQ(abilityObj, nullptr); } @@ -487,14 +419,14 @@ HWTEST_F(SystemAbilityMgrTest, CheckSystemAbility005, TestSize.Level3) HWTEST_F(SystemAbilityMgrTest, ListSystemAbility001, TestSize.Level1) { int32_t systemAbilityId = DISTRIBUTED_SCHED_TEST_TT_ID; - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); - ISystemAbilityManager::SAExtraProp extraProp(false, DUMP_FLAG_PRIORITY_DEFAULT, u"", u""); - saMgr->AddSystemAbility(systemAbilityId, new TestTransactionService(), extraProp); - auto saList = saMgr->ListSystemAbilities(DUMP_FLAG_PRIORITY_ALL); + sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_TRUE(sm != nullptr); + sm->AddSystemAbility(systemAbilityId, new TestTransactionService()); + auto saList = sm->ListSystemAbilities(); EXPECT_TRUE(!saList.empty()); auto iter = std::find(saList.begin(), saList.end(), to_utf16(std::to_string(systemAbilityId))); EXPECT_TRUE(iter != saList.end()); + sm->RemoveSystemAbility(systemAbilityId); } /** @@ -504,8 +436,8 @@ HWTEST_F(SystemAbilityMgrTest, ListSystemAbility001, TestSize.Level1) */ HWTEST_F(SystemAbilityMgrTest, OnRemoteDied001, TestSize.Level1) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + EXPECT_TRUE(saMgr != nullptr); sptr callback = new SystemAbilityLoadCallbackMock(); saMgr->OnAbilityCallbackDied(callback->AsObject()); EXPECT_TRUE(saMgr->startingAbilityMap_.empty()); @@ -519,9 +451,7 @@ HWTEST_F(SystemAbilityMgrTest, OnRemoteDied001, TestSize.Level1) */ HWTEST_F(SystemAbilityMgrTest, DoMakeRemoteBinder001, TestSize.Level2) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); - saMgr->dBinderService_ = DBinderService::GetInstance(); + sptr saMgr = SystemAbilityManager::GetInstance(); std::string deviceId = "1111111"; int32_t systemAbilityId = 0; auto remoteObject = saMgr->DoMakeRemoteBinder(systemAbilityId, 0, 0, deviceId); @@ -537,9 +467,7 @@ HWTEST_F(SystemAbilityMgrTest, DoMakeRemoteBinder001, TestSize.Level2) HWTEST_F(SystemAbilityMgrTest, DoMakeRemoteBinder002, TestSize.Level2) { DTEST_LOG << " DoMakeRemoteBinder002 " << std::endl; - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); - saMgr->dBinderService_ = DBinderService::GetInstance(); + sptr saMgr = SystemAbilityManager::GetInstance(); std::string deviceId = "2222222"; int32_t systemAbilityId = -1; auto remoteObject = saMgr->DoMakeRemoteBinder(systemAbilityId, 0, 0, deviceId); @@ -559,8 +487,9 @@ HWTEST_F(SystemAbilityMgrTest, startingAbilityMapTest001, TestSize.Level1) * @tc.steps: step1. init startingAbilityMap_ * @tc.expected: step1. init startingAbilityMap_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->startingAbilityMap_.clear(); + sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback3 = new SystemAbilityLoadCallbackMock(); @@ -608,8 +537,9 @@ HWTEST_F(SystemAbilityMgrTest, startingAbilityMapTest002, TestSize.Level1) * @tc.steps: step1. init startingAbilityMap_ * @tc.expected: step1. init startingAbilityMap_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->startingAbilityMap_.clear(); + sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); std::map mockCallbackMap1 = { @@ -638,8 +568,8 @@ HWTEST_F(SystemAbilityMgrTest, startingAbilityMapTest003, TestSize.Level1) * @tc.steps: step1. init startingAbilityMap_ * @tc.expected: step1. init startingAbilityMap_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->startingAbilityMap_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -670,8 +600,8 @@ HWTEST_F(SystemAbilityMgrTest, startingAbilityMapTest004, TestSize.Level1) * @tc.steps: step1. init startingAbilityMap_ * @tc.expected: step1. init startingAbilityMap_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->startingAbilityMap_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -702,8 +632,8 @@ HWTEST_F(SystemAbilityMgrTest, startingAbilityMapTest005, TestSize.Level1) * @tc.steps: step1. init startingAbilityMap_ * @tc.expected: step1. init startingAbilityMap_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->startingAbilityMap_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -735,8 +665,8 @@ HWTEST_F(SystemAbilityMgrTest, startingAbilityMapTest006, TestSize.Level1) * @tc.steps: step1. init startingAbilityMap_ * @tc.expected: step1. init startingAbilityMap_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->startingAbilityMap_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -767,8 +697,8 @@ HWTEST_F(SystemAbilityMgrTest, startingAbilityMapTest007, TestSize.Level1) * @tc.steps: step1. init startingAbilityMap_ * @tc.expected: step1. init startingAbilityMap_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->startingAbilityMap_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -799,8 +729,8 @@ HWTEST_F(SystemAbilityMgrTest, startingAbilityMapTest008, TestSize.Level1) * @tc.steps: step1. init startingAbilityMap_ * @tc.expected: step1. init startingAbilityMap_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->startingAbilityMap_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -833,8 +763,8 @@ HWTEST_F(SystemAbilityMgrTest, startingAbilityMapTest009, TestSize.Level1) * @tc.steps: step1. init startingAbilityMap_ * @tc.expected: step1. init startingAbilityMap_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->startingAbilityMap_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -866,8 +796,8 @@ HWTEST_F(SystemAbilityMgrTest, startingAbilityMapTest010, TestSize.Level1) * @tc.steps: step1. init startingAbilityMap_ * @tc.expected: step1. init startingAbilityMap_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->startingAbilityMap_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -907,8 +837,8 @@ HWTEST_F(SystemAbilityMgrTest, startingAbilityMapTest011, TestSize.Level1) * @tc.steps: step1. init startingAbilityMap_ * @tc.expected: step1. init startingAbilityMap_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->startingAbilityMap_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -949,8 +879,8 @@ HWTEST_F(SystemAbilityMgrTest, startingAbilityMapTest012, TestSize.Level1) * @tc.steps: step1. init startingAbilityMap_ * @tc.expected: step1. init startingAbilityMap_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->startingAbilityMap_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -992,11 +922,11 @@ HWTEST_F(SystemAbilityMgrTest, OnRemoteCallbackDied001, TestSize.Level1) * @tc.steps: step1. init remoteCallbacks_ * @tc.expected: step1. init remoteCallbacks_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); + saMgr->remoteCallbacks_.clear(); saMgr->remoteCallbacks_ = { {"11111", {mockLoadCallback1, mockLoadCallback2}} }; @@ -1021,8 +951,8 @@ HWTEST_F(SystemAbilityMgrTest, OnRemoteCallbackDied002, TestSize.Level1) * @tc.steps: step1. init remoteCallbacks_ with one device and one callback * @tc.expected: step1. init remoteCallbacks_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->remoteCallbacks_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); saMgr->remoteCallbacks_ = { {"11111", {mockLoadCallback1}} @@ -1048,8 +978,8 @@ HWTEST_F(SystemAbilityMgrTest, OnRemoteCallbackDied003, TestSize.Level1) * @tc.steps: step1. init remoteCallbacks_ with one device and one callback * @tc.expected: step1. init remoteCallbacks_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->remoteCallbacks_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); saMgr->remoteCallbacks_ = { @@ -1076,8 +1006,8 @@ HWTEST_F(SystemAbilityMgrTest, OnRemoteCallbackDied004, TestSize.Level1) * @tc.steps: step1. init remoteCallbacks_ * @tc.expected: step1. init remoteCallbacks_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->remoteCallbacks_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -1106,8 +1036,8 @@ HWTEST_F(SystemAbilityMgrTest, OnRemoteCallbackDied005, TestSize.Level1) * @tc.steps: step1. init remoteCallbacks_ * @tc.expected: step1. init remoteCallbacks_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->remoteCallbacks_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -1136,8 +1066,8 @@ HWTEST_F(SystemAbilityMgrTest, OnRemoteCallbackDied006, TestSize.Level1) * @tc.steps: step1. init remoteCallbacks_ * @tc.expected: step1. init remoteCallbacks_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->remoteCallbacks_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -1167,8 +1097,8 @@ HWTEST_F(SystemAbilityMgrTest, OnRemoteCallbackDied007, TestSize.Level1) * @tc.steps: step1. init remoteCallbacks_ * @tc.expected: step1. init remoteCallbacks_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->remoteCallbacks_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -1197,8 +1127,8 @@ HWTEST_F(SystemAbilityMgrTest, OnRemoteCallbackDied008, TestSize.Level1) * @tc.steps: step1. init remoteCallbacks_ * @tc.expected: step1. init remoteCallbacks_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->remoteCallbacks_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -1216,9 +1146,10 @@ HWTEST_F(SystemAbilityMgrTest, OnRemoteCallbackDied008, TestSize.Level1) } /** - * @tc.name: DoLoadRemoteSystemAbility001 test + * @tc.name: OnRemoteCallbackDied008 test * @tc.desc: test for callback dead, with one device, some callback * @tc.type: FUNC + * @tc.require: I5KMF7 */ HWTEST_F(SystemAbilityMgrTest, DoLoadRemoteSystemAbility001, TestSize.Level1) { @@ -1227,8 +1158,8 @@ HWTEST_F(SystemAbilityMgrTest, DoLoadRemoteSystemAbility001, TestSize.Level1) * @tc.steps: step1. init remoteCallbacks_ * @tc.expected: step1. init remoteCallbacks_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->remoteCallbacks_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -1259,8 +1190,8 @@ HWTEST_F(SystemAbilityMgrTest, DoLoadRemoteSystemAbility002, TestSize.Level1) * @tc.steps: step1. init remoteCallbacks_ * @tc.expected: step1. init remoteCallbacks_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->remoteCallbacks_.clear(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -1288,8 +1219,8 @@ HWTEST_F(SystemAbilityMgrTest, DoLoadRemoteSystemAbility003, TestSize.Level1) * @tc.steps: step1. init remoteCallbacks_ * @tc.expected: step1. init remoteCallbacks_ */ - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->remoteCallbacks_.clear(); sptr mockLoadCallback1 = new SystemAbilityLoadCallbackMock(); sptr mockLoadCallback2 = new SystemAbilityLoadCallbackMock(); @@ -1315,8 +1246,8 @@ HWTEST_F(SystemAbilityMgrTest, DoLoadRemoteSystemAbility003, TestSize.Level1) HWTEST_F(SystemAbilityMgrTest, DoLoadRemoteSystemAbility004, TestSize.Level1) { DTEST_LOG << " DoLoadRemoteSystemAbility004 start " << std::endl; - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->remoteCallbacks_.clear(); saMgr->DoLoadRemoteSystemAbility(11111, 0, 0, "222", nullptr); ASSERT_EQ(saMgr->remoteCallbacks_.size(), 0); } @@ -1348,6 +1279,7 @@ HWTEST_F(SystemAbilityMgrTest, ReportGetSAFre001, TestSize.Level3) { DTEST_LOG << " ReportGetSAFre001 start " << std::endl; ReportGetSAFrequency(1, 1, 1); + sptr saMgr = SystemAbilityManager::GetInstance(); uint32_t realUid = 1; uint32_t readSaid = 1; uint64_t key = SamgrUtil::GenerateFreKey(realUid, readSaid); @@ -1368,9 +1300,9 @@ HWTEST_F(SystemAbilityMgrTest, ReportGetSAFre001, TestSize.Level3) HWTEST_F(SystemAbilityMgrTest, ReportGetSAFre002, TestSize.Level3) { DTEST_LOG << " ReportGetSAFre002 start " << std::endl; - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); int32_t uid = 1; + saMgr->saFrequencyMap_.clear(); int32_t count = saMgr->UpdateSaFreMap(uid, TEST_SYSTEM_ABILITY1); ASSERT_EQ(saMgr->saFrequencyMap_.size(), 1); saMgr->ReportGetSAPeriodically(); @@ -1386,9 +1318,9 @@ HWTEST_F(SystemAbilityMgrTest, ReportGetSAFre002, TestSize.Level3) HWTEST_F(SystemAbilityMgrTest, ReportGetSAFre003, TestSize.Level3) { DTEST_LOG << " ReportGetSAFre003 start " << std::endl; - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); int32_t uid = -1; + saMgr->saFrequencyMap_.clear(); int32_t count = saMgr->UpdateSaFreMap(uid, TEST_SYSTEM_ABILITY1); saMgr->ReportGetSAPeriodically(); ASSERT_EQ(saMgr->saFrequencyMap_.size(), 0); @@ -1403,13 +1335,13 @@ HWTEST_F(SystemAbilityMgrTest, ReportGetSAFre003, TestSize.Level3) HWTEST_F(SystemAbilityMgrTest, ReportGetSAFre004, TestSize.Level3) { DTEST_LOG << " ReportGetSAFre004 start " << std::endl; - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); int32_t uid = 1; uint64_t key = SamgrUtil::GenerateFreKey(uid, TEST_SYSTEM_ABILITY1); saMgr->saFrequencyMap_[key] = MAX_COUNT; int32_t count = saMgr->UpdateSaFreMap(uid, TEST_SYSTEM_ABILITY1); EXPECT_EQ(saMgr->saFrequencyMap_[key], MAX_COUNT); + saMgr->saFrequencyMap_.clear(); } /** @@ -1421,8 +1353,10 @@ HWTEST_F(SystemAbilityMgrTest, ReportGetSAFre004, TestSize.Level3) HWTEST_F(SystemAbilityMgrTest, GetSystemProcessInfo001, TestSize.Level3) { DTEST_LOG << " GetSystemProcessInfo001 " << std::endl; - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + std::shared_ptr systemAbilityStateScheduler = + std::make_shared(); + saMgr->abilityStateScheduler_ = systemAbilityStateScheduler; SystemProcessInfo ProcessInfo; int32_t ret = saMgr->GetSystemProcessInfo(SAID, ProcessInfo); EXPECT_EQ(ret, ERR_INVALID_VALUE); @@ -1437,8 +1371,7 @@ HWTEST_F(SystemAbilityMgrTest, GetSystemProcessInfo001, TestSize.Level3) HWTEST_F(SystemAbilityMgrTest, GetSystemProcessInfo002, TestSize.Level3) { DTEST_LOG << " GetSystemProcessInfo002 " << std::endl; - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); SystemProcessInfo ProcessInfo; saMgr->abilityStateScheduler_ = nullptr; int32_t ret = saMgr->GetSystemProcessInfo(SAID, ProcessInfo); @@ -1454,8 +1387,10 @@ HWTEST_F(SystemAbilityMgrTest, GetSystemProcessInfo002, TestSize.Level3) HWTEST_F(SystemAbilityMgrTest, GetRunningSystemProcess001, TestSize.Level3) { DTEST_LOG << " GetRunningSystemProcess001 " << std::endl; - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + std::shared_ptr systemAbilityStateScheduler = + std::make_shared(); + saMgr->abilityStateScheduler_ = systemAbilityStateScheduler; std::list systemProcessInfos; int32_t ret = saMgr->GetRunningSystemProcess(systemProcessInfos); EXPECT_EQ(ret, ERR_OK); @@ -1470,8 +1405,7 @@ HWTEST_F(SystemAbilityMgrTest, GetRunningSystemProcess001, TestSize.Level3) HWTEST_F(SystemAbilityMgrTest, GetRunningSystemProcess002, TestSize.Level3) { DTEST_LOG << " GetRunningSystemProcess002 " << std::endl; - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); std::list systemProcessInfos; saMgr->abilityStateScheduler_ = nullptr; int32_t ret = saMgr->GetRunningSystemProcess(systemProcessInfos); @@ -1486,8 +1420,7 @@ HWTEST_F(SystemAbilityMgrTest, GetRunningSystemProcess002, TestSize.Level3) */ HWTEST_F(SystemAbilityMgrTest, GetRunningSystemProcess003, TestSize.Level3) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); saMgr->abilityStateScheduler_ = nullptr; std::list systemProcessInfos; int32_t ret = saMgr->GetRunningSystemProcess(systemProcessInfos); @@ -1503,11 +1436,54 @@ HWTEST_F(SystemAbilityMgrTest, GetRunningSystemProcess003, TestSize.Level3) HWTEST_F(SystemAbilityMgrTest, WatchDogInit001, TestSize.Level3) { DTEST_LOG << " WatchDogInit001 " << std::endl; - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); EXPECT_NE(saMgr, nullptr); } +/** + * @tc.name: RemoveSystemAbility006 + * @tc.desc: test RemoveSystemAbility, ERR_INVALID_VALUE. + * @tc.type: FUNC + * @tc.require: I6NKWX + */ +HWTEST_F(SystemAbilityMgrTest, RemoveSystemAbility006, TestSize.Level0) +{ + sptr saMgr = SystemAbilityManager::GetInstance(); + sptr testAbility = new TestTransactionService(); + ISystemAbilityManager::SAExtraProp saExtraProp; + saMgr->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, testAbility, saExtraProp); + std::shared_ptr saScheduler = saMgr->abilityStateScheduler_; + saMgr->abilityStateScheduler_ = nullptr; + int32_t ret = saMgr->RemoveSystemAbility(testAbility); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + saMgr->abilityStateScheduler_ = saScheduler; +} + +/** + * @tc.name: RemoveSystemAbility007 + * @tc.desc: test RemoveSystemAbility, ERR_OK. + * @tc.type: FUNC + * @tc.require: I6NKWX + */ +HWTEST_F(SystemAbilityMgrTest, RemoveSystemAbility007, TestSize.Level0) +{ + sptr saMgr = SystemAbilityManager::GetInstance(); + EXPECT_TRUE(saMgr != nullptr); + saMgr->workHandler_ = make_shared("workHandler"); + std::shared_ptr systemAbilityStateScheduler = + std::make_shared(); + saMgr->abilityStateScheduler_ = systemAbilityStateScheduler; + sptr testAbility = new TestTransactionService(); + ISystemAbilityManager::SAExtraProp saExtraProp; + saMgr->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, testAbility, saExtraProp); + CommonSaProfile saProfile = {u"test", DISTRIBUTED_SCHED_TEST_TT_ID}; + saProfile.cacheCommonEvent = true; + saMgr->saProfileMap_[DISTRIBUTED_SCHED_TEST_TT_ID] = saProfile; + int32_t ret = saMgr->RemoveSystemAbility(testAbility); + EXPECT_EQ(ret, ERR_OK); + saMgr->saProfileMap_.erase(DISTRIBUTED_SCHED_TEST_TT_ID); +} + /** * @tc.name: AddSystemProcess001 * @tc.desc: test AddSystemProcess, abilityStateScheduler_ is nullptr @@ -1516,8 +1492,7 @@ HWTEST_F(SystemAbilityMgrTest, WatchDogInit001, TestSize.Level3) */ HWTEST_F(SystemAbilityMgrTest, AddSystemProcess001, TestSize.Level3) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); std::u16string procName = u"test"; sptr testAbility = new TestTransactionService(); saMgr->abilityStateScheduler_ = nullptr; @@ -1533,8 +1508,7 @@ HWTEST_F(SystemAbilityMgrTest, AddSystemProcess001, TestSize.Level3) */ HWTEST_F(SystemAbilityMgrTest, RemoveSystemProcess001, TestSize.Level3) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); sptr testAbility = new TestTransactionService(); saMgr->abilityStateScheduler_ = nullptr; int32_t result = saMgr->RemoveSystemProcess(testAbility); @@ -1558,8 +1532,7 @@ HWTEST_F(SystemAbilityMgrTest, RemoveSystemProcess001, TestSize.Level3) */ HWTEST_F(SystemAbilityMgrTest, RemoveSystemProcess002, TestSize.Level3) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); sptr testAbility = new TestTransactionService(); saMgr->abilityStateScheduler_ = nullptr; saMgr->systemProcessMap_[u"test"] = testAbility; @@ -1575,7 +1548,7 @@ HWTEST_F(SystemAbilityMgrTest, RemoveSystemProcess002, TestSize.Level3) */ HWTEST_F(SystemAbilityMgrTest, SetDeviceName001, TestSize.Level3) { - sptr saMgr = new SystemAbilityManager; + sptr saMgr = SystemAbilityManager::GetInstance(); saMgr->SetDeviceName(DEVICE_NAME); EXPECT_EQ(saMgr->deviceName_, DEVICE_NAME); } @@ -1588,7 +1561,7 @@ HWTEST_F(SystemAbilityMgrTest, SetDeviceName001, TestSize.Level3) */ HWTEST_F(SystemAbilityMgrTest, GetDeviceName001, TestSize.Level3) { - sptr saMgr = new SystemAbilityManager; + sptr saMgr = SystemAbilityManager::GetInstance(); saMgr->SetDeviceName(DEVICE_NAME); auto ret = saMgr->GetDeviceName(); EXPECT_EQ(ret, DEVICE_NAME); @@ -1602,8 +1575,8 @@ HWTEST_F(SystemAbilityMgrTest, GetDeviceName001, TestSize.Level3) */ HWTEST_F(SystemAbilityMgrTest, OnAbilityCallbackDied001, TestSize.Level3) { - sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->startingAbilityMap_.clear(); saMgr->OnAbilityCallbackDied(nullptr); EXPECT_TRUE(saMgr->startingAbilityMap_.empty()); } diff --git a/test/fuzztest/samgrdumper_fuzzer/samgrdumper_fuzzer.cpp b/test/fuzztest/samgrdumper_fuzzer/samgrdumper_fuzzer.cpp index c81daef5..6f20faca 100644 --- a/test/fuzztest/samgrdumper_fuzzer/samgrdumper_fuzzer.cpp +++ b/test/fuzztest/samgrdumper_fuzzer/samgrdumper_fuzzer.cpp @@ -90,9 +90,10 @@ void SamgrDumperFuzzTest(const uint8_t* data, size_t size) SystemAbilityManagerDumper::GetSamgrIpcStatistics(result); SystemAbilityManagerDumper::StopSamgrIpcStatistics(result); SystemAbilityManagerDumper::StartSamgrIpcStatistics(result); + SystemAbilityManagerDumper::GetFfrtDumpInfoProc(scheduler, args, result); SystemAbilityManagerDumper::GetSAMgrFfrtInfo(result); int32_t pid = BuildInt32FromData(data, size); - SystemAbilityManagerDumper::DumpFfrtInfoInProc(scheduler, pid, result); + SystemAbilityManagerDumper::DumpFfrtInfoByProcName(pid, Str8ToStr16(processName), result); std::shared_ptr manager = std::make_shared(); manager->abilityStateScheduler_ = std::make_shared(); @@ -148,30 +149,6 @@ void FuzzListenerDumpProc(const uint8_t* data, size_t size) SystemAbilityManagerDumper::ListenerDumpProc(dumpListeners, fd, args); args.clear(); } - -void FuzzFfrtLoadMetrics(const uint8_t* data, size_t size) -{ - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; - int32_t pid = GetData(); - std::shared_ptr scheduler = std::make_shared(); - int32_t fd = -1; - std::vector args; - args.push_back("--ffrt"); - args.push_back(ToString(pid)); - args.push_back("--start-stat"); - std::string result; - SystemAbilityManagerDumper::GetFfrtLoadMetrics(scheduler, fd, args, result); - SystemAbilityManagerDumper::ClearFfrtStatistics(); - SystemAbilityManagerDumper::GetFfrtLoadMetrics(scheduler, fd, args, result); - args.pop_back(); - args.push_back("--stop-stat"); - SystemAbilityManagerDumper::GetFfrtLoadMetrics(scheduler, fd, args, result); - args.pop_back(); - args.push_back("--stat"); - SystemAbilityManagerDumper::GetFfrtLoadMetrics(scheduler, fd, args, result); -} } } @@ -184,7 +161,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::Samgr::SamgrDumperFuzzTest(data, size); OHOS::Samgr::FuzzListenerDumpProc(data, size); - OHOS::Samgr::FuzzFfrtLoadMetrics(data, size); return 0; } -- Gitee