mirror of
https://gitee.com/openharmony/bundlemanager_bundle_framework
synced 2024-11-27 17:30:39 +00:00
add 性能测试用例
Signed-off-by: junyi233 <zhengjun29@huawei.com>
This commit is contained in:
parent
ec63fcc5f3
commit
b2646f1464
@ -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",
|
||||
]
|
||||
}
|
||||
|
60
test/benchmarktest/bundlemgr_proxy_test/BUILD.gn
Normal file
60
test/benchmarktest/bundlemgr_proxy_test/BUILD.gn
Normal file
@ -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",
|
||||
]
|
||||
}
|
2273
test/benchmarktest/bundlemgr_proxy_test/bundlemgr_proxy_test.cpp
Normal file
2273
test/benchmarktest/bundlemgr_proxy_test/bundlemgr_proxy_test.cpp
Normal file
File diff suppressed because it is too large
Load Diff
62
test/benchmarktest/installer_proxy_test/BUILD.gn
Normal file
62
test/benchmarktest/installer_proxy_test/BUILD.gn
Normal file
@ -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",
|
||||
]
|
||||
}
|
160
test/benchmarktest/installer_proxy_test/installer_proxy_test.cpp
Normal file
160
test/benchmarktest/installer_proxy_test/installer_proxy_test.cpp
Normal file
@ -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 <fstream>
|
||||
#include <future>
|
||||
#include <gtest/gtest.h>
|
||||
#include <benchmark/benchmark.h>
|
||||
|
||||
#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<IBundleMgr> GetBundleMgrProxy()
|
||||
{
|
||||
sptr<ISystemAbilityManager> systemAbilityManager =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (!systemAbilityManager) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
|
||||
if (!remoteObject) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return iface_cast<IBundleMgr>(remoteObject);
|
||||
}
|
||||
|
||||
sptr<IBundleInstaller> GetInstallerProxy()
|
||||
{
|
||||
sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
|
||||
if (!bundleMgrProxy) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sptr<IBundleInstaller> 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<IBundleInstaller> installerProxy = GetInstallerProxy();
|
||||
std::string bundleFilePath = THIRD_BUNDLE_PATH + "test.hap";
|
||||
InstallParam installParam;
|
||||
installParam.installFlag = InstallFlag::REPLACE_EXISTING;
|
||||
sptr<InstallerProxyTest> 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<IBundleInstaller> installerProxy = GetInstallerProxy();
|
||||
std::vector<std::string> bundleFilePaths;
|
||||
std::string bundleFilePath = THIRD_BUNDLE_PATH + "test.hap";
|
||||
bundleFilePaths.push_back(bundleFilePath);
|
||||
InstallParam installParam;
|
||||
installParam.installFlag = InstallFlag::REPLACE_EXISTING;
|
||||
sptr<InstallerProxyTest> 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<IBundleInstaller> installerProxy = GetInstallerProxy();
|
||||
InstallParam installParam;
|
||||
installParam.installFlag = InstallFlag::REPLACE_EXISTING;
|
||||
installParam.userId = Constants::DEFAULT_USERID;
|
||||
sptr<InstallerProxyTest> 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();
|
BIN
test/benchmarktest/resource/benchmarkTestBundle/test.hap
Normal file
BIN
test/benchmarktest/resource/benchmarkTestBundle/test.hap
Normal file
Binary file not shown.
8
test/benchmarktest/resource/ohos_test.xml
Normal file
8
test/benchmarktest/resource/ohos_test.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration ver="2.0">
|
||||
<target name="BenchmarkTestInstallerProxy">
|
||||
<preparer>
|
||||
<option name="push" value="benchmarkTestBundle/test.hap -> /data/test/benchmark" src="res"/>
|
||||
</preparer>
|
||||
</target>
|
||||
</configuration>
|
Loading…
Reference in New Issue
Block a user