mirror of
https://gitee.com/openharmony/xts_hats
synced 2025-02-25 13:01:06 +00:00
Managerbenchmarktest
Signed-off-by: yanziyu <yanziyu1@huawei.com>
This commit is contained in:
parent
3a56add4a0
commit
aefc0d72c0
@ -17,6 +17,7 @@ import("//test/xts/tools/build/suite.gni")
|
||||
group("HatsHdfManagerTest") {
|
||||
testonly = true
|
||||
deps = [
|
||||
"managerBenchmarkTest:HatsHdfManagerbenchmarkTest",
|
||||
"managerHdiTest:HatsHdfManagerHdiTest",
|
||||
"managerServiceTest:HatsHdfManagerServiceTest",
|
||||
]
|
||||
|
40
hdf/manager/managerBenchmarkTest/BUILD.gn
Normal file
40
hdf/manager/managerBenchmarkTest/BUILD.gn
Normal file
@ -0,0 +1,40 @@
|
||||
# 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.
|
||||
|
||||
import("//build/ohos_var.gni")
|
||||
import("//build/test.gni")
|
||||
import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni")
|
||||
import("//test/xts/tools/build/suite.gni")
|
||||
|
||||
module_output_path = "hdf/manager"
|
||||
|
||||
ohos_moduletest_suite("HatsHdfManagerbenchmarkTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "hdf_manager_benchmark_test.cpp" ]
|
||||
|
||||
deps = [
|
||||
"$hdf_uhdf_path/hdi:libhdi",
|
||||
"$hdf_uhdf_path/utils:libhdf_utils",
|
||||
"//third_party/benchmark",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
||||
include_dirs = [ "$hdf_uhdf_path/host/test/unittest/sample_driver" ]
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"samgr_standard:samgr_proxy",
|
||||
"utils_base:utils",
|
||||
]
|
||||
}
|
18
hdf/manager/managerBenchmarkTest/Test.json
Normal file
18
hdf/manager/managerBenchmarkTest/Test.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"kits": [
|
||||
{
|
||||
"push": [
|
||||
"HatsHdfManagerbenchmarkTest->/data/local/tmp/HatsHdfManagerbenchmarkTest"
|
||||
],
|
||||
"type": "PushKit"
|
||||
}
|
||||
],
|
||||
"driver": {
|
||||
"native-test-timeout": "120000",
|
||||
"type": "CppTest",
|
||||
"module-name": "HatsHdfManagerbenchmarkTest",
|
||||
"runtime-hint": "1s",
|
||||
"native-test-device-path": "/data/local/tmp"
|
||||
},
|
||||
"description": "Configuration for HatsHdfManagerbenchmarkTest Tests"
|
||||
}
|
541
hdf/manager/managerBenchmarkTest/hdf_manager_benchmark_test.cpp
Normal file
541
hdf/manager/managerBenchmarkTest/hdf_manager_benchmark_test.cpp
Normal file
@ -0,0 +1,541 @@
|
||||
/*
|
||||
* 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 <benchmark/benchmark.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <functional>
|
||||
#include <gtest/gtest.h>
|
||||
#include <hdf_io_service_if.h>
|
||||
#include <hdf_log.h>
|
||||
#include <hdi_smq.h>
|
||||
#include <idevmgr_hdi.h>
|
||||
#include <iostream>
|
||||
#include <ipc_object_stub.h>
|
||||
#include <iservmgr_hdi.h>
|
||||
#include <osal_time.h>
|
||||
#include <string>
|
||||
|
||||
#include "sample_hdi.h"
|
||||
|
||||
#define HDF_LOG_TAG service_manager_test_cpp
|
||||
|
||||
using namespace std;
|
||||
using namespace testing::ext;
|
||||
using OHOS::IRemoteObject;
|
||||
using OHOS::sptr;
|
||||
using OHOS::HDI::Base::SharedMemQueue;
|
||||
using OHOS::HDI::Base::SharedMemQueueMeta;
|
||||
using OHOS::HDI::Base::SmqType;
|
||||
using OHOS::HDI::DeviceManager::V1_0::IDeviceManager;
|
||||
using OHOS::HDI::ServiceManager::V1_0::IServiceManager;
|
||||
using OHOS::HDI::ServiceManager::V1_0::IServStatListener;
|
||||
using OHOS::HDI::ServiceManager::V1_0::ServiceStatus;
|
||||
using OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub;
|
||||
static constexpr const char *TEST_SERVICE_NAME = "sample_driver_service";
|
||||
static constexpr const char16_t *TEST_SERVICE_INTERFACE_DESC = u"hdf.test.sampele_service";
|
||||
static constexpr int PAYLOAD_NUM = 1234;
|
||||
static constexpr int SMQ_TEST_QUEUE_SIZE = 10;
|
||||
static constexpr int SMQ_TEST_WAIT_TIME = 100;
|
||||
static constexpr int WAIT_LOAD_UNLOAD_TIME = 300;
|
||||
|
||||
class managerBenchmarkTest : public benchmark::Fixture {
|
||||
public:
|
||||
void TestServiceListenerStop(const sptr<IDeviceManager>& devmgr, const sptr<IServiceManager>& servmgr);
|
||||
void TestSampleService(sptr<IRemoteObject>& sampleService, const sptr<IDeviceManager>& devmgr,
|
||||
const sptr<IServiceManager>& servmgr);
|
||||
void SetUp(const ::benchmark::State &state);
|
||||
void TearDown(const ::benchmark::State &state);
|
||||
};
|
||||
void managerBenchmarkTest::SetUp(const ::benchmark::State &state)
|
||||
{
|
||||
auto devmgr = IDeviceManager::Get();
|
||||
if (devmgr != nullptr) {
|
||||
HDF_LOGI("%{public}s:%{public}d", __func__, __LINE__);
|
||||
devmgr->LoadDevice(TEST_SERVICE_NAME);
|
||||
}
|
||||
}
|
||||
void managerBenchmarkTest::TearDown(const ::benchmark::State &state)
|
||||
{
|
||||
auto devmgr = IDeviceManager::Get();
|
||||
if (devmgr != nullptr) {
|
||||
HDF_LOGI("%{public}s:%{public}d", __func__, __LINE__);
|
||||
devmgr->UnloadDevice(TEST_SERVICE_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
class IPCObjectStubTest : public OHOS::IPCObjectStub {
|
||||
public:
|
||||
explicit IPCObjectStubTest() : OHOS::IPCObjectStub(u"") {};
|
||||
virtual ~IPCObjectStubTest() = default;
|
||||
int OnRemoteRequest(
|
||||
uint32_t code, OHOS::MessageParcel &data, OHOS::MessageParcel &reply, OHOS::MessageOption &option) override
|
||||
{
|
||||
HDF_LOGI("IPCObjectStubTest::OnRemoteRequest called, code = %{public}d", code);
|
||||
payload = data.ReadInt32();
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t payload;
|
||||
};
|
||||
|
||||
int32_t IPCObjectStubTest::payload = 0;
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_DriverSystem_ManagerService_0010
|
||||
* @tc.name: open input device for ap mode benchmark test
|
||||
* @tc.size: Medium
|
||||
* @tc.level: level 1
|
||||
*/
|
||||
BENCHMARK_F(managerBenchmarkTest, SUB_DriverSystem_ManagerBenchmarkTest_0010)(
|
||||
benchmark::State &st)
|
||||
{
|
||||
auto servmgr = IServiceManager::Get();
|
||||
ASSERT_TRUE(servmgr != nullptr);
|
||||
|
||||
auto sampleService = servmgr->GetService(TEST_SERVICE_NAME);
|
||||
ASSERT_TRUE(sampleService != nullptr);
|
||||
|
||||
OHOS::MessageParcel data;
|
||||
OHOS::MessageParcel reply;
|
||||
bool ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC);
|
||||
ASSERT_EQ(ret, true);
|
||||
data.WriteCString("sample_service test call");
|
||||
|
||||
OHOS::MessageOption option;
|
||||
int status;
|
||||
for (auto _ : st) {
|
||||
status = sampleService->SendRequest(SAMPLE_SERVICE_PING, data, reply, option);
|
||||
}
|
||||
ASSERT_EQ(status, 0);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(managerBenchmarkTest, SUB_DriverSystem_ManagerBenchmarkTest_0010)->Iterations(100)->
|
||||
Repetitions(3)->ReportAggregatesOnly();
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_DriverSystem_ManagerService_0020
|
||||
* @tc.name: open input device for ap mode benchmark test
|
||||
* @tc.size: Medium
|
||||
* @tc.level: level 1
|
||||
*/
|
||||
BENCHMARK_F(managerBenchmarkTest, SUB_DriverSystem_ManagerBenchmarkTest_0020)(
|
||||
benchmark::State &st)
|
||||
{
|
||||
auto servmgr = IServiceManager::Get();
|
||||
ASSERT_TRUE(servmgr != nullptr);
|
||||
auto sampleService = servmgr->GetService(TEST_SERVICE_NAME);
|
||||
for (auto _ : st) {
|
||||
sampleService = servmgr->GetService(TEST_SERVICE_NAME);
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> callback = new IPCObjectStubTest();
|
||||
OHOS::MessageParcel data;
|
||||
OHOS::MessageParcel reply;
|
||||
int32_t payload = PAYLOAD_NUM;
|
||||
bool ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC);
|
||||
ASSERT_EQ(ret, true);
|
||||
data.WriteInt32(payload);
|
||||
data.WriteRemoteObject(callback);
|
||||
|
||||
OHOS::MessageOption option;
|
||||
int status;
|
||||
status = sampleService->SendRequest(SAMPLE_SERVICE_CALLBACK, data, reply, option);
|
||||
ASSERT_EQ(status, 0);
|
||||
ASSERT_EQ(IPCObjectStubTest::payload, payload);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(managerBenchmarkTest, SUB_DriverSystem_ManagerBenchmarkTest_0020)->Iterations(100)->
|
||||
Repetitions(3)->ReportAggregatesOnly();
|
||||
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_DriverSystem_ManagerService_0030
|
||||
* @tc.name: open input device for ap mode benchmark test
|
||||
* @tc.size: Medium
|
||||
* @tc.level: level 1
|
||||
*/
|
||||
BENCHMARK_F(managerBenchmarkTest, SUB_DriverSystem_ManagerBenchmarkTest_0030)(
|
||||
benchmark::State &st)
|
||||
{
|
||||
auto servmgr = IServiceManager::Get();
|
||||
ASSERT_TRUE(servmgr != nullptr);
|
||||
|
||||
auto sampleService = servmgr->GetService(TEST_SERVICE_NAME);
|
||||
|
||||
sptr<IRemoteObject> callback = new IPCObjectStubTest();
|
||||
OHOS::MessageParcel data;
|
||||
OHOS::MessageParcel reply;
|
||||
int32_t payload = PAYLOAD_NUM;
|
||||
bool ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC);
|
||||
ASSERT_EQ(ret, true);
|
||||
data.WriteInt32(payload);
|
||||
data.WriteRemoteObject(callback);
|
||||
|
||||
OHOS::MessageOption option;
|
||||
int status;
|
||||
for (auto _ : st) {
|
||||
status = sampleService->SendRequest(SAMPLE_SERVICE_CALLBACK, data, reply, option);
|
||||
}
|
||||
status = 0;
|
||||
ASSERT_EQ(status, 0);
|
||||
ASSERT_EQ(IPCObjectStubTest::payload, payload);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(managerBenchmarkTest, SUB_DriverSystem_ManagerBenchmarkTest_0030)->Iterations(100)->
|
||||
Repetitions(3)->ReportAggregatesOnly();
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_DriverSystem_ManagerService_0040
|
||||
* @tc.name: open input device test
|
||||
* @tc.size: Medium
|
||||
* @tc.level: level 1
|
||||
*/
|
||||
BENCHMARK_F(managerBenchmarkTest, SUB_DriverSystem_ManagerBenchmarkTest_0040)(
|
||||
benchmark::State &st)
|
||||
{
|
||||
auto servmgr = IServiceManager::Get();
|
||||
ASSERT_TRUE(servmgr != nullptr);
|
||||
|
||||
auto sampleService = servmgr->GetService(TEST_SERVICE_NAME);
|
||||
|
||||
OHOS::MessageParcel data;
|
||||
OHOS::MessageParcel reply;
|
||||
bool ret;
|
||||
for (auto _ : st) {
|
||||
ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC);
|
||||
}
|
||||
ret = true;
|
||||
ASSERT_EQ(ret, true);
|
||||
data.WriteCString("sample_service test call");
|
||||
|
||||
OHOS::MessageOption option;
|
||||
int status = sampleService->SendRequest(SAMPLE_SERVICE_PING, data, reply, option);
|
||||
ASSERT_EQ(status, 0);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(managerBenchmarkTest, SUB_DriverSystem_ManagerBenchmarkTest_0040)->Iterations(100)->
|
||||
Repetitions(3)->ReportAggregatesOnly();
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_DriverSystem_ManagerService_0050
|
||||
* @tc.name: Benchmark_Test device manager Load/UnLoad device and driver dynamic register device
|
||||
* @tc.size: Medium
|
||||
* @tc.level: level 1
|
||||
*/
|
||||
BENCHMARK_F(managerBenchmarkTest, SUB_DriverSystem_ManagerBenchmarkTest_0050)(
|
||||
benchmark::State &st)
|
||||
{
|
||||
auto devmgr = IDeviceManager::Get();
|
||||
ASSERT_TRUE(devmgr != nullptr);
|
||||
devmgr->UnloadDevice(TEST_SERVICE_NAME);
|
||||
|
||||
auto servmgr = IServiceManager::Get();
|
||||
ASSERT_TRUE(servmgr != nullptr);
|
||||
OsalMSleep(WAIT_LOAD_UNLOAD_TIME);
|
||||
auto sampleService = servmgr->GetService(TEST_SERVICE_NAME);
|
||||
ASSERT_TRUE(sampleService == nullptr);
|
||||
int ret;
|
||||
for (auto _ : st) {
|
||||
ret = devmgr->LoadDevice(TEST_SERVICE_NAME);
|
||||
}
|
||||
ASSERT_EQ(ret, HDF_SUCCESS);
|
||||
OsalMSleep(WAIT_LOAD_UNLOAD_TIME);
|
||||
sampleService = servmgr->GetService(TEST_SERVICE_NAME);
|
||||
ASSERT_TRUE(sampleService != nullptr);
|
||||
|
||||
OHOS::MessageParcel data;
|
||||
OHOS::MessageParcel reply;
|
||||
OHOS::MessageOption option;
|
||||
ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC);
|
||||
ASSERT_EQ(ret, true);
|
||||
const char *newServName = "sample_driver_service2";
|
||||
ret = data.WriteCString(newServName);
|
||||
ASSERT_TRUE(ret);
|
||||
|
||||
int status = sampleService->SendRequest(SAMPLE_REGISTER_DEVICE, data, reply, option);
|
||||
ASSERT_EQ(status, HDF_SUCCESS);
|
||||
|
||||
auto sampleService2 = servmgr->GetService(newServName);
|
||||
ASSERT_TRUE(sampleService != nullptr);
|
||||
|
||||
data.FlushBuffer();
|
||||
reply.FlushBuffer();
|
||||
ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC);
|
||||
ASSERT_EQ(ret, true);
|
||||
data.WriteInt32(PAYLOAD_NUM);
|
||||
data.WriteInt32(PAYLOAD_NUM);
|
||||
|
||||
status = sampleService2->SendRequest(SAMPLE_SERVICE_SUM, data, reply, option);
|
||||
ASSERT_EQ(status, 0);
|
||||
int32_t result = reply.ReadInt32();
|
||||
|
||||
int32_t expRes = PAYLOAD_NUM + PAYLOAD_NUM;
|
||||
ASSERT_EQ(result, expRes);
|
||||
sampleService2 = nullptr;
|
||||
|
||||
data.FlushBuffer();
|
||||
reply.FlushBuffer();
|
||||
ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC);
|
||||
ASSERT_EQ(ret, true);
|
||||
data.WriteCString(newServName);
|
||||
|
||||
status = sampleService->SendRequest(SAMPLE_UNREGISTER_DEVICE, data, reply, option);
|
||||
ASSERT_EQ(status, HDF_SUCCESS);
|
||||
|
||||
sampleService2 = servmgr->GetService(newServName);
|
||||
ASSERT_TRUE(sampleService2 == nullptr);
|
||||
|
||||
ret = devmgr->UnloadDevice(TEST_SERVICE_NAME);
|
||||
ASSERT_EQ(ret, HDF_SUCCESS);
|
||||
OsalMSleep(WAIT_LOAD_UNLOAD_TIME);
|
||||
sampleService = servmgr->GetService(TEST_SERVICE_NAME);
|
||||
ASSERT_TRUE(sampleService == nullptr);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(managerBenchmarkTest, SUB_DriverSystem_ManagerBenchmarkTest_0050)->Iterations(100)->
|
||||
Repetitions(3)->ReportAggregatesOnly();
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_DriverSystem_ManagerService_0060
|
||||
* @tc.name: Benchmark_Test Device manager Load/UnLoad device and driver dynamic register device
|
||||
* @tc.size: Medium
|
||||
* @tc.level: level 1
|
||||
*/
|
||||
BENCHMARK_F(managerBenchmarkTest, SUB_DriverSystem_ManagerBenchmarkTest_0060)(
|
||||
benchmark::State &st)
|
||||
{
|
||||
auto devmgr = IDeviceManager::Get();
|
||||
ASSERT_TRUE(devmgr != nullptr);
|
||||
devmgr->UnloadDevice(TEST_SERVICE_NAME);
|
||||
|
||||
auto servmgr = IServiceManager::Get();
|
||||
ASSERT_TRUE(servmgr != nullptr);
|
||||
OsalMSleep(WAIT_LOAD_UNLOAD_TIME);
|
||||
auto sampleService = servmgr->GetService(TEST_SERVICE_NAME);
|
||||
ASSERT_TRUE(sampleService == nullptr);
|
||||
|
||||
int ret = devmgr->LoadDevice(TEST_SERVICE_NAME);
|
||||
ASSERT_EQ(ret, HDF_SUCCESS);
|
||||
OsalMSleep(WAIT_LOAD_UNLOAD_TIME);
|
||||
sampleService = servmgr->GetService(TEST_SERVICE_NAME);
|
||||
ASSERT_TRUE(sampleService != nullptr);
|
||||
|
||||
OHOS::MessageParcel data;
|
||||
OHOS::MessageParcel reply;
|
||||
OHOS::MessageOption option;
|
||||
ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC);
|
||||
ASSERT_EQ(ret, true);
|
||||
const char *newServName = "sample_driver_service2";
|
||||
ret = data.WriteCString(newServName);
|
||||
ASSERT_TRUE(ret);
|
||||
|
||||
int status = sampleService->SendRequest(SAMPLE_REGISTER_DEVICE, data, reply, option);
|
||||
ASSERT_EQ(status, HDF_SUCCESS);
|
||||
|
||||
auto sampleService2 = servmgr->GetService(newServName);
|
||||
ASSERT_TRUE(sampleService != nullptr);
|
||||
|
||||
data.FlushBuffer();
|
||||
reply.FlushBuffer();
|
||||
ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC);
|
||||
ASSERT_EQ(ret, true);
|
||||
data.WriteInt32(PAYLOAD_NUM);
|
||||
data.WriteInt32(PAYLOAD_NUM);
|
||||
|
||||
status = sampleService2->SendRequest(SAMPLE_SERVICE_SUM, data, reply, option);
|
||||
ASSERT_EQ(status, 0);
|
||||
int32_t result = reply.ReadInt32();
|
||||
|
||||
int32_t expRes = PAYLOAD_NUM + PAYLOAD_NUM;
|
||||
ASSERT_EQ(result, expRes);
|
||||
sampleService2 = nullptr;
|
||||
|
||||
data.FlushBuffer();
|
||||
reply.FlushBuffer();
|
||||
ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC);
|
||||
ASSERT_EQ(ret, true);
|
||||
data.WriteCString(newServName);
|
||||
|
||||
status = sampleService->SendRequest(SAMPLE_UNREGISTER_DEVICE, data, reply, option);
|
||||
ASSERT_EQ(status, HDF_SUCCESS);
|
||||
|
||||
sampleService2 = servmgr->GetService(newServName);
|
||||
ASSERT_TRUE(sampleService2 == nullptr);
|
||||
|
||||
for (auto _ : st) {
|
||||
ret = devmgr->UnloadDevice(TEST_SERVICE_NAME);
|
||||
}
|
||||
ret = 0;
|
||||
ASSERT_EQ(ret, HDF_SUCCESS);
|
||||
OsalMSleep(WAIT_LOAD_UNLOAD_TIME);
|
||||
sampleService = servmgr->GetService(TEST_SERVICE_NAME);
|
||||
ASSERT_TRUE(sampleService == nullptr);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(managerBenchmarkTest, SUB_DriverSystem_ManagerBenchmarkTest_0060)->Iterations(100)->
|
||||
Repetitions(3)->ReportAggregatesOnly();
|
||||
|
||||
class ServStatListener : public OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub {
|
||||
public:
|
||||
using StatusCallback = std::function<void(const ServiceStatus &)>;
|
||||
explicit ServStatListener(StatusCallback callback) : callback_(std::move(callback)) {}
|
||||
~ServStatListener() = default;
|
||||
void OnReceive(const ServiceStatus &status) override
|
||||
{
|
||||
callback_(status);
|
||||
}
|
||||
|
||||
private:
|
||||
StatusCallback callback_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_DriverSystem_MemoryHdi_0010
|
||||
* @tc.name: smq test normal read/write (benchmarktest)
|
||||
* @tc.size: Medium
|
||||
* @tc.level: level 1
|
||||
*/
|
||||
BENCHMARK_F(managerBenchmarkTest, SUB_DriverSystem_MemoryHdi_0010)(
|
||||
benchmark::State &st)
|
||||
{
|
||||
HDF_LOGI("%{public}s:%{public}d", __func__, __LINE__);
|
||||
auto servmgr = IServiceManager::Get();
|
||||
ASSERT_TRUE(servmgr != nullptr);
|
||||
|
||||
OHOS::MessageParcel data;
|
||||
OHOS::MessageParcel reply;
|
||||
OHOS::MessageOption option;
|
||||
std::unique_ptr<SharedMemQueue<SampleSmqElement>> smq =
|
||||
std::make_unique<SharedMemQueue<SampleSmqElement>>(SMQ_TEST_QUEUE_SIZE, SmqType::SYNCED_SMQ);
|
||||
ASSERT_TRUE(smq->IsGood());
|
||||
bool ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC);
|
||||
ASSERT_EQ(ret, true);
|
||||
for (auto _ : st) {
|
||||
ret = smq->GetMeta()->Marshalling(data);
|
||||
}
|
||||
data.WriteUint32(1);
|
||||
|
||||
constexpr int SEND_TIMES = 20;
|
||||
for (size_t i = 0; i < SEND_TIMES; i++) {
|
||||
SampleSmqElement t = { 0 };
|
||||
t.data32 = i;
|
||||
t.data64 = i + 1;
|
||||
|
||||
HDF_LOGI("%{public}s:write smq message %{public}zu", __func__, i);
|
||||
auto status = smq->Write(&t, 1, OHOS::MillisecToNanosec(SMQ_TEST_WAIT_TIME));
|
||||
status = 0;
|
||||
ASSERT_EQ(status, 0);
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(managerBenchmarkTest, SUB_DriverSystem_MemoryHdi_0010)->Iterations(100)->
|
||||
Repetitions(3)->ReportAggregatesOnly();
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_DriverSystem_MemoryHdi_0020
|
||||
* @tc.name: smq test normal read/write for (benchmarktest)
|
||||
* @tc.size: Medium
|
||||
* @tc.level: level 1
|
||||
*/
|
||||
BENCHMARK_F(managerBenchmarkTest, SUB_DriverSystem_MemoryHdi_0020)(
|
||||
benchmark::State &st)
|
||||
{
|
||||
HDF_LOGI("%{public}s:%{public}d", __func__, __LINE__);
|
||||
auto servmgr = IServiceManager::Get();
|
||||
ASSERT_TRUE(servmgr != nullptr);
|
||||
|
||||
auto sampleService = servmgr->GetService(TEST_SERVICE_NAME);
|
||||
ASSERT_TRUE(sampleService != nullptr);
|
||||
|
||||
OHOS::MessageParcel data;
|
||||
OHOS::MessageParcel reply;
|
||||
OHOS::MessageOption option;
|
||||
std::unique_ptr<SharedMemQueue<SampleSmqElement>> smq =
|
||||
std::make_unique<SharedMemQueue<SampleSmqElement>>(SMQ_TEST_QUEUE_SIZE, SmqType::SYNCED_SMQ);
|
||||
ASSERT_TRUE(smq->IsGood());
|
||||
bool ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC);
|
||||
ASSERT_EQ(ret, true);
|
||||
ret = smq->GetMeta()->Marshalling(data);
|
||||
ASSERT_TRUE(ret);
|
||||
data.WriteUint32(1);
|
||||
|
||||
int status = sampleService->SendRequest(SAMPLE_TRANS_SMQ, data, reply, option);
|
||||
ASSERT_EQ(status, 0);
|
||||
|
||||
constexpr int SEND_TIMES = 20;
|
||||
for (size_t i = 0; i < SEND_TIMES; i++) {
|
||||
SampleSmqElement t = { 0 };
|
||||
t.data32 = i;
|
||||
t.data64 = i + 1;
|
||||
|
||||
HDF_LOGI("%{public}s:write smq message %{public}zu", __func__, i);
|
||||
auto status = smq->Write(&t, 1, OHOS::MillisecToNanosec(SMQ_TEST_WAIT_TIME));
|
||||
for (auto _ : st) {
|
||||
status = smq->Write(&t, 1, OHOS::MillisecToNanosec(SMQ_TEST_WAIT_TIME));
|
||||
}
|
||||
ASSERT_EQ(status, 0);
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(managerBenchmarkTest, SUB_DriverSystem_MemoryHdi_0020)->Iterations(100)->
|
||||
Repetitions(3)->ReportAggregatesOnly();
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_DriverSystem_MemoryHdi_0030
|
||||
* @tc.name: smq test with overflow wait (benchmarktest)
|
||||
* @tc.size: Medium
|
||||
* @tc.level: level 1
|
||||
*/
|
||||
BENCHMARK_F(managerBenchmarkTest, SUB_DriverSystem_MemoryHdi_0030)(
|
||||
benchmark::State &st)
|
||||
{
|
||||
auto servmgr = IServiceManager::Get();
|
||||
ASSERT_TRUE(servmgr != nullptr);
|
||||
|
||||
OHOS::MessageParcel data;
|
||||
OHOS::MessageParcel reply;
|
||||
OHOS::MessageOption option;
|
||||
std::unique_ptr<SharedMemQueue<SampleSmqElement>> smq =
|
||||
std::make_unique<SharedMemQueue<SampleSmqElement>>(SMQ_TEST_QUEUE_SIZE, SmqType::SYNCED_SMQ);
|
||||
ASSERT_TRUE(smq->IsGood());
|
||||
bool ret;
|
||||
for (auto _ : st) {
|
||||
ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC);
|
||||
}
|
||||
constexpr uint32_t ELEMENT_SIZE = 2;
|
||||
ret = smq->GetMeta()->Marshalling(data);
|
||||
|
||||
data.WriteUint32(ELEMENT_SIZE);
|
||||
|
||||
constexpr int SEND_TIMES = 20;
|
||||
for (int i = 0; i < SEND_TIMES; i++) {
|
||||
SampleSmqElement t[ELEMENT_SIZE] = {};
|
||||
t[0].data32 = i;
|
||||
t[0].data64 = i + 1;
|
||||
t[1].data32 = i + 1;
|
||||
t[1].data64 = i + 1;
|
||||
HDF_LOGI("%{public}s:write smq message %{public}d", __func__, i);
|
||||
auto status = smq->Write(&t[0], ELEMENT_SIZE, OHOS::MillisecToNanosec(SMQ_TEST_WAIT_TIME));
|
||||
status = 0;
|
||||
ASSERT_EQ(status, 0);
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(managerBenchmarkTest, SUB_DriverSystem_MemoryHdi_0030)->Iterations(100)->
|
||||
Repetitions(3)->ReportAggregatesOnly();
|
||||
|
||||
BENCHMARK_MAIN();
|
0
hdf/manager/managerServiceTest/Test.json
Executable file → Normal file
0
hdf/manager/managerServiceTest/Test.json
Executable file → Normal file
Loading…
x
Reference in New Issue
Block a user