mirror of
https://github.com/openharmony/notification_ces_standard.git
synced 2026-07-01 04:39:51 -04:00
!265 Add benchmark test case
Merge pull request !265 from FangJinliang/pr_264
This commit is contained in:
+2
-1
@@ -131,7 +131,8 @@
|
||||
"//base/notification/common_event_service/test/systemtest:systemtest",
|
||||
"//base/notification/common_event_service/tools:moduletest",
|
||||
"//base/notification/common_event_service/tools:systemtest",
|
||||
"//base/notification/common_event_service/tools:unittest"
|
||||
"//base/notification/common_event_service/tools:unittest",
|
||||
"//base/notification/common_event_service/test/benchmarktest:benchmarktest"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ ohos_moduletest("cesModuleTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"${services_path}/test/mock/src/mock_bundle_manager.cpp",
|
||||
"${common_event_service_path}/test/mock/mock_bundle_manager.cpp",
|
||||
"${services_path}/test/mock/src/mock_ipc.cpp",
|
||||
"common_event_services_module_test.cpp",
|
||||
]
|
||||
@@ -41,7 +41,7 @@ ohos_moduletest("cesModuleTest") {
|
||||
"//foundation/distributedschedule/samgr/services/samgr/native/include",
|
||||
"//foundation/distributedschedule/samgr/utils/native/include",
|
||||
"${services_path}/include",
|
||||
"${services_path}/test/mock/include",
|
||||
"${common_event_service_path}/test/mock/include",
|
||||
"//third_party/json/include",
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
|
||||
+2
-2
@@ -40,7 +40,7 @@ namespace EventFwk {
|
||||
namespace {
|
||||
std::mutex mtx_;
|
||||
const time_t TIME_OUT_SECONDS_LIMIT = 3;
|
||||
static OHOS::sptr<OHOS::EventFwk::MockBundleMgrService> bundleObject = nullptr;
|
||||
static OHOS::sptr<OHOS::AppExecFwk::MockBundleMgrService> bundleObject = nullptr;
|
||||
std::shared_ptr<EventHandler> handlerPtr;
|
||||
} // namespace
|
||||
|
||||
@@ -76,7 +76,7 @@ void cesModuleTest::SetUpTestCase()
|
||||
auto task = []() { EventRunner::GetMainEventRunner()->Run(); };
|
||||
handlerPtr->PostTask(task);
|
||||
|
||||
bundleObject = new OHOS::EventFwk::MockBundleMgrService();
|
||||
bundleObject = new OHOS::AppExecFwk::MockBundleMgrService();
|
||||
OHOS::DelayedSingleton<BundleManagerHelper>::GetInstance()->sptrBundleMgr_ =
|
||||
OHOS::iface_cast<OHOS::AppExecFwk::IBundleMgr>(bundleObject);
|
||||
OHOS::DelayedSingleton<CommonEventManagerService>::GetInstance()->OnStart();
|
||||
|
||||
@@ -20,7 +20,7 @@ ohos_moduletest("CesPublishOrderedEventModuleTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"${services_path}/test/mock/src/mock_bundle_manager.cpp",
|
||||
"${common_event_service_path}/test/mock/mock_bundle_manager.cpp",
|
||||
"${services_path}/test/mock/src/mock_ipc.cpp",
|
||||
"common_event_services_publish_ordered_module_test.cpp",
|
||||
]
|
||||
@@ -41,7 +41,7 @@ ohos_moduletest("CesPublishOrderedEventModuleTest") {
|
||||
"//foundation/distributedschedule/samgr/services/samgr/native/include",
|
||||
"//foundation/distributedschedule/samgr/utils/native/include",
|
||||
"${services_path}/include",
|
||||
"${services_path}/test/mock/include",
|
||||
"${common_event_service_path}/test/mock/include",
|
||||
"//third_party/json/include",
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
|
||||
+2
-2
@@ -40,7 +40,7 @@ using namespace OHOS::EventFwk;
|
||||
using OHOS::Parcel;
|
||||
|
||||
namespace {
|
||||
static OHOS::sptr<OHOS::EventFwk::MockBundleMgrService> p_bundleObject = nullptr;
|
||||
static OHOS::sptr<OHOS::AppExecFwk::MockBundleMgrService> p_bundleObject = nullptr;
|
||||
const std::string EVENTCASE1 = "com.ces.test.event.case1";
|
||||
const std::string EVENTCASE2 = "com.ces.test.event.case2";
|
||||
const std::string EVENTCASE3 = "com.ces.test.event.case3";
|
||||
@@ -386,7 +386,7 @@ private:
|
||||
|
||||
void CesPublishOrderedEventModuleTest::SetUpTestCase(void)
|
||||
{
|
||||
p_bundleObject = new OHOS::EventFwk::MockBundleMgrService();
|
||||
p_bundleObject = new OHOS::AppExecFwk::MockBundleMgrService();
|
||||
OHOS::DelayedSingleton<BundleManagerHelper>::GetInstance()->sptrBundleMgr_ =
|
||||
OHOS::iface_cast<OHOS::AppExecFwk::IBundleMgr>(p_bundleObject);
|
||||
OHOS::DelayedSingleton<CommonEventManagerService>::GetInstance()->OnStart();
|
||||
|
||||
@@ -19,7 +19,7 @@ module_output_path = "common_event_service/services"
|
||||
config("cesfwk_services_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
include_dirs = [ "${services_path}/test/mock/include" ]
|
||||
include_dirs = [ "${services_path}/test/unittest/mock/include" ]
|
||||
|
||||
cflags = []
|
||||
|
||||
@@ -32,7 +32,7 @@ ohos_unittest("common_event_publish_system_event_test") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"${services_path}/test/unittest/mock/src/mock_access_token_helper.cpp",
|
||||
"${common_event_service_path}/test/mock/mock_access_token_helper.cpp",
|
||||
"${services_path}/test/unittest/mock/src/mock_bundle_manager.cpp",
|
||||
"common_event_publish_system_event_test.cpp",
|
||||
]
|
||||
@@ -63,7 +63,7 @@ ohos_unittest("common_event_dump_test") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"${services_path}/test/unittest/mock/src/mock_access_token_helper.cpp",
|
||||
"${common_event_service_path}/test/mock/mock_access_token_helper.cpp",
|
||||
"${services_path}/test/unittest/mock/src/mock_bundle_manager.cpp",
|
||||
"common_event_dump_test.cpp",
|
||||
]
|
||||
@@ -94,7 +94,7 @@ ohos_unittest("common_event_freeze_test") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"${services_path}/test/unittest/mock/src/mock_access_token_helper.cpp",
|
||||
"${common_event_service_path}/test/mock/mock_access_token_helper.cpp",
|
||||
"${services_path}/test/unittest/mock/src/mock_bundle_manager.cpp",
|
||||
"common_event_freeze_test.cpp",
|
||||
]
|
||||
@@ -125,7 +125,7 @@ ohos_unittest("common_event_sticky_test") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"${services_path}/test/unittest/mock/src/mock_access_token_helper.cpp",
|
||||
"${common_event_service_path}/test/mock/mock_access_token_helper.cpp",
|
||||
"${services_path}/test/unittest/mock/src/mock_bundle_manager.cpp",
|
||||
"common_event_sticky_test.cpp",
|
||||
]
|
||||
@@ -156,7 +156,7 @@ ohos_unittest("common_event_subscribe_unit_test") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"${services_path}/test/unittest/mock/src/mock_access_token_helper.cpp",
|
||||
"${common_event_service_path}/test/mock/mock_access_token_helper.cpp",
|
||||
"${services_path}/test/unittest/mock/src/mock_bundle_manager.cpp",
|
||||
"${services_path}/test/unittest/mock/src/mock_ipc.cpp",
|
||||
"common_event_subscribe_unit_test.cpp",
|
||||
@@ -188,7 +188,7 @@ ohos_unittest("common_event_unsubscribe_unit_test") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"${services_path}/test/unittest/mock/src/mock_access_token_helper.cpp",
|
||||
"${common_event_service_path}/test/mock/mock_access_token_helper.cpp",
|
||||
"${services_path}/test/unittest/mock/src/mock_bundle_manager.cpp",
|
||||
"common_event_unsubscribe_unit_test.cpp",
|
||||
]
|
||||
@@ -219,7 +219,7 @@ ohos_unittest("common_event_publish_ordered_event_unit_test") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"${services_path}/test/unittest/mock/src/mock_access_token_helper.cpp",
|
||||
"${common_event_service_path}/test/mock/mock_access_token_helper.cpp",
|
||||
"${services_path}/test/unittest/mock/src/mock_bundle_manager.cpp",
|
||||
"common_event_publish_ordered_event_unit_test.cpp",
|
||||
]
|
||||
@@ -250,7 +250,7 @@ ohos_unittest("common_event_publish_permission_event_unit_test") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"${services_path}/test/unittest/mock/src/mock_access_token_helper.cpp",
|
||||
"${common_event_service_path}/test/mock/mock_access_token_helper.cpp",
|
||||
"${services_path}/test/unittest/mock/src/mock_bundle_manager.cpp",
|
||||
"common_event_publish_permission_event_unit_test.cpp",
|
||||
]
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::EventFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace {
|
||||
const std::string EVENT = "com.ces.test.event";
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::EventFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
namespace {
|
||||
const std::string EVENTCASE1 = "com.ces.test.event.case1";
|
||||
const std::string EVENTCASE2 = "com.ces.test.event.case2";
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::EventFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace {
|
||||
constexpr uint8_t PID = 0;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::EventFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace {
|
||||
const std::string EVENT = "com.ces.test.event";
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::EventFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace {
|
||||
constexpr uint8_t PID = 0;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::EventFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace {
|
||||
const std::string EVENT = "com.ces.test.event";
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::EventFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace {
|
||||
const std::string EVENT = "com.ces.test.event";
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::EventFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace {
|
||||
const std::string EVENT = "com.ces.test.event";
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "application_info.h"
|
||||
#include "bundle_mgr_host.h"
|
||||
#include "bundle_mgr_interface.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "ohos/aafwk/content/want.h"
|
||||
#include "iremote_proxy.h"
|
||||
#include "iremote_stub.h"
|
||||
@@ -32,9 +31,7 @@ namespace AppExecFwk {
|
||||
class MockBundleMgrService : public BundleMgrHost {
|
||||
public:
|
||||
MockBundleMgrService()
|
||||
{
|
||||
HILOG_ERROR("BundleMgrService::BundleMgrService");
|
||||
}
|
||||
{}
|
||||
|
||||
~MockBundleMgrService()
|
||||
{}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "mock_bundle_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace EventFwk {
|
||||
namespace AppExecFwk {
|
||||
constexpr uint16_t SYSTEM_UID = 1000;
|
||||
|
||||
void MockBundleMgrService::MockSetIsSystemApp(bool isSystemApp)
|
||||
@@ -29,7 +29,6 @@ void MockBundleMgrService::MockSetIsSystemApp(bool isSystemApp)
|
||||
|
||||
bool MockBundleMgrService::CheckIsSystemAppByUid(const int uid)
|
||||
{
|
||||
EVENT_LOGD("MockBundleMgrService::CheckIsSystemAppByUid");
|
||||
if (isSystemAppMock_) {
|
||||
return isSystemApp_;
|
||||
}
|
||||
@@ -38,7 +37,6 @@ bool MockBundleMgrService::CheckIsSystemAppByUid(const int uid)
|
||||
|
||||
int MockBundleMgrService::CheckPermission(const std::string &bundleName, const std::string &permission)
|
||||
{
|
||||
EVENT_LOGD("MockBundleMgrService::CheckPermission");
|
||||
static int num1 = 0;
|
||||
static int num2 = 0;
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# 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("//base/notification/common_event_service/event.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
config("bechmark_test_config") {
|
||||
include_dirs = [ "//third_party/json/include" ]
|
||||
|
||||
configs = []
|
||||
}
|
||||
|
||||
group("benchmarktest") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
"common_event_publish_test:benchmarktest",
|
||||
"common_event_service_test:benchmarktest",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
# Copyright (c) 2021 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("//base/notification/common_event_service/event.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
module_output_path = "common_event_service/benchmarktest"
|
||||
|
||||
ohos_benchmarktest("Common_Event_Publish_Test") {
|
||||
module_out_path = module_output_path
|
||||
include_dirs = [ "${services_path}/include" ]
|
||||
|
||||
sources = [ "common_event_publish_test.cpp" ]
|
||||
|
||||
deps = [
|
||||
"${ces_native_path}:cesfwk_innerkits",
|
||||
"//third_party/benchmark:benchmark",
|
||||
|
||||
# "//third_party/googletest:gtest_main",
|
||||
# "//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"eventhandler:libeventhandler",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
subsystem_name = "notification"
|
||||
part_name = "common_event_service"
|
||||
}
|
||||
|
||||
group("benchmarktest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
|
||||
deps += [
|
||||
# deps file
|
||||
":Common_Event_Publish_Test",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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 <string>
|
||||
#include <vector>
|
||||
|
||||
#include "common_event_constant.h"
|
||||
#include "common_event_listener.h"
|
||||
#include "common_event_manager.h"
|
||||
#include "singleton.h"
|
||||
|
||||
using namespace OHOS::EventFwk;
|
||||
|
||||
namespace {
|
||||
class BenchmarkCommonEventPublish : public benchmark::Fixture {
|
||||
public:
|
||||
BenchmarkCommonEventPublish()
|
||||
{
|
||||
Iterations(iterations);
|
||||
Repetitions(repetitions);
|
||||
ReportAggregatesOnly();
|
||||
}
|
||||
|
||||
virtual ~BenchmarkCommonEventPublish() override = default;
|
||||
|
||||
void SetUp(const ::benchmark::State &state) override
|
||||
{}
|
||||
|
||||
void TearDown(const ::benchmark::State &state) override
|
||||
{}
|
||||
|
||||
protected:
|
||||
const int32_t repetitions = 1;
|
||||
const int32_t iterations = 100;
|
||||
};
|
||||
|
||||
class CommonEventSubscriberBenchmark : public CommonEventSubscriber {
|
||||
public:
|
||||
explicit CommonEventSubscriberBenchmark(const CommonEventSubscribeInfo &subscribeInfo) : CommonEventSubscriber(
|
||||
subscribeInfo) {};
|
||||
virtual ~CommonEventSubscriberBenchmark() {};
|
||||
virtual void OnReceiveEvent(const CommonEventData &data) {};
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.name: SubscribeCommonEventTestCase
|
||||
* @tc.desc: SubscribeCommonEvent
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
BENCHMARK_F(BenchmarkCommonEventPublish, SubscribeCommonEventTestCase)(benchmark::State &state)
|
||||
{
|
||||
std::string eventName = "SUBSCRIBER_EVENT_BENCHMARK";
|
||||
MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(eventName);
|
||||
CommonEventSubscribeInfo subscribeInfo(matchingSkills);
|
||||
auto subscriberPtr = std::make_shared<CommonEventSubscriberBenchmark>(subscribeInfo);
|
||||
while (state.KeepRunning()) {
|
||||
CommonEventManager::SubscribeCommonEvent(subscriberPtr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UnsubscribeCommonEventTestCase
|
||||
* @tc.desc: UnsubscribeCommonEvent
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
BENCHMARK_F(BenchmarkCommonEventPublish, UnsubscribeCommonEventTestCase)(benchmark::State &state)
|
||||
{
|
||||
std::string eventName = "UNSUBSCRIBER_EVENT_BENCHMARK";
|
||||
MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(eventName);
|
||||
CommonEventSubscribeInfo subscribeInfo(matchingSkills);
|
||||
subscribeInfo.SetPriority(1000);
|
||||
auto subscriberPtr = std::make_shared<CommonEventSubscriberBenchmark>(subscribeInfo);
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
if (OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
|
||||
OHOS::EventFwk::CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PublishCommonEventTestCase
|
||||
* @tc.desc: PublishCommonEvent
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
BENCHMARK_F(BenchmarkCommonEventPublish, PublishCommonEventTestCase)(benchmark::State &state)
|
||||
{
|
||||
std::string eventAction = "PUBLISH_COMMON_EVENT_BENCHMARK";
|
||||
std::string entity = "ADDENTITY";
|
||||
bool stickty = false;
|
||||
Want testWant;
|
||||
testWant.SetAction(eventAction);
|
||||
testWant.AddEntity(entity);
|
||||
CommonEventData commonEventData(testWant);
|
||||
CommonEventPublishInfo publishInfo;
|
||||
publishInfo.SetSticky(stickty);
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
OHOS::EventFwk::CommonEventManager::PublishCommonEvent(commonEventData, publishInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Run the benchmark
|
||||
BENCHMARK_MAIN();
|
||||
@@ -0,0 +1,67 @@
|
||||
# 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("//base/notification/common_event_service/event.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
module_output_path = "common_event_service/benchmarktest"
|
||||
|
||||
ohos_benchmarktest("Common_Event_Manager_Service_Test") {
|
||||
module_out_path = module_output_path
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${common_event_service_path}/test/mock/include",
|
||||
"${ces_core_path}/include",
|
||||
"${ces_innerkits_path}/include",
|
||||
"//foundation/distributedschedule/safwk/services/safwk/include",
|
||||
"${services_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${common_event_service_path}/test/mock/mock_access_token_helper.cpp",
|
||||
"${common_event_service_path}/test/mock/mock_bundle_manager.cpp",
|
||||
"${common_event_service_path}/test/mock/mock_ipc.cpp",
|
||||
"common_event_manager_service_test.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${ces_common_path}:libevent_common",
|
||||
"${ces_core_path}:cesfwk_core",
|
||||
"${ces_native_path}:cesfwk_innerkits",
|
||||
"${services_path}:cesfwk_services",
|
||||
"//third_party/benchmark:benchmark",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"eventhandler:libeventhandler",
|
||||
"ipc:ipc_core",
|
||||
"ipc:libdbinder",
|
||||
]
|
||||
subsystem_name = "notification"
|
||||
part_name = "common_event_service"
|
||||
}
|
||||
|
||||
group("benchmarktest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
|
||||
deps += [
|
||||
# deps file
|
||||
":Common_Event_Manager_Service_Test",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* 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 <string>
|
||||
#include <vector>
|
||||
|
||||
#define private public
|
||||
#include "common_event_constant.h"
|
||||
#include "common_event_listener.h"
|
||||
#include "common_event_manager_service.h"
|
||||
#include "mock_bundle_manager.h"
|
||||
#include "singleton.h"
|
||||
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::EventFwk;
|
||||
|
||||
namespace {
|
||||
class BenchmarkCommonEventManagerService : public benchmark::Fixture {
|
||||
public:
|
||||
BenchmarkCommonEventManagerService()
|
||||
{
|
||||
Iterations(iterations);
|
||||
Repetitions(repetitions);
|
||||
ReportAggregatesOnly();
|
||||
}
|
||||
|
||||
virtual ~BenchmarkCommonEventManagerService() override = default;
|
||||
|
||||
void SetUp(const ::benchmark::State &state) override
|
||||
{
|
||||
OHOS::DelayedSingleton<CommonEventManagerService>::GetInstance()->OnStart();
|
||||
}
|
||||
void TearDown(const ::benchmark::State &state) override
|
||||
{
|
||||
OHOS::DelayedSingleton<CommonEventManagerService>::GetInstance()->OnStop();
|
||||
}
|
||||
|
||||
protected:
|
||||
const int32_t repetitions = 3;
|
||||
const int32_t iterations = 100;
|
||||
};
|
||||
|
||||
class CommonEventSubscriberBenchmark : public CommonEventSubscriber {
|
||||
public:
|
||||
explicit CommonEventSubscriberBenchmark(const CommonEventSubscribeInfo &subscribeInfo) : CommonEventSubscriber(
|
||||
subscribeInfo) {};
|
||||
virtual ~CommonEventSubscriberBenchmark() {};
|
||||
virtual void OnReceiveEvent(const CommonEventData &data) {};
|
||||
};
|
||||
/**
|
||||
* @tc.name: CommonEventSubscribeTestCase001
|
||||
* @tc.desc: SubscribeCommonEvent: event is normal
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
BENCHMARK_F(BenchmarkCommonEventManagerService, CommonEventSubscribeTestCase001)(benchmark::State &state)
|
||||
{
|
||||
std::string eventName = "SUBSCRIBEEVENT_BENCHMARK";
|
||||
MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(eventName);
|
||||
CommonEventSubscribeInfo subscribeInfo(matchingSkills);
|
||||
auto subscriberPtr = std::make_shared<CommonEventSubscriberBenchmark>(subscribeInfo);
|
||||
OHOS::sptr<CommonEventListener> commonEventListener = new CommonEventListener(subscriberPtr);
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
bool result = OHOS::DelayedSingleton<CommonEventManagerService>::GetInstance()->SubscribeCommonEvent(
|
||||
subscribeInfo, commonEventListener);
|
||||
if (!result) {
|
||||
state.SkipWithError("SubscribeCommonEvent failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CommonEventSubscribeTestCase002
|
||||
* @tc.desc: SubscribeCommonEvent: event is number
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
BENCHMARK_F(BenchmarkCommonEventManagerService, CommonEventSubscribeTestCase002)(benchmark::State &state)
|
||||
{
|
||||
std::string eventName = "1";
|
||||
MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(eventName);
|
||||
CommonEventSubscribeInfo subscribeInfo(matchingSkills);
|
||||
auto subscriberPtr = std::make_shared<CommonEventSubscriberBenchmark>(subscribeInfo);
|
||||
OHOS::sptr<CommonEventListener> commonEventListener = new CommonEventListener(subscriberPtr);
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
bool result = OHOS::DelayedSingleton<CommonEventManagerService>::GetInstance()->SubscribeCommonEvent(
|
||||
subscribeInfo, commonEventListener);
|
||||
if (!result) {
|
||||
state.SkipWithError("SubscribeCommonEvent failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CommonEventSubscribeTestCase003
|
||||
* @tc.desc: SubscribeCommonEvent: event is empty
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
BENCHMARK_F(BenchmarkCommonEventManagerService, CommonEventSubscribeTestCase003)(benchmark::State &state)
|
||||
{
|
||||
std::string eventName = "";
|
||||
MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(eventName);
|
||||
CommonEventSubscribeInfo subscribeInfo(matchingSkills);
|
||||
auto subscriberPtr = std::make_shared<CommonEventSubscriberBenchmark>(subscribeInfo);
|
||||
OHOS::sptr<CommonEventListener> commonEventListener = new CommonEventListener(subscriberPtr);
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
bool result = OHOS::DelayedSingleton<CommonEventManagerService>::GetInstance()->SubscribeCommonEvent(
|
||||
subscribeInfo, commonEventListener);
|
||||
if (!result) {
|
||||
state.SkipWithError("SubscribeCommonEvent failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CommonEventUnsubscribeTestCase
|
||||
* @tc.desc: UnsubscribeCommonEvent
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
BENCHMARK_F(BenchmarkCommonEventManagerService, CommonEventUnsubscribeTestCase)(benchmark::State &state)
|
||||
{
|
||||
std::string eventName = "SUBSCRIBEEVENT_BENCHMARK";
|
||||
MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(eventName);
|
||||
CommonEventSubscribeInfo subscribeInfo(matchingSkills);
|
||||
auto subscriberPtr = std::make_shared<CommonEventSubscriberBenchmark>(subscribeInfo);
|
||||
OHOS::sptr<CommonEventListener> commonEventListener = new CommonEventListener(subscriberPtr);
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
bool result = OHOS::DelayedSingleton<CommonEventManagerService>::GetInstance()->UnsubscribeCommonEvent(
|
||||
commonEventListener);
|
||||
if (!result) {
|
||||
state.SkipWithError("UnsubscribeCommonEvent failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CommonEventPublishTestCase
|
||||
* @tc.desc: PublishCommonEvent
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
BENCHMARK_F(BenchmarkCommonEventManagerService, CommonEventPublishTestCase)(benchmark::State &state)
|
||||
{
|
||||
std::string eventName = "SUBSCRIBEEVENT_BENCHMARK";
|
||||
std::string eventAction = "SUBSCRIBEEVENT_BENCHMARK";
|
||||
bool stickty = false;
|
||||
MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(eventName);
|
||||
Want testWant;
|
||||
testWant.SetAction(eventAction);
|
||||
CommonEventData commonEventData(testWant);
|
||||
CommonEventPublishInfo publishInfo;
|
||||
publishInfo.SetSticky(stickty);
|
||||
CommonEventSubscribeInfo subscribeInfo(matchingSkills);
|
||||
auto subscriberPtr = std::make_shared<CommonEventSubscriberBenchmark>(subscribeInfo);
|
||||
OHOS::sptr<CommonEventListener> commonEventListener = new CommonEventListener(subscriberPtr);
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
bool result = OHOS::DelayedSingleton<CommonEventManagerService>::GetInstance()->PublishCommonEvent(
|
||||
commonEventData, publishInfo, commonEventListener, UNDEFINED_USER);
|
||||
if (!result) {
|
||||
state.SkipWithError("PublishCommonEvent failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CommonEventDumpStateTestCase
|
||||
* @tc.desc: DumpState
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
BENCHMARK_F(BenchmarkCommonEventManagerService, CommonEventDumpStateTestCase)(benchmark::State &state)
|
||||
{
|
||||
std::string eventName = "SUBSCRIBEEVENT_BENCHMARK";
|
||||
MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(eventName);
|
||||
CommonEventSubscribeInfo subscribeInfo(matchingSkills);
|
||||
auto subscriberPtr = std::make_shared<CommonEventSubscriberBenchmark>(subscribeInfo);
|
||||
OHOS::sptr<CommonEventListener> commonEventListener = new CommonEventListener(subscriberPtr);
|
||||
|
||||
bool result = OHOS::DelayedSingleton<CommonEventManagerService>::GetInstance()->SubscribeCommonEvent(
|
||||
subscribeInfo, commonEventListener);
|
||||
if (!result) {
|
||||
state.SkipWithError("DumpState subscribe common event failed.");
|
||||
}
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
std::vector<std::string> stateTest;
|
||||
if (OHOS::DelayedSingleton<CommonEventManagerService>::GetInstance()->DumpState("", ALL_USER, stateTest)) {
|
||||
if (stateTest.size() < 1) {
|
||||
state.SkipWithError("DumpState failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Run the benchmark
|
||||
BENCHMARK_MAIN();
|
||||
+601
-693
File diff suppressed because it is too large
Load Diff
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_MOCK_IPC_SKELETON_H
|
||||
#define OHOS_MOCK_IPC_SKELETON_H
|
||||
|
||||
#include "iremote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
class IPCSkeleton {
|
||||
public:
|
||||
IPCSkeleton() = default;
|
||||
~IPCSkeleton() = default;
|
||||
|
||||
// default max is 4, only if you need a customize value
|
||||
static bool SetMaxWorkThreadNum(int maxThreadNum);
|
||||
|
||||
// join current thread into work loop.
|
||||
static void JoinWorkThread();
|
||||
|
||||
// remove current thread from work loop.
|
||||
static void StopWorkThread();
|
||||
|
||||
static pid_t GetCallingPid();
|
||||
|
||||
static pid_t GetCallingUid();
|
||||
|
||||
static std::string GetLocalDeviceID();
|
||||
|
||||
static std::string GetCallingDeviceID();
|
||||
|
||||
static bool IsLocalCalling();
|
||||
|
||||
static IPCSkeleton &GetInstance();
|
||||
|
||||
static sptr<IRemoteObject> GetContextObject();
|
||||
|
||||
static bool SetContextObject(sptr<IRemoteObject> &object);
|
||||
|
||||
static int FlushCommands(IRemoteObject *object);
|
||||
|
||||
static std::string ResetCallingIdentity();
|
||||
|
||||
static bool SetCallingIdentity(std::string &identity);
|
||||
|
||||
static void SetCallingUid(pid_t uid);
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_MOCK_IPC_SKELETON_H
|
||||
+34
-37
@@ -1,37 +1,34 @@
|
||||
/*
|
||||
* 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 "access_token_helper.h"
|
||||
#include "event_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace EventFwk {
|
||||
using namespace OHOS::Security;
|
||||
|
||||
constexpr unsigned int PERMISSION_GRANTED = 1;
|
||||
|
||||
bool AccessTokenHelper::VerifyNativeToken(const AccessToken::AccessTokenID &callerToken)
|
||||
{
|
||||
EVENT_LOGD("MockAccessTokenHelper::VerifyNativeToken");
|
||||
return callerToken == PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
int AccessTokenHelper::VerifyAccessToken(const AccessToken::AccessTokenID &callerToken, const std::string &permission)
|
||||
{
|
||||
EVENT_LOGD("MockAccessTokenHelper::VerifyAccessToken");
|
||||
return callerToken != PERMISSION_GRANTED;
|
||||
}
|
||||
} // namespace EventFwk
|
||||
} // namespace OHOS
|
||||
/*
|
||||
* 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 "access_token_helper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace EventFwk {
|
||||
using namespace OHOS::Security;
|
||||
|
||||
constexpr unsigned int PERMISSION_GRANTED = 1;
|
||||
|
||||
bool AccessTokenHelper::VerifyNativeToken(const AccessToken::AccessTokenID &callerToken)
|
||||
{
|
||||
return callerToken == PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
int AccessTokenHelper::VerifyAccessToken(const AccessToken::AccessTokenID &callerToken, const std::string &permission)
|
||||
{
|
||||
return callerToken == PERMISSION_GRANTED;
|
||||
}
|
||||
} // namespace EventFwk
|
||||
} // namespace OHOS
|
||||
+46
-48
@@ -1,49 +1,47 @@
|
||||
/*
|
||||
* 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 "mock_bundle_manager.h"
|
||||
#include "ability_info.h"
|
||||
#include "application_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace EventFwk {
|
||||
constexpr int SYSTEM_UID = 1000;
|
||||
|
||||
void MockBundleMgrService::MockSetIsSystemApp(bool isSystemApp)
|
||||
{
|
||||
isSystemAppMock_ = true;
|
||||
isSystemApp_ = isSystemApp;
|
||||
}
|
||||
|
||||
bool MockBundleMgrService::CheckIsSystemAppByUid(const int uid)
|
||||
{
|
||||
EVENT_LOGD("MockBundleMgrService::CheckIsSystemAppByUid");
|
||||
if (isSystemAppMock_) {
|
||||
return isSystemApp_;
|
||||
}
|
||||
return (uid > SYSTEM_UID) ? false : true;
|
||||
}
|
||||
|
||||
int MockBundleMgrService::CheckPermission(const std::string &bundleName, const std::string &permission)
|
||||
{
|
||||
EVENT_LOGD("MockBundleMgrService::CheckPermission");
|
||||
if (!bundleName.compare("hello")) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
/*
|
||||
* 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 "mock_bundle_manager.h"
|
||||
#include "ability_info.h"
|
||||
#include "application_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
constexpr int SYSTEM_UID = 1000;
|
||||
|
||||
void MockBundleMgrService::MockSetIsSystemApp(bool isSystemApp)
|
||||
{
|
||||
isSystemAppMock_ = true;
|
||||
isSystemApp_ = isSystemApp;
|
||||
}
|
||||
|
||||
bool MockBundleMgrService::CheckIsSystemAppByUid(const int uid)
|
||||
{
|
||||
if (isSystemAppMock_) {
|
||||
return isSystemApp_;
|
||||
}
|
||||
return (uid > SYSTEM_UID) ? false : true;
|
||||
}
|
||||
|
||||
int MockBundleMgrService::CheckPermission(const std::string &bundleName, const std::string &permission)
|
||||
{
|
||||
if (!bundleName.compare("hello")) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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 "mock_ipc_skeleton.h"
|
||||
|
||||
namespace OHOS {
|
||||
#ifdef CONFIG_IPC_SINGLE
|
||||
using namespace IPC_SINGLE;
|
||||
#endif
|
||||
|
||||
pid_t uid_ = 1000;
|
||||
|
||||
pid_t IPCSkeleton::GetCallingUid()
|
||||
{
|
||||
return uid_;
|
||||
}
|
||||
|
||||
pid_t IPCSkeleton::GetCallingPid()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void IPCSkeleton::SetCallingUid(pid_t uid)
|
||||
{
|
||||
uid_ = uid;
|
||||
}
|
||||
} // namespace OHOS
|
||||
Reference in New Issue
Block a user