diff --git a/test/benchmarktest/BUILD.gn b/test/benchmarktest/BUILD.gn index d21c1858c..8dfb5f065 100644 --- a/test/benchmarktest/BUILD.gn +++ b/test/benchmarktest/BUILD.gn @@ -9,10 +9,14 @@ # 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. +# limitations under the License. -group("unittest") { +group("benchmarktest") { testonly = true - deps = [ "ability_info_test:unittest" ] + deps = [ + "ability_info_test:benchmarktest", + "bundlemgr_proxy_test:benchmarktest", + "installer_proxy_test:benchmarktest", + ] } diff --git a/test/benchmarktest/bundlemgr_proxy_test/BUILD.gn b/test/benchmarktest/bundlemgr_proxy_test/BUILD.gn new file mode 100644 index 000000000..4790f8ce6 --- /dev/null +++ b/test/benchmarktest/bundlemgr_proxy_test/BUILD.gn @@ -0,0 +1,60 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/appexecfwk/standard/appexecfwk.gni") + +module_output_path = "bundle_framework/benchmark/bundle_framework" + +ohos_benchmarktest("BenchmarkTestBundleMgrProxy") { + module_out_path = module_output_path + include_dirs = [ + "//third_party/json/include", + "//base/notification/ces_standard/test/systemtest/common/resource", + ] + + sources = [ "bundlemgr_proxy_test.cpp" ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + deps = [ + "${common_path}:libappexecfwk_common", + "${innerkits_path}/appexecfwk_base:appexecfwk_base", + "${services_path}/test/moduletest/utils:tool_common", + "//foundation/aafwk/standard/interfaces/innerkits/base:base", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//third_party/benchmark:benchmark", + "//third_party/googletest:gtest_main", + ] + + defines = [ "APP_LOG_TAG = \"BundleMgrTool\"" ] + + external_deps = [ "ipc:ipc_core" ] + resource_config_file = "//foundation/appexecfwk/standard/test/benchmarktest/resource/ohos_test.xml" +} + +group("benchmarktest") { + testonly = true + deps = [] + + deps += [ + # deps file + ":BenchmarkTestBundleMgrProxy", + ] +} diff --git a/test/benchmarktest/bundlemgr_proxy_test/bundlemgr_proxy_test.cpp b/test/benchmarktest/bundlemgr_proxy_test/bundlemgr_proxy_test.cpp new file mode 100644 index 000000000..ef3d0169b --- /dev/null +++ b/test/benchmarktest/bundlemgr_proxy_test/bundlemgr_proxy_test.cpp @@ -0,0 +1,2273 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "bundle_constants.h" +#include "bundle_mgr_proxy.h" +#include "bundle_status_callback_host.h" +#include "clean_cache_callback_host.h" +#include "common_tool.h" +#include "iservice_registry.h" +#include "nlohmann/json.hpp" +#include "status_receiver_host.h" +#include "system_ability_definition.h" +#include "testConfigParser.h" + +using OHOS::AAFwk::Want; +using namespace testing::ext; +using namespace std::chrono_literals; +using namespace OHOS; +using namespace OHOS::AppExecFwk; + +namespace { +const std::string ERROR_INSTALL_FAILED = "install failed!"; +const std::string ERROR_UNINSTALL_FAILED = "uninstall failed!"; +const std::string MSG_SUCCESS = "[SUCCESS]"; +const std::string OPERATION_FAILED = "Failure"; +const std::string OPERATION_SUCCESS = "Success"; +const std::string SYSTEM_SETTINGS_BUNDLE_NAME = "com.ohos.settings"; +const std::string bundleName = "com.ohos.contactsdataability"; +const std::string abilityName = "com.ohos.contactsdataability.MainAbility"; +const std::string hapFilePath = "/data/test/benchmark/test.hap"; +const std::string MODULE_NAME_TEST = "entry"; +const std::string COMMON_EVENT_EVENT = "usual.event.PACKAGE_ADDED"; +const int32_t DEFAULT_USERID = 100; +class BundleStatusCallbackImpl : public BundleStatusCallbackHost { +public: + BundleStatusCallbackImpl(); + virtual ~BundleStatusCallbackImpl() override; + virtual void OnBundleStateChanged(const uint8_t installType, const int32_t resultCode, const std::string &resultMsg, + const std::string &bundleName) override; + virtual void OnBundleAdded(const std::string &bundleName, const int userId) override {}; + virtual void OnBundleUpdated(const std::string &bundleName, const int userId) override {}; + virtual void OnBundleRemoved(const std::string &bundleName, const int userId) override {}; + +private: + DISALLOW_COPY_AND_MOVE(BundleStatusCallbackImpl); +}; + +BundleStatusCallbackImpl::BundleStatusCallbackImpl() +{} + +BundleStatusCallbackImpl::~BundleStatusCallbackImpl() +{} + +void BundleStatusCallbackImpl::OnBundleStateChanged( + const uint8_t installType, const int32_t resultCode, const std::string &resultMsg, const std::string &bundleName) +{} + +class CleanCacheCallBackImpl : public CleanCacheCallbackHost { +public: + CleanCacheCallBackImpl(); + virtual ~CleanCacheCallBackImpl() override; + + virtual void OnCleanCacheFinished(bool succeeded) override; + bool GetSucceededResult() const; + +private: + mutable std::promise resultSucceededSignal_; + DISALLOW_COPY_AND_MOVE(CleanCacheCallBackImpl); +}; + +CleanCacheCallBackImpl::CleanCacheCallBackImpl() +{} + +CleanCacheCallBackImpl::~CleanCacheCallBackImpl() +{} + +void CleanCacheCallBackImpl::OnCleanCacheFinished(bool succeeded) +{ + resultSucceededSignal_.set_value(!succeeded); +} + +bool CleanCacheCallBackImpl::GetSucceededResult() const +{ + auto future = resultSucceededSignal_.get_future(); + future.wait(); + return future.get(); +} + +class StatusReceiverImpl : public StatusReceiverHost { +public: + StatusReceiverImpl(); + virtual ~StatusReceiverImpl(); + virtual void OnStatusNotify(const int progress) override; + virtual void OnFinished(const int32_t resultCode, const std::string &resultMsg) override; + std::string GetResultMsg() const; + +private: + mutable std::promise resultMsgSignal_; + int iProgress_ = 0; + + DISALLOW_COPY_AND_MOVE(StatusReceiverImpl); +}; + +StatusReceiverImpl::StatusReceiverImpl() +{} + +StatusReceiverImpl::~StatusReceiverImpl() +{} + +void StatusReceiverImpl::OnFinished(const int32_t resultCode, const std::string &resultMsg) +{ + resultMsgSignal_.set_value(resultMsg); +} +void StatusReceiverImpl::OnStatusNotify(const int progress) +{ + iProgress_ = progress; +} + +std::string StatusReceiverImpl::GetResultMsg() const +{ + auto future = resultMsgSignal_.get_future(); + future.wait(); + std::string resultMsg = future.get(); + if (resultMsg == MSG_SUCCESS) { + return OPERATION_SUCCESS; + } else { + return OPERATION_FAILED + resultMsg; + } +} + +class BundleMgrProxyTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + static void Install( + const std::string &bundleFilePath, const InstallFlag installFlag, std::vector &resvec); + static void Uninstall(const std::string &bundleName, std::vector &resvec); + static void HapUninstall( + const std::string &bundleName, const std::string &modulePackage, std::vector &resvec); + static sptr GetBundleMgrProxy(); + static sptr GetInstallerProxy(); + void CheckBundleInfo(const uint32_t index, BundleInfo &bundleInfo) const; + void CreateDir(const std::string &path) const; + void CheckFileExist(const std::string &bundleName) const; + void CheckFileExist(const std::string &bundleName, const std::string &modulePackage) const; + void CheckFileNonExist(const std::string &bundleName) const; + void CheckFileNonExist(const std::string &bundleName, const std::string &modulePackage) const; +}; + +void BundleMgrProxyTest::SetUpTestCase() +{} + +void BundleMgrProxyTest::TearDownTestCase() +{} + +void BundleMgrProxyTest::SetUp() +{} + +void BundleMgrProxyTest::TearDown() +{} + +void BundleMgrProxyTest::Install( + const std::string &bundleFilePath, const InstallFlag installFlag, std::vector &resvec) +{ + sptr installerProxy = GetInstallerProxy(); + if (!installerProxy) { + resvec.push_back(ERROR_INSTALL_FAILED); + return; + } + InstallParam installParam; + installParam.installFlag = installFlag; + installParam.userId = Constants::DEFAULT_USERID; + sptr statusReceiver = (new (std::nothrow) StatusReceiverImpl()); + installerProxy->Install(bundleFilePath, installParam, statusReceiver); + resvec.push_back(statusReceiver->GetResultMsg()); +} + +void BundleMgrProxyTest::Uninstall(const std::string &bundleName, std::vector &resvec) +{ + sptr installerProxy = GetInstallerProxy(); + if (!installerProxy) { + resvec.push_back(ERROR_UNINSTALL_FAILED); + return; + } + + if (bundleName.empty()) { + resvec.push_back(ERROR_UNINSTALL_FAILED); + } else { + InstallParam installParam; + installParam.userId = Constants::DEFAULT_USERID; + sptr statusReceiver = (new (std::nothrow) StatusReceiverImpl()); + installerProxy->Uninstall(bundleName, installParam, statusReceiver); + resvec.push_back(statusReceiver->GetResultMsg()); + } +} + +void BundleMgrProxyTest::HapUninstall( + const std::string &bundleName, const std::string &modulePackage, std::vector &resvec) +{ + sptr installerProxy = GetInstallerProxy(); + if (!installerProxy) { + resvec.push_back(ERROR_UNINSTALL_FAILED); + return; + } + + if (bundleName.empty()) { + resvec.push_back(ERROR_UNINSTALL_FAILED); + } else { + InstallParam installParam; + installParam.userId = Constants::DEFAULT_USERID; + sptr statusReceiver = (new (std::nothrow) StatusReceiverImpl()); + installerProxy->Uninstall(bundleName, modulePackage, installParam, statusReceiver); + resvec.push_back(statusReceiver->GetResultMsg()); + } +} + +sptr BundleMgrProxyTest::GetBundleMgrProxy() +{ + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + return nullptr; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (!remoteObject) { + return nullptr; + } + + return iface_cast(remoteObject); +} + +sptr BundleMgrProxyTest::GetInstallerProxy() +{ + sptr bundleMgrProxy = GetBundleMgrProxy(); + if (!bundleMgrProxy) { + return nullptr; + } + + sptr installerProxy = bundleMgrProxy->GetBundleInstaller(); + if (!installerProxy) { + return nullptr; + } + + return installerProxy; +} + +void BundleMgrProxyTest::CheckFileExist(const std::string &bundleName) const +{} + +void BundleMgrProxyTest::CheckFileExist(const std::string &bundleName, const std::string &modulePackage) const +{} + +void BundleMgrProxyTest::CheckFileNonExist(const std::string &bundleName) const +{} + +void BundleMgrProxyTest::CheckFileNonExist(const std::string &bundleName, const std::string &modulePackage) const +{} + +void BundleMgrProxyTest::CheckBundleInfo(const uint32_t index, BundleInfo &bundleInfo) const +{} + +void BundleMgrProxyTest::CreateDir(const std::string &path) const +{} + +/** + * @tc.name: BenchmarkTestGetApplicationInfo + * @tc.desc: Testcase for testing GetApplicationInfo. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetApplicationInfoByFlag(benchmark::State &state) +{ + int userId = Constants::DEFAULT_USERID; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + ApplicationInfo appInfo; + appInfo.name = "com.ohos.contactsdataability"; + appInfo.bundleName = "com.ohos.contactsdataability"; + appInfo.versionName = "1.0"; + appInfo.iconPath = "$media:icon"; + appInfo.description = "dataability_description"; + appInfo.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"; + appInfo.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability"; + appInfo.apiReleaseType = "Release"; + appInfo.deviceId = "PHONE-001"; + appInfo.entityType = "unsppecified"; + appInfo.vendor = "ohos"; + appInfo.nativeLibraryPath = "libs/arm"; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetApplicationInfo(bundleName, ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, appInfo); + } +} + +/** + * @tc.name: BenchmarkTestGetApplicationInfo + * @tc.desc: Testcase for testing GetApplicationInfo. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetApplicationInfoByUserId(benchmark::State &state) +{ + int userId = Constants::DEFAULT_USERID; + int32_t flags = 0; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + ApplicationInfo appInfo; + appInfo.name = "com.ohos.contactsdataability"; + appInfo.bundleName = "com.ohos.contactsdataability"; + appInfo.versionName = "1.0"; + appInfo.iconPath = "$media:icon"; + appInfo.description = "dataability_description"; + appInfo.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"; + appInfo.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability"; + appInfo.apiReleaseType = "Release"; + appInfo.deviceId = "PHONE-001"; + appInfo.entityType = "unsppecified"; + appInfo.vendor = "ohos"; + appInfo.nativeLibraryPath = "libs/arm"; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetApplicationInfo(bundleName, flags, userId, appInfo); + } +} + +/** + * @tc.name: BenchmarkTestGetApplicationInfosByApplicationFlag + * @tc.desc: Testcase for testing GetApplicationInfos. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetApplicationInfosByApplicationFlag(benchmark::State &state) +{ + int userId = Constants::DEFAULT_USERID; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::vector appInfos; + ApplicationInfo appInfo; + appInfo.name = "com.ohos.contactsdataability"; + appInfo.bundleName = "com.ohos.contactsdataability"; + appInfo.versionName = "1.0"; + appInfo.iconPath = "$media:icon"; + appInfo.description = "dataability_description"; + appInfo.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"; + appInfo.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability"; + appInfo.apiReleaseType = "Release"; + appInfo.deviceId = "PHONE-001"; + appInfo.entityType = "unsppecified"; + appInfo.vendor = "ohos"; + appInfo.nativeLibraryPath = "libs/arm"; + appInfos.push_back(appInfo); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetApplicationInfos(ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION, userId, appInfos); + } +} + +/** + * @tc.name: BenchmarkTestGetApplicationInfosByFlags + * @tc.desc: Testcase for testing GetApplicationInfos. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetApplicationInfosByFlags(benchmark::State &state) +{ + int userId = Constants::DEFAULT_USERID; + int32_t flags = 0; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::vector appInfos; + ApplicationInfo appInfo; + appInfo.name = "com.ohos.contactsdataability"; + appInfo.bundleName = "com.ohos.contactsdataability"; + appInfo.versionName = "1.0"; + appInfo.iconPath = "$media:icon"; + appInfo.description = "dataability_description"; + appInfo.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"; + appInfo.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability"; + appInfo.apiReleaseType = "Release"; + appInfo.deviceId = "PHONE-001"; + appInfo.entityType = "unsppecified"; + appInfo.vendor = "ohos"; + appInfo.nativeLibraryPath = "libs/arm"; + appInfos.push_back(appInfo); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetApplicationInfos(flags, userId, appInfos); + } +} + +/** + * @tc.name: BenchmarkTestGetBundleInfoByBundleFlag + * @tc.desc: Testcase for testing GetBundleInfo. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetBundleInfoByBundleFlag(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + BundleInfo info; + info.name = "com.ohos.contactsdataability"; + info.versionName = "1.0"; + info.vendor = "ohos"; + info.releaseType = "Release"; + info.mainEntry = "com.ohos.contactsdataability"; + info.entryModuleName = "entry"; + info.appId = "com.ohos.contactsdataability_BNtg4JBClbl92Rgc3jm/RfcAdrHXaM8F0QOiwVEhnV5ebE5jNIYnAx+weFRT3QTyUjRNdhmc2aAzWyi+5t5CoBM="; + info.cpuAbi = "armeabi"; + info.description = "dataability_description"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.bundleName = "com.ohos.contactsdataability"; + info.applicationInfo.versionName = "1.0"; + info.applicationInfo.iconPath = "$media:icon"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"; + info.applicationInfo.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability"; + info.applicationInfo.apiReleaseType = "Release"; + info.applicationInfo.deviceId = "PHONE-001"; + info.applicationInfo.entityType = "unsppecified"; + info.applicationInfo.vendor = "ohos"; + info.applicationInfo.nativeLibraryPath = "libs/arm"; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetBundleInfo(bundleName, BundleFlag::GET_BUNDLE_DEFAULT, info); + } +} + +/** + * @tc.name: BenchmarkTestGetBundleInfoByFlags + * @tc.desc: Testcase for testing GetBundleInfo. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetBundleInfoByFlags(benchmark::State &state) +{ + int32_t flags = 0; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + BundleInfo info; + info.name = "com.ohos.contactsdataability"; + info.versionName = "1.0"; + info.vendor = "ohos"; + info.releaseType = "Release"; + info.mainEntry = "com.ohos.contactsdataability"; + info.entryModuleName = "entry"; + info.appId = "com.ohos.contactsdataability_BNtg4JBClbl92Rgc3jm/RfcAdrHXaM8F0QOiwVEhnV5ebE5jNIYnAx+weFRT3QTyUjRNdhmc2aAzWyi+5t5CoBM="; + info.cpuAbi = "armeabi"; + info.description = "dataability_description"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.bundleName = "com.ohos.contactsdataability"; + info.applicationInfo.versionName = "1.0"; + info.applicationInfo.iconPath = "$media:icon"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"; + info.applicationInfo.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability"; + info.applicationInfo.apiReleaseType = "Release"; + info.applicationInfo.deviceId = "PHONE-001"; + info.applicationInfo.entityType = "unsppecified"; + info.applicationInfo.vendor = "ohos"; + info.applicationInfo.nativeLibraryPath = "libs/arm"; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetBundleInfo(bundleName, flags, info); + } +} + +/** + * @tc.name: BenchmarkTestGetBundleInfosByBundleFlag + * @tc.desc: Testcase for testing GetBundleInfos. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetBundleInfosByBundleFlag(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::vector bundleInfos; + BundleInfo info; + info.name = "com.ohos.contactsdataability"; + info.versionName = "1.0"; + info.vendor = "ohos"; + info.releaseType = "Release"; + info.mainEntry = "com.ohos.contactsdataability"; + info.entryModuleName = "entry"; + info.appId = "com.ohos.contactsdataability_BNtg4JBClbl92Rgc3jm/RfcAdrHXaM8F0QOiwVEhnV5ebE5jNIYnAx+weFRT3QTyUjRNdhmc2aAzWyi+5t5CoBM="; + info.cpuAbi = "armeabi"; + info.description = "dataability_description"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.bundleName = "com.ohos.contactsdataability"; + info.applicationInfo.versionName = "1.0"; + info.applicationInfo.iconPath = "$media:icon"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"; + info.applicationInfo.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability"; + info.applicationInfo.apiReleaseType = "Release"; + info.applicationInfo.deviceId = "PHONE-001"; + info.applicationInfo.entityType = "unsppecified"; + info.applicationInfo.vendor = "ohos"; + info.applicationInfo.nativeLibraryPath = "libs/arm"; + bundleInfos.push_back(info); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetBundleInfos(BundleFlag::GET_BUNDLE_DEFAULT, bundleInfos); + } +} + +/** + * @tc.name: BenchmarkTestGetBundleInfosByFlags + * @tc.desc: Testcase for testing GetBundleInfos. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetBundleInfosByFlags(benchmark::State &state) +{ + int32_t flags = 0; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::vector bundleInfos; + BundleInfo info; + info.name = "com.ohos.contactsdataability"; + info.versionName = "1.0"; + info.vendor = "ohos"; + info.releaseType = "Release"; + info.mainEntry = "com.ohos.contactsdataability"; + info.entryModuleName = "entry"; + info.appId = "com.ohos.contactsdataability_BNtg4JBClbl92Rgc3jm/RfcAdrHXaM8F0QOiwVEhnV5ebE5jNIYnAx+weFRT3QTyUjRNdhmc2aAzWyi+5t5CoBM="; + info.cpuAbi = "armeabi"; + info.description = "dataability_description"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.bundleName = "com.ohos.contactsdataability"; + info.applicationInfo.versionName = "1.0"; + info.applicationInfo.iconPath = "$media:icon"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"; + info.applicationInfo.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability"; + info.applicationInfo.apiReleaseType = "Release"; + info.applicationInfo.deviceId = "PHONE-001"; + info.applicationInfo.entityType = "unsppecified"; + info.applicationInfo.vendor = "ohos"; + info.applicationInfo.nativeLibraryPath = "libs/arm"; + bundleInfos.push_back(info); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetBundleInfos(flags, bundleInfos); + } +} + +/** + * @tc.name: BenchmarkTestGetUidByBundleName + * @tc.desc: Obtains the application ID based on the given bundle name and user ID. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetUidByBundleName(benchmark::State &state) +{ + int userId = Constants::DEFAULT_USERID; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetUidByBundleName(bundleName, userId); + } +} + +/** + * @tc.name: BenchmarkTestGetAppIdByBundleName + * @tc.desc: Obtains the application ID based on the given bundle name and user ID. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetAppIdByBundleName(benchmark::State &state) +{ + int userId = Constants::DEFAULT_USERID; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetAppIdByBundleName(bundleName, userId); + } +} + +/** + * @tc.name: BenchmarkTestGetBundleNameForUid + * @tc.desc: Testcase for testing GetBundleNameForUid. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetBundleNameForUid(benchmark::State &state) +{ + int uid = Constants::INVALID_UID; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::string bundleName = "com.ohos.contactsdataability"; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetBundleNameForUid(uid, bundleName); + } +} + +/** + * @tc.name: BenchmarkTestGetBundlesForUid + * @tc.desc: Testcase for testing GetBundlesForUid. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetBundlesForUid(benchmark::State &state) +{ + int uid = Constants::INVALID_UID; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::vector bundleNames; + bundleNames.push_back(bundleName); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetBundlesForUid(uid, bundleNames); + } +} + +/** + * @tc.name: BenchmarkTestGetNameForUid + * @tc.desc: Testcase for testing GetNameForUid. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetNameForUid(benchmark::State &state) +{ + int uid = Constants::INVALID_UID; + std::string name; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetNameForUid(uid, name); + } +} + +/** + * @tc.name: BenchmarkTestGetAppType + * @tc.desc: Testcase for testing GetAppType. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetAppType(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetAppType(SYSTEM_SETTINGS_BUNDLE_NAME); + } +} + +/** + * @tc.name: BenchmarkTestCheckIsSystemAppByUid + * @tc.desc: Testcase for testing CheckIsSystemAppByUid. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestCheckIsSystemAppByUid(benchmark::State &state) +{ + int uid = Constants::DEFAULT_USERID; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->CheckIsSystemAppByUid(uid); + } +} + +/** + * @tc.name: BenchmarkTestGetBundleInfosByMetaData + * @tc.desc: Testcase for testing GetBundleInfosByMetaData. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetBundleInfosByMetaData(benchmark::State &state) +{ + std::vector bundleInfos; + BundleInfo info; + info.name = "com.ohos.contactsdataability"; + info.versionName = "1.0"; + info.vendor = "ohos"; + info.releaseType = "Release"; + info.mainEntry = "com.ohos.contactsdataability"; + info.entryModuleName = "entry"; + info.appId = "com.ohos.contactsdataability_BNtg4JBClbl92Rgc3jm/RfcAdrHXaM8F0QOiwVEhnV5ebE5jNIYnAx+weFRT3QTyUjRNdhmc2aAzWyi+5t5CoBM="; + info.cpuAbi = "armeabi"; + info.description = "dataability_description"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.bundleName = "com.ohos.contactsdataability"; + info.applicationInfo.versionName = "1.0"; + info.applicationInfo.iconPath = "$media:icon"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"; + info.applicationInfo.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability"; + info.applicationInfo.apiReleaseType = "Release"; + info.applicationInfo.deviceId = "PHONE-001"; + info.applicationInfo.entityType = "unsppecified"; + info.applicationInfo.vendor = "ohos"; + info.applicationInfo.nativeLibraryPath = "libs/arm"; + bundleInfos.push_back(info); + std::string metadata = "string"; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetBundleInfosByMetaData(metadata, bundleInfos); + } +} + +/** + * @tc.name: BenchmarkTestQueryAbilityInfo + * @tc.desc: Testcase for testing QueryAbilityInfo. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestQueryAbilityInfo(benchmark::State &state) +{ + Want want; + ElementName name; + name.SetAbilityName(abilityName); + name.SetBundleName(bundleName); + want.SetElement(name); + + AbilityInfo info; + info.name = "allLogAbility"; + info.description = "dataability_description"; + info.iconPath = "$media:icon"; + info.labelId = 0; + info.descriptionId = 0; + info.iconId = 0; + info.kind = "data"; + info.deviceTypes = {"smartVision"}; + info.uri = "dataability://com.ohos.callogability"; + info.readPermission = "ohos.permission.READ_CALL_LOG"; + info.writePermission = "ohos.permission.WRITE_CALL_LOG"; + info.package = "com.ohos.contactsdataability"; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.applicationName = "com.ohos.contactsdataability"; + info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability/com.ohos.contactsdataability/assets/entry/resources.index"; + info.versionName = "1.0"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.cpuAbi = "armeabi"; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->QueryAbilityInfo(want, info); + } +} + +/** + * @tc.name: BenchmarkTestQueryAbilityInfoByFlags + * @tc.desc: Testcase for testing QueryAbilityInfo. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestQueryAbilityInfoByFlags(benchmark::State &state) +{ + Want want; + ElementName name; + name.SetAbilityName(abilityName); + name.SetBundleName(bundleName); + want.SetElement(name); + + AbilityInfo info; + info.name = "allLogAbility"; + info.description = "dataability_description"; + info.iconPath = "$media:icon"; + info.labelId = 0; + info.descriptionId = 0; + info.iconId = 0; + info.kind = "data"; + info.deviceTypes = {"smartVision"}; + info.uri = "dataability://com.ohos.callogability"; + info.readPermission = "ohos.permission.READ_CALL_LOG"; + info.writePermission = "ohos.permission.WRITE_CALL_LOG"; + info.package = "com.ohos.contactsdataability"; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.applicationName = "com.ohos.contactsdataability"; + info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability/com.ohos.contactsdataability/assets/entry/resources.index"; + info.versionName = "1.0"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.cpuAbi = "armeabi"; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->QueryAbilityInfo(want, 0, 0, info); + } +} + +/** + * @tc.name: BenchmarkTestQueryAbilityInfos + * @tc.desc: Testcase for testing QueryAbilityInfos. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestQueryAbilityInfos(benchmark::State &state) +{ + Want want; + ElementName name; + name.SetAbilityName(abilityName); + name.SetBundleName(bundleName); + want.SetElement(name); + + std::vector abilityInfos; + AbilityInfo info; + info.name = "allLogAbility"; + info.description = "dataability_description"; + info.iconPath = "$media:icon"; + info.labelId = 0; + info.descriptionId = 0; + info.iconId = 0; + info.kind = "data"; + info.deviceTypes = {"smartVision"}; + info.uri = "dataability://com.ohos.callogability"; + info.readPermission = "ohos.permission.READ_CALL_LOG"; + info.writePermission = "ohos.permission.WRITE_CALL_LOG"; + info.package = "com.ohos.contactsdataability"; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.applicationName = "com.ohos.contactsdataability"; + info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability/com.ohos.contactsdataability/assets/entry/resources.index"; + info.versionName = "1.0"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.cpuAbi = "armeabi"; + abilityInfos.push_back(info); + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->QueryAbilityInfos(want, abilityInfos); + } +} + +/** + * @tc.name: BenchmarkTestQueryAbilityInfosByFlags + * @tc.desc: Testcase for testing QueryAbilityInfos. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestQueryAbilityInfosByFlags(benchmark::State &state) +{ + Want want; + ElementName name; + name.SetAbilityName(abilityName); + name.SetBundleName(bundleName); + want.SetElement(name); + + std::vector abilityInfos; + AbilityInfo info; + info.name = "allLogAbility"; + info.description = "dataability_description"; + info.iconPath = "$media:icon"; + info.labelId = 0; + info.descriptionId = 0; + info.iconId = 0; + info.kind = "data"; + info.deviceTypes = {"smartVision"}; + info.uri = "dataability://com.ohos.callogability"; + info.readPermission = "ohos.permission.READ_CALL_LOG"; + info.writePermission = "ohos.permission.WRITE_CALL_LOG"; + info.package = "com.ohos.contactsdataability"; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.applicationName = "com.ohos.contactsdataability"; + info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability/com.ohos.contactsdataability/assets/entry/resources.index"; + info.versionName = "1.0"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.cpuAbi = "armeabi"; + abilityInfos.push_back(info); + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->QueryAbilityInfos(want, 0, 0, abilityInfos); + } +} + +/** + * @tc.name: BenchmarkTestQueryAbilityInfosForClone + * @tc.desc: Testcase for testing QueryAbilityInfosForClone. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestQueryAbilityInfosForClone(benchmark::State &state) +{ + Want want; + ElementName name; + name.SetAbilityName(abilityName); + name.SetBundleName(bundleName); + want.SetElement(name); + + std::vector abilityInfos; + AbilityInfo info; + info.name = "allLogAbility"; + info.description = "dataability_description"; + info.iconPath = "$media:icon"; + info.labelId = 0; + info.descriptionId = 0; + info.iconId = 0; + info.kind = "data"; + info.deviceTypes = {"smartVision"}; + info.uri = "dataability://com.ohos.callogability"; + info.readPermission = "ohos.permission.READ_CALL_LOG"; + info.writePermission = "ohos.permission.WRITE_CALL_LOG"; + info.package = "com.ohos.contactsdataability"; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.applicationName = "com.ohos.contactsdataability"; + info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability/com.ohos.contactsdataability/assets/entry/resources.index"; + info.versionName = "1.0"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.cpuAbi = "armeabi"; + abilityInfos.push_back(info); + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->QueryAbilityInfosForClone(want, abilityInfos); + } +} + +/** + * @tc.name: BenchmarkTestQueryAbilityInfosById + * @tc.desc: Testcase for testing QueryAllAbilityInfos. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestQueryAbilityInfosById(benchmark::State &state) +{ + Want want; + ElementName name; + name.SetAbilityName(abilityName); + name.SetBundleName(bundleName); + want.SetElement(name); + + std::vector abilityInfos; + AbilityInfo info; + info.name = "allLogAbility"; + info.description = "dataability_description"; + info.iconPath = "$media:icon"; + info.labelId = 0; + info.descriptionId = 0; + info.iconId = 0; + info.kind = "data"; + info.deviceTypes = {"smartVision"}; + info.uri = "dataability://com.ohos.callogability"; + info.readPermission = "ohos.permission.READ_CALL_LOG"; + info.writePermission = "ohos.permission.WRITE_CALL_LOG"; + info.package = "com.ohos.contactsdataability"; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.applicationName = "com.ohos.contactsdataability"; + info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability/com.ohos.contactsdataability/assets/entry/resources.index"; + info.versionName = "1.0"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.cpuAbi = "armeabi"; + abilityInfos.push_back(info); + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->QueryAllAbilityInfos(want, 0, abilityInfos); + } +} + +/** + * @tc.name: BenchmarkTestQueryAbilityInfoByUri + * @tc.desc: Testcase for testing QueryAbilityInfoByUri. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestQueryAbilityInfoByUri(benchmark::State &state) +{ + std::string abilityUri = "err://com.test.demo.weatherfa.UserADataAbility"; + AbilityInfo info; + info.name = "allLogAbility"; + info.description = "dataability_description"; + info.iconPath = "$media:icon"; + info.labelId = 0; + info.descriptionId = 0; + info.iconId = 0; + info.kind = "data"; + info.deviceTypes = {"smartVision"}; + info.uri = "dataability://com.ohos.callogability"; + info.readPermission = "ohos.permission.READ_CALL_LOG"; + info.writePermission = "ohos.permission.WRITE_CALL_LOG"; + info.package = "com.ohos.contactsdataability"; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.applicationName = "com.ohos.contactsdataability"; + info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability/com.ohos.contactsdataability/assets/entry/resources.index"; + info.versionName = "1.0"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.cpuAbi = "armeabi"; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->QueryAbilityInfoByUri(abilityUri, info); + } +} + +/** + * @tc.name: BenchmarkTestQueryAbilityInfoByUriAndId + * @tc.desc: Testcase for testing QueryAbilityInfoByUri. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestQueryAbilityInfoByUriAndId(benchmark::State &state) +{ + std::string abilityUri = "err://com.test.demo.weatherfa.UserADataAbility"; + AbilityInfo info; + info.name = "allLogAbility"; + info.description = "dataability_description"; + info.iconPath = "$media:icon"; + info.labelId = 0; + info.descriptionId = 0; + info.iconId = 0; + info.kind = "data"; + info.deviceTypes = {"smartVision"}; + info.uri = "dataability://com.ohos.callogability"; + info.readPermission = "ohos.permission.READ_CALL_LOG"; + info.writePermission = "ohos.permission.WRITE_CALL_LOG"; + info.package = "com.ohos.contactsdataability"; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.applicationName = "com.ohos.contactsdataability"; + info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability/com.ohos.contactsdataability/assets/entry/resources.index"; + info.versionName = "1.0"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.cpuAbi = "armeabi"; + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->QueryAbilityInfoByUri(abilityUri, 0, info); + } +} + +/** + * @tc.name: BenchmarkTestQueryAbilityInfosByUri + * @tc.desc: Testcase for testing QueryAbilityInfosByUri. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestQueryAbilityInfosByUri(benchmark::State &state) +{ + std::string abilityUri = "err://com.test.demo.weatherfa.UserADataAbility"; + std::vector abilityInfos; + AbilityInfo info; + info.name = "allLogAbility"; + info.description = "dataability_description"; + info.iconPath = "$media:icon"; + info.labelId = 0; + info.descriptionId = 0; + info.iconId = 0; + info.kind = "data"; + info.deviceTypes = {"smartVision"}; + info.uri = "dataability://com.ohos.callogability"; + info.readPermission = "ohos.permission.READ_CALL_LOG"; + info.writePermission = "ohos.permission.WRITE_CALL_LOG"; + info.package = "com.ohos.contactsdataability"; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.applicationName = "com.ohos.contactsdataability"; + info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability/com.ohos.contactsdataability/assets/entry/resources.index"; + info.versionName = "1.0"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.cpuAbi = "armeabi"; + abilityInfos.push_back(info); + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->QueryAbilityInfosByUri(abilityUri, abilityInfos); + } +} + +/** + * @tc.name: BenchmarkTestQueryKeepAliveBundleInfos + * @tc.desc: Testcase for testing QueryKeepAliveBundleInfos. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestQueryKeepAliveBundleInfos(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::vector bundleInfos; + BundleInfo info; + info.name = "com.ohos.contactsdataability"; + info.versionName = "1.0"; + info.vendor = "ohos"; + info.releaseType = "Release"; + info.mainEntry = "com.ohos.contactsdataability"; + info.entryModuleName = "entry"; + info.appId = "com.ohos.contactsdataability_BNtg4JBClbl92Rgc3jm/RfcAdrHXaM8F0QOiwVEhnV5ebE5jNIYnAx+weFRT3QTyUjRNdhmc2aAzWyi+5t5CoBM="; + info.cpuAbi = "armeabi"; + info.description = "dataability_description"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.bundleName = "com.ohos.contactsdataability"; + info.applicationInfo.versionName = "1.0"; + info.applicationInfo.iconPath = "$media:icon"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"; + info.applicationInfo.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability"; + info.applicationInfo.apiReleaseType = "Release"; + info.applicationInfo.deviceId = "PHONE-001"; + info.applicationInfo.entityType = "unsppecified"; + info.applicationInfo.vendor = "ohos"; + info.applicationInfo.nativeLibraryPath = "libs/arm"; + bundleInfos.push_back(info); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->QueryKeepAliveBundleInfos(bundleInfos); + } +} + +/** + * @tc.name: BenchmarkTestGetAbilityLabel + * @tc.desc: Testcase for testing GetAbilityLabel. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetAbilityLabel(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetAbilityLabel(bundleName, abilityName); + } +} + +/** + * @tc.name: BenchmarkTestGetBundleArchiveInfo + * @tc.desc: Testcase for testing GetBundleArchiveInfo. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetBundleArchiveInfo(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + BundleInfo info; + info.name = "com.ohos.contactsdataability"; + info.versionName = "1.0"; + info.vendor = "ohos"; + info.releaseType = "Release"; + info.mainEntry = "com.ohos.contactsdataability"; + info.entryModuleName = "entry"; + info.appId = "com.ohos.contactsdataability_BNtg4JBClbl92Rgc3jm/RfcAdrHXaM8F0QOiwVEhnV5ebE5jNIYnAx+weFRT3QTyUjRNdhmc2aAzWyi+5t5CoBM="; + info.cpuAbi = "armeabi"; + info.description = "dataability_description"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.bundleName = "com.ohos.contactsdataability"; + info.applicationInfo.versionName = "1.0"; + info.applicationInfo.iconPath = "$media:icon"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"; + info.applicationInfo.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability"; + info.applicationInfo.apiReleaseType = "Release"; + info.applicationInfo.deviceId = "PHONE-001"; + info.applicationInfo.entityType = "unsppecified"; + info.applicationInfo.vendor = "ohos"; + info.applicationInfo.nativeLibraryPath = "libs/arm"; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetBundleArchiveInfo(hapFilePath, 0, info); + } +} + +/** + * @tc.name: BenchmarkTestGetBundleArchiveInfoByFlag + * @tc.desc: Testcase for testing GetBundleArchiveInfo. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetBundleArchiveInfoByFlag(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + BundleInfo info; + info.name = "com.ohos.contactsdataability"; + info.versionName = "1.0"; + info.vendor = "ohos"; + info.releaseType = "Release"; + info.mainEntry = "com.ohos.contactsdataability"; + info.entryModuleName = "entry"; + info.appId = "com.ohos.contactsdataability_BNtg4JBClbl92Rgc3jm/RfcAdrHXaM8F0QOiwVEhnV5ebE5jNIYnAx+weFRT3QTyUjRNdhmc2aAzWyi+5t5CoBM="; + info.cpuAbi = "armeabi"; + info.description = "dataability_description"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.bundleName = "com.ohos.contactsdataability"; + info.applicationInfo.versionName = "1.0"; + info.applicationInfo.iconPath = "$media:icon"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"; + info.applicationInfo.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability"; + info.applicationInfo.apiReleaseType = "Release"; + info.applicationInfo.deviceId = "PHONE-001"; + info.applicationInfo.entityType = "unsppecified"; + info.applicationInfo.vendor = "ohos"; + info.applicationInfo.nativeLibraryPath = "libs/arm"; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetBundleArchiveInfo(hapFilePath, BundleFlag::GET_BUNDLE_DEFAULT, info); + } +} + +/** + * @tc.name: BenchmarkTestGetLaunchWantForBundle + * @tc.desc: Testcase for testing GetLaunchWantForBundle. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetLaunchWantForBundle(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + Want want; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetLaunchWantForBundle(bundleName, want); + } +} + +/** + * @tc.name: BenchmarkTestCheckPermission + * @tc.desc: Testcase for testing CheckPermission. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestCheckPermission(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::string permission; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->CheckPermission(bundleName, permission); + } +} + +/** + * @tc.name: BenchmarkTestCheckPermissionByUid + * @tc.desc: Testcase for testing CheckPermissionByUid. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestCheckPermissionByUid(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::string permission; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->CheckPermissionByUid(bundleName, permission, Constants::DEFAULT_USERID); + } +} + +/** + * @tc.name: BenchmarkTestGetAllPermissionGroupDefs + * @tc.desc: Testcase for testing GetAllPermissionGroupDefs. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetAllPermissionGroupDefs(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::vector permissionDefs; + PermissionDef info; + info.bundleName = "com.ohos.contactsdataability"; + info.description = "dataability_description"; + permissionDefs.push_back(info); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetAllPermissionGroupDefs(permissionDefs); + } +} + +/** + * @tc.name: BenchmarkTestGetPermissionDef + * @tc.desc: Testcase for testing GetPermissionDef. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetPermissionDef(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::string permissionName; + PermissionDef info; + info.bundleName = "com.ohos.contactsdataability"; + info.description = "dataability_description"; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetPermissionDef(permissionName, info); + } +} + +/** + * @tc.name: BenchmarkTestHasSystemCapability + * @tc.desc: Testcase for testing HasSystemCapability. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestHasSystemCapability(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->HasSystemCapability(abilityName); + } +} + +/** + * @tc.name: BenchmarkTestGetSystemAvailableCapabilities + * @tc.desc: Testcase for testing GetSystemAvailableCapabilities. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetSystemAvailableCapabilities(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::vector systemCaps = {"bmsSystemBundle_A1"}; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetSystemAvailableCapabilities(systemCaps); + } +} + +/** + * @tc.name: BenchmarkTestIsSafeMode + * @tc.desc: Testcase for testing IsSafeMode. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestIsSafeMode(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->IsSafeMode(); + } +} + +/** + * @tc.name: BenchmarkTestCleanBundleDataFiles + * @tc.desc: Testcase for testing CleanBundleDataFiles. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestCleanBundleDataFiles(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->CleanBundleDataFiles(bundleName, 0); + } +} + +/** + * @tc.name: BenchmarkTestRegisterBundleStatusCallback + * @tc.desc: Testcase for testing RegisterBundleStatusCallback. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestRegisterBundleStatusCallback(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + sptr bundleStatusCallback = (new (std::nothrow) BundleStatusCallbackImpl()); + bundleStatusCallback->SetBundleName(bundleName); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->RegisterBundleStatusCallback(bundleStatusCallback); + } +} + +/** + * @tc.name: BenchmarkTestClearBundleStatusCallback + * @tc.desc: Testcase for testing ClearBundleStatusCallback. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestClearBundleStatusCallback(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + sptr bundleStatusCallback = (new (std::nothrow) BundleStatusCallbackImpl()); + bundleStatusCallback->SetBundleName(bundleName); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->ClearBundleStatusCallback(bundleStatusCallback); + } +} + +/** + * @tc.name: BenchmarkTestUnregisterBundleStatusCallback + * @tc.desc: Testcase for testing UnregisterBundleStatusCallback. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestUnregisterBundleStatusCallback(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->UnregisterBundleStatusCallback(); + } +} + +/** + * @tc.name: BenchmarkTestDumpInfos + * @tc.desc: Testcase for testing DumpInfos. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestDumpInfos(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + const std::string EMPTY_STRING = ""; + std::string allInfoResult; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->DumpInfos( + DumpFlag::DUMP_ALL_BUNDLE_INFO, EMPTY_STRING, DEFAULT_USERID, allInfoResult); + } +} + +/** + * @tc.name: BenchmarkTestIsApplicationEnabled + * @tc.desc: Testcase for testing IsApplicationEnabled. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestIsApplicationEnabled(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->IsApplicationEnabled(bundleName); + } +} + +/** + * @tc.name: BenchmarkTestSetApplicationEnabled + * @tc.desc: Testcase for testing SetApplicationEnabled. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestSetApplicationEnabled(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->SetApplicationEnabled(bundleName, false); + } +} + +/** + * @tc.name: BenchmarkTestIsAbilityEnabled + * @tc.desc: Testcase for testing IsAbilityEnabled. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestIsAbilityEnabled(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + AbilityInfo info; + info.name = "allLogAbility"; + info.description = "dataability_description"; + info.iconPath = "$media:icon"; + info.labelId = 0; + info.descriptionId = 0; + info.iconId = 0; + info.kind = "data"; + info.deviceTypes = {"smartVision"}; + info.uri = "dataability://com.ohos.callogability"; + info.readPermission = "ohos.permission.READ_CALL_LOG"; + info.writePermission = "ohos.permission.WRITE_CALL_LOG"; + info.package = "com.ohos.contactsdataability"; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.applicationName = "com.ohos.contactsdataability"; + info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability/com.ohos.contactsdataability/assets/entry/resources.index"; + info.versionName = "1.0"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.cpuAbi = "armeabi"; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->IsAbilityEnabled(info); + } +} + +/** + * @tc.name: BenchmarkTestSetAbilityEnabled + * @tc.desc: Testcase for testing SetAbilityEnabled. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestSetAbilityEnabled(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + AbilityInfo info; + info.name = "allLogAbility"; + info.description = "dataability_description"; + info.iconPath = "$media:icon"; + info.labelId = 0; + info.descriptionId = 0; + info.iconId = 0; + info.kind = "data"; + info.deviceTypes = {"smartVision"}; + info.uri = "dataability://com.ohos.callogability"; + info.readPermission = "ohos.permission.READ_CALL_LOG"; + info.writePermission = "ohos.permission.WRITE_CALL_LOG"; + info.package = "com.ohos.contactsdataability"; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.applicationName = "com.ohos.contactsdataability"; + info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability/com.ohos.contactsdataability/assets/entry/resources.index"; + info.versionName = "1.0"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.cpuAbi = "armeabi"; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->SetAbilityEnabled(info, false); + } +} + +/** + * @tc.name: BenchmarkTestGetAbilityIcon + * @tc.desc: Testcase for testing GetAbilityIcon. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetAbilityIcon(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetAbilityIcon(bundleName, abilityName); + } +} + +/** + * @tc.name: BenchmarkTestGetBundleInstaller + * @tc.desc: Testcase for testing GetBundleInstaller. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetBundleInstaller(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetBundleInstaller(); + } +} + +/** + * @tc.name: BenchmarkTestGetBundleUserMgr + * @tc.desc: Testcase for testing GetBundleUserMgr. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetBundleUserMgr(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetBundleUserMgr(); + } +} + +/** + * @tc.name: BenchmarkTestCanRequestPermission + * @tc.desc: Testcase for testing CanRequestPermission. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestCanRequestPermission(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::string permission; + int userId = Constants::DEFAULT_USERID; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->CanRequestPermission(bundleName, permission, userId); + } +} + +/** + * @tc.name: BenchmarkTestRequestPermissionFromUser + * @tc.desc: Testcase for testing RequestPermissionFromUser. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestRequestPermissionFromUser(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::string permission; + int userId = Constants::DEFAULT_USERID; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->RequestPermissionFromUser(bundleName, permission, userId); + } +} + +/** + * @tc.name: BenchmarkTestRegisterAllPermissionsChanged + * @tc.desc: Testcase for testing RegisterAllPermissionsChanged. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestRegisterAllPermissionsChanged(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + Parcel data; + sptr object = data.ReadParcelable(); + sptr callback = iface_cast(object); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->RegisterAllPermissionsChanged(callback); + } +} + +/** + * @tc.name: BenchmarkTestRegisterPermissionsChanged + * @tc.desc: Testcase for testing RegisterPermissionsChanged. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestRegisterPermissionsChanged(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + Parcel data; + sptr object = data.ReadParcelable(); + sptr callback = iface_cast(object); + std::vector uids; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->RegisterPermissionsChanged(uids, callback); + } +} + +/** + * @tc.name: BenchmarkTestUnregisterPermissionsChanged + * @tc.desc: Testcase for testing UnregisterPermissionsChanged. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestUnregisterPermissionsChanged(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + Parcel data; + sptr object = data.ReadParcelable(); + sptr callback = iface_cast(object); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->UnregisterPermissionsChanged(callback); + } +} + +/** + * @tc.name: BenchmarkTestGetAllFormsInfo + * @tc.desc: Testcase for testing GetAllFormsInfo. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetAllFormsInfo(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::vector formInfos; + FormInfo info; + info.package = "com.ohos.contactsdataability"; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.name = "com.ohos.contactsdataability"; + info.description = "dataability_description"; + formInfos.push_back(info); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetAllFormsInfo(formInfos); + } +} + +/** + * @tc.name: BenchmarkTestGetFormsInfoByApp + * @tc.desc: Testcase for testing GetFormsInfoByApp. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetFormsInfoByApp(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::vector formInfos; + FormInfo info; + info.package = "com.ohos.contactsdataability"; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.name = "com.ohos.contactsdataability"; + info.description = "dataability_description"; + formInfos.push_back(info); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetFormsInfoByApp(bundleName, formInfos); + } +} + +/** + * @tc.name: BenchmarkTestGetFormsInfoByModule + * @tc.desc: Testcase for testing GetFormsInfoByModule. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetFormsInfoByModule(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::vector formInfos; + FormInfo info; + info.package = "com.ohos.contactsdataability"; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.name = "com.ohos.contactsdataability"; + info.description = "dataability_description"; + formInfos.push_back(info); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetFormsInfoByModule(bundleName, MODULE_NAME_TEST, formInfos); + } +} + +/** + * @tc.name: BenchmarkTestGetShortcutInfos + * @tc.desc: Testcase for testing GetShortcutInfos. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetShortcutInfos(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::vector shortcutInfos; + ShortcutInfo info; + info.bundleName = "com.ohos.contactsdataability"; + info.iconId = 0; + info.labelId = 0; + shortcutInfos.push_back(info); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetShortcutInfos(bundleName, shortcutInfos); + } +} + +/** + * @tc.name: BenchmarkTestGetAllCommonEventInfo + * @tc.desc: Testcase for testing GetAllCommonEventInfo. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetAllCommonEventInfo(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::vector commonEventInfos; + CommonEventInfo info; + info.name = "com.ohos.contactsdataability"; + info.bundleName = "com.ohos.contactsdataability"; + commonEventInfos.push_back(info); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetAllCommonEventInfo(COMMON_EVENT_EVENT, commonEventInfos); + } +} + +/** + * @tc.name: BenchmarkTestGetModuleUsageRecords + * @tc.desc: Testcase for testing GetModuleUsageRecords. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetModuleUsageRecords(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::vector moduleUsageRecords; + ModuleUsageRecord info; + info.bundleName = "com.ohos.contactsdataability"; + info.name = "com.ohos.contactsdataability"; + moduleUsageRecords.push_back(info); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetModuleUsageRecords(DEFAULT_USERID, moduleUsageRecords); + } +} + +/** + * @tc.name: BenchmarkTestNotifyAbilityLifeStatus + * @tc.desc: Testcase for testing NotifyAbilityLifeStatus. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestNotifyAbilityLifeStatus(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + int64_t time = + std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->NotifyAbilityLifeStatus(bundleName, abilityName, time, 0); + } +} + +/** + * @tc.name: BenchmarkTestRemoveClonedBundle + * @tc.desc: Testcase for testing RemoveClonedBundle. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestRemoveClonedBundle(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->RemoveClonedBundle(bundleName, DEFAULT_USERID); + } +} + +/** + * @tc.name: BenchmarkTestCheckBundleNameInAllowList + * @tc.desc: Testcase for testing CheckBundleNameInAllowList. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestCheckBundleNameInAllowList(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->CheckBundleNameInAllowList(bundleName); + } +} + +/** + * @tc.name: BenchmarkTestGetDistributedBundleInfo + * @tc.desc: Testcase for testing GetDistributedBundleInfo. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetDistributedBundleInfo(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::string networkId; + DistributedBundleInfo distributedBundleInfo; + distributedBundleInfo.name = "com.ohos.contactsdataability"; + distributedBundleInfo.appId = "com.ohos.contactsdataability_BNtg4JBClbl92Rgc3jm/RfcAdrHXaM8F0QOiwVEhnV5ebE5jNIYnAx+weFRT3QTyUjRNdhmc2aAzWyi+5t5CoBM="; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetDistributedBundleInfo(networkId, DEFAULT_USERID, bundleName, distributedBundleInfo); + } +} + +/** + * @tc.name: BenchmarkTestGetAppPrivilegeLevel + * @tc.desc: Testcase for testing GetAppPrivilegeLevel. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetAppPrivilegeLevel(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetAppPrivilegeLevel(bundleName); + } +} + +/** + * @tc.name: BenchmarkTestQueryExtensionAbilityInfosByWant + * @tc.desc: Testcase for testing QueryExtensionAbilityInfos. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestQueryExtensionAbilityInfosByWant(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + Want want; + ElementName name; + name.SetAbilityName(abilityName); + name.SetBundleName(bundleName); + want.SetElement(name); + int32_t flags = 0; + std::vector infos; + ExtensionAbilityInfo info; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.name = "com.ohos.contactsdataability"; + info.description = "dataability_description"; + info.readPermission = "ohos.permission.READ_CALL_LOG"; + info.writePermission = "ohos.permission.WRITE_CALL_LOG"; + info.uri = "dataability://com.ohos.callogability"; + info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability/com.ohos.contactsdataability/assets/entry/resources.index"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.bundleName = "com.ohos.contactsdataability"; + info.applicationInfo.versionName = "1.0"; + info.applicationInfo.iconPath = "$media:icon"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"; + info.applicationInfo.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability"; + info.applicationInfo.apiReleaseType = "Release"; + info.applicationInfo.deviceId = "PHONE-001"; + info.applicationInfo.entityType = "unsppecified"; + info.applicationInfo.vendor = "ohos"; + info.applicationInfo.nativeLibraryPath = "libs/arm"; + infos.push_back(info); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->QueryExtensionAbilityInfos(want, flags, DEFAULT_USERID, infos); + } +} + +/** + * @tc.name: BenchmarkTestQueryExtensionAbilityInfosByType + * @tc.desc: Testcase for testing QueryExtensionAbilityInfos. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestQueryExtensionAbilityInfosByType(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::vector infos; + ExtensionAbilityInfo info; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.name = "com.ohos.contactsdataability"; + info.description = "dataability_description"; + info.readPermission = "ohos.permission.READ_CALL_LOG"; + info.writePermission = "ohos.permission.WRITE_CALL_LOG"; + info.uri = "dataability://com.ohos.callogability"; + info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability/com.ohos.contactsdataability/assets/entry/resources.index"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.bundleName = "com.ohos.contactsdataability"; + info.applicationInfo.versionName = "1.0"; + info.applicationInfo.iconPath = "$media:icon"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"; + info.applicationInfo.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability"; + info.applicationInfo.apiReleaseType = "Release"; + info.applicationInfo.deviceId = "PHONE-001"; + info.applicationInfo.entityType = "unsppecified"; + info.applicationInfo.vendor = "ohos"; + info.applicationInfo.nativeLibraryPath = "libs/arm"; + infos.push_back(info); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->QueryExtensionAbilityInfos(ExtensionAbilityType::FORM, DEFAULT_USERID, infos); + } +} + +/** + * @tc.name: BenchmarkTestQueryExtensionAbilityInfos + * @tc.desc: Testcase for testing QueryExtensionAbilityInfos. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestQueryExtensionAbilityInfos(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + Want want; + ElementName name; + name.SetAbilityName(abilityName); + name.SetBundleName(bundleName); + want.SetElement(name); + int32_t flags = 0; + std::vector infos; + ExtensionAbilityInfo info; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.name = "com.ohos.contactsdataability"; + info.description = "dataability_description"; + info.readPermission = "ohos.permission.READ_CALL_LOG"; + info.writePermission = "ohos.permission.WRITE_CALL_LOG"; + info.uri = "dataability://com.ohos.callogability"; + info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability/com.ohos.contactsdataability/assets/entry/resources.index"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.bundleName = "com.ohos.contactsdataability"; + info.applicationInfo.versionName = "1.0"; + info.applicationInfo.iconPath = "$media:icon"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"; + info.applicationInfo.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability"; + info.applicationInfo.apiReleaseType = "Release"; + info.applicationInfo.deviceId = "PHONE-001"; + info.applicationInfo.entityType = "unsppecified"; + info.applicationInfo.vendor = "ohos"; + info.applicationInfo.nativeLibraryPath = "libs/arm"; + infos.push_back(info); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->QueryExtensionAbilityInfos(want, ExtensionAbilityType::FORM, flags, DEFAULT_USERID, infos); + } +} + +/** + * @tc.name: BenchmarkTestVerifyCallingPermission + * @tc.desc: Testcase for testing VerifyCallingPermission. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestVerifyCallingPermission(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + std::string appPermission = "USER_GRANT"; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->VerifyCallingPermission(appPermission); + } +} + +/** + * @tc.name: BenchmarkTestGetAccessibleAppCodePaths + * @tc.desc: Testcase for testing GetAccessibleAppCodePaths. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetAccessibleAppCodePaths(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetAccessibleAppCodePaths(DEFAULT_USERID); + } +} + +/** + * @tc.name: BenchmarkTestQueryExtensionAbilityInfoByUri + * @tc.desc: Testcase for testing QueryExtensionAbilityInfoByUri. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestQueryExtensionAbilityInfoByUri(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + ExtensionAbilityInfo info; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.name = "com.ohos.contactsdataability"; + info.description = "dataability_description"; + info.readPermission = "ohos.permission.READ_CALL_LOG"; + info.writePermission = "ohos.permission.WRITE_CALL_LOG"; + info.uri = "dataability://com.ohos.callogability"; + info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability/com.ohos.contactsdataability/assets/entry/resources.index"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.bundleName = "com.ohos.contactsdataability"; + info.applicationInfo.versionName = "1.0"; + info.applicationInfo.iconPath = "$media:icon"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"; + info.applicationInfo.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability"; + info.applicationInfo.apiReleaseType = "Release"; + info.applicationInfo.deviceId = "PHONE-001"; + info.applicationInfo.entityType = "unsppecified"; + info.applicationInfo.vendor = "ohos"; + info.applicationInfo.nativeLibraryPath = "libs/arm"; + const std::string URI = "dataability://com.example.hiworld.himusic.UserADataAbility"; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->QueryExtensionAbilityInfoByUri(URI, DEFAULT_USERID, info); + } +} + +/** + * @tc.name: BenchmarkTestGetAbilityPixelMapIcon + * @tc.desc: Testcase for testing GetAbilityPixelMapIcon. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetAbilityPixelMapIcon(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetAbilityPixelMapIcon(bundleName, abilityName); + } +} + +/** + * @tc.name: BenchmarkTestGetAbilityInfo + * @tc.desc: Testcase for testing GetAbilityInfo. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestGetAbilityInfo(benchmark::State &state) +{ + sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); + AbilityInfo info; + info.name = "allLogAbility"; + info.description = "dataability_description"; + info.iconPath = "$media:icon"; + info.labelId = 0; + info.descriptionId = 0; + info.iconId = 0; + info.kind = "data"; + info.deviceTypes = {"smartVision"}; + info.uri = "dataability://com.ohos.callogability"; + info.readPermission = "ohos.permission.READ_CALL_LOG"; + info.writePermission = "ohos.permission.WRITE_CALL_LOG"; + info.package = "com.ohos.contactsdataability"; + info.bundleName = "com.ohos.contactsdataability"; + info.moduleName = "entry"; + info.applicationName = "com.ohos.contactsdataability"; + info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability/com.ohos.contactsdataability/assets/entry/resources.index"; + info.versionName = "1.0"; + info.applicationInfo.name = "com.ohos.contactsdataability"; + info.applicationInfo.description = "dataability_description"; + info.applicationInfo.cpuAbi = "armeabi"; + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + bundleMgrProxy->GetAbilityInfo(bundleName, abilityName, info); + } +} + +BENCHMARK(BenchmarkTestGetApplicationInfoByFlag)->Iterations(1000); +BENCHMARK(BenchmarkTestGetApplicationInfoByUserId)->Iterations(1000); +BENCHMARK(BenchmarkTestGetApplicationInfosByApplicationFlag)->Iterations(1000); +BENCHMARK(BenchmarkTestGetApplicationInfosByFlags)->Iterations(1000); +BENCHMARK(BenchmarkTestGetBundleInfoByBundleFlag)->Iterations(1000); +BENCHMARK(BenchmarkTestGetBundleInfoByFlags)->Iterations(1000); +BENCHMARK(BenchmarkTestGetBundleInfosByBundleFlag)->Iterations(1000); +BENCHMARK(BenchmarkTestGetBundleInfosByFlags)->Iterations(1000); +BENCHMARK(BenchmarkTestGetUidByBundleName)->Iterations(1000); +BENCHMARK(BenchmarkTestGetAppIdByBundleName)->Iterations(1000); +BENCHMARK(BenchmarkTestGetBundleNameForUid)->Iterations(1000); +BENCHMARK(BenchmarkTestGetBundlesForUid)->Iterations(1000); +BENCHMARK(BenchmarkTestGetNameForUid)->Iterations(1000); +BENCHMARK(BenchmarkTestGetAppType)->Iterations(1000); +BENCHMARK(BenchmarkTestCheckIsSystemAppByUid)->Iterations(1000); +BENCHMARK(BenchmarkTestGetBundleInfosByMetaData)->Iterations(1000); +BENCHMARK(BenchmarkTestQueryAbilityInfo)->Iterations(1000); +BENCHMARK(BenchmarkTestQueryAbilityInfoByFlags)->Iterations(1000); +BENCHMARK(BenchmarkTestQueryAbilityInfos)->Iterations(1000); +BENCHMARK(BenchmarkTestQueryAbilityInfosByFlags)->Iterations(1000); +BENCHMARK(BenchmarkTestQueryAbilityInfosForClone)->Iterations(1000); +BENCHMARK(BenchmarkTestQueryAbilityInfosById)->Iterations(1000); +BENCHMARK(BenchmarkTestQueryAbilityInfoByUriAndId)->Iterations(1000); +BENCHMARK(BenchmarkTestQueryAbilityInfoByUri)->Iterations(1000); +BENCHMARK(BenchmarkTestQueryAbilityInfosByUri)->Iterations(1000); +BENCHMARK(BenchmarkTestQueryKeepAliveBundleInfos)->Iterations(1000); +BENCHMARK(BenchmarkTestGetAbilityLabel)->Iterations(1000); +BENCHMARK(BenchmarkTestGetBundleArchiveInfo)->Iterations(1000); +BENCHMARK(BenchmarkTestGetBundleArchiveInfoByFlag)->Iterations(1000); +BENCHMARK(BenchmarkTestGetLaunchWantForBundle)->Iterations(1000); +BENCHMARK(BenchmarkTestCheckPermission)->Iterations(1000); +BENCHMARK(BenchmarkTestCheckPermissionByUid)->Iterations(1000); +BENCHMARK(BenchmarkTestGetAllPermissionGroupDefs)->Iterations(1000); +BENCHMARK(BenchmarkTestGetPermissionDef)->Iterations(1000); +BENCHMARK(BenchmarkTestHasSystemCapability)->Iterations(1000); +BENCHMARK(BenchmarkTestGetSystemAvailableCapabilities)->Iterations(1000); +BENCHMARK(BenchmarkTestIsSafeMode)->Iterations(1000); +BENCHMARK(BenchmarkTestCleanBundleDataFiles)->Iterations(1000); +BENCHMARK(BenchmarkTestRegisterBundleStatusCallback)->Iterations(1000); +BENCHMARK(BenchmarkTestClearBundleStatusCallback)->Iterations(1000); +BENCHMARK(BenchmarkTestUnregisterBundleStatusCallback)->Iterations(1000); +BENCHMARK(BenchmarkTestDumpInfos)->Iterations(1000); +BENCHMARK(BenchmarkTestIsApplicationEnabled)->Iterations(1000); +BENCHMARK(BenchmarkTestSetApplicationEnabled)->Iterations(1000); +BENCHMARK(BenchmarkTestIsAbilityEnabled)->Iterations(1000); +BENCHMARK(BenchmarkTestSetAbilityEnabled)->Iterations(1000); +BENCHMARK(BenchmarkTestGetAbilityIcon)->Iterations(1000); +BENCHMARK(BenchmarkTestGetBundleInstaller)->Iterations(1000); +BENCHMARK(BenchmarkTestGetBundleUserMgr)->Iterations(1000); +BENCHMARK(BenchmarkTestCanRequestPermission)->Iterations(1000); +BENCHMARK(BenchmarkTestRequestPermissionFromUser)->Iterations(1000); +BENCHMARK(BenchmarkTestRegisterAllPermissionsChanged)->Iterations(1000); +BENCHMARK(BenchmarkTestRegisterPermissionsChanged)->Iterations(1000); +BENCHMARK(BenchmarkTestUnregisterPermissionsChanged)->Iterations(1000); +BENCHMARK(BenchmarkTestGetAllFormsInfo)->Iterations(1000); +BENCHMARK(BenchmarkTestGetFormsInfoByApp)->Iterations(1000); +BENCHMARK(BenchmarkTestGetFormsInfoByModule)->Iterations(1000); +BENCHMARK(BenchmarkTestGetShortcutInfos)->Iterations(1000); +BENCHMARK(BenchmarkTestGetAllCommonEventInfo)->Iterations(1000); +BENCHMARK(BenchmarkTestGetModuleUsageRecords)->Iterations(1000); +BENCHMARK(BenchmarkTestNotifyAbilityLifeStatus)->Iterations(1000); +BENCHMARK(BenchmarkTestRemoveClonedBundle)->Iterations(1000); +BENCHMARK(BenchmarkTestCheckBundleNameInAllowList)->Iterations(1000); +BENCHMARK(BenchmarkTestGetDistributedBundleInfo)->Iterations(1000); +BENCHMARK(BenchmarkTestGetAppPrivilegeLevel)->Iterations(1000); +BENCHMARK(BenchmarkTestQueryExtensionAbilityInfosByWant)->Iterations(1000); +BENCHMARK(BenchmarkTestQueryExtensionAbilityInfos)->Iterations(1000); +BENCHMARK(BenchmarkTestQueryExtensionAbilityInfosByType)->Iterations(1000); +BENCHMARK(BenchmarkTestVerifyCallingPermission)->Iterations(1000); +BENCHMARK(BenchmarkTestGetAccessibleAppCodePaths)->Iterations(1000); +BENCHMARK(BenchmarkTestQueryExtensionAbilityInfoByUri)->Iterations(1000); +BENCHMARK(BenchmarkTestGetAbilityPixelMapIcon)->Iterations(1000); +BENCHMARK(BenchmarkTestGetAbilityInfo)->Iterations(1000); +} // namespace + +BENCHMARK_MAIN(); \ No newline at end of file diff --git a/test/benchmarktest/installer_proxy_test/BUILD.gn b/test/benchmarktest/installer_proxy_test/BUILD.gn new file mode 100644 index 000000000..b6cd5ba39 --- /dev/null +++ b/test/benchmarktest/installer_proxy_test/BUILD.gn @@ -0,0 +1,62 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/appexecfwk/standard/appexecfwk.gni") + +module_output_path = "bundle_framework/benchmark/bundle_framework" + +ohos_benchmarktest("BenchmarkTestInstallerProxy") { + module_out_path = module_output_path + include_dirs = [ "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content/" ] + + sources = [ "installer_proxy_test.cpp" ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + deps = [ + "${common_path}:libappexecfwk_common", + "${innerkits_path}/appexecfwk_base:appexecfwk_base", + "${innerkits_path}/appexecfwk_core:appexecfwk_core", + "${services_path}/test/moduletest/utils:tool_common", + "//foundation/aafwk/standard/interfaces/innerkits/base:base", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//third_party/benchmark:benchmark", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "ces_standard:cesfwk_innerkits", + "ipc:ipc_core", + "utils_base:utils", + ] + resource_config_file = "//foundation/appexecfwk/standard/test/benchmarktest/resource/ohos_test.xml" +} + +group("benchmarktest") { + testonly = true + deps = [] + + deps += [ + # deps file + ":BenchmarkTestInstallerProxy", + ] +} diff --git a/test/benchmarktest/installer_proxy_test/installer_proxy_test.cpp b/test/benchmarktest/installer_proxy_test/installer_proxy_test.cpp new file mode 100644 index 000000000..c5b7bab68 --- /dev/null +++ b/test/benchmarktest/installer_proxy_test/installer_proxy_test.cpp @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "bundle_constants.h" +#include "bundle_installer_interface.h" +#include "bundle_mgr_interface.h" +#include "common_event_manager.h" +#include "common_event_support.h" +#include "common_tool.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" +#include "status_receiver_host.h" + +using namespace testing::ext; +using namespace std::chrono_literals; +using namespace OHOS; +using namespace OHOS::AppExecFwk; +using namespace OHOS::EventFwk; +namespace { +const std::string THIRD_BUNDLE_PATH = "/data/test/benchmark/"; + +class InstallerProxyTest : public StatusReceiverHost { +public: + InstallerProxyTest(); + virtual ~InstallerProxyTest() override; + virtual void OnStatusNotify(const int progress) override; + virtual void OnFinished(const int32_t resultCode, const std::string &resultMsg) override; +}; + +InstallerProxyTest::InstallerProxyTest() +{} + +InstallerProxyTest::~InstallerProxyTest() +{} + +void InstallerProxyTest::OnStatusNotify(const int progress) +{} + +void InstallerProxyTest::OnFinished(const int32_t resultCode, const std::string &resultMsg) +{} + +sptr GetBundleMgrProxy() +{ + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + return nullptr; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (!remoteObject) { + return nullptr; + } + + return iface_cast(remoteObject); +} + +sptr GetInstallerProxy() +{ + sptr bundleMgrProxy = GetBundleMgrProxy(); + if (!bundleMgrProxy) { + return nullptr; + } + + sptr installerProxy = bundleMgrProxy->GetBundleInstaller(); + if (!installerProxy) { + return nullptr; + } + + return installerProxy; +} + +/** + * @tc.name: BenchmarkTestInstallerProxyInfo + * @tc.desc: Testcase for testing Installs an application through the proxy object. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestInstallerProxyInfo(benchmark::State &state) +{ + sptr installerProxy = GetInstallerProxy(); + std::string bundleFilePath = THIRD_BUNDLE_PATH + "test.hap"; + InstallParam installParam; + installParam.installFlag = InstallFlag::REPLACE_EXISTING; + sptr statusReceiver(new (std::nothrow) InstallerProxyTest()); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + installerProxy->Install(bundleFilePath, installParam, statusReceiver); + } +} + +/** + * @tc.name: BenchmarkTestInstallerProxyInfo + * @tc.desc: Testcase for testing Installs multiple haps. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestMultipleInstallerProxyInfo(benchmark::State &state) +{ + sptr installerProxy = GetInstallerProxy(); + std::vector bundleFilePaths; + std::string bundleFilePath = THIRD_BUNDLE_PATH + "test.hap"; + bundleFilePaths.push_back(bundleFilePath); + InstallParam installParam; + installParam.installFlag = InstallFlag::REPLACE_EXISTING; + sptr statusReceiver(new (std::nothrow) InstallerProxyTest()); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + installerProxy->Install(bundleFilePaths, installParam, statusReceiver); + } +} + +/** + * @tc.name: BenchmarkTestInstallerProxyInfo + * @tc.desc: Testcase for testing Uninstalls an application through the proxy object. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + +static void BenchmarkTestUninstallerApplication(benchmark::State &state) +{ + sptr installerProxy = GetInstallerProxy(); + InstallParam installParam; + installParam.installFlag = InstallFlag::REPLACE_EXISTING; + installParam.userId = Constants::DEFAULT_USERID; + sptr statusReceiver = (new (std::nothrow) InstallerProxyTest()); + const std::string bundleName = "com.example.l3jsdemo"; + std::string bundleFilePath = THIRD_BUNDLE_PATH + "test.hap"; + installerProxy->Install(bundleFilePath, installParam, statusReceiver); + for (auto _ : state) { + /* @tc.steps: step1.call ReadFromParcel in loop */ + installerProxy->Uninstall(bundleName, installParam, statusReceiver); + } +} + +BENCHMARK(BenchmarkTestInstallerProxyInfo)->Iterations(1000); +BENCHMARK(BenchmarkTestMultipleInstallerProxyInfo)->Iterations(1000); +BENCHMARK(BenchmarkTestUninstallerApplication)->Iterations(1000); +} // namespace + +BENCHMARK_MAIN(); \ No newline at end of file diff --git a/test/benchmarktest/resource/benchmarkTestBundle/test.hap b/test/benchmarktest/resource/benchmarkTestBundle/test.hap new file mode 100644 index 000000000..832b4abae Binary files /dev/null and b/test/benchmarktest/resource/benchmarkTestBundle/test.hap differ diff --git a/test/benchmarktest/resource/ohos_test.xml b/test/benchmarktest/resource/ohos_test.xml new file mode 100644 index 000000000..7baf07013 --- /dev/null +++ b/test/benchmarktest/resource/ohos_test.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file