!574 补充性能测试用例

Merge pull request !574 from 刘水/master
This commit is contained in:
openharmony_ci
2022-05-24 04:20:10 +00:00
committed by Gitee
6 changed files with 560 additions and 0 deletions
+1
View File
@@ -17,6 +17,7 @@ group("test") {
deps = []
if (support_jsapi) {
deps += [
"benchmarktest:benchmarktest",
"fuzztest:fuzztest",
"unittest:unittest",
]
+23
View File
@@ -0,0 +1,23 @@
# 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("//foundation/distributedhardware/devicemanager/devicemanager.gni")
group("benchmarktest") {
testonly = true
deps = [
"device_manager_fa_test:benchmarktest",
"device_manager_test:benchmarktest",
]
}
@@ -0,0 +1,65 @@
# 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/distributedhardware/devicemanager/devicemanager.gni")
module_output_path = "device_manager_base/devicemanager"
ohos_benchmarktest("DeviceManagerFaTest") {
module_out_path = module_output_path
sources = [ "device_manager_fa_test.cpp" ]
include_dirs = [
"${common_path}/include",
"${innerkits_path}/native_cpp/include/notify",
]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [
"${utils_path}:devicemanagerutils",
"${utils_path}:devicemanagerutils",
"//foundation/arkui/napi:ace_napi",
"//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk",
"//third_party/benchmark:benchmark",
"//third_party/bounds_checking_function:libsec_shared",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
]
external_deps = [
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr_standard:samgr_proxy",
"startup_l2:syspara",
]
}
group("benchmarktest") {
testonly = true
deps = []
deps += [
# deps file
":DeviceManagerFaTest",
]
}
@@ -0,0 +1,300 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <benchmark/benchmark.h>
#include <unistd.h>
#include <vector>
#include "device_manager.h"
#include "dm_app_image_info.h"
#include "dm_subscribe_info.h"
#include "device_manager_callback.h"
#include "dm_constants.h"
using namespace std;
using namespace OHOS;
using namespace OHOS::DistributedHardware;
namespace {
class DeviceDiscoveryCallbackTest : public DiscoveryCallback {
public:
DeviceDiscoveryCallbackTest() : DiscoveryCallback() {}
virtual ~DeviceDiscoveryCallbackTest() {}
virtual void OnDiscoverySuccess(uint16_t subscribeId) override {}
virtual void OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason) override {}
virtual void OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) override {}
};
class DmInitCallbackTest : public DmInitCallback {
public:
DmInitCallbackTest() : DmInitCallback() {}
virtual ~DmInitCallbackTest() override {}
virtual void OnRemoteDied() override {}
};
class DeviceStateCallbackTest : public DeviceStateCallback {
public:
DeviceStateCallbackTest() : DeviceStateCallback() {}
virtual ~DeviceStateCallbackTest() override {}
virtual void OnDeviceOnline(const DmDeviceInfo &deviceInfo) override {}
virtual void OnDeviceReady(const DmDeviceInfo &deviceInfo) override {}
virtual void OnDeviceOffline(const DmDeviceInfo &deviceInfo) override {}
virtual void OnDeviceChanged(const DmDeviceInfo &deviceInfo) override {}
};
class DeviceManagerFaCallbackTest : public DeviceManagerFaCallback {
public:
DeviceManagerFaCallbackTest() : DeviceManagerFaCallback() {}
virtual ~DeviceManagerFaCallbackTest() override {}
virtual void OnCall(const std::string &paramJson) override {}
};
class DeviceManagerFaTest : public benchmark::Fixture {
public:
DeviceManagerFaTest()
{
Iterations(iterations);
Repetitions(repetitions);
ReportAggregatesOnly();
}
~DeviceManagerFaTest() override = default;
void SetUp(const ::benchmark::State &state) override
{
}
void TearDown(const ::benchmark::State &state) override
{
}
protected:
const int32_t repetitions = 3;
const int32_t iterations = 1000;
// sleep 1000ms
const int32_t usleepTime = 1000 * 1000;
const string pkgName = "com.ohos.devicemanager";
const string extra = "";
const string bundleName = "";
const string extraString = "";
const string packageName = "";
const int32_t authType = 0;
};
class GetTrustedDeviceListTest : public DeviceManagerFaTest {
public:
void SetUp(const ::benchmark::State &state) override {}
void TearDown(const ::benchmark::State &state) override {}
};
class DeviceDiscoveryTest : public DeviceManagerFaTest {
public:
void SetUp(const ::benchmark::State &state) override
{
DeviceManager::GetInstance().StopDeviceDiscovery(bundleName, subscribeId);
usleep(usleepTime);
}
void TearDown(const ::benchmark::State &state) override
{
DeviceManager::GetInstance().StopDeviceDiscovery(bundleName, subscribeId);
usleep(usleepTime);
}
protected:
const int16_t subscribeId = 0;
};
class AuthenticateDeviceTest : public DeviceManagerFaTest {
public:
void TearDown(const ::benchmark::State &state) override
{
DmDeviceInfo deviceInfo;
DeviceManager::GetInstance().UnAuthenticateDevice(bundleName, deviceInfo);
usleep(usleepTime);
}
};
class UnAuthenticateDeviceTest : public DeviceManagerFaTest {
public:
void SetUp(const ::benchmark::State &state) override
{
DmDeviceInfo deviceInfo;
std::shared_ptr<AuthenticateCallback> callback = nullptr;
DeviceManager::GetInstance().AuthenticateDevice(pkgName,
authType, deviceInfo, extraString, callback);
usleep(usleepTime);
}
};
class RegisterDeviceManagerFaTest : public DeviceManagerFaTest {
public:
void TearDown(const ::benchmark::State &state) override
{
DeviceManager::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName);
usleep(usleepTime);
}
};
class UnRegisterDeviceManagerFaTest : public DeviceManagerFaTest {
public:
void SetUp(const ::benchmark::State &state) override
{
std::shared_ptr<DeviceManagerFaCallbackTest> callback = std::make_shared<DeviceManagerFaCallbackTest>();
DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(pkgName, callback);
usleep(usleepTime);
}
};
class RegisterDevStateTest : public DeviceManagerFaTest {
public:
void TearDown(const ::benchmark::State &state) override
{
DeviceManager::GetInstance().UnRegisterDevStateCallback(bundleName);
usleep(usleepTime);
}
};
// GetTrustedDeviceList
BENCHMARK_F(GetTrustedDeviceListTest, GetTrustedDeviceListTestCase)(
benchmark::State &state)
{
while (state.KeepRunning()) {
std::vector<DmDeviceInfo> devList {};
int32_t ret = DeviceManager::GetInstance().GetTrustedDeviceList(bundleName, extra, devList);
if (ret != DM_OK) {
state.SkipWithError("GetTrustedDeviceListTestCase failed.");
}
}
}
// StartDeviceDiscovery
BENCHMARK_F(DeviceDiscoveryTest, StartDeviceDiscoveryTestCase)(
benchmark::State &state)
{
while (state.KeepRunning()) {
DmSubscribeInfo subInfo;
std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DeviceDiscoveryCallbackTest>();
int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(bundleName,
subInfo, extra, callback);
if (ret != DM_OK) {
state.SkipWithError("StartDeviceDiscoveryTestCase faild.");
}
}
}
// StopDeviceDiscovery
BENCHMARK_F(DeviceDiscoveryTest, StoptDeviceDiscoveryTestCase)(
benchmark::State &state)
{
while (state.KeepRunning()) {
state.PauseTiming();
DmSubscribeInfo subInfo;
std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DeviceDiscoveryCallbackTest>();
int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(bundleName,
subInfo, extra, callback);
if (ret != DM_OK) {
state.SkipWithError("StopDeviceDiscoveryTestCase faild.");
}
state.ResumeTiming();
ret =DeviceManager::GetInstance().StopDeviceDiscovery(bundleName, subscribeId);
if (ret != DM_OK) {
state.SkipWithError("StopDeviceDiscoveryTestCase faild.");
}
}
}
// AuthenticateDevice
BENCHMARK_F(AuthenticateDeviceTest, AuthenticateDeviceTestCase)(
benchmark::State &state)
{
while (state.KeepRunning()) {
DmDeviceInfo deviceInfo;
std::shared_ptr<AuthenticateCallback> callback = nullptr;
int32_t ret = DeviceManager::GetInstance().AuthenticateDevice(pkgName,
authType, deviceInfo, extraString, callback);
if (ret != DM_OK) {
state.SkipWithError("AuthenticateDeviceTestCase faild.");
}
}
}
// UnAuthenticateDevice
BENCHMARK_F(UnAuthenticateDeviceTest, UnAuthenticateDeviceTestCase)(
benchmark::State &state)
{
while (state.KeepRunning()) {
state.PauseTiming();
DmDeviceInfo deviceInfo;
std::shared_ptr<AuthenticateCallback> callback = nullptr;
int32_t ret = DeviceManager::GetInstance().AuthenticateDevice(pkgName,
authType, deviceInfo, extraString, callback);
if (ret != DM_OK) {
state.SkipWithError("UnAuthenticateDeviceTestCase faild.");
}
state.ResumeTiming();
ret = DeviceManager::GetInstance().UnAuthenticateDevice(bundleName, deviceInfo);
if (ret != DM_OK) {
state.SkipWithError("UnAuthenticateDeviceTestCase faild.");
}
}
}
// RegisterDeviceManagerFaCallback
BENCHMARK_F(RegisterDeviceManagerFaTest, RegisterDeviceManagerFaCallbackTestCase)(
benchmark::State &state)
{
while (state.KeepRunning()) {
std::shared_ptr<DeviceManagerFaCallbackTest> callback = std::make_shared<DeviceManagerFaCallbackTest>();
int32_t ret = DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(packageName, callback);
if (ret != DM_OK) {
state.SkipWithError("AuthenticateDeviceTestCase faild.");
}
}
}
// UnRegisterDeviceManagerFaCallback
BENCHMARK_F(UnRegisterDeviceManagerFaTest, UnRegisterDeviceManagerFaCallbackTestCase)(
benchmark::State &state)
{
while (state.KeepRunning()) {
state.PauseTiming();
std::shared_ptr<DeviceManagerFaCallbackTest> callback = std::make_shared<DeviceManagerFaCallbackTest>();
int32_t ret = DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(packageName, callback);
if (ret != DM_OK) {
state.SkipWithError("AuthenticateDeviceTestCase faild.");
}
state.ResumeTiming();
ret = DeviceManager::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName);
if (ret != DM_OK) {
state.SkipWithError("UnRegisterDeviceManagerFaCallbackTestCase faild.");
}
}
}
// RegisterDevStateCallback
BENCHMARK_F(RegisterDevStateTest, RegisterDevStateCallbackTestCase)(
benchmark::State &state)
{
while (state.KeepRunning()) {
int32_t ret = DeviceManager::GetInstance().RegisterDevStateCallback(bundleName, extra);
if (ret != DM_OK) {
state.SkipWithError("RegisterDevStateCallbackTestCase faild.");
}
}
}
}
// Run the benchmark
BENCHMARK_MAIN();
@@ -0,0 +1,61 @@
# 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/distributedhardware/devicemanager/devicemanager.gni")
module_output_path = "device_manager_base/devicemanager"
ohos_benchmarktest("DeviceManagerTest") {
module_out_path = module_output_path
sources = [ "device_manager_test.cpp" ]
include_dirs = [ "${common_path}/include" ]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [
"${utils_path}:devicemanagerutils",
"${utils_path}:devicemanagerutils",
"//foundation/arkui/napi:ace_napi",
"//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk",
"//third_party/benchmark:benchmark",
"//third_party/bounds_checking_function:libsec_shared",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
]
external_deps = [
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr_standard:samgr_proxy",
"startup_l2:syspara",
]
}
group("benchmarktest") {
testonly = true
deps = []
deps += [
# deps file
":DeviceManagerTest",
]
}
@@ -0,0 +1,110 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <benchmark/benchmark.h>
#include <unistd.h>
#include <vector>
#include "device_manager.h"
#include "dm_app_image_info.h"
#include "dm_constants.h"
using namespace std;
using namespace OHOS;
using namespace OHOS::DistributedHardware;
namespace {
class BenchmarkDmInit : public DmInitCallback {
public:
BenchmarkDmInit() : DmInitCallback() {}
virtual ~BenchmarkDmInit() override {}
virtual void OnRemoteDied() override {}
};
class DeviceManagerTest : public benchmark::Fixture {
public:
DeviceManagerTest()
{
Iterations(iterations);
Repetitions(repetitions);
ReportAggregatesOnly();
}
~DeviceManagerTest() override = default;
void SetUp(const ::benchmark::State &state) override
{
}
void TearDown(const ::benchmark::State &state) override
{
}
protected:
const string pkgName = "ohos.distributedhardware.devicemanager";
const int32_t repetitions = 16;
const int32_t iterations = 1;
};
// InitDeviceManager
BENCHMARK_F(DeviceManagerTest, InitDeviceManagerTestCase)(benchmark::State &state)
{
while (state.KeepRunning()) {
std::shared_ptr<BenchmarkDmInit> callback = std::make_shared<BenchmarkDmInit>();
int32_t ret = DeviceManager::GetInstance().InitDeviceManager(pkgName, callback);
if (ret != DM_OK) {
state.SkipWithError("InitDeviceManagerTestCase failed.");
}
}
}
// GetFaParam
BENCHMARK_F(DeviceManagerTest, GetFaParamTestCase)(benchmark::State &state)
{
while (state.KeepRunning()) {
DmAuthParam authParam;
int32_t ret = DeviceManager::GetInstance().GetFaParam(pkgName, authParam);
if (ret != DM_OK) {
state.SkipWithError("GetFaParamTestCase. faild");
}
}
}
// SetUserOperation
BENCHMARK_F(DeviceManagerTest, SetUserOperationTestCase)(benchmark::State &state)
{
while (state.KeepRunning()) {
int32_t action = 0;
int32_t ret = DeviceManager::GetInstance().SetUserOperation(pkgName, action);
if (ret != DM_OK) {
state.SkipWithError("SetUserOperationTestCase failed.");
}
}
}
// GetUdidByNetworkId
BENCHMARK_F(DeviceManagerTest, GetUdidByNetworkIdTestCase)(benchmark::State &state)
{
while (state.KeepRunning()) {
std::string netWorkId = "";
std::string uuid = "";
int32_t ret = DeviceManager::GetInstance().GetUuidByNetworkId(pkgName, netWorkId, uuid);
if (ret != DM_OK) {
state.SkipWithError("SetUserOperationTestCase failed.");
}
}
}
}
// Run the benchmark
BENCHMARK_MAIN();